@Test void testGetGraph() throws TypeErrorException { Map<String, EntityDetail> entityStore = new HashMap<>(); Map<String, Relationship> relationshipStore = new HashMap<>(); String rootEntityGUID = "1111"; List<String> entityTypeGUIDs = null; List<String> relationshipTypeGUIDs = null; List<InstanceStatus> limitResultsByStatus = null; List<String> limitResultsByClassification = null; EntityDetail entity1 = new EntityDetail(); entity1.setGUID("1111"); entityStore.put(entity1.getGUID(), entity1); when(repositoryValidator.verifyInstanceHasRightStatus(any(), any())).thenReturn(true); when(repositoryValidator.verifyEntityIsClassified(any(), any())).thenReturn(true); when(repositoryHelper.isTypeOf(anyString(),anyString(),anyString())).thenReturn(true); InMemoryEntityNeighbourhood inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper,"", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); InstanceGraph graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertNull(graph.getRelationships()); EntityDetail entity2 = new EntityDetail(); entity2.setGUID("2222"); Relationship relationship1 = new Relationship(); relationship1.setGUID("3333"); InstanceType type = new InstanceType(); type.setTypeDefGUID("4444"); EntityProxy entityProxy1 = getEntityProxy(entity1.getGUID(), null, type); EntityProxy entityProxy2 = getEntityProxy(entity2.getGUID(), null, type); relationship1.setEntityOneProxy(entityProxy1); relationship1.setEntityTwoProxy(entityProxy2); entityStore.put(entity2.getGUID(), entity2); relationshipStore.put(relationship1.getGUID(), relationship1); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper, "", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 2); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); EntityDetail entity3 = new EntityDetail(); entity3.setGUID("5555"); EntityProxy entityProxy3 = getEntityProxy(entity3.getGUID(), null, type); entityStore.put(entity3.getGUID(), entity3); Relationship relationship2 = new Relationship(); relationship2.setGUID("6666"); relationship2.setEntityOneProxy(entityProxy2); relationship2.setEntityTwoProxy(entityProxy3); relationshipStore.put(relationship2.getGUID(), relationship2); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper, "",repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 2); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper,"", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 3); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 3); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsEntityWithGuid(graph, "5555")); assertTrue(graph.getRelationships().size() == 2); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); assertTrue(graphContainsRelationshipWithGuid(graph, "6666")); List<Classification> classificationsForEntity2 = new ArrayList<>(); Classification testClassification = new Classification(); testClassification.setName(CLASSIFICATION_1); classificationsForEntity2.add(testClassification); testClassification = new Classification(); testClassification.setName(CLASSIFICATION_2); classificationsForEntity2.add(testClassification); entity2.setClassifications(classificationsForEntity2); entityStore.put(entity2.getGUID(), entity2); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper,"", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 2); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); limitResultsByClassification = new ArrayList<>(); limitResultsByClassification.add(CLASSIFICATION_1); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper,"", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 2); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); limitResultsByClassification.add(CLASSIFICATION_2); limitResultsByClassification.add(CLASSIFICATION_3); limitResultsByClassification = new ArrayList<>(); limitResultsByClassification.add(CLASSIFICATION_1); inMemoryEntityNeighbourhood = new InMemoryEntityNeighbourhood(repositoryHelper,"", repositoryValidator, entityStore, relationshipStore, rootEntityGUID, entityTypeGUIDs, relationshipTypeGUIDs, limitResultsByStatus, limitResultsByClassification, 1); graph = inMemoryEntityNeighbourhood.createInstanceGraph(); assertTrue(graph.getEntities().size() == 2); assertTrue(graphContainsEntityWithGuid(graph, "1111")); assertTrue(graphContainsEntityWithGuid(graph, "2222")); assertTrue(graphContainsRelationshipWithGuid(graph, "3333")); }
InstanceGraph createInstanceGraph() throws TypeErrorException { Set<String> entities = new HashSet<>(); Set<String> visitedEntities = new HashSet<>(); Set<String> visitedRelationships = new HashSet<>(); entities.add(rootEntityGUID); this.createGraph(entities, visitedEntities, visitedRelationships, 0); List<EntityDetail> entityList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); EntityDetail rootEntity = (entityStore.get(rootEntityGUID)); entityList.add(rootEntity); for (String entityGuid : this.graphEntities) { if (!entityGuid.equals(rootEntityGUID)) { entityList.add(this.entityStore.get(entityGuid)); } } for (String relationshipGuid : this.graphRelationships) { relationshipList.add(this.relationshipStore.get(relationshipGuid)); } return new InstanceGraph(entityList, relationshipList); }
InMemoryEntityNeighbourhood { InstanceGraph createInstanceGraph() throws TypeErrorException { Set<String> entities = new HashSet<>(); Set<String> visitedEntities = new HashSet<>(); Set<String> visitedRelationships = new HashSet<>(); entities.add(rootEntityGUID); this.createGraph(entities, visitedEntities, visitedRelationships, 0); List<EntityDetail> entityList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); EntityDetail rootEntity = (entityStore.get(rootEntityGUID)); entityList.add(rootEntity); for (String entityGuid : this.graphEntities) { if (!entityGuid.equals(rootEntityGUID)) { entityList.add(this.entityStore.get(entityGuid)); } } for (String relationshipGuid : this.graphRelationships) { relationshipList.add(this.relationshipStore.get(relationshipGuid)); } return new InstanceGraph(entityList, relationshipList); } }
InMemoryEntityNeighbourhood { InstanceGraph createInstanceGraph() throws TypeErrorException { Set<String> entities = new HashSet<>(); Set<String> visitedEntities = new HashSet<>(); Set<String> visitedRelationships = new HashSet<>(); entities.add(rootEntityGUID); this.createGraph(entities, visitedEntities, visitedRelationships, 0); List<EntityDetail> entityList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); EntityDetail rootEntity = (entityStore.get(rootEntityGUID)); entityList.add(rootEntity); for (String entityGuid : this.graphEntities) { if (!entityGuid.equals(rootEntityGUID)) { entityList.add(this.entityStore.get(entityGuid)); } } for (String relationshipGuid : this.graphRelationships) { relationshipList.add(this.relationshipStore.get(relationshipGuid)); } return new InstanceGraph(entityList, relationshipList); } InMemoryEntityNeighbourhood(OMRSRepositoryHelper      repositoryHelper,
                                String                    repositoryName,
                                OMRSRepositoryValidator   repositoryValidator,
                                Map<String, EntityDetail> entityStore,
                                Map<String, Relationship> relationshipStore,
                                String                    rootEntityGUID,
                                List<String>              entityTypeGUIDs,
                                List<String>              relationshipTypeGUIDs,
                                List<InstanceStatus>      limitResultsByStatus,
                                List<String>              limitResultsByClassification,
                                int                       level); }
