+ ( 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
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
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
wr.write(content);\r
wr.flush();\r
\r
-\r
try {\r
result.requestPayload = content;\r
result.requestPayloadsRaw = contentRaw;\r
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
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
*/
public class XmlReplayDevTest extends XmlReplayTest {
-// @Test
+ @Test
public void runMaster() throws Exception {
String masterFile = System.getProperty("xmlReplayMaster");
if (Tools.notEmpty(masterFile)){
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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<document name="persons">\r
+ <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+ <inAuthority>${inAuthority}</inAuthority>\r
+ <shortIdentifier>${shortIdentifier}</shortIdentifier>\r
+ <refName>urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne'</refName>\r
+ <displayName>John Wayne</displayName>\r
+ <displayNameComputed>false</displayNameComputed>\r
+ <shortDisplayName>JohnWayne</shortDisplayName>\r
+ <shortDisplayNameComputed>false</shortDisplayNameComputed>\r
+ <foreName>John</foreName>\r
+ <surName>Wayne</surName>\r
+ <birthDate>May 26, 1907</birthDate>\r
+ <deathDate>June 11, 1979</deathDate>\r
+ <birthPlace>Winterset, Iowa</birthPlace>\r
+ <groups>\r
+ <group>Irish</group>\r
+ <group>Scottish</group>\r
+ </groups>\r
+ <gender>male</gender>\r
+ <bioNote>born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive\r
+ voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions.</bioNote>\r
+ </ns2:persons_common>\r
+</document>\r
+\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<document name="persons">\r
+ <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">\r
+ <inAuthority>${inAuthority}</inAuthority>\r
+ <shortIdentifier>${shortIdentifier}</shortIdentifier>\r
+ <refName>urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne'</refName>\r
+ <displayName>John Wayne</displayName>\r
+ <displayNameComputed>false</displayNameComputed>\r
+ <shortDisplayName>JohnWayne</shortDisplayName>\r
+ <shortDisplayNameComputed>false</shortDisplayNameComputed>\r
+ <foreName>John</foreName>\r
+ <surName>Wayne</surName>\r
+ <birthDate>May 26, 1907</birthDate>\r
+ <deathDate>June 11, 1979</deathDate>\r
+ <birthPlace>Winterset, Iowa</birthPlace>\r
+ <groups>\r
+ <group>Irish</group>\r
+ <group>Scottish</group>\r
+ </groups>\r
+ <gender>male</gender>\r
+ <bioNote>born Marion Robert Morrison and betterknown by his stage name John Wayne, was an American film actor, director and producer. He epitomized rugged masculinity and has become an enduring American icon. He is famous for his distinctive\r
+ voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions.</bioNote>\r
+ </ns2:persons_common>\r
+ \r
+ <ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation" xmlns:ns2="http://collectionspace.org/services/jaxb">\r
+ <pageNum>0</pageNum>\r
+ <pageSize>40</pageSize>\r
+ <itemsInPage>1</itemsInPage>\r
+ <totalItems>1</totalItems>\r
+ <fieldsReturned>subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object</fieldsReturned>\r
+ <relation-list-item>\r
+ <subjectCsid>${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
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>
<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
<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
*/
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;
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;
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;
/**
* Creates the authority.
*
- * @param input the input
- *
* @return the response
*/
@POST
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+
/**
* Update authority.
- *
+ *
* @param specifier the csid or id
- * @param theUpdate the the update
- *
+ *
* @return the multipart output
*/
@PUT
}
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();
}
/*************************************************************************
* 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");
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);
}
}
} 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(
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();
throw bigReThrow(e, ServiceMessages.UPDATE_FAILED + WorkflowClient.SERVICE_PAYLOAD_NAME, csid);
}
return result.getBytes();
- }
-
+ }
+
/**
* Gets the authority item.
}
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);
}
// 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(
}
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);
}
}
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(
((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;
}
/**
*
* @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) {
}
// 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();
}
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);
}
}
*/
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
*
return item;
}
- /**
- * setCommonPart set associated item
- * @param vocabularyItem
- */
@Override
public void setCommonPart(AICommon item) {
this.item = item;
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 ==========================
+
}
</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"
</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"
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
.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
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
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;
/** security context */
private SecurityContext securityContext;
+ private UriInfo uriInfo;
+
/**
* Instantiates a new abstract service context impl.
*/
* @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)
*/
@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)
*/
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;
+ }
}
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;
/**
* 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";
*/
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();
+
}
* @param <T>
* @param <TL>
*/
-public abstract class RemoteDocumentModelHandlerImpl<T, TL>
+public abstract class RemoteDocumentModelHandlerImpl<T, TL>
extends DocumentModelHandler<T, TL> {
/** The logger. */
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) {
<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
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
<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
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() {
}
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
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 {
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);