From: Laramie Crocker Date: Thu, 21 Apr 2011 08:48:01 +0000 (+0000) Subject: CSPACE-3739 Updated schema, query paramters, POST behavior, and chaining of ServiceCo... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=053d0e4739fbf3d09e9383fc75ddc2ea0cf5aa92;p=tmp%2Fjakarta-migration.git CSPACE-3739 Updated schema, query paramters, POST behavior, and chaining of ServiceContext impls handling of ctx-ui-queryParameters, after 4-20-2011 meeting with layer leads. --- diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java index 89807bf87..ae1a9178e 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplay.java @@ -562,7 +562,7 @@ public class XmlReplay { for (Node testgroup : testgroupNodes) { - JexlContext jc = new MapContext(); //Get a new JexlContext for each test group. + XmlReplayEval.MapContextWKeys jc = new XmlReplayEval.MapContextWKeys();//MapContext(); //Get a new JexlContext for each test group. evalStruct.jc = jc; autoDeletePOSTS = testgroup.valueOf("@autoDeletePOSTS"); diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java index a9ece6858..2662413b2 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayEval.java @@ -25,8 +25,12 @@ package org.collectionspace.services.IntegrationTests.xmlreplay; import org.apache.commons.jexl2.Expression; import org.apache.commons.jexl2.JexlContext; import org.apache.commons.jexl2.JexlEngine; +import org.apache.commons.jexl2.MapContext; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Set; /** * User: laramie @@ -113,8 +117,8 @@ public class XmlReplayEval { Object resultObj = expr.evaluate(jc); String resultStr; if (null == resultObj){ - resultStr = "ERROR"; - System.out.println("Jexl context: "+jc.toString()); + //debug: System.out.println("null found while evaluationg variable: '"+var+"' Jexl context: "+dumpContext(jc)); + resultStr = "${"+var+"}"; } else { resultStr = resultObj.toString(); @@ -124,4 +128,23 @@ public class XmlReplayEval { return result.toString(); } + protected static String dumpContext(JexlContext jc){ + String result = ""; + if (jc instanceof MapContextWKeys){ + Set keys = ((MapContextWKeys)jc).getKeys(); + result = keys.toString(); + } else { + result = jc.toString(); + } + return result; + } + + public static class MapContextWKeys extends MapContext implements JexlContext { + private Map map = new HashMap(); + public Set getKeys(){ + return this.map.keySet(); + } + } + + } 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 6e6303ccf..dfd9c1c4b 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 @@ -66,8 +66,14 @@ - + + + + + + --> + 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 e911c554b..e26e11267 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 @@ -169,7 +169,7 @@ GET - /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true @@ -187,7 +187,7 @@ GET - /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true @@ -207,7 +207,7 @@ GET - /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true @@ -226,7 +226,74 @@ GET - /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true + + !-- ========================= POST a person ===================================================== --> + + + + POST + /cspace-services/personauthorities/ + person/personauthorities_common.xml + + CSPACE3739PersonAuthority + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorParent + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorChild + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorChild2 + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common_w_relations_POST.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + ${itemCSID} + ${PersonParent.CSID} + ${PersonChild.CSID} + ${PersonChild2.CSID} + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml new file mode 100755 index 000000000..7d75d8be4 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_POST.xml @@ -0,0 +1,73 @@ + + + + ${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 + + hasBroader + + ${itemCSID} + Person + John Wayne, Me + + + ${parentCSID} + Person + John Wayne 2, the evil twin, Parent + + + + hasBroader + + ${childCSID} + Person + John Wayne 2, the evil twin, child + + + ${itemCSID} + Person + John Wayne + + + + hasBroader + + ${child2CSID} + Person + John Wayne 2, the evil twin, child + + + ${itemCSID} + Person + John Wayne + + + + + + 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 eb5a0511c..6ca1012de 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 @@ -36,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.CommonAPI; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; @@ -54,6 +55,7 @@ import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.management.relation.Relation; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; @@ -198,16 +200,32 @@ public abstract class AuthorityItemDocumentModelHandler throws Exception { MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); super.extractAllParts(wrapDoc); - - String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); - - //TODO: add broader, etc. here. - String predicate = RelationshipType.HAS_BROADER.value(); - RelationsCommonList relationsCommonList = getRelations(thisCSID, null, predicate); - if (relationsCommonList.getTotalItems() == 0){ - relationsCommonList = getRelations(null, thisCSID, predicate); //for development... try switching subject and object. This is not correct, though. + String showRelations = ctx.getQueryParams().getFirst(CommonAPI.showRelations_QP); + if (!Tools.isTrue(showRelations)){ + return; + } + String thisCSID = NuxeoUtils.getCsid(wrapDoc.getWrappedObject()); + + String predicate = RelationshipType.HAS_BROADER.value(); + RelationsCommonList parentListOuter = getRelations(thisCSID, null, predicate); + List parentList = parentListOuter.getRelationListItem(); + + RelationsCommonList childrenListOuter = getRelations(null, thisCSID, predicate); + List childrenList = childrenListOuter.getRelationListItem(); + + //Assume that there are more children than parents. Will be true for parent/child, but maybe not for other relations. + //Now add all parents to our childrenList, to be able to return just one list of consolidated results. + //Not optimal, but that's the current design spec. + long added = 0; + for (RelationsCommonList.RelationListItem parent : parentList) { + childrenList.add(parent); + added++; } - PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, relationsCommonList); + long childrenSize = childrenList.size(); + childrenListOuter.setTotalItems(childrenSize); + childrenListOuter.setItemsInPage(childrenListOuter.getItemsInPage()+added); + + PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, childrenListOuter); ctx.addOutputPart(relationsPart); } @@ -252,14 +270,16 @@ public abstract class AuthorityItemDocumentModelHandler 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) { - System.out.println("Nothing to do in updateRelations: " + input); + //System.out.println("Nothing to do in updateRelations: " + input); return null; } RelationsCommonList relationsCommonListBody = (RelationsCommonList) part.getBody(); ServiceContext ctx = getServiceContext(); - MultivaluedMap queryParams = ctx.getQueryParams(); - String predicate = RelationshipType.HAS_BROADER.value(); + UriInfo uriInfo = ctx.getUriInfo(); + MultivaluedMap queryParams = uriInfo.getQueryParameters(); + + String predicate = RelationshipType.HAS_BROADER.value(); queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate); queryParams.putSingle(IRelationsManager.SUBJECT_QP, null); queryParams.putSingle(IRelationsManager.SUBJECT_TYPE_QP, null); @@ -297,7 +317,15 @@ public abstract class AuthorityItemDocumentModelHandler List parentList = parentListOuter.getRelationListItem(); for (RelationsCommonList.RelationListItem inboundItem : inboundList) { - if (inboundItem.getObjectCsid().equals(itemCSID) && inboundItem.getPredicate().equals(HAS_BROADER)){ + if (inboundItem.getObject().getCsid().equalsIgnoreCase(CommonAPI.AuthorityItemCSID_REPLACE)){ + inboundItem.setObjectCsid(itemCSID); + inboundItem.getObject().setCsid(itemCSID); + } + if (inboundItem.getSubject().getCsid().equalsIgnoreCase(CommonAPI.AuthorityItemCSID_REPLACE)){ + inboundItem.setSubjectCsid(itemCSID); + inboundItem.getSubject().setCsid(itemCSID); + } + if (inboundItem.getObject().getCsid().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){ @@ -305,7 +333,7 @@ public abstract class AuthorityItemDocumentModelHandler } 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)) { + } else if (inboundItem.getSubject().getCsid().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){ @@ -314,12 +342,12 @@ public abstract class AuthorityItemDocumentModelHandler 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(parentList, ctx); //todo: there are items appearing on both lists....april 20. deleteRelations(childList, ctx); createRelations(actionList, ctx); @@ -328,19 +356,27 @@ public abstract class AuthorityItemDocumentModelHandler private void createRelations(List inboundList, ServiceContext ctx){ for (RelationsCommonList.RelationListItem item : inboundList) { - RelationsCommon rc = new RelationsCommon(); - //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().getDocumentType()); - rc.setDocumentType2(item.getObject().getDocumentType()); + RelationsCommon rc = new RelationsCommon(); + //rc.setCsid(item.getCsid()); + String itemCsid = item.getSubject().getCsid(); + rc.setDocumentId1(itemCsid); + rc.setSubjectCsid(itemCsid); + + String objCsid = item.getObject().getCsid(); + rc.setDocumentId2(objCsid); + rc.setObjectCsid(objCsid); + + rc.setRelationshipType(item.getPredicate()); + //RelationshipType foo = (RelationshipType.valueOf(item.getPredicate())) ; + //rc.setPredicate(foo); + + 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()); + //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. } @@ -349,7 +385,7 @@ public abstract class AuthorityItemDocumentModelHandler try { for (RelationsCommonList.RelationListItem inboundItem : list) { RelationResource relationResource = new RelationResource(); - System.out.println("\r\n==== TO DELETE: "+inboundItem.getCsid()); + //System.out.println("\r\n==== TO DELETE: "+inboundItem.getCsid()); Object res = relationResource.delete(inboundItem.getCsid()); } } catch (Throwable t){ @@ -382,12 +418,17 @@ public abstract class AuthorityItemDocumentModelHandler if (item==null || item2==null){ return false; } - return (item.getSubjectCsid().equals(item2.getSubjectCsid())) - && (item.getObjectCsid().equals(item2.getObjectCsid())) + RelationsDocListItem subj1 = item.getSubject(); + RelationsDocListItem subj2 = item2.getSubject(); + RelationsDocListItem obj1 = item.getObject(); + RelationsDocListItem obj2 = item2.getObject(); + + return (subj1.getCsid().equals(subj2.getCsid())) + && (obj1.getCsid().equals(obj1.getCsid())) && ( (item.getPredicate().equals(item2.getPredicate())) && (item.getRelationshipType().equals(item2.getRelationshipType())) ) - && (item.getObject().getDocumentType().equals(item2.getObject().getDocumentType())) - && (item.getSubject().getDocumentType().equals(item2.getSubject().getDocumentType())) ; + && (obj1.getDocumentType().equals(obj2.getDocumentType())) + && (subj1.getDocumentType().equals(subj2.getDocumentType())) ; } private void removeFromList(List list, RelationsCommonList.RelationListItem item){ diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java index c4cba8ac4..d08232e0b 100755 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/CommonAPI.java @@ -10,5 +10,7 @@ public class CommonAPI { public static String getVersionString(){ return COMMON_API; } + public static String AuthorityItemCSID_REPLACE="${itemCSID}"; + public static String showRelations_QP = "showRelations"; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 891fac1c7..2f3798e3f 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -593,6 +593,12 @@ public abstract class AbstractServiceContextImpl */ @Override public MultivaluedMap getQueryParams() { + + if (queryParams == null){ + if (this.uriInfo != null){ + queryParams = this.uriInfo.getQueryParameters(); + } + } if (queryParams == null){ queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl(); } diff --git a/services/jaxb/src/main/resources/relations_common.xsd b/services/jaxb/src/main/resources/relations_common.xsd index 2f03cf8e1..32e60ad90 100644 --- a/services/jaxb/src/main/resources/relations_common.xsd +++ b/services/jaxb/src/main/resources/relations_common.xsd @@ -76,6 +76,11 @@ + + + + + @@ -90,7 +95,6 @@ - diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java index c59509d1f..e1bc98dad 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java @@ -50,8 +50,7 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl