// Get clients for the CollectionSpace services
//
/** The MA x_ records. */
- private static int MAX_RECORDS = 100;
+ private static int MAX_RECORDS = 1000;
/**
* Performance test.
<artifactId>org.collectionspace.services.person.client</artifactId>\r
<version>${project.version}</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.organization.client</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
<!-- External dependencies --> \r
<dependency>\r
<groupId>org.testng</groupId>\r
--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.collectionspace.services.client.test;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.collectionspace.services.OrganizationJAXBSchema;\r
+import org.collectionspace.services.client.CollectionSpaceClient;\r
+import org.collectionspace.services.client.IntakeClient;\r
+import org.collectionspace.services.client.OrgAuthorityClient;\r
+import org.collectionspace.services.client.OrgAuthorityClientUtils;\r
+import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
+import org.collectionspace.services.intake.IntakesCommon;\r
+//import org.collectionspace.services.intake.IntakesCommonList;\r
+import org.collectionspace.services.jaxb.AbstractCommonList;\r
+\r
+import org.jboss.resteasy.client.ClientResponse;\r
+\r
+//import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
+import org.testng.Assert;\r
+import org.testng.annotations.AfterClass;\r
+import org.testng.annotations.Test;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * OrganizationAuthRefDocsTest, carries out tests against a\r
+ * deployed and running Organization Service.\r
+ *\r
+ * $LastChangedRevision: 1327 $\r
+ * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $\r
+ */\r
+public class OrganizationAuthRefDocsTest extends BaseServiceTest {\r
+\r
+ private final Logger logger =\r
+ LoggerFactory.getLogger(OrganizationAuthRefDocsTest.class);\r
+\r
+ // Instance variables specific to this test.\r
+ final String SERVICE_PATH_COMPONENT = "intakes";\r
+ final String ORGANIZATION_AUTHORITY_NAME = "TestOrganizationAuth";\r
+ private String knownIntakeId = null;\r
+ private List<String> intakeIdsCreated = new ArrayList<String>();\r
+ private List<String> orgIdsCreated = new ArrayList<String>();\r
+ private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();\r
+ private int OK_STATUS = Response.Status.OK.getStatusCode();\r
+ private String orgAuthCSID = null; \r
+ private String currentOwnerOrgCSID = null; \r
+ private String currentOwnerRefName = null;\r
+ private String depositorRefName = null;\r
+ private String conditionCheckAssesorRefName = null;\r
+ private String insurerRefName = null;\r
+ private String fieldCollectorRefName = null;\r
+ private String valuerRefName = null;\r
+ private final int NUM_AUTH_REF_DOCS_EXPECTED = 1;\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()\r
+ */\r
+ @Override\r
+ protected CollectionSpaceClient getClientInstance() {\r
+ throw new UnsupportedOperationException(); //method not supported (or needed) in this test class\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)\r
+ */\r
+ @Override\r
+ protected AbstractCommonList getAbstractCommonList(\r
+ ClientResponse<AbstractCommonList> response) {\r
+ throw new UnsupportedOperationException(); //method not supported (or needed) in this test class\r
+ }\r
+\r
+ // ---------------------------------------------------------------\r
+ // CRUD tests : CREATE tests\r
+ // ---------------------------------------------------------------\r
+ // Success outcomes\r
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)\r
+ public void createIntakeWithAuthRefs(String testName) throws Exception {\r
+\r
+ testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName);\r
+\r
+ // Submit the request to the service and store the response.\r
+ String identifier = createIdentifier();\r
+ \r
+ // Create all the organization refs and entities\r
+ createOrgRefs();\r
+\r
+ IntakeClient intakeClient = new IntakeClient();\r
+ MultipartOutput multipart = createIntakeInstance(\r
+ "entryNumber-" + identifier,\r
+ "entryDate-" + identifier,\r
+ currentOwnerRefName,\r
+ depositorRefName,\r
+ conditionCheckAssesorRefName,\r
+ insurerRefName,\r
+ fieldCollectorRefName,\r
+ valuerRefName );\r
+\r
+ ClientResponse<Response> res = intakeClient.create(multipart);\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ \r
+ // Check the status code of the response: does it match\r
+ // the expected response(s)?\r
+ //\r
+ // Specifically:\r
+ // Does it fall within the set of valid status codes?\r
+ // Does it exactly match the expected status code?\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug(testName + ": status = " + statusCode);\r
+ }\r
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);\r
+ } finally {\r
+ res.releaseConnection();\r
+ }\r
+\r
+ // Store the ID returned from the first resource created\r
+ // for additional tests below.\r
+ if (knownIntakeId == null){\r
+ knownIntakeId = extractId(res);\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug(testName + ": knownIntakeId=" + knownIntakeId);\r
+ }\r
+ }\r
+ \r
+ // Store the IDs from every resource created by tests,\r
+ // so they can be deleted after tests have been run.\r
+ intakeIdsCreated.add(extractId(res));\r
+ }\r
+ \r
+ /**\r
+ * Creates the organization refs.\r
+ */\r
+ protected void createOrgRefs(){\r
+ OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+ String authRefName = \r
+ OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false);\r
+ MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(\r
+ ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName());\r
+ ClientResponse<Response> res = orgAuthClient.create(multipart);\r
+ int statusCode = res.getStatus();\r
+\r
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ Assert.assertEquals(statusCode, CREATED_STATUS);\r
+ orgAuthCSID = extractId(res);\r
+ \r
+ currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Olivier Owner", true);\r
+ currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName);\r
+ orgIdsCreated.add(currentOwnerOrgCSID);\r
+ \r
+ depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Debbie Depositor", true);\r
+ orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName));\r
+ \r
+ conditionCheckAssesorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Andrew Assessor", true);\r
+ orgIdsCreated.add(createOrganization("Andrew", "Assessor", conditionCheckAssesorRefName));\r
+ \r
+ insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Ingrid Insurer", true);\r
+ orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName));\r
+ \r
+ fieldCollectorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Connie Collector", true);\r
+ orgIdsCreated.add(createOrganization("Connie", "Collector", fieldCollectorRefName));\r
+ \r
+ valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
+ authRefName, "Vince Valuer", true);\r
+ orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName));\r
+ \r
+\r
+ }\r
+ \r
+ protected String createOrganization(String shortName, String longName, String refName ) {\r
+ OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+ Map<String, String> orgInfo = new HashMap<String,String>();\r
+ orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName);\r
+ orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName);\r
+ MultipartOutput multipart = \r
+ OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, \r
+ refName, orgInfo, orgAuthClient.getItemCommonPartName());\r
+ ClientResponse<Response> res = orgAuthClient.createItem(orgAuthCSID, multipart);\r
+ int statusCode = res.getStatus();\r
+\r
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ Assert.assertEquals(statusCode, CREATED_STATUS);\r
+ return extractId(res);\r
+ }\r
+\r
+ // Success outcomes\r
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,\r
+ dependsOnMethods = {"createIntakeWithAuthRefs"})\r
+ public void readAndCheckAuthRefDocs(String testName) throws Exception {\r
+\r
+ // Perform setup.\r
+ testSetup(OK_STATUS, ServiceRequestType.READ,testName);\r
+ \r
+ // Get the auth ref docs and check them\r
+ OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
+ ClientResponse<AuthorityRefDocList> refDocListResp =\r
+ orgAuthClient.getReferencingObjects(orgAuthCSID, currentOwnerOrgCSID);\r
+\r
+ int statusCode = refDocListResp.getStatus();\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug(testName + ".getReferencingObjects: status = " + statusCode);\r
+ }\r
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),\r
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);\r
+ AuthorityRefDocList list = refDocListResp.getEntity();\r
+\r
+ // Optionally output additional data about list members for debugging.\r
+ boolean iterateThroughList = true;\r
+ boolean fFoundIntake = false;\r
+ if(iterateThroughList && logger.isDebugEnabled()){\r
+ List<AuthorityRefDocList.AuthorityRefDocItem> items =\r
+ list.getAuthorityRefDocItem();\r
+ int i = 0;\r
+ logger.debug(testName + ": Docs that use: " + currentOwnerRefName);\r
+ for(AuthorityRefDocList.AuthorityRefDocItem item : items){\r
+ logger.debug(testName + ": list-item[" + i + "] " +\r
+ item.getDocType() + "(" +\r
+ item.getDocId() + ") Name:[" +\r
+ item.getDocName() + "] Number:[" +\r
+ item.getDocNumber() + "] in field:[" +\r
+ item.getSourceField() + "]");\r
+ if(!fFoundIntake && knownIntakeId.equalsIgnoreCase(item.getDocId())) {\r
+ fFoundIntake = true;\r
+ }\r
+ i++;\r
+ }\r
+ Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!");\r
+ }\r
+ }\r
+\r
+\r
+ // ---------------------------------------------------------------\r
+ // Cleanup of resources created during testing\r
+ // ---------------------------------------------------------------\r
+\r
+ /**\r
+ * Deletes all resources created by tests, after all tests have been run.\r
+ *\r
+ * This cleanup method will always be run, even if one or more tests fail.\r
+ * For this reason, it attempts to remove all resources created\r
+ * at any point during testing, even if some of those resources\r
+ * may be expected to be deleted by certain tests.\r
+ */\r
+ @AfterClass(alwaysRun=true)\r
+ public void cleanUp() {\r
+ String noTest = System.getProperty("noTestCleanup");\r
+ if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Skipping Cleanup phase ...");\r
+ }\r
+ return;\r
+ }\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Cleaning up temporary resources created for testing ...");\r
+ }\r
+ IntakeClient intakeClient = new IntakeClient();\r
+ // Note: Any non-success responses are ignored and not reported.\r
+ for (String resourceId : intakeIdsCreated) {\r
+ ClientResponse<Response> res = intakeClient.delete(resourceId);\r
+ res.releaseConnection();\r
+ }\r
+ // Delete persons before PersonAuth\r
+ OrgAuthorityClient personAuthClient = new OrgAuthorityClient();\r
+ for (String resourceId : orgIdsCreated) {\r
+ ClientResponse<Response> res = personAuthClient.deleteItem(orgAuthCSID, resourceId);\r
+ res.releaseConnection();\r
+ }\r
+ if (orgAuthCSID != null) {\r
+ personAuthClient.delete(orgAuthCSID).releaseConnection();\r
+ }\r
+ }\r
+\r
+ // ---------------------------------------------------------------\r
+ // Utility methods used by tests above\r
+ // ---------------------------------------------------------------\r
+ @Override\r
+ public String getServicePathComponent() {\r
+ return SERVICE_PATH_COMPONENT;\r
+ }\r
+\r
+ private MultipartOutput createIntakeInstance(String entryNumber,\r
+ String entryDate,\r
+ String currentOwner,\r
+ String depositor,\r
+ String conditionCheckAssesor,\r
+ String insurer,\r
+ String fieldCollector,\r
+ String Valuer ) {\r
+ IntakesCommon intake = new IntakesCommon();\r
+ intake.setEntryNumber(entryNumber);\r
+ intake.setEntryDate(entryDate);\r
+ intake.setCurrentOwner(currentOwner);\r
+ intake.setDepositor(depositor);\r
+ intake.setConditionCheckAssesor(conditionCheckAssesor);\r
+ intake.setInsurer(insurer);\r
+ intake.setFieldCollector(fieldCollector);\r
+ intake.setValuer(Valuer);\r
+ MultipartOutput multipart = new MultipartOutput();\r
+ OutputPart commonPart =\r
+ multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);\r
+ commonPart.getHeaders().add("label", new IntakeClient().getCommonPartName());\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("to be created, intake common");\r
+ logger.debug(objectAsXmlString(intake, IntakesCommon.class));\r
+ }\r
+\r
+ return multipart;\r
+ }\r
+}\r
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;
final String SERVICE_PATH_COMPONENT = "intakes";
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
private String knownIntakeId = null;
- private List<String> intakeIdsCreated = new ArrayList();
- private List<String> personIdsCreated = new ArrayList();
+ private List<String> intakeIdsCreated = new ArrayList<String>();
+ private List<String> personIdsCreated = new ArrayList<String>();
private int CREATED_STATUS = Response.Status.CREATED.getStatusCode();
private int OK_STATUS = Response.Status.OK.getStatusCode();
private String personAuthCSID = null;
valuerRefName );
ClientResponse<Response> 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.
intakeIdsCreated.add(extractId(res));
}
+ /**
+ * Creates the person refs.
+ */
protected void createPersonRefs(){
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
String authRefName =
// Note: Any non-success responses are ignored and not reported.
for (String resourceId : intakeIdsCreated) {
ClientResponse<Response> res = intakeClient.delete(resourceId);
+ res.releaseConnection();
}
// Delete persons before PersonAuth
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
for (String resourceId : personIdsCreated) {
ClientResponse<Response> res = personAuthClient.deleteItem(personAuthCSID, resourceId);
+ res.releaseConnection();
}
if (personAuthCSID != null) {
- personAuthClient.delete(personAuthCSID);
+ personAuthClient.delete(personAuthCSID).releaseConnection();
}
}
//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;
* @param csid the csid
* @return the client response
*/
+ @Override
public ClientResponse<Response> delete(String csid) {
return orgAuthorityProxy.delete(csid);
}
public ClientResponse<OrganizationsCommonList> 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<AuthorityRefDocList> getReferencingObjects(String parentcsid, String csid) {
+ return orgAuthorityProxy.getReferencingObjects(parentcsid, csid);
+ }
+
/**
* Read item list for named authority.
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;
@Produces({"application/xml"})
@Path("/{vcsid}/items/")
ClientResponse<OrganizationsCommonList> 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<AuthorityRefDocList> getReferencingObjects(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemcsid") String itemcsid);
// List Items for a named authority
@GET
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;
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;
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<String, String> queryParams = ui.getQueryParameters();
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(), queryParams);
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ RepositoryClient repoClient = getRepositoryClient(ctx);
+ DocumentFilter myFilter = handler.getDocumentFilter();
+ String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
+ List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
+ if (list != null) {
+ serviceType = list.get(0);
+ }
+ DocumentWrapper<DocumentModel> 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.
*
public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) {
OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList();
try {
- ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+ ServiceContext<MultipartInput, MultipartOutput> 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) {
ServiceContext<MultipartInput, MultipartOutput> 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 + "'");
" LIKE " + "'%" + partialTerm + "%'";
myFilter.appendWhereClause(ptClause);
}
- handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
organizationObjectList = (OrganizationsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String whereClause =
OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
- ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
- "='"+parentSpecifier+"'";
+ ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+
+ "='" + parentSpecifier+"'";
// Need to get an Authority by name
ServiceContext<MultipartInput, MultipartOutput> 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 + ":" +
" LIKE " +
"'%" + partialTerm + "%'";
myFilter.appendWhereClause(ptClause);
- }
-
- handler.setDocumentFilter(myFilter);
+ }
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
ServiceContext<MultipartInput, MultipartOutput> 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 + "'" +
ContactJAXBSchema.IN_ITEM +
"='" + itemcsid + "'" +
" AND ecm:isProxy = 0");
- handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
contactObjectList = (ContactsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
*/
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;
throw new WebApplicationException(response);
}
try {
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
// Note that we have to create the service context for the Items, not the main service
- ServiceContext<MultipartInput, MultipartOutput> ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName());
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+ queryParams);
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
RepositoryClient repoClient = getRepositoryClient(ctx);
- DocumentFilter myFilter = handler.createDocumentFilter();
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
- myFilter.setPagination(queryParams);
+ DocumentFilter myFilter = handler.getDocumentFilter();
String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE;
List<String> list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
if (list != null) {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
ServiceContext<MultipartInput, MultipartOutput> 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) {
ServiceContext<MultipartInput, MultipartOutput> 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 + "'");
"'%" + partialTerm + "%'";
handler.getDocumentFilter().appendWhereClause(ptClause);
}
-//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
personObjectList = (PersonsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {
@Context UriInfo ui) {
PersonsCommonList personObjectList = new PersonsCommonList();
try {
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String whereClause =
PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+
- ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+
- "='"+parentSpecifier+"'";
+ ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME+
+ "='" + parentSpecifier+"'";
// Need to get an Authority by name
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
ServiceContext<MultipartInput, MultipartOutput> 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%'
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) {
ServiceContext<MultipartInput, MultipartOutput> 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 " +
ContactJAXBSchema.IN_ITEM +
"='" + itemcsid + "'" +
" AND ecm:isProxy = 0");
-//REM: handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
contactObjectList = (ContactsCommonList) handler.getCommonPartList();
} catch (UnauthorizedException ue) {