Skip to content

Commit

Permalink
Detect deleted relationship as fast as possible
Browse files Browse the repository at this point in the history
Signed-off-by: Mandy Chessell <mandy.e.chessell@gmail.com>
  • Loading branch information
mandy-chessell committed Jan 16, 2023
1 parent a8557d0 commit d6a6ddc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ public Relationship isRelationshipKnown(String userId,
List<OMRSRepositoryConnector> cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName);

FederationControl federationControl = new SequentialFederationControl(userId, cohortConnectors, auditLog, methodName);
GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, false, auditLog, methodName);
GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, auditLog, methodName);

/*
* Ready to process the request. Create requests occur in the first repository that accepts the call.
Expand Down Expand Up @@ -1706,7 +1706,7 @@ public Relationship getRelationship(String userId,
List<OMRSRepositoryConnector> cohortConnectors = enterpriseParentConnector.getCohortConnectors(methodName);

FederationControl federationControl = new SequentialFederationControl(userId, cohortConnectors, auditLog, methodName);
GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, true, auditLog, methodName);
GetRelationshipExecutor executor = new GetRelationshipExecutor(userId, guid, auditLog, methodName);

/*
* Ready to process the request. Create requests occur in the first repository that accepts the call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class RelationshipsAccumulator extends QueryInstanceAccumulatorBase
{
private volatile Map<String, Relationship> accumulatedRelationships = new HashMap<>();
private final Map<String, Relationship> accumulatedRelationships = new HashMap<>();


/**
Expand Down Expand Up @@ -108,7 +108,7 @@ public synchronized void addRelationships(List<Relationship> relationships,


/**
* Extract the results - this will the a unique list of relationships selected from the instances
* Extract the results - this will a list of unique relationships selected from the instances
* supplied to this accumulator. It should be called once all the executors have completed processing
* their request(s).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ public EntityDetail getEntityDetail() throws InvalidParameterException,
EntityProxyOnlyException,
UserNotAuthorizedException
{
final String repositoryName = "Enterprise";

EntityDetail entity = this.isEntityKnown(false);

if (entity != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import org.odpi.openmetadata.frameworks.auditlog.AuditLog;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.OMRSMetadataCollection;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.InstanceStatus;
import org.odpi.openmetadata.repositoryservices.connectors.stores.metadatacollectionstore.properties.instances.Relationship;
import org.odpi.openmetadata.repositoryservices.enterprise.repositoryconnector.accumulators.MaintenanceAccumulator;
import org.odpi.openmetadata.repositoryservices.ffdc.OMRSErrorCode;
import org.odpi.openmetadata.repositoryservices.ffdc.exception.*;

import java.util.Date;
Expand All @@ -19,7 +21,7 @@ public class GetRelationshipExecutor extends RepositoryExecutorBase
private final MaintenanceAccumulator accumulator;
private final String relationshipGUID;

private boolean allExceptions = true;

private Date asOfTime = null;
private Relationship retrievedRelationship = null;

Expand All @@ -30,13 +32,11 @@ public class GetRelationshipExecutor extends RepositoryExecutorBase
*
* @param userId unique identifier for requesting user
* @param relationshipGUID unique identifier (guid) for the relationship
* @param allExceptions is the a isRelationshipKnown or getRelationship request
* @param auditLog logging destination
* @param methodName calling method
*/
public GetRelationshipExecutor(String userId,
String relationshipGUID,
boolean allExceptions,
AuditLog auditLog,
String methodName)
{
Expand All @@ -45,7 +45,6 @@ public GetRelationshipExecutor(String userId,
this.accumulator = new MaintenanceAccumulator(auditLog);

this.relationshipGUID = relationshipGUID;
this.allExceptions = allExceptions;
}


Expand Down Expand Up @@ -96,22 +95,11 @@ public boolean issueRequestToRepository(String metadataCollectio
*/
if (asOfTime == null)
{
if (allExceptions)
{
retrievedRelationship = metadataCollection.getRelationship(userId,
relationshipGUID);
}
else
{
retrievedRelationship = metadataCollection.isRelationshipKnown(userId,
relationshipGUID);
}
retrievedRelationship = metadataCollection.isRelationshipKnown(userId, relationshipGUID);
}
else
{
retrievedRelationship = metadataCollection.getRelationship(userId,
relationshipGUID,
asOfTime);
retrievedRelationship = metadataCollection.getRelationship(userId, relationshipGUID, asOfTime);
}
if (retrievedRelationship != null)
{
Expand Down Expand Up @@ -191,12 +179,26 @@ public Relationship getRelationship() throws InvalidParameterException,

if (relationship != null)
{
if (relationship.getStatus() == InstanceStatus.DELETED)
{
throw new RelationshipNotKnownException(OMRSErrorCode.RELATIONSHIP_SOFT_DELETED.getMessageDefinition(relationship.getType().getTypeDefName(),
relationship.getGUID(),
methodName,
repositoryName),
this.getClass().getName(),
methodName);
}

return relationship;
}

accumulator.throwCapturedRelationshipNotKnownException();

return null;
throw new RelationshipNotKnownException(OMRSErrorCode.RELATIONSHIP_NOT_KNOWN.getMessageDefinition(relationshipGUID,
methodName,
repositoryName),
this.getClass().getName(),
methodName);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public abstract class RepositoryExecutorBase implements RepositoryExecutor
{
final String repositoryName = "Enterprise";

protected String methodName;
protected String userId;

Expand Down

0 comments on commit d6a6ddc

Please sign in to comment.