]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3780 Partial fix. Checking in files to get a stable base.
authorLaramie Crocker <laramie@berkeley.edu>
Sat, 16 Apr 2011 23:07:39 +0000 (23:07 +0000)
committerLaramie Crocker <laramie@berkeley.edu>
Sat, 16 Apr 2011 23:07:39 +0000 (23:07 +0000)
26 files changed:
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java
services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java
services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java
services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personauthorities_common.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml [new file with mode: 0755]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/r-1.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml
services/authority/pom.xml
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml
services/common/src/main/cspace/config/services/tenants/hearstmuseum/tenant-bindings.xml
services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/jaxb/src/main/resources/relations_common.xsd
services/person/client/src/test/resources/log4j.properties
services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd
services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java
services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java
services/relation/service/src/main/java/org/collectionspace/services/relation/RelationResource.java

index 012c1645d8841da7b95fb8015418f33f0cecd81b..70e9a0e2004c69e38e1af6b9743e3d7b5dc89ee3 100755 (executable)
@@ -217,6 +217,7 @@ public class ServiceResult {
                 + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" )\r
                 + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" )\r
                 + "; gotExpected:"+gotExpectedResult()\r
+                +";result:"+result+";"\r
                 + ( partsSummary(true))\r
                 +"}"\r
                 + ( includePayloads && Tools.notBlank(requestPayload) ? LINE+"requestPayload:"+LINE+CRLF+requestPayload+LINE : "" )\r
index 60ba460c2ebdf523fada3fd4e84d46b2092ef8d0..545a2b8f6592eebe1daee0ff65899c288f7b3aaf 100755 (executable)
@@ -27,6 +27,7 @@ import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;\r
 import org.apache.commons.httpclient.methods.DeleteMethod;\r
 import org.apache.commons.httpclient.methods.GetMethod;\r
+import org.apache.commons.httpclient.methods.PostMethod;\r
 import org.apache.commons.io.FileUtils;\r
 \r
 import java.io.BufferedReader;\r
@@ -226,19 +227,22 @@ public class XmlReplayTransport {
         return doPOST_PUT(urlString, xmlString, contentRaw, BOUNDARY, method, contentType, authForTest, fromTestID); //method is POST or PUT.\r
     }\r
 \r
-\r
-    public static ServiceResult doPOST_PUT(String urlString, String content, Map<String,String> contentRaw,\r
-                                           String boundary, String method, String contentType,\r
-                                           String authForTest, String fromTestID) throws Exception {\r
-        ServiceResult result = new ServiceResult();\r
-        result.method = method;\r
-        //HACK for speed testing.  Result: XmlReplay takes 9ms to process one test\r
+        //HACK for speed testing in doPOST_PUT.\r
+        //  Result: XmlReplay takes 9ms to process one test\r
         // right up to the point of actually firing an HTTP request.\r
         // or ~ 120 records per second.\r
         //result.CSID = "2";\r
         //result.overrideGotExpectedResult();\r
         //if (true) return result;\r
         //END-HACK\r
+\r
+    public static ServiceResult doPOST_PUT(String urlString, String content, Map<String,String> contentRaw,\r
+                                           String boundary, String method, String contentType,\r
+                                           String authForTest, String fromTestID) throws Exception {\r
+        ServiceResult result = new ServiceResult();\r
+        result.method = method;\r
+        String deleteURL = "";\r
+        String location = "";\r
         try {\r
             URL url = new URL(urlString);\r
             HttpURLConnection conn;\r
@@ -261,7 +265,6 @@ public class XmlReplayTransport {
             wr.write(content);\r
             wr.flush();\r
 \r
-\r
             try {\r
                 result.requestPayload = content;\r
                 result.requestPayloadsRaw = contentRaw;\r
@@ -270,26 +273,13 @@ public class XmlReplayTransport {
                 if (400 <= result.responseCode && result.responseCode <= 499){\r
                     return result;\r
                 }\r
-                BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));\r
-                String line;\r
-                StringBuffer sb = new StringBuffer();\r
-                while ((line = rd.readLine()) != null) {\r
-                    sb.append(line).append("\r\n");\r
-                }\r
-                String msg = sb.toString();\r
-                result.result = msg;\r
-                result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE"));\r
-\r
-                rd.close();\r
+                readStream(conn, result);\r
             } catch (Throwable t){\r
                 //System.err.println("ERROR getting content from response: "+t);\r
                 result.error = t.toString();\r
             }\r
             wr.close();\r
 \r
-\r
-            String deleteURL = "";\r
-            String location = "";\r
             Map<String, List<String>> headers = conn.getHeaderFields();\r
             List<String> locations = headers.get("Location");\r
             if (locations != null){\r
@@ -303,11 +293,77 @@ public class XmlReplayTransport {
             result.location = location;\r
             result.deleteURL = deleteURL;\r
             result.CSID = location;\r
+        } catch (Throwable t2){\r
+            result.error = "ERROR in XmlReplayTransport: "+t2;\r
+        }\r
+        return result;\r
+    }\r
 \r
+\r
+    public static ServiceResult doPOST_PUT_PostMethod(String urlString, String content, Map<String,String> contentRaw,\r
+                                           String boundary, String method, String contentType,\r
+                                           String authForTest, String fromTestID) throws Exception {\r
+        ServiceResult result = new ServiceResult();\r
+        result.method = method;\r
+        String deleteURL = "";\r
+        String location = "";\r
+        try {\r
+            HttpClient client = new HttpClient();\r
+            PostMethod postMethod = new PostMethod(urlString);\r
+            postMethod.setRequestHeader("Accept", "multipart/mixed");\r
+            postMethod.addRequestHeader("Accept", "application/xml");\r
+            postMethod.setRequestHeader("Authorization", "Basic " + authForTest);\r
+            postMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID);\r
+            //this method takes an array of params.  Not sure what they expect us to do with a raw post:\r
+            //   postMethod.setRequestBody();\r
+            int statusCode1 = 0;\r
+            String res = "";\r
+            try {\r
+                statusCode1 = client.executeMethod(postMethod);\r
+                result.responseCode = statusCode1;\r
+                //System.out.println("statusCode: "+statusCode1+" statusLine ==>" + postMethod.getStatusLine());\r
+                result.responseMessage = postMethod.getStatusText();\r
+                res = postMethod.getResponseBodyAsString();\r
+                Header[] headers = postMethod.getResponseHeaders("Location");\r
+                if (headers.length>0) {\r
+                    System.out.println("headers[0]:  "+headers[0]);\r
+                    String locationZero = headers[0].getValue();\r
+                    if (locationZero != null){\r
+                        String[] segments = locationZero.split("/");\r
+                        location = segments[segments.length - 1];\r
+                        deleteURL = Tools.glue(urlString, "/", location);\r
+                    }\r
+                }\r
+                postMethod.releaseConnection();\r
+            } catch (Throwable t){\r
+                result.error = t.toString();\r
+            }\r
+            result.result = res;\r
+            result.location = location;\r
+            result.deleteURL = deleteURL;\r
+            result.CSID = location;\r
         } catch (Throwable t2){\r
             result.error = "ERROR in XmlReplayTransport: "+t2;\r
         }\r
         return result;\r
     }\r
 \r
+    private static void readStream(HttpURLConnection  conn, ServiceResult result) throws Throwable {\r
+        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));\r
+        try {\r
+                String line;\r
+                StringBuffer sb = new StringBuffer();\r
+                while ((line = rd.readLine()) != null) {\r
+                    sb.append(line).append("\r\n");\r
+                }\r
+                String msg = sb.toString();\r
+                result.result = msg;\r
+                result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE"));\r
+        } finally {\r
+            rd.close();\r
+        }\r
+\r
+\r
+    }\r
+\r
 }\r
