]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-590, CSPACE-2126, modifying authorities to support shortIdentifier. This is...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 23 Jun 2010 06:26:51 +0000 (06:26 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Wed, 23 Jun 2010 06:26:51 +0000 (06:26 +0000)
52 files changed:
services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionAuthRefsTest.java
services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java [new file with mode: 0644]
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectAuthRefsTest.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeAuthRefsTest.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/PersonAuthRefDocsTest.java
services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java
services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java
services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml
services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd
services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd
services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java
services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java
services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java
services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java
services/location/jaxb/src/main/resources/location_common.xsd
services/location/jaxb/src/main/resources/locationauthority_common.xsd
services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java
services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementAuthRefsTest.java
services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml
services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd
services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd
services/organization/client/pom.xml
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java
services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java
services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java
services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java
services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java
services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java
services/organization/jaxb/src/main/resources/organization_common.xsd
services/organization/jaxb/src/main/resources/orgauthority_common.xsd
services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java [new file with mode: 0644]
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java
services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/OSGI-INF/layouts-contrib.xml
services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/personauthorities_common.xsd
services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java
services/person/import/src/main/java/org/collectionspace/services/person/importer/PersonAuthorityBaseImport.java
services/person/jaxb/src/main/java/org/collectionspace/services/PersonAuthorityJAXBSchema.java
services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java
services/person/jaxb/src/main/resources/person_common.xsd
services/person/jaxb/src/main/resources/personauthority_common.xsd
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java [new file with mode: 0644]
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java

index f526eac63bcdc59495c319d6d363b4062d10a388..69eca30e41c6f4917e8fdd60b3a41e426afa5769 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> 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 (file)
index 0000000..2d41de9
--- /dev/null
@@ -0,0 +1,268 @@
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright (c) 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ *\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.collectionspace.services.client;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.io.StringWriter;\r
+import java.util.List;\r
+\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.bind.Marshaller;\r
+import javax.xml.bind.Unmarshaller;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.apache.commons.io.FileUtils;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.w3c.dom.Document;\r
+\r
+/**\r
+ * CollectionSpaceClientUtils.\r
+ *\r
+ * Base abstract class on which client tests of services are based.\r
+ *\r
+ * $LastChangedRevision: 2261 $\r
+ * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $\r
+ */\r
+\r
+// FIXME: http://issues.collectionspace.org/browse/CSPACE-1685\r
+\r
+public class CollectionSpaceClientUtils {\r
+\r
+    //Maven's base directory -i.e., the one containing the current pom.xml\r
+    /** The Constant logger. */\r
+    private static final Logger logger = LoggerFactory.getLogger(CollectionSpaceClientUtils.class);\r
+        \r
+    protected static final int STATUS_BAD_REQUEST =\r
+        Response.Status.BAD_REQUEST.getStatusCode();\r
+    protected static final int STATUS_CREATED =\r
+        Response.Status.CREATED.getStatusCode();\r
+    protected static final int STATUS_NOT_FOUND =\r
+        Response.Status.NOT_FOUND.getStatusCode();\r
+    protected static final int STATUS_OK =\r
+        Response.Status.OK.getStatusCode();\r
+\r
+    /**\r
+     * Extract id.\r
+     *\r
+     * @param res the res\r
+     * @return the string\r
+     */\r
+    static public String extractId(ClientResponse<Response> res) {\r
+        MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+        String uri = (String) ((List<Object>) mvm.get("Location")).get(0);\r
+        if (logger.isDebugEnabled()) {\r
+            logger.debug("extractId:uri=" + uri);\r
+        }\r
+        String[] segments = uri.split("/");\r
+        String id = segments[segments.length - 1];\r
+        if (logger.isDebugEnabled()) {\r
+            logger.debug("id=" + id);\r
+        }\r
+        return id;\r
+    }\r
\r
+    /**\r
+     * Extract part.\r
+     *\r
+     * @param input the input\r
+     * @param label the label\r
+     * @param clazz the clazz\r
+     * @return the object\r
+     * @throws Exception the exception\r
+     */\r
+    static public Object extractPart(MultipartInput input, String label, Class<?> clazz)\r
+            throws Exception {\r
+        Object obj = null;\r
+        String partLabel = "";\r
+        List<InputPart> parts = input.getParts();\r
+        if (parts.size() == 0) {\r
+            logger.warn("No parts found in multipart body.");\r
+        }\r
+        if (logger.isDebugEnabled()) {\r
+            logger.debug("Parts:");\r
+            for (InputPart part : parts) {\r
+                partLabel = part.getHeaders().getFirst("label");\r
+                logger.debug("part = " + partLabel);\r
+            }\r
+        }\r
+        boolean partLabelMatched = false;\r
+        for (InputPart part : parts) {\r
+            partLabel = part.getHeaders().getFirst("label");\r
+            if (label.equalsIgnoreCase(partLabel)) {\r
+                partLabelMatched = true;\r
+                if (logger.isDebugEnabled()) {\r
+                    logger.debug("found part" + partLabel);\r
+                }\r
+                String partStr = part.getBodyAsString();\r
+                if (partStr == null || partStr.trim().isEmpty()) {\r
+                    logger.warn("Part '" + label + "' in multipart body is empty.");\r
+                } else {\r
+                    if (logger.isDebugEnabled()) {\r
+                        logger.debug("extracted part as str=\n" + partStr);\r
+                    }\r
+                    obj = part.getBody(clazz, null);\r
+                    if (logger.isDebugEnabled()) {\r
+                        logger.debug("extracted part as obj=\n",\r
+                                objectAsXmlString(obj, clazz));\r
+                    }\r
+                }\r
+                break;\r
+            }\r
+        }\r
+        if (!partLabelMatched) {\r
+            logger.warn("Could not find part '" + label + "' in multipart body.");\r
+            // In the event that getBodyAsString() or getBody(), above, do *not*\r
+            // throw an IOException, but getBody() nonetheless retrieves a null object.\r
+            // This *may* be unreachable.\r
+        } else if (obj == null) {\r
+            logger.warn("Could not extract part '" + label\r
+                    + "' in multipart body as an object.");\r
+        }\r
+        return obj;\r
+    }\r
+\r
+    /**\r
+     * Gets the part object.\r
+     *\r
+     * @param partStr the part str\r
+     * @param clazz the clazz\r
+     * @return the part object\r
+     * @throws JAXBException the jAXB exception\r
+     */\r
+    static public Object getPartObject(String partStr, Class<?> clazz)\r
+            throws JAXBException {\r
+        JAXBContext jc = JAXBContext.newInstance(clazz);\r
+        ByteArrayInputStream bais = null;\r
+        Object obj = null;\r
+        try {\r
+            bais = new ByteArrayInputStream(partStr.getBytes());\r
+            Unmarshaller um = jc.createUnmarshaller();\r
+            obj = um.unmarshal(bais);\r
+        } finally {\r
+            if (bais != null) {\r
+                try {\r
+                    bais.close();\r
+                } catch (Exception e) {\r
+                       if (logger.isDebugEnabled() == true) {\r
+                               e.printStackTrace();\r
+                       }\r
+                }\r
+            }\r
+        }\r
+        return obj;\r
+    }\r
+\r
+    /**\r
+     * Object as xml string.\r
+     *\r
+     * @param o the o\r
+     * @param clazz the clazz\r
+     * @return the string\r
+     */\r
+    static public String objectAsXmlString(Object o, Class<?> clazz) {\r
+        StringWriter sw = new StringWriter();\r
+        try {\r
+            JAXBContext jc = JAXBContext.newInstance(clazz);\r
+            Marshaller m = jc.createMarshaller();\r
+            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,\r
+                    Boolean.TRUE);\r
+            m.marshal(o, sw);\r
+        } catch (Exception e) {\r
+            e.printStackTrace();\r
+        }\r
+        return sw.toString();\r
+    }\r
+\r
+    /**\r
+     * getObjectFromFile get object of given class from given file (in classpath)\r
+     * @param jaxbClass\r
+     * @param fileName of the file to read to construct the object\r
+     * @return\r
+     * @throws Exception\r
+     */\r
+    static public Object getObjectFromFile(Class<?> jaxbClass, String fileName)\r
+            throws Exception {\r
+\r
+        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+        Unmarshaller unmarshaller = context.createUnmarshaller();\r
+        //note: setting schema to null will turn validator off\r
+        unmarshaller.setSchema(null);\r
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();\r
+        InputStream is = tccl.getResourceAsStream(fileName);\r
+        return getObjectFromStream(jaxbClass, is);\r
+    }\r
+\r
+    /**\r
+     * Gets the xml document.\r
+     *\r
+     * @param fileName the file name\r
+     * @return the xml document\r
+     * @throws Exception the exception\r
+     */\r
+    static public Document getXmlDocument(String fileName) throws Exception {\r
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r
+        File f = new File(fileName);\r
+        if (!f.exists()) {\r
+            throw new IllegalArgumentException("test data file " + fileName + " not found!");\r
+        }\r
+        // Create the builder and parse the file\r
+        return factory.newDocumentBuilder().parse(f);\r
+    }\r
+\r
+    /**\r
+     * Gets the xml document as string.\r
+     *\r
+     * @param fileName the file name\r
+     * @return the xml document as string\r
+     * @throws Exception the exception\r
+     */\r
+    static public String getXmlDocumentAsString(String fileName) throws Exception {\r
+        byte[] b = FileUtils.readFileToByteArray(new File(fileName));\r
+        return new String(b);\r
+    }\r
+\r
+    /**\r
+     * getObjectFromStream get object of given class from given inputstream\r
+     * @param jaxbClass\r
+     * @param is stream to read to construct the object\r
+     * @return\r
+     * @throws Exception\r
+     */\r
+    static public Object getObjectFromStream(Class<?> jaxbClass, InputStream is) throws Exception {\r
+        JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+        Unmarshaller unmarshaller = context.createUnmarshaller();\r
+        //note: setting schema to null will turn validator off\r
+        unmarshaller.setSchema(null);\r
+        return jaxbClass.cast(unmarshaller.unmarshal(is));\r
+    }\r
+}\r
index 9e4e1d006f8e1ba365e39710bc41b3d2577d97bb..cf5c8675efd2122c42d6c512c1de7dbeac5b4417 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
         int statusCode = res.getStatus();
 
