@Test void createOrUpdateExternalRelationship_existingRelationship() throws InvalidParameterException, PropertyServerException, UserNotAuthorizedException { final String methodName = "createOrUpdateExternalRelationship"; mockTypeDef(RELATIONSHIP_TYPE_NAME, RELATIONSHIP_TYPE_GUID); Relationship mockedRelationship = mock(Relationship.class); when(mockedRelationship.getGUID()).thenReturn(RELATIONSHIP_GUID); when(repositoryHandler.getRelationshipBetweenEntities(USER, FIRST_GUID, ENTITY_TYPE_NAME, SECOND_GUID, RELATIONSHIP_TYPE_GUID, RELATIONSHIP_TYPE_NAME, methodName)).thenReturn(mockedRelationship); RelationshipDifferences mockedDifferences = mock(RelationshipDifferences.class); when(mockedDifferences.hasInstancePropertiesDifferences()).thenReturn(true); when(repositoryHelper.getRelationshipDifferences(any(), any(), anyBoolean())).thenReturn(mockedDifferences); dataEngineCommonHandler.createOrUpdateExternalRelationship(USER, FIRST_GUID, SECOND_GUID, RELATIONSHIP_TYPE_NAME, ENTITY_TYPE_NAME, EXTERNAL_SOURCE_DE_QUALIFIED_NAME, null); verify(invalidParameterHandler, times(1)).validateUserId(USER, methodName); verify(repositoryHandler, times(0)).createExternalRelationship(USER, RELATIONSHIP_TYPE_GUID, EXTERNAL_SOURCE_DE_GUID, EXTERNAL_SOURCE_DE_QUALIFIED_NAME, FIRST_GUID, SECOND_GUID, null, methodName); verify(repositoryHandler, times(1)).updateRelationshipProperties(USER, RELATIONSHIP_GUID, null, methodName); }
protected void createOrUpdateExternalRelationship(String userId, String firstGUID, String secondGUID, String relationshipTypeName, String firstEntityTypeName, String externalSourceName, InstanceProperties relationshipProperties) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createOrUpdateExternalRelationship"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(firstGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); invalidParameterHandler.validateGUID(secondGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, relationshipTypeName); Optional<Relationship> relationship = Optional.ofNullable(repositoryHandler.getRelationshipBetweenEntities(userId, firstGUID, firstEntityTypeName, secondGUID, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName)); if (!relationship.isPresent()) { String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); repositoryHandler.createExternalRelationship(userId, relationshipTypeDef.getGUID(), externalSourceGUID, externalSourceName, firstGUID, secondGUID, relationshipProperties, methodName); } else { Relationship originalRelationship = relationship.get(); RelationshipDifferences relationshipDifferences = repositoryHelper.getRelationshipDifferences(originalRelationship, buildRelationship(originalRelationship.getGUID(), relationshipProperties), true); if (relationshipDifferences.hasInstancePropertiesDifferences()) { repositoryHandler.updateRelationshipProperties(userId, originalRelationship.getGUID(), relationshipProperties, methodName); } } }
DataEngineCommonHandler { protected void createOrUpdateExternalRelationship(String userId, String firstGUID, String secondGUID, String relationshipTypeName, String firstEntityTypeName, String externalSourceName, InstanceProperties relationshipProperties) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createOrUpdateExternalRelationship"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(firstGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); invalidParameterHandler.validateGUID(secondGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, relationshipTypeName); Optional<Relationship> relationship = Optional.ofNullable(repositoryHandler.getRelationshipBetweenEntities(userId, firstGUID, firstEntityTypeName, secondGUID, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName)); if (!relationship.isPresent()) { String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); repositoryHandler.createExternalRelationship(userId, relationshipTypeDef.getGUID(), externalSourceGUID, externalSourceName, firstGUID, secondGUID, relationshipProperties, methodName); } else { Relationship originalRelationship = relationship.get(); RelationshipDifferences relationshipDifferences = repositoryHelper.getRelationshipDifferences(originalRelationship, buildRelationship(originalRelationship.getGUID(), relationshipProperties), true); if (relationshipDifferences.hasInstancePropertiesDifferences()) { repositoryHandler.updateRelationshipProperties(userId, originalRelationship.getGUID(), relationshipProperties, methodName); } } } }
DataEngineCommonHandler { protected void createOrUpdateExternalRelationship(String userId, String firstGUID, String secondGUID, String relationshipTypeName, String firstEntityTypeName, String externalSourceName, InstanceProperties relationshipProperties) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createOrUpdateExternalRelationship"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(firstGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); invalidParameterHandler.validateGUID(secondGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, relationshipTypeName); Optional<Relationship> relationship = Optional.ofNullable(repositoryHandler.getRelationshipBetweenEntities(userId, firstGUID, firstEntityTypeName, secondGUID, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName)); if (!relationship.isPresent()) { String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); repositoryHandler.createExternalRelationship(userId, relationshipTypeDef.getGUID(), externalSourceGUID, externalSourceName, firstGUID, secondGUID, relationshipProperties, methodName); } else { Relationship originalRelationship = relationship.get(); RelationshipDifferences relationshipDifferences = repositoryHelper.getRelationshipDifferences(originalRelationship, buildRelationship(originalRelationship.getGUID(), relationshipProperties), true); if (relationshipDifferences.hasInstancePropertiesDifferences()) { repositoryHandler.updateRelationshipProperties(userId, originalRelationship.getGUID(), relationshipProperties, methodName); } } } DataEngineCommonHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler,
                                   RepositoryHandler repositoryHandler, OMRSRepositoryHelper repositoryHelper,
                                   DataEngineRegistrationHandler dataEngineRegistrationHandler); }