index a99cb6cd07cb2f4aa37762b25eb1576dfa409990..ff3b52933a058faf654e6c9ea5ce8a1f532f16fb 100755 (executable)
@@ -22,7 +22,7 @@ import java.util.List;
  */
 public class XmlReplayDevTest extends XmlReplayTest {
 
-//    @Test
+    @Test
     public void runMaster() throws Exception {
         String masterFile = System.getProperty("xmlReplayMaster");
         if (Tools.notEmpty(masterFile)){
index e94aa926e9667d35dfe13a9d00f420f7c22fd5ff..9e44b4c24fa27ce2a06d691ed81412650267ceae 100644 (file)
@@ -9,7 +9,7 @@
      when you check it in.\r
 -->\r
     <!--<protoHostPort>http://173.45.245.189:8180</protoHostPort>-->\r
-    <protoHostPort>http://localhost:8180</protoHostPort>\r
+    <protoHostPort>http://localhost:8280</protoHostPort>\r
     \r
     <!-- legal values for dumpServiceResult=[minimal,detailed,full] -->\r
     <dump payloads="true" dumpServiceResult="detailed" />\r
      \r
     <!--\r
     <run controlFile="objectexit/object-exit.xml" testGroup="makeone" />\r
-    -->\r
     <run controlFile="relation/relation.xml" testGroup="makeRelations" />\r
+    <run controlFile="person/person.xml" testGroup="person" />\r
+    <run controlFile="person/person.xml" testGroup="addOnePerson" />\r
+    -->\r
+    <run controlFile="person/person.xml" testGroup="updatePerson" />\r
+    \r
 </xmlReplayMaster>\r
 \r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml
new file mode 100755 (executable)
index 0000000..8e68267
--- /dev/null
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xmlReplay>\r
+    <testGroup ID="person" 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
+        <test ID="Person1">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/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
+            </vars>\r
+        </test>\r
+        <test ID="Person2">\r
+            <method>POST</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/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">johnWayneActor2</var>\r
+            </vars>\r
+        </test>\r
+        <test>\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)</uri>\r
+        </test>\r
+        \r
+        <test>\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+        </test>\r
+        <test>\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}</uri>\r
+        </test>\r
+        <test ID="authorityList">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/</uri>\r
+        </test>\r
+        <test ID="personList">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/</uri>\r
+        </test>\r
+        \r
+        <test ID="relatePersons"  auth="test">\r
+             <method>POST</method>\r
+             <uri>/cspace-services/relations/</uri>\r
+             <filename>relation/r-1.xml</filename>\r
+             <vars>\r
+                <var ID="documentId1">${Person1.CSID}</var>\r
+                <var ID="documentId2">${Person2.CSID}</var>\r
+                <var ID="documentType1">persons</var>\r
+                <var ID="documentType2">persons</var>\r
+                <var ID="relationshipType">hasBroader</var>\r
+             </vars>\r
+        </test>\r
+        \r
+        <test ID="relatePersonsInverse"  auth="test">\r
+             <method>POST</method>\r
+             <uri>/cspace-services/relations/</uri>\r
+             <filename>relation/r-1.xml</filename>\r
+             <vars>\r
+             <!-- Person2 and Person1 are switched in this record. \r
+                  Ultimately we don't want any hasNarrower actually stored.\r
+             -->\r
+                <var ID="documentId1">${Person2.CSID}</var>\r
+                <var ID="documentId2">${Person1.CSID}</var>\r
+                <var ID="documentType1">persons</var>\r
+                <var ID="documentType2">persons</var>\r
+                <var ID="relationshipType">hasNarrower</var>\r
+             </vars>\r
+         </test>\r
+        \r
+   </testGroup>\r
+   \r
+   <testGroup ID="addOnePerson" autoDeletePOSTS="false">\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.xml</filename>\r
+            <vars>\r
+               <!--<var ID="inAuthority">${PersonAuth1.CSID}</var>-->\r
+               <var ID="authShortIdentifier">CSPACE3739PersonAuthority</var>\r
+            </vars>\r
+        </test>\r
+        \r
+       </testGroup>\r
+       \r
+       <testGroup ID="updatePerson" 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="Person1">\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">johnWayneActor</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
+        \r
+           <test ID="PersonPUT">\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">\r
+            <method>GET</method>\r
+            <uri>/cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID}</uri>\r
+        </test>\r
+       </testGroup>\r
+</xmlReplay>\r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personauthorities_common.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personauthorities_common.xml
new file mode 100755 (executable)
index 0000000..ad7de6e
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<document name="personauthorities">\r
+<ns2:personauthorities_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+<displayName>${authShortIdentifier}</displayName>\r
+<shortIdentifier>${authShortIdentifier}</shortIdentifier>\r
+<refName>urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier})'${authShortIdentifier}'</refName>\r
+<vocabType>PersonAuthority</vocabType>\r
+</ns2:personauthorities_common>\r
+</document>\r
+\r
+\r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common.xml
new file mode 100755 (executable)
index 0000000..bd2834b
--- /dev/null
@@ -0,0 +1,26 @@
+<?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
+</document>\r
+\r
+\r
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml
new file mode 100755 (executable)
index 0000000..bc36c2a
--- /dev/null
@@ -0,0 +1,70 @@
+<?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
+               <relationshipType>hasBroader</relationshipType>\r
+               <predicate>hasBroader</predicate>\r
+               <predicateDisplayName>hasBroader</predicateDisplayName>\r
+               <objectCsid>${parentCSID}</objectCsid>\r
+               <subject>\r
+                 <csid>${myCSID}</csid>\r
+                 <type>Person</type>\r
+                 <name>John Wayne, Me</name>\r
+               </subject>\r
+               <object>\r
+                 <csid>${parentCSID}</csid>\r
+                 <type>Person</type>\r
+                 <name>John Wayne 2, the evil twin, Parent</name>\r
+               </object>\r
+       </relation-list-item>\r
+       <relation-list-item>\r
+               <subjectCsid>${childCSID}</subjectCsid>\r
+               <relationshipType>hasBroader</relationshipType>\r
+               <predicate>hasBroader</predicate>\r
+               <predicateDisplayName>hasBroader</predicateDisplayName>\r
+               <objectCsid>${myCSID}</objectCsid>\r
+               <subject>\r
+                 <csid>${childCSID}</csid>\r
+                 <type>Person</type>\r
+                 <name>John Wayne 2, the evil twin, child</name>\r
+               </subject>\r
+               <object>\r
+                 <csid>${myCSID}</csid>\r
+                 <type>Person</type>\r
+                 <name>John Wayne</name>\r
+               </object>\r
+       </relation-list-item>\r
+  </ns3:relations-common-list>\r
+\r
+  \r
+</document>\r
+\r
+\r
index 983a839cd1b05675ec2f6664dc06b319862e84d7..bf61191126aa53ed88ff05ea8daf8db73c89202c 100644 (file)
@@ -4,16 +4,11 @@
           xmlns:ns2="http://collectionspace.org/services/relation" 
           xmlns:ns3="http://collectionspace.org/services/jaxb">
     <documentId1>${documentId1}</documentId1>
