Skip to content

Commit

Permalink
Merge pull request #6606 from alexandra-bucur/fix-overriding-entities
Browse files Browse the repository at this point in the history
Avoid overriding entity details when saving classifications received on entity proxy
  • Loading branch information
mandy-chessell authored Jun 11, 2022
2 parents f4c7009 + ad3a78e commit 5f14e64
Showing 1 changed file with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDef;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefAttribute;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefCategory;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.typedefs.TypeDefGallery;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.repositoryconnector.OMRSRepositoryHelper;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityNotKnownException;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.EntityProxyOnlyException;
Expand Down Expand Up @@ -68,19 +67,17 @@
import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
import static org.apache.tinkerpop.gremlin.process.traversal.P.within;
import static org.apache.tinkerpop.gremlin.process.traversal.P.without;

import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;

import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_CLASSIFICATION_CLASSIFICATION_NAME;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_ENTITY_CURRENT_STATUS;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_ENTITY_GUID;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_ENTITY_IS_PROXY;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_ENTITY_CURRENT_STATUS;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_ENTITY_TYPE_NAME;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_PREFIX_CLASSIFICATION;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_PREFIX_ENTITY;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_PREFIX_RELATIONSHIP;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_RELATIONSHIP_GUID;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_RELATIONSHIP_CURRENT_STATUS;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_RELATIONSHIP_GUID;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_KEY_RELATIONSHIP_TYPE_NAME;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.PROPERTY_NAME_TYPE_NAME;
import static org.odpi.openmetadata.adapters.repositoryservices.graphrepository.repositoryconnector.GraphOMRSConstants.corePropertiesClassification;
Expand Down Expand Up @@ -424,7 +421,7 @@ synchronized void saveEntityReferenceCopyToStore(EntityDetail entity)

/*
* Error condition
* Either the locsl repository is being asked to save a reference copy of something it already owns,
* Either the local repository is being asked to save a reference copy of something it already owns,
* or it already has a proxy or reference copy of an entity from a repository other than the one that
* submitted this reference copy.
*/
Expand Down Expand Up @@ -503,31 +500,29 @@ synchronized void saveEntityReferenceCopyToStore(EntityDetail entity)
* 1) A request to save a reference copy pertains to either creation of a ref copy or update of a ref copy. It would
* be an error if the existing entity has a different metadataCollectionId to the entity to be saved. In this case
* an exception is thrown.
* 2) There may already be a proxy (e.g. from earlier creation of a relationship). Because we are being passed a
* full entity detail to save as a reference copy, the ref copy replaces the proxy. But the reference copy must
* have the same metadataCollectionId as the proxy, else there has been confusion as to who owns the entity
* 2) There may already be an entity, a proxy or a reference copy. Update only its classifications.
*
* In summary
* - if no entity, create the ref copy
* - if existing entity,
* - if its a proxy
* check the metadataCollectionId matches the one passed.
* - if no entity, create the entity as entity proxy
* - if existing entity
* - if it's a proxy
* check the metadataCollectionId matches the one passed (between entities)
* if matching metadataCollectionId
* update the existing entity, replacing the proxy with the ref copy; the proxy flag will be cleared.
* update only its classifications
* else
* error
* - else not a proxy
* if matching metadataCollectionId
* update the existing entity
* if matching metadataCollectionId (between entities)
* update only its classifications
* else
* error
*
* This can be simplified to:
* - if no entity
* create the ref copy
* create the entity as entity proxy
* - if existing entity,
* if matching metadataCollectionId
* update the existing entity, clearing proxy flag if it was set
* if matching metadataCollectionId (between entities)
* update only its classifications
* else
* error
*/
Expand Down Expand Up @@ -563,7 +558,7 @@ synchronized void saveEntityReferenceCopyToStore(EntityProxy entity)

/*
* Error condition
* Either the locsl repository is being asked to save a reference copy of something it already owns,
* Either the local repository is being asked to save a reference copy of something it already owns,
* or it already has a proxy or reference copy of an entity from a repository other than the one that
* submitted this reference copy.
*/
Expand All @@ -585,35 +580,15 @@ synchronized void saveEntityReferenceCopyToStore(EntityProxy entity)
else
{

// No existing vertex found - create one
// No existing vertex found - create one and populate it with the entity proxy data
log.debug("{} create vertex for entity {}", methodName, entity.getGUID());
vertex = g.addV("Entity").next();
entityMapper.mapEntityProxyToVertex(entity, vertex);
}

/*
* Whether this just created a new vertex or is reusing an existing vertex (for a reference copy or proxy),
* populate the vertex.
* The mapping of an entity detail to the vertex will clear the proxy flag, even if previously set.
*/


try
{
entityMapper.mapEntityProxyToVertex(entity, vertex);

// Create a vertex per classification and link them to the entity vertex
List<Classification> classifications = entity.getClassifications();
if (classifications != null)
{
for (Classification classification : classifications)
{
log.debug("{} add classification: {} ", methodName, classification.getName());
Vertex classificationVertex = g.addV("Classification").next();
classificationMapper.mapClassificationToVertex(classification, classificationVertex);
vertex.addEdge("Classifier", classificationVertex);
}
}

updateEntityClassifications(entity, vertex, g);
}
catch (Exception e)
{
Expand Down Expand Up @@ -1437,7 +1412,7 @@ private void updateEntityClassifications(EntitySummary entity,
existingClassifierEdgesByName.remove(existingName);
}
}
// remove from the map - needs to be done outside the previous loop to prevent a ConcurrentModificationExcpetion
// remove from the map - needs to be done outside the previous loop to prevent a ConcurrentModificationException
for (String name : namesToRemoveSet)
{
existingClassificationVerticesByName.remove(name);
Expand Down

0 comments on commit 5f14e64

Please sign in to comment.