<run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
<run controlFile="person/person.xml" testGroup="person" />\r
<run controlFile="person/person.xml" testGroup="addOnePerson" />\r
- <run controlFile="relation/relation.xml" testGroup="makeRelations" />\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
- \r
+ \r
\r
</xmlReplayMaster>\r
\r
</test>\r
\r
\r
- <test ID="PersonPUT">\r
+ <test ID="PersonPUT_1p2c">\r
<method>PUT</method>\r
<uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID}</uri>\r
<filename>person/persons_common_w_relations.xml</filename>\r
</vars>\r
</test>\r
\r
- <test ID="GETPersonPUT">\r
+ <test ID="GETPersonPUT_1p2c">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ </test>\r
+ \r
+ <test ID="PersonPUT_1p">\r
+ <method>PUT</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID}</uri>\r
+ <filename>person/persons_common_w_relations_2.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="myCSID">${Person1.CSID}</var>\r
+ <var ID="parentCSID">${PersonParent.CSID}</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="GETPersonPUT_1p">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ </test>\r
+ \r
+ \r
+ <test ID="PersonPUT_1p1c">\r
+ <method>PUT</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID}</uri>\r
+ <filename>person/persons_common_w_relations.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="myCSID">${Person1.CSID}</var>\r
+ <var ID="parentCSID">${PersonParent.CSID}</var>\r
+ <var ID="childCSID">${PersonChild.CSID}</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="GETPersonPUT_1p1c">\r
+ <method>GET</method>\r
+ <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+ </test>\r
+ \r
+ <test ID="PersonPUT_2c">\r
+ <method>PUT</method>\r
+ <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID}</uri>\r
+ <filename>person/persons_common_w_relations_3.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="myCSID">${Person1.CSID}</var>\r
+ <var ID="childCSID">${PersonChild.CSID}</var>\r
+ <var ID="child2CSID">${PersonChild2.CSID}</var>\r
+ </vars>\r
+ </test>\r
+ \r
+ <test ID="GETPersonPUT_2c">\r
<method>GET</method>\r
<uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
</test>\r
<objectCsid>${parentCSID}</objectCsid>\r
<subject>\r
<csid>${myCSID}</csid>\r
- <type>Person</type>\r
+ <documentType>Person</documentType>\r
<name>John Wayne, Me</name>\r
</subject>\r
<object>\r
<csid>${parentCSID}</csid>\r
- <type>Person</type>\r
+ <documentType>Person</documentType>\r
<name>John Wayne 2, the evil twin, Parent</name>\r
</object>\r
</relation-list-item>\r
<objectCsid>${myCSID}</objectCsid>\r
<subject>\r
<csid>${childCSID}</csid>\r
- <type>Person</type>\r
+ <documentType>Person</documentType>\r
<name>John Wayne 2, the evil twin, child</name>\r
</subject>\r
<object>\r
<csid>${myCSID}</csid>\r
- <type>Person</type>\r
+ <documentType>Person</documentType>\r
<name>John Wayne</name>\r
</object>\r
</relation-list-item>\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
+ <subjectCsid>${myCSID}</subjectCsid>\r
+ <documentType1>Person</documentType1>\r
+ <documentType2>Person</documentType2>\r
+ <relationshipType>hasBroader</relationshipType>\r
+ <predicate>hasBroader</predicate>\r
+ <predicateDisplayName>hasBroader</predicateDisplayName>\r
+ <objectCsid>${parentCSID}</objectCsid>\r
+ <subject>\r
+ <csid>${myCSID}</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
+ </ns3:relations-common-list>\r
+\r
+ \r
+</document>\r
+\r
+\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
+ <subjectCsid>${childCSID}</subjectCsid>\r
+ <documentType1>Person</documentType1>\r
+ <documentType2>Person</documentType2>\r
+ <relationshipType>hasBroader</relationshipType>\r
+ <predicate>hasBroader</predicate>\r
+ <predicateDisplayName>hasBroader</predicateDisplayName>\r
+ <objectCsid>${myCSID}</objectCsid>\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>${myCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne</name>\r
+ </object>\r
+ </relation-list-item>\r
+ <relation-list-item>\r
+ <subjectCsid>${child2CSID}</subjectCsid>\r
+ <documentType1>Person</documentType1>\r
+ <documentType2>Person</documentType2>\r
+ <relationshipType>hasBroader</relationshipType>\r
+ <predicate>hasBroader</predicate>\r
+ <predicateDisplayName>hasBroader</predicateDisplayName>\r
+ <objectCsid>${myCSID}</objectCsid>\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>${myCSID}</csid>\r
+ <documentType>Person</documentType>\r
+ <name>John Wayne</name>\r
+ </object>\r
+ </relation-list-item>\r
+ </ns3:relations-common-list>\r
+\r
+ \r
+</document>\r
+\r
+\r
<vars>\r
<var ID="documentId1">${oe1.CSID}</var>\r
<var ID="documentId2">${oe2.CSID}</var>\r
- <var ID="documentType1">ObjectExit</var>\r
- <var ID="documentType2">ObjectExit</var>\r
+ <var ID="documentType1">objectexit</var>\r
+ <var ID="documentType2">objectexit</var>\r
<var ID="relationshipType">hasBroader</var>\r
</vars>\r
</test>\r
<!-- switched oe2 and oe1 on this -->\r
<var ID="documentId1">${oe2.CSID}</var>\r
<var ID="documentId2">${oe1.CSID}</var>\r
- <var ID="documentType1">ObjectExit</var>\r
- <var ID="documentType2">ObjectExit</var>\r
+ <var ID="documentType1">objectexit</var>\r
+ <var ID="documentType2">objectexit</var>\r
<var ID="relationshipType">hasBroader</var>\r
</vars>\r
</test>\r
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;
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;
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;
public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
extends RemoteDocumentModelHandlerImpl<AICommon, AICommonList> {
+ private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
+
private String authorityItemCommonSchemaName;
//private final Logger logger = LoggerFactory.getLogger(AuthorityItemDocumentModelHandler.class);
}
//===================================================================
+ /*
+ 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) {
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<RelationsCommonList.RelationListItem> inboundList = relationsCommonListBody.getRelationListItem();
- for (RelationsCommonList.RelationListItem item : inboundList) {
+ List<RelationsCommonList.RelationListItem> actionList = newList();
+ List<RelationsCommonList.RelationListItem> childList = childListOuter.getRelationListItem();
+ List<RelationsCommonList.RelationListItem> 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<RelationsCommonList.RelationListItem> 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<RelationsCommonList.RelationListItem> 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<RelationsCommonList.RelationListItem> newList(){
+ List<RelationsCommonList.RelationListItem> result = new ArrayList<RelationsCommonList.RelationListItem>();
+ return result;
+ }
+ protected List<RelationsCommonList.RelationListItem> cloneList(List<RelationsCommonList.RelationListItem> inboundList){
+ List<RelationsCommonList.RelationListItem> result = newList();
+ for (RelationsCommonList.RelationListItem item: inboundList){
+ result.add(item);
+ }
+ return result;
+ }
+ private RelationsCommonList.RelationListItem findInList(List<RelationsCommonList.RelationListItem> 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<RelationsCommonList.RelationListItem> list, RelationsCommonList.RelationListItem item){
+ list.remove(item);
}
//================= TODO: move this to common, refactoring this and CollectionObjectResource.java
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;
throw bre;
} catch (DocumentException de) {
throw de;
+ } catch (WebApplicationException wae){
+ throw wae;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Caught exception ", e);
<xs:sequence>\r
<xs:element name="uri" type="xs:anyURI" minOccurs="1"/>\r
<xs:element name="csid" type="xs:string" minOccurs="1"/>\r
- <xs:element name="type" type="xs:string" minOccurs="1"/>\r
+ <xs:element name="service" type="xs:string" minOccurs="1"/>\r
<xs:element name="name" type="xs:string" minOccurs="1"/>\r
<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
+ <xs:element name="error" type="xs:string" minOccurs="0"/>\r
</xs:sequence>\r
</xs:complexType>\r
\r
//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);
} 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;
}