Commit 10e735c6 authored by Jason's avatar Jason
Browse files

Merge branch 'app-id-filtering' into 'master'

Remove extra call to cosmos for get groups API

See merge request !41
parents f1d2a25b 57a2b35c
Pipeline #32116 passed with stages
in 13 minutes and 36 seconds
......@@ -10,6 +10,9 @@ import lombok.Data;
import lombok.Generated;
import lombok.NoArgsConstructor;
import java.util.HashSet;
import java.util.Set;
/**
* We use 2 json library annotation in this class for performance optimization
* @ConfiledJson @JsonAttribute annotations are from dsljson library and they are used for conversion when storing and retrieving from reference db,
......@@ -31,6 +34,9 @@ public class ParentReference {
private String description;
@JsonIgnore
private String dataPartitionId;
@JsonIgnore
@Builder.Default
private Set<String> appIds = new HashSet<>();
@JsonAttribute(index = 3)
public String getId() {
......@@ -61,6 +67,11 @@ public class ParentReference {
.build();
}
@JsonIgnore
public Set<String> getAppIds() {
return appIds;
}
@JsonIgnore
public boolean isRootUserGroup() {
return "users".equalsIgnoreCase(name);
......
......@@ -73,8 +73,8 @@ public class ListGroupsApiTest {
@Test
public void shouldSerializeOutput() throws Exception {
ParentReference g1 = ParentReference.builder().name("viewers").id("viewers@dp.domain.com").description("").build();
ParentReference g2 = ParentReference.builder().name("data.x").id("data.x@dp.domain.com").description("a data group").build();
ParentReference g1 = ParentReference.builder().name("data.x").id("data.x@dp.domain.com").description("a data group").build();
ParentReference g2 = ParentReference.builder().name("viewers").id("viewers@dp.domain.com").description("").build();
List<ParentReference> groups = Arrays.asList(g1, g2);
ListGroupResponseDto expectedResult = ListGroupResponseDto.builder().desId("a@b.com").memberEmail("a@b.com").groups(groups).build();
......
......@@ -48,6 +48,7 @@ public class VertexUtilService {
.name(vertex.getName())
.description(vertex.getDescription())
.dataPartitionId(vertex.getDataPartitionId())
.appIds(vertex.getAppIds())
.build();
}
......
......@@ -137,20 +137,9 @@ public class RetrieveGroupRepoGremlin implements RetrieveGroupRepo {
return ChildrenTreeDto.builder().childrenUserIds(new ArrayList<>()).build();
}
@Override
public Set<ParentReference> filterParentsByAppId(
Set<ParentReference> parentReferences, String partitionId, String appId) {
Map<String, ParentReference> parentReferenceById = parentReferences.stream()
.collect(Collectors.toMap(ParentReference::getId, Function.identity()));
String[] nodeIds = parentReferenceById.keySet().toArray(new String[0]);
GraphTraversal<Vertex, Vertex> graphTraversal = gremlinConnector.getGraphTraversalSource().V()
.has(VertexPropertyNames.DATA_PARTITION_ID, partitionId)
.or(buildOrTraversalsByNodeIds(nodeIds))
.or(__.hasNot(VertexPropertyNames.APP_ID), __.has(VertexPropertyNames.APP_ID, appId));
return gremlinConnector.getVertices(graphTraversal).stream()
.map(NodeVertex::getNodeId)
.flatMap(nodeId -> Arrays.stream(nodeIds).filter(nodeId::equals))
.map(parentReferenceById::get)
public Set<ParentReference> filterParentsByAppId(Set<ParentReference> parentReferences, String partitionId, String appId) {
return parentReferences.stream()
.filter(pr -> pr.getAppIds().isEmpty() || pr.getAppIds().contains(appId))
.collect(Collectors.toSet());
}
......
......@@ -25,6 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
......@@ -475,10 +476,25 @@ public class RetrieveGroupRepoGremlinTest {
.next();
Set<ParentReference> parentReferences = new HashSet<>();
parentReferences.add(ParentReference.builder().id(group1Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder().id(group2Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder().id(group3Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder().id(group4Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder()
.id(group1Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.build());
parentReferences.add(ParentReference.builder()
.id(group2Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.appIds(new HashSet<>(Collections.singletonList("appid")))
.build());
parentReferences.add(ParentReference.builder()
.id(group3Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.appIds(new HashSet<>(Collections.singletonList("otherappid")))
.build());
parentReferences.add(ParentReference.builder()
.id(group4Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.appIds(new HashSet<>(Arrays.asList("otherappid","appid")))
.build());
Set<ParentReference> res = retrieveGroupRepo.filterParentsByAppId(parentReferences, "dp", "appid");
Assert.assertEquals(3, res.size());
......@@ -510,9 +526,20 @@ public class RetrieveGroupRepoGremlinTest {
.next();
Set<ParentReference> parentReferences = new HashSet<>();
parentReferences.add(ParentReference.builder().id(group1Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder().id(group2Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder().id(group3Vertex.value(VertexPropertyNames.NODE_ID)).dataPartitionId("dp").build());
parentReferences.add(ParentReference.builder()
.id(group1Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.build());
parentReferences.add(ParentReference.builder()
.id(group2Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.appIds(new HashSet<>(Collections.singletonList("appid")))
.build());
parentReferences.add(ParentReference.builder()
.id(group3Vertex.value(VertexPropertyNames.NODE_ID))
.dataPartitionId("dp")
.appIds(new HashSet<>(Collections.singletonList("appid")))
.build());
Set<ParentReference> res = retrieveGroupRepo.filterParentsByAppId(parentReferences, "dp", "appid");
Assert.assertEquals(3, res.size());
......
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