You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/10/02 10:40:09 UTC

[incubator-dlab] branch develop updated: DLAB-000 fixed bug connected with group removing

This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git


The following commit(s) were added to refs/heads/develop by this push:
     new 4aed1c0  DLAB-000 fixed bug connected with group removing
4aed1c0 is described below

commit 4aed1c0b4a4738263b2c3ba9556a6861a45ecd88
Author: bhliva <bo...@epam.com>
AuthorDate: Wed Oct 2 13:39:55 2019 +0300

    DLAB-000 fixed bug connected with group removing
---
 .../service/impl/UserGroupServiceImpl.java           | 20 ++++++++------------
 .../service/impl/UserGroupServiceImplTest.java       |  9 +++++----
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java
index c3867c9..0a71587 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImpl.java
@@ -89,19 +89,15 @@ public class UserGroupServiceImpl implements UserGroupService {
 
 	@Override
 	public void removeGroup(String groupId) {
-		final List<ProjectDTO> notTerminatedProjects =
-				projectDAO.getProjectsWithEndpointStatusNotIn(UserInstanceStatus.TERMINATED,
-						UserInstanceStatus.TERMINATING);
-		if (!notTerminatedProjects.isEmpty()){
-			notTerminatedProjects
-					.stream()
-					.filter(p -> !p.getGroups().contains(groupId))
-					.findAny()
-					.orElseThrow(() -> new ResourceConflictException("Group can not be removed because it is used in some " +
-							"project"));
-		}
-		if (userRoleDao.removeGroup(groupId)) {
+		if (projectDAO.getProjectsWithEndpointStatusNotIn(UserInstanceStatus.TERMINATED,
+				UserInstanceStatus.TERMINATING)
+				.stream()
+				.map(ProjectDTO::getGroups)
+				.noneMatch(groups -> groups.contains(groupId))) {
+			userRoleDao.removeGroup(groupId);
 			userGroupDao.removeGroup(groupId);
+		} else {
+			throw new ResourceConflictException("Group can not be removed because it is used in some project");
 		}
 	}
 
diff --git a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImplTest.java b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImplTest.java
index 52f985c..d494d5d 100644
--- a/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImplTest.java
+++ b/services/self-service/src/test/java/com/epam/dlab/backendapi/service/impl/UserGroupServiceImplTest.java
@@ -174,7 +174,8 @@ public class UserGroupServiceImplTest {
 
 		when(userRoleDao.removeGroup(anyString())).thenReturn(true);
 		when(projectDAO.getProjectsWithEndpointStatusNotIn(UserInstanceStatus.TERMINATED,
-				UserInstanceStatus.TERMINATING)).thenReturn(Collections.emptyList());
+				UserInstanceStatus.TERMINATING)).thenReturn(Collections.singletonList( new ProjectDTO(
+				"name", Collections.singleton(GROUP), "", "", null, Collections.emptyList())));
 		doNothing().when(userGroupDao).removeGroup(anyString());
 
 		try {
@@ -183,8 +184,8 @@ public class UserGroupServiceImplTest {
 			assertEquals("Group can not be removed because it is used in some project", e.getMessage());
 		}
 
-		verify(userRoleDao).removeGroup(GROUP);
-		verify(userGroupDao).removeGroup(GROUP);
+		verify(userRoleDao, never()).removeGroup(GROUP);
+		verify(userGroupDao, never()).removeGroup(GROUP);
 		verifyNoMoreInteractions(userGroupDao, userRoleDao);
 	}
 
@@ -201,7 +202,7 @@ public class UserGroupServiceImplTest {
 		userGroupService.removeGroup(GROUP);
 
 		verify(userRoleDao).removeGroup(GROUP);
-		verify(userGroupDao, never()).removeGroup(GROUP);
+		verify(userGroupDao).removeGroup(GROUP);
 		verifyNoMoreInteractions(userGroupDao, userRoleDao);
 	}
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org