Commit 1d9d556e authored by Rostislav Vatolin [SLB]'s avatar Rostislav Vatolin [SLB]
Browse files

add provider specific method

parent c5b25ea7
Pipeline #45750 passed with stages
in 19 minutes and 39 seconds
......@@ -42,7 +42,7 @@ public class RemoveMemberService {
!removeMemberServiceDto.getRequesterId().equalsIgnoreCase(serviceAccountId)) {
throw new AppException(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase(), "Not authorized to manage members");
}
EntityNode memberNode = getEntityNode(memberEmail, partitionId);
EntityNode memberNode = retrieveGroupRepo.getMemberNodeForRemovalFromGroup(memberEmail, partitionId);
removeMemberServiceDto.setChildrenReference(memberNode.getDirectChildReference(retrieveGroupRepo, existingGroupEntityNode).orElseThrow(
() -> new AppException(HttpStatus.NOT_FOUND.value(), HttpStatus.NOT_FOUND.getReasonPhrase(), String.format("Group %s does not have %s as a child/member", groupEmail, memberEmail))
));
......@@ -67,12 +67,4 @@ public class RemoveMemberService {
groupCacheService.refreshListGroupCache(impactedUsers, removeMemberServiceDto.getPartitionId());
return impactedUsers;
}
private EntityNode getEntityNode(String id, String partitionId) {
return retrieveGroupRepo.getEntityNode(id, partitionId)
.orElseThrow(() -> new AppException(
HttpStatus.NOT_FOUND.value(),
HttpStatus.NOT_FOUND.getReasonPhrase(),
String.format("Not found entity node by email: %s and partitionId: %s", id, partitionId)));
}
}
......@@ -16,6 +16,8 @@ public interface RetrieveGroupRepo {
Optional<EntityNode> getEntityNode(String entityEmail, String partitionId);
EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId);
Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds);
Map<String, Set<String>> getUserPartitionAssociations(Set<String> userIds);
......
......@@ -77,7 +77,7 @@ public class RemoveMemberServiceTests {
.name("member")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com")
......@@ -128,7 +128,7 @@ public class RemoveMemberServiceTests {
.name("member")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com")
......@@ -170,7 +170,7 @@ public class RemoveMemberServiceTests {
.name("member")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com")
......@@ -219,7 +219,7 @@ public class RemoveMemberServiceTests {
.name("member")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("data.x@common.contoso.com")
......@@ -271,7 +271,7 @@ public class RemoveMemberServiceTests {
.name("users")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("users@common.contoso.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("users@common.contoso.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("data.default.owners@common.contoso.com")
......@@ -328,7 +328,7 @@ public class RemoveMemberServiceTests {
.name("member")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode("member@xxx.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup("member@xxx.com", "common")).thenReturn(memberNode);
EntityNode entityNode = EntityNode.builder()
.type(NodeType.USER)
.nodeId("member@xxx.com")
......@@ -378,8 +378,8 @@ public class RemoveMemberServiceTests {
.name("datafier")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode(
"datafier@evd-ddl-us-common.iam.gserviceaccount.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup(
"datafier@evd-ddl-us-common.iam.gserviceaccount.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("users.data.root@common.contoso.com")
......@@ -437,8 +437,8 @@ public class RemoveMemberServiceTests {
.name("users.data.root")
.dataPartitionId("common")
.build();
when(retrieveGroupRepo.getEntityNode(
"users.data.root@common.contoso.com", "common")).thenReturn(Optional.of(memberNode));
when(retrieveGroupRepo.getMemberNodeForRemovalFromGroup(
"users.data.root@common.contoso.com", "common")).thenReturn(memberNode);
EntityNode groupNode = EntityNode.builder()
.type(NodeType.GROUP)
.nodeId("users.test@common.contoso.com")
......
......@@ -90,6 +90,14 @@ public class AwsRetrieveGroupRepo implements RetrieveGroupRepo {
}
}
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
if (!memberId.endsWith(String.format("@%s.%s", partitionId, config.getDomain()))) {
return EntityNode.createMemberNodeForNewUser(memberId, partitionId);
}
return EntityNode.createNodeFromGroupEmail(memberId);
}
@Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
if (nodeIds.isEmpty()) {
......
......@@ -54,6 +54,15 @@ public class RetrieveGroupRepoGremlin implements RetrieveGroupRepo {
return gremlinConnector.getVertex(traversal).map(vertexUtilService::createMemberNode);
}
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
return getEntityNode(memberId, partitionId)
.orElseThrow(() -> new AppException(
HttpStatus.NOT_FOUND.value(),
HttpStatus.NOT_FOUND.getReasonPhrase(),
String.format("Not found entity node by email: %s and partitionId: %s", memberId, partitionId)));
}
@Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
return new HashSet<>();
......
......@@ -87,6 +87,14 @@ public class RetrieveGroupRepoRedis implements RetrieveGroupRepo {
}
}
@Override
public EntityNode getMemberNodeForRemovalFromGroup(String memberId, String partitionId) {
if (!memberId.endsWith(String.format("@%s.%s", partitionId, config.getDomain()))) {
return EntityNode.createMemberNodeForNewUser(memberId, partitionId);
}
return EntityNode.createNodeFromGroupEmail(memberId);
}
@Override
public Set<EntityNode> getEntityNodes(String partitionId, List<String> nodeIds) {
if (nodeIds.isEmpty()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment