From 1db82874478690b0f65680bc572d13943fb804cd Mon Sep 17 00:00:00 2001 From: Laramie Crocker Date: Sat, 16 Apr 2011 23:07:39 +0000 Subject: [PATCH] CSPACE-3780 Partial fix. Checking in files to get a stable base. --- .../xmlreplay/ServiceResult.java | 1 + .../xmlreplay/XmlReplayTransport.java | 100 +++++-- .../test/XmlReplayDevTest.java | 2 +- .../test-data/xmlreplay/dev-master.xml | 8 +- .../test-data/xmlreplay/person/person.xml | 171 ++++++++++++ .../person/personauthorities_common.xml | 11 + .../xmlreplay/person/persons_common.xml | 26 ++ .../person/persons_common_w_relations.xml | 70 +++++ .../test-data/xmlreplay/relation/r-1.xml | 13 +- .../test-data/xmlreplay/relation/relation.xml | 19 +- services/authority/pom.xml | 11 + .../common/vocabulary/AuthorityResource.java | 250 ++++++------------ .../AuthorityItemDocumentModelHandler.java | 132 ++++++++- .../collectionspace/tenant-bindings.xml | 8 + .../tenants/hearstmuseum/tenant-bindings.xml | 6 + ...tMultiPartCollectionSpaceResourceImpl.java | 3 + .../services/common/ResourceBase.java | 1 + .../context/AbstractServiceContextImpl.java | 23 +- .../common/context/ServiceContext.java | 10 +- .../java/RemoteDocumentModelHandlerImpl.java | 14 +- .../src/main/resources/relations_common.xsd | 2 + .../src/test/resources/log4j.properties | 2 +- .../resources/schemas/relations_common.xsd | 2 + .../services/client/RelationClient.java | 3 + .../client/test/RelationServiceTest.java | 2 +- .../services/relation/RelationResource.java | 2 +- 26 files changed, 670 insertions(+), 222 deletions(-) create mode 100755 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml create mode 100755 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personauthorities_common.xml create mode 100755 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common.xml create mode 100755 services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java index 012c1645d..70e9a0e20 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/ServiceResult.java @@ -217,6 +217,7 @@ public class ServiceResult { + ( Tools.notEmpty(location) ? "; location.CSID:"+location : "" ) + ( Tools.notEmpty(error) ? "; ERROR:"+error : "" ) + "; gotExpected:"+gotExpectedResult() + +";result:"+result+";" + ( partsSummary(true)) +"}" + ( includePayloads && Tools.notBlank(requestPayload) ? LINE+"requestPayload:"+LINE+CRLF+requestPayload+LINE : "" ) diff --git a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java index 60ba460c2..545a2b8f6 100755 --- a/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java +++ b/services/IntegrationTests/src/main/java/org/collectionspace/services/IntegrationTests/xmlreplay/XmlReplayTransport.java @@ -27,6 +27,7 @@ import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.DeleteMethod; import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.io.FileUtils; import java.io.BufferedReader; @@ -226,19 +227,22 @@ public class XmlReplayTransport { return doPOST_PUT(urlString, xmlString, contentRaw, BOUNDARY, method, contentType, authForTest, fromTestID); //method is POST or PUT. } - - public static ServiceResult doPOST_PUT(String urlString, String content, Map contentRaw, - String boundary, String method, String contentType, - String authForTest, String fromTestID) throws Exception { - ServiceResult result = new ServiceResult(); - result.method = method; - //HACK for speed testing. Result: XmlReplay takes 9ms to process one test + //HACK for speed testing in doPOST_PUT. + // Result: XmlReplay takes 9ms to process one test // right up to the point of actually firing an HTTP request. // or ~ 120 records per second. //result.CSID = "2"; //result.overrideGotExpectedResult(); //if (true) return result; //END-HACK + + public static ServiceResult doPOST_PUT(String urlString, String content, Map contentRaw, + String boundary, String method, String contentType, + String authForTest, String fromTestID) throws Exception { + ServiceResult result = new ServiceResult(); + result.method = method; + String deleteURL = ""; + String location = ""; try { URL url = new URL(urlString); HttpURLConnection conn; @@ -261,7 +265,6 @@ public class XmlReplayTransport { wr.write(content); wr.flush(); - try { result.requestPayload = content; result.requestPayloadsRaw = contentRaw; @@ -270,26 +273,13 @@ public class XmlReplayTransport { if (400 <= result.responseCode && result.responseCode <= 499){ return result; } - BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String line; - StringBuffer sb = new StringBuffer(); - while ((line = rd.readLine()) != null) { - sb.append(line).append("\r\n"); - } - String msg = sb.toString(); - result.result = msg; - result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE")); - - rd.close(); + readStream(conn, result); } catch (Throwable t){ //System.err.println("ERROR getting content from response: "+t); result.error = t.toString(); } wr.close(); - - String deleteURL = ""; - String location = ""; Map> headers = conn.getHeaderFields(); List locations = headers.get("Location"); if (locations != null){ @@ -303,11 +293,77 @@ public class XmlReplayTransport { result.location = location; result.deleteURL = deleteURL; result.CSID = location; + } catch (Throwable t2){ + result.error = "ERROR in XmlReplayTransport: "+t2; + } + return result; + } + + public static ServiceResult doPOST_PUT_PostMethod(String urlString, String content, Map contentRaw, + String boundary, String method, String contentType, + String authForTest, String fromTestID) throws Exception { + ServiceResult result = new ServiceResult(); + result.method = method; + String deleteURL = ""; + String location = ""; + try { + HttpClient client = new HttpClient(); + PostMethod postMethod = new PostMethod(urlString); + postMethod.setRequestHeader("Accept", "multipart/mixed"); + postMethod.addRequestHeader("Accept", "application/xml"); + postMethod.setRequestHeader("Authorization", "Basic " + authForTest); + postMethod.setRequestHeader("X-XmlReplay-fromTestID", fromTestID); + //this method takes an array of params. Not sure what they expect us to do with a raw post: + // postMethod.setRequestBody(); + int statusCode1 = 0; + String res = ""; + try { + statusCode1 = client.executeMethod(postMethod); + result.responseCode = statusCode1; + //System.out.println("statusCode: "+statusCode1+" statusLine ==>" + postMethod.getStatusLine()); + result.responseMessage = postMethod.getStatusText(); + res = postMethod.getResponseBodyAsString(); + Header[] headers = postMethod.getResponseHeaders("Location"); + if (headers.length>0) { + System.out.println("headers[0]: "+headers[0]); + String locationZero = headers[0].getValue(); + if (locationZero != null){ + String[] segments = locationZero.split("/"); + location = segments[segments.length - 1]; + deleteURL = Tools.glue(urlString, "/", location); + } + } + postMethod.releaseConnection(); + } catch (Throwable t){ + result.error = t.toString(); + } + result.result = res; + result.location = location; + result.deleteURL = deleteURL; + result.CSID = location; } catch (Throwable t2){ result.error = "ERROR in XmlReplayTransport: "+t2; } return result; } + private static void readStream(HttpURLConnection conn, ServiceResult result) throws Throwable { + BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + try { + String line; + StringBuffer sb = new StringBuffer(); + while ((line = rd.readLine()) != null) { + sb.append(line).append("\r\n"); + } + String msg = sb.toString(); + result.result = msg; + result.boundary = PayloadLogger.parseBoundary(conn.getHeaderField("CONTENT-TYPE")); + } finally { + rd.close(); + } + + + } + } diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java index a99cb6cd0..ff3b52933 100755 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/XmlReplayDevTest.java @@ -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)){ diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml index e94aa926e..9e44b4c24 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/dev-master.xml @@ -9,7 +9,7 @@ when you check it in. --> - http://localhost:8180 + http://localhost:8280 @@ -59,7 +59,11 @@ + + + --> + + 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 index 000000000..8e6826700 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/person.xml @@ -0,0 +1,171 @@ + + + + + POST + /cspace-services/personauthorities/ + person/personauthorities_common.xml + + CSPACE3739PersonAuthority + + + + POST + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + + + + POST + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor2 + + + + GET + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority) + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID} + + + GET + /cspace-services/personauthorities/ + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/ + + + + POST + /cspace-services/relations/ + relation/r-1.xml + + ${Person1.CSID} + ${Person2.CSID} + persons + persons + hasBroader + + + + + POST + /cspace-services/relations/ + relation/r-1.xml + + + ${Person2.CSID} + ${Person1.CSID} + persons + persons + hasNarrower + + + + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common_w_relations.xml + + + CSPACE3739PersonAuthority + + + + + + + + POST + /cspace-services/personauthorities/ + person/personauthorities_common.xml + + CSPACE3739PersonAuthority + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorParent + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorChild + + + + + POST + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/ + person/persons_common.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActorChild2 + + + + + + PUT + /cspace-services/personauthorities/urn:cspace:name(CSPACE3739PersonAuthority)/items/${Person1.CSID} + person/persons_common_w_relations.xml + + ${PersonAuth1.CSID} + CSPACE3739PersonAuthority + johnWayneActor + ${Person1.CSID} + ${PersonParent.CSID} + ${PersonChild.CSID} + + + + + GET + /cspace-services/personauthorities/${PersonAuth1.CSID}/items/${Person1.CSID} + + + 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 index 000000000..ad7de6efa --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/personauthorities_common.xml @@ -0,0 +1,11 @@ + + + +${authShortIdentifier} +${authShortIdentifier} +urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier})'${authShortIdentifier}' +PersonAuthority + + + + 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 index 000000000..bd2834b78 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common.xml @@ -0,0 +1,26 @@ + + + + ${inAuthority} + ${shortIdentifier} + urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne' + John Wayne + false + JohnWayne + false + John + Wayne + May 26, 1907 + June 11, 1979 + Winterset, Iowa + + Irish + Scottish + + male + 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 + voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. + + + + 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 index 000000000..bc36c2ab7 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/person/persons_common_w_relations.xml @@ -0,0 +1,70 @@ + + + + ${inAuthority} + ${shortIdentifier} + urn:cspace:org.collectionspace.demo:personauthority:name(${authShortIdentifier}):person:name(${shortIdentifier})'John Wayne' + John Wayne + false + JohnWayne + false + John + Wayne + May 26, 1907 + June 11, 1979 + Winterset, Iowa + + Irish + Scottish + + male + 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 + voice, walk and height. He was also known for his conservative political views and his support in the 1950s for anti-communist positions. + + + + 0 + 40 + 1 + 1 + subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid|subject|object + + ${myCSID} + hasBroader + hasBroader + hasBroader + ${parentCSID} + + ${myCSID} + Person + John Wayne, Me + + + ${parentCSID} + Person + John Wayne 2, the evil twin, Parent + + + + ${childCSID} + hasBroader + hasBroader + hasBroader + ${myCSID} + + ${childCSID} + Person + John Wayne 2, the evil twin, child + + + ${myCSID} + Person + John Wayne + + + + + + + + diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/r-1.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/r-1.xml index 983a839cd..bf6119112 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/r-1.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/r-1.xml @@ -4,16 +4,11 @@ xmlns:ns2="http://collectionspace.org/services/relation" xmlns:ns3="http://collectionspace.org/services/jaxb"> ${documentId1} - - objectexit - + ${documentType1} ${documentId2} - - objectexit - - COLLECTIONOBJECT_INTAKE - - COLLECTIONOBJECT_INTAKE.displayName + ${documentType1} + ${relationshipType} + ${relationshipType} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml index 7f878d5ea..4f4e1ea74 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/relation/relation.xml @@ -16,15 +16,32 @@ /cspace-services/objectexit/ relation/oe1.xml - + POST /cspace-services/relations/ relation/r-1.xml ${oe1.CSID} ${oe2.CSID} + objectexit + objectexit + hasBroader + + + + POST + /cspace-services/relations/ + relation/r-1.xml + + + ${oe2.CSID} + ${oe1.CSID} + objectexit + objectexit + hasBroader + diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index 94d2e32e9..c389af556 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -23,8 +23,11 @@ */ 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 ctx = null; Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM"); @@ -461,27 +443,19 @@ public abstract class AuthorityResource 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 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); } } diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 6421c54db..64820ef53 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -23,15 +23,34 @@ */ 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 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 objectProps.remove(AuthorityItemJAXBSchema.CSID); } + @Override + public void extractAllParts(DocumentWrapper 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 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 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 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 ========================== + } diff --git a/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml b/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml index f1ee390f0..7769d2b43 100644 --- a/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml +++ b/services/common/src/main/cspace/config/services/tenants/collectionspace/tenant-bindings.xml @@ -1271,6 +1271,14 @@ + + + objectNamePropertydisplayName + + objectNumberPropertyshortIdentifier + + + + + objectNamePropertydisplayName + + ctx = createServiceContext(input); return create(input, ctx); } catch (Exception e) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index c606c8bde..891fac1c7 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -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 /** security context */ private SecurityContext securityContext; + private UriInfo uriInfo; + /** * Instantiates a new abstract service context impl. */ @@ -160,7 +163,7 @@ public abstract class AbstractServiceContextImpl * @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 */ @Override public MultivaluedMap getQueryParams() { + if (queryParams == null){ + queryParams = new org.jboss.resteasy.specimpl.MultivaluedMapImpl(); + } return this.queryParams; } + @Override + public MultivaluedMap 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 public void setQueryParams(MultivaluedMap theQueryParams) { this.queryParams = theQueryParams; } + + @Override + public void setUriInfo(UriInfo ui){ + this.uriInfo = ui; + } + + @Override + public UriInfo getUriInfo(){ + return this.uriInfo; + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index 369e2a664..872d04c2d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -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 { /** * 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 { */ public MultivaluedMap getQueryParams(); + public MultivaluedMap getQueryParamsPtr(); + /** * Sets the query params. * * @param queryParams the query params */ public void setQueryParams(MultivaluedMap queryParams); + + public void setUriInfo(UriInfo ui); + + public UriInfo getUriInfo(); + } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 4f4364224..af724ced9 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -82,7 +82,7 @@ import org.dom4j.Document; * @param * @param */ -public abstract class RemoteDocumentModelHandlerImpl +public abstract class RemoteDocumentModelHandlerImpl extends DocumentModelHandler { /** The logger. */ @@ -115,10 +115,14 @@ public abstract class RemoteDocumentModelHandlerImpl List inputParts = ctx.getInput().getParts(); for (PayloadInputPart part : inputParts) { String partLabel = part.getLabel(); - ObjectPartType partMeta = partsMetaMap.get(partLabel); - // extractPart(docModel, partLabel, partMeta); - Map unQObjectProperties = extractPart(docModel, partLabel, partMeta); - addOutputPart(unQObjectProperties, partLabel, partMeta); + try{ + ObjectPartType partMeta = partsMetaMap.get(partLabel); + // extractPart(docModel, partLabel, partMeta); + Map 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) { diff --git a/services/jaxb/src/main/resources/relations_common.xsd b/services/jaxb/src/main/resources/relations_common.xsd index d56054346..8488aa300 100644 --- a/services/jaxb/src/main/resources/relations_common.xsd +++ b/services/jaxb/src/main/resources/relations_common.xsd @@ -52,6 +52,8 @@ + + diff --git a/services/person/client/src/test/resources/log4j.properties b/services/person/client/src/test/resources/log4j.properties index 4519e9992..1a5d8cfb5 100644 --- a/services/person/client/src/test/resources/log4j.properties +++ b/services/person/client/src/test/resources/log4j.properties @@ -19,7 +19,7 @@ log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n #packages -log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.collectionspace=INFO log4j.logger.org.apache=INFO log4j.logger.httpclient=INFO log4j.logger.org.jboss.resteasy=INFO diff --git a/services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd b/services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd index abfb09147..ac4e1eb49 100644 --- a/services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd +++ b/services/relation/3rdparty/nuxeo-platform-cs-relation/src/main/resources/schemas/relations_common.xsd @@ -53,6 +53,8 @@ + + diff --git a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java index 351a60cc6..8ace93f91 100644 --- a/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java +++ b/services/relation/client/src/main/java/org/collectionspace/services/client/RelationClient.java @@ -39,6 +39,9 @@ public class RelationClient extends AbstractPoxServiceClientImpl 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); -- 2.47.3