]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1152 and CSPACE-2126. Changed Vocabulary schema to include a shortIdentifier...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 14 Jun 2010 05:29:19 +0000 (05:29 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Mon, 14 Jun 2010 05:29:19 +0000 (05:29 +0000)
15 files changed:
services/common/src/main/config/services/tenant-bindings.xml
services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml
services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies_common.xsd
services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java
services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java
services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java
services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java
services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java
services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java
services/vocabulary/jaxb/src/main/resources/vocabulary_common.xsd
services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java

index a7fef44f0022815a8ca57bff65b39c8fabeae45b..2fdd37b8693fadee116759c5ec92ae7fb756408d 100644 (file)
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.vocabulary.nuxeo.VocabularyDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.vocabulary.nuxeo.VocabularyValidatorHandler
+            </service:validatorHandler>
             <service:object name="Vocabulary" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index f8f97dae707019be180a84b4c361a1971cb1a772..e7601154375b0ee58236b45716a042a28e50e9fa 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="vocabularies_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>inVocabulary</widget></row>
         <row><widget>status</widget></row>
         </properties>
       </widget>
       
+      <widget name="shortIdentifier" type="text">
+        <labels>
+          <label mode="any">Short Identifier</label>
+        </labels>
+        <translated>true</translated>
+        <fields>
+          <field schema="vocabularyitems_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 9e646713fe2f78b9c6f5de670bd3e090660b7a9c..75d0dd21d59c62027e11d078e22b44e03a3a2bee 100644 (file)
@@ -25,6 +25,7 @@
                <!--  Vocabulary Information Group -->
                <xs:element name="displayName" type="xs:string"/>
                <xs:element name="refName" type="xs:string"/>
+               <xs:element name="shortIdentifier" type="xs:string"/>
                <xs:element name="vocabType" type="xs:string"/>
 
 </xs:schema>
index 556c1ea8f87e079f94545bc9cd7ddd2f1df97be5..09bf431f4951e4e50c43cfe5c1cee1e2ea67850d 100644 (file)
@@ -24,6 +24,7 @@
                <!--  inVocabulary is the csid of the owning Vocabulary -->
                <xs:element name="inVocabulary" type="xs:string" />
                <xs:element name="refName" type="xs:string"/>
+               <xs:element name="shortIdentifier" type="xs:string"/>
                <xs:element name="displayName" type="xs:string"/>
                 <xs:element name="status" type="xs:string"/>
 
index a5f3fb5371117abeb175eca0bb9698db98fa4dd0..999b741d95c6f5c99e9e00000a4e4f2438d4d153 100644 (file)
@@ -123,6 +123,16 @@ public class VocabularyClient extends AbstractServiceClientImpl {
         return vocabularyProxy.read(csid);
     }
 
+    /**
+     * Read by name.
+     *
+     * @param name the name
+     * @return the client response
+     */
+    public ClientResponse<MultipartInput> readByName(String name) {
+        return vocabularyProxy.readByName(name);
+    }
+
     /**
      * Creates the.
      *
index 0689bd9caddbb4fc8ae98f52623ce6ec981765f1..b564c9fb50002239414c612648855aa83d68eeac 100644 (file)
@@ -22,9 +22,11 @@ public class VocabularyClientUtils {
         LoggerFactory.getLogger(VocabularyClientUtils.class);\r
 \r
     public static MultipartOutput createEnumerationInstance(\r
-               String displayName, String refName, String headerLabel ) {\r
+               String displayName, String shortIdentifier, String headerLabel ) {\r
         VocabulariesCommon vocabulary = new VocabulariesCommon();\r
         vocabulary.setDisplayName(displayName);\r
+        vocabulary.setShortIdentifier(shortIdentifier);\r
+        String refName = createVocabularyRefName(shortIdentifier, displayName);\r
         vocabulary.setRefName(refName);\r
         vocabulary.setVocabType("enum");\r
         MultipartOutput multipart = new MultipartOutput();\r
@@ -42,13 +44,15 @@ public class VocabularyClientUtils {
                // Note that we do not use the map, but we will once we add more info to the \r
                // items\r
     public static MultipartOutput createVocabularyItemInstance(String inVocabulary, \r
-               String vocabItemRefName, Map<String, String> vocabItemInfo, String headerLabel){\r
+               String vocabularyRefName, Map<String, String> vocabItemInfo, String headerLabel){\r
         VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();\r
         vocabularyItem.setInVocabulary(inVocabulary);\r
-               vocabularyItem.setRefName(vocabItemRefName);\r
-               String value = null;\r
-        if((value = (String)vocabItemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME))!=null)\r
-               vocabularyItem.setDisplayName(value);\r
+       String shortId = vocabItemInfo.get(VocabularyItemJAXBSchema.SHORT_IDENTIFIER);\r
+       String displayName = vocabItemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME);\r
+               vocabularyItem.setShortIdentifier(shortId);\r
+               vocabularyItem.setDisplayName(displayName);\r
+       String refName = createVocabularyItemRefName(vocabularyRefName, shortId, displayName);\r
+               vocabularyItem.setRefName(refName);\r
         MultipartOutput multipart = new MultipartOutput();\r
         OutputPart commonPart = multipart.addPart(vocabularyItem,\r
             MediaType.APPLICATION_XML_TYPE);\r
@@ -68,27 +72,25 @@ public class VocabularyClientUtils {
        int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
        // Type of service request being tested\r
        ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
-       String displayName = itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME);\r
-       String refName = createVocabularyItemRefName(vocabularyRefName, displayName, true);\r
 \r
        if(logger.isDebugEnabled()){\r
-               logger.debug("Import: Create Item: \""+displayName\r
+               logger.debug("Import: Create Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME)\r
                                +"\" in personAuthorityulary: \"" + vocabularyRefName +"\"");\r
        }\r
        MultipartOutput multipart = \r
-               createVocabularyItemInstance( vcsid, refName,\r
+               createVocabularyItemInstance( vcsid, vocabularyRefName,\r
                                itemMap, 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: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME)\r
                                +"\" in personAuthority: \"" + vocabularyRefName\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: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME)\r
                                +"\" in personAuthority: \"" + vocabularyRefName +"\", Status:"+ statusCode);\r
        }\r
 \r
@@ -126,19 +128,19 @@ public class VocabularyClientUtils {
         return id;\r
     }\r
     \r
-    public static String createVocabularyRefName(String vocabularyName, boolean withDisplaySuffix) {\r
+    public static String createVocabularyRefName(String shortIdentifier, String displaySuffix) {\r
        String refName = "urn:cspace:org.collectionspace.demo:vocabulary:name("\r
-                       +vocabularyName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+vocabularyName+"'";\r
+                       +shortIdentifier+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
     public static String createVocabularyItemRefName(\r
-                                               String vocabularyRefName, String vocabItemName, boolean withDisplaySuffix) {\r
-       String refName = vocabularyRefName+":item:name("+vocabItemName+")";\r
-       if(withDisplaySuffix)\r
-               refName += "'"+vocabItemName+"'";\r
+                                               String vocabularyRefName, String shortIdentifier, String displaySuffix) {\r
+       String refName = vocabularyRefName+":item:name("+shortIdentifier+")";\r
+       if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+               refName += "'"+displaySuffix+"'";\r
        return refName;\r
     }\r
 \r
index 171f7328955ecd2b1bffcbea7913519c85415608..7440be3407fcaa5bd30b8da8708c9969ad6a4bef 100644 (file)
@@ -38,6 +38,11 @@ public interface VocabularyProxy extends CollectionSpaceProxy {
     @Path("/{csid}")
     ClientResponse<MultipartInput> read(@PathParam("csid") String csid);
 
+    //(R)ead by name
+    @GET
+    @Path("/urn:cspace:name({name})")
+    ClientResponse<MultipartInput> readByName(@PathParam("name") String name);
+
     //(U)pdate
     @PUT
     @Path("/{csid}")
index befc9d0160532abc6771fdcbb6bc604837c79541..ea5deea28f3e307c077a3e578f720e0b9e4f81ff 100644 (file)
@@ -65,16 +65,21 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
     final String SERVICE_PATH_COMPONENT = "vocabularies";
     final String ITEM_SERVICE_PATH_COMPONENT = "items";
     private String knownResourceId = null;
+    private String knownResourceShortIdentifer = null;
     private String knownResourceRefName = null;
+    private String knownResourceFullRefName = null;
     private String knownItemResourceId = null;
     private int nItemsToCreateInList = 3;
     private List<String> allResourceIdsCreated = new ArrayList<String>();
     private Map<String, String> allResourceItemIdsCreated =
         new HashMap<String, String>();
     
-    protected void setKnownResource( String id, String refName ) {
+    protected void setKnownResource( String id, String shortIdentifer,
+                                                               String refName, String fullRefName ) {
        knownResourceId = id;
+       knownResourceShortIdentifer = shortIdentifer;
        knownResourceRefName = refName;
+       knownResourceFullRefName = fullRefName;
     }
 
     /* (non-Javadoc)
@@ -114,9 +119,8 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
         VocabularyClient client = new VocabularyClient();
         String identifier = createIdentifier();
         String displayName = "displayName-" + identifier;
-       String refName = VocabularyClientUtils.createVocabularyRefName(displayName, false);
        MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
-                                       displayName, refName, client.getCommonPartName());
+                                       displayName, identifier, client.getCommonPartName());
         ClientResponse<Response> res = client.create(multipart);
         int statusCode = res.getStatus();
 
@@ -136,7 +140,9 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
         // Store the ID returned from the first resource created
         // for additional tests below.
         if (knownResourceId == null){
-               setKnownResource(extractId(res), refName);
+               setKnownResource(extractId(res), identifier,
+                               VocabularyClientUtils.createVocabularyRefName(identifier, null),
+                               VocabularyClientUtils.createVocabularyRefName(identifier, displayName));
             if (logger.isDebugEnabled()) {
                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
             }
@@ -159,7 +165,9 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
 
         VocabularyClient client = new VocabularyClient();
         HashMap<String, String> itemInfo = new HashMap<String, String>();
-        itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, createIdentifier());
+        String shortId = createIdentifier();
+        itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, shortId);
+        itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-"+shortId);
         String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId,
                                knownResourceRefName, itemInfo, client);
 
@@ -183,7 +191,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
     public void createList(String testName) throws Exception {
         for (int i = 0; i < 3; i++) {
                // Force create to reset the known resource info
-               setKnownResource(null, null);
+               setKnownResource(null, null, null, null);
             create(testName);
             // Add nItemsToCreateInList items to each vocab
             for (int j = 0; j < nItemsToCreateInList; j++) {
@@ -207,6 +215,68 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
     public void createWithWrongXmlSchema(String testName) throws Exception {
     }
 
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+               dependsOnMethods = {"create"})
+    public void createWithBadShortId(String testName) throws Exception {
+        
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        testSetup(STATUS_BAD_REQUEST, ServiceRequestType.CREATE);
+
+        // Submit the request to the service and store the response.
+        VocabularyClient client = new VocabularyClient();
+       MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
+                                       "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
+        ClientResponse<Response> res = client.create(multipart);
+        int statusCode = res.getStatus();
+
+        // Check the status code of the response: does it match
+        // the expected response(s)?
+        //
+        // Specifically:
+        // Does it fall within the set of valid status codes?
+        // Does it exactly match the expected status code?
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+    }
+
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+               dependsOnMethods = {"createItem"})
+    public void createItemWithBadShortId(String testName) throws Exception {
+        
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        setupCreateWithMalformedXml();
+
+        // Submit the request to the service and store the response.
+        VocabularyClient client = new VocabularyClient();
+        HashMap<String, String> itemInfo = new HashMap<String, String>();
+        itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!");
+        itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "Bad Item!");
+       MultipartOutput multipart = 
+               VocabularyClientUtils.createVocabularyItemInstance( knownResourceId, knownResourceRefName,
+                               itemInfo, client.getItemCommonPartName() );
+       ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
+
+       int statusCode = res.getStatus();
+
+       if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
+               throw new RuntimeException("Could not create Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME)
+                               +"\" in personAuthority: \"" + knownResourceRefName
+                               +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+       }
+       if(statusCode != EXPECTED_STATUS_CODE) {
+               throw new RuntimeException("Unexpected Status when creating Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME)
+                               +"\" in personAuthority: \"" + knownResourceRefName +"\", Status:"+ statusCode);
+       }
+    }
+
     /*
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
@@ -330,11 +400,56 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
             VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
                     client.getCommonPartName(), VocabulariesCommon.class);
             Assert.assertNotNull(vocabulary);
+            Assert.assertEquals(vocabulary.getRefName(), knownResourceFullRefName);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
+    /**
+     * Read by name.
+     *
+     * @param testName the test name
+     * @throws Exception the exception
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+               dependsOnMethods = {"read"})
+        public void readByName(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.
+        VocabularyClient client = new VocabularyClient();
+        ClientResponse<MultipartInput> res = client.readByName(knownResourceShortIdentifer);
+        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();
+                   VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
+                               client.getCommonPartName(), VocabulariesCommon.class);
+                   Assert.assertNotNull(vocabulary);
+               } catch (Exception e) {
+                   throw new RuntimeException(e);
+               }
+        } finally {
+               res.releaseConnection();
+        }
+    }
+
     /*
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
             dependsOnMethods = {"read"})
@@ -399,7 +514,7 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
                 client.getItemCommonPartName(), VocabularyitemsCommon.class);
         Assert.assertNotNull(vocabularyItem);
-
+        Assert.assertEquals(vocabularyItem.getInVocabulary(), knownResourceId);
     }
 
     // Failure outcomes
@@ -883,9 +998,8 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
         // The only relevant ID may be the one used in update(), below.
         VocabularyClient client = new VocabularyClient();
        String displayName = "displayName-" + NON_EXISTENT_ID;
-       String refName = VocabularyClientUtils.createVocabularyRefName(displayName, false);
        MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
-                               displayName, refName, client.getCommonPartName());
+                               displayName, NON_EXISTENT_ID, client.getCommonPartName());
         ClientResponse<MultipartInput> res =
                 client.update(NON_EXISTENT_ID, multipart);
         int statusCode = res.getStatus();
@@ -915,10 +1029,11 @@ public class VocabularyServiceTest extends AbstractServiceTestImpl {
         // The only relevant ID may be the one used in update(), below.
         VocabularyClient client = new VocabularyClient();
         HashMap<String, String> itemInfo = new HashMap<String, String>();
-        itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "nonex");
+        itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
+        itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-nonex");
         MultipartOutput multipart = 
                VocabularyClientUtils.createVocabularyItemInstance(knownResourceId, 
-                       VocabularyClientUtils.createVocabularyItemRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true),
+                       VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
                        itemInfo, client.getItemCommonPartName());
         ClientResponse<MultipartInput> res =
                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
index dd00fe2f9b72d4e13eb9ccd473e9a2af645e7822..96e8d13463e45782a09f7cbcbfd93adc5e20de48 100644 (file)
@@ -53,7 +53,7 @@ public class VocabularyBaseImport {
     final String SERVICE_PATH_COMPONENT = "vocabularies";
     final String ITEM_SERVICE_PATH_COMPONENT = "items";
 
-    public void createEnumeration(String vocabName, List<String> enumValues) {
+    public void createEnumeration(String vocabDisplayName, String shortName, List<String> enumValues) {
 
         // Expected status code: 201 Created
         int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
@@ -61,30 +61,29 @@ public class VocabularyBaseImport {
         ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
 
         if (logger.isDebugEnabled()) {
-            logger.debug("Import: Create vocabulary: \"" + vocabName + "\"");
+            logger.debug("Import: Create vocabulary: \"" + vocabDisplayName + "\"");
         }
-        String baseVocabRefName = VocabularyClientUtils.createVocabularyRefName(vocabName, false);
-        String fullVocabRefName = baseVocabRefName + "'" + vocabName + "'";
+        String baseVocabRefName = VocabularyClientUtils.createVocabularyRefName(shortName, null);
         MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
-                vocabName, fullVocabRefName, client.getCommonPartName());
+                       vocabDisplayName, shortName, client.getCommonPartName());
         ClientResponse<Response> res = client.create(multipart);
 
         int statusCode = res.getStatus();
 
         if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
-            throw new RuntimeException("Could not create enumeration: \"" + vocabName
+            throw new RuntimeException("Could not create enumeration: \"" + vocabDisplayName
                     + "\" " + VocabularyClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
         }
         if (statusCode != EXPECTED_STATUS_CODE) {
             throw new RuntimeException("Unexpected Status when creating enumeration: \""
-                    + vocabName + "\", Status:" + statusCode);
+                    + vocabDisplayName + "\", Status:" + statusCode);
         }
 
         // Store the ID returned from this create operation
         // for additional tests below.
         String newVocabId = VocabularyClientUtils.extractId(res);
         if (logger.isDebugEnabled()) {
-            logger.debug("Import: Created vocabulary: \"" + vocabName + "\" ID:"
+            logger.debug("Import: Created vocabulary: \"" + vocabDisplayName + "\" ID:"
                     + newVocabId);
         }
         for (String itemName : enumValues) {
@@ -105,6 +104,12 @@ public class VocabularyBaseImport {
         final String entryReasonsVocabName = "Entry Reasons";
         final String responsibleDeptsVocabName = "Responsible Departments";
         final String termStatusVocabName = "Term Status";
+        
+        final String acquisitionMethodsShortName = "acqMethods";
+        final String entryMethodsShortName = "entryMethods";
+        final String entryReasonsShortName = "entryReasons";
+        final String responsibleDeptsShortName = "responsibleDepts";
+        final String termStatusShortName = "termStatus";
 
         List<String> acquisitionMethodsEnumValues =
                 Arrays.asList("Gift", "Purchase", "Exchange", "Transfer", "Treasure");
@@ -120,11 +125,11 @@ public class VocabularyBaseImport {
         List<String> termStatusEnumValues =
                 Arrays.asList("Provisional", "Under Review", "Accepted", "Rejected");
 
-        vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues);
-        vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues);
-        vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues);
-        vbi.createEnumeration(responsibleDeptsVocabName, respDeptNamesEnumValues);
-        vbi.createEnumeration(termStatusVocabName, termStatusEnumValues);
+        vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsShortName, acquisitionMethodsEnumValues);
+        vbi.createEnumeration(entryMethodsVocabName, entryMethodsShortName, entryMethodsEnumValues);
+        vbi.createEnumeration(entryReasonsVocabName, entryReasonsShortName, entryReasonsEnumValues);
+        vbi.createEnumeration(responsibleDeptsVocabName, responsibleDeptsShortName, respDeptNamesEnumValues);
+        vbi.createEnumeration(termStatusVocabName, termStatusShortName, termStatusEnumValues);
 
         logger.info("VocabularyBaseImport complete.");
     }
index 988070cd78638b5dff2c2fe3384a4c28d92f26c5..ff9c9bd53e9056f7cfb73eb38a90773e129575bf 100644 (file)
@@ -12,7 +12,8 @@ public interface VocabularyItemJAXBSchema {
        final static String DISPLAY_NAME = "displayName";\r
        final static String IN_VOCABULARY = "inVocabulary";\r
        final static String REF_NAME = "refName";\r
-        final static String STATUS = "status";\r
+       final static String SHORT_IDENTIFIER = "shortIdentifier";\r
+    final static String STATUS = "status";\r
        final static String CSID = "csid";\r
 }\r
 \r
index 09d23eb7a7056520c70170eb375607fad735d029..9f3c8f276174d5c445ded0e86fa19ead55e79ae6 100644 (file)
@@ -8,7 +8,9 @@ package org.collectionspace.services;
  *\r
  */\r
 public interface VocabularyJAXBSchema {\r
+       final static String VOCABULARIES_COMMON = "vocabularies_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 a478cdd54dd4829f41498d0af0110575f4d28974..314171239cb0a8832fcb8de6caef519dbe6c5672 100644 (file)
@@ -36,6 +36,7 @@
                 
                 <!--  Vocabulary 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"/>                
             </xs:sequence>
index fe732caceb76ba883a04b3d476ded3e2503d0a80..e9fb1a95f988b39aa1e8a70d6ad496875db505a9 100644 (file)
@@ -23,6 +23,7 @@
                 <!--  Vocabularyitem Information Group -->
                 <xs:element name="inVocabulary" type="xs:string" />
                 <xs:element name="displayName" type="xs:string"/>
+                                                               <xs:element name="shortIdentifier" type="xs:string"/>
                 <xs:element name="refName" type="xs:string"/>
                 <xs:element name="status" type="xs:string"/>
             </xs:sequence>
index 1a99e2c0e7a7b47c46494eaebfd711a2cb01871a..d5cc5391a85452fd0b8384e628e0750f548d1695 100644 (file)
@@ -39,6 +39,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
+import org.collectionspace.services.VocabularyJAXBSchema;
 import org.collectionspace.services.VocabularyItemJAXBSchema;
 import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
@@ -162,6 +163,10 @@ public class VocabularyResource extends
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
+        } catch (BadRequestException bre) {
+            Response response = Response.status(
+                    Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
         } catch (UnauthorizedException ue) {
             Response response = Response.status(
                     Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
@@ -234,6 +239,70 @@ public class VocabularyResource extends
         return result;
     }
 
+    /**
+     * Gets the vocabulary by name.
+     * 
+     * @param specifier the specifier
+     * 
+     * @return the vocabulary
+     */
+    @GET
+    @Path("urn:cspace:name({specifier})")
+    public MultipartOutput getVocabularyByName(@PathParam("specifier") String specifier) {
+        if (specifier == null) {
+            logger.error("getVocabularyByName: missing name!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "get failed on Vocabulary (missing specifier)").type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        String whereClause =
+               VocabularyJAXBSchema.VOCABULARIES_COMMON+
+               ":"+VocabularyJAXBSchema.SHORT_IDENTIFIER+
+               "='"+specifier+"'";
+        // We only get a single doc - if there are multiple,
+        // it is an error in use.
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("getVocabularyByName with name=" + specifier);
+        } 
+        MultipartOutput result = null;
+        try {
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
+            DocumentHandler handler = createDocumentHandler(ctx);
+            DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+            handler.setDocumentFilter(myFilter);
+            getRepositoryClient(ctx).get(ctx, handler);
+            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("getVocabularyByName", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Get failed on Vocabulary spec=" + specifier).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("getVocabularyByName", 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 Vocabulary spec:" + specifier + ": was not found.").type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return result;
+    }
+
     /**
      * Gets the vocabulary list.
      * 
@@ -249,14 +318,11 @@ public class VocabularyResource extends
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
-//            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
             DocumentFilter myFilter = handler.getDocumentFilter();
-//            myFilter.setPagination(queryParams);
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
                 myFilter.setWhereClause("vocabularies_common:refName='" + nameQ + "'");
             }
-//            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
index f1cf2a2d244436e61206e2286ebcfd396e5ee6af..606351afc0ac8ee235d4376adfd8644a6310b75a 100644 (file)
@@ -49,6 +49,8 @@
  */
 package org.collectionspace.services.vocabulary.nuxeo;
 
+import java.util.regex.Pattern;
+
 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -65,6 +67,7 @@ import org.slf4j.LoggerFactory;
 public class VocabularyItemValidatorHandler implements ValidatorHandler {
 
     final Logger logger = LoggerFactory.getLogger(VocabularyItemValidatorHandler.class);
+    private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
 
     @Override
     public void validate(Action action, ServiceContext ctx)
@@ -78,10 +81,18 @@ public class VocabularyItemValidatorHandler implements ValidatorHandler {
                     VocabularyitemsCommon.class);
             String msg = "";
             boolean invalid = false;
-                                               String displayName = vocabItem.getDisplayName();
+                       String displayName = vocabItem.getDisplayName();
             if((displayName==null)||(displayName.length()<2)) {
                 invalid = true;
                 msg += "displayName must be non-null, and at least 2 chars long!";
+            }
+                       String shortId = vocabItem.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)) {