From: Laramie Crocker Date: Tue, 19 Apr 2011 04:59:21 +0000 (+0000) Subject: CSPACE-3725 from trunk. Adds extra detail to calculated/looked up fields in Relation... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=1ea47b1ce34ae86eec7308beb36b35978fdfaf81;p=tmp%2Fjakarta-migration.git CSPACE-3725 from trunk. Adds extra detail to calculated/looked up fields in Relation list item, useful also for debugging (but not committed on branch 1.6) issues like CSPACE-3780 --- diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml index d9742dcda..6e6303ccf 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml @@ -62,10 +62,13 @@ - + + + + --> - + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml index f298ae509..e911c554b 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml @@ -153,7 +153,7 @@ - + PUT /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} person/persons_common_w_relations.xml @@ -167,7 +167,64 @@ - + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + + + + PUT + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} + person/persons_common_w_relations_2.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + ${Person1.CSID} + ${PersonParent.CSID} + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + + + + + PUT + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} + person/persons_common_w_relations.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + ${Person1.CSID} + ${PersonParent.CSID} + ${PersonChild.CSID} + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + + + + PUT + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} + person/persons_common_w_relations_3.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + ${Person1.CSID} + ${PersonChild.CSID} + ${PersonChild2.CSID} + + + + GET /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml index 988d7fd5c..f4be7468d 100755 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml @@ -38,12 +38,12 @@ ${parentCSID} ${myCSID} - Person + Person John Wayne, Me ${parentCSID} - Person + Person John Wayne 2, the evil twin, Parent @@ -57,12 +57,12 @@ ${myCSID} ${childCSID} - Person + Person John Wayne 2, the evil twin, child ${myCSID} - Person + Person John Wayne diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_2.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_2.xml new file mode 100755 index 000000000..85f01c6de --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_2.xml @@ -0,0 +1,55 @@ + + + + ${inAuthority} + ${shortIdentifier} + urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne' + John Wayne + false + JohnWayne + false + John + Wayne + May 26, 1907 + June 11, 1979 + Winterset, Iowa + + Irish + Scottish + + male + born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive + voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. + + + + 0 + 40 + 1 + 1 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + ${myCSID} + Person + Person + hasBroader + hasBroader + hasBroader + ${parentCSID} + + ${myCSID} + Person + John Wayne, Me + + + ${parentCSID} + Person + John Wayne 2, the evil twin, Parent + + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_3.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_3.xml new file mode 100755 index 000000000..37916fa93 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_3.xml @@ -0,0 +1,74 @@ + + + + ${inAuthority} + ${shortIdentifier} + urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne' + John Wayne + false + JohnWayne + false + John + Wayne + May 26, 1907 + June 11, 1979 + Winterset, Iowa + + Irish + Scottish + + male + born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive + voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. + + + + 0 + 40 + 1 + 1 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + ${childCSID} + Person + Person + hasBroader + hasBroader + hasBroader + ${myCSID} + + ${childCSID} + Person + John Wayne 2, the evil twin, child + + + ${myCSID} + Person + John Wayne + + + + ${child2CSID} + Person + Person + hasBroader + hasBroader + hasBroader + ${myCSID} + + ${child2CSID} + Person + John Wayne 2, the evil twin, child + + + ${myCSID} + Person + John Wayne + + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml index d81763611..70d3d1535 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml @@ -23,8 +23,8 @@ ${oe1.CSID} ${oe2.CSID} - ObjectExit - ObjectExit + objectexit + objectexit hasBroader @@ -36,8 +36,8 @@ ${oe2.CSID} ${oe1.CSID} - ObjectExit - ObjectExit + objectexit + objectexit hasBroader diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index db893dcd2..eb5a0511c 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -24,7 +24,10 @@ package org.collectionspace.services.common.vocabulary.nuxeo; import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.ListIterator; import java.util.Map; import org.collectionspace.services.client.PayloadInputPart; @@ -33,6 +36,7 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.RelationClient; //import org.collectionspace.services.common.authority.AuthorityItemRelations; +import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentWrapper; @@ -47,6 +51,8 @@ import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationsDocListItem; import org.collectionspace.services.relation.RelationshipType; import org.nuxeo.ecm.core.api.DocumentModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; @@ -60,6 +66,8 @@ import javax.ws.rs.core.UriInfo; public abstract class AuthorityItemDocumentModelHandler extends RemoteDocumentModelHandlerImpl { + private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class); + private String authorityItemCommonSchemaName; //private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class); @@ -225,6 +233,22 @@ public abstract class AuthorityItemDocumentModelHandler } //=================================================================== + /* + for (RelationsCommonList.RelationListItem parentListItem : parentList.getRelationListItem()) { + System.out.println(" parentListItems " + parentListItem); + //todo: if num-parents > 1 then complain. + //todo: if not found in update list, remove from system + //todo: if update list item not found in parent list, add to system. + } + for (RelationsCommonList.RelationListItem childListItem : childList.getRelationListItem()) { + System.out.println(" childListItem: " + childListItem); + //todo: if not found in update list, remove from system + //todo: if update list item not found in child list, add to system. + } + + + + */ public RelationsCommonList updateRelations(String itemCSID, PoxPayloadIn input) throws Exception { PayloadInputPart part = input.getPart(RelationClient.SERVICE_COMMON_LIST_NAME); //input.getPart("relations_common"); if (part == null) { @@ -242,43 +266,132 @@ public abstract class AuthorityItemDocumentModelHandler queryParams.putSingle(IRelationsManager.OBJECT_QP, itemCSID); queryParams.putSingle(IRelationsManager.OBJECT_TYPE_QP, null); - RelationsCommonList childList = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. - for (RelationsCommonList.RelationListItem childListItem : childList.getRelationListItem()) { - // System.out.println(" childListItem: " + childListItem); - //todo: if not found in update list, remove from system - //todo: if update list item not found in child list, add to system. - } + RelationsCommonList childListOuter = (new RelationResource()).getList(ctx.getUriInfo()); //magically knows all query params because they are in the context. //Leave predicate, swap subject and object. + queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate); queryParams.putSingle(IRelationsManager.SUBJECT_QP, itemCSID); queryParams.putSingle(IRelationsManager.OBJECT_QP, null); - RelationsCommonList parentList = (new RelationResource()).getList(ctx.getUriInfo()); - for (RelationsCommonList.RelationListItem parentListItem : parentList.getRelationListItem()) { - // System.out.println(" parentListItem: " + parentListItem); - //todo: if num-parents > 1 then complain. - //todo: if not found in update list, remove from system - //todo: if update list item not found in parent list, add to system. - } + RelationsCommonList parentListOuter = (new RelationResource()).getList(ctx.getUriInfo()); + /* + go through inboundList, remove anything from childList that matches from childList + go through inboundList, remove anything from parentList that matches from parentList + go through parentList, delete all remaining + go through childList, delete all remaining + go through actionList, add all remaining. + check for duplicate children + check for more than one parent. + + inboundList parentList childList actionList + ---------------- --------------- ---------------- ---------------- + child-a parent-c child-a child-b + child-b parent-d child-c + parent-a + */ + String HAS_BROADER = RelationshipType.HAS_BROADER.value(); + List inboundList = relationsCommonListBody.getRelationListItem(); - for (RelationsCommonList.RelationListItem item : inboundList) { + List actionList = newList(); + List childList = childListOuter.getRelationListItem(); + List parentList = parentListOuter.getRelationListItem(); + + for (RelationsCommonList.RelationListItem inboundItem : inboundList) { + if (inboundItem.getObjectCsid().equals(itemCSID) && inboundItem.getPredicate().equals(HAS_BROADER)){ + //then this is an item that says we have a child. + RelationsCommonList.RelationListItem childItem = findInList(childList, inboundItem); + if (childItem != null){ + removeFromList(childList, childItem); //exists, just take it off delete list + } else { + actionList.add(inboundItem); //doesn't exist as a child, but is a child. Add to additions list + } + } else if (inboundItem.getSubjectCsid().equals(itemCSID) && inboundItem.getPredicate().equals(HAS_BROADER)) { + //then this is an item that says we have a parent + RelationsCommonList.RelationListItem parentItem = findInList(parentList, inboundItem); + if (parentItem != null){ + removeFromList(parentList, parentItem); //exists, just take it off delete list + } else { + actionList.add(inboundItem); //doesn't exist as a parent, but is a parent. Add to additions list + } + } else { + System.out.println("\r\n\r\n================\r\n Element didn't match parent or child, but may have partial fields that match. inboundItem: "+inboundItem); + //not dealing with: hasNarrower or any other predicate. + + } + } + deleteRelations(parentList, ctx); + deleteRelations(childList, ctx); + createRelations(actionList, ctx); + + return relationsCommonListBody; + } + + private void createRelations(List inboundList, ServiceContext ctx){ + for (RelationsCommonList.RelationListItem item : inboundList) { RelationsCommon rc = new RelationsCommon(); - rc.setCsid(item.getCsid()); + //rc.setCsid(item.getCsid()); rc.setDocumentId1(item.getSubjectCsid()); rc.setDocumentId2(item.getObjectCsid()); rc.setRelationshipType(item.getPredicate()); //todo: is an enum: rc.setPredicate(item.getPredicate()); - rc.setDocumentType1(item.getSubject().getType()); - rc.setDocumentType2(item.getObject().getType()); + rc.setDocumentType1(item.getSubject().getDocumentType()); + rc.setDocumentType2(item.getObject().getDocumentType()); PoxPayloadOut payloadOut = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME); PayloadOutputPart outputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMONPART_NAME, rc); payloadOut.addPart(outputPart); - + System.out.println("\r\n==== TO CREATE: "+rc.getDocumentId1()+"==>"+rc.getPredicate()+"==>"+rc.getDocumentId2()); RelationResource relationResource = new RelationResource(); Object res = relationResource.create(ctx.getUriInfo(), payloadOut.toXML()); //NOTE ui recycled from above to pass in unknown query params. } - return relationsCommonListBody; + } + private void deleteRelations(List list,ServiceContext ctx){ + try { + for (RelationsCommonList.RelationListItem inboundItem : list) { + RelationResource relationResource = new RelationResource(); + System.out.println("\r\n==== TO DELETE: "+inboundItem.getCsid()); + Object res = relationResource.delete(inboundItem.getCsid()); + } + } catch (Throwable t){ + String msg = "Unable to deleteRelations: "+ Tools.errorToString(t, true); + logger.error(msg); + } + } + + private List newList(){ + List result = new ArrayList(); + return result; + } + protected List cloneList(List inboundList){ + List result = newList(); + for (RelationsCommonList.RelationListItem item: inboundList){ + result.add(item); + } + return result; + } + private RelationsCommonList.RelationListItem findInList(List list, RelationsCommonList.RelationListItem item){ + for (RelationsCommonList.RelationListItem listItem : list) { + if (itemsEqual(listItem, item)){ //equals must be defined, else + return listItem; + } + } + return null; + } + + private boolean itemsEqual(RelationsCommonList.RelationListItem item, RelationsCommonList.RelationListItem item2){ + if (item==null || item2==null){ + return false; + } + return (item.getSubjectCsid().equals(item2.getSubjectCsid())) + && (item.getObjectCsid().equals(item2.getObjectCsid())) + && ( (item.getPredicate().equals(item2.getPredicate())) + && (item.getRelationshipType().equals(item2.getRelationshipType())) ) + && (item.getObject().getDocumentType().equals(item2.getObject().getDocumentType())) + && (item.getSubject().getDocumentType().equals(item2.getSubject().getDocumentType())) ; + } + + private void removeFromList(List list, RelationsCommonList.RelationListItem item){ + list.remove(item); } //================= TODO: move this to common, refactoring this and CollectionObjectResource.java diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index b4b8ff4ee..eb8e399f3 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -24,6 +24,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MultivaluedMap; import org.collectionspace.services.client.IQueryManager; @@ -730,6 +731,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient - + + + + diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index 3996c8ec3..c17d4379d 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -157,34 +157,38 @@ public class RelationDocumentModelHandler //Now fill in summary info for the related docs: subject and object. String subjectCsid = relationListItem.getSubjectCsid(); - RelationsDocListItem subject = createRelationsDocListItem(ctx, sbt, subjectCsid, tReader); + String documentType = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_1); + RelationsDocListItem subject = createRelationsDocListItem(ctx, sbt, subjectCsid, tReader, documentType); relationListItem.setSubject(subject); String objectCsid = relationListItem.getObjectCsid(); - RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader); + documentType = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_2); + RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader, documentType); relationListItem.setObject(object); return relationListItem; } + // DocumentModel itemDocModel = docModelFromCSID(ctx, itemCsid); + protected RelationsDocListItem createRelationsDocListItem(ServiceContext ctx, ServiceBindingType sbt, String itemCsid, - TenantBindingConfigReaderImpl tReader) throws Exception { + TenantBindingConfigReaderImpl tReader, + String documentType) throws Exception { RelationsDocListItem item = new RelationsDocListItem(); - // DocumentModel itemDocModel = docModelFromCSID(ctx, itemCsid); + item.setDocumentType(documentType);//this one comes from the record, as documentType1, documentType2. + item.setService(documentType);//this one comes from the record, as documentType1, documentType2. Current app seems to use servicename for this. + item.setCsid(itemCsid); + DocumentModel itemDocModel = NuxeoUtils.getDocFromCsid(getRepositorySession(), ctx, itemCsid); //null if not found. if (itemDocModel!=null){ String itemDocType = itemDocModel.getDocumentType().getName(); + item.setDocumentTypeFromModel(itemDocType); //this one comes from the nuxeo documentType //TODO: ensure that itemDocType is really the entry point, i.e. servicename==doctype - //ServiceBindingType itemSbt = tReader.getServiceBinding(ctx.getTenantId(), itemDocType); + //ServiceBindingType itemSbt2 = tReader.getServiceBinding(ctx.getTenantId(), itemDocType); ServiceBindingType itemSbt = tReader.getServiceBindingForDocType(ctx.getTenantId(), itemDocType); - //String bar = "\r\n=======================\r\n"; - //System.out.println(bar+"itemDocType: "+itemDocType); - //System.out.println(bar+"ServiceBindingType: "+itemSbt); - //System.out.println(bar); - try { String itemDocname = ServiceBindingUtils.getMappedFieldInDoc(itemSbt, ServiceBindingUtils.OBJ_NAME_PROP, itemDocModel); item.setName(itemDocname); @@ -199,9 +203,9 @@ public class RelationDocumentModelHandler } catch (Throwable t){ System.out.println("\r\n\r\n\r\n=================\r\n NOTE: field "+ServiceBindingUtils.OBJ_NUMBER_PROP+" not found in DocModel: "+itemDocModel.getName()+" inner: "+t.getMessage()); } - item.setType(itemDocType); + } else { + item.setError("INVALID: related object is absent"); } - item.setCsid(itemCsid); return item; }