]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3725 from trunk. Adds extra detail to calculated/looked up fields in Relation...
authorLaramie Crocker <laramie@berkeley.edu>
Tue, 19 Apr 2011 04:59:21 +0000 (04:59 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Tue, 19 Apr 2011 04:59:21 +0000 (04:59 +0000)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_2.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations_3.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/jaxb/src/main/resources/relations_common.xsd
services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java

index d9742dcda1cde8ac3c9e4e3f0649565636ffab38..6e6303ccfe4872f544aa2fe0963d3defd25f0f03 100644 (file)
     <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
index f298ae509178a5f19e87ab2662f6424a14822a44..e911c554b6866c329dc08b1d99b5ef595fbdb9d7 100755 (executable)
         </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
index 988d7fd5c52323c7e42ab8f9f3a22ffd130004dc..f4be7468dc7070925847a10b5d0810465912f94c 100755 (executable)
                <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
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 (executable)
index 0000000..85f01c6
--- /dev/null
@@ -0,0 +1,55 @@
+<?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
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 (executable)
index 0000000..37916fa
--- /dev/null
@@ -0,0 +1,74 @@
+<?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
index d8176361179e7dbb2f5c5d246bad46d373da563c..70d3d1535da75c03a98728d3b3176d009418eec8 100644 (file)
@@ -23,8 +23,8 @@
              <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
@@ -36,8 +36,8 @@
                 <!-- 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
index db893dcd2ccd82b85fbcc86d2ac72e99bdd73227..eb5a0511c3a40bde042a140ca5c2159190b41c81 100644 (file)
 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<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);
@@ -225,6 +233,22 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
     }
 
     //===================================================================
+    /*
+        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<AICommon, AICommonList>
         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
 
index b4b8ff4eedd9bdba5c9dff60c3302c4f9bd40149..eb8e399f3b84b71e2ebda6d4d9659f8ebe0ae265 100644 (file)
@@ -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<PoxPayloadIn,
             throw bre;
         } catch (DocumentException de) {
             throw de;
+        } catch (WebApplicationException wae){
+            throw wae;
         } catch (Exception e) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception ", e);
index 8488aa300b2a320d7c3c677cdc7f1167ca0151b8..2f03cf8e13e38bde919fe7253c39092d8a2e9bed 100644 (file)
         <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
index 3996c8ec3b62c17bc7af454d44003efd500b93ae..c17d4379da473ac6b302b47783581a7fecd9902a 100644 (file)
@@ -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;
     }