From: Patrick Schmitz Date: Tue, 2 Mar 2010 08:42:28 +0000 (+0000) Subject: CSPACE-852. Added support in tenant-bindings.xml for authority reference fields in... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=44aa88a6972f8c247c621e1724a7321a951c13af;p=tmp%2Fjakarta-migration.git CSPACE-852. Added support in tenant-bindings.xml for authority reference fields in collectionobject and acquisition schemas. Added {csid}/authorityrefs subresource support to CollectionObject and Acquisition. Refactored the code that was in IntakeDocumentModelHandler (getAuthorityRefs) into RemoteDocumentModelHandlerImpl. Added tests for both services. --- diff --git a/services/acquisition/client/pom.xml b/services/acquisition/client/pom.xml index 5ad554610..7cfe4b51f 100644 --- a/services/acquisition/client/pom.xml +++ b/services/acquisition/client/pom.xml @@ -38,6 +38,11 @@ org.collectionspace.services.client ${cspace.services.client.version} + + org.collectionspace.services + org.collectionspace.services.person.client + ${cspace.services.client.version} + org.testng diff --git a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java index 954d0eedb..2051c24e1 100644 --- a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java +++ b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionClient.java @@ -3,6 +3,7 @@ package org.collectionspace.services.client; import javax.ws.rs.core.Response; import org.collectionspace.services.acquisition.AcquisitionsCommonList; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.ServiceContext; import org.jboss.resteasy.client.ProxyFactory; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; @@ -84,6 +85,15 @@ public class AcquisitionClient extends AbstractServiceClientImpl { return acquisitionProxy.read(csid); } + /** + * @param csid + * @return + * @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String) + */ + public ClientResponse getAuthorityRefs(String csid) { + return acquisitionProxy.getAuthorityRefs(csid); + } + /** * @param intake * @return diff --git a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java index 0a7c02e45..233ccad27 100644 --- a/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java +++ b/services/acquisition/client/src/main/java/org/collectionspace/services/client/AcquisitionProxy.java @@ -11,6 +11,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import org.collectionspace.services.acquisition.AcquisitionsCommonList; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; @@ -36,6 +37,12 @@ public interface AcquisitionProxy { @Path("/{csid}") ClientResponse read(@PathParam("csid") String csid); + // List Authority references + @GET + @Produces({"application/xml"}) + @Path("/{csid}/authorityrefs/") + ClientResponse getAuthorityRefs(@PathParam("csid") String csid); + //(U)pdate @PUT @Path("/{csid}") diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java new file mode 100644 index 000000000..43aabc68e --- /dev/null +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java @@ -0,0 +1,299 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.PersonJAXBSchema; +import org.collectionspace.services.client.AcquisitionClient; +import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.acquisition.AcquisitionsCommon; +import org.collectionspace.services.acquisition.AcquisitionsCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * AcquisitionAuthRefsTest, carries out tests against a + * deployed and running Acquisition Service. + * + * $LastChangedRevision: 1327 $ + * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + */ +public class AcquisitionAuthRefsTest extends BaseServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(AcquisitionAuthRefsTest.class); + + // Instance variables specific to this test. + private AcquisitionClient acquisitionClient = new AcquisitionClient(); + private PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + final String SERVICE_PATH_COMPONENT = "acquisitions"; + final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + private String knownResourceId = null; + private List acquisitionIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + private int OK_STATUS = Response.Status.OK.getStatusCode(); + private String personAuthCSID = null; + private String acquisitionAuthorizerRefName = null; + private String acquisitionFundingSourceRefName = null; + // Not ready for multiples, yet + //private String acquisitionSourcesRefName = null; + private String fieldCollectorRefName = null; + private final int NUM_AUTH_REFS_EXPECTED = 3; + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + public void createWithAuthRefs(String testName) throws Exception { + + testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + + // Create all the person refs and entities + createPersonRefs(); + + MultipartOutput multipart = createAcquisitionInstance( + "April 1, 2010", + acquisitionAuthorizerRefName, + acquisitionFundingSourceRefName, + fieldCollectorRefName ); + + ClientResponse res = acquisitionClient.create(multipart); + + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + acquisitionIdsCreated.add(extractId(res)); + } + + protected void createPersonRefs(){ + String authRefName = + PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( + PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + ClientResponse res = personAuthClient.create(multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + personAuthCSID = extractId(res); + + acquisitionAuthorizerRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Annie Authorizer", true); + personIdsCreated.add(createPerson("Annie", "Authorizer", acquisitionAuthorizerRefName)); + + acquisitionFundingSourceRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Sammy Source", true); + personIdsCreated.add(createPerson("Sammy", "Source", acquisitionFundingSourceRefName)); + + + fieldCollectorRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Connie Collector", true); + personIdsCreated.add(createPerson("Connie", "Collector", fieldCollectorRefName)); + } + + protected String createPerson(String firstName, String surName, String refName ) { + Map personInfo = new HashMap(); + personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); + personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + MultipartOutput multipart = + PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, + refName, personInfo, personAuthClient.getItemCommonPartName()); + ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + return extractId(res); + } + + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"createWithAuthRefs"}) + public void readAndCheckAuthRefs(String testName) throws Exception { + + // Perform setup. + testSetup(OK_STATUS, ServiceRequestType.READ,testName); + + // Submit the request to the service and store the response. + ClientResponse res = acquisitionClient.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ".read: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + MultipartInput input = (MultipartInput) res.getEntity(); + AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input, + acquisitionClient.getCommonPartName(), AcquisitionsCommon.class); + Assert.assertNotNull(acquisition); + // Check a couple of fields + Assert.assertEquals(acquisition.getAcquisitionAuthorizer(), acquisitionAuthorizerRefName); + Assert.assertEquals(acquisition.getFieldCollector(), fieldCollectorRefName); + + // Get the auth refs and check them + ClientResponse res2 = acquisitionClient.getAuthorityRefs(knownResourceId); + statusCode = res2.getStatus(); + + if(logger.isDebugEnabled()){ + logger.debug(testName + ".getAuthorityRefs: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + AuthorityRefList list = res2.getEntity(); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + List items = + list.getAuthorityRefItem(); + int i = 0; + for(AuthorityRefList.AuthorityRefItem item : items){ + logger.debug(testName + ": list-item[" + i + "] Field:" + + item.getSourceField() + "= " + + item.getAuthDisplayName() + + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + Assert.assertEquals(i, NUM_AUTH_REFS_EXPECTED, "Did not find all authrefs!"); + } + } + + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + // @AfterClass(alwaysRun=true) + public void cleanUp() { + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + // Note: Any non-success responses are ignored and not reported. + for (String resourceId : acquisitionIdsCreated) { + ClientResponse res = acquisitionClient.delete(resourceId); + } + // Delete persons before PersonAuth + for (String resourceId : personIdsCreated) { + ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + } + ClientResponse res = personAuthClient.delete(personAuthCSID); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createAcquisitionInstance( + String accessionDate, + String acquisitionAuthorizer, + String acquisitionFundingSource, + String fieldCollector ) { + AcquisitionsCommon acquisition = new AcquisitionsCommon(); + acquisition.setAccessionDate(accessionDate); + acquisition.setAcquisitionAuthorizer(acquisitionAuthorizer); + acquisition.setAcquisitionFundingSource(acquisitionFundingSource); + acquisition.setFieldCollector(fieldCollector); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(acquisition, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", acquisitionClient.getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, acquisition common"); + logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class)); + } + + return multipart; + } +} diff --git a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java index 1db3cfadf..910b733f2 100644 --- a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java +++ b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java @@ -23,6 +23,8 @@ */ package org.collectionspace.services.acquisition; +import java.util.List; + import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -39,18 +41,23 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; +import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.util.HttpResponseCodes; +import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -308,6 +315,38 @@ public class AcquisitionResource throw new WebApplicationException(response); } return acquisitionObjectList; - } + } + + @GET + @Path("{csid}/authorityrefs") + @Produces("application/xml") + public AuthorityRefList getAuthorityRefs( + @PathParam("csid") String csid, + @Context UriInfo ui) { + AuthorityRefList authRefList = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentWrapper docWrapper = + getRepositoryClient(ctx).getDoc(ctx, csid); + RemoteDocumentModelHandlerImpl handler + = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx); + List authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef"); + String prefix = ctx.getCommonPartLabel()+":"; + authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields); + } 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 getAuthorityRefs", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } + } diff --git a/services/collectionobject/client/pom.xml b/services/collectionobject/client/pom.xml index 95f3cc5ce..c71cab028 100644 --- a/services/collectionobject/client/pom.xml +++ b/services/collectionobject/client/pom.xml @@ -37,6 +37,11 @@ org.collectionspace.services.client ${cspace.services.client.version} + + org.collectionspace.services + org.collectionspace.services.person.client + ${cspace.services.client.version} + org.testng diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index a342a9580..1f1e02019 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -35,6 +35,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.query.IQueryManager; import org.jboss.resteasy.client.ProxyFactory; @@ -84,6 +85,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { /** * Read list. * + * @see org.collectionspace.services.client.CollectionObjectProxy#readList() * @return the client response< collectionobjects common list> */ public ClientResponse readList() { @@ -97,6 +99,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * This is an intentionally empty method that is used for performance test * to get a rough time estimate of the client to server response-request overhead. * + * @see org.collectionspace.services.client.CollectionObjectProxy#roundtrip() * @return the client response< response> */ public ClientResponse roundtrip() { @@ -108,6 +111,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * * @param keywords the keywords * + * @see org.collectionspace.services.client.CollectionObjectProxy#keywordSearch() * @return the client response< collectionobjects common list> */ public ClientResponse keywordSearch(String keywords) { @@ -120,17 +124,29 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * * @param csid the csid * + * @see org.collectionspace.services.client.CollectionObjectProxy#keywordSearch() * @return the client response< multipart input> */ public ClientResponse read(String csid) { return collectionObjectProxy.read(csid); } + /** + * @param csid + * @return + * @see org.collectionspace.services.client.CollectionObjectProxy#getAuthorityRefs(java.lang.String) + */ + public ClientResponse getAuthorityRefs(String csid) { + return collectionObjectProxy.getAuthorityRefs(csid); + } + + /** * Creates the. * * @param multipart the multipart * + * @see org.collectionspace.services.client.CollectionObjectProxy#create() * @return the client response< response> */ public ClientResponse create(MultipartOutput multipart) { @@ -143,6 +159,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * @param csid the csid * @param multipart the multipart * + * @see org.collectionspace.services.client.CollectionObjectProxy#update() * @return the client response< multipart input> */ public ClientResponse update(String csid, MultipartOutput multipart) { @@ -154,6 +171,7 @@ public class CollectionObjectClient extends AbstractServiceClientImpl { * * @param csid the csid * + * @see org.collectionspace.services.client.CollectionObjectProxy#delete() * @return the client response< response> */ public ClientResponse delete(String csid) { diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java index 9928ef42c..d0e0a4dcf 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java @@ -13,6 +13,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -51,6 +52,13 @@ public interface CollectionObjectProxy { @GET @Path("/{csid}") ClientResponse read(@PathParam("csid") String csid); + + // List Authority references + @GET + @Produces({"application/xml"}) + @Path("/{csid}/authorityrefs/") + ClientResponse getAuthorityRefs(@PathParam("csid") String csid); + //(U)pdate @PUT diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java new file mode 100644 index 000000000..970bbbe03 --- /dev/null +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java @@ -0,0 +1,307 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.PersonJAXBSchema; +import org.collectionspace.services.client.CollectionObjectClient; +import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.collectionobject.CollectionobjectsCommon; +import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CollectionObjectAuthRefsTest, carries out tests against a + * deployed and running CollectionObject Service. + * + * $LastChangedRevision: 1327 $ + * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + */ +public class CollectionObjectAuthRefsTest extends BaseServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(CollectionObjectAuthRefsTest.class); + + // Instance variables specific to this test. + private CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + private PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + final String SERVICE_PATH_COMPONENT = "collectionobjects"; + final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + private String knownResourceId = null; + private List collectionObjectIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + private int OK_STATUS = Response.Status.OK.getStatusCode(); + private String personAuthCSID = null; + private String contentOrganizationRefName = null; + private String contentPeopleRefName = null; + private String contentPersonRefName = null; + private String inscriberRefName = null; + private final int NUM_AUTH_REFS_EXPECTED = 4; + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + public void createWithAuthRefs(String testName) throws Exception { + + testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + + // Create all the person refs and entities + createPersonRefs(); + + MultipartOutput multipart = createCollectionObjectInstance( + "Obj Title", + "ObjNum-1234", + contentOrganizationRefName, + contentPeopleRefName, + contentPersonRefName, + inscriberRefName ); + + ClientResponse res = collectionObjectClient.create(multipart); + + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + collectionObjectIdsCreated.add(extractId(res)); + } + + protected void createPersonRefs(){ + String authRefName = + PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( + PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + ClientResponse res = personAuthClient.create(multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + personAuthCSID = extractId(res); + + contentOrganizationRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Omni Org", true); + personIdsCreated.add(createPerson("Omni", "Org", contentOrganizationRefName)); + + contentPeopleRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Pushy People", true); + personIdsCreated.add(createPerson("Pushy", "People", contentPeopleRefName)); + + contentPersonRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Connie ContactPerson", true); + personIdsCreated.add(createPerson("Connie", "ContactPerson", contentPersonRefName)); + + inscriberRefName = PersonAuthorityClientUtils.createPersonRefName( + authRefName, "Ingrid Inscriber", true); + personIdsCreated.add(createPerson("Ingrid", "Inscriber", inscriberRefName)); + } + + protected String createPerson(String firstName, String surName, String refName ) { + Map personInfo = new HashMap(); + personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); + personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + MultipartOutput multipart = + PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, + refName, personInfo, personAuthClient.getItemCommonPartName()); + ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + return extractId(res); + } + + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"createWithAuthRefs"}) + public void readAndCheckAuthRefs(String testName) throws Exception { + + // Perform setup. + testSetup(OK_STATUS, ServiceRequestType.READ,testName); + + // Submit the request to the service and store the response. + ClientResponse res = collectionObjectClient.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ".read: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + MultipartInput input = (MultipartInput) res.getEntity(); + CollectionobjectsCommon collectionObject = (CollectionobjectsCommon) extractPart(input, + collectionObjectClient.getCommonPartName(), CollectionobjectsCommon.class); + Assert.assertNotNull(collectionObject); + // Check a couple of fields + Assert.assertEquals(collectionObject.getContentOrganization(), contentOrganizationRefName); + Assert.assertEquals(collectionObject.getInscriber(), inscriberRefName); + + // Get the auth refs and check them + ClientResponse res2 = collectionObjectClient.getAuthorityRefs(knownResourceId); + statusCode = res2.getStatus(); + + if(logger.isDebugEnabled()){ + logger.debug(testName + ".getAuthorityRefs: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + AuthorityRefList list = res2.getEntity(); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + List items = + list.getAuthorityRefItem(); + int i = 0; + for(AuthorityRefList.AuthorityRefItem item : items){ + logger.debug(testName + ": list-item[" + i + "] Field:" + + item.getSourceField() + "= " + + item.getAuthDisplayName() + + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + Assert.assertEquals(i, NUM_AUTH_REFS_EXPECTED, "Did not find all authrefs!"); + } + } + + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + // @AfterClass(alwaysRun=true) + public void cleanUp() { + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + // Note: Any non-success responses are ignored and not reported. + for (String resourceId : collectionObjectIdsCreated) { + ClientResponse res = collectionObjectClient.delete(resourceId); + } + // Delete persons before PersonAuth + for (String resourceId : personIdsCreated) { + ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + } + ClientResponse res = personAuthClient.delete(personAuthCSID); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createCollectionObjectInstance( + String title, + String objNum, + String contentOrganization, + String contentPeople, + String contentPerson, + String inscriber ) { + CollectionobjectsCommon collectionObject = new CollectionobjectsCommon(); + collectionObject.setTitle(title); + collectionObject.setObjectNumber(objNum); + collectionObject.setContentOrganization(contentOrganization); + collectionObject.setContentPeople(contentPeople); + collectionObject.setContentPerson(contentPerson); + collectionObject.setInscriber(inscriber); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, collectionObject common"); + logger.debug(objectAsXmlString(collectionObject, CollectionobjectsCommon.class)); + } + + return multipart; + } +} diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 6785a488e..ac027467a 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -25,19 +25,17 @@ */ package org.collectionspace.services.collectionobject; -import java.util.List; import java.util.ArrayList; -import java.util.Iterator; -import java.lang.reflect.Type; +import java.util.List; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; import javax.ws.rs.DELETE; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; +import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; @@ -45,33 +43,33 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.common.query.QueryManager; -import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; +import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.BadRequestException; -import org.collectionspace.services.common.document.DocumentNotFoundException; -import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.query.IQueryManager; +import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.security.UnauthorizedException; -import org.jboss.resteasy.plugins.providers.multipart.InputPart; +import org.collectionspace.services.intake.IntakeResource; +import org.collectionspace.services.intake.IntakesCommonList; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.relation.NewRelationResource; +import org.collectionspace.services.relation.RelationsCommonList; +import org.collectionspace.services.relation.RelationshipType; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.jboss.resteasy.util.HttpResponseCodes; +import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.collectionspace.services.intake.IntakesCommonList; -import org.collectionspace.services.intake.IntakeResource; - -import org.collectionspace.services.relation.NewRelationResource; -import org.collectionspace.services.relation.RelationshipType; -import org.collectionspace.services.relation.RelationsCommonList; -import org.collectionspace.services.relation.RelationsCommon; - /** * The Class CollectionObjectResource. @@ -393,6 +391,37 @@ public class CollectionObjectResource return result; } + + @GET + @Path("{csid}/authorityrefs") + @Produces("application/xml") + public AuthorityRefList getAuthorityRefs( + @PathParam("csid") String csid, + @Context UriInfo ui) { + AuthorityRefList authRefList = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentWrapper docWrapper = + getRepositoryClient(ctx).getDoc(ctx, csid); + RemoteDocumentModelHandlerImpl handler + = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx); + List authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef"); + String prefix = ctx.getCommonPartLabel()+":"; + authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields); + } 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 getAuthorityRefs", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } /** * Roundtrip. diff --git a/services/common/src/main/config/tenant-bindings.xml b/services/common/src/main/config/tenant-bindings.xml index 8345e9b06..fd6177686 100644 --- a/services/common/src/main/config/tenant-bindings.xml +++ b/services/common/src/main/config/tenant-bindings.xml @@ -39,6 +39,12 @@ + + authRefcontentOrganization + authRefcontentPeople + authRefcontentPerson + authRefinscriber + - + + authRefacquisitionAuthorizer + authRefacquisitionFundingSource + + authReffieldCollector + + 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 3e86596f8..6efb988a7 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 @@ -29,13 +29,19 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; + +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.BadRequestException; import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.service.ObjectPartType; +import org.collectionspace.services.common.vocabulary.RefNameUtils; import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.nuxeo.ecm.core.api.DocumentModel; @@ -182,4 +188,48 @@ public abstract class RemoteDocumentModelHandlerImpl ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType()); } //TODO: handle other media types } + + public AuthorityRefList getAuthorityRefs( + DocumentWrapper docWrapper, + String pathPrefix, + List authRefFields) { + AuthorityRefList authRefList = new AuthorityRefList(); + try { + DocumentModel docModel = docWrapper.getWrappedObject(); + List list = + authRefList.getAuthorityRefItem(); + + for(String field:authRefFields){ + String refName = (String)docModel.getPropertyValue(pathPrefix+field); + if(refName==null) + continue; + try{ + RefNameUtils.AuthorityTermInfo termInfo = + RefNameUtils.parseAuthorityTermInfo(refName); + AuthorityRefList.AuthorityRefItem ilistItem = + new AuthorityRefList.AuthorityRefItem(); + ilistItem.setRefName(refName); + ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName); + ilistItem.setItemDisplayName(termInfo.displayName); + ilistItem.setSourceField(field); + ilistItem.setUri(termInfo.getRelativeUri()); + list.add(ilistItem); + } catch( Exception e ) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityRefs", e); + } + } + } + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityRefs", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } + + } diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java index e6bd2f786..159d79696 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java @@ -23,18 +23,16 @@ */ package org.collectionspace.services.intake; -import java.util.Iterator; import java.util.List; -import java.util.Map; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; import javax.ws.rs.DELETE; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; +import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; @@ -42,28 +40,22 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.IntakeJAXBSchema; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; - -import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentFilter; -import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.security.UnauthorizedException; -import org.collectionspace.services.common.service.ObjectPartType; -import org.collectionspace.services.common.vocabulary.RefNameUtils; -import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem; -import org.collectionspace.services.intake.nuxeo.IntakeDocumentModelHandler; -import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.util.HttpResponseCodes; @@ -218,7 +210,8 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl { ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); - IntakeDocumentModelHandler handler = (IntakeDocumentModelHandler)createDocumentHandler(ctx); + RemoteDocumentModelHandlerImpl handler + = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx); List authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues("authRef"); String prefix = ctx.getCommonPartLabel()+":"; authRefList = handler.getAuthorityRefs(docWrapper, prefix, authRefFields); diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java index 15b7c873c..30107afa3 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/nuxeo/IntakeDocumentModelHandler.java @@ -26,25 +26,11 @@ package org.collectionspace.services.intake.nuxeo; import java.util.Iterator; import java.util.List; -import javax.ws.rs.PathParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - import org.collectionspace.services.IntakeJAXBSchema; -import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.common.context.MultipartServiceContextFactory; -import org.collectionspace.services.common.context.MultipartServiceContextImpl; -import org.collectionspace.services.common.context.ServiceContext; -import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.DocumentWrapper; -import org.collectionspace.services.common.security.UnauthorizedException; -import org.collectionspace.services.common.vocabulary.RefNameUtils; import org.collectionspace.services.intake.IntakesCommon; import org.collectionspace.services.intake.IntakesCommonList; import org.collectionspace.services.intake.IntakesCommonList.IntakeListItem; - import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.nuxeo.ecm.core.api.DocumentModel; @@ -152,48 +138,6 @@ public class IntakeDocumentModelHandler public String getQProperty(String prop) { return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop; } - - public AuthorityRefList getAuthorityRefs( - DocumentWrapper docWrapper, - String pathPrefix, - List authRefFields) { - AuthorityRefList authRefList = new AuthorityRefList(); - try { - DocumentModel docModel = docWrapper.getWrappedObject(); - List list = - authRefList.getAuthorityRefItem(); - - for(String field:authRefFields){ - String refName = (String)docModel.getPropertyValue(pathPrefix+field); - if(refName==null) - continue; - try{ - RefNameUtils.AuthorityTermInfo termInfo = - RefNameUtils.parseAuthorityTermInfo(refName); - AuthorityRefList.AuthorityRefItem ilistItem = - new AuthorityRefList.AuthorityRefItem(); - ilistItem.setRefName(refName); - ilistItem.setAuthDisplayName(termInfo.inAuthority.displayName); - ilistItem.setItemDisplayName(termInfo.displayName); - ilistItem.setSourceField(field); - ilistItem.setUri(termInfo.getRelativeUri()); - list.add(ilistItem); - } catch( Exception e ) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getAuthorityRefs", e); - } - } - } - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getIntakeList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return authRefList; - } - + }