From 22d0e4f4a8798524e6261058d46b7fa843709bc9 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Mon, 24 Sep 2012 16:22:21 -0700 Subject: [PATCH] CSPACE-5540: Relationships in relations-payloads to structured objects only differing by relationship metatypes are now considered new relationships by the handleRelations code. This means that the old identical relationships are deleted and new ones with the updated relationship metatype are created in their place. --- .../collectionobject-hierarchy-csid.xml | 65 ++++++++++++++----- .../java/RemoteDocumentModelHandlerImpl.java | 16 +++-- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy-csid.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy-csid.xml index b9c62eff2..173931fb6 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy-csid.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/collectionobject/collectionobject-hierarchy-csid.xml @@ -234,6 +234,55 @@ 200 + + + + GET + /cspace-services/relations?sbj=${CreateBlackRook.CSID}&obj=${CreateBagOfBlackChessPieces.CSID} + 200 + + + collectionobject/hierarchy/res/relationship-metatype.res.xml + + ${UpdateBlackRookWithRelations.relationshipMetaType} + ${CreateBagOfBlackChessPieces.CSID} + ${CreateBlackRook.CSID} + + + + + + + PUT + /cspace-services/collectionobjects/${CreateBlackRook.CSID} + collectionobject/hierarchy/4-collectionobject-update-with-parent-child-csids.xml + + This black rook is nearly intact, save for two tiny fragments. + ${CreateBlackRook.CSID} + ${CreateBagOfBlackChessPieces.CSID} + ${CreateBlackRookFragment1.CSID} + ${CreateBlackRookFragment2.CSID} + derivative + + 200 + + + + + + GET + /cspace-services/relations?sbj=${CreateBlackRook.CSID}&obj=${CreateBagOfBlackChessPieces.CSID} + 200 + + + collectionobject/hierarchy/res/relationship-metatype.res.xml + + ${UpdateBlackRooksRelationsWithDiffMetatype.relationshipMetaType} + ${CreateBagOfBlackChessPieces.CSID} + ${CreateBlackRook.CSID} + + + - - - GET - /cspace-services/relations?sbj=${CreateBlackQueen.CSID}&obj=${CreateBagOfBlackChessPieces.CSID} - 200 - - - collectionobject/hierarchy/res/relationship-metatype.res.xml - - ${CreateBagOfBlackChessPieces.relationshipMetaType} - ${CreateBagOfBlackChessPieces.CSID} - ${CreateBlackQueen.CSID} - - - diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index fa70a28f6..5af6540c6 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -104,6 +104,7 @@ public abstract class RemoteDocumentModelHandlerImpl /** The logger. */ private final Logger logger = LoggerFactory.getLogger(RemoteDocumentModelHandlerImpl.class); private final static String CR = "\r\n"; + private final static String EMPTYSTR = ""; /* (non-Javadoc) * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#setServiceContext(org.collectionspace.services.common.context.ServiceContext) @@ -1082,6 +1083,7 @@ public abstract class RemoteDocumentModelHandlerImpl RelationsDocListItem subj2 = item2.getSubject(); RelationsDocListItem obj1 = item1.getObject(); RelationsDocListItem obj2 = item2.getObject(); + String subj1Csid = subj1.getCsid(); String subj2Csid = subj2.getCsid(); String subj1RefName = subj1.getRefName(); @@ -1091,16 +1093,22 @@ public abstract class RemoteDocumentModelHandlerImpl String obj2Csid = obj2.getCsid(); String obj1RefName = obj1.getRefName(); String obj2RefName = obj2.getRefName(); - - boolean isEqual = - (subj1Csid.equals(subj2Csid) || ((subj2Csid==null) && subj1RefName.equals(subj2RefName))) + + String item1Metatype = item1.getRelationshipMetaType(); + item1Metatype = item1Metatype != null ? item1Metatype : EMPTYSTR; + + String item2Metatype = item2.getRelationshipMetaType(); + item2Metatype = item2Metatype != null ? item2Metatype : EMPTYSTR; + + boolean isEqual = (subj1Csid.equals(subj2Csid) || ((subj2Csid==null) && subj1RefName.equals(subj2RefName))) && (obj1Csid.equals(obj1Csid) || ((obj2Csid==null) && obj1RefName.equals(obj2RefName))) // predicate is proper, but still allow relationshipType && (item1.getPredicate().equals(item2.getPredicate()) || ((item2.getPredicate()==null) && item1.getRelationshipType().equals(item2.getRelationshipType()))) // Allow missing docTypes, so long as they do not conflict && (obj1.getDocumentType().equals(obj2.getDocumentType()) || obj2.getDocumentType()==null) - && (subj1.getDocumentType().equals(subj2.getDocumentType()) || subj2.getDocumentType()==null); + && (subj1.getDocumentType().equals(subj2.getDocumentType()) || subj2.getDocumentType()==null) + && (item1Metatype.equalsIgnoreCase(item2Metatype)); return isEqual; } -- 2.47.3