*/\r
public class XmlReplayMasterTest extends XmlReplayTest {\r
\r
-// @Test\r
+ @Test\r
public void runMaster() throws Exception {\r
XmlReplay replay = createXmlReplayUsingIntegrationTestsModule("..");\r
List<List<ServiceResult>> list = replay.runMaster(XmlReplay.DEFAULT_MASTER_CONTROL);\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
-\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
+ <run controlFile="person/person.xml" testGroup="postPerson" />\r
+ <run controlFile="relation/relation.xml" testGroup="makeRelationsNested" />\r
+ <run controlFile="relation/relation.xml" testGroup="r2only" />\r
+ <run controlFile="person/person.xml" testGroup="postPerson" />\r
-->\r
- <!-- TODO: make this an override: autoDeletePOSTS="true"-->\r
\r
- \r
+\r
+ \r
+ <!-- TODO: make this an override: autoDeletePOSTS="true"-->\r
</xmlReplayMaster>\r
\r
<var ID="shortIdentifier">johnWayneActor</var>\r
<var ID="CSID">${itemCSID}</var>\r
<var ID="parentCSID">${PersonParent.CSID}</var>\r
+ <var ID="parentUri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonParent.CSID}</var>\r
<var ID="childCSID">${PersonChild.CSID}</var>\r
+ <var ID="childUri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild.CSID}</var>\r
<var ID="child2CSID">${PersonChild2.CSID}</var>\r
+ <var ID="child2Uri">/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${PersonChild2.CSID}</var>\r
</vars>\r
</test>\r
\r
</subject>\r
<object>\r
<csid>${parentCSID}</csid>\r
+ <uri>${parentUri}</uri>\r
<documentType>Person</documentType>\r
<name>John Wayne 2, the evil twin, Parent</name>\r
</object>\r
<predicate>hasBroader</predicate>\r
<subject>\r
<csid>${childCSID}</csid>\r
+ <uri>${childUri}</uri>\r
<documentType>Person</documentType>\r
<name>John Wayne 2, the evil twin, child</name>\r
</subject>\r
<relation-list-item>\r
<predicate>hasBroader</predicate>\r
<subject>\r
+ <uri>${child2Uri}</uri>\r
<csid>${child2CSID}</csid>\r
<documentType>Person</documentType>\r
<name>John Wayne 2, the evil twin, child</name>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<document name="relations">
+ <ns2:relations_common xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb">
+ <documentId1>${documentId1}</documentId1>
+ <documentType1>${documentType1}</documentType1>
+ <documentId2>${documentId2}</documentId2>
+ <documentType2>${documentType2}</documentType2>
+ <relationshipType>${relationshipType}</relationshipType>
+ <predicateDisplayName>${relationshipType}</predicateDisplayName>
+ <subjectCsid>${documentId1}</subjectCsid>
+ <objectCsid>${documentId2}</objectCsid>
+ <subjectUri>/my/long/uri/${documentId1}</subjectUri>
+ <objectUri>/my/long/uri/${documentId2}</objectUri>
+ </ns2:relations_common>
+</document>
+
</test>\r
-->\r
</testGroup>\r
+ \r
+ <testGroup ID="makeRelationsNested" autoDeletePOSTS="true">\r
+ <test ID="oe1" auth="test">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/objectexit/</uri>\r
+ <filename>relation/oe1.xml</filename>\r
+ </test>\r
+ <test ID="oe2" auth="test">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/objectexit/</uri>\r
+ <filename>relation/oe1.xml</filename>\r
+ </test>\r
+ <test ID="relate1" auth="test">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/relations/</uri>\r
+ <filename>relation/r-2.xml</filename>\r
+ <vars>\r
+ <var ID="documentId1">${oe1.CSID}</var>\r
+ <var ID="documentId2">${itemCSID}</var>\r
+ <var ID="documentType1">ObjectExit</var>\r
+ <var ID="documentType2">ObjectExit</var>\r
+ <var ID="relationshipType">hasBroader</var>\r
+ </vars>\r
+ </test>\r
+ <test ID="relationsGET" auth="test">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/relations/</uri>\r
+ </test>\r
+ </testGroup>\r
+ \r
+ <testGroup ID="r2only" autoDeletePOSTS="true">\r
+ <test ID="relate" auth="test">\r
+ <method>POST</method>\r
+ <uri>/cspace-services/relations/</uri>\r
+ <filename>relation/r-2.xml</filename>\r
+ <vars>\r
+ <var ID="documentId1">1234-5678</var>\r
+ <var ID="documentId2">${itemCSID}</var>\r
+ <var ID="documentType1">ObjectExit</var>\r
+ <var ID="documentType2">ObjectExit</var>\r
+ <var ID="relationshipType">hasBroader</var>\r
+ </vars>\r
+ </test>\r
+ <test ID="relationsGET" auth="test">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/relations/</uri>\r
+ </test>\r
+ </testGroup>\r
\r
</xmlReplay>\r
\r
File below this line have been ported. -->\r
<!-- ============================================= -->\r
\r
- <run controlFile="person/person.xml" testGroup="updatePerson" />\r
+ <!--\r
<run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
+ <run controlFile="person/person.xml" testGroup="updatePerson" />\r
+ -->\r
+ <run controlFile="relation/relation.xml" testGroup="r2only" />\r
+ <run controlFile="person/person.xml" testGroup="postPerson" />\r
+ \r
\r
</xmlReplayMaster>\r
\r
import java.util.ListIterator;
import java.util.Map;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.PayloadInputPart;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
this.inAuthority = inAuthority;
}
+ @Override
+ public String getUri(DocumentModel docModel) {
+ return getServiceContextPath()+inAuthority+"/"+ AuthorityClient.ITEMS+"/"+getCsid(docModel);
+ }
+
+
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
*/
DocumentModel documentModel = (wrapDoc.getWrappedObject());
String itemCsid = documentModel.getName();
- //TODO: create all relations.... UPDATE and CREATE will call. Updates AuthorityItem part
- RelationsCommonList relationsCommonList = updateRelations(itemCsid, input);
+ //UPDATE and CREATE will call. Updates relations part
+ RelationsCommonList relationsCommonList = updateRelations(itemCsid, input, wrapDoc);
+
PayloadOutputPart payloadOutputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, relationsCommonList);
ctx.setProperty(RelationClient.SERVICE_COMMON_LIST_NAME, payloadOutputPart);
}
((PoxPayloadOut)ctx.getOutput()).addPart(foo);
}
- //===================================================================
- /*
- 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 {
+ public RelationsCommonList updateRelations(String itemCSID, PoxPayloadIn input, DocumentWrapper<DocumentModel> wrapDoc)
+ 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);
- return null;
+ return null; //nothing to do--they didn't send a list of relations.
}
RelationsCommonList relationsCommonListBody = (RelationsCommonList) part.getBody();
List<RelationsCommonList.RelationListItem> childList = childListOuter.getRelationListItem();
List<RelationsCommonList.RelationListItem> parentList = parentListOuter.getRelationListItem();
+ DocumentModel docModel = wrapDoc.getWrappedObject();
+
for (RelationsCommonList.RelationListItem inboundItem : inboundList) {
if (inboundItem.getObject().getCsid().equalsIgnoreCase(CommonAPI.AuthorityItemCSID_REPLACE)){
inboundItem.setObjectCsid(itemCSID);
inboundItem.getObject().setCsid(itemCSID);
+ inboundItem.getObject().setUri(getUri(docModel));
}
if (inboundItem.getSubject().getCsid().equalsIgnoreCase(CommonAPI.AuthorityItemCSID_REPLACE)){
inboundItem.setSubjectCsid(itemCSID);
inboundItem.getSubject().setCsid(itemCSID);
+ inboundItem.getSubject().setUri(getUri(docModel));
}
if (inboundItem.getObject().getCsid().equals(itemCSID) && inboundItem.getPredicate().equals(HAS_BROADER)) {
//then this is an item that says we have a child.
deleteRelations(parentList, ctx); //todo: there are items appearing on both lists....april 20.
deleteRelations(childList, ctx);
createRelations(actionList, ctx);
-
+ //We return all elements on the inbound list, since we have just worked to make them exist in the system
+ // and be non-redundant, etc. That list came from relationsCommonListBody, so it is still attached to it, just pass that back.
return relationsCommonListBody;
}
+ // this method calls the RelationResource to have it create the relations and persist them.
private void createRelations(List<RelationsCommonList.RelationListItem> inboundList, ServiceContext ctx){
for (RelationsCommonList.RelationListItem item : inboundList) {
RelationsCommon rc = new RelationsCommon();
//rc.setCsid(item.getCsid());
- String itemCsid = item.getSubject().getCsid();
- rc.setDocumentId1(itemCsid);
- rc.setSubjectCsid(itemCsid);
+ //todo: assignTo(item, rc);
+ RelationsDocListItem itemSubject = item.getSubject();
+ RelationsDocListItem itemObject = item.getObject();
+
+ String subjectCsid = itemSubject.getCsid();
+ rc.setDocumentId1(subjectCsid);
+ rc.setSubjectCsid(subjectCsid);
String objCsid = item.getObject().getCsid();
rc.setDocumentId2(objCsid);
rc.setRelationshipType(item.getPredicate());
//RelationshipType foo = (RelationshipType.valueOf(item.getPredicate())) ;
- //rc.setPredicate(foo);
+ //rc.setPredicate(foo); //this must be one of the type found in the enum in services/jaxb/src/main/resources/relations_common.xsd
+
+ rc.setDocumentType1(itemSubject.getDocumentType());
+ rc.setDocumentType2(itemObject.getDocumentType());
+
+ rc.setSubjectUri(itemSubject.getUri());
+ rc.setObjectUri(itemObject.getUri());
- 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);
*/\r
public interface AuthorityClient<LT extends AbstractCommonList, ILT extends AbstractCommonList, P extends AuthorityProxy<LT, ILT>> \r
extends CollectionSpacePoxClient<LT, P> {\r
+\r
+ /** The uri path element for items in an authority */\r
+ public static String ITEMS = "items"; //used to construct uri's in service paths for authorities.\r
+\r
/*\r
* Basic CRUD operations\r
*/\r
\r
/** The Constant RELATIONSHIP_TYPE_DISPLAYNAME. */\r
final static String RELATIONSHIP_TYPE_DISPLAYNAME = "predicateDisplayName";\r
+\r
+ final static String subjectUri = "subjectUri";\r
+\r
+ final static String objectUri = "objectUri";\r
+\r
}\r
\r
\r
public String getCsid(DocumentModel docModel) {
return NuxeoUtils.getCsid(docModel);
}
+
+ public String getUri(DocumentModel docModel) {
+ return getServiceContextPath()+getCsid(docModel);
+ }
/**
* getRepositorySession returns Nuxeo Repository Session
* @return
<xs:element name="subjectCsid" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentId1 -->\r
<xs:element name="objectCsid" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentId2 -->\r
<xs:element name="predicate" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/> <!-- new name for relationshipType -->\r
+ <xs:element name="subjectUri" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="objectUri" type="xs:string" minOccurs="1"/>\r
</xs:sequence>\r
</xs:complexType>\r
</xs:element>\r
// Subitem constants
//
public static final String SERVICE_ITEM_NAME = "locations";
- public static final String SERVICE_PATH_ITEMS_COMPONENT = "items"; //FIXME: REM - This should be defined in an AuthorityClient base class
public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
//
// Payload Part/Schema part names
import java.util.Map;
import org.collectionspace.services.LocationJAXBSchema;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.ContactClient;
import org.collectionspace.services.client.ContactClientUtils;
}
public String getItemServicePathComponent() {
- return LocationAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
+ return AuthorityClient.ITEMS;
}
// Instance variables specific to this test.
// Subitem constants
//
public static final String SERVICE_ITEM_NAME = "organizations";
- public static final String SERVICE_PATH_ITEMS_COMPONENT = "items"; //FIXME: REM - This should be defined in an AuthorityClient base class
public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
//
// Payload Part/Schema part names
import org.collectionspace.services.OrganizationJAXBSchema;
import org.collectionspace.services.PersonJAXBSchema;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.ContactClient;
import org.collectionspace.services.client.ContactClientUtils;
* @return the item service path component
*/
public String getItemServicePathComponent() {
- return OrgAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
+ return AuthorityClient.ITEMS;
}
/**
// Subitem constants
//
public static final String SERVICE_ITEM_NAME = "persons";
- public static final String SERVICE_PATH_ITEMS_COMPONENT = "items"; //FIXME: REM - This should be defined in an AuthorityClient base class
public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
//
// Payload Part/Schema part names
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.PayloadOutputPart;
import org.collectionspace.services.client.PoxPayloadIn;
}
public String getItemServicePathComponent() {
- return PersonAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
+ return AuthorityClient.ITEMS;
}
/** The test forename. */
<!-- document-id-1 would be the id of the collectionobject -->\r
<!-- document-type-1 would be the doc-type of the collectionobject -->\r
<!-- document-id-2 would be the id of the intake -->\r
- <!-- document-type-2 would be the doc-type of the intake -->\r
+` <!-- document-type-2 would be the doc-type of the intake -->\r
<!-- 2. left to right container and containee or children -->\r
<!-- e.g. for collectionobject containing other collectionobjects -->\r
<!-- document-id-1 would be the id of the container collectionobject -->\r
<xs:element name="objectCsid" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentId2 -->\r
<xs:element name="documentType2" type="xs:string" minOccurs="1" maxOccurs="1"/>\r
\r
- <!-- type of relatinoship between two entities -->\r
+ <!-- type of relationship between two entities -->\r
<xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
<xs:element name="predicate" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/> <!-- new name for relationshipType -->\r
<xs:element name="predicateDisplayName" type="xs:string" minOccurs="1"/>\r
\r
+\r
+ <xs:element name="subjectUri" type="xs:string"/>\r
+ <xs:element name="objectUri" type="xs:string"/>\r
+\r
<!-- enumeration defining the type of relationship between two entities -->\r
<xs:simpleType name="RelationshipType">\r
<xs:restriction base="xs:string">\r
</xs:restriction>\r
</xs:simpleType>\r
\r
+\r
</xs:schema>\r
\r
\r
String subjectCsid = relationListItem.getSubjectCsid();
String documentType = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_1);
RelationsDocListItem subject = createRelationsDocListItem(ctx, sbt, subjectCsid, tReader, documentType);
+
+ //Object o1 = docModel.getProperty(ctx.getCommonPartLabel(), "subject");
+ //Object o2 = docModel.getProperty(ctx.getCommonPartLabel(), "object");
+
+ String subjectUri = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.subjectUri);
+ subject.setUri(subjectUri);
relationListItem.setSubject(subject);
String objectCsid = relationListItem.getObjectCsid();
documentType = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.DOCUMENT_TYPE_2);
RelationsDocListItem object = createRelationsDocListItem(ctx, sbt, objectCsid, tReader, documentType);
+
+ String objectUri = (String) docModel.getProperty(ctx.getCommonPartLabel(), RelationJAXBSchema.objectUri);
+ object.setUri(objectUri);
relationListItem.setObject(object);
return relationListItem;
// Subitem constants
//
public static final String SERVICE_ITEM_NAME = "vocabularyitems";
- public static final String SERVICE_PATH_ITEMS_COMPONENT = "items"; //FIXME: REM - This should be defined in an AuthorityClient base class
public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
@Override
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.PayloadOutputPart;
private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
// Instance variables specific to this test.
final String SERVICE_PATH_COMPONENT = VocabularyClient.SERVICE_PATH_COMPONENT;//"vocabularies";
- final String SERVICE_PATH_ITEMS_COMPONENT = VocabularyClient.SERVICE_PATH_ITEMS_COMPONENT;//"items";
final String SERVICE_PAYLOAD_NAME = VocabularyClient.SERVICE_PAYLOAD_NAME;
final String SERVICE_ITEM_PAYLOAD_NAME = VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME;
private String knownResourceId = null;
}
public String getServicePathItemsComponent() {
- return this.SERVICE_PATH_ITEMS_COMPONENT;
+ return AuthorityClient.ITEMS;
}
/**