InMemoryEntityNeighbourhood { InstanceGraph createInstanceGraph() throws TypeErrorException { Set<String> entities = new HashSet<>(); Set<String> visitedEntities = new HashSet<>(); Set<String> visitedRelationships = new HashSet<>(); entities.add(rootEntityGUID); this.createGraph(entities, visitedEntities, visitedRelationships, 0); List<EntityDetail> entityList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); EntityDetail rootEntity = (entityStore.get(rootEntityGUID)); entityList.add(rootEntity); for (String entityGuid : this.graphEntities) { if (!entityGuid.equals(rootEntityGUID)) { entityList.add(this.entityStore.get(entityGuid)); } } for (String relationshipGuid : this.graphRelationships) { relationshipList.add(this.relationshipStore.get(relationshipGuid)); } return new InstanceGraph(entityList, relationshipList); } InMemoryEntityNeighbourhood(OMRSRepositoryHelper      repositoryHelper,
                                String                    repositoryName,
                                OMRSRepositoryValidator   repositoryValidator,
                                Map<String, EntityDetail> entityStore,
                                Map<String, Relationship> relationshipStore,
                                String                    rootEntityGUID,
                                List<String>              entityTypeGUIDs,
                                List<String>              relationshipTypeGUIDs,
                                List<InstanceStatus>      limitResultsByStatus,
                                List<String>              limitResultsByClassification,
                                int                       level);  }
InMemoryEntityNeighbourhood { InstanceGraph createInstanceGraph() throws TypeErrorException { Set<String> entities = new HashSet<>(); Set<String> visitedEntities = new HashSet<>(); Set<String> visitedRelationships = new HashSet<>(); entities.add(rootEntityGUID); this.createGraph(entities, visitedEntities, visitedRelationships, 0); List<EntityDetail> entityList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); EntityDetail rootEntity = (entityStore.get(rootEntityGUID)); entityList.add(rootEntity); for (String entityGuid : this.graphEntities) { if (!entityGuid.equals(rootEntityGUID)) { entityList.add(this.entityStore.get(entityGuid)); } } for (String relationshipGuid : this.graphRelationships) { relationshipList.add(this.relationshipStore.get(relationshipGuid)); } return new InstanceGraph(entityList, relationshipList); } InMemoryEntityNeighbourhood(OMRSRepositoryHelper      repositoryHelper,
                                String                    repositoryName,
                                OMRSRepositoryValidator   repositoryValidator,
                                Map<String, EntityDetail> entityStore,
                                Map<String, Relationship> relationshipStore,
                                String                    rootEntityGUID,
                                List<String>              entityTypeGUIDs,
                                List<String>              relationshipTypeGUIDs,
                                List<InstanceStatus>      limitResultsByStatus,
                                List<String>              limitResultsByClassification,
                                int                       level);   }