-
-    <documentType1>objectexit</documentType1>
-
+    <documentType1>${documentType1}</documentType1>
     <documentId2>${documentId2}</documentId2>
-
-    <documentType2>objectexit</documentType2>
-
-    <relationshipType>COLLECTIONOBJECT_INTAKE</relationshipType>
-
-    <predicateDisplayName>COLLECTIONOBJECT_INTAKE.displayName</predicateDisplayName>
+    <documentType2>${documentType1}</documentType2>
+    <relationshipType>${relationshipType}</relationshipType>
+    <predicateDisplayName>${relationshipType}</predicateDisplayName>
   </ns2:relations_common>
 </document>
 
index 7f878d5ead61f97253535102c6457abb659a60de..4f4e1ea743ad4b00b6b72d31bd764880c35d6492 100644 (file)
              <uri>/cspace-services/objectexit/</uri>\r
              <filename>relation/oe1.xml</filename>\r
          </test>\r
-         <test ID="oe2"  auth="test">\r
+         <test ID="relate1"  auth="test">\r
              <method>POST</method>\r
              <uri>/cspace-services/relations/</uri>\r
              <filename>relation/r-1.xml</filename>\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="relationshipType">hasBroader</var>\r
+             </vars>\r
+         </test>\r
+         <test ID="relate2"  auth="test">\r
+             <method>POST</method>\r
+             <uri>/cspace-services/relations/</uri>\r
+             <filename>relation/r-1.xml</filename>\r
+             <vars>\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="relationshipType">hasBroader</var>\r
              </vars>\r
          </test>\r
+         \r
          <!--\r
          <test>\r
             <method>GET</method>\r
index 43f8092b2dd963d6c5d77cac384f7643ca3a8d80..6c46438fc382af8c353dd54cd93727189b5bd6e2 100644 (file)
             <version>${project.version}</version>\r
             <scope>provided</scope>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.relation.service</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.relation.client</artifactId>\r
+            <version>${project.version}</version>\r
+        </dependency>\r
+\r
 \r
         <!-- Utilities -->\r
 \r
index 94d2e32e9a2b995f60da0996abd6e2d5b7ef4ea1..c389af556a76ad91b19b95f7d3523e97f946f705 100644 (file)
  */
 package org.collectionspace.services.common.vocabulary;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.util.List;
 
+import javax.management.relation.Relation;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.Encoded;
@@ -44,9 +47,14 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.client.IQueryManager;
+import org.collectionspace.services.client.PayloadInputPart;
+import org.collectionspace.services.client.PayloadOutputPart;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.RelationClient;
 import org.collectionspace.services.client.workflow.WorkflowClient;
+import org.collectionspace.services.common.document.JaxbUtils;
+import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
@@ -72,6 +80,10 @@ import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.query.QueryManager;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
+import org.collectionspace.services.relation.RelationResource;
+import org.collectionspace.services.relation.RelationsCommon;
+import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationshipType;
 import org.jboss.resteasy.util.HttpResponseCodes;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
@@ -201,8 +213,6 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
        /**
         * Creates the authority.
         * 
-        * @param input the input
-        * 
         * @return the response
         */
        @POST
@@ -216,24 +226,11 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        path.path("" + csid);
                        Response response = Response.created(path.build()).build();
                        return response;
-               } catch (BadRequestException bre) {
-                       Response response = Response.status(
-                                       Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
                } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in createVocabulary", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+                       throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
                }
        }
-       
+
        protected String buildWhereForAuthByName(String name) {
                return authorityCommonSchemaName+
                                ":"+AuthorityJAXBSchema.SHORT_IDENTIFIER+
@@ -348,10 +345,9 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
 
        /**
         * Update authority.
-        * 
+        *
         * @param specifier the csid or id
-        * @param theUpdate the the update
-        * 
+        *
         * @return the multipart output
         */
        @PUT
@@ -374,22 +370,8 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        }
                        getRepositoryClient(ctx).update(ctx, csid, handler);
                        result = ctx.getOutput();
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caught exception in updateAuthority", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                                       "Update failed on Authority specifier=" + specifier).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
                } catch (Exception e) {
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+                       throw bigReThrow(e, ServiceMessages.UPDATE_FAILED);
                }
                return result.getBytes();
        }
@@ -442,13 +424,13 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
        /*************************************************************************
         * Create an AuthorityItem - this is a sub-resource of Authority
         * @param specifier either a CSID or one of the urn forms
-        * @param input the payload 
         * @return Authority item response
         *************************************************************************/
        @POST
        @Path("{csid}/items")
-       public Response createAuthorityItem(@PathParam("csid") String specifier, String xmlPayload) {
+       public Response createAuthorityItem(@Context UriInfo ui, @PathParam("csid") String specifier, String xmlPayload) {
                try {
+
                        PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
                        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = null;
                        Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM");
@@ -461,27 +443,19 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                                parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
                        }
                        ctx = createServiceContext(getItemServiceName(), input);
+            ctx.setUriInfo(ui);    //Laramie
                        DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
                        String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
                        UriBuilder path = UriBuilder.fromResource(resourceClass);
                        path.path(parentcsid + "/items/" + itemcsid);
                        Response response = Response.created(path.build()).build();
+
+            //updateRelations(ui, itemcsid, input);
+
                        return response;
-               } catch (BadRequestException bre) {
-                       Response response = Response.status(
-                                       Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
                } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in createAuthorityItem", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+            //TODO:    if e is 400 type error, then call throwWebAppException(400,...);
+            throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
                }
        }
 
@@ -504,10 +478,9 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.READ_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
         }
-                
         return result.getBytes();
     }
-    
+
     @PUT
     @Path("{csid}/items/{itemcsid}" + WorkflowClient.SERVICE_PATH)
     public byte[] updateWorkflow(
@@ -518,10 +491,10 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
        try {
                ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx = createServiceContext(getItemServiceName());
                String parentWorkspaceName = parentCtx.getRepositoryWorkspaceName();
-               
+
                PoxPayloadIn workflowUpdate = new PoxPayloadIn(xmlPayload);
                MultipartServiceContext ctx = (MultipartServiceContext) createServiceContext(WorkflowClient.SERVICE_NAME, workflowUpdate);
-               WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);
+            WorkflowDocumentModelHandler handler = createWorkflowDocumentHandler(ctx);
                ctx.setRespositoryWorkspaceName(parentWorkspaceName); //find the document in the parent's workspace
                getRepositoryClient(ctx).update(ctx, itemcsid, handler);
                result = ctx.getOutput();
@@ -529,8 +502,8 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
             throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
         }
         return result.getBytes();
