Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #247 from cmgrote/main
Browse files Browse the repository at this point in the history
Fixes for consistency operations
  • Loading branch information
cmgrote authored Oct 8, 2021
2 parents 7824921 + 021c7cb commit 1993eb1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ public EntityProxyMapping(XtdbOMRSRepositoryConnector xtdbConnector,
}

/**
* Map from XTDB to Egeria.
* Map from XTDB to Egeria. NOTE: This method should ONLY be used when you are certain that you have
* only a proxy that you are translating. In general, it is better to use the getFromDoc method which
* will automatically determine whether you have a full entity or only a proxy, and translate either to
* only the proxy representation as-needed. (This method here should really be treated as an internal
* method of this class, and is only public given that it overrides another public method in the parent
* class.)
* @return EntityProxy
* @see #getFromDoc(XtdbOMRSRepositoryConnector, XtdbDocument)
* @see #EntityProxyMapping(XtdbOMRSRepositoryConnector, XtdbDocument)
*/
@Override
Expand Down Expand Up @@ -83,6 +89,8 @@ protected XtdbDocument.Builder toDoc() {
@Override
protected void fromDoc() {
super.fromDoc();
// Note: the following will ONLY work for true proxy objects, not full entities (for full
// entities this will return a full set of properties, not only the unique properties
InstanceProperties uniqueProperties = InstancePropertiesMapping.getFromDoc(xtdbConnector, instanceHeader.getType(), xtdbDoc);
((EntityProxy) instanceHeader).setUniqueProperties(uniqueProperties);
}
Expand All @@ -102,7 +110,6 @@ public static EntityProxy fromMap(IPersistentMap doc) throws IOException, Invali
EntityProxy ep = new EntityProxy();
EntitySummaryMapping.fromMap(ep, doc);
InstanceType entityType = getTypeFromInstance(doc, null);
// TODO: very small risk that this actually retrieves more than just unique properties
InstanceProperties uniqueProperties = InstancePropertiesMapping.getFromMap(entityType, doc);
ep.setUniqueProperties(uniqueProperties);
return ep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ protected AbstractGraphOperation(XtdbOMRSRepositoryConnector xtdb,
this.limitResultsByStatus = limitResultsByStatus;
}

/**
* Create a new search operation.
* @param xtdb connectivity to XTDB
* @param startEntityGUID unique identifier of the starting entity for the traversal
* @param limitResultsByStatus list of statuses by which to limit results
* @param existingDB the already-opened point-in-time from which to retrieve results
*/
protected AbstractGraphOperation(XtdbOMRSRepositoryConnector xtdb,
String startEntityGUID,
List<InstanceStatus> limitResultsByStatus,
IXtdbDatasource existingDB) {
super(xtdb, existingDB);
this.startEntityGUID = startEntityGUID;
this.limitResultsByStatus = limitResultsByStatus;
}

/**
* Find the entities and relationships that radiate out from the supplied entity GUID.
* The results are scoped by the provided type GUIDs, other limiters, and the level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public static EntityProxy proxyByRef(XtdbOMRSRepositoryConnector xtdb, IXtdbData
if (log.isDebugEnabled())
log.debug(Constants.FOUND_RESULTS, xtdbDoc == null ? null : xtdbDoc.toMap());
if (xtdbDoc != null) {
EntityProxyMapping epm = new EntityProxyMapping(xtdb, xtdbDoc);
return epm.toEgeria();
return EntityProxyMapping.getFromDoc(xtdb, xtdbDoc);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,31 @@ public class DeleteEntity extends DeleteInstance {
private static final String METHOD_NAME = FUNCTION_NAME.toString();

// Query to retrieve all non-deleted relationships that point to this entity,
// including their metadataCollectionId (mid)
// (mixed quoting is necessary to ensure the eid is evaluated, so it becomes first in the join
// ordering of the query for performance reasons)
private static final String RELN_QUERY = "" +
"(quote {:find [r mid]" +
" :where [[r :" + RelationshipMapping.ENTITY_PROXIES + " e]" +
" [r :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]" +
" [r :" + InstanceAuditHeaderMapping.CURRENT_STATUS + " s]" +
" [(not= s " + InstanceStatus.DELETED.getOrdinal() + ")]" +
" [r :" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + " mid]]" +
" :in [e]})";
"{:find [(quote r)]" +
" :where [[(quote r) :" + RelationshipMapping.ENTITY_PROXIES + " eid]" +
" [(quote r) :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]" +
" [(quote r) :" + InstanceAuditHeaderMapping.CURRENT_STATUS + " (quote s)]" +
" [(quote (not= s " + InstanceStatus.DELETED.getOrdinal() + "))]]}";

private static final String FN = "" +
"(fn [ctx eid user] " +
" (let [db (xtdb.api/db ctx)" +
" tx-id (:tx-id db)" +
" relationships (xtdb.api/q db " + RELN_QUERY + " eid)" +
" relationships (xtdb.api/q db " + RELN_QUERY + ")" +
" existing (xtdb.api/entity db eid)" +
" deleted (.doc (" + DeleteEntity.class.getCanonicalName() + ". tx-id existing user eid))" +
getTxnTimeCalculation("deleted") + "]" +
// For each of the relationships that was found, check the metadataCollectionId of it to determine
// whether to delete the relationship (homed in this repo, same as entity) or to purge it (reference copy)
// by delegating to the appropriate transaction function for those operations
" (conj (vec (for [[rid mid] relationships]" +
" (let [home (get existing :" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + ")]" +
" (if (= home mid)" +
//" (conj (vec (for [[rid mid] relationships]" +
" (conj (vec (for [[rid] relationships]" +
" (let [home (get existing :" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + ")" +
" mid (xtdb.api/pull db [:" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + "] rid)]" +
" (if (= home (:" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + " mid))" +
" [:xtdb.api/fn " + DeleteRelationship.FUNCTION_NAME + " rid user]" +
" [:xtdb.api/fn " + PurgeRelationship.FUNCTION_NAME + " rid true]))))" +
// And of course also persist the soft-deleted entity itself as part of this transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public class PurgeEntity extends AbstractTransactionFunction {

// Query to retrieve ALL relationships that point to this entity, irrespective of status or
// home repository
// (mixed quoting is necessary to ensure the eid is evaluated, so it becomes first in the join
// ordering of the query for performance reasons)
private static final String RELN_QUERY = "" +
"(quote {:find [r]" +
" :where [[r :" + RelationshipMapping.ENTITY_PROXIES + " e]" +
" [r :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]]" +
" :in [e]})";
"{:find [(quote r)]" +
" :where [[(quote r) :" + RelationshipMapping.ENTITY_PROXIES + " eid]" +
" [(quote r) :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]]}";

private static final String FN = "" +
"(fn [ctx eid force] " +
" (let [db (xtdb.api/db ctx)" +
" tx-id (:tx-id db)" +
" relationships (xtdb.api/q db " + RELN_QUERY + " eid)" +
" relationships (xtdb.api/q db " + RELN_QUERY + ")" +
" existing (xtdb.api/entity db eid)" +
" deleted (.doc (" + PurgeEntity.class.getCanonicalName() + ". tx-id existing eid force))]" +
// For each of the relationships that was found, delegate to the purge transaction function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ public class ReIdentifyEntity extends ReIdentifyInstance {
private static final String METHOD_NAME = FUNCTION_NAME.toString();

// Query to retrieve all homed relationships that have this entity as one of their endpoints
// (mixed quoting is necessary to ensure the eid is evaluated, so it becomes first in the join
// ordering of the query for performance reasons)
private static final String RELN_QUERY = "" +
"(quote {:find [r]" +
" :where [[r :" + RelationshipMapping.ENTITY_PROXIES + " e]" +
" [r :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]" +
" [r :" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + " mid]]" +
" :in [e mid]})";
"{:find [(quote r)]" +
" :where [[(quote r) :" + RelationshipMapping.ENTITY_PROXIES + " eid]" +
" [(quote r) :" + InstanceAuditHeaderMapping.TYPE_DEF_CATEGORY + " " + TypeDefCategory.RELATIONSHIP_DEF.getOrdinal() + "]" +
" [(quote r) :" + InstanceAuditHeaderMapping.METADATA_COLLECTION_ID + " mid]]}";

private static final String FN = "" +
"(fn [ctx eid user nid mid] " +
" (let [db (xtdb.api/db ctx)" +
" tx-id (:tx-id db)" +
" relationships (xtdb.api/q db " + RELN_QUERY + " eid mid)" +
" relationships (xtdb.api/q db " + RELN_QUERY + ")" +
" existing (xtdb.api/entity db eid)" +
" updates (.tuple (" + ReIdentifyEntity.class.getCanonicalName() + ". tx-id existing user eid nid mid))]" +
" (vec (concat (vec (for [[rid] relationships]" +
Expand Down

0 comments on commit 1993eb1

Please sign in to comment.