\r
for (Node testgroup : testgroupNodes) {\r
\r
- JexlContext jc = new MapContext(); //Get a new JexlContext for each test group.\r
+ XmlReplayEval.MapContextWKeys jc = new XmlReplayEval.MapContextWKeys();//MapContext(); //Get a new JexlContext for each test group.\r
evalStruct.jc = jc;\r
\r
autoDeletePOSTS = testgroup.valueOf("@autoDeletePOSTS");\r
import org.apache.commons.jexl2.Expression;\r
import org.apache.commons.jexl2.JexlContext;\r
import org.apache.commons.jexl2.JexlEngine;\r
+import org.apache.commons.jexl2.MapContext;\r
\r
+import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
\r
/**\r
* User: laramie\r
Object resultObj = expr.evaluate(jc);\r
String resultStr;\r
if (null == resultObj){\r
- resultStr = "ERROR";\r
- System.out.println("Jexl context: "+jc.toString());\r
+ //debug: System.out.println("null found while evaluationg variable: '"+var+"' Jexl context: "+dumpContext(jc));\r
+ resultStr = "${"+var+"}";\r
} else {\r
resultStr = resultObj.toString();\r
\r
return result.toString();\r
}\r
\r
+ protected static String dumpContext(JexlContext jc){\r
+ String result = "";\r
+ if (jc instanceof MapContextWKeys){\r
+ Set keys = ((MapContextWKeys)jc).getKeys();\r
+ result = keys.toString();\r
+ } else {\r
+ result = jc.toString();\r
+ }\r
+ return result;\r
+ }\r
+\r
+ public static class MapContextWKeys extends MapContext implements JexlContext {\r
+ private Map<String,Object> map = new HashMap();\r
+ public Set getKeys(){\r
+ return this.map.keySet();\r
+ }\r
+ }\r
+\r
+\r
}\r
<run controlFile="person/person.xml" testGroup="updatePerson" />\r
<run controlFile="person/person.xml" testGroup="updatePerson" />\r
<run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
- <run controlFile="person/person.xml" testGroup="updatePerson" />\r
+\r
+ <run controlFile="person/person.xml" testGroup="updatePerson" autoDeletePOSTS="true" />\r
+ <run controlFile="person/person.xml" testGroup="updatePerson" autoDeletePOSTS="true" />\r
+ <run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
+ \r
+ <run controlFile="person/person.xml" testGroup="postPerson" />\r
-->\r
+ <!-- TODO: make this an override: autoDeletePOSTS="true"-->\r
\r
\r
</xmlReplayMaster>\r
\r
<test ID="GETPersonPUT_1p2c">\r
<method>GET</method>\r
- <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
</test>\r
\r
<test ID="PersonPUT_1p">\r
\r
<test ID="GETPersonPUT_1p">\r
<method>GET</method>\r
- <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
</test>\r
\r
\r
\r
<test ID="GETPersonPUT_1p1c">\r
<method>GET</method>\r
- <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
</test>\r
\r
<test ID="PersonPUT_2c">\r
\r
<test ID="GETPersonPUT_2c">\r
<method>GET</method>\r
- <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
</test>\r
</testGroup>\r
+ \r
+ !-- ========================= POST a person ===================================================== -->\r
+ \r
+ <testGroup ID="postPerson" autoDeletePOSTS="true">\r
+ <test ID="PersonAuth1" auth="admin@collectionspace.org">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/personauthorities/</uri>\r
+ <filename>person/personauthorities_common.xml</filename>\r
+ <vars>\r
+ <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="PersonParent">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
+ <filename>person/persons_common.xml</filename>\r
+ <vars>\r
+ <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
+ <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+ <var ID="shortIdentifier">johnWayneActorParent</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="PersonChild">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
+ <filename>person/persons_common.xml</filename>\r
+ <vars>\r
+ <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
+ <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+ <var ID="shortIdentifier">johnWayneActorChild</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="PersonChild2">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
+ <filename>person/persons_common.xml</filename>\r
+ <vars>\r
+ <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
+ <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+ <var ID="shortIdentifier">johnWayneActorChild2</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="Person1">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/</uri>\r
+ <filename>person/persons_common_w_relations_POST.xml</filename>\r
+ <vars>\r
+ <var ID="inAuthority">${PersonAuth1.CSID}</var>\r
+ <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+ <var ID="shortIdentifier">johnWayneActor</var>\r
+ <var ID="CSID">${itemCSID}</var>\r
+ <var ID="parentCSID">${PersonParent.CSID}</var>\r
+ <var ID="childCSID">${PersonChild.CSID}</var>\r
+ <var ID="child2CSID">${PersonChild2.CSID}</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="GETpostPerson">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}?showRelations=true</uri>\r
+ </test>\r
+ \r
+ </testGroup>\r
</xmlReplay>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<document name="persons">\r
+ <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+ <inAuthority>${inAuthority}</inAuthority>\r
+ <shortIdentifier>${shortIdentifier}</shortIdentifier>\r
+ <refName>urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne'</refName>\r
+ <displayName>John Wayne</displayName>\r
+ <displayNameComputed>false</displayNameComputed>\r
+ <shortDisplayName>JohnWayne</shortDisplayName>\r
+ <shortDisplayNameComputed>false</shortDisplayNameComputed>\r
+ <foreName>John</foreName>\r
+ <surName>Wayne</surName>\r
+ <birthDate>May 26, 1907</birthDate>\r
+ <deathDate>June 11, 1979</deathDate>\r
+ <birthPlace>Winterset, Iowa</birthPlace>\r
+ <groups>\r
+ <group>Irish</group>\r
+ <group>Scottish</group>\r
+ </groups>\r
+ <gender>male</gender>\r
+ <bioNote>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\r
+ voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions.</bioNote>\r
+ </ns2:persons_common>\r
+ \r
+ <ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation" xmlns:ns2="http://collectionspace.org/services/jaxb">\r
+ <pageNum>0</pageNum>\r
+ <pageSize>40</pageSize>\r
+ <itemsInPage>1</itemsInPage>\r
+ <totalItems>1</totalItems>\r
+ <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>\r
+ <relation-list-item>\r
+ <predicate>hasBroader</predicate>\r
+ <subject>\r
+ <csid>${itemCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne, Me</name>\r
+ </subject>\r
+ <object>\r
+ <csid>${parentCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne 2, the evil twin, Parent</name>\r
+ </object>\r
+ </relation-list-item>\r
+ <relation-list-item>\r
+ <predicate>hasBroader</predicate>\r
+ <subject>\r
+ <csid>${childCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne 2, the evil twin, child</name>\r
+ </subject>\r
+ <object>\r
+ <csid>${itemCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne</name>\r
+ </object>\r
+ </relation-list-item>\r
+ <relation-list-item>\r
+ <predicate>hasBroader</predicate>\r
+ <subject>\r
+ <csid>${child2CSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne 2, the evil twin, child</name>\r
+ </subject>\r
+ <object>\r
+ <csid>${itemCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne</name>\r
+ </object>\r
+ </relation-list-item>\r
+ </ns3:relations-common-list>\r
+</document>\r
+\r
+\r
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;
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;
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<RelationsCommonList.RelationListItem> parentList = parentListOuter.getRelationListItem();
+
+ RelationsCommonList childrenListOuter = getRelations(null, thisCSID, predicate);
+ List<RelationsCommonList.RelationListItem> 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);
}
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);
List<RelationsCommonList.RelationListItem> 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){
} 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){
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);
private void createRelations(List<RelationsCommonList.RelationListItem> 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.
}
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){
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<RelationsCommonList.RelationListItem> list, RelationsCommonList.RelationListItem item){
public static String getVersionString(){\r
return COMMON_API;\r
}\r
+ public static String AuthorityItemCSID_REPLACE="${itemCSID}";\r
+ public static String showRelations_QP = "showRelations";\r
}\r
\r
*/
@Override
public MultivaluedMap<String, String> getQueryParams() {
+
+ if (queryParams == null){
+ if (this.uriInfo != null){
+ queryParams = this.uriInfo.getQueryParameters();
+ }
+ }
if (queryParams == null){
queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl<String,String>();
}
<xs:element name="number" type="xs:string" minOccurs="1"/>\r
<xs:element name="documentType" type="xs:string" minOccurs="1"/>\r
<xs:element name="documentTypeFromModel" type="xs:string" minOccurs="1"/>\r
+ <!-- order is for potential use by app/gui. services won't do anything with it.-->\r
+ <xs:element name="order" type="xs:string" minOccurs="0"/>\r
+ <!-- key is for things like -which predicate type search did this list come from-->\r
+ <xs:element name="key" type="xs:string" minOccurs="0"/>\r
+ <!-- error is filled in and present only when sercices has crawled this record, and found that the related item was not in DB.-->\r
<xs:element name="error" type="xs:string" minOccurs="0"/>\r
</xs:sequence>\r
</xs:complexType>\r
<xs:element name="relation-list-item" maxOccurs="unbounded">\r
<xs:complexType>\r
<xs:sequence>\r
- <!-- uri to retrieve collection object details -->\r
<xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
<xs:element name="csid" type="xs:string" minOccurs="1"/>\r
<xs:element name="subjectCsid" type="xs:string" minOccurs="1"/>\r
//\r
// Assert that the Subject ID and Predicate ID are not the same\r
//\r
- assert(relationsCommon.getDocumentId1().equalsIgnoreCase(relationsCommon.getDocumentId2()) == false) :\r
- SUBJECT_EQUALS_PREDICATE_ERROR;\r
+ assert(relationsCommon.getDocumentId1().equalsIgnoreCase(relationsCommon.getDocumentId2()) == false) : SUBJECT_EQUALS_PREDICATE_ERROR;\r
} catch (AssertionError e) {\r
if (logger.isErrorEnabled() == true) {\r
logger.error(e.getMessage(), e);\r