-    }    
-    
+    }
+
        
        /**
         * Gets the authority item.
@@ -566,9 +539,17 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        }
                        ctx = (RemoteServiceContext)createServiceContext(getItemServiceName(), queryParams);
                        ctx.setJaxRsContext(jaxRsContext);
+
+
+
+            // NEW laramie
+            ctx.setUriInfo(ui); //ARG!   must pass this or subsequent calls will not have a ui.
+            // NEW
+
+
                        DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
                        if(itemSpec.form==SpecifierForm.CSID) {
-                               getRepositoryClient(ctx).get(ctx, itemSpec.value, handler);
+                               getRepositoryClient(ctx).get(ctx, itemSpec.value, handler);
                        } else {
                                String itemWhereClause = 
                                        buildWhereForAuthItemByName(itemSpec.value, parentcsid);
@@ -578,25 +559,8 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        }
                        // TODO should we assert that the item is in the passed vocab?
                        result = ctx.getOutput();
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("getAuthorityItem", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                                       "Get failed on AuthorityItem specifier=" + itemspecifier).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
                } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("getAuthorityItem", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+                       throw bigReThrow(e, ServiceMessages.GET_FAILED);
                }
                if (result == null) {
                        Response response = Response.status(Response.Status.NOT_FOUND).entity(
@@ -664,17 +628,8 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        }
                        getRepositoryClient(ctx).getFiltered(ctx, handler);
                        return (AuthItemCommonList) handler.getCommonPartList();
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
                } catch (Exception e) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("Caught exception in getAuthorityItemList", e);
-                       }
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+                       throw bigReThrow(e, ServiceMessages.LIST_FAILED);
                }
        }
 
@@ -741,27 +696,9 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                                serviceType,
                                refName,
                                myFilter.getPageSize(), myFilter.getStartPage(), true /*computeTotal*/ );
-       } catch (UnauthorizedException ue) {
-               Response response = Response.status(
-                               Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
-               throw new WebApplicationException(response);
-       } catch (DocumentNotFoundException dnfe) {
-               if (logger.isDebugEnabled()) {
-                       logger.debug("getReferencingObjects", dnfe);
-               }
-               Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                               "GetReferencingObjects failed with parentspecifier=" 
-                               + parentspecifier + " and itemspecifier=" + itemspecifier).type(
-                               "text/plain").build();
-               throw new WebApplicationException(response);
-       } catch (Exception e) { // Includes DocumentException
-               if (logger.isDebugEnabled()) {
-                       logger.debug("GetReferencingObjects", e);
-               }
-               Response response = Response.status(
-                               Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
-               throw new WebApplicationException(response);
-       }
+       } catch (Exception e) {
+                       throw bigReThrow(e, ServiceMessages.GET_FAILED);
+               }
        if (authRefDocList == null) {
                Response response = Response.status(Response.Status.NOT_FOUND).entity(
                                "Get failed, the requested Item CSID:" + itemspecifier + ": was not found.").type(
@@ -819,19 +756,9 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(
                ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES);
             authRefList = handler.getAuthorityRefs(docWrapper, authRefFields);
-        } catch (UnauthorizedException ue) {
-            Response response = Response.status(
-                    Response.Status.UNAUTHORIZED).entity("Failed to retrieve authority references: reason " + ue.getErrorReason()).type("text/plain").build();
-            throw new WebApplicationException(response);
         } catch (Exception e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Caught exception in getAuthorityRefs", e);
-            }
-            Response response = Response.status(
-                    Response.Status.INTERNAL_SERVER_ERROR).entity("Failed to retrieve authority references").type("text/plain").build();
-            throw new WebApplicationException(response);
-        }
-        return authRefList;
+                       throw bigReThrow(e, ServiceMessages.GET_FAILED  + " parentspecifier: "+parentspecifier + " itemspecifier:" +itemspecifier);
+               }return authRefList;
     }
 
        /**
@@ -839,13 +766,13 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
         * 
         * @param parentspecifier either a CSID or one of the urn forms
         * @param itemspecifier either a CSID or one of the urn forms
-        * @param theUpdate the the update
-        * 
+        *
         * @return the multipart output
         */
        @PUT
        @Path("{csid}/items/{itemcsid}")
        public byte[] updateAuthorityItem(
+            @Context UriInfo ui,
                        @PathParam("csid") String parentspecifier,
                        @PathParam("itemcsid") String itemspecifier,
                        String xmlPayload) {
@@ -877,28 +804,14 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
                        }
                        // Note that we have to create the service context for the Items, not the main service
                        DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            ctx.setUriInfo(ui);
                        getRepositoryClient(ctx).update(ctx, itemcsid, handler);
                        result = ctx.getOutput();
-               } catch (BadRequestException bre) {
-                       Response response = Response.status(
-                                       Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caught DNF exception in updateAuthorityItem", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                                       "Update failed on AuthorityItem csid=" + itemspecifier).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
+
+            //PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
+            //updateRelations(itemcsid, input);
                } catch (Exception e) {
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+            throw bigReThrow(e, ServiceMessages.UPDATE_FAILED);
                }
                return result.getBytes();
        }
