@Test public void testGetValues() throws Exception { List<RelationshipType> relationshipTypeList = new ArrayList<>(); List<Relationship> relationshipList = new ArrayList<>(); Relationship relationship = mock(Relationship.class); Item item = mock(Item.class); Entity entity = mock(Entity.class); EntityType entityType = mock(EntityType.class); RelationshipType relationshipType = mock(RelationshipType.class); related.setRelationshipTypeString("LeftwardType"); relationshipTypeList.add(relationshipType); relationshipList.add(relationship); related.setPlace(0); when(item.getID()).thenReturn(UUID.randomUUID()); when(relationshipType.getLeftwardType()).thenReturn("LeftwardType"); when(relationshipType.getLeftType()).thenReturn(entityType); when(entityService.getAllRelationshipTypes(context, entity)).thenReturn(relationshipTypeList); when(entityService.findByItemId(context, item.getID())).thenReturn(entity); when(entityService.getType(context, entity)).thenReturn(entityType); when(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)) .thenReturn(relationshipList); when(relationship.getRelationshipType()).thenReturn(relationshipType); when(relationship.getLeftPlace()).thenReturn(0); when(relationship.getRightItem()).thenReturn(item); assertEquals("TestGetValues 0", virtualMetadataConfiguration.getValues(context, item), related.getValues(context, item)); related.setPlace(1); assertEquals("TestGetValues 1", virtualMetadataConfiguration.getValues(context, item), related.getValues(context, item)); related.setPlace(2); assertEquals("TestGetValues 2", new ArrayList<>(), related.getValues(context, item)); }
@Override public List<String> getValues(Context context, Item item) throws SQLException { Entity entity = entityService.findByItemId(context, item.getID()); EntityType entityType = entityService.getType(context, entity); List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity); List<RelationshipType> possibleRelationshipTypes = new LinkedList<>(); for (RelationshipType relationshipType : relationshipTypes) { if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils .equals(relationshipType.getRightwardType(), relationshipTypeString)) { possibleRelationshipTypes.add(relationshipType); } } List<Relationship> relationships = new LinkedList<>(); for (RelationshipType relationshipType : possibleRelationshipTypes) { relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } for (Relationship relationship : relationships) { if (relationship.getRelationshipType().getLeftType() == entityType) { if (relationship.getLeftPlace() == place) { Item otherItem = relationship.getRightItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } else if (relationship.getRelationshipType().getRightType() == entityType) { if (relationship.getRightPlace() == place) { Item otherItem = relationship.getLeftItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } } return new LinkedList<>(); }
Related implements VirtualMetadataConfiguration { @Override public List<String> getValues(Context context, Item item) throws SQLException { Entity entity = entityService.findByItemId(context, item.getID()); EntityType entityType = entityService.getType(context, entity); List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity); List<RelationshipType> possibleRelationshipTypes = new LinkedList<>(); for (RelationshipType relationshipType : relationshipTypes) { if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils .equals(relationshipType.getRightwardType(), relationshipTypeString)) { possibleRelationshipTypes.add(relationshipType); } } List<Relationship> relationships = new LinkedList<>(); for (RelationshipType relationshipType : possibleRelationshipTypes) { relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } for (Relationship relationship : relationships) { if (relationship.getRelationshipType().getLeftType() == entityType) { if (relationship.getLeftPlace() == place) { Item otherItem = relationship.getRightItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } else if (relationship.getRelationshipType().getRightType() == entityType) { if (relationship.getRightPlace() == place) { Item otherItem = relationship.getLeftItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } } return new LinkedList<>(); } }
Related implements VirtualMetadataConfiguration { @Override public List<String> getValues(Context context, Item item) throws SQLException { Entity entity = entityService.findByItemId(context, item.getID()); EntityType entityType = entityService.getType(context, entity); List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity); List<RelationshipType> possibleRelationshipTypes = new LinkedList<>(); for (RelationshipType relationshipType : relationshipTypes) { if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils .equals(relationshipType.getRightwardType(), relationshipTypeString)) { possibleRelationshipTypes.add(relationshipType); } } List<Relationship> relationships = new LinkedList<>(); for (RelationshipType relationshipType : possibleRelationshipTypes) { relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } for (Relationship relationship : relationships) { if (relationship.getRelationshipType().getLeftType() == entityType) { if (relationship.getLeftPlace() == place) { Item otherItem = relationship.getRightItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } else if (relationship.getRelationshipType().getRightType() == entityType) { if (relationship.getRightPlace() == place) { Item otherItem = relationship.getLeftItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } } return new LinkedList<>(); }  }
Related implements VirtualMetadataConfiguration { @Override public List<String> getValues(Context context, Item item) throws SQLException { Entity entity = entityService.findByItemId(context, item.getID()); EntityType entityType = entityService.getType(context, entity); List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity); List<RelationshipType> possibleRelationshipTypes = new LinkedList<>(); for (RelationshipType relationshipType : relationshipTypes) { if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils .equals(relationshipType.getRightwardType(), relationshipTypeString)) { possibleRelationshipTypes.add(relationshipType); } } List<Relationship> relationships = new LinkedList<>(); for (RelationshipType relationshipType : possibleRelationshipTypes) { relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } for (Relationship relationship : relationships) { if (relationship.getRelationshipType().getLeftType() == entityType) { if (relationship.getLeftPlace() == place) { Item otherItem = relationship.getRightItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } else if (relationship.getRelationshipType().getRightType() == entityType) { if (relationship.getRightPlace() == place) { Item otherItem = relationship.getLeftItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } } return new LinkedList<>(); }  String getRelationshipTypeString(); void setRelationshipTypeString(String relationshipTypeString); Integer getPlace(); void setPlace(Integer place); VirtualMetadataConfiguration getVirtualMetadataConfiguration(); void setVirtualMetadataConfiguration(VirtualMetadataConfiguration
                                                        virtualMetadataConfiguration); @Override void setUseForPlace(boolean useForPlace); @Override boolean getUseForPlace(); @Override void setPopulateWithNameVariant(boolean populateWithNameVariant); @Override boolean getPopulateWithNameVariant(); @Override List<String> getValues(Context context, Item item); }
Related implements VirtualMetadataConfiguration { @Override public List<String> getValues(Context context, Item item) throws SQLException { Entity entity = entityService.findByItemId(context, item.getID()); EntityType entityType = entityService.getType(context, entity); List<RelationshipType> relationshipTypes = entityService.getAllRelationshipTypes(context, entity); List<RelationshipType> possibleRelationshipTypes = new LinkedList<>(); for (RelationshipType relationshipType : relationshipTypes) { if (StringUtils.equals(relationshipType.getLeftwardType(), relationshipTypeString) || StringUtils .equals(relationshipType.getRightwardType(), relationshipTypeString)) { possibleRelationshipTypes.add(relationshipType); } } List<Relationship> relationships = new LinkedList<>(); for (RelationshipType relationshipType : possibleRelationshipTypes) { relationships.addAll(relationshipService.findByItemAndRelationshipType(context, item, relationshipType)); } for (Relationship relationship : relationships) { if (relationship.getRelationshipType().getLeftType() == entityType) { if (relationship.getLeftPlace() == place) { Item otherItem = relationship.getRightItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } else if (relationship.getRelationshipType().getRightType() == entityType) { if (relationship.getRightPlace() == place) { Item otherItem = relationship.getLeftItem(); return virtualMetadataConfiguration.getValues(context, otherItem); } } } return new LinkedList<>(); }  String getRelationshipTypeString(); void setRelationshipTypeString(String relationshipTypeString); Integer getPlace(); void setPlace(Integer place); VirtualMetadataConfiguration getVirtualMetadataConfiguration(); void setVirtualMetadataConfiguration(VirtualMetadataConfiguration
                                                        virtualMetadataConfiguration); @Override void setUseForPlace(boolean useForPlace); @Override boolean getUseForPlace(); @Override void setPopulateWithNameVariant(boolean populateWithNameVariant); @Override boolean getPopulateWithNameVariant(); @Override List<String> getValues(Context context, Item item);  }