<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"
</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>
</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>
<!-- 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>
<!-- 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"/>
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.
*
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
// 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
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
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
@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}")
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)
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();
// 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);
}
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);
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++) {
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,
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"})
VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
client.getItemCommonPartName(), VocabularyitemsCommon.class);
Assert.assertNotNull(vocabularyItem);
-
+ Assert.assertEquals(vocabularyItem.getInVocabulary(), knownResourceId);
}
// Failure outcomes
// 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();
// 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);
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();
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) {
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");
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.");
}
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
*\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
<!-- 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>
<!-- 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>
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;
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();
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.
*
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) {
*/
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;
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)
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)) {