@@ -916,44 +829,35 @@ public abstract class AuthorityResource<AuthCommon, AuthCommonList, AuthItemComm
        public Response deleteAuthorityItem(
                        @PathParam("csid") String parentcsid,
                        @PathParam("itemcsid") String itemcsid) {
-               if (logger.isDebugEnabled()) {
-                       logger.debug("deleteAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
-               }
-               if (parentcsid == null || "".equals(parentcsid)) {
-                       logger.error("deleteVocabularyItem: missing csid!");
-                       Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                                       "delete failed on AuthorityItem parentcsid=" + parentcsid).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               }
-               if (itemcsid == null || "".equals(itemcsid)) {
-                       logger.error("deleteVocabularyItem: missing itemcsid!");
-                       Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                                       "delete failed on AuthorityItem=" + itemcsid).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               }
+               try{
+            if (logger.isDebugEnabled()) {
+                logger.debug("deleteAuthorityItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+            }
+
+            if (parentcsid == null || "".equals(parentcsid)) {
+                logger.error("deleteVocabularyItem: missing csid!");
+                Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                        "delete failed on AuthorityItem parentcsid=" + parentcsid).type(
+                        "text/plain").build();
+                throw new WebApplicationException(response);
+            }
+            if (itemcsid == null || "".equals(itemcsid)) {
+                logger.error("deleteVocabularyItem: missing itemcsid!");
+                Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                        "delete failed on AuthorityItem=" + itemcsid).type(
+                        "text/plain").build();
+                throw new WebApplicationException(response);
+            }
+        }catch (Throwable t){
+            System.out.println("ERROR in setting up DELETE: "+t);
+        }
                try {
                        // Note that we have to create the service context for the Items, not the main service
                        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(getItemServiceName());
                        getRepositoryClient(ctx).delete(ctx, itemcsid);
                        return Response.status(HttpResponseCodes.SC_OK).build();
-               } catch (UnauthorizedException ue) {
-                       Response response = Response.status(
-                                       Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (DocumentNotFoundException dnfe) {
-                       if (logger.isDebugEnabled()) {
-                               logger.debug("caught exception in deleteAuthorityItem", dnfe);
-                       }
-                       Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                                       "Delete failed on AuthorityItem itemcsid=" + itemcsid).type(
-                                       "text/plain").build();
-                       throw new WebApplicationException(response);
-               } catch (Exception e) {
-                       Response response = Response.status(
-                                       Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
-                       throw new WebApplicationException(response);
+            } catch (Exception e) {
+                       throw bigReThrow(e, ServiceMessages.DELETE_FAILED + "  itemcsid: " + itemcsid+ " parentcsid:" + parentcsid);
                }
        }
     
index 6421c54db92132d811d127766b07dce1ee41c786..64820ef538150df3c52b0a4d713bef7b78b8bc0c 100644 (file)
  */
 package org.collectionspace.services.common.vocabulary.nuxeo;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
+import org.collectionspace.services.client.PayloadInputPart;
+import org.collectionspace.services.client.PayloadOutputPart;
+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.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
+import org.collectionspace.services.relation.RelationResource;
+import org.collectionspace.services.relation.RelationsCommon;
+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 javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
 /**
  * AuthorityItemDocumentModelHandler
  *
@@ -105,10 +124,6 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
         return item;
     }
 
-    /**
-     * setCommonPart set associated item
-     * @param vocabularyItem
-     */
     @Override
     public void setCommonPart(AICommon item) {
         this.item = item;
@@ -170,5 +185,114 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon, AICommonList>
        objectProps.remove(AuthorityItemJAXBSchema.CSID);
     }
 
+     @Override
+    public void extractAllParts(DocumentWrapper<DocumentModel> wrapDoc)
+            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.
+        }
+        PayloadOutputPart relationsPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, relationsCommonList);
+        ctx.addOutputPart(relationsPart);
+    }
+
+    public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
+        super.fillAllParts(wrapDoc, action);
+        ServiceContext ctx = getServiceContext();
+        PoxPayloadIn input = (PoxPayloadIn)ctx.getInput();
+        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);
+        PayloadOutputPart payloadOutputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, relationsCommonList);
+        ctx.setProperty(RelationClient.SERVICE_COMMON_LIST_NAME, payloadOutputPart);
+    }
+
+    public void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
+        super.completeUpdate(wrapDoc);
+        //now we add part for relations list
+        ServiceContext ctx = getServiceContext();
+        PayloadOutputPart foo = (PayloadOutputPart)ctx.getProperty(RelationClient.SERVICE_COMMON_LIST_NAME);
+        ((PoxPayloadOut)ctx.getOutput()).addPart(foo);
+    }
+
+    //===================================================================
+    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);
+            return null;
+        }
+        RelationsCommonList relationsCommonListBody = (RelationsCommonList) part.getBody();
+
+        ServiceContext ctx = getServiceContext();
+        MultivaluedMap queryParams = ctx.getQueryParamsPtr();
+       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);
+        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.
+        }
+
+        //Leave predicate, swap subject and object.
+        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.
+        }
+        List<RelationsCommonList.RelationListItem> inboundList = relationsCommonListBody.getRelationListItem();
+        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());
+
+            PoxPayloadOut payloadOut = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
+            PayloadOutputPart outputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMONPART_NAME, rc);
+            payloadOut.addPart(outputPart);
+
+            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;
+    }
+    //================= TODO: move this to common, refactoring this and  CollectionObjectResource.java
+
+    public RelationsCommonList getRelations(String subjectCSID, String objectCSID, String predicate) throws Exception {
+        ServiceContext ctx = getServiceContext();
+        MultivaluedMap queryParams = ctx.getQueryParams();
+        queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate);
+        queryParams.putSingle(IRelationsManager.SUBJECT_QP, subjectCSID);
+        queryParams.putSingle(IRelationsManager.OBJECT_QP, objectCSID);
+
+        RelationResource relationResource = new RelationResource();
+        RelationsCommonList relationsCommonList = relationResource.getList(ctx.getUriInfo());
+        return relationsCommonList;
+    }
+
+    //============================= END refactor ==========================
+
 }
 
