From 4193c5bfa88f29782ae2c1efd697e6d0b9d2d88b Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Mon, 14 Jun 2010 05:29:19 +0000 Subject: [PATCH] CSPACE-1152 and CSPACE-2126. Changed Vocabulary schema to include a shortIdentifier. This is now used as the basis of the refName. Added support to vocabulary for readByName. Added validatorHandler to require that shortIdentifier only contain word chars. --- .../main/config/services/tenant-bindings.xml | 3 + .../resources/OSGI-INF/layouts-contrib.xml | 28 ++++ .../resources/schemas/vocabularies_common.xsd | 1 + .../schemas/vocabularyitems_common.xsd | 1 + .../services/client/VocabularyClient.java | 10 ++ .../client/VocabularyClientUtils.java | 42 +++--- .../services/client/VocabularyProxy.java | 5 + .../client/test/VocabularyServiceTest.java | 137 ++++++++++++++++-- .../importer/VocabularyBaseImport.java | 31 ++-- .../services/VocabularyItemJAXBSchema.java | 3 +- .../services/VocabularyJAXBSchema.java | 2 + .../src/main/resources/vocabulary_common.xsd | 1 + .../main/resources/vocabularyitem_common.xsd | 1 + .../vocabulary/VocabularyResource.java | 72 ++++++++- .../nuxeo/VocabularyItemValidatorHandler.java | 13 +- 15 files changed, 301 insertions(+), 49 deletions(-) diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index a7fef44f0..2fdd37b86 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -293,6 +293,9 @@ org.collectionspace.services.vocabulary.nuxeo.VocabularyDocumentModelHandler + + org.collectionspace.services.vocabulary.nuxeo.VocabularyValidatorHandler + displayName + shortIdentifier refName vocabType @@ -28,6 +29,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + @@ -65,6 +79,7 @@ displayName + shortIdentifier refName inVocabulary status @@ -83,6 +98,19 @@ + + + + + true + + shortIdentifier + + + dataInputText + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies_common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies_common.xsd index 9e646713f..75d0dd21d 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies_common.xsd +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies_common.xsd @@ -25,6 +25,7 @@ + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd index 556c1ea8f..09bf431f4 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd @@ -24,6 +24,7 @@ + diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java index a5f3fb537..999b741d9 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -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 readByName(String name) { + return vocabularyProxy.readByName(name); + } + /** * Creates the. * diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java index 0689bd9ca..b564c9fb5 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClientUtils.java @@ -22,9 +22,11 @@ public class VocabularyClientUtils { LoggerFactory.getLogger(VocabularyClientUtils.class); public static MultipartOutput createEnumerationInstance( - String displayName, String refName, String headerLabel ) { + String displayName, String shortIdentifier, String headerLabel ) { VocabulariesCommon vocabulary = new VocabulariesCommon(); vocabulary.setDisplayName(displayName); + vocabulary.setShortIdentifier(shortIdentifier); + String refName = createVocabularyRefName(shortIdentifier, displayName); vocabulary.setRefName(refName); vocabulary.setVocabType("enum"); MultipartOutput multipart = new MultipartOutput(); @@ -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 // items public static MultipartOutput createVocabularyItemInstance(String inVocabulary, - String vocabItemRefName, Map vocabItemInfo, String headerLabel){ + String vocabularyRefName, Map vocabItemInfo, String headerLabel){ VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon(); vocabularyItem.setInVocabulary(inVocabulary); - vocabularyItem.setRefName(vocabItemRefName); - String value = null; - if((value = (String)vocabItemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME))!=null) - vocabularyItem.setDisplayName(value); + String shortId = vocabItemInfo.get(VocabularyItemJAXBSchema.SHORT_IDENTIFIER); + String displayName = vocabItemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME); + vocabularyItem.setShortIdentifier(shortId); + vocabularyItem.setDisplayName(displayName); + String refName = createVocabularyItemRefName(vocabularyRefName, shortId, displayName); + vocabularyItem.setRefName(refName); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE); @@ -68,27 +72,25 @@ public class VocabularyClientUtils { int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; - String displayName = itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME); - String refName = createVocabularyItemRefName(vocabularyRefName, displayName, true); if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+displayName + logger.debug("Import: Create Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthorityulary: \"" + vocabularyRefName +"\""); } MultipartOutput multipart = - createVocabularyItemInstance( vcsid, refName, + createVocabularyItemInstance( vcsid, vocabularyRefName, itemMap, client.getItemCommonPartName() ); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+refName + throw new RuntimeException("Could not create Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + vocabularyRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+refName + throw new RuntimeException("Unexpected Status when creating Item: \""+itemMap.get(VocabularyItemJAXBSchema.DISPLAY_NAME) +"\" in personAuthority: \"" + vocabularyRefName +"\", Status:"+ statusCode); } @@ -126,19 +128,19 @@ public class VocabularyClientUtils { return id; } - public static String createVocabularyRefName(String vocabularyName, boolean withDisplaySuffix) { + public static String createVocabularyRefName(String shortIdentifier, String displaySuffix) { String refName = "urn:cspace:org.collectionspace.demo:vocabulary:name(" - +vocabularyName+")"; - if(withDisplaySuffix) - refName += "'"+vocabularyName+"'"; + +shortIdentifier+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } public static String createVocabularyItemRefName( - String vocabularyRefName, String vocabItemName, boolean withDisplaySuffix) { - String refName = vocabularyRefName+":item:name("+vocabItemName+")"; - if(withDisplaySuffix) - refName += "'"+vocabItemName+"'"; + String vocabularyRefName, String shortIdentifier, String displaySuffix) { + String refName = vocabularyRefName+":item:name("+shortIdentifier+")"; + if(displaySuffix!=null&&!displaySuffix.isEmpty()) + refName += "'"+displaySuffix+"'"; return refName; } diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java index 171f73289..7440be340 100644 --- a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java @@ -38,6 +38,11 @@ public interface VocabularyProxy extends CollectionSpaceProxy { @Path("/{csid}") ClientResponse read(@PathParam("csid") String csid); + //(R)ead by name + @GET + @Path("/urn:cspace:name({name})") + ClientResponse readByName(@PathParam("name") String name); + //(U)pdate @PUT @Path("/{csid}") diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index befc9d016..ea5deea28 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -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 allResourceIdsCreated = new ArrayList(); private Map allResourceItemIdsCreated = new HashMap(); - 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 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 itemInfo = new HashMap(); - 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 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 itemInfo = new HashMap(); + 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 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 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 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 itemInfo = new HashMap(); - 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 res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); diff --git a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java index dd00fe2f9..96e8d1346 100644 --- a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java +++ b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java @@ -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 enumValues) { + public void createEnumeration(String vocabDisplayName, String shortName, List 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 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 acquisitionMethodsEnumValues = Arrays.asList("Gift", "Purchase", "Exchange", "Transfer", "Treasure"); @@ -120,11 +125,11 @@ public class VocabularyBaseImport { List 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."); } diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java index 988070cd7..ff9c9bd53 100644 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java @@ -12,7 +12,8 @@ public interface VocabularyItemJAXBSchema { final static String DISPLAY_NAME = "displayName"; final static String IN_VOCABULARY = "inVocabulary"; final static String REF_NAME = "refName"; - final static String STATUS = "status"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; + final static String STATUS = "status"; final static String CSID = "csid"; } diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java index 09d23eb7a..9f3c8f276 100644 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java @@ -8,7 +8,9 @@ package org.collectionspace.services; * */ public interface VocabularyJAXBSchema { + final static String VOCABULARIES_COMMON = "vocabularies_common"; final static String DISPLAY_NAME = "displayName"; + final static String SHORT_IDENTIFIER = "shortIdentifier"; final static String REF_NAME = "refName"; final static String VOCAB_TYPE = "vocabType"; final static String CSID = "csid"; diff --git a/services/vocabulary/jaxb/src/main/resources/vocabulary_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabulary_common.xsd index a478cdd54..314171239 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabulary_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabulary_common.xsd @@ -36,6 +36,7 @@ + diff --git a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd index fe732cace..e9fb1a95f 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd @@ -23,6 +23,7 @@ + diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 1a99e2c0e..d5cc5391a 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -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 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 queryParams = ui.getQueryParameters(); ServiceContext 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) { diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java index f1cf2a2d2..606351afc 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java @@ -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)) { -- 2.47.3