DataEngineCommonHandler { protected void createOrUpdateExternalRelationship(String userId, String firstGUID, String secondGUID, String relationshipTypeName, String firstEntityTypeName, String externalSourceName, InstanceProperties relationshipProperties) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createOrUpdateExternalRelationship"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(firstGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); invalidParameterHandler.validateGUID(secondGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, relationshipTypeName); Optional<Relationship> relationship = Optional.ofNullable(repositoryHandler.getRelationshipBetweenEntities(userId, firstGUID, firstEntityTypeName, secondGUID, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName)); if (!relationship.isPresent()) { String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); repositoryHandler.createExternalRelationship(userId, relationshipTypeDef.getGUID(), externalSourceGUID, externalSourceName, firstGUID, secondGUID, relationshipProperties, methodName); } else { Relationship originalRelationship = relationship.get(); RelationshipDifferences relationshipDifferences = repositoryHelper.getRelationshipDifferences(originalRelationship, buildRelationship(originalRelationship.getGUID(), relationshipProperties), true); if (relationshipDifferences.hasInstancePropertiesDifferences()) { repositoryHandler.updateRelationshipProperties(userId, originalRelationship.getGUID(), relationshipProperties, methodName); } } } DataEngineCommonHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler,
                                   RepositoryHandler repositoryHandler, OMRSRepositoryHelper repositoryHelper,
                                   DataEngineRegistrationHandler dataEngineRegistrationHandler);  }
DataEngineCommonHandler { protected void createOrUpdateExternalRelationship(String userId, String firstGUID, String secondGUID, String relationshipTypeName, String firstEntityTypeName, String externalSourceName, InstanceProperties relationshipProperties) throws InvalidParameterException, UserNotAuthorizedException, PropertyServerException { final String methodName = "createOrUpdateExternalRelationship"; invalidParameterHandler.validateUserId(userId, methodName); invalidParameterHandler.validateGUID(firstGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); invalidParameterHandler.validateGUID(secondGUID, CommonMapper.GUID_PROPERTY_NAME, methodName); TypeDef relationshipTypeDef = repositoryHelper.getTypeDefByName(userId, relationshipTypeName); Optional<Relationship> relationship = Optional.ofNullable(repositoryHandler.getRelationshipBetweenEntities(userId, firstGUID, firstEntityTypeName, secondGUID, relationshipTypeDef.getGUID(), relationshipTypeDef.getName(), methodName)); if (!relationship.isPresent()) { String externalSourceGUID = dataEngineRegistrationHandler.getExternalDataEngineByQualifiedName(userId, externalSourceName); repositoryHandler.createExternalRelationship(userId, relationshipTypeDef.getGUID(), externalSourceGUID, externalSourceName, firstGUID, secondGUID, relationshipProperties, methodName); } else { Relationship originalRelationship = relationship.get(); RelationshipDifferences relationshipDifferences = repositoryHelper.getRelationshipDifferences(originalRelationship, buildRelationship(originalRelationship.getGUID(), relationshipProperties), true); if (relationshipDifferences.hasInstancePropertiesDifferences()) { repositoryHandler.updateRelationshipProperties(userId, originalRelationship.getGUID(), relationshipProperties, methodName); } } } DataEngineCommonHandler(String serviceName, String serverName, InvalidParameterHandler invalidParameterHandler,
                                   RepositoryHandler repositoryHandler, OMRSRepositoryHelper repositoryHelper,
                                   DataEngineRegistrationHandler dataEngineRegistrationHandler);   }