index f1ee390f0af84f604869ea0f63c825e3560a37d1..7769d2b438ae2ad81ce325cceaa559f0ca9805d5 100644 (file)
                     </service:field>
                 </service:params>
             </service:initHandler>
+
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>displayName</types:value></types:item>
+                <!-- there is no objectNumberProperty for persons -->
+                     <types:item><types:key>objectNumberProperty</types:key><types:value>shortIdentifier</types:value></types:item>
+
+            </service:properties>
+
             <service:object id="1" name="Person" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index 40da882fcd5f58dcd992b8d4d3d34c49c050ab35..5d9d7f85f35429c18946ec1bd5fde4af474beaaf 100644 (file)
                     </service:field>
                 </service:params>
             </service:initHandler>
+            <service:properties xmlns:service='http://collectionspace.org/services/common/service'>
+                <types:item><types:key>objectNameProperty</types:key><types:value>displayName</types:value></types:item>
+                <!-- there is no objectNumberProperty for persons
+                     <types:item><types:key>objectNumberProperty</types:key><types:value>displayName</types:value></types:item>
+                -->
+            </service:properties>
             <service:object id="1" name="Person" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index 123ee7dcf90c2edca84558e8d9707f2ba1904866..efa1c75ed65568bfb8f93f7dfcfddc92ba02908e 100644 (file)
@@ -43,6 +43,7 @@ import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContextFactory;\r
+import org.collectionspace.services.common.document.BadRequestException;\r
 import org.collectionspace.services.common.document.DocumentHandler;\r
 import org.collectionspace.services.common.document.DocumentNotFoundException;\r
 import org.collectionspace.services.common.security.UnauthorizedException;\r
@@ -88,6 +89,8 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends
                                        .entity(serviceMsg + " on " + getClass().getName()\r
                                                        + " csid=" + csid).type("text/plain").build();\r
                        return new WebApplicationException(response);\r
