From: Patrick Schmitz Date: Wed, 23 Jun 2010 06:26:51 +0000 (+0000) Subject: CSPACE-590, CSPACE-2126, modifying authorities to support shortIdentifier. This is... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=41bffeffdb603e4541ade9fef0836986b62a6368;p=tmp%2Fjakarta-migration.git CSPACE-590, CSPACE-2126, modifying authorities to support shortIdentifier. This is now used to create refNames, and used to get by name. Updated associated utilities for creating authorities and items. Updated all the various tests that create authorities and instances. --- 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 index f526eac63..69eca30e4 100644 --- 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 @@ -152,11 +152,9 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { } protected void createPersonRefs(){ - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -165,23 +163,26 @@ public class AcquisitionAuthRefsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); - acquisitionAuthorizerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Annie Authorizer", true); - personIdsCreated.add(createPerson("Annie", "Authorizer", acquisitionAuthorizerRefName)); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - acquisitionFundingSourceRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Sammy Source", true); - personIdsCreated.add(createPerson("Sammy", "Source", acquisitionFundingSourceRefName)); + String csid = createPerson("Annie", "Authorizer", "annieAuth", authRefName); + acquisitionAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); + + csid = createPerson("Sammy", "Source", "sammySource", authRefName); + acquisitionFundingSourceRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); MultipartOutput multipart = - PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java new file mode 100644 index 000000000..2d41de9c4 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java @@ -0,0 +1,268 @@ +/** + * 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 (c) 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; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.List; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.commons.io.FileUtils; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.InputPart; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; + +/** + * CollectionSpaceClientUtils. + * + * Base abstract class on which client tests of services are based. + * + * $LastChangedRevision: 2261 $ + * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $ + */ + +// FIXME: http://issues.collectionspace.org/browse/CSPACE-1685 + +public class CollectionSpaceClientUtils { + + //Maven's base directory -i.e., the one containing the current pom.xml + /** The Constant logger. */ + private static final Logger logger = LoggerFactory.getLogger(CollectionSpaceClientUtils.class); + + protected static final int STATUS_BAD_REQUEST = + Response.Status.BAD_REQUEST.getStatusCode(); + protected static final int STATUS_CREATED = + Response.Status.CREATED.getStatusCode(); + protected static final int STATUS_NOT_FOUND = + Response.Status.NOT_FOUND.getStatusCode(); + protected static final int STATUS_OK = + Response.Status.OK.getStatusCode(); + + /** + * Extract id. + * + * @param res the res + * @return the string + */ + static public String extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((List) mvm.get("Location")).get(0); + if (logger.isDebugEnabled()) { + logger.debug("extractId:uri=" + uri); + } + String[] segments = uri.split("/"); + String id = segments[segments.length - 1]; + if (logger.isDebugEnabled()) { + logger.debug("id=" + id); + } + return id; + } + + /** + * Extract part. + * + * @param input the input + * @param label the label + * @param clazz the clazz + * @return the object + * @throws Exception the exception + */ + static public Object extractPart(MultipartInput input, String label, Class clazz) + throws Exception { + Object obj = null; + String partLabel = ""; + List parts = input.getParts(); + if (parts.size() == 0) { + logger.warn("No parts found in multipart body."); + } + if (logger.isDebugEnabled()) { + logger.debug("Parts:"); + for (InputPart part : parts) { + partLabel = part.getHeaders().getFirst("label"); + logger.debug("part = " + partLabel); + } + } + boolean partLabelMatched = false; + for (InputPart part : parts) { + partLabel = part.getHeaders().getFirst("label"); + if (label.equalsIgnoreCase(partLabel)) { + partLabelMatched = true; + if (logger.isDebugEnabled()) { + logger.debug("found part" + partLabel); + } + String partStr = part.getBodyAsString(); + if (partStr == null || partStr.trim().isEmpty()) { + logger.warn("Part '" + label + "' in multipart body is empty."); + } else { + if (logger.isDebugEnabled()) { + logger.debug("extracted part as str=\n" + partStr); + } + obj = part.getBody(clazz, null); + if (logger.isDebugEnabled()) { + logger.debug("extracted part as obj=\n", + objectAsXmlString(obj, clazz)); + } + } + break; + } + } + if (!partLabelMatched) { + logger.warn("Could not find part '" + label + "' in multipart body."); + // In the event that getBodyAsString() or getBody(), above, do *not* + // throw an IOException, but getBody() nonetheless retrieves a null object. + // This *may* be unreachable. + } else if (obj == null) { + logger.warn("Could not extract part '" + label + + "' in multipart body as an object."); + } + return obj; + } + + /** + * Gets the part object. + * + * @param partStr the part str + * @param clazz the clazz + * @return the part object + * @throws JAXBException the jAXB exception + */ + static public Object getPartObject(String partStr, Class clazz) + throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(clazz); + ByteArrayInputStream bais = null; + Object obj = null; + try { + bais = new ByteArrayInputStream(partStr.getBytes()); + Unmarshaller um = jc.createUnmarshaller(); + obj = um.unmarshal(bais); + } finally { + if (bais != null) { + try { + bais.close(); + } catch (Exception e) { + if (logger.isDebugEnabled() == true) { + e.printStackTrace(); + } + } + } + } + return obj; + } + + /** + * Object as xml string. + * + * @param o the o + * @param clazz the clazz + * @return the string + */ + static public String objectAsXmlString(Object o, Class clazz) { + StringWriter sw = new StringWriter(); + try { + JAXBContext jc = JAXBContext.newInstance(clazz); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(o, sw); + } catch (Exception e) { + e.printStackTrace(); + } + return sw.toString(); + } + + /** + * getObjectFromFile get object of given class from given file (in classpath) + * @param jaxbClass + * @param fileName of the file to read to construct the object + * @return + * @throws Exception + */ + static public Object getObjectFromFile(Class jaxbClass, String fileName) + throws Exception { + + JAXBContext context = JAXBContext.newInstance(jaxbClass); + Unmarshaller unmarshaller = context.createUnmarshaller(); + //note: setting schema to null will turn validator off + unmarshaller.setSchema(null); + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + InputStream is = tccl.getResourceAsStream(fileName); + return getObjectFromStream(jaxbClass, is); + } + + /** + * Gets the xml document. + * + * @param fileName the file name + * @return the xml document + * @throws Exception the exception + */ + static public Document getXmlDocument(String fileName) throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + File f = new File(fileName); + if (!f.exists()) { + throw new IllegalArgumentException("test data file " + fileName + " not found!"); + } + // Create the builder and parse the file + return factory.newDocumentBuilder().parse(f); + } + + /** + * Gets the xml document as string. + * + * @param fileName the file name + * @return the xml document as string + * @throws Exception the exception + */ + static public String getXmlDocumentAsString(String fileName) throws Exception { + byte[] b = FileUtils.readFileToByteArray(new File(fileName)); + return new String(b); + } + + /** + * getObjectFromStream get object of given class from given inputstream + * @param jaxbClass + * @param is stream to read to construct the object + * @return + * @throws Exception + */ + static public Object getObjectFromStream(Class jaxbClass, InputStream is) throws Exception { + JAXBContext context = JAXBContext.newInstance(jaxbClass); + Unmarshaller unmarshaller = context.createUnmarshaller(); + //note: setting schema to null will turn validator off + unmarshaller.setSchema(null); + return jaxbClass.cast(unmarshaller.unmarshal(is)); + } +} 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 index 9e4e1d006..cf5c8675e 100644 --- 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 @@ -83,6 +83,7 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { /** The person auth csid. */ private String personAuthCSID = null; + private String personAuthRefName = null; /** The content organization ref name. */ private String contentOrganizationRefName = null; @@ -184,11 +185,9 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { * Creates the person refs. */ protected void createPersonRefs(){ - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -196,22 +195,24 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); + // TODO Test that we can reuse the client above. + personAuthRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - contentOrganizationRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Omni Org", true); - personIdsCreated.add(createPerson("Omni", "Org", contentOrganizationRefName)); + String csid = createPerson("Omni", "Org", "omniOrg"); + contentOrganizationRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - contentPeopleRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Pushy People", true); - personIdsCreated.add(createPerson("Pushy", "People", contentPeopleRefName)); + csid = createPerson("Pushy", "People", "pushyPeople"); + contentPeopleRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - contentPersonRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Connie ContactPerson", true); - personIdsCreated.add(createPerson("Connie", "ContactPerson", contentPersonRefName)); + csid = createPerson("Connie", "ContactPerson", "connieContactPerson"); + contentPersonRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - contentInscriberRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Ingrid Inscriber", true); - personIdsCreated.add(createPerson("Ingrid", "Inscriber", contentInscriberRefName)); + csid = createPerson("Ingrid", "Inscriber", "ingridInscriber"); + contentInscriberRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); } /** @@ -222,14 +223,15 @@ public class CollectionObjectAuthRefsTest extends BaseServiceTest { * @param refName the ref name * @return the string */ - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortIdentifier ) { Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortIdentifier); PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + personAuthRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java index d3e7c09d4..2137d338d 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java @@ -155,10 +155,8 @@ public class IntakeAuthRefsTest extends BaseServiceTest { protected void createPersonRefs(){ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -167,37 +165,38 @@ public class IntakeAuthRefsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); - currentOwnerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Olivier Owner", true); - personIdsCreated.add(createPerson("Olivier", "Owner", currentOwnerRefName)); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - depositorRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Debbie Depositor", true); - personIdsCreated.add(createPerson("Debbie", "Depositor", depositorRefName)); + String csid = createPerson("Olivier", "Owner", "olivierOwner", authRefName); + currentOwnerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - conditionCheckerAssessorRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Andrew Checker-Assessor", true); - personIdsCreated.add(createPerson("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName)); + csid = createPerson("Debbie", "Depositor", "debbieDepositor", authRefName); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - insurerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Ingrid Insurer", true); - personIdsCreated.add(createPerson("Ingrid", "Insurer", insurerRefName)); + csid = createPerson("Andrew", "Assessor", "andrewAssessor", authRefName); + conditionCheckerAssessorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - valuerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Vince Valuer", true); - personIdsCreated.add(createPerson("Vince", "Valuer", valuerRefName)); + csid = createPerson("Ingrid", "Insurer", "ingridInsurer", authRefName); + insurerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); - + csid = createPerson("Vince", "Valuer", "vinceValuer", authRefName); + valuerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + personIdsCreated.add(csid); } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); @@ -327,13 +326,12 @@ public class IntakeAuthRefsTest extends BaseServiceTest { } private MultipartOutput createIntakeInstance(String entryNumber, - String entryDate, - String currentOwner, - String depositor, - String conditionCheckerAssessor, - String insurer, - String Valuer ) { - + String entryDate, + String currentOwner, + String depositor, + String conditionCheckerAssessor, + String insurer, + String Valuer ) { IntakesCommon intake = new IntakesCommon(); intake.setEntryNumber(entryNumber); intake.setEntryDate(entryDate); 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 index 1be1479c5..246fb1f1a 100644 --- 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 @@ -71,6 +71,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { private List intakeIdsCreated = new ArrayList(); private List orgIdsCreated = new ArrayList(); private String orgAuthCSID = null; + private String orgAuthRefName = null; private String currentOwnerOrgCSID = null; private String currentOwnerRefName = null; private String depositorRefName = null; @@ -163,10 +164,10 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { */ protected void createOrgRefs(){ OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); - String authRefName = - OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false); + orgAuthRefName = + OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, null); MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName()); + ORGANIZATION_AUTHORITY_NAME, ORGANIZATION_AUTHORITY_NAME, orgAuthClient.getCommonPartName()); ClientResponse res = orgAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -175,38 +176,40 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); orgAuthCSID = extractId(res); - currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName( - authRefName, "Olivier Owner", true); - currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName); + currentOwnerOrgCSID = createOrganization("olivierOwner", "Olivier Owner", "Olivier Owner"); orgIdsCreated.add(currentOwnerOrgCSID); + currentOwnerRefName = OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, currentOwnerOrgCSID, orgAuthClient); - depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName( - authRefName, "Debbie Depositor", true); - orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName)); + String newOrgCSID = createOrganization("debbieDepositor", "Debbie Depositor", "Debbie Depositor"); + depositorRefName = + OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient); + orgIdsCreated.add(newOrgCSID); - conditionCheckerAssessorRefName = OrgAuthorityClientUtils.createOrganizationRefName( - authRefName, "Andrew Checker-Assessor", true); - orgIdsCreated.add(createOrganization("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName)); + newOrgCSID = createOrganization("andrewCheckerAssessor", "Andrew Checker-Assessor", "Andrew Checker-Assessor"); + conditionCheckerAssessorRefName = + OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient); + orgIdsCreated.add(newOrgCSID); - insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName( - authRefName, "Ingrid Insurer", true); - orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName)); + newOrgCSID = createOrganization("ingridInsurer", "Ingrid Insurer", "Ingrid Insurer"); + insurerRefName = + OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient); + orgIdsCreated.add(newOrgCSID); - valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName( - authRefName, "Vince Valuer", true); - orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName)); - - + newOrgCSID = createOrganization("vinceValuer", "Vince Valuer", "Vince Valuer"); + valuerRefName = + OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient); + orgIdsCreated.add(newOrgCSID); } - - protected String createOrganization(String shortName, String longName, String refName ) { + + protected String createOrganization(String shortId, String shortName, String longName) { OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); Map orgInfo = new HashMap(); + orgInfo.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName); orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName); MultipartOutput multipart = - OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, - refName, orgInfo, orgAuthClient.getItemCommonPartName()); + OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, orgAuthRefName, + orgInfo, orgAuthClient.getItemCommonPartName()); ClientResponse res = orgAuthClient.createItem(orgAuthCSID, multipart); int statusCode = res.getStatus(); 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 b600372d1..3bc8b4160 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 @@ -118,11 +118,11 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { MultipartOutput multipart = createIntakeInstance( "entryNumber-" + identifier, "entryDate-" + identifier, - currentOwnerRefName, - depositorRefName, - conditionCheckerAssessorRefName, - insurerRefName, - valuerRefName ); + currentOwnerRefName, + depositorRefName, + conditionCheckerAssessorRefName, + insurerRefName, + valuerRefName ); ClientResponse res = intakeClient.create(multipart); try { @@ -163,10 +163,8 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { */ protected void createPersonRefs(){ PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -175,38 +173,50 @@ public class PersonAuthRefDocsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); - currentOwnerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Olivier Owner", true); - currentOwnerPersonCSID = createPerson("Olivier", "Owner", currentOwnerRefName); - personIdsCreated.add(currentOwnerPersonCSID); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); - depositorRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Debbie Depositor", true); - personIdsCreated.add(createPerson("Debbie", "Depositor", depositorRefName)); + String csid = createPerson("Olivier", "Owner", "olivierOwner", authRefName); + Assert.assertNotNull(csid); + currentOwnerPersonCSID = csid; + currentOwnerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + Assert.assertNotNull(currentOwnerRefName); + personIdsCreated.add(csid); - conditionCheckerAssessorRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Andrew Checker-Assessor", true); - personIdsCreated.add(createPerson("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName)); + csid = createPerson("Debbie", "Depositor", "debbieDepositor", authRefName); + Assert.assertNotNull(csid); + depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + Assert.assertNotNull(depositorRefName); + personIdsCreated.add(csid); - insurerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Ingrid Insurer", true); - personIdsCreated.add(createPerson("Ingrid", "Insurer", insurerRefName)); + csid = createPerson("Andrew", "Assessor", "andrewAssessor", authRefName); + Assert.assertNotNull(csid); + conditionCheckerAssessorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + Assert.assertNotNull(conditionCheckerAssessorRefName); + personIdsCreated.add(csid); - valuerRefName = PersonAuthorityClientUtils.createPersonRefName( - authRefName, "Vince Valuer", true); - personIdsCreated.add(createPerson("Vince", "Valuer", valuerRefName)); + csid = createPerson("Ingrid", "Insurer", "ingridInsurer", authRefName); + Assert.assertNotNull(csid); + insurerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + Assert.assertNotNull(insurerRefName); + personIdsCreated.add(csid); + + csid = createPerson("Vince", "Valuer", "vinceValuer", authRefName); + Assert.assertNotNull(csid); + valuerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + Assert.assertNotNull(valuerRefName); + personIdsCreated.add(csid); - } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java index e51422ae0..122b15c18 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java @@ -123,7 +123,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { MultipartOutput multipart = createLoaninInstance( "loanInNumber-" + identifier, "returnDate-" + identifier, - lenderRefName, + lenderRefName, lendersAuthorizerRefName, lendersContactRefName, loanInContactRefName); @@ -165,10 +165,8 @@ public class LoaninAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -177,23 +175,25 @@ public class LoaninAuthRefsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + // Create temporary Person resources, and their corresponding refNames // by which they can be identified. - lenderRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Linus Lender", true); - personIdsCreated.add(createPerson("Linus", "Lender", lenderRefName)); + String csid = createPerson("Linus", "Lender", "linusLender", authRefName); + personIdsCreated.add(csid); + lenderRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - lendersAuthorizerRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Art Lendersauthorizor", true); - personIdsCreated.add(createPerson("Art", "Lendersauthorizor", lendersAuthorizerRefName)); + csid = createPerson("Art", "Lendersauthorizor", "artLendersauthorizor", authRefName); + personIdsCreated.add(csid); + lendersAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - lendersContactRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Larry Lenderscontact", true); - personIdsCreated.add(createPerson("Larry", "Lenderscontact", lendersContactRefName)); + csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", authRefName); + personIdsCreated.add(csid); + lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - loanInContactRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Carrie Loanincontact", true); - personIdsCreated.add(createPerson("Carrie", "Loanincontact", loanInContactRefName)); + csid = createPerson("Carrie", "Loanincontact", "carrieLoanincontact", authRefName); + personIdsCreated.add(csid); + loanInContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); // FIXME: Add instance(s) of 'lenders' field when we can work with // repeatable / multivalued authority reference fields. Be sure to @@ -201,14 +201,15 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // revise check for numbers of authority fields expected in readAndCheckAuthRefs. } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java index d7c3670cb..c6ba93bae 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java @@ -162,10 +162,8 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -173,30 +171,33 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); - + + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + // Create temporary Person resources, and their corresponding refNames // by which they can be identified. - borrowersContactRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Bradley BorrowersContact", true); - personIdsCreated.add(createPerson("Bradley", "BorrowersContact", borrowersContactRefName)); + String csid = createPerson("Art", "Lendersauthorizor", "artLendersauthorizor", authRefName); + personIdsCreated.add(csid); + lendersAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); - lendersAuthorizerRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Art Lendersauthorizor", true); - personIdsCreated.add(createPerson("Art", "Lendersauthorizor", lendersAuthorizerRefName)); - - lendersContactRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Larry Lenderscontact", true); - personIdsCreated.add(createPerson("Larry", "Lenderscontact", lendersContactRefName)); + csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", authRefName); + personIdsCreated.add(csid); + lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); + + csid = createPerson("Bradley", "BorrowersContact", "bradleyBorrowersContact", authRefName); + personIdsCreated.add(csid); + borrowersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml index 6e6c34dc3..a8c915f1f 100644 --- a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -11,6 +11,7 @@ displayName + shortIdentifier refName vocabType @@ -28,6 +29,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + @@ -65,6 +79,7 @@ inAuthority + shortIdentifier refName displayName displayNameComputed @@ -89,6 +104,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd index 0a1f73678..a307bf88f 100644 --- a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd @@ -24,6 +24,7 @@ + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd index d64d2c15f..0bc24ef76 100644 --- a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd @@ -23,6 +23,7 @@ + diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index 063f1ac17..09ca4808e 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -34,9 +34,11 @@ public class LocationAuthorityClientUtils { * @return The MultipartOutput payload for the create call */ public static MultipartOutput createLocationAuthorityInstance( - String displayName, String refName, String headerLabel ) { + String displayName, String shortIdentifier, String headerLabel ) { LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon(); locationAuthority.setDisplayName(displayName); + locationAuthority.setShortIdentifier(shortIdentifier); + String refName = createLocationAuthRefName(shortIdentifier, displayName); locationAuthority.setRefName(refName); locationAuthority.setVocabType("LocationAuthority"); MultipartOutput multipart = new MultipartOutput(); @@ -59,9 +61,13 @@ public class LocationAuthorityClientUtils { * @return The MultipartOutput payload for the create call */ public static MultipartOutput createLocationInstance(String inAuthority, - String locationRefName, Map locationInfo, String headerLabel){ + String locationAuthRefName, Map locationInfo, String headerLabel){ LocationsCommon location = new LocationsCommon(); + String shortId = locationInfo.get(LocationJAXBSchema.SHORT_IDENTIFIER); + String displayName = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME); + location.setShortIdentifier(shortId); location.setInAuthority(inAuthority); + String locationRefName = createLocationRefName(locationAuthRefName, shortId, displayName); location.setRefName(locationRefName); String value = null; value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED); @@ -119,26 +125,26 @@ public class LocationAuthorityClientUtils { locationMap.get(LocationJAXBSchema.NAME)); } - String refName = createLocationRefName(locationAuthorityRefName, displayName, true); - if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+displayName +"\" in locationAuthority: \"" + locationAuthorityRefName +"\""); } MultipartOutput multipart = - createLocationInstance( vcsid, refName, + createLocationInstance( vcsid, locationAuthorityRefName, locationMap, client.getItemCommonPartName() ); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+refName + throw new RuntimeException("Could not create Item: \"" + +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) +"\" in locationAuthority: \"" + locationAuthorityRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+refName + throw new RuntimeException("Unexpected Status when creating Item: \"" + +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) +"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode); } @@ -200,19 +206,34 @@ public class LocationAuthorityClientUtils { return createItemInAuthority(vcsid, commonPartXML, client ); } - public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) { + /** + * Creates the locationAuthority ref name. + * + * @param shortId the locationAuthority shortIdentifier + * @param displaySuffix displayName to be appended, if non-null + * @return the string + */ + public static String createLocationAuthRefName(String shortId, String displaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name(" - +locationAuthorityName+")"; - if(withDisplaySuffix) - refName += "'"+locationAuthorityName+"'"; + +shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } + /** + * Creates the location ref name. + * + * @param locationAuthRefName the locationAuthority ref name + * @param shortId the location shortIdentifier + * @param displaySuffix displayName to be appended, if non-null + * @return the string + */ public static String createLocationRefName( - String locationAuthRefName, String locationName, boolean withDisplaySuffix) { - String refName = locationAuthRefName+":location:name("+locationName+")"; - if(withDisplaySuffix) - refName += "'"+locationName+"'"; + String locationAuthRefName, String shortId, String displaySuffix) { + String refName = locationAuthRefName+":location:name("+shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index 34759a91f..776d270ef 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -76,42 +76,23 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { /** The CONTACT service path component. */ final String CONTACT_SERVICE_PATH_COMPONENT = "contacts"; - /** The TEST name. */ final String TEST_NAME = "Shelf 1"; - - /** The TEST conditionNote. */ + final String TEST_SHORTID = "shelf1"; final String TEST_CONDITION_NOTE = "Basically clean"; - - /** The TEST death date. */ final String TEST_CONDITION_NOTE_DATE = "June 11, 1979"; - - /** The TEST securityNote. */ final String TEST_SECURITY_NOTE = "Kind of safe"; - - /** The TEST location type. */ // TODO Make loc type be a controlled vocab term. final String TEST_LOCATION_TYPE = "Shelf"; - - /** The TEST location type. */ // TODO Make status type be a controlled vocab term. final String TEST_STATUS = "Approved"; /** The known resource id. */ private String knownResourceId = null; - - /** The known resource display name. */ - private String knownResourceDisplayName = null; - - /** The known resource ref name. */ + private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; - - /** The known locationType ref name. */ private String knownLocationTypeRefName = null; - - /** The known item resource id. */ private String knownItemResourceId = null; - - /** The known contact resource id. */ + private String knownItemResourceShortIdentifer = null; private String knownContactResourceId = null; /** The n items to create in list. */ @@ -124,6 +105,18 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { private Map allItemResourceIdsCreated = new HashMap(); + protected void setKnownResource( String id, String shortIdentifer, + String refName ) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; + } + + protected void setKnownItemResource( String id, String shortIdentifer ) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -163,13 +156,12 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); - String identifier = createIdentifier(); - String displayName = "displayName-" + identifier; - String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, false); - String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true); + String shortId = createIdentifier(); + String displayName = "displayName-" + shortId; + String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null); MultipartOutput multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance( - displayName, fullRefName, client.getCommonPartName()); + displayName, shortId, client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -186,16 +178,11 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - // Store the refname from the first resource created - // for additional tests below. - knownResourceRefName = baseRefName; - String newID = LocationAuthorityClientUtils.extractId(res); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = newID; - knownResourceDisplayName = displayName; + setKnownResource( newID, shortId, baseRefName ); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -217,7 +204,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { logger.debug(testBanner(testName, CLASS_NAME)); } setupCreate(); - String newID = createItemInAuthority(knownResourceId, knownResourceRefName); + createItemInAuthority(knownResourceId, knownResourceRefName); } /** @@ -229,45 +216,32 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { */ private String createItemInAuthority(String vcsid, String authRefName) { - final String testName = "createItemInAuthority"; + final String testName = "createItemInAuthority("+vcsid+","+authRefName+")"; if(logger.isDebugEnabled()){ logger.debug(testBanner(testName, CLASS_NAME)); } // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); - String identifier = createIdentifier(); - String refName = LocationAuthorityClientUtils.createLocationRefName(authRefName, TEST_NAME, true); Map shelf1Map = new HashMap(); // TODO Make loc type and status be controlled vocabs. shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME); + shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID); shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); shelf1Map.put(LocationJAXBSchema.STATUS, TEST_STATUS); - MultipartOutput multipart = - LocationAuthorityClientUtils.createLocationInstance(vcsid, refName, shelf1Map, - client.getItemCommonPartName() ); - ClientResponse res = client.createItem(vcsid, multipart); - int statusCode = res.getStatus(); - String newID = LocationAuthorityClientUtils.extractId(res); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid, + authRefName, shelf1Map, client ); // Store the ID returned from the first item resource created // for additional tests below. if (knownItemResourceId == null){ - knownItemResourceId = newID; + setKnownItemResource(newID, TEST_SHORTID); if (logger.isDebugEnabled()) { - logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + logger.debug(testName + ": knownItemResourceId=" + newID); } } @@ -391,14 +365,14 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { public void readByName(String testName) throws Exception { if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); + logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME)); } // Perform setup. setupRead(); // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.readByName(knownResourceDisplayName); + ClientResponse res = client.readByName(knownResourceShortIdentifer); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -771,7 +745,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } - readItemList(null, knownResourceDisplayName); + readItemList(null, knownResourceShortIdentifer); } /** @@ -780,7 +754,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { * @param vcsid the vcsid * @param name the name */ - private void readItemList(String vcsid, String name) { + private void readItemList(String vcsid, String shortId) { String testName = "readItemList"; @@ -792,8 +766,8 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { ClientResponse res = null; if(vcsid!= null) { res = client.readItemList(vcsid); - } else if(name!= null) { - res = client.readItemListForNamedAuthority(name); + } else if(shortId!= null) { + res = client.readItemListForNamedAuthority(shortId); } else { Assert.fail("readItemList passed null csid and name!"); } @@ -1035,9 +1009,8 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in update(), below. LocationAuthorityClient client = new LocationAuthorityClient(); String displayName = "displayName-NON_EXISTENT_ID"; - String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true); MultipartOutput multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance( - displayName, fullRefName, client.getCommonPartName()); + displayName, "nonEx", client.getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); @@ -1074,12 +1047,13 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { LocationAuthorityClient client = new LocationAuthorityClient(); Map nonexMap = new HashMap(); nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME); + nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx"); nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); nonexMap.put(LocationJAXBSchema.STATUS, TEST_STATUS); MultipartOutput multipart = LocationAuthorityClientUtils.createLocationInstance(NON_EXISTENT_ID, - LocationAuthorityClientUtils.createLocationRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap, - client.getItemCommonPartName() ); + LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"), + nonexMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java index 134e3193b..c699bf846 100644 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java @@ -11,6 +11,7 @@ public interface LocationAuthorityJAXBSchema { final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common"; final static String DISPLAY_NAME = "displayName"; final static String REF_NAME = "refName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String VOCAB_TYPE = "vocabType"; final static String CSID = "csid"; } diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java index 7b7e70c46..01205e6f9 100644 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java @@ -10,6 +10,7 @@ package org.collectionspace.services; public interface LocationJAXBSchema { final static String LOCATIONS_COMMON = "locations_common"; final static String CSID = "csid"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String IN_AUTHORITY = "inAuthority"; final static String REF_NAME = "refName"; final static String DISPLAY_NAME = "displayName"; diff --git a/services/location/jaxb/src/main/resources/location_common.xsd b/services/location/jaxb/src/main/resources/location_common.xsd index f4fa8bee5..4ed013b46 100644 --- a/services/location/jaxb/src/main/resources/location_common.xsd +++ b/services/location/jaxb/src/main/resources/location_common.xsd @@ -22,6 +22,7 @@ + diff --git a/services/location/jaxb/src/main/resources/locationauthority_common.xsd b/services/location/jaxb/src/main/resources/locationauthority_common.xsd index 83547ffdb..b14a584bc 100644 --- a/services/location/jaxb/src/main/resources/locationauthority_common.xsd +++ b/services/location/jaxb/src/main/resources/locationauthority_common.xsd @@ -36,6 +36,7 @@ + diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java index e71af43d7..868518917 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java @@ -213,7 +213,7 @@ public class LocationAuthorityResource extends } String whereClause = LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ - ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+ + ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+specifier+"'"; // We only get a single doc - if there are multiple, // it is an error in use. @@ -697,7 +697,7 @@ public class LocationAuthorityResource extends MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ - ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+ + ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+parentSpecifier+"'"; // Need to get an Authority by name ServiceContext ctx = createServiceContext(queryParams); diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java index 7fb6ad7f9..96e9a5e50 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java @@ -158,10 +158,8 @@ public class MovementAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - String authRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -170,21 +168,24 @@ public class MovementAuthRefsTest extends BaseServiceTest { Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + // Create temporary Person resources, and their corresponding refNames // by which they can be identified. - movementContactRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Melvin MovementContact", true); - personIdsCreated.add(createPerson("Melvin", "MovementContact", movementContactRefName)); + String csid = createPerson("Melvin", "MovementContact", "melvinMovementContact", authRefName); + personIdsCreated.add(csid); + movementContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml index 746cea068..c6194dd4d 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -12,6 +12,7 @@ displayName refName + shortIdentifier vocabType @@ -28,6 +29,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + @@ -65,6 +79,7 @@ inAuthority + shortIdentifier refName displayName @@ -95,6 +110,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd index 8b01afa3f..1d234996a 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd @@ -24,6 +24,7 @@ + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd index a1238c77b..02b47f2a4 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd @@ -24,6 +24,7 @@ + diff --git a/services/organization/client/pom.xml b/services/organization/client/pom.xml index 5afa2f9ae..6be06fb10 100644 --- a/services/organization/client/pom.xml +++ b/services/organization/client/pom.xml @@ -31,6 +31,12 @@ org.collectionspace.services.organization.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + org.collectionspace.services org.collectionspace.services.client 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 b6b954d33..b826dac19 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 @@ -225,6 +225,39 @@ public class OrgAuthorityClient extends AbstractServiceClientImpl { return orgAuthorityProxy.readItem(vcsid, csid); } + /** + * Read named item. + * + * @param vcsid the vcsid + * @param shortId the shortIdentifier + * @return the client response + */ + public ClientResponse readNamedItem(String vcsid, String shortId) { + return orgAuthorityProxy.readNamedItem(vcsid, shortId); + } + + /** + * Read item in Named Authority. + * + * @param authShortId the shortIdentifier for the Authority + * @param csid the csid + * @return the client response + */ + public ClientResponse readItemInNamedAuthority(String authShortId, String csid) { + return orgAuthorityProxy.readItemInNamedAuthority(authShortId, csid); + } + + /** + * Read named item in Named Authority. + * + * @param authShortId the shortIdentifier for the Authority + * @param itemShortId the shortIdentifier for the item + * @return the client response + */ + public ClientResponse readNamedItemInNamedAuthority(String authShortId, String itemShortId) { + return orgAuthorityProxy.readNamedItem(authShortId, itemShortId); + } + /** * Creates the item. * diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java index 68036c182..1459ae28b 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java @@ -37,7 +37,10 @@ import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.organization.OrganizationsCommon; import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.person.PersonauthoritiesCommon; +import org.collectionspace.services.person.PersonsCommon; 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.slf4j.Logger; @@ -51,20 +54,88 @@ public class OrgAuthorityClientUtils { /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(OrgAuthorityClientUtils.class); + private static final ServiceRequestType READ_REQ = ServiceRequestType.READ; + + /** + * @param csid the id of the OrgAuthority + * @param client if null, creates a new client + * @return + */ + public static String getAuthorityRefName(String csid, OrgAuthorityClient client){ + if(client==null) + client = new OrgAuthorityClient(); + ClientResponse res = client.read(csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + OrgauthoritiesCommon orgAuthority = + (OrgauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + if(orgAuthority==null) { + throw new RuntimeException("Null orgAuthority returned from service."); + } + return orgAuthority.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + /** + * @param csid the id of the PersonAuthority + * @param client if null, creates a new client + * @return + */ + public static String getOrgRefName(String inAuthority, String csid, OrgAuthorityClient client){ + if(client==null) + client = new OrgAuthorityClient(); + ClientResponse res = client.readItem(inAuthority, csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon org = + (OrganizationsCommon) CollectionSpaceClientUtils.extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + if(org==null) { + throw new RuntimeException("Null Organization returned from service."); + } + return org.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } /** * Creates the org authority instance. * * @param displayName the display name - * @param refName the ref name + * @param shortIdentifier the short Id * @param headerLabel the header label * @return the multipart output */ public static MultipartOutput createOrgAuthorityInstance( - String displayName, String refName, String headerLabel ) { + String displayName, String shortIdentifier, String headerLabel ) { OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); orgAuthority.setDisplayName(displayName); - orgAuthority.setRefName(refName); + orgAuthority.setShortIdentifier(shortIdentifier); + String refName = createOrgAuthRefName(shortIdentifier, displayName); orgAuthority.setVocabType("OrgAuthority"); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); @@ -81,13 +152,13 @@ public class OrgAuthorityClientUtils { /** * Creates the item in authority. * - * @param vcsid the vcsid - * @param orgAuthorityRefName the org authority ref name - * @param orgInfo the org info + * @param inAuthority the owning authority + * @param orgAuthorityRefName the owning Authority ref name + * @param orgInfo the org info. OrganizationJAXBSchema.SHORT_IDENTIFIER is REQUIRED. * @param client the client * @return the string */ - public static String createItemInAuthority(String vcsid, + public static String createItemInAuthority(String inAuthority, String orgAuthorityRefName, Map orgInfo, OrgAuthorityClient client) { // Expected status code: 201 Created @@ -95,26 +166,26 @@ public class OrgAuthorityClientUtils { // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; String displayName = createDisplayName(orgInfo); - String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true); if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+displayName +"\" in orgAuthority: \"" + orgAuthorityRefName +"\""); } MultipartOutput multipart = - createOrganizationInstance(vcsid, refName, orgInfo, client.getItemCommonPartName()); - ClientResponse res = client.createItem(vcsid, multipart); + createOrganizationInstance(inAuthority, orgAuthorityRefName, + orgInfo, client.getItemCommonPartName()); + ClientResponse res = client.createItem(inAuthority, multipart); String result; try { int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+displayName + throw new RuntimeException("Could not create Item: \""+orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER) +"\" in orgAuthority: \"" + orgAuthorityRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+ displayName + throw new RuntimeException("Unexpected Status when creating Item: \""+ orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER) +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode); } @@ -130,22 +201,30 @@ public class OrgAuthorityClientUtils { * Creates the organization instance. * * @param inAuthority the in authority - * @param orgRefName the org ref name + * @param orgAuthRefName the owning Authority ref name * @param orgInfo the org info * @param headerLabel the header label * @return the multipart output */ public static MultipartOutput createOrganizationInstance(String inAuthority, - String orgRefName, Map orgInfo, String headerLabel){ + String orgAuthRefName, Map orgInfo, String headerLabel){ OrganizationsCommon organization = new OrganizationsCommon(); organization.setInAuthority(inAuthority); - organization.setRefName(orgRefName); + String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER); + if (shortId == null || shortId.isEmpty()) { + throw new IllegalArgumentException("shortIdentifier cannot be null or empty"); + } + organization.setShortIdentifier(shortId); String value = null; value = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED); boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); organization.setDisplayNameComputed(displayNameComputed); - if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null) + if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null) organization.setDisplayName(value); + + String refName = createOrganizationRefName(orgAuthRefName, shortId, value); + organization.setRefName(refName); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.SHORT_NAME))!=null) organization.setShortName(value); if((value = (String)orgInfo.get(OrganizationJAXBSchema.LONG_NAME))!=null) @@ -222,15 +301,15 @@ public class OrgAuthorityClientUtils { /** * Creates the org auth ref name. * - * @param orgAuthorityName the org authority name - * @param withDisplaySuffix the with display suffix + * @param shortId the orgAuthority shortIdentifier + * @param displaySuffix displayName to be appended, if non-null * @return the string */ - public static String createOrgAuthRefName(String orgAuthorityName, boolean withDisplaySuffix) { + public static String createOrgAuthRefName(String shortId, String displaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:orgauthority:name(" - +orgAuthorityName+")"; - if(withDisplaySuffix) - refName += "'"+orgAuthorityName+"'"; + +shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } @@ -238,15 +317,15 @@ public class OrgAuthorityClientUtils { * Creates the organization ref name. * * @param orgAuthRefName the org auth ref name - * @param orgName the org name - * @param withDisplaySuffix the with display suffix + * @param shortId the person shortIdentifier + * @param displaySuffix displayName to be appended, if non-null * @return the string */ public static String createOrganizationRefName( - String orgAuthRefName, String orgName, boolean withDisplaySuffix) { - String refName = orgAuthRefName+":organization:name("+orgName+")"; - if(withDisplaySuffix) - refName += "'"+orgName+"'"; + String orgAuthRefName, String shortId, String displaySuffix) { + String refName = orgAuthRefName+":organization:name("+shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } 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 54f2091ce..32ca3dbd9 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 @@ -8,8 +8,10 @@ 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.core.Response; +import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.contact.ContactsCommonList; @@ -80,7 +82,16 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @GET @Produces({"application/xml"}) @Path("/urn:cspace:name({specifier})/items/") - ClientResponse readItemListForNamedAuthority(@PathParam("specifier") String specifier); + ClientResponse readItemListForNamedAuthority( + @PathParam("specifier") String specifier); + + // List Items for a named authority matching a partial term. + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({specifier})/items/") + ClientResponse readItemListForNamedAuthority( + @PathParam("specifier") String specifier, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm); // List Item Authority References @GET @@ -100,6 +111,21 @@ public interface OrgAuthorityProxy extends CollectionSpaceProxy { @Path("/{vcsid}/items/{csid}") ClientResponse readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + //(R)ead Named Item + @GET + @Path("/{vcsid}/items/urn:cspace:name({specifier})") + ClientResponse readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier); + + //(R)ead Item In Named Authority + @GET + @Path("/urn:cspace:name({specifier})/items/{csid}") + ClientResponse readItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("csid") String csid); + + //(R)ead Named Item In Named Authority + @GET + @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})") + ClientResponse readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier); + //(U)pdate Item @PUT @Path("/{vcsid}/items/{csid}") diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java index 7ab612d5d..59b5054de 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java @@ -65,21 +65,16 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. - /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "orgauthorities"; - - // Temporary Person and Organization Authority names, used for test purposes. final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; final String ORG_AUTHORITY_NAME = "TestOrgAuth"; - /** The known resource ref name. */ + + private String knownResourceId = null; private String knownResourceRefName = null; - /** The known auth resource id. */ - private String knownAuthResourceId = null; - /** The known item id. */ - private String knownItemId = null; + private String knownItemResourceId = null; /** The all resource ids created. */ private List allResourceIdsCreated = new ArrayList(); @@ -105,6 +100,11 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { /** The number of authorityreferences expected. */ private final int NUM_AUTH_REFS_EXPECTED = 2; + protected void setKnownResource( String id, String refName ) { + knownResourceId = id; + knownResourceRefName = refName; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -142,39 +142,40 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Create a new Organization Authority resource. OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); - String identifier = createIdentifier(); - String displayName = "TestOrgAuth-" + identifier; - boolean createWithDisplayName = false; - knownResourceRefName = - OrgAuthorityClientUtils.createOrgAuthRefName(displayName, createWithDisplayName); + String shortId = createIdentifier(); + String displayName = "TestOrgAuth-" + shortId; + String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, knownResourceRefName, orgAuthClient.getCommonPartName()); + displayName, shortId, orgAuthClient.getCommonPartName()); // Submit the request to the service and store the response. ClientResponse res = orgAuthClient.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); - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - knownAuthResourceId = extractId(res); + 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 IDs from every resource created by tests, + // so they can be deleted after tests have been run. + String newId = extractId(res); + if (knownResourceId == null){ + setKnownResource( newId, baseRefName ); + } + allResourceIdsCreated.add(newId); } finally { res.releaseConnection(); } - allResourceIdsCreated.add(knownAuthResourceId); // Create all the person refs and entities createPersonRefs(); @@ -189,8 +190,9 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // contain references to Persons, via their refNames, as // per the initialization(s) below. Map testOrgMap = new HashMap(); + testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, - "Test Organization-" + identifier); + "Test Organization-" + shortId); testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Test Organization Name"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Anytown, USA"); testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, organizationContactPersonRefName); @@ -198,12 +200,12 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Finishing creating the new Organization item, then // submit the request to the service and store the response. - knownItemId = OrgAuthorityClientUtils.createItemInAuthority( - knownAuthResourceId, knownResourceRefName, testOrgMap, orgAuthClient); + knownItemResourceId = OrgAuthorityClientUtils.createItemInAuthority( + knownResourceId, knownResourceRefName, testOrgMap, orgAuthClient); // Store the IDs from every item created by tests, // so they can be deleted after tests have been run. - allItemResourceIdsCreated.put(knownItemId, knownAuthResourceId); + allItemResourceIdsCreated.put(knownItemResourceId, knownResourceId); } /** @@ -213,10 +215,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - String personAuthRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, personAuthRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); try { @@ -229,12 +229,13 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { res.releaseConnection(); } - // Create a temporary Person resource, and its corresponding refName - // by which it can be identified. - organizationContactPersonRefName = - PersonAuthorityClientUtils.createPersonRefName(personAuthRefName, "Charlie Orgcontact", true); - personIdsCreated.add(createPerson("Charlie", "Orgcontact", organizationContactPersonRefName)); - + String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); + + // Create temporary Person resources, and their corresponding refNames + // by which they can be identified. + String csid = createPerson("Charlie", "Orgcontact", "charlieOrgcontact", authRefName); + personIdsCreated.add(csid); + organizationContactPersonRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); } /** @@ -242,17 +243,19 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { * * @param firstName the first name * @param surName the sur name - * @param refName the ref name + * @param shortId + * @param authRefName * @return the string */ - protected String createPerson(String firstName, String surName, String refName ) { + protected String createPerson(String firstName, String surName, String shortId, String authRefName ) { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map personInfo = new HashMap(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, - refName, personInfo, personAuthClient.getItemCommonPartName()); + authRefName, personInfo, personAuthClient.getItemCommonPartName()); String result = null; ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); @@ -277,26 +280,26 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // This sub-body Organization resource will be created in the same // Organization authority as its parent Organization resource. - String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization", subBodyRefName); - allItemResourceIdsCreated.put(subBodyResourceId, knownAuthResourceId); + String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization"); + allItemResourceIdsCreated.put(subBodyResourceId, knownResourceId); + subBodyRefName = OrgAuthorityClientUtils.getOrgRefName(knownResourceId, subBodyResourceId, null); } - protected String createSubBodyOrganization(String subBodyName, String refName) { + protected String createSubBodyOrganization(String subBodyName) { OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); Map subBodyOrgMap = new HashMap(); + String shortId = createIdentifier(); + subBodyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId ); subBodyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, - subBodyName + "-" + createIdentifier()); + subBodyName + "-" + shortId); subBodyOrgMap.put(OrganizationJAXBSchema.LONG_NAME, subBodyName + " Long Name"); subBodyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, subBodyName + " Founding Place"); - String subBodyDisplayName = OrgAuthorityClientUtils.createDisplayName(subBodyOrgMap); - subBodyRefName = - OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, subBodyDisplayName, true); MultipartOutput multipart = - OrgAuthorityClientUtils.createOrganizationInstance(knownAuthResourceId, - subBodyRefName, subBodyOrgMap, orgAuthClient.getItemCommonPartName()); + OrgAuthorityClientUtils.createOrganizationInstance(knownResourceId, + knownResourceRefName, subBodyOrgMap, orgAuthClient.getItemCommonPartName()); String result = null; - ClientResponse res = orgAuthClient.createItem(knownAuthResourceId, multipart); + ClientResponse res = orgAuthClient.createItem(knownResourceId, multipart); try { int statusCode = res.getStatus(); Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), @@ -330,7 +333,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); ClientResponse res = - orgAuthClient.readItem(knownAuthResourceId, knownItemId); + orgAuthClient.readItem(knownResourceId, knownItemResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -357,7 +360,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // FIXME - need to create this method in the client // and get the ID for the organization item ClientResponse res2 = - orgAuthClient.getItemAuthorityRefs(knownAuthResourceId, knownItemId); + orgAuthClient.getItemAuthorityRefs(knownResourceId, knownItemResourceId); statusCode = res2.getStatus(); if(logger.isDebugEnabled()){ @@ -427,7 +430,9 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { } // Delete PersonAuthority resource(s). // Note: Any non-success response is ignored and not reported. - personAuthClient.delete(personAuthCSID).releaseConnection(); + if(personAuthCSID!=null) { + personAuthClient.delete(personAuthCSID).releaseConnection(); + } String parentResourceId; String itemResourceId; @@ -459,19 +464,4 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - - /** - * Creates the org authority instance. - * - * @param identifier the identifier - * @return the multipart output - */ - private MultipartOutput createOrgAuthorityInstance(String identifier) { - String displayName = "displayName-" + identifier; - String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true); - return OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, refName, - new OrgAuthorityClient().getCommonPartName()); - } - } diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index 5f5c4d95a..4ee853c5d 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -81,17 +81,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { /** The test organization founding place. */ private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA"; - /** The known resource id. */ + // Hold some values for a recently created item to verify upon read. private String knownResourceId = null; - - /** The known resource display name. */ - private String knownResourceDisplayName = null; - - /** The known resource ref name. */ + private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; - - /** The known item resource id. */ private String knownItemResourceId = null; + private String knownItemResourceShortIdentifer = null; /** The known contact resource id. */ private String knownContactResourceId = null; @@ -107,6 +102,18 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { private Map allContactResourceIdsCreated = new HashMap(); + protected void setKnownResource( String id, String shortIdentifer, + String refName ) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; + } + + protected void setKnownItemResource( String id, String shortIdentifer ) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -146,12 +153,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - String identifier = createIdentifier(); - String displayName = "displayName-" + identifier; - String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true); + String shortId = createIdentifier(); + String displayName = "displayName-" + shortId; + String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null); MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, refName, client.getCommonPartName()); + displayName, shortId, client.getCommonPartName()); String newID = null; ClientResponse res = client.create(multipart); @@ -171,10 +178,6 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - // Store the refname from the first resource created - // for additional tests below. - knownResourceRefName = refName; - newID = OrgAuthorityClientUtils.extractId(res); } finally { res.releaseConnection(); @@ -183,8 +186,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = newID; - knownResourceDisplayName = displayName; + setKnownResource( newID, shortId, baseRefName ); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -222,9 +224,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - String identifier = createIdentifier(); - String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true); + String shortId = "testOrg"; Map testOrgMap = new HashMap(); + testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME); testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org"); @@ -236,7 +238,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Store the ID returned from the first item resource created // for additional tests below. if (knownItemResourceId == null){ - knownItemResourceId = newID; + setKnownItemResource(newID, shortId); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } @@ -494,39 +496,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.read(knownResourceId); - try { - int statusCode = res.getStatus(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures - try { - MultipartInput input = (MultipartInput) res.getEntity(); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } - } finally { - res.releaseConnection(); - } + readInternal(testName, knownResourceId, null); } /** @@ -538,6 +508,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) public void readByName(String testName) throws Exception { + readInternal(testName, null, knownResourceShortIdentifer); + } + + protected void readInternal(String testName, String CSID, String shortId) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -547,7 +521,14 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.readByName(knownResourceDisplayName); + ClientResponse res = null; + if(CSID!=null) { + res = client.read(CSID); + } else if(shortId!=null) { + res = client.readByName(shortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } try { int statusCode = res.getStatus(); @@ -573,50 +554,60 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } } -/* - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readByName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); + /** + * Read item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readItem(String testName) throws Exception { + readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); + } - // Submit the request to the service and store the response. - ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); + /** + * Read item in Named Auth. + * + * TODO Enable this if we really need this - it is a funky case, where we would have + * the shortId of the item, but the CSID of the parent authority!? Unlikely. + * + * @param testName the test name + * @throws Exception the exception + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readItemInNamedAuth(String testName) throws Exception { + readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); + } + */ - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures - try { - MultipartInput input = (MultipartInput) res.getEntity(); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } + /** + * Read named item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readNamedItem(String testName) throws Exception { + readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } -*/ /** - * Read item. - * - * @param testName the test name - * @throws Exception the exception - */ -@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readItem(String testName) throws Exception { + * Read Named item in Named Auth. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readNamedItemInNamedAuth(String testName) throws Exception { + readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); + } + + protected void readItemInternal(String testName, + String authCSID, String authShortId, String itemCSID, String itemShortId) + throws Exception { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); @@ -626,7 +617,26 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + ClientResponse res = null; + if(authCSID!=null) { + if(itemCSID!=null) { + res = client.readItem(authCSID, itemCSID); + } else if(itemShortId!=null) { + res = client.readNamedItem(authCSID, itemShortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } + } else if(authShortId!=null) { + if(itemCSID!=null) { + res = client.readItemInNamedAuthority(authShortId, itemCSID); + } else if(itemShortId!=null) { + res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } + } else { + Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); + } try { int statusCode = res.getStatus(); @@ -647,8 +657,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { boolean showFull = true; if(showFull && logger.isDebugEnabled()){ logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); + logger.debug(objectAsXmlString(organization, OrganizationsCommon.class)); } Assert.assertEquals(organization.getInAuthority(), knownResourceId); } finally { @@ -850,7 +859,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -926,7 +935,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { * @param testName the test name */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readItemNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -956,7 +965,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { * @param testName the test name */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readContact"}) + groups = {"readItem"}, dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1048,7 +1057,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { */ @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) public void readItemListByAuthorityName() { - readItemList(null, knownResourceDisplayName); + readItemList(null, knownResourceShortIdentifer); } /** @@ -1546,7 +1555,9 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. OrgAuthorityClient client = new OrgAuthorityClient(); - MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID); + MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance( + NON_EXISTENT_ID, NON_EXISTENT_ID, + new OrgAuthorityClient().getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); @@ -1582,11 +1593,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in update(), below. OrgAuthorityClient client = new OrgAuthorityClient(); Map nonexOrgMap = new HashMap(); + nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent"); nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); - String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true); MultipartOutput multipart = OrgAuthorityClientUtils.createOrganizationInstance( - NON_EXISTENT_ID, refName, + NON_EXISTENT_ID, knownResourceRefName, nonexOrgMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); @@ -2056,18 +2067,4 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { return getContactServiceRootURL(parentResourceIdentifier, itemResourceIdentifier) + "/" + contactResourceIdentifier; } - - /** - * Creates the org authority instance. - * - * @param identifier the identifier - * @return the multipart output - */ - private MultipartOutput createOrgAuthorityInstance(String identifier) { - String displayName = "displayName-" + identifier; - String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true); - return OrgAuthorityClientUtils.createOrgAuthorityInstance( - displayName, refName, - new OrgAuthorityClient().getCommonPartName()); - } } diff --git a/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java index 57c77a428..75bd8ae11 100644 --- a/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java +++ b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java @@ -58,7 +58,7 @@ public class OrgAuthorityBaseImport { final String SERVICE_PATH_COMPONENT = "orgauthorities"; final String ITEM_SERVICE_PATH_COMPONENT = "items"; - public void createOrgAuthority(String orgAuthorityName, + public void createOrgAuthority(String orgAuthorityDisplayName, String orgAuthorityShortId, List> orgInfos ) { // Expected status code: 201 Created @@ -67,32 +67,30 @@ public class OrgAuthorityBaseImport { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; if(logger.isDebugEnabled()){ - logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\""); + logger.debug("Import: Create orgAuthority: \"" + orgAuthorityShortId +"\""); } - String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, false); - String fullOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, true); + String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityShortId, null); MultipartOutput multipart = - OrgAuthorityClientUtils.createOrgAuthorityInstance( - orgAuthorityName, fullOrgAuthRefName, - client.getCommonPartName()); + OrgAuthorityClientUtils.createOrgAuthorityInstance( + orgAuthorityDisplayName, orgAuthorityShortId, client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName + throw new RuntimeException("Could not create enumeration: \""+orgAuthorityShortId +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { throw new RuntimeException("Unexpected Status when creating enumeration: \"" - +orgAuthorityName +"\", Status:"+ statusCode); + +orgAuthorityShortId +"\", Status:"+ statusCode); } // Store the ID returned from this create operation // for additional tests below. String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res); if(logger.isDebugEnabled()){ - logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:" + logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityShortId +"\" ID:" +newOrgAuthorityId ); } for(Map orgInfo : orgInfos){ @@ -112,14 +110,17 @@ public class OrgAuthorityBaseImport { OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport(); final String demoOrgAuthorityName = "Demo Org Authority"; + final String demoOrgAuthorityShortId = "demoOrgAuth"; Map mmiOrgMap = new HashMap(); + mmiOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "mmi"); mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI"); mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image"); mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes"); mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984"); mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY"); Map pahmaOrgMap = new HashMap(); + pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "pahma"); pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA"); pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology"); pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley"); @@ -127,6 +128,7 @@ public class OrgAuthorityBaseImport { pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901"); pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA"); Map savoyOrgMap = new HashMap(); + savoyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "savoyTh"); savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre"); savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900"); savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952"); @@ -134,7 +136,7 @@ public class OrgAuthorityBaseImport { List> orgMaps = Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap ); - oabi.createOrgAuthority(demoOrgAuthorityName, orgMaps); + oabi.createOrgAuthority(demoOrgAuthorityName, demoOrgAuthorityShortId, orgMaps); logger.info("OrgAuthorityBaseImport complete."); } diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java index 90798f988..05844ad2b 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java @@ -10,6 +10,7 @@ package org.collectionspace.services; public interface OrgAuthorityJAXBSchema { final static String ORGAUTHORITIES_COMMON = "orgauthorities_common"; final static String DISPLAY_NAME = "displayName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String REF_NAME = "refName"; final static String VOCAB_TYPE = "vocabType"; final static String CSID = "csid"; diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java index bb9b16b99..21efbd036 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java @@ -12,6 +12,7 @@ public interface OrganizationJAXBSchema { final static String CSID = "csid"; final static String IN_AUTHORITY = "inAuthority"; final static String REF_NAME = "refName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String DISPLAY_NAME = "displayName"; final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; final static String SHORT_NAME = "shortName"; diff --git a/services/organization/jaxb/src/main/resources/organization_common.xsd b/services/organization/jaxb/src/main/resources/organization_common.xsd index 12ae91440..1f6738c97 100644 --- a/services/organization/jaxb/src/main/resources/organization_common.xsd +++ b/services/organization/jaxb/src/main/resources/organization_common.xsd @@ -21,6 +21,7 @@ + diff --git a/services/organization/jaxb/src/main/resources/orgauthority_common.xsd b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd index 32eb77317..a9e129be1 100644 --- a/services/organization/jaxb/src/main/resources/orgauthority_common.xsd +++ b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd @@ -34,6 +34,7 @@ + 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 fce0ab972..6bdba2eac 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 @@ -253,7 +253,7 @@ public class OrgAuthorityResource extends } String whereClause = OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+ - ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+ + ":"+OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+specifier+"'"; // We only get a single doc - if there are multiple, // it is an error in use. @@ -677,6 +677,144 @@ public class OrgAuthorityResource extends return result; } + /** + * Gets the person by name. + * + * @param parentcsid the parentcsid + * @param itemspecifier the shrotId of the person + * + * @return the person + */ + @GET + @Path("{csid}/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getOrganizationByName( + @PathParam("csid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier) { + if (parentcsid == null || "".equals(parentcsid) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getOrganizationByName: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Organization with parentcsid=" + + parentcsid + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + OrganizationJAXBSchema.ORGANIZATIONS_COMMON+ + ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + if (logger.isDebugEnabled()) { + logger.debug("getOrganizationByName with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganization", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Organization itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganizationByName", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Organization itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the person by name, in a named authority. + * + * @param parentspecifier the shortId of the parent + * @param itemspecifier the shortId of the person + * + * @return the person + */ + @GET + @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getOrganizationByNameInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier) { + if (parentspecifier == null || "".equals(parentspecifier) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getOrganizationByNameInNamedAuthority: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Organization with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + OrganizationJAXBSchema.ORGANIZATIONS_COMMON+ + ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + if (logger.isDebugEnabled()) { + logger.debug("getOrganizationByNameInNamedAuthority with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + // HACK HACK Since we do not use the parent CSID yet this should work. + DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganizationByNameInNamedAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Person itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganizationByNameInNamedAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + /** * Gets the authority refs for an Organization item. * @param parentcsid @@ -795,30 +933,12 @@ public class OrgAuthorityResource extends MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+ - ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+ + ":" + OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+ "='" + 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.getDocumentFilter();// new DocumentFilter(); - - // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'" - myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + - OrganizationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); - - // AND organizations_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" + - OrganizationJAXBSchema.DISPLAY_NAME + - " LIKE " + - "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - personObjectList = (OrganizationsCommonList) handler.getCommonPartList(); + return getOrganizationList(parentcsid, partialTerm, ui); } catch (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -831,7 +951,6 @@ public class OrgAuthorityResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); throw new WebApplicationException(response); } - return personObjectList; } /** diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java new file mode 100644 index 000000000..ba8f36684 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java @@ -0,0 +1,111 @@ +/** + * 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 University of California at Berkeley + + * 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. + *//** + * 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 University of California at Berkeley + + * 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. + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.organization.nuxeo; + +import java.util.regex.Pattern; + +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class OrgAuthorityValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(OrgAuthorityValidatorHandler.class); + private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + if(logger.isDebugEnabled()) { + logger.debug("validate() action=" + action.name()); + } + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + OrgauthoritiesCommon organizationAuth = + (OrgauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + OrgauthoritiesCommon.class); + String msg = ""; + boolean invalid = false; + String shortId = organizationAuth.getShortIdentifier(); + if(shortId==null){ + invalid = true; + msg += "shortIdentifier must be non-null"; + } else if(shortIdBadPattern.matcher(shortId).find()) { + invalid = true; + msg += "shortIdentifier must only contain standard word characters"; + } + /* + if(action.equals(Action.CREATE)) { + //create specific validation here + } else if(action.equals(Action.UPDATE)) { + //update specific validation here + } + */ + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +} diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java index 6c579ca2d..f20d9464b 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java @@ -57,6 +57,7 @@ import org.collectionspace.services.common.document.InvalidDocumentException; import org.collectionspace.services.common.document.ValidatorHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.regex.Pattern; /** * @@ -65,6 +66,7 @@ import org.slf4j.LoggerFactory; public class OrganizationValidatorHandler implements ValidatorHandler { final Logger logger = LoggerFactory.getLogger(OrganizationValidatorHandler.class); + private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() @Override public void validate(Action action, ServiceContext ctx) @@ -81,6 +83,14 @@ public class OrganizationValidatorHandler implements ValidatorHandler { if(!org.isDisplayNameComputed() && (org.getDisplayName()==null)) { invalid = true; msg += "displayName must be non-null if displayNameComputed is false!"; + } + String shortId = org.getShortIdentifier(); + if(shortId==null){ + invalid = true; + msg += "shortIdentifier must be non-null"; + } else if(shortIdBadPattern.matcher(shortId).find()) { + invalid = true; + msg += "shortIdentifier must only contain standard word characters"; } /* if(action.equals(Action.CREATE)) { diff --git a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/OSGI-INF/layouts-contrib.xml index 108e3fad5..5a7d60f66 100644 --- a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -11,6 +11,7 @@ displayName + shortIdentifier refName vocabType @@ -28,6 +29,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + @@ -65,6 +79,7 @@ displayName + shortIdentifier refName inAuthority foreName @@ -94,7 +109,20 @@ true - displayName + displayName + + + dataInputText + + + + + + + + true + + shortIdentifier dataInputText diff --git a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/personauthorities_common.xsd b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/personauthorities_common.xsd index 915bc31a6..d146c213d 100644 --- a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/personauthorities_common.xsd +++ b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/personauthorities_common.xsd @@ -24,6 +24,7 @@ + diff --git a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd index d1f733f1b..dfe77455b 100644 --- a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd +++ b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd @@ -23,6 +23,7 @@ + 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 b89410b23..d01f1213c 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 @@ -172,6 +172,17 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.delete(csid); } + /** + * Gets the referencing objects. + * + * @param parentcsid the parentcsid + * @param csid the csid + * @return the referencing objects + */ + public ClientResponse getReferencingObjects(String parentcsid, String csid) { + return personAuthorityProxy.getReferencingObjects(parentcsid, csid); + } + /** * Read item list. * @@ -194,17 +205,6 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.readItemList(vcsid, partialTerm); } - /** - * Gets the referencing objects. - * - * @param parentcsid the parentcsid - * @param csid the csid - * @return the referencing objects - */ - public ClientResponse getReferencingObjects(String parentcsid, String csid) { - return personAuthorityProxy.getReferencingObjects(parentcsid, csid); - } - /** * Read item list for named authority. * @@ -226,6 +226,39 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl { return personAuthorityProxy.readItem(vcsid, csid); } + /** + * Read named item. + * + * @param vcsid the vcsid + * @param shortId the shortIdentifier + * @return the client response + */ + public ClientResponse readNamedItem(String vcsid, String shortId) { + return personAuthorityProxy.readNamedItem(vcsid, shortId); + } + + /** + * Read item in Named Authority. + * + * @param authShortId the shortIdentifier for the Authority + * @param csid the csid + * @return the client response + */ + public ClientResponse readItemInNamedAuthority(String authShortId, String csid) { + return personAuthorityProxy.readItemInNamedAuthority(authShortId, csid); + } + + /** + * Read named item in Named Authority. + * + * @param authShortId the shortIdentifier for the Authority + * @param itemShortId the shortIdentifier for the item + * @return the client response + */ + public ClientResponse readNamedItemInNamedAuthority(String authShortId, String itemShortId) { + return personAuthorityProxy.readNamedItem(authShortId, itemShortId); + } + /** * Creates the item. * diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index 142aa80fe..a734425a3 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -40,6 +40,7 @@ import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.person.PersonsCommon; import org.collectionspace.services.person.PersonauthoritiesCommon; 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.slf4j.Logger; @@ -53,19 +54,88 @@ public class PersonAuthorityClientUtils { /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(PersonAuthorityClientUtils.class); + private static final ServiceRequestType READ_REQ = ServiceRequestType.READ; + + /** + * @param csid the id of the PersonAuthority + * @param client if null, creates a new client + * @return + */ + public static String getAuthorityRefName(String csid, PersonAuthorityClient client){ + if(client==null) + client = new PersonAuthorityClient(); + ClientResponse res = client.read(csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + PersonauthoritiesCommon personAuthority = + (PersonauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input, + client.getCommonPartName(), PersonauthoritiesCommon.class); + if(personAuthority==null) { + throw new RuntimeException("Null personAuthority returned from service."); + } + return personAuthority.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } + + /** + * @param csid the id of the PersonAuthority + * @param client if null, creates a new client + * @return + */ + public static String getPersonRefName(String inAuthority, String csid, PersonAuthorityClient client){ + if(client==null) + client = new PersonAuthorityClient(); + ClientResponse res = client.readItem(inAuthority, csid); + try { + int statusCode = res.getStatus(); + if(!READ_REQ.isValidStatusCode(statusCode) + ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) { + throw new RuntimeException("Invalid status code returned: "+statusCode); + } + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + PersonsCommon person = + (PersonsCommon) CollectionSpaceClientUtils.extractPart(input, + client.getItemCommonPartName(), PersonsCommon.class); + if(person==null) { + throw new RuntimeException("Null person returned from service."); + } + return person.getRefName(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); + } + } /** * Creates the person authority instance. * * @param displayName the display name - * @param refName the ref name + * @param shortIdentifier the short Id * @param headerLabel the header label * @return the multipart output */ public static MultipartOutput createPersonAuthorityInstance( - String displayName, String refName, String headerLabel ) { + String displayName, String shortIdentifier, String headerLabel ) { PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon(); personAuthority.setDisplayName(displayName); + personAuthority.setShortIdentifier(shortIdentifier); + String refName = createPersonAuthRefName(shortIdentifier, displayName); personAuthority.setRefName(refName); personAuthority.setVocabType("PersonAuthority"); MultipartOutput multipart = new MultipartOutput(); @@ -83,17 +153,21 @@ public class PersonAuthorityClientUtils { /** * Creates the person instance. * - * @param inAuthority the in authority - * @param personRefName the person ref name + * @param inAuthority the owning authority + * @param personAuthRefName the owning Authority ref name * @param personInfo the person info * @param headerLabel the header label * @return the multipart output */ public static MultipartOutput createPersonInstance(String inAuthority, - String personRefName, Map personInfo, String headerLabel){ + String personAuthRefName, Map personInfo, String headerLabel){ PersonsCommon person = new PersonsCommon(); person.setInAuthority(inAuthority); - person.setRefName(personRefName); + String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER); + if (shortId == null || shortId.isEmpty()) { + throw new IllegalArgumentException("shortIdentifier cannot be null or empty"); + } + person.setShortIdentifier(shortId); // // If the 'DISPLAY_NAME_COMPUTED' property is null or empty then @@ -112,6 +186,8 @@ public class PersonAuthorityClientUtils { if (displayNameComputed == false && displayName == null) { throw new IllegalArgumentException("displayName cannot be null when displayComputed is 'false'"); } + String refName = createPersonRefName(personAuthRefName, shortId, displayName); + person.setRefName(refName); String value; if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) //FIXME: REM - I don't think we need to check for null -null is a valid value and won't cause any problems. @@ -168,7 +244,7 @@ public class PersonAuthorityClientUtils { * * @param vcsid the vcsid * @param personAuthorityRefName the person authority ref name - * @param personMap the person map + * @param personMap the person map. PersonJAXBSchema.SHORT_IDENTIFIER is REQUIRED. * @param client the client * @return the string */ @@ -195,16 +271,15 @@ public class PersonAuthorityClientUtils { personMap.get(PersonJAXBSchema.SUR_NAME), personMap.get(PersonJAXBSchema.BIRTH_DATE), personMap.get(PersonJAXBSchema.DEATH_DATE)); + personMap.put(PersonJAXBSchema.DISPLAY_NAME, displayName); } - String refName = createPersonRefName(personAuthorityRefName, displayName, true); - if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \"" + displayName +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\""); } MultipartOutput multipart = - createPersonInstance(vcsid, refName, + createPersonInstance(vcsid, personAuthorityRefName, personMap, client.getItemCommonPartName()); String result = null; @@ -213,12 +288,12 @@ public class PersonAuthorityClientUtils { int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+refName + throw new RuntimeException("Could not create Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER) +"\" in personAuthority: \"" + personAuthorityRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+refName + throw new RuntimeException("Unexpected Status when creating Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER) +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode); } @@ -231,17 +306,17 @@ public class PersonAuthorityClientUtils { } /** - * Creates the person auth ref name. + * Creates the personAuthority ref name. * - * @param personAuthorityName the person authority name - * @param withDisplaySuffix the with display suffix + * @param shortId the personAuthority shortIdentifier + * @param displaySuffix displayName to be appended, if non-null * @return the string */ - public static String createPersonAuthRefName(String personAuthorityName, boolean withDisplaySuffix) { + public static String createPersonAuthRefName(String shortId, String displaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:personauthority:name(" - +personAuthorityName+")"; - if(withDisplaySuffix) - refName += "'"+personAuthorityName+"'"; + +shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } @@ -249,15 +324,15 @@ public class PersonAuthorityClientUtils { * Creates the person ref name. * * @param personAuthRefName the person auth ref name - * @param personName the person name - * @param withDisplaySuffix the with display suffix + * @param shortId the person shortIdentifier + * @param displaySuffix displayName to be appended, if non-null * @return the string */ public static String createPersonRefName( - String personAuthRefName, String personName, boolean withDisplaySuffix) { - String refName = personAuthRefName+":person:name("+personName+")"; - if(withDisplaySuffix) - refName += "'"+personName+"'"; + String personAuthRefName, String shortId, String displaySuffix) { + String refName = personAuthRefName+":person:name("+shortId+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java index b66d7b41b..56faaf186 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java @@ -89,7 +89,16 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @GET @Produces({"application/xml"}) @Path("/urn:cspace:name({specifier})/items/") - ClientResponse readItemListForNamedAuthority(@PathParam("specifier") String specifier); + ClientResponse readItemListForNamedAuthority( + @PathParam("specifier") String specifier); + + // List Items for a named authority matching a partial term. + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({specifier})/items/") + ClientResponse readItemListForNamedAuthority( + @PathParam("specifier") String specifier, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm); //(C)reate Item @POST @@ -101,6 +110,21 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy { @Path("/{vcsid}/items/{csid}") ClientResponse readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + //(R)ead Named Item + @GET + @Path("/{vcsid}/items/urn:cspace:name({specifier})") + ClientResponse readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier); + + //(R)ead Item In Named Authority + @GET + @Path("/urn:cspace:name({specifier})/items/{csid}") + ClientResponse readItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("csid") String csid); + + //(R)ead Named Item In Named Authority + @GET + @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})") + ClientResponse readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier); + //(U)pdate Item @PUT @Path("/{vcsid}/items/{csid}") diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java index 869795cf6..a6558eafc 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java @@ -69,6 +69,9 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // Displayname final String TEST_PARTIAL_TERM_DISPLAY_NAME = TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME; + // + // shortId + final String TEST_SHORT_ID = "lechWalesa"; // Non-existent partial term name (first letters of each of the words // in a pangram for the English alphabet). @@ -434,13 +437,12 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - String identifier = createIdentifier(); - String displayName = "displayName-" + identifier; - String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false); - String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true); + String shortId = createIdentifier(); + String displayName = "displayName-" + shortId; + String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, fullRefName, client.getCommonPartName()); + displayName, shortId, client.getCommonPartName()); String newID = null; ClientResponse res = client.create(multipart); @@ -479,7 +481,8 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { * @param authorityCsid The CSID of the Authority in which the term will be created. * @param authRefName The refName of the Authority in which the term will be created. */ - private void createItemInAuthorityForPartialTermMatch(String authorityCsid, String authRefName) + private void createItemInAuthorityForPartialTermMatch( + String authorityCsid, String authRefName) throws Exception { String testName = "createItemInAuthorityForPartialTermMatch"; @@ -490,19 +493,18 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, - TEST_PARTIAL_TERM_DISPLAY_NAME, true); Map partialTermPersonMap = new HashMap(); // // Fill the property map // + partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID ); partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME); partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME); partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME); partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male"); MultipartOutput multipart = - PersonAuthorityClientUtils.createPersonInstance(authorityCsid, refName, partialTermPersonMap, + PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, partialTermPersonMap, client.getItemCommonPartName() ); String newID = null; diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index ebcb15414..47ded8b7c 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -88,18 +88,13 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { /** The test death date. */ final String TEST_DEATH_DATE = "June 11, 1979"; - - /** The known resource id. */ + + // Hold some values for a recently created item to verify upon read. private String knownResourceId = null; - - /** The known resource display name. */ - private String knownResourceDisplayName = null; - - /** The known resource ref name. */ + private String knownResourceShortIdentifer = null; private String knownResourceRefName = null; - - /** The known item resource id. */ private String knownItemResourceId = null; + private String knownItemResourceShortIdentifer = null; // The resource ID of an item resource used for partial term matching tests. private String knownItemPartialTermResourceId = null; @@ -118,6 +113,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { private Map allContactResourceIdsCreated = new HashMap(); + protected void setKnownResource( String id, String shortIdentifer, + String refName ) { + knownResourceId = id; + knownResourceShortIdentifer = shortIdentifer; + knownResourceRefName = refName; + } + + protected void setKnownItemResource( String id, String shortIdentifer ) { + knownItemResourceId = id; + knownItemResourceShortIdentifer = shortIdentifer; + } + + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -157,13 +165,12 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - String identifier = createIdentifier(); - String displayName = "displayName-" + identifier; - String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false); - String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true); + String shortId = createIdentifier(); + String displayName = "displayName-" + shortId; + String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, fullRefName, client.getCommonPartName()); + displayName, shortId, client.getCommonPartName()); String newID = null; ClientResponse res = client.create(multipart); @@ -187,15 +194,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { } finally { res.releaseConnection(); } - // Store the refname from the first resource created - // for additional tests below. - knownResourceRefName = baseRefName; - // Store the ID returned from the first resource created - // for additional tests below. + // Save values for additional tests if (knownResourceId == null){ - knownResourceId = newID; - knownResourceDisplayName = displayName; - if (logger.isDebugEnabled()) { + setKnownResource( newID, shortId, baseRefName ); + if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } } @@ -235,13 +237,15 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true); + Map johnWayneMap = new HashMap(); // // Fill the property map // + String shortId = "johnWayneActor"; johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false"); johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne"); + johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME); johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME); @@ -256,7 +260,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { "He was also known for his conservative political views and his support in " + "the 1950s for anti-communist positions."); MultipartOutput multipart = - PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap, + PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap, client.getItemCommonPartName() ); String newID = null; @@ -280,7 +284,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Store the ID returned from the first item resource created // for additional tests below. if (knownItemResourceId == null){ - knownItemResourceId = newID; + setKnownItemResource(newID, shortId); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } @@ -548,38 +552,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) public void read(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); - - // Submit the request to the service and store the response. - PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse res = client.read(knownResourceId); - try { - int statusCode = res.getStatus(); - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures - try { - MultipartInput input = (MultipartInput) res.getEntity(); - PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); - Assert.assertNotNull(personAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } - } finally { - res.releaseConnection(); - } + readInternal(testName, knownResourceId, null); } /** @@ -591,7 +564,10 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, groups = {"read"}, dependsOnGroups = {"create"}) public void readByName(String testName) throws Exception { - + readInternal(testName, null, knownResourceShortIdentifer); + } + + protected void readInternal(String testName, String CSID, String shortId) { if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -600,7 +576,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse res = client.readByName(knownResourceDisplayName); + ClientResponse res = null; + if(CSID!=null) { + res = client.read(CSID); + } else if(shortId!=null) { + res = client.readByName(shortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } try { int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -625,51 +608,58 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { } } -/* - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readByName(String testName) throws Exception { - - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } - // Perform setup. - setupRead(); + /** + * Read item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readItem(String testName) throws Exception { + readItemInternal(testName, knownResourceId, null, knownItemResourceId, null); + } - // Submit the request to the service and store the response. - ClientResponse res = client.read(knownResourceId); - int statusCode = res.getStatus(); + /** + * Read item in Named Auth. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readItemInNamedAuth(String testName) throws Exception { + readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null); + } - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures - try { - MultipartInput input = (MultipartInput) res.getEntity(); - PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input, - client.getCommonPartName(), PersonauthoritiesCommon.class); - Assert.assertNotNull(personAuthority); - } catch (Exception e) { - throw new RuntimeException(e); - } + /** + * Read named item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readNamedItem(String testName) throws Exception { + readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer); } -*/ /** - * Read item. - * - * @param testName the test name - * @throws Exception the exception - */ -@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"read"}) - public void readItem(String testName) throws Exception { - + * Read Named item in Named Auth. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readItem"}, dependsOnGroups = {"read"}) + public void readNamedItemInNamedAuth(String testName) throws Exception { + readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer); + } + + protected void readItemInternal(String testName, + String authCSID, String authShortId, String itemCSID, String itemShortId) + throws Exception { + if (logger.isDebugEnabled()) { logger.debug(testBanner(testName, CLASS_NAME)); } @@ -678,7 +668,26 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); - ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + ClientResponse res = null; + if(authCSID!=null) { + if(itemCSID!=null) { + res = client.readItem(authCSID, itemCSID); + } else if(itemShortId!=null) { + res = client.readNamedItem(authCSID, itemShortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } + } else if(authShortId!=null) { + if(itemCSID!=null) { + res = client.readItemInNamedAuthority(authShortId, itemCSID); + } else if(itemShortId!=null) { + res = client.readNamedItemInNamedAuthority(authShortId, itemShortId); + } else { + Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null"); + } + } else { + Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null"); + } try { int statusCode = res.getStatus(); @@ -913,7 +922,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { * @throws Exception the exception */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readContact(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -998,7 +1007,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { * @param testName the test name */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readItem"}) + groups = {"readItem"}, dependsOnMethods = {"readItem"}) public void readItemNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1032,7 +1041,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { * @param testName the test name */ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"read"}, dependsOnMethods = {"readContact"}) + groups = {"readItem"}, dependsOnMethods = {"readContact"}) public void readContactNonExistent(String testName) { if (logger.isDebugEnabled()) { @@ -1115,7 +1124,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { item.getDisplayName()); logger.debug(testName + ": list-item[" + i + "] URI=" + item.getUri()); - readItemList(csid, null); + readItemList(csid, null, testName); i++; } } @@ -1124,17 +1133,19 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { /** * Read item list. */ - @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) - public void readItemList() { - readItemList(knownResourceId, null); + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnMethods = {"readList"}) + public void readItemList(String testName) { + readItemList(knownResourceId, null, testName); } /** * Read item list by authority name. */ - @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) - public void readItemListByAuthorityName() { - readItemList(null, knownResourceDisplayName); + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnMethods = {"readItemList"}) + public void readItemListByAuthorityName(String testName) { + readItemList(null, knownResourceShortIdentifer, testName); } /** @@ -1143,9 +1154,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { * @param vcsid the vcsid * @param name the name */ - private void readItemList(String vcsid, String name) { - - final String testName = "readItemList"; + private void readItemList(String vcsid, String name, String testName) { // Perform setup. setupReadList(); @@ -1683,9 +1692,8 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in update(), below. PersonAuthorityClient client = new PersonAuthorityClient(); String displayName = "displayName-NON_EXISTENT_ID"; - String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - displayName, fullRefName, client.getCommonPartName()); + displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); try { @@ -1725,13 +1733,14 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // The only relevant ID may be the one used in update(), below. PersonAuthorityClient client = new PersonAuthorityClient(); Map nonexMap = new HashMap(); + nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX"); nonexMap.put(PersonJAXBSchema.FORE_NAME, "John"); nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); nonexMap.put(PersonJAXBSchema.GENDER, "male"); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, - PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap, - client.getItemCommonPartName() ); + PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), + nonexMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); try { diff --git a/services/person/import/src/main/java/org/collectionspace/services/person/importer/PersonAuthorityBaseImport.java b/services/person/import/src/main/java/org/collectionspace/services/person/importer/PersonAuthorityBaseImport.java index b69799cd2..f68810601 100644 --- a/services/person/import/src/main/java/org/collectionspace/services/person/importer/PersonAuthorityBaseImport.java +++ b/services/person/import/src/main/java/org/collectionspace/services/person/importer/PersonAuthorityBaseImport.java @@ -62,7 +62,7 @@ public class PersonAuthorityBaseImport { // Instance variables specific to this test. private PersonAuthorityClient client = new PersonAuthorityClient(); - public void createPersonAuthority(String personAuthorityName, + public void createPersonAuthority(String displayName, String shortId, List> personMaps ) { // Expected status code: 201 Created @@ -71,33 +71,31 @@ public class PersonAuthorityBaseImport { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; if(logger.isDebugEnabled()){ - logger.debug("Import: Create personAuthority: \"" + personAuthorityName +"\""); + logger.debug("Import: Create personAuthority: \"" + displayName +"\""); } String basePersonRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, false); - String fullPersonRefName = - PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, true); + PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - personAuthorityName, fullPersonRefName, client.getCommonPartName()); + displayName, shortId, client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create enumeration: \""+personAuthorityName + throw new RuntimeException("Could not create enumeration: \""+displayName +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { throw new RuntimeException("Unexpected Status when creating enumeration: \"" - +personAuthorityName +"\", Status:"+ statusCode); + +displayName +"\", Status:"+ statusCode); } // Store the ID returned from this create operation // for additional tests below. String newPersonAuthorityId = PersonAuthorityClientUtils.extractId(res); if(logger.isDebugEnabled()){ - logger.debug("Import: Created personAuthorityulary: \"" + personAuthorityName +"\" ID:" + logger.debug("Import: Created personAuthorityulary: \"" + displayName +"\" ID:" +newPersonAuthorityId ); } for(Map personMap : personMaps){ @@ -113,12 +111,14 @@ public class PersonAuthorityBaseImport { PersonAuthorityBaseImport pabi = new PersonAuthorityBaseImport(); final String demoPersonAuthorityName = "Demo Person Authority"; + final String demoPersonAuthorityShortId = "demoPersonAuth"; /* Strings are: shortName, longName, nameAdditions, contactName, foundingDate, dissolutionDate, foundingPlace, function, description */ Map johnWayneMap = new HashMap(); + johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "johnWayne_Actor"); johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John"); johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); johnWayneMap.put(PersonJAXBSchema.GENDER, "male"); @@ -132,6 +132,7 @@ public class PersonAuthorityBaseImport { "He was also known for his conservative political views and his support in " + "the 1950s for anti-communist positions."); Map patrickSchmitzMap = new HashMap(); + patrickSchmitzMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "plSchmitz_Geek"); patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick"); patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz"); patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male"); @@ -148,7 +149,8 @@ public class PersonAuthorityBaseImport { List> personsMaps = Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap ); - pabi.createPersonAuthority(demoPersonAuthorityName, personsMaps); + pabi.createPersonAuthority(demoPersonAuthorityName, + demoPersonAuthorityShortId, personsMaps); logger.info("PersonAuthorityBaseImport complete."); } diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java index b80986b82..691f44f76 100644 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java +++ b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java @@ -10,6 +10,7 @@ package org.collectionspace.services; public interface PersonAuthorityJAXBSchema { final static String PERSONAUTHORITIES_COMMON = "personauthorities_common"; final static String DISPLAY_NAME = "displayName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String REF_NAME = "refName"; final static String VOCAB_TYPE = "vocabType"; final static String CSID = "csid"; diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java index c9e1f54ed..ad4fdf305 100644 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java +++ b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java @@ -11,6 +11,7 @@ public interface PersonJAXBSchema { final static String PERSONS_COMMON = "persons_common"; final static String CSID = "csid"; final static String IN_AUTHORITY = "inAuthority"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String REF_NAME = "refName"; final static String DISPLAY_NAME = "displayName"; final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; diff --git a/services/person/jaxb/src/main/resources/person_common.xsd b/services/person/jaxb/src/main/resources/person_common.xsd index 4294cef9c..a41450d88 100644 --- a/services/person/jaxb/src/main/resources/person_common.xsd +++ b/services/person/jaxb/src/main/resources/person_common.xsd @@ -33,6 +33,7 @@ + diff --git a/services/person/jaxb/src/main/resources/personauthority_common.xsd b/services/person/jaxb/src/main/resources/personauthority_common.xsd index 7ff8dcd40..3d6f0ba03 100644 --- a/services/person/jaxb/src/main/resources/personauthority_common.xsd +++ b/services/person/jaxb/src/main/resources/personauthority_common.xsd @@ -36,6 +36,7 @@ + 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 c6a488486..22326fc43 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 @@ -244,13 +244,13 @@ public class PersonAuthorityResource extends } String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+ - ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+ + ":"+PersonAuthorityJAXBSchema.SHORT_IDENTIFIER+ "='"+specifier+"'"; // We only get a single doc - if there are multiple, // it is an error in use. if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority with name=" + specifier); + logger.debug("getPersonAuthorityByName with name=" + specifier); } MultipartOutput result = null; try { @@ -266,7 +266,7 @@ public class PersonAuthorityResource extends throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority", dnfe); + logger.debug("getPersonAuthorityByName", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed on PersonAuthority spec=" + specifier).type( @@ -274,7 +274,7 @@ public class PersonAuthorityResource extends throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { - logger.debug("getPersonAuthority", e); + logger.debug("getPersonAuthorityByName", e); } Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); @@ -656,6 +656,144 @@ public class PersonAuthorityResource extends return result; } + /** + * Gets the person by name. + * + * @param parentcsid the parentcsid + * @param itemspecifier the shrotId of the person + * + * @return the person + */ + @GET + @Path("{csid}/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getPersonByName( + @PathParam("csid") String parentcsid, + @PathParam("itemspecifier") String itemspecifier) { + if (parentcsid == null || "".equals(parentcsid) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getPersonByName: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Person with parentcsid=" + + parentcsid + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + PersonJAXBSchema.PERSONS_COMMON+ + ":"+PersonJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + if (logger.isDebugEnabled()) { + logger.debug("getPerson with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getPerson", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Person itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getPerson", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the person by name, in a named authority. + * + * @param parentspecifier the shortId of the parent + * @param itemspecifier the shortId of the person + * + * @return the person + */ + @GET + @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})") + public MultipartOutput getPersonByNameInNamedAuthority( + @PathParam("parentspecifier") String parentspecifier, + @PathParam("itemspecifier") String itemspecifier) { + if (parentspecifier == null || "".equals(parentspecifier) + || itemspecifier == null || "".equals(itemspecifier)) { + logger.error("getPersonByNameInNamedAuthority: missing parentcsid or itemspecifier!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Person with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + PersonJAXBSchema.PERSONS_COMMON+ + ":"+PersonJAXBSchema.SHORT_IDENTIFIER+ + "='"+itemspecifier+"'"; + if (logger.isDebugEnabled()) { + logger.debug("getPersonByNameInNamedAuthority with parentspecifier=" + + parentspecifier + " and itemspecifier=" + itemspecifier); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + // HACK HACK Since we do not use the parent CSID yet this should work. + DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, handler); + // TODO should we assert that the item is in the passed personAuthority? + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getPersonByNameInNamedAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Person itemspecifier=" + itemspecifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getPersonByNameInNamedAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + /** * Gets the person list. * @@ -727,31 +865,15 @@ public class PersonAuthorityResource extends @Context UriInfo ui) { PersonsCommonList personObjectList = new PersonsCommonList(); try { + MultivaluedMap queryParams = ui.getQueryParameters(); String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON + - ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME + + ":" + PersonAuthorityJAXBSchema.SHORT_IDENTIFIER + "='" + 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); - - // Add the where clause "persons_common:inAuthority='" + parentcsid + "'" - handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" + - PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); - - // AND persons_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" + - PersonJAXBSchema.DISPLAY_NAME + - " LIKE " + - "'%" + partialTerm + "%'"; - handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - personObjectList = (PersonsCommonList) handler.getCommonPartList(); + return getPersonList(parentcsid, partialTerm, ui); } catch (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -764,7 +886,6 @@ public class PersonAuthorityResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); throw new WebApplicationException(response); } - return personObjectList; } /** diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java new file mode 100644 index 000000000..decd75b27 --- /dev/null +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java @@ -0,0 +1,111 @@ +/** + * 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 University of California at Berkeley + + * 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. + *//** + * 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 University of California at Berkeley + + * 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. + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.person.nuxeo; + +import java.util.regex.Pattern; + +import org.collectionspace.services.person.PersonauthoritiesCommon; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class PersonAuthorityValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(PersonAuthorityValidatorHandler.class); + private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + if(logger.isDebugEnabled()) { + logger.debug("validate() action=" + action.name()); + } + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + PersonauthoritiesCommon personAuth = + (PersonauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + PersonauthoritiesCommon.class); + String msg = ""; + boolean invalid = false; + String shortId = personAuth.getShortIdentifier(); + if(shortId==null){ + invalid = true; + msg += "shortIdentifier must be non-null"; + } else if(shortIdBadPattern.matcher(shortId).find()) { + invalid = true; + msg += "shortIdentifier must only contain standard word characters"; + } + /* + if(action.equals(Action.CREATE)) { + //create specific validation here + } else if(action.equals(Action.UPDATE)) { + //update specific validation here + } + */ + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +} diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java index f2f8023f5..78eee7972 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java @@ -49,6 +49,8 @@ */ package org.collectionspace.services.person.nuxeo; +import java.util.regex.Pattern; + import org.collectionspace.services.person.PersonsCommon; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; @@ -65,6 +67,7 @@ import org.slf4j.LoggerFactory; public class PersonValidatorHandler implements ValidatorHandler { final Logger logger = LoggerFactory.getLogger(PersonValidatorHandler.class); + private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches() @Override public void validate(Action action, ServiceContext ctx) @@ -81,6 +84,14 @@ public class PersonValidatorHandler implements ValidatorHandler { if(!person.isDisplayNameComputed() && (person.getDisplayName()==null)) { invalid = true; msg += "displayName must be non-null if displayNameComputed is false!"; + } + String shortId = person.getShortIdentifier(); + if(shortId==null){ + invalid = true; + msg += "shortIdentifier must be non-null"; + } else if(shortIdBadPattern.matcher(shortId).find()) { + invalid = true; + msg += "shortIdentifier must only contain standard word characters"; } /* if(action.equals(Action.CREATE)) {