From f009c6d0bfaca0cd79667af366c584d5c903a796 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 11 May 2010 21:08:05 +0000 Subject: [PATCH] CSPACE-1079: Added getReferencingObjects() support to Organization service. --- .../test/PerformanceTest.java | 2 +- services/intake/client/pom.xml | 5 + .../test/OrganizationAuthRefDocsTest.java | 350 ++++++++++++++++++ .../client/test/PersonAuthRefDocsTest.java | 46 ++- .../services/client/OrgAuthorityClient.java | 14 + .../services/client/OrgAuthorityProxy.java | 15 + .../organization/OrgAuthorityResource.java | 115 +++++- .../client/PersonAuthorityClient.java | 2 +- .../person/PersonAuthorityResource.java | 37 +- 9 files changed, 521 insertions(+), 65 deletions(-) create mode 100644 services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java index 3e01d21e2..0706ccc6d 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java @@ -65,7 +65,7 @@ public class PerformanceTest extends CollectionSpacePerformanceTest { // Get clients for the CollectionSpace services // /** The MA x_ records. */ - private static int MAX_RECORDS = 100; + private static int MAX_RECORDS = 1000; /** * Performance test. diff --git a/services/intake/client/pom.xml b/services/intake/client/pom.xml index 09b15d019..04b698a1c 100644 --- a/services/intake/client/pom.xml +++ b/services/intake/client/pom.xml @@ -52,6 +52,11 @@ org.collectionspace.services.person.client ${project.version} + + org.collectionspace.services + org.collectionspace.services.organization.client + ${project.version} + org.testng diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java new file mode 100644 index 000000000..4c7be741e --- /dev/null +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java @@ -0,0 +1,350 @@ +/** + * 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.OrganizationJAXBSchema; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.IntakeClient; +import org.collectionspace.services.client.OrgAuthorityClient; +import org.collectionspace.services.client.OrgAuthorityClientUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; +import org.collectionspace.services.intake.IntakesCommon; +//import org.collectionspace.services.intake.IntakesCommonList; +import org.collectionspace.services.jaxb.AbstractCommonList; + +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; + +/** + * OrganizationAuthRefDocsTest, carries out tests against a + * deployed and running Organization Service. + * + * $LastChangedRevision: 1327 $ + * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + */ +public class OrganizationAuthRefDocsTest extends BaseServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(OrganizationAuthRefDocsTest.class); + + // Instance variables specific to this test. + final String SERVICE_PATH_COMPONENT = "intakes"; + final String ORGANIZATION_AUTHORITY_NAME = "TestOrganizationAuth"; + private String knownIntakeId = null; + private List intakeIdsCreated = new ArrayList(); + private List orgIdsCreated = new ArrayList(); + private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + private int OK_STATUS = Response.Status.OK.getStatusCode(); + private String orgAuthCSID = null; + private String currentOwnerOrgCSID = null; + private String currentOwnerRefName = null; + private String depositorRefName = null; + private String conditionCheckAssesorRefName = null; + private String insurerRefName = null; + private String fieldCollectorRefName = null; + private String valuerRefName = null; + private final int NUM_AUTH_REF_DOCS_EXPECTED = 1; + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() { + throw new UnsupportedOperationException(); //method not supported (or needed) in this test class + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + throw new UnsupportedOperationException(); //method not supported (or needed) in this test class + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + public void createIntakeWithAuthRefs(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 organization refs and entities + createOrgRefs(); + + IntakeClient intakeClient = new IntakeClient(); + MultipartOutput multipart = createIntakeInstance( + "entryNumber-" + identifier, + "entryDate-" + identifier, + currentOwnerRefName, + depositorRefName, + conditionCheckAssesorRefName, + insurerRefName, + fieldCollectorRefName, + valuerRefName ); + + ClientResponse res = intakeClient.create(multipart); + try { + 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); + } finally { + res.releaseConnection(); + } + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownIntakeId == null){ + knownIntakeId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownIntakeId=" + knownIntakeId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + intakeIdsCreated.add(extractId(res)); + } + + /** + * Creates the organization refs. + */ + protected void createOrgRefs(){ + OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); + String authRefName = + OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false); + MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( + ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName()); + ClientResponse res = orgAuthClient.create(multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + orgAuthCSID = extractId(res); + + currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Olivier Owner", true); + currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName); + orgIdsCreated.add(currentOwnerOrgCSID); + + depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Debbie Depositor", true); + orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName)); + + conditionCheckAssesorRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Andrew Assessor", true); + orgIdsCreated.add(createOrganization("Andrew", "Assessor", conditionCheckAssesorRefName)); + + insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Ingrid Insurer", true); + orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName)); + + fieldCollectorRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Connie Collector", true); + orgIdsCreated.add(createOrganization("Connie", "Collector", fieldCollectorRefName)); + + valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName( + authRefName, "Vince Valuer", true); + orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName)); + + + } + + protected String createOrganization(String shortName, String longName, String refName ) { + OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); + Map orgInfo = new HashMap(); + orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName); + orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, + refName, orgInfo, orgAuthClient.getItemCommonPartName()); + ClientResponse res = orgAuthClient.createItem(orgAuthCSID, 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 = {"createIntakeWithAuthRefs"}) + public void readAndCheckAuthRefDocs(String testName) throws Exception { + + // Perform setup. + testSetup(OK_STATUS, ServiceRequestType.READ,testName); + + // Get the auth ref docs and check them + OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); + ClientResponse refDocListResp = + orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID); + + int statusCode = refDocListResp.getStatus(); + + if(logger.isDebugEnabled()){ + logger.debug(testName + ".getReferencingObjects: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + AuthorityRefDocList list = refDocListResp.getEntity(); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + boolean fFoundIntake = false; + if(iterateThroughList && logger.isDebugEnabled()){ + List items = + list.getAuthorityRefDocItem(); + int i = 0; + logger.debug(testName + ": Docs that use: " + currentOwnerRefName); + for(AuthorityRefDocList.AuthorityRefDocItem item : items){ + logger.debug(testName + ": list-item[" + i + "] " + + item.getDocType() + "(" + + item.getDocId() + ") Name:[" + + item.getDocName() + "] Number:[" + + item.getDocNumber() + "] in field:[" + + item.getSourceField() + "]"); + if(!fFoundIntake && knownIntakeId.equalsIgnoreCase(item.getDocId())) { + fFoundIntake = true; + } + i++; + } + Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!"); + } + } + + + // --------------------------------------------------------------- + // 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() { + String noTest = System.getProperty("noTestCleanup"); + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + IntakeClient intakeClient = new IntakeClient(); + // Note: Any non-success responses are ignored and not reported. + for (String resourceId : intakeIdsCreated) { + ClientResponse res = intakeClient.delete(resourceId); + res.releaseConnection(); + } + // Delete persons before PersonAuth + OrgAuthorityClient personAuthClient = new OrgAuthorityClient(); + for (String resourceId : orgIdsCreated) { + ClientResponse res = personAuthClient.deleteItem(orgAuthCSID, resourceId); + res.releaseConnection(); + } + if (orgAuthCSID != null) { + personAuthClient.delete(orgAuthCSID).releaseConnection(); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createIntakeInstance(String entryNumber, + String entryDate, + String currentOwner, + String depositor, + String conditionCheckAssesor, + String insurer, + String fieldCollector, + String Valuer ) { + IntakesCommon intake = new IntakesCommon(); + intake.setEntryNumber(entryNumber); + intake.setEntryDate(entryDate); + intake.setCurrentOwner(currentOwner); + intake.setDepositor(depositor); + intake.setConditionCheckAssesor(conditionCheckAssesor); + intake.setInsurer(insurer); + intake.setFieldCollector(fieldCollector); + intake.setValuer(Valuer); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new IntakeClient().getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, intake common"); + logger.debug(objectAsXmlString(intake, IntakesCommon.class)); + } + + return multipart; + } +} diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java index 22bc83728..d327824e2 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java @@ -37,12 +37,12 @@ import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.intake.IntakesCommon; -import org.collectionspace.services.intake.IntakesCommonList; +//import org.collectionspace.services.intake.IntakesCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +//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; @@ -68,8 +68,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { final String SERVICE_PATH_COMPONENT = "intakes"; final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private String knownIntakeId = null; - private List intakeIdsCreated = new ArrayList(); - private List personIdsCreated = new ArrayList(); + private List intakeIdsCreated = 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; @@ -126,21 +126,24 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { valuerRefName ); ClientResponse res = intakeClient.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); + try { + 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); + } finally { + res.releaseConnection(); } - 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. @@ -156,6 +159,9 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { intakeIdsCreated.add(extractId(res)); } + /** + * Creates the person refs. + */ protected void createPersonRefs(){ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); String authRefName = @@ -291,14 +297,16 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { // Note: Any non-success responses are ignored and not reported. for (String resourceId : intakeIdsCreated) { ClientResponse res = intakeClient.delete(resourceId); + res.releaseConnection(); } // Delete persons before PersonAuth PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); for (String resourceId : personIdsCreated) { ClientResponse res = personAuthClient.deleteItem(personAuthCSID, resourceId); + res.releaseConnection(); } if (personAuthCSID != null) { - personAuthClient.delete(personAuthCSID); + personAuthClient.delete(personAuthCSID).releaseConnection(); } } diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java index 5894be657..b6b954d33 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -29,6 +29,7 @@ package org.collectionspace.services.client; //import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.organization.OrgauthoritiesCommonList; @@ -165,6 +166,7 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { * @param csid the csid * @return the client response */ + @Override public ClientResponse delete(String csid) { return orgAuthorityProxy.delete(csid); } @@ -178,6 +180,18 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { public ClientResponse readItemList(String vcsid) { return orgAuthorityProxy.readItemList(vcsid); } + + /** + * Gets the referencing objects. + * + * @param parentcsid the parentcsid + * @param csid the csid + * @return the referencing objects + */ + public ClientResponse getReferencingObjects(String parentcsid, String csid) { + return orgAuthorityProxy.getReferencingObjects(parentcsid, csid); + } + /** * Read item list for named authority. diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java index 600e0a6d8..54f2091ce 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java @@ -10,6 +10,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.organization.OrgauthoritiesCommonList; @@ -60,6 +61,20 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @Produces({"application/xml"}) @Path("/{vcsid}/items/") ClientResponse readItemList(@PathParam("vcsid") String vcsid); + + /** + * @param parentcsid + * @param itemcsid + * @param csid + * @return + * @see org.collectionspace.services.client.IntakeProxy#getAuthorityRefs(java.lang.String) + */ + @GET + @Path("{csid}/items/{itemcsid}/refObjs") + @Produces("application/xml") + ClientResponse getReferencingObjects( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid); // List Items for a named authority @GET diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 8edf38210..56af0dd39 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -46,8 +46,10 @@ import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.common.context.MultipartServiceContext; +//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.MultipartServiceContextFactory; import org.collectionspace.services.common.context.ServiceBindingUtils; @@ -58,12 +60,14 @@ 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.repository.RepositoryClient; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.contact.ContactJAXBSchema; import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; @@ -342,6 +346,90 @@ public class OrgAuthorityResource extends return result; } + /** + * Gets the entities referencing this Organization instance. The service type + * can be passed as a query param "type", and must match a configured type + * for the service bindings. If not set, the type defaults to + * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. + * @param parentcsid + * + * @param csid the parent csid + * @param itemcsid the person csid + * @param ui the ui + * + * @return the info for the referencing objects + */ + @GET + @Path("{csid}/items/{itemcsid}/refObjs") + @Produces("application/xml") + public AuthorityRefDocList getReferencingObjects( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @Context UriInfo ui) { + AuthorityRefDocList authRefDocList = null; + if (logger.isDebugEnabled()) { + logger.debug("getReferencingObjects with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid) + || itemcsid == null || "".equals(itemcsid)) { + logger.error("getPerson: missing parentcsid or itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Person with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + // Note that we have to create the service context for the Items, not the main service + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + RepositoryClient repoClient = getRepositoryClient(ctx); + DocumentFilter myFilter = handler.getDocumentFilter(); + String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; + List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); + if (list != null) { + serviceType = list.get(0); + } + DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); + DocumentModel docModel = docWrapper.getWrappedObject(); + String refName = (String)docModel.getPropertyValue(OrganizationJAXBSchema.REF_NAME); + + authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(repoClient, + ctx.getTenantId(), serviceType, refName, + myFilter.getPageSize(), myFilter.getStartPage(), true ); + } 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 parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).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); + } + if (authRefDocList == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Person CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return authRefDocList; + } + + /** * Gets the org authority. * @@ -410,16 +498,14 @@ public class OrgAuthorityResource extends public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) { OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList(); try { - ServiceContext ctx = createServiceContext(); MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); + DocumentFilter myFilter = handler.getDocumentFilter(); String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { myFilter.setWhereClause("orgauthorities_common:refName='" + nameQ + "'"); } - handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); orgAuthorityObjectList = (OrgauthoritiesCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -701,8 +787,7 @@ public class OrgAuthorityResource extends ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method + DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" + "'" + parentcsid + "'"); @@ -714,7 +799,6 @@ public class OrgAuthorityResource extends " LIKE " + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause); } - handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -753,16 +837,15 @@ public class OrgAuthorityResource extends MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+ - ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+ - "='"+parentSpecifier+"'"; + ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+ + "='" + parentSpecifier+"'"; // Need to get an Authority by name ServiceContext ctx = createServiceContext(queryParams); String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.createDocumentFilter();// new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method + DocumentFilter myFilter = handler.getDocumentFilter();// new DocumentFilter(); // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'" myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + @@ -776,9 +859,7 @@ public class OrgAuthorityResource extends " LIKE " + "'%" + partialTerm + "%'"; myFilter.appendWhereClause(ptClause); - } - - handler.setDocumentFilter(myFilter); + } getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (OrganizationsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -977,8 +1058,7 @@ public class OrgAuthorityResource extends ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method + DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter(); myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + ContactJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'" + @@ -987,7 +1067,6 @@ public class OrgAuthorityResource extends ContactJAXBSchema.IN_ITEM + "='" + itemcsid + "'" + " AND ecm:isProxy = 0"); - handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); contactObjectList = (ContactsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java index c34e5ca9a..6145dc9fa 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java @@ -26,7 +26,7 @@ */ package org.collectionspace.services.client; -import javax.ws.rs.PathParam; +//import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; //import org.collectionspace.services.common.authorityref.AuthorityRefList; diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index a02ee7ab2..a1d8a708e 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -355,13 +355,13 @@ public class PersonAuthorityResource extends throw new WebApplicationException(response); } try { + MultivaluedMap queryParams = ui.getQueryParameters(); // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName()); + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); RepositoryClient repoClient = getRepositoryClient(ctx); - DocumentFilter myFilter = handler.createDocumentFilter(); - MultivaluedMap queryParams = ui.getQueryParameters(); - myFilter.setPagination(queryParams); + DocumentFilter myFilter = handler.getDocumentFilter(); String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); if (list != null) { @@ -467,13 +467,10 @@ public class PersonAuthorityResource extends MultivaluedMap queryParams = ui.getQueryParameters(); ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); -//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); -//REM: myFilter.setPagination(queryParams); //FIXME String nameQ = queryParams.getFirst("refName"); if (nameQ != null) { handler.getDocumentFilter().setWhereClause("personauthorities_common:refName='" + nameQ + "'"); } -//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personAuthorityObjectList = (PersonauthoritiesCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -712,9 +709,6 @@ public class PersonAuthorityResource extends ServiceContext ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); -//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); -//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method - // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); @@ -728,7 +722,6 @@ public class PersonAuthorityResource extends "'%" + partialTerm + "%'"; handler.getDocumentFilter().appendWhereClause(ptClause); } -//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -765,23 +758,20 @@ public class PersonAuthorityResource extends @Context UriInfo ui) { PersonsCommonList personObjectList = new PersonsCommonList(); try { - MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+ - ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+ - "='"+parentSpecifier+"'"; + ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME+ + "='" + parentSpecifier+"'"; // Need to get an Authority by name + MultivaluedMap queryParams = ui.getQueryParameters(); ServiceContext ctx = createServiceContext(queryParams); String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); - ctx = createServiceContext(getItemServiceName(), queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); -//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); -//REM: myFilter.setPagination(queryParams); //FIXME // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" - handler.createDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + + handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); // AND persons_common:displayName LIKE '%partialTerm%' @@ -791,10 +781,8 @@ public class PersonAuthorityResource extends PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; - handler.createDocumentFilter().appendWhereClause(ptClause); - } - -//REM: handler.setDocumentFilter(myFilter); + handler.getDocumentFilter().appendWhereClause(ptClause); + } getRepositoryClient(ctx).getFiltered(ctx, handler); personObjectList = (PersonsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { @@ -1000,9 +988,7 @@ public class PersonAuthorityResource extends ServiceContext ctx = createServiceContext(getContactServiceName(), queryParams); DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid); -//REM: DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); -//REM: myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method - handler.createDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + + handler.getDocumentFilter().setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" + ContactJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'" + " AND " + @@ -1010,7 +996,6 @@ public class PersonAuthorityResource extends ContactJAXBSchema.IN_ITEM + "='" + itemcsid + "'" + " AND ecm:isProxy = 0"); -//REM: handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).getFiltered(ctx, handler); contactObjectList = (ContactsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { -- 2.47.3