+               } else if (e instanceof BadRequestException) {\r
+            return new WebApplicationException(e, ((BadRequestException) e).getErrorCode());\r
                } else if (e instanceof WebApplicationException) {\r
                        //\r
                        // subresource may have already thrown this exception\r
index 9b6e6f51f4b2bb0fae040e426cb48166cdf7c17f..b1554cb9e9c1c6afb41ee7a065e4aec45df1f857 100644 (file)
@@ -99,6 +99,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl {
                String xmlPayload) {\r
         try {\r
                PoxPayloadIn input = new PoxPayloadIn(xmlPayload);\r
+            System.out.println("\r\n\r\n==============================\r\nxmlPayload:\r\n"+xmlPayload);\r
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(input);\r
             return create(input, ctx);\r
         } catch (Exception e) {\r
index c606c8bdecd0f9c8549871b9b35a5dd537e9836a..891fac1c74891b46cd18809725ae22287966b868 100644 (file)
@@ -28,6 +28,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.workflow.WorkflowClient;
@@ -92,6 +93,8 @@ public abstract class AbstractServiceContextImpl<IT, OT>
     /** security context */
     private SecurityContext securityContext;
 
+    private UriInfo uriInfo;
+
     /**
      * Instantiates a new abstract service context impl.
      */
@@ -160,7 +163,7 @@ public abstract class AbstractServiceContextImpl<IT, OT>
      * @see org.collectionspace.services.common.context.ServiceContext#getCommonPartLabel(java.lang.String)
      */
     public String getCommonPartLabel(String schemaName) {
-        return schemaName.toLowerCase() + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;
+        return schemaName.toLowerCase() + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
     }
 
     /* (non-Javadoc)
@@ -590,9 +593,17 @@ public abstract class AbstractServiceContextImpl<IT, OT>
      */
     @Override
     public MultivaluedMap<String, String> getQueryParams() {
+         if (queryParams == null){
+             queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl<String,String>();
+        }
         return this.queryParams;
     }
 
+    @Override
+     public MultivaluedMap<String, String> getQueryParamsPtr() {
+           return this.queryParams;
+    }
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.context.ServiceContext#setQueryParams(javax.ws.rs.core.MultivaluedMap)
      */
@@ -600,4 +611,14 @@ public abstract class AbstractServiceContextImpl<IT, OT>
     public void setQueryParams(MultivaluedMap<String, String> theQueryParams) {
         this.queryParams = theQueryParams;
     }
+
+    @Override
+    public void setUriInfo(UriInfo ui){
+        this.uriInfo = ui;
+    }
+
+   @Override
+   public UriInfo getUriInfo(){
+        return this.uriInfo;
+    }
 }
index 369e2a664c4c6b2b2af2179e54e85be61939b1b9..872d04c2d959466df757836e946547bf646d7b0d 100644 (file)
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -47,7 +48,7 @@ public interface ServiceContext<IT, OT> {
     /**
      * The character used to separate the words in a part label
      */
-    public static final String PART_LABEL_SEPERATOR = "_";
+    public static final String PART_LABEL_SEPARATOR = "_";
     /** The Constant PART_COMMON_LABEL. */
     public static final String PART_COMMON_LABEL = "common";
 
@@ -246,12 +247,19 @@ public interface ServiceContext<IT, OT> {
      */
     public MultivaluedMap<String, String> getQueryParams();
 
+    public MultivaluedMap<String, String>  getQueryParamsPtr();
+
     /**
      * Sets the query params.
      * 
      * @param queryParams the query params
      */
     public void setQueryParams(MultivaluedMap<String, String> queryParams);
+
+    public void setUriInfo(UriInfo ui);
+
+    public UriInfo getUriInfo();
+
 }
 
 
index 4f43642242a409d951f1b703ae9b33b6589c9964..af724ced94159a55da934950b2e55c08ce60633c 100644 (file)
@@ -82,7 +82,7 @@ import org.dom4j.Document;
  * @param <T> 
  * @param <TL> 
  */
-public abstract class RemoteDocumentModelHandlerImpl<T, TL>
+public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
         extends DocumentModelHandler<T, TL> {
 
     /** The logger. */
@@ -115,10 +115,14 @@ public abstract class RemoteDocumentModelHandlerImpl<T, TL>
                List<PayloadInputPart> inputParts = ctx.getInput().getParts();
                for (PayloadInputPart part : inputParts) {
                    String partLabel = part.getLabel();
-                   ObjectPartType partMeta = partsMetaMap.get(partLabel);
-       //            extractPart(docModel, partLabel, partMeta);
-                   Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
-                   addOutputPart(unQObjectProperties, partLabel, partMeta);
+                try{
+                    ObjectPartType partMeta = partsMetaMap.get(partLabel);
+        //            extractPart(docModel, partLabel, partMeta);
+                    Map<String, Object> unQObjectProperties = extractPart(docModel, partLabel, partMeta);
+                    addOutputPart(unQObjectProperties, partLabel, partMeta);
+                } catch (Throwable t){
+                    System.out.println("===============================\r\nUnable to addOutputPart: "+partLabel+" error: "+t);
+                }
                }
         } else {
                if (logger.isWarnEnabled() == true) {
index d56054346c15b7f94885f1156f53ce869d34205a..8488aa300b2a320d7c3c677cdc7f1167ca0151b8 100644 (file)
@@ -52,6 +52,8 @@
             <xs:enumeration value="contains"/>\r
             <!-- document with id as document-id-1 contains one or more document with id as document-id-2 -->\r
             <xs:enumeration value="collectionobject-intake"/>\r
+            <!-- document with id as document-id-1 has parent document with id as document-id-2 -->\r
+            <xs:enumeration value="hasBroader" />\r
         </xs:restriction>\r
     </xs:simpleType>\r
 \r
index 4519e9992b28124010fe35f85726d26c49650b99..1a5d8cfb5655ec026bcfd2e34b98ba1ac0eba9c4 100644 (file)
@@ -19,7 +19,7 @@ log4j.appender.R.layout=org.apache.log4j.PatternLayout
 log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
 \r
 #packages\r
-log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.collectionspace=INFO\r
 log4j.logger.org.apache=INFO\r
 log4j.logger.httpclient=INFO\r
 log4j.logger.org.jboss.resteasy=INFO\r
index abfb09147d30a88ac9137275f8eba260aff431b8..ac4e1eb495f92dc8af45f98ec0358a8235f2bf21 100644 (file)
@@ -53,6 +53,8 @@
             <xs:enumeration value="association" />\r
             <!-- document with id as document-id-1 contains one or more document with id as document-id-2 -->\r
             <xs:enumeration value="contains" />\r
+            <!-- document with id as document-id-1 has parent document with id as document-id-2 -->\r
+            <xs:enumeration value="hasBroader" />\r
         </xs:restriction>\r
     </xs:simpleType>\r
 \r
index 351a60cc66a3ca1bc968d47593ccdd9a9cf254b5..8ace93f91296f858529846fa5d0f77be23da82c5 100644 (file)
@@ -39,6 +39,9 @@ public class RelationClient extends AbstractPoxServiceClientImpl<RelationsCommon
        public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
        public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/";     
        public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+       public static final String SERVICE_COMMON_LIST_NAME = "relations-common-list";
+
+    public static final String SERVICE_COMMONPART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
 
        @Override
        public String getServiceName() {
index bfce67d258b78e10331921aa25ee5353d4c7c8e1..26ecb6bf0f8e6fa2183d9392edd24c3e4b418767 100644 (file)
@@ -175,7 +175,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl {
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, STATUS_INTERNAL_SERVER_ERROR);   //should be an error: same objectID and subjectID are not allowed by validator.
+        Assert.assertEquals(statusCode, STATUS_BAD_REQUEST);   //should be an error: same objectID and subjectID are not allowed by validator.
     }
 
     // Failure outcomes
index c9cfb4f2c278c3f5d7a174f1e5e86b740a35bf45..b74764c194d16be5c1651abe94350d2c11f6242e 100644 (file)
@@ -86,6 +86,7 @@ public class RelationResource extends ResourceBase {
                return this.getRelationList(queryParams, subjectCsid, subjectType, predicate, objectCsid, objectType);
        }
 
+    //this is called by collectionobjectresource...so it is still public.
     public RelationsCommonList getRelationList(MultivaluedMap<String, String> queryParams, String subjectCsid, String subjectType,
                                                                          String predicate, String objectCsid, String objectType) throws WebApplicationException {
         try {
@@ -94,7 +95,6 @@ public class RelationResource extends ResourceBase {
 
             String relationClause = RelationsUtils.buildWhereClause(subjectCsid, subjectType, predicate, objectCsid, objectType);
             handler.getDocumentFilter().appendWhereClause(relationClause, IQueryManager.SEARCH_QUALIFIER_AND);
-
             return (RelationsCommonList)finish_getList(ctx, handler);
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.LIST_FAILED);