index d3e7c09d42f532dc0926e20590ea7381699fc0ea..2137d338dd8668a07cff5b347c4f399cf2e48998 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> 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);
index 1be1479c5e79ddee6d15c57c89fe60aa40b51b30..246fb1f1a53546f5110e79fea7da1c28f61a6874 100644 (file)
@@ -71,6 +71,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
     private List<String> intakeIdsCreated = new ArrayList<String>();\r
     private List<String> orgIdsCreated = new ArrayList<String>();\r
     private String orgAuthCSID = null; \r
+    private String orgAuthRefName = null; \r
     private String currentOwnerOrgCSID = null; \r
     private String currentOwnerRefName = null;\r
     private String depositorRefName = null;\r
@@ -163,10 +164,10 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
      */\r
     protected void createOrgRefs(){\r
         OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
-       String authRefName = \r
-               OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false);\r
+        orgAuthRefName = \r
+               OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, null);\r
        MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(\r
-                       ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName());\r
+                       ORGANIZATION_AUTHORITY_NAME, ORGANIZATION_AUTHORITY_NAME, orgAuthClient.getCommonPartName());\r
         ClientResponse<Response> res = orgAuthClient.create(multipart);\r
         int statusCode = res.getStatus();\r
 \r
@@ -175,38 +176,40 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
         Assert.assertEquals(statusCode, STATUS_CREATED);\r
         orgAuthCSID = extractId(res);\r
         \r
-        currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
-                                                               authRefName, "Olivier Owner", true);\r
-                               currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName);\r
+               currentOwnerOrgCSID = createOrganization("olivierOwner", "Olivier Owner", "Olivier Owner");\r
         orgIdsCreated.add(currentOwnerOrgCSID);\r
+        currentOwnerRefName = OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, currentOwnerOrgCSID, orgAuthClient);\r
         \r
-        depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
-                                                                       authRefName, "Debbie Depositor", true);\r
-        orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName));\r
+               String newOrgCSID = createOrganization("debbieDepositor", "Debbie Depositor", "Debbie Depositor");\r
+        depositorRefName = \r
+               OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+        orgIdsCreated.add(newOrgCSID);\r
         \r
-        conditionCheckerAssessorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
-                                                                       authRefName, "Andrew Checker-Assessor", true);\r
-        orgIdsCreated.add(createOrganization("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName));\r
+               newOrgCSID = createOrganization("andrewCheckerAssessor", "Andrew Checker-Assessor", "Andrew Checker-Assessor");\r
+               conditionCheckerAssessorRefName = \r
+               OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+        orgIdsCreated.add(newOrgCSID);\r
         \r
-        insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
-                                                                       authRefName, "Ingrid Insurer", true);\r
-        orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName));\r
+               newOrgCSID = createOrganization("ingridInsurer", "Ingrid Insurer", "Ingrid Insurer");\r
+               insurerRefName = \r
+               OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+        orgIdsCreated.add(newOrgCSID);\r
         \r
-        valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
-                                                                       authRefName, "Vince Valuer", true);\r
-        orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName));\r
-        \r
-\r
+               newOrgCSID = createOrganization("vinceValuer", "Vince Valuer", "Vince Valuer");\r
+               valuerRefName = \r
+               OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+        orgIdsCreated.add(newOrgCSID);\r
     }\r
-    \r
-    protected String createOrganization(String shortName, String longName, String refName ) {\r
+\r
+    protected String createOrganization(String shortId, String shortName, String longName) {\r
         OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
         Map<String, String> orgInfo = new HashMap<String,String>();\r
+        orgInfo.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);\r
         orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName);\r
         orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName);\r
        MultipartOutput multipart = \r
-               OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, \r
-                               refName, orgInfo, orgAuthClient.getItemCommonPartName());\r
+               OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, orgAuthRefName,\r
+                               orgInfo, orgAuthClient.getItemCommonPartName());\r
         ClientResponse<Response> res = orgAuthClient.createItem(orgAuthCSID, multipart);\r
         int statusCode = res.getStatus();\r
 \r
index b600372d15f36fd6b80b6fdc079832f851d3234e..3bc8b4160a5cb4bd5e15fb0fceb436d4f917fd17 100644 (file)
@@ -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<Response> 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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
         int statusCode = res.getStatus();
 
index e51422ae03fb4ab754ea21aea12b3533faaf4c8d..122b15c1838f1ab81640d3dc41549497359d31a8 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
         int statusCode = res.getStatus();
 
index d7c3670cb9669470c3ed51b53732e94986ea854d..c6ba93baece1a9373c6353394ed7966e3c8fb10d 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
         int statusCode = res.getStatus();
 
index 6e6c34dc302ec89644af6db41c9ddd9268ab17e6..a8c915f1f67afc1c4b7782dae77daf742373d369 100644 (file)
@@ -11,6 +11,7 @@
       </templates>
       <rows>
         <row><widget>displayName</widget></row>
+                               <row><widget>shortIdentifier</widget></row>
         <row><widget>refName</widget></row>
         <row><widget>vocabType</widget></row>
       </rows>
         </properties>
       </widget>
       
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="locationauthorities_common">shortIdentifier</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
       <widget name="refName" type="text">
         <labels>
           <label mode="any">RefName</label>
@@ -65,6 +79,7 @@
       </templates>
       <rows>
         <row><widget>inAuthority</widget></row>
+                               <row><widget>shortIdentifier</widget></row>
         <row><widget>refName</widget></row>
         <row><widget>displayName</widget></row>
         <row><widget>displayNameComputed</widget></row>
         </properties>
       </widget>
 
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="locations_common">shortIdentifier</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
       <widget name="refName" type="text">
         <labels>
           <label mode="any">refName</label>
index 0a1f73678080b484bb683af8cb7d2130e12a6ced..a307bf88fdc461270d54f62e0b7b3e33790f9247 100644 (file)
@@ -24,6 +24,7 @@
 
                <!--  LocationAuthority Information Group -->
                <xs:element name="displayName" type="xs:string"/>
+               <xs:element name="shortIdentifier" type="xs:string"/>
                <xs:element name="refName" type="xs:string"/>
                <xs:element name="vocabType" type="xs:string"/>
 
index d64d2c15f107e84078e859001edab0b806d2f656..0bc24ef7648b62f21a4e36fec21d646ee1e9c685 100644 (file)
@@ -23,6 +23,7 @@
     <!--  Location Information Group -->
     <!--  inAuthority is the csid of the owning LocationAuthority -->
     <xs:element name="inAuthority" type="xs:string" />
+               <xs:element name="shortIdentifier" type="xs:string"/>
     <xs:element name="refName" type="xs:string"/>
     <xs:element name="displayName" type="xs:string"/>
     <xs:element name="displayNameComputed" type="xs:boolean"/>
index 063f1ac17ee818b2b9daf7ca315d6785e513af96..09ca4808eb0371c0693a022ffc80c79562d5bcbb 100644 (file)
@@ -34,9 +34,11 @@ public class LocationAuthorityClientUtils {
      * @return The MultipartOutput payload for the create call\r
      */\r
     public static MultipartOutput createLocationAuthorityInstance(\r
-               String displayName, String refName, String headerLabel ) {\r
+               String displayName, String shortIdentifier, String headerLabel ) {\r
         LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon();\r
         locationAuthority.setDisplayName(displayName);\r
+        locationAuthority.setShortIdentifier(shortIdentifier);\r
+        String refName = createLocationAuthRefName(shortIdentifier, displayName);\r
         locationAuthority.setRefName(refName);\r
         locationAuthority.setVocabType("LocationAuthority");\r
         MultipartOutput multipart = new MultipartOutput();\r
@@ -59,9 +61,13 @@ public class LocationAuthorityClientUtils {
      * @return The MultipartOutput payload for the create call\r
      */\r
     public static MultipartOutput createLocationInstance(String inAuthority, \r
-               String locationRefName, Map<String, String> locationInfo, String headerLabel){\r
+               String locationAuthRefName, Map<String, String> locationInfo, String headerLabel){\r
         LocationsCommon location = new LocationsCommon();\r
+       String shortId = locationInfo.get(LocationJAXBSchema.SHORT_IDENTIFIER);\r
+       String displayName = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME);\r
+       location.setShortIdentifier(shortId);\r
         location.setInAuthority(inAuthority);\r
+       String locationRefName = createLocationRefName(locationAuthRefName, shortId, displayName);\r
                location.setRefName(locationRefName);\r
                String value = null;\r
        value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
@@ -119,26 +125,26 @@ public class LocationAuthorityClientUtils {
                        locationMap.get(LocationJAXBSchema.NAME));\r
        }\r
        \r
-       String refName = createLocationRefName(locationAuthorityRefName, displayName, true);\r
-\r
        if(logger.isDebugEnabled()){\r
                logger.debug("Import: Create Item: \""+displayName\r
                                +"\" in locationAuthority: \"" + locationAuthorityRefName +"\"");\r
        }\r
        MultipartOutput multipart = \r
-               createLocationInstance( vcsid, refName,\r
+               createLocationInstance( vcsid, locationAuthorityRefName,\r
                        locationMap, client.getItemCommonPartName() );\r
        ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
 \r
        int statusCode = res.getStatus();\r
 \r
        if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
-               throw new RuntimeException("Could not create Item: \""+refName\r
+               throw new RuntimeException("Could not create Item: \""\r
+                               +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER)\r
                                +"\" in locationAuthority: \"" + locationAuthorityRefName\r
                                +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
        }\r
        if(statusCode != EXPECTED_STATUS_CODE) {\r
-               throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+               throw new RuntimeException("Unexpected Status when creating Item: \""\r
+                               +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER)\r
                                +"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode);\r
        }\r
 \r
@@ -200,19 +206,34 @@ public class LocationAuthorityClientUtils {
        return createItemInAuthority(vcsid, commonPartXML, client );\r
     }    \r
 \r
-    public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) {\r
+    /**\r
+     * Creates the locationAuthority ref name.\r
+     *\r
+     * @param shortId the locationAuthority shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
+     * @return the string\r
+     */\r
+    public static String createLocationAuthRefName(String shortId, String displaySuffix) {\r
        String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name("\r
-                       +locationAuthorityName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+locationAuthorityName+"'";\r
+                       +shortId+")";\r
+               if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+                       refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
+    /**\r
+     * Creates the location ref name.\r
+     *\r
+     * @param locationAuthRefName the locationAuthority ref name\r
+     * @param shortId the location shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
+     * @return the string\r
+     */\r
     public static String createLocationRefName(\r
-                                               String locationAuthRefName, String locationName, boolean withDisplaySuffix) {\r
-       String refName = locationAuthRefName+":location:name("+locationName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+locationName+"'";\r
+                                               String locationAuthRefName, String shortId, String displaySuffix) {\r
+       String refName = locationAuthRefName+":location:name("+shortId+")";\r
+               if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+                       refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
index 34759a91f5e9806c283f89fc8f3f2f7e43c8e380..776d270ef806b8af898f27c89cb4be7b79017ea4 100644 (file)
@@ -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<String, String> allItemResourceIdsCreated =
         new HashMap<String, String>();
     
+    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<Response> 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<String, String> shelf1Map = new HashMap<String,String>();
         // 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<Response> 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<MultipartInput> res = client.readByName(knownResourceDisplayName);
+        ClientResponse<MultipartInput> 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<LocationsCommonList> 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<MultipartInput> 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<String, String> nonexMap = new HashMap<String,String>();
         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<MultipartInput> res =
                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
         int statusCode = res.getStatus();
index 134e3193b61a36811dcf76902c2c8a2c856016e1..c699bf846bd4108922dfc9dfbc6fa694771add46 100644 (file)
@@ -11,6 +11,7 @@ public interface LocationAuthorityJAXBSchema {
        final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common";\r
        final static String DISPLAY_NAME = "displayName";\r
        final static String REF_NAME = "refName";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String VOCAB_TYPE = "vocabType";\r
        final static String CSID = "csid";\r
 }\r
index 7b7e70c46d50eae3b8029f81c75bb82867cb3ed1..01205e6f91aaf6f638438a45232e1a53b71dedff 100644 (file)
@@ -10,6 +10,7 @@ package org.collectionspace.services;
 public interface LocationJAXBSchema {\r
        final static String LOCATIONS_COMMON = "locations_common";\r
        final static String CSID = "csid";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String IN_AUTHORITY = "inAuthority";\r
        final static String REF_NAME = "refName";\r
        final static String DISPLAY_NAME = "displayName";\r
index f4fa8bee5f73f31cde4af2b2341247eff0b5ccfe..4ed013b46006c3bfe71d0b2a9d6fac4523c829ff 100644 (file)
@@ -22,6 +22,7 @@
                 
                 <!--  Location Information Group -->
                                                                <xs:element name="inAuthority" type="xs:string" />
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                                                                <xs:element name="refName" type="xs:string"/>
                                                                <xs:element name="displayName" type="xs:string"/>
                                                                <xs:element name="displayNameComputed" type="xs:boolean"/>
index 83547ffdbb0a518a75828aa1d319d91105edbd65..b14a584bc9909b0f8e0f7000c1171402c29eb61b 100644 (file)
@@ -36,6 +36,7 @@
                 
                 <!--  LocationAuthority Information Group -->
                 <xs:element name="displayName" type="xs:string"/>
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="refName" type="xs:string"/>
                 <xs:element name="vocabType" type="xs:string"/>
                 
index e71af43d77ebbee43876e7ce61f688657a00019c..8685189176aac2ac78ffc4010e9c4c85dd6241bf 100644 (file)
@@ -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<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+
-               ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+
+               ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+
                "='"+parentSpecifier+"'";
             // Need to get an Authority by name
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
index 7fb6ad7f9b0a7559d03d6080651bcb973c79ae42..96e9a5e50787064dbbb864e4e74d5948cd4a1bc5 100644 (file)
@@ -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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
         int statusCode = res.getStatus();
 
index 746cea068af0d92349f67a9a609bc227a884175e..c6194dd4d1fa9d3c8a885d2a896e53077e986709 100644 (file)
@@ -12,6 +12,7 @@
       <rows>
         <row><widget>displayName</widget></row>
         <row><widget>refName</widget></row>
+        <row><widget>shortIdentifier</widget></row>
         <row><widget>vocabType</widget></row>
       </rows>
 
         </properties>
       </widget>
       
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="orgauthorities_common">shortIdentifier</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
       <widget name="refName" type="text">
         <labels>
           <label mode="any">refName</label>
@@ -65,6 +79,7 @@
       </templates>
       <rows>
         <row><widget>inAuthority</widget></row>
+        <row><widget>shortIdentifier</widget></row>
         <row><widget>refName</widget></row>
         <row><widget>displayName</widget></row>
 <!--        <row><widget>displayNameComputed</widget></row> -->
         </properties>
       </widget>
 
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="organizations_common">shortIdentifier</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
      <widget name="refName" type="text">
         <labels>
           <label mode="any">refName</label>
index 8b01afa3fa15051bcae5e90b7e1c0455e817e1ff..1d234996a685689dc13d769597bdfeede18639ac 100644 (file)
@@ -24,6 +24,7 @@
     <!--  Organization Information Group -->
     <!--  inAuthority is the csid of the owning OrgAuthority -->
     <xs:element name="inAuthority" type="xs:string" />
+               <xs:element name="shortIdentifier" type="xs:string"/>
     <xs:element name="refName" type="xs:string"/>
     <xs:element name="displayName" type="xs:string"/>
     <xs:element name="displayNameComputed" type="xs:boolean"/>
index a1238c77bf40317705ca4a2f5721636d9da88d69..02b47f2a4eeb8bd976d47bdc07d66a1d8218ed97 100644 (file)
@@ -24,6 +24,7 @@
 
                <!--  OrgAuthority Information Group -->
                <xs:element name="displayName" type="xs:string"/>
+               <xs:element name="shortIdentifier" type="xs:string"/>
                <xs:element name="refName" type="xs:string"/>
                <xs:element name="vocabType" type="xs:string"/>
 
index 5afa2f9ae9cbe5d3ca6377e429efd7484e6c1e66..6be06fb10df134fa89ecdd27e347758be8f5bcb0 100644 (file)
             <artifactId>org.collectionspace.services.organization.jaxb</artifactId>\r
             <version>${project.version}</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>org.collectionspace.services</groupId>\r
+            <artifactId>org.collectionspace.services.common</artifactId>\r
+            <optional>true</optional>\r
+            <version>${project.version}</version>\r
+        </dependency>        \r
         <dependency>\r
             <groupId>org.collectionspace.services</groupId>\r
             <artifactId>org.collectionspace.services.client</artifactId>\r
index b6b954d33f432ef0f79b27f8ff60f3b62b034203..b826dac194efe5702dd4faf210e69b46c6616d51 100644 (file)
@@ -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<MultipartInput> 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<MultipartInput> 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<MultipartInput> readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
+        return orgAuthorityProxy.readNamedItem(authShortId, itemShortId);
+    }
+
     /**
      * Creates the item.
      *
index 68036c1822ea210a76b294a482051181202480e7..1459ae28b6af923e9f46bcdf5dc19c5a94f976a2 100644 (file)
@@ -37,7 +37,10 @@ import org.collectionspace.services.OrganizationJAXBSchema;
 import org.collectionspace.services.client.test.ServiceRequestType;\r
 import org.collectionspace.services.organization.OrganizationsCommon;\r
 import org.collectionspace.services.organization.OrgauthoritiesCommon;\r
+import org.collectionspace.services.person.PersonauthoritiesCommon;\r
+import org.collectionspace.services.person.PersonsCommon;\r
 import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
 import org.slf4j.Logger;\r
@@ -51,20 +54,88 @@ public class OrgAuthorityClientUtils {
     /** The Constant logger. */\r
     private static final Logger logger =\r
         LoggerFactory.getLogger(OrgAuthorityClientUtils.class);\r
+       private static final ServiceRequestType READ_REQ = ServiceRequestType.READ;\r
+\r
+    /**\r
+     * @param csid the id of the OrgAuthority\r
+     * @param client if null, creates a new client\r
+     * @return\r
+     */\r
+    public static String getAuthorityRefName(String csid, OrgAuthorityClient client){\r
+       if(client==null)\r
+               client = new OrgAuthorityClient();\r
+        ClientResponse<MultipartInput> res = client.read(csid);\r
+        try {\r
+               int statusCode = res.getStatus();\r
+               if(!READ_REQ.isValidStatusCode(statusCode)\r
+                       ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+                       throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+               }\r
+               //FIXME: remove the following try catch once Aron fixes signatures\r
+               try {\r
+                   MultipartInput input = (MultipartInput) res.getEntity();\r
+                   OrgauthoritiesCommon orgAuthority = \r
+                       (OrgauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input,\r
+                           client.getCommonPartName(), OrgauthoritiesCommon.class);\r
+                       if(orgAuthority==null) {\r
+                               throw new RuntimeException("Null orgAuthority returned from service.");\r
+                       }\r
+                   return orgAuthority.getRefName();\r
+               } catch (Exception e) {\r
+                   throw new RuntimeException(e);\r
+               }\r
+        } finally {\r
+               res.releaseConnection();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @param csid the id of the PersonAuthority\r
+     * @param client if null, creates a new client\r
+     * @return\r
+     */\r
+    public static String getOrgRefName(String inAuthority, String csid, OrgAuthorityClient client){\r
+       if(client==null)\r
+               client = new OrgAuthorityClient();\r
+        ClientResponse<MultipartInput> res = client.readItem(inAuthority, csid);\r
+        try {\r
+               int statusCode = res.getStatus();\r
+               if(!READ_REQ.isValidStatusCode(statusCode)\r
+                               ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+                       throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+               }\r
+               //FIXME: remove the following try catch once Aron fixes signatures\r
+               try {\r
+                   MultipartInput input = (MultipartInput) res.getEntity();\r
+                   OrganizationsCommon org = \r
+                       (OrganizationsCommon) CollectionSpaceClientUtils.extractPart(input,\r
+                           client.getItemCommonPartName(), OrganizationsCommon.class);\r
+                       if(org==null) {\r
+                               throw new RuntimeException("Null Organization returned from service.");\r
+                       }\r
+                   return org.getRefName();\r
+               } catch (Exception e) {\r
+                   throw new RuntimeException(e);\r
+               }\r
+        } finally {\r
+               res.releaseConnection();\r
+        }\r
+    }\r
 \r
     /**\r
      * Creates the org authority instance.\r
      *\r
      * @param displayName the display name\r
-     * @param refName the ref name\r
+     * @param shortIdentifier the short Id \r
      * @param headerLabel the header label\r
      * @return the multipart output\r
      */\r
     public static MultipartOutput createOrgAuthorityInstance(\r
-               String displayName, String refName, String headerLabel ) {\r
+               String displayName, String shortIdentifier, String headerLabel ) {\r
         OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon();\r
         orgAuthority.setDisplayName(displayName);\r
-        orgAuthority.setRefName(refName);\r
+        orgAuthority.setShortIdentifier(shortIdentifier);\r
+        String refName = createOrgAuthRefName(shortIdentifier, displayName);\r
         orgAuthority.setVocabType("OrgAuthority");\r
         MultipartOutput multipart = new MultipartOutput();\r
         OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);\r
@@ -81,13 +152,13 @@ public class OrgAuthorityClientUtils {
     /**\r
      * Creates the item in authority.\r
      *\r
-     * @param vcsid the vcsid\r
-     * @param orgAuthorityRefName the org authority ref name\r
-     * @param orgInfo the org info\r
+     * @param inAuthority the owning authority\r
+     * @param orgAuthorityRefName the owning Authority ref name\r
+     * @param orgInfo the org info. OrganizationJAXBSchema.SHORT_IDENTIFIER is REQUIRED.\r
      * @param client the client\r
      * @return the string\r
      */\r
-    public static String createItemInAuthority(String vcsid\r
+    public static String createItemInAuthority(String inAuthority\r
                String orgAuthorityRefName, Map<String, String> orgInfo,\r
                OrgAuthorityClient client) {\r
        // Expected status code: 201 Created\r
@@ -95,26 +166,26 @@ public class OrgAuthorityClientUtils {
        // Type of service request being tested\r
        ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
         String displayName = createDisplayName(orgInfo);\r
-       String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true);\r
 \r
        if(logger.isDebugEnabled()){\r
                logger.debug("Import: Create Item: \""+displayName\r
                                +"\" in orgAuthority: \"" + orgAuthorityRefName +"\"");\r
        }\r
        MultipartOutput multipart =\r
-               createOrganizationInstance(vcsid, refName, orgInfo, client.getItemCommonPartName());\r
-       ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+               createOrganizationInstance(inAuthority, orgAuthorityRefName, \r
+                               orgInfo, client.getItemCommonPartName());\r
+       ClientResponse<Response> res = client.createItem(inAuthority, multipart);\r
        String result;\r
        try {   \r
                int statusCode = res.getStatus();\r
        \r
                if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
-                       throw new RuntimeException("Could not create Item: \""+displayName\r
+                       throw new RuntimeException("Could not create Item: \""+orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER)\r
                                        +"\" in orgAuthority: \"" + orgAuthorityRefName\r
                                        +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
                }\r
                if(statusCode != EXPECTED_STATUS_CODE) {\r
-                       throw new RuntimeException("Unexpected Status when creating Item: \""+ displayName\r
+                       throw new RuntimeException("Unexpected Status when creating Item: \""+ orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER)\r
                                        +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);\r
                }\r
        \r
@@ -130,22 +201,30 @@ public class OrgAuthorityClientUtils {
      * Creates the organization instance.\r
      *\r
      * @param inAuthority the in authority\r
-     * @param orgRefName the org ref name\r
+     * @param orgAuthRefName the owning Authority ref name\r
      * @param orgInfo the org info\r
      * @param headerLabel the header label\r
      * @return the multipart output\r
      */\r
     public static MultipartOutput createOrganizationInstance(String inAuthority, \r
-               String orgRefName, Map<String, String> orgInfo, String headerLabel){\r
+               String orgAuthRefName, Map<String, String> orgInfo, String headerLabel){\r
         OrganizationsCommon organization = new OrganizationsCommon();\r
         organization.setInAuthority(inAuthority);\r
-               organization.setRefName(orgRefName);\r
+       String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER);\r
+       if (shortId == null || shortId.isEmpty()) {\r
+               throw new IllegalArgumentException("shortIdentifier cannot be null or empty");\r
+       }       \r
+       organization.setShortIdentifier(shortId);\r
                String value = null;\r
        value = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
        boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); \r
                organization.setDisplayNameComputed(displayNameComputed);\r
-        if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null)\r
+               if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null)\r
                organization.setDisplayName(value);\r
+               \r
+       String refName = createOrganizationRefName(orgAuthRefName, shortId, value);\r
+       organization.setRefName(refName);\r
+\r
         if((value = (String)orgInfo.get(OrganizationJAXBSchema.SHORT_NAME))!=null)\r
                organization.setShortName(value);\r
         if((value = (String)orgInfo.get(OrganizationJAXBSchema.LONG_NAME))!=null)\r
@@ -222,15 +301,15 @@ public class OrgAuthorityClientUtils {
     /**\r
      * Creates the org auth ref name.\r
      *\r
-     * @param orgAuthorityName the org authority name\r
-     * @param withDisplaySuffix the with display suffix\r
+     * @param shortId the orgAuthority shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
      * @return the string\r
      */\r
-    public static String createOrgAuthRefName(String orgAuthorityName, boolean withDisplaySuffix) {\r
+    public static String createOrgAuthRefName(String shortId, String displaySuffix) {\r
        String refName = "urn:cspace:org.collectionspace.demo:orgauthority:name("\r
-                       +orgAuthorityName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+orgAuthorityName+"'";\r
+                       +shortId+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
@@ -238,15 +317,15 @@ public class OrgAuthorityClientUtils {
      * Creates the organization ref name.\r
      *\r
      * @param orgAuthRefName the org auth ref name\r
-     * @param orgName the org name\r
-     * @param withDisplaySuffix the with display suffix\r
+     * @param shortId the person shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
      * @return the string\r
      */\r
     public static String createOrganizationRefName(\r
-                                               String orgAuthRefName, String orgName, boolean withDisplaySuffix) {\r
-       String refName = orgAuthRefName+":organization:name("+orgName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+orgName+"'";\r
+                       String orgAuthRefName, String shortId, String displaySuffix) {\r
+       String refName = orgAuthRefName+":organization:name("+shortId+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
index 54f2091cef632c1d014126a534f6aabff280f88d..32ca3dbd9073293d4c899dd0ddc9548c36ac846b 100644 (file)
@@ -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<OrganizationsCommonList> readItemListForNamedAuthority(@PathParam("specifier") String specifier);
+    ClientResponse<OrganizationsCommonList> 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<OrganizationsCommonList> 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<MultipartInput> readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid);
 
+    //(R)ead Named Item
+    @GET
+    @Path("/{vcsid}/items/urn:cspace:name({specifier})")
+    ClientResponse<MultipartInput> readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier);
+
+    //(R)ead Item In Named Authority
+    @GET
+    @Path("/urn:cspace:name({specifier})/items/{csid}")
+    ClientResponse<MultipartInput> 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<MultipartInput> readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier);
+
     //(U)pdate Item
     @PUT
     @Path("/{vcsid}/items/{csid}")
index 7ab612d5d7763f88c8eed6d1090693487d114c95..59b5054de0b19fa45e7b7ce908cb0a2be1274b7d 100644 (file)
@@ -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<String> allResourceIdsCreated = new ArrayList<String>();
@@ -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<Response> 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<String, String> testOrgMap = new HashMap<String,String>();
+        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<Response> 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<String, String> personInfo = new HashMap<String,String>();
         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<Response> 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<String, String> subBodyOrgMap = new HashMap<String,String>();
+        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<Response> res = orgAuthClient.createItem(knownAuthResourceId, multipart);
+       ClientResponse<Response> 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<MultipartInput> 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<AuthorityRefList> 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());
-    }
-
 }
index 5f5c4d95aff1a9c9665140025ed61773adcdc76c..4ee853c5d3930e6617c04a02289d6a4602812fcc 100644 (file)
@@ -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<String, String> allContactResourceIdsCreated =
         new HashMap<String, String>();
     
+    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<Response> 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<String, String> testOrgMap = new HashMap<String,String>();
+        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<MultipartInput> 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<MultipartInput> res = client.readByName(knownResourceDisplayName);
+        ClientResponse<MultipartInput> 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<MultipartInput> 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<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
+        ClientResponse<MultipartInput> 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<MultipartInput> 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<String, String> nonexOrgMap = new HashMap<String,String>();
+        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<MultipartInput> 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());
-    }
 }
index 57c77a428ee1cfee2c40e8747f17aca7e78d34d9..75bd8ae113bfa76cceaad0ce9fd1f47d0565d43b 100644 (file)
@@ -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<Map<String,String>> 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<Response> 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<String,String> orgInfo : orgInfos){
@@ -112,14 +110,17 @@ public class OrgAuthorityBaseImport {
 
                OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport();
                final String demoOrgAuthorityName = "Demo Org Authority";
+               final String demoOrgAuthorityShortId = "demoOrgAuth";
 
         Map<String, String> mmiOrgMap = new HashMap<String,String>();
+        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<String, String> pahmaOrgMap = new HashMap<String,String>();
+        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<String, String> savoyOrgMap = new HashMap<String,String>();
+        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<Map<String, String>> orgMaps = 
                Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap );
 
-               oabi.createOrgAuthority(demoOrgAuthorityName, orgMaps);
+               oabi.createOrgAuthority(demoOrgAuthorityName, demoOrgAuthorityShortId, orgMaps);
 
                logger.info("OrgAuthorityBaseImport complete.");
        }
index 90798f9889d4478d5d463bfc4fd55cb1cc92dbc1..05844ad2bfc18fbec635cb73f3b7ca878f6eb454 100644 (file)
@@ -10,6 +10,7 @@ package org.collectionspace.services;
 public interface OrgAuthorityJAXBSchema {\r
        final static String ORGAUTHORITIES_COMMON = "orgauthorities_common";\r
        final static String DISPLAY_NAME = "displayName";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String REF_NAME = "refName";\r
        final static String VOCAB_TYPE = "vocabType";\r
        final static String CSID = "csid";\r
index bb9b16b9977e34b9962fb2fa789940616c5e88b9..21efbd0361dccb199e6e12f524898f3c123c555b 100644 (file)
@@ -12,6 +12,7 @@ public interface OrganizationJAXBSchema {
        final static String CSID = "csid";\r
        final static String IN_AUTHORITY = "inAuthority";\r
     final static String REF_NAME = "refName";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String DISPLAY_NAME = "displayName";\r
        final static String DISPLAY_NAME_COMPUTED = "displayNameComputed";\r
        final static String SHORT_NAME = "shortName";\r
index 12ae914404272b68c87b7134771cb7128debdb70..1f6738c973da081311ddab5c22afc63b21d8a057 100644 (file)
@@ -21,6 +21,7 @@
                 <xs:element name="csid" type="xs:string" />                            
                 <!--  Organization Information Group -->
                 <xs:element name="inAuthority" type="xs:string" />
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="refName" type="xs:string"/>
                 <xs:element name="displayName" type="xs:string"/>
                 <xs:element name="displayNameComputed" type="xs:boolean"/>
index 32eb77317f301ea8b9e9ee674e9bb647efb2edc1..a9e129be1fc4c1d139c01ae0e526e19e40f7633e 100644 (file)
@@ -34,6 +34,7 @@
                 <xs:element name="csid" type="xs:string" />
                 
                 <!--  OrgAuthority Information Group -->
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="displayName" type="xs:string"/>
                 <xs:element name="refName" type="xs:string"/>
                 <xs:element name="vocabType" type="xs:string"/>                
index fce0ab97280929a7e6e0acf5fb0a030b1309a623..6bdba2eacfbe811c056495cce6f5a48fdbbc847c 100644 (file)
@@ -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<MultipartInput, MultipartOutput> 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<MultipartInput, MultipartOutput> 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<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
-               ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+
+               ":" + OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+
                "='" + parentSpecifier+"'";
             // Need to get an Authority by name
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
-
-            ctx = createServiceContext(getItemServiceName(), queryParams);
-            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            DocumentFilter myFilter = handler.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 (file)
index 0000000..ba8f366
--- /dev/null
@@ -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);
+        }
+    }
+}
index 6c579ca2da3d933997a11e3e55779beab6aa19bf..f20d9464b4010d33c5872aba96c5f2ac1d34688f 100644 (file)
@@ -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)) {
index 108e3fad5dabeea682fb5463afc93681b23f7668..5a7d60f66a340ecf28c657df4947f79026875c05 100644 (file)
@@ -11,6 +11,7 @@
       </templates>
       <rows>
         <row><widget>displayName</widget></row>
+        <row><widget>shortIdentifier</widget></row>
         <row><widget>refName</widget></row>
         <row><widget>vocabType</widget></row>
       </rows>
         </properties>
       </widget>
       
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="personauthorities_common">shortIdentifier</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
       <widget name="refName" type="text">
         <labels>
           <label mode="any">RefName</label>
@@ -65,6 +79,7 @@
       </templates>
       <rows>
         <row><widget>displayName</widget></row>
+        <row><widget>shortIdentifier</widget></row>
         <row><widget>refName</widget></row>
         <row><widget>inAuthority</widget></row>
         <row><widget>foreName</widget></row>
         </labels>
         <translated>true</translated>
         <fields>
-          <field schema="personauthorities_common">displayName</field>
+          <field schema="persons_common">displayName</field>
+        </fields>
+        <properties widgetMode="edit">
+          <property name="styleClass">dataInputText</property>
+        </properties>
+      </widget>
+      
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="persons_common">shortIdentifier</field>
         </fields>
         <properties widgetMode="edit">
           <property name="styleClass">dataInputText</property>
index 915bc31a615d0b2f883f46d89d1684c999a3dd42..d146c213d57a509d088ce465ef29fa776e5afdc4 100644 (file)
@@ -24,6 +24,7 @@
 
                <!--  PersonAuthority Information Group -->
                <xs:element name="displayName" type="xs:string"/>
+               <xs:element name="shortIdentifier" type="xs:string"/>
                <xs:element name="refName" type="xs:string"/>
                <xs:element name="vocabType" type="xs:string"/>
 
index d1f733f1bbca87c280f17dd3d2533e3a0d7a8c51..dfe77455ba2eab4d2c2e2ab6226b71fc323b9b30 100644 (file)
@@ -23,6 +23,7 @@
     <!--  Person Information Group -->
     <!--  inAuthority is the csid of the owning PersonAuthority -->
     <xs:element name="inAuthority" type="xs:string" />
+               <xs:element name="shortIdentifier" type="xs:string"/>
     <xs:element name="refName" type="xs:string"/>
     <xs:element name="displayName" type="xs:string"/>
     <xs:element name="displayNameComputed" type="xs:boolean"/>
index b89410b235e42ff2b83cf3121a3e72726eb388d1..d01f1213cd6e949a732a8b43cc3d1778fa2cd917 100644 (file)
@@ -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<AuthorityRefDocList> 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<AuthorityRefDocList> 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<MultipartInput> 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<MultipartInput> 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<MultipartInput> readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
+        return personAuthorityProxy.readNamedItem(authShortId, itemShortId);
+    }
+
     /**
      * Creates the item.
      *
index 142aa80fe423a0af2832b64e2eba2732537ab3a7..a734425a3e46d54c69fb68e6a07fe4b1649b4633 100644 (file)
@@ -40,6 +40,7 @@ import org.collectionspace.services.client.test.ServiceRequestType;
 import org.collectionspace.services.person.PersonsCommon;\r
 import org.collectionspace.services.person.PersonauthoritiesCommon;\r
 import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
 import org.slf4j.Logger;\r
@@ -53,19 +54,88 @@ public class PersonAuthorityClientUtils {
     /** The Constant logger. */\r
     private static final Logger logger =\r
         LoggerFactory.getLogger(PersonAuthorityClientUtils.class);\r
+       private static final ServiceRequestType READ_REQ = ServiceRequestType.READ;\r
+\r
+    /**\r
+     * @param csid the id of the PersonAuthority\r
+     * @param client if null, creates a new client\r
+     * @return\r
+     */\r
+    public static String getAuthorityRefName(String csid, PersonAuthorityClient client){\r
+       if(client==null)\r
+               client = new PersonAuthorityClient();\r
+        ClientResponse<MultipartInput> res = client.read(csid);\r
+        try {\r
+               int statusCode = res.getStatus();\r
+               if(!READ_REQ.isValidStatusCode(statusCode)\r
+                       ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+                       throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+               }\r
+               //FIXME: remove the following try catch once Aron fixes signatures\r
+               try {\r
+                   MultipartInput input = (MultipartInput) res.getEntity();\r
+                   PersonauthoritiesCommon personAuthority = \r
+                       (PersonauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input,\r
+                           client.getCommonPartName(), PersonauthoritiesCommon.class);\r
+                       if(personAuthority==null) {\r
+                               throw new RuntimeException("Null personAuthority returned from service.");\r
+                       }\r
+                   return personAuthority.getRefName();\r
+               } catch (Exception e) {\r
+                   throw new RuntimeException(e);\r
+               }\r
+        } finally {\r
+               res.releaseConnection();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @param csid the id of the PersonAuthority\r
+     * @param client if null, creates a new client\r
+     * @return\r
+     */\r
+    public static String getPersonRefName(String inAuthority, String csid, PersonAuthorityClient client){\r
+       if(client==null)\r
+               client = new PersonAuthorityClient();\r
+        ClientResponse<MultipartInput> res = client.readItem(inAuthority, csid);\r
+        try {\r
+               int statusCode = res.getStatus();\r
+               if(!READ_REQ.isValidStatusCode(statusCode)\r
+                               ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+                       throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+               }\r
+               //FIXME: remove the following try catch once Aron fixes signatures\r
+               try {\r
+                   MultipartInput input = (MultipartInput) res.getEntity();\r
+                   PersonsCommon person = \r
+                       (PersonsCommon) CollectionSpaceClientUtils.extractPart(input,\r
+                           client.getItemCommonPartName(), PersonsCommon.class);\r
+                       if(person==null) {\r
+                               throw new RuntimeException("Null person returned from service.");\r
+                       }\r
+                   return person.getRefName();\r
+               } catch (Exception e) {\r
+                   throw new RuntimeException(e);\r
+               }\r
+        } finally {\r
+               res.releaseConnection();\r
+        }\r
+    }\r
 \r
     /**\r
      * Creates the person authority instance.\r
      *\r
      * @param displayName the display name\r
-     * @param refName the ref name\r
+     * @param shortIdentifier the short Id \r
      * @param headerLabel the header label\r
      * @return the multipart output\r
      */\r
     public static MultipartOutput createPersonAuthorityInstance(\r
-               String displayName, String refName, String headerLabel ) {\r
+               String displayName, String shortIdentifier, String headerLabel ) {\r
         PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
         personAuthority.setDisplayName(displayName);\r
+        personAuthority.setShortIdentifier(shortIdentifier);\r
+        String refName = createPersonAuthRefName(shortIdentifier, displayName);\r
         personAuthority.setRefName(refName);\r
         personAuthority.setVocabType("PersonAuthority");\r
         MultipartOutput multipart = new MultipartOutput();\r
@@ -83,17 +153,21 @@ public class PersonAuthorityClientUtils {
     /**\r
      * Creates the person instance.\r
      *\r
-     * @param inAuthority the in authority\r
-     * @param personRefName the person ref name\r
+     * @param inAuthority the owning authority\r
+     * @param personAuthRefName the owning Authority ref name\r
      * @param personInfo the person info\r
      * @param headerLabel the header label\r
      * @return the multipart output\r
      */\r
     public static MultipartOutput createPersonInstance(String inAuthority, \r
-               String personRefName, Map<String, String> personInfo, String headerLabel){\r
+               String personAuthRefName, Map<String, String> personInfo, String headerLabel){\r
         PersonsCommon person = new PersonsCommon();\r
         person.setInAuthority(inAuthority);\r
-               person.setRefName(personRefName);\r
+       String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER);\r
+       if (shortId == null || shortId.isEmpty()) {\r
+               throw new IllegalArgumentException("shortIdentifier cannot be null or empty");\r
+       }       \r
+       person.setShortIdentifier(shortId);\r
                \r
                //\r
                // If the 'DISPLAY_NAME_COMPUTED' property is null or empty then\r
@@ -112,6 +186,8 @@ public class PersonAuthorityClientUtils {
        if (displayNameComputed == false && displayName == null) {\r
                throw new IllegalArgumentException("displayName cannot be null when displayComputed is 'false'");\r
        }       \r
+       String refName = createPersonRefName(personAuthRefName, shortId, displayName);\r
+               person.setRefName(refName);\r
        \r
        String value;\r
         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. \r
@@ -168,7 +244,7 @@ public class PersonAuthorityClientUtils {
      *\r
      * @param vcsid the vcsid\r
      * @param personAuthorityRefName the person authority ref name\r
-     * @param personMap the person map\r
+     * @param personMap the person map. PersonJAXBSchema.SHORT_IDENTIFIER is REQUIRED.\r
      * @param client the client\r
      * @return the string\r
      */\r
@@ -195,16 +271,15 @@ public class PersonAuthorityClientUtils {
                        personMap.get(PersonJAXBSchema.SUR_NAME),\r
                        personMap.get(PersonJAXBSchema.BIRTH_DATE),\r
                        personMap.get(PersonJAXBSchema.DEATH_DATE));\r
+               personMap.put(PersonJAXBSchema.DISPLAY_NAME, displayName);\r
        }\r
        \r
-       String refName = createPersonRefName(personAuthorityRefName, displayName, true);\r
-\r
        if(logger.isDebugEnabled()){\r
                logger.debug("Import: Create Item: \"" + displayName\r
                                +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\"");\r
        }\r
        MultipartOutput multipart = \r
-               createPersonInstance(vcsid, refName,\r
+               createPersonInstance(vcsid, personAuthorityRefName,\r
                        personMap, client.getItemCommonPartName());\r
        \r
        String result = null;\r
@@ -213,12 +288,12 @@ public class PersonAuthorityClientUtils {
                int statusCode = res.getStatus();\r
        \r
                if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
-                       throw new RuntimeException("Could not create Item: \""+refName\r
+                       throw new RuntimeException("Could not create Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER)\r
                                        +"\" in personAuthority: \"" + personAuthorityRefName\r
                                        +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
                }\r
                if(statusCode != EXPECTED_STATUS_CODE) {\r
-                       throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+                       throw new RuntimeException("Unexpected Status when creating Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER)\r
                                        +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
                }\r
        \r
@@ -231,17 +306,17 @@ public class PersonAuthorityClientUtils {
     }\r
 \r
     /**\r
-     * Creates the person auth ref name.\r
+     * Creates the personAuthority ref name.\r
      *\r
-     * @param personAuthorityName the person authority name\r
-     * @param withDisplaySuffix the with display suffix\r
+     * @param shortId the personAuthority shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
      * @return the string\r
      */\r
-    public static String createPersonAuthRefName(String personAuthorityName, boolean withDisplaySuffix) {\r
+    public static String createPersonAuthRefName(String shortId, String displaySuffix) {\r
        String refName = "urn:cspace:org.collectionspace.demo:personauthority:name("\r
-                       +personAuthorityName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+personAuthorityName+"'";\r
+                       +shortId+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
@@ -249,15 +324,15 @@ public class PersonAuthorityClientUtils {
      * Creates the person ref name.\r
      *\r
      * @param personAuthRefName the person auth ref name\r
-     * @param personName the person name\r
-     * @param withDisplaySuffix the with display suffix\r
+     * @param shortId the person shortIdentifier\r
+     * @param displaySuffix displayName to be appended, if non-null\r
      * @return the string\r
      */\r
     public static String createPersonRefName(\r
-                                               String personAuthRefName, String personName, boolean withDisplaySuffix) {\r
-       String refName = personAuthRefName+":person:name("+personName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+personName+"'";\r
+                                               String personAuthRefName, String shortId, String displaySuffix) {\r
+       String refName = personAuthRefName+":person:name("+shortId+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
index b66d7b41b5f9e6150e7d13278f21141e502c59c8..56faaf1869d0aa24e9c36c013925677727f02069 100644 (file)
@@ -89,7 +89,16 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy {
     @GET
     @Produces({"application/xml"})
     @Path("/urn:cspace:name({specifier})/items/")
-    ClientResponse<PersonsCommonList> readItemListForNamedAuthority(@PathParam("specifier") String specifier);
+    ClientResponse<PersonsCommonList> 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<PersonsCommonList> 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<MultipartInput> readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid);
 
+    //(R)ead Named Item
+    @GET
+    @Path("/{vcsid}/items/urn:cspace:name({specifier})")
+    ClientResponse<MultipartInput> readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier);
+
+    //(R)ead Item In Named Authority
+    @GET
+    @Path("/urn:cspace:name({specifier})/items/{csid}")
+    ClientResponse<MultipartInput> 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<MultipartInput> readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier);
+
     //(U)pdate Item
     @PUT
     @Path("/{vcsid}/items/{csid}")
index 869795cf6f169c601e80bb92e9e19b4aa9aac34d..a6558eafc3538bccbee271e78c3e00c7a412f0d0 100644 (file)
@@ -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<Response> 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<String, String> partialTermPersonMap = new HashMap<String,String>();
         //
         // 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;
index ebcb154148966281294acf0a1e1f2af1e84c372f..47ded8b7c92a79da883712f9cc50e6ea8cfb6e05 100644 (file)
@@ -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<String, String> allContactResourceIdsCreated =
         new HashMap<String, String>();
 
+    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<Response> 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<String, String> johnWayneMap = new HashMap<String,String>();
         //
         // 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<MultipartInput> 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<MultipartInput> res = client.readByName(knownResourceDisplayName);
+        ClientResponse<MultipartInput> 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<MultipartInput> 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<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
+        ClientResponse<MultipartInput> 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<MultipartInput> 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<String, String> nonexMap = new HashMap<String,String>();
+        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<MultipartInput> res =
                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
         try {
index b69799cd2dd521eded60fc40c970ba99f1168091..f688106014203b3c7c332e3c671c9d4d0330d8b8 100644 (file)
@@ -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<Map<String, String>> 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<Response> 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<String,String> 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<String, String> johnWayneMap = new HashMap<String,String>();
+        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<String, String> patrickSchmitzMap = new HashMap<String,String>();
+        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<Map<String, String>> personsMaps = 
                Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );
 
-        pabi.createPersonAuthority(demoPersonAuthorityName, personsMaps);
+        pabi.createPersonAuthority(demoPersonAuthorityName, 
+                                               demoPersonAuthorityShortId, personsMaps);
 
                logger.info("PersonAuthorityBaseImport complete.");
        }
index b80986b823280bfa77c14595810c512b5a659df8..691f44f7663bf872e19a1dd7687f92c6d263ca24 100644 (file)
@@ -10,6 +10,7 @@ package org.collectionspace.services;
 public interface PersonAuthorityJAXBSchema {\r
        final static String PERSONAUTHORITIES_COMMON = "personauthorities_common";\r
        final static String DISPLAY_NAME = "displayName";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String REF_NAME = "refName";\r
        final static String VOCAB_TYPE = "vocabType";\r
        final static String CSID = "csid";\r
index c9e1f54ede8fbf2ef76ffa034e67bbc9593e1e47..ad4fdf305a9188361494763e50de8e6234b8f2cf 100644 (file)
@@ -11,6 +11,7 @@ public interface PersonJAXBSchema {
        final static String PERSONS_COMMON = "persons_common";\r
        final static String CSID = "csid";\r
        final static String IN_AUTHORITY = "inAuthority";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
        final static String REF_NAME = "refName";\r
        final static String DISPLAY_NAME = "displayName";\r
        final static String DISPLAY_NAME_COMPUTED = "displayNameComputed";\r
index 4294cef9c0077d07f0120a85d29d554ba83b5d73..a41450d88dc6c5f5f6e1b332d92a4829d8569028 100644 (file)
@@ -33,6 +33,7 @@
                 
                 <!--  Person Information Group -->
                 <xs:element name="inAuthority" type="xs:string" />
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="refName" type="xs:string" />
                 <xs:element name="displayName" type="xs:string"/>
                 <xs:element name="displayNameComputed" type="xs:boolean"/>
index 7ff8dcd40d088e814e4a9ae73616b73f0096c791..3d6f0ba03809628231043fd9fcd767ccabebf1da 100644 (file)
@@ -36,6 +36,7 @@
                 
                 <!--  PersonAuthority Information Group -->
                 <xs:element name="displayName" type="xs:string"/>
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="refName" type="xs:string"/>
                 <xs:element name="vocabType" type="xs:string"/>
                 
index c6a488486fad2bca5030ca770d7f4c788f862e97..22326fc43a7c32135f135efb402e6811e2dac6d8 100644 (file)
@@ -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<MultipartInput, MultipartOutput> 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<MultipartInput, MultipartOutput> 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<String, String> queryParams = ui.getQueryParameters();
             String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON +
-               ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME +
+               ":" + PersonAuthorityJAXBSchema.SHORT_IDENTIFIER +
                "='" + parentSpecifier+"'";
             // Need to get an Authority by name
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             String parentcsid = 
                getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
-            ctx = createServiceContext(getItemServiceName(), queryParams);
-            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-
-            // 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 (file)
index 0000000..decd75b
--- /dev/null
@@ -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);
+        }
+    }
+}
index f2f8023f5c848492a3456eaedbc4ed0ee1b8a489..78eee79725e4afc087625f33a7d3b157b85d6b2d 100644 (file)
@@ -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)) {