}
protected void createPersonRefs(){
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
- acquisitionAuthorizerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Annie Authorizer", true);
- personIdsCreated.add(createPerson("Annie", "Authorizer", acquisitionAuthorizerRefName));
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
- acquisitionFundingSourceRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Sammy Source", true);
- personIdsCreated.add(createPerson("Sammy", "Source", acquisitionFundingSourceRefName));
+ String csid = createPerson("Annie", "Authorizer", "annieAuth", authRefName);
+ acquisitionAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
+
+ csid = createPerson("Sammy", "Source", "sammySource", authRefName);
+ acquisitionFundingSourceRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
MultipartOutput multipart =
- PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright (c) 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ *\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.collectionspace.services.client;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.io.StringWriter;\r
+import java.util.List;\r
+\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.JAXBException;\r
+import javax.xml.bind.Marshaller;\r
+import javax.xml.bind.Unmarshaller;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.apache.commons.io.FileUtils;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.w3c.dom.Document;\r
+\r
+/**\r
+ * CollectionSpaceClientUtils.\r
+ *\r
+ * Base abstract class on which client tests of services are based.\r
+ *\r
+ * $LastChangedRevision: 2261 $\r
+ * $LastChangedDate: 2010-05-28 16:52:22 -0700 (Fri, 28 May 2010) $\r
+ */\r
+\r
+// FIXME: http://issues.collectionspace.org/browse/CSPACE-1685\r
+\r
+public class CollectionSpaceClientUtils {\r
+\r
+ //Maven's base directory -i.e., the one containing the current pom.xml\r
+ /** The Constant logger. */\r
+ private static final Logger logger = LoggerFactory.getLogger(CollectionSpaceClientUtils.class);\r
+ \r
+ protected static final int STATUS_BAD_REQUEST =\r
+ Response.Status.BAD_REQUEST.getStatusCode();\r
+ protected static final int STATUS_CREATED =\r
+ Response.Status.CREATED.getStatusCode();\r
+ protected static final int STATUS_NOT_FOUND =\r
+ Response.Status.NOT_FOUND.getStatusCode();\r
+ protected static final int STATUS_OK =\r
+ Response.Status.OK.getStatusCode();\r
+\r
+ /**\r
+ * Extract id.\r
+ *\r
+ * @param res the res\r
+ * @return the string\r
+ */\r
+ static public String extractId(ClientResponse<Response> res) {\r
+ MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+ String uri = (String) ((List<Object>) mvm.get("Location")).get(0);\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("extractId:uri=" + uri);\r
+ }\r
+ String[] segments = uri.split("/");\r
+ String id = segments[segments.length - 1];\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("id=" + id);\r
+ }\r
+ return id;\r
+ }\r
+ \r
+ /**\r
+ * Extract part.\r
+ *\r
+ * @param input the input\r
+ * @param label the label\r
+ * @param clazz the clazz\r
+ * @return the object\r
+ * @throws Exception the exception\r
+ */\r
+ static public Object extractPart(MultipartInput input, String label, Class<?> clazz)\r
+ throws Exception {\r
+ Object obj = null;\r
+ String partLabel = "";\r
+ List<InputPart> parts = input.getParts();\r
+ if (parts.size() == 0) {\r
+ logger.warn("No parts found in multipart body.");\r
+ }\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Parts:");\r
+ for (InputPart part : parts) {\r
+ partLabel = part.getHeaders().getFirst("label");\r
+ logger.debug("part = " + partLabel);\r
+ }\r
+ }\r
+ boolean partLabelMatched = false;\r
+ for (InputPart part : parts) {\r
+ partLabel = part.getHeaders().getFirst("label");\r
+ if (label.equalsIgnoreCase(partLabel)) {\r
+ partLabelMatched = true;\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("found part" + partLabel);\r
+ }\r
+ String partStr = part.getBodyAsString();\r
+ if (partStr == null || partStr.trim().isEmpty()) {\r
+ logger.warn("Part '" + label + "' in multipart body is empty.");\r
+ } else {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("extracted part as str=\n" + partStr);\r
+ }\r
+ obj = part.getBody(clazz, null);\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("extracted part as obj=\n",\r
+ objectAsXmlString(obj, clazz));\r
+ }\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ if (!partLabelMatched) {\r
+ logger.warn("Could not find part '" + label + "' in multipart body.");\r
+ // In the event that getBodyAsString() or getBody(), above, do *not*\r
+ // throw an IOException, but getBody() nonetheless retrieves a null object.\r
+ // This *may* be unreachable.\r
+ } else if (obj == null) {\r
+ logger.warn("Could not extract part '" + label\r
+ + "' in multipart body as an object.");\r
+ }\r
+ return obj;\r
+ }\r
+\r
+ /**\r
+ * Gets the part object.\r
+ *\r
+ * @param partStr the part str\r
+ * @param clazz the clazz\r
+ * @return the part object\r
+ * @throws JAXBException the jAXB exception\r
+ */\r
+ static public Object getPartObject(String partStr, Class<?> clazz)\r
+ throws JAXBException {\r
+ JAXBContext jc = JAXBContext.newInstance(clazz);\r
+ ByteArrayInputStream bais = null;\r
+ Object obj = null;\r
+ try {\r
+ bais = new ByteArrayInputStream(partStr.getBytes());\r
+ Unmarshaller um = jc.createUnmarshaller();\r
+ obj = um.unmarshal(bais);\r
+ } finally {\r
+ if (bais != null) {\r
+ try {\r
+ bais.close();\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled() == true) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return obj;\r
+ }\r
+\r
+ /**\r
+ * Object as xml string.\r
+ *\r
+ * @param o the o\r
+ * @param clazz the clazz\r
+ * @return the string\r
+ */\r
+ static public String objectAsXmlString(Object o, Class<?> clazz) {\r
+ StringWriter sw = new StringWriter();\r
+ try {\r
+ JAXBContext jc = JAXBContext.newInstance(clazz);\r
+ Marshaller m = jc.createMarshaller();\r
+ m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,\r
+ Boolean.TRUE);\r
+ m.marshal(o, sw);\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ return sw.toString();\r
+ }\r
+\r
+ /**\r
+ * getObjectFromFile get object of given class from given file (in classpath)\r
+ * @param jaxbClass\r
+ * @param fileName of the file to read to construct the object\r
+ * @return\r
+ * @throws Exception\r
+ */\r
+ static public Object getObjectFromFile(Class<?> jaxbClass, String fileName)\r
+ throws Exception {\r
+\r
+ JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+ Unmarshaller unmarshaller = context.createUnmarshaller();\r
+ //note: setting schema to null will turn validator off\r
+ unmarshaller.setSchema(null);\r
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();\r
+ InputStream is = tccl.getResourceAsStream(fileName);\r
+ return getObjectFromStream(jaxbClass, is);\r
+ }\r
+\r
+ /**\r
+ * Gets the xml document.\r
+ *\r
+ * @param fileName the file name\r
+ * @return the xml document\r
+ * @throws Exception the exception\r
+ */\r
+ static public Document getXmlDocument(String fileName) throws Exception {\r
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r
+ File f = new File(fileName);\r
+ if (!f.exists()) {\r
+ throw new IllegalArgumentException("test data file " + fileName + " not found!");\r
+ }\r
+ // Create the builder and parse the file\r
+ return factory.newDocumentBuilder().parse(f);\r
+ }\r
+\r
+ /**\r
+ * Gets the xml document as string.\r
+ *\r
+ * @param fileName the file name\r
+ * @return the xml document as string\r
+ * @throws Exception the exception\r
+ */\r
+ static public String getXmlDocumentAsString(String fileName) throws Exception {\r
+ byte[] b = FileUtils.readFileToByteArray(new File(fileName));\r
+ return new String(b);\r
+ }\r
+\r
+ /**\r
+ * getObjectFromStream get object of given class from given inputstream\r
+ * @param jaxbClass\r
+ * @param is stream to read to construct the object\r
+ * @return\r
+ * @throws Exception\r
+ */\r
+ static public Object getObjectFromStream(Class<?> jaxbClass, InputStream is) throws Exception {\r
+ JAXBContext context = JAXBContext.newInstance(jaxbClass);\r
+ Unmarshaller unmarshaller = context.createUnmarshaller();\r
+ //note: setting schema to null will turn validator off\r
+ unmarshaller.setSchema(null);\r
+ return jaxbClass.cast(unmarshaller.unmarshal(is));\r
+ }\r
+}\r
/** The person auth csid. */
private String personAuthCSID = null;
+ private String personAuthRefName = null;
/** The content organization ref name. */
private String contentOrganizationRefName = null;
* Creates the person refs.
*/
protected void createPersonRefs(){
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
+ // TODO Test that we can reuse the client above.
+ personAuthRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
- contentOrganizationRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Omni Org", true);
- personIdsCreated.add(createPerson("Omni", "Org", contentOrganizationRefName));
+ String csid = createPerson("Omni", "Org", "omniOrg");
+ contentOrganizationRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- contentPeopleRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Pushy People", true);
- personIdsCreated.add(createPerson("Pushy", "People", contentPeopleRefName));
+ csid = createPerson("Pushy", "People", "pushyPeople");
+ contentPeopleRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- contentPersonRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Connie ContactPerson", true);
- personIdsCreated.add(createPerson("Connie", "ContactPerson", contentPersonRefName));
+ csid = createPerson("Connie", "ContactPerson", "connieContactPerson");
+ contentPersonRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- contentInscriberRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Ingrid Inscriber", true);
- personIdsCreated.add(createPerson("Ingrid", "Inscriber", contentInscriberRefName));
+ csid = createPerson("Ingrid", "Inscriber", "ingridInscriber");
+ contentInscriberRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
}
/**
* @param refName the ref name
* @return the string
*/
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortIdentifier ) {
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortIdentifier);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ personAuthRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
protected void createPersonRefs(){
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
- currentOwnerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Olivier Owner", true);
- personIdsCreated.add(createPerson("Olivier", "Owner", currentOwnerRefName));
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
- depositorRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Debbie Depositor", true);
- personIdsCreated.add(createPerson("Debbie", "Depositor", depositorRefName));
+ String csid = createPerson("Olivier", "Owner", "olivierOwner", authRefName);
+ currentOwnerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- conditionCheckerAssessorRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Andrew Checker-Assessor", true);
- personIdsCreated.add(createPerson("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName));
+ csid = createPerson("Debbie", "Depositor", "debbieDepositor", authRefName);
+ depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- insurerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Ingrid Insurer", true);
- personIdsCreated.add(createPerson("Ingrid", "Insurer", insurerRefName));
+ csid = createPerson("Andrew", "Assessor", "andrewAssessor", authRefName);
+ conditionCheckerAssessorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
- valuerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Vince Valuer", true);
- personIdsCreated.add(createPerson("Vince", "Valuer", valuerRefName));
+ csid = createPerson("Ingrid", "Insurer", "ingridInsurer", authRefName);
+ insurerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
-
+ csid = createPerson("Vince", "Valuer", "vinceValuer", authRefName);
+ valuerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ personIdsCreated.add(csid);
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
}
private MultipartOutput createIntakeInstance(String entryNumber,
- String entryDate,
- String currentOwner,
- String depositor,
- String conditionCheckerAssessor,
- String insurer,
- String Valuer ) {
-
+ String entryDate,
+ String currentOwner,
+ String depositor,
+ String conditionCheckerAssessor,
+ String insurer,
+ String Valuer ) {
IntakesCommon intake = new IntakesCommon();
intake.setEntryNumber(entryNumber);
intake.setEntryDate(entryDate);
private List<String> intakeIdsCreated = new ArrayList<String>();\r
private List<String> orgIdsCreated = new ArrayList<String>();\r
private String orgAuthCSID = null; \r
+ private String orgAuthRefName = null; \r
private String currentOwnerOrgCSID = null; \r
private String currentOwnerRefName = null;\r
private String depositorRefName = null;\r
*/\r
protected void createOrgRefs(){\r
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
- String authRefName = \r
- OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, false);\r
+ orgAuthRefName = \r
+ OrgAuthorityClientUtils.createOrgAuthRefName(ORGANIZATION_AUTHORITY_NAME, null);\r
MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(\r
- ORGANIZATION_AUTHORITY_NAME, authRefName, orgAuthClient.getCommonPartName());\r
+ ORGANIZATION_AUTHORITY_NAME, ORGANIZATION_AUTHORITY_NAME, orgAuthClient.getCommonPartName());\r
ClientResponse<Response> res = orgAuthClient.create(multipart);\r
int statusCode = res.getStatus();\r
\r
Assert.assertEquals(statusCode, STATUS_CREATED);\r
orgAuthCSID = extractId(res);\r
\r
- currentOwnerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
- authRefName, "Olivier Owner", true);\r
- currentOwnerOrgCSID = createOrganization("Olivier", "Owner", currentOwnerRefName);\r
+ currentOwnerOrgCSID = createOrganization("olivierOwner", "Olivier Owner", "Olivier Owner");\r
orgIdsCreated.add(currentOwnerOrgCSID);\r
+ currentOwnerRefName = OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, currentOwnerOrgCSID, orgAuthClient);\r
\r
- depositorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
- authRefName, "Debbie Depositor", true);\r
- orgIdsCreated.add(createOrganization("Debbie", "Depositor", depositorRefName));\r
+ String newOrgCSID = createOrganization("debbieDepositor", "Debbie Depositor", "Debbie Depositor");\r
+ depositorRefName = \r
+ OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+ orgIdsCreated.add(newOrgCSID);\r
\r
- conditionCheckerAssessorRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
- authRefName, "Andrew Checker-Assessor", true);\r
- orgIdsCreated.add(createOrganization("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName));\r
+ newOrgCSID = createOrganization("andrewCheckerAssessor", "Andrew Checker-Assessor", "Andrew Checker-Assessor");\r
+ conditionCheckerAssessorRefName = \r
+ OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+ orgIdsCreated.add(newOrgCSID);\r
\r
- insurerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
- authRefName, "Ingrid Insurer", true);\r
- orgIdsCreated.add(createOrganization("Ingrid", "Insurer", insurerRefName));\r
+ newOrgCSID = createOrganization("ingridInsurer", "Ingrid Insurer", "Ingrid Insurer");\r
+ insurerRefName = \r
+ OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+ orgIdsCreated.add(newOrgCSID);\r
\r
- valuerRefName = OrgAuthorityClientUtils.createOrganizationRefName(\r
- authRefName, "Vince Valuer", true);\r
- orgIdsCreated.add(createOrganization("Vince", "Valuer", valuerRefName));\r
- \r
-\r
+ newOrgCSID = createOrganization("vinceValuer", "Vince Valuer", "Vince Valuer");\r
+ valuerRefName = \r
+ OrgAuthorityClientUtils.getOrgRefName(orgAuthCSID, newOrgCSID, orgAuthClient);\r
+ orgIdsCreated.add(newOrgCSID);\r
}\r
- \r
- protected String createOrganization(String shortName, String longName, String refName ) {\r
+\r
+ protected String createOrganization(String shortId, String shortName, String longName) {\r
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();\r
Map<String, String> orgInfo = new HashMap<String,String>();\r
+ orgInfo.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);\r
orgInfo.put(OrganizationJAXBSchema.SHORT_NAME, shortName);\r
orgInfo.put(OrganizationJAXBSchema.LONG_NAME, longName);\r
MultipartOutput multipart = \r
- OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, \r
- refName, orgInfo, orgAuthClient.getItemCommonPartName());\r
+ OrgAuthorityClientUtils.createOrganizationInstance(orgAuthCSID, orgAuthRefName,\r
+ orgInfo, orgAuthClient.getItemCommonPartName());\r
ClientResponse<Response> res = orgAuthClient.createItem(orgAuthCSID, multipart);\r
int statusCode = res.getStatus();\r
\r
MultipartOutput multipart = createIntakeInstance(
"entryNumber-" + identifier,
"entryDate-" + identifier,
- currentOwnerRefName,
- depositorRefName,
- conditionCheckerAssessorRefName,
- insurerRefName,
- valuerRefName );
+ currentOwnerRefName,
+ depositorRefName,
+ conditionCheckerAssessorRefName,
+ insurerRefName,
+ valuerRefName );
ClientResponse<Response> res = intakeClient.create(multipart);
try {
*/
protected void createPersonRefs(){
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
- currentOwnerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Olivier Owner", true);
- currentOwnerPersonCSID = createPerson("Olivier", "Owner", currentOwnerRefName);
- personIdsCreated.add(currentOwnerPersonCSID);
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
- depositorRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Debbie Depositor", true);
- personIdsCreated.add(createPerson("Debbie", "Depositor", depositorRefName));
+ String csid = createPerson("Olivier", "Owner", "olivierOwner", authRefName);
+ Assert.assertNotNull(csid);
+ currentOwnerPersonCSID = csid;
+ currentOwnerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ Assert.assertNotNull(currentOwnerRefName);
+ personIdsCreated.add(csid);
- conditionCheckerAssessorRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Andrew Checker-Assessor", true);
- personIdsCreated.add(createPerson("Andrew", "Checker-Assessor", conditionCheckerAssessorRefName));
+ csid = createPerson("Debbie", "Depositor", "debbieDepositor", authRefName);
+ Assert.assertNotNull(csid);
+ depositorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ Assert.assertNotNull(depositorRefName);
+ personIdsCreated.add(csid);
- insurerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Ingrid Insurer", true);
- personIdsCreated.add(createPerson("Ingrid", "Insurer", insurerRefName));
+ csid = createPerson("Andrew", "Assessor", "andrewAssessor", authRefName);
+ Assert.assertNotNull(csid);
+ conditionCheckerAssessorRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ Assert.assertNotNull(conditionCheckerAssessorRefName);
+ personIdsCreated.add(csid);
- valuerRefName = PersonAuthorityClientUtils.createPersonRefName(
- authRefName, "Vince Valuer", true);
- personIdsCreated.add(createPerson("Vince", "Valuer", valuerRefName));
+ csid = createPerson("Ingrid", "Insurer", "ingridInsurer", authRefName);
+ Assert.assertNotNull(csid);
+ insurerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ Assert.assertNotNull(insurerRefName);
+ personIdsCreated.add(csid);
+
+ csid = createPerson("Vince", "Valuer", "vinceValuer", authRefName);
+ Assert.assertNotNull(csid);
+ valuerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+ Assert.assertNotNull(valuerRefName);
+ personIdsCreated.add(csid);
-
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
MultipartOutput multipart = createLoaninInstance(
"loanInNumber-" + identifier,
"returnDate-" + identifier,
- lenderRefName,
+ lenderRefName,
lendersAuthorizerRefName,
lendersContactRefName,
loanInContactRefName);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- lenderRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Linus Lender", true);
- personIdsCreated.add(createPerson("Linus", "Lender", lenderRefName));
+ String csid = createPerson("Linus", "Lender", "linusLender", authRefName);
+ personIdsCreated.add(csid);
+ lenderRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
- lendersAuthorizerRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Art Lendersauthorizor", true);
- personIdsCreated.add(createPerson("Art", "Lendersauthorizor", lendersAuthorizerRefName));
+ csid = createPerson("Art", "Lendersauthorizor", "artLendersauthorizor", authRefName);
+ personIdsCreated.add(csid);
+ lendersAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
- lendersContactRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Larry Lenderscontact", true);
- personIdsCreated.add(createPerson("Larry", "Lenderscontact", lendersContactRefName));
+ csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", authRefName);
+ personIdsCreated.add(csid);
+ lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
- loanInContactRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Carrie Loanincontact", true);
- personIdsCreated.add(createPerson("Carrie", "Loanincontact", loanInContactRefName));
+ csid = createPerson("Carrie", "Loanincontact", "carrieLoanincontact", authRefName);
+ personIdsCreated.add(csid);
+ loanInContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
// FIXME: Add instance(s) of 'lenders' field when we can work with
// repeatable / multivalued authority reference fields. Be sure to
// revise check for numbers of authority fields expected in readAndCheckAuthRefs.
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
-
+
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- borrowersContactRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Bradley BorrowersContact", true);
- personIdsCreated.add(createPerson("Bradley", "BorrowersContact", borrowersContactRefName));
+ String csid = createPerson("Art", "Lendersauthorizor", "artLendersauthorizor", authRefName);
+ personIdsCreated.add(csid);
+ lendersAuthorizerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
- lendersAuthorizerRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Art Lendersauthorizor", true);
- personIdsCreated.add(createPerson("Art", "Lendersauthorizor", lendersAuthorizerRefName));
-
- lendersContactRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Larry Lenderscontact", true);
- personIdsCreated.add(createPerson("Larry", "Lenderscontact", lendersContactRefName));
+ csid = createPerson("Larry", "Lenderscontact", "larryLenderscontact", authRefName);
+ personIdsCreated.add(csid);
+ lendersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
+
+ csid = createPerson("Bradley", "BorrowersContact", "bradleyBorrowersContact", authRefName);
+ personIdsCreated.add(csid);
+ borrowersContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
</templates>
<rows>
<row><widget>displayName</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>refName</widget></row>
<row><widget>vocabType</widget></row>
</rows>
</properties>
</widget>
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="locationauthorities_common">shortIdentifier</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="refName" type="text">
<labels>
<label mode="any">RefName</label>
</templates>
<rows>
<row><widget>inAuthority</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>refName</widget></row>
<row><widget>displayName</widget></row>
<row><widget>displayNameComputed</widget></row>
</properties>
</widget>
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="locations_common">shortIdentifier</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="refName" type="text">
<labels>
<label mode="any">refName</label>
<!-- LocationAuthority Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
<!-- Location Information Group -->
<!-- inAuthority is the csid of the owning LocationAuthority -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
* @return The MultipartOutput payload for the create call\r
*/\r
public static MultipartOutput createLocationAuthorityInstance(\r
- String displayName, String refName, String headerLabel ) {\r
+ String displayName, String shortIdentifier, String headerLabel ) {\r
LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon();\r
locationAuthority.setDisplayName(displayName);\r
+ locationAuthority.setShortIdentifier(shortIdentifier);\r
+ String refName = createLocationAuthRefName(shortIdentifier, displayName);\r
locationAuthority.setRefName(refName);\r
locationAuthority.setVocabType("LocationAuthority");\r
MultipartOutput multipart = new MultipartOutput();\r
* @return The MultipartOutput payload for the create call\r
*/\r
public static MultipartOutput createLocationInstance(String inAuthority, \r
- String locationRefName, Map<String, String> locationInfo, String headerLabel){\r
+ String locationAuthRefName, Map<String, String> locationInfo, String headerLabel){\r
LocationsCommon location = new LocationsCommon();\r
+ String shortId = locationInfo.get(LocationJAXBSchema.SHORT_IDENTIFIER);\r
+ String displayName = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME);\r
+ location.setShortIdentifier(shortId);\r
location.setInAuthority(inAuthority);\r
+ String locationRefName = createLocationRefName(locationAuthRefName, shortId, displayName);\r
location.setRefName(locationRefName);\r
String value = null;\r
value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
locationMap.get(LocationJAXBSchema.NAME));\r
}\r
\r
- String refName = createLocationRefName(locationAuthorityRefName, displayName, true);\r
-\r
if(logger.isDebugEnabled()){\r
logger.debug("Import: Create Item: \""+displayName\r
+"\" in locationAuthority: \"" + locationAuthorityRefName +"\"");\r
}\r
MultipartOutput multipart = \r
- createLocationInstance( vcsid, refName,\r
+ createLocationInstance( vcsid, locationAuthorityRefName,\r
locationMap, client.getItemCommonPartName() );\r
ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
\r
int statusCode = res.getStatus();\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
- throw new RuntimeException("Could not create Item: \""+refName\r
+ throw new RuntimeException("Could not create Item: \""\r
+ +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in locationAuthority: \"" + locationAuthorityRefName\r
+"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
- throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""\r
+ +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode);\r
}\r
\r
return createItemInAuthority(vcsid, commonPartXML, client );\r
} \r
\r
- public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) {\r
+ /**\r
+ * Creates the locationAuthority ref name.\r
+ *\r
+ * @param shortId the locationAuthority shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
+ * @return the string\r
+ */\r
+ public static String createLocationAuthRefName(String shortId, String displaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name("\r
- +locationAuthorityName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+locationAuthorityName+"'";\r
+ +shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
+ /**\r
+ * Creates the location ref name.\r
+ *\r
+ * @param locationAuthRefName the locationAuthority ref name\r
+ * @param shortId the location shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
+ * @return the string\r
+ */\r
public static String createLocationRefName(\r
- String locationAuthRefName, String locationName, boolean withDisplaySuffix) {\r
- String refName = locationAuthRefName+":location:name("+locationName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+locationName+"'";\r
+ String locationAuthRefName, String shortId, String displaySuffix) {\r
+ String refName = locationAuthRefName+":location:name("+shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
/** The CONTACT service path component. */
final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
- /** The TEST name. */
final String TEST_NAME = "Shelf 1";
-
- /** The TEST conditionNote. */
+ final String TEST_SHORTID = "shelf1";
final String TEST_CONDITION_NOTE = "Basically clean";
-
- /** The TEST death date. */
final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
-
- /** The TEST securityNote. */
final String TEST_SECURITY_NOTE = "Kind of safe";
-
- /** The TEST location type. */
// TODO Make loc type be a controlled vocab term.
final String TEST_LOCATION_TYPE = "Shelf";
-
- /** The TEST location type. */
// TODO Make status type be a controlled vocab term.
final String TEST_STATUS = "Approved";
/** The known resource id. */
private String knownResourceId = null;
-
- /** The known resource display name. */
- private String knownResourceDisplayName = null;
-
- /** The known resource ref name. */
+ private String knownResourceShortIdentifer = null;
private String knownResourceRefName = null;
-
- /** The known locationType ref name. */
private String knownLocationTypeRefName = null;
-
- /** The known item resource id. */
private String knownItemResourceId = null;
-
- /** The known contact resource id. */
+ private String knownItemResourceShortIdentifer = null;
private String knownContactResourceId = null;
/** The n items to create in list. */
private Map<String, String> allItemResourceIdsCreated =
new HashMap<String, String>();
+ protected void setKnownResource( String id, String shortIdentifer,
+ String refName ) {
+ knownResourceId = id;
+ knownResourceShortIdentifer = shortIdentifer;
+ knownResourceRefName = refName;
+ }
+
+ protected void setKnownItemResource( String id, String shortIdentifer ) {
+ knownItemResourceId = id;
+ knownItemResourceShortIdentifer = shortIdentifer;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
// Submit the request to the service and store the response.
LocationAuthorityClient client = new LocationAuthorityClient();
- String identifier = createIdentifier();
- String displayName = "displayName-" + identifier;
- String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, false);
- String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true);
+ String shortId = createIdentifier();
+ String displayName = "displayName-" + shortId;
+ String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
MultipartOutput multipart =
LocationAuthorityClientUtils.createLocationAuthorityInstance(
- displayName, fullRefName, client.getCommonPartName());
+ displayName, shortId, client.getCommonPartName());
ClientResponse<Response> res = client.create(multipart);
int statusCode = res.getStatus();
invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
- // Store the refname from the first resource created
- // for additional tests below.
- knownResourceRefName = baseRefName;
-
String newID = LocationAuthorityClientUtils.extractId(res);
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
- knownResourceId = newID;
- knownResourceDisplayName = displayName;
+ setKnownResource( newID, shortId, baseRefName );
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
logger.debug(testBanner(testName, CLASS_NAME));
}
setupCreate();
- String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
+ createItemInAuthority(knownResourceId, knownResourceRefName);
}
/**
*/
private String createItemInAuthority(String vcsid, String authRefName) {
- final String testName = "createItemInAuthority";
+ final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
if(logger.isDebugEnabled()){
logger.debug(testBanner(testName, CLASS_NAME));
}
// Submit the request to the service and store the response.
LocationAuthorityClient client = new LocationAuthorityClient();
- String identifier = createIdentifier();
- String refName = LocationAuthorityClientUtils.createLocationRefName(authRefName, TEST_NAME, true);
Map<String, String> shelf1Map = new HashMap<String,String>();
// TODO Make loc type and status be controlled vocabs.
shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
+ shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
shelf1Map.put(LocationJAXBSchema.STATUS, TEST_STATUS);
- MultipartOutput multipart =
- LocationAuthorityClientUtils.createLocationInstance(vcsid, refName, shelf1Map,
- client.getItemCommonPartName() );
- ClientResponse<Response> res = client.createItem(vcsid, multipart);
- int statusCode = res.getStatus();
- String newID = LocationAuthorityClientUtils.extractId(res);
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
+ authRefName, shelf1Map, client );
// Store the ID returned from the first item resource created
// for additional tests below.
if (knownItemResourceId == null){
- knownItemResourceId = newID;
+ setKnownItemResource(newID, TEST_SHORTID);
if (logger.isDebugEnabled()) {
- logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
+ logger.debug(testName + ": knownItemResourceId=" + newID);
}
}
public void readByName(String testName) throws Exception {
if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName, CLASS_NAME));
+ logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
}
// Perform setup.
setupRead();
// Submit the request to the service and store the response.
LocationAuthorityClient client = new LocationAuthorityClient();
- ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
+ ClientResponse<MultipartInput> res = client.readByName(knownResourceShortIdentifer);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
- readItemList(null, knownResourceDisplayName);
+ readItemList(null, knownResourceShortIdentifer);
}
/**
* @param vcsid the vcsid
* @param name the name
*/
- private void readItemList(String vcsid, String name) {
+ private void readItemList(String vcsid, String shortId) {
String testName = "readItemList";
ClientResponse<LocationsCommonList> res = null;
if(vcsid!= null) {
res = client.readItemList(vcsid);
- } else if(name!= null) {
- res = client.readItemListForNamedAuthority(name);
+ } else if(shortId!= null) {
+ res = client.readItemListForNamedAuthority(shortId);
} else {
Assert.fail("readItemList passed null csid and name!");
}
// The only relevant ID may be the one used in update(), below.
LocationAuthorityClient client = new LocationAuthorityClient();
String displayName = "displayName-NON_EXISTENT_ID";
- String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true);
MultipartOutput multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
- displayName, fullRefName, client.getCommonPartName());
+ displayName, "nonEx", client.getCommonPartName());
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
int statusCode = res.getStatus();
LocationAuthorityClient client = new LocationAuthorityClient();
Map<String, String> nonexMap = new HashMap<String,String>();
nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
+ nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
nonexMap.put(LocationJAXBSchema.STATUS, TEST_STATUS);
MultipartOutput multipart =
LocationAuthorityClientUtils.createLocationInstance(NON_EXISTENT_ID,
- LocationAuthorityClientUtils.createLocationRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
- client.getItemCommonPartName() );
+ LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
+ nonexMap, client.getItemCommonPartName() );
ClientResponse<MultipartInput> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
int statusCode = res.getStatus();
final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common";\r
final static String DISPLAY_NAME = "displayName";\r
final static String REF_NAME = "refName";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String VOCAB_TYPE = "vocabType";\r
final static String CSID = "csid";\r
}\r
public interface LocationJAXBSchema {\r
final static String LOCATIONS_COMMON = "locations_common";\r
final static String CSID = "csid";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String IN_AUTHORITY = "inAuthority";\r
final static String REF_NAME = "refName";\r
final static String DISPLAY_NAME = "displayName";\r
<!-- Location Information Group -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
<!-- LocationAuthority Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
}
String whereClause =
LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+
- ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+
+ ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+
"='"+specifier+"'";
// We only get a single doc - if there are multiple,
// it is an error in use.
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String whereClause =
LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+
- ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+
+ ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+
"='"+parentSpecifier+"'";
// Need to get an Authority by name
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
- String authRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
int statusCode = res.getStatus();
Assert.assertEquals(statusCode, STATUS_CREATED);
personAuthCSID = extractId(res);
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+
// Create temporary Person resources, and their corresponding refNames
// by which they can be identified.
- movementContactRefName =
- PersonAuthorityClientUtils.createPersonRefName(authRefName, "Melvin MovementContact", true);
- personIdsCreated.add(createPerson("Melvin", "MovementContact", movementContactRefName));
+ String csid = createPerson("Melvin", "MovementContact", "melvinMovementContact", authRefName);
+ personIdsCreated.add(csid);
+ movementContactRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
}
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
int statusCode = res.getStatus();
<rows>
<row><widget>displayName</widget></row>
<row><widget>refName</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>vocabType</widget></row>
</rows>
</properties>
</widget>
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="orgauthorities_common">shortIdentifier</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="refName" type="text">
<labels>
<label mode="any">refName</label>
</templates>
<rows>
<row><widget>inAuthority</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>refName</widget></row>
<row><widget>displayName</widget></row>
<!-- <row><widget>displayNameComputed</widget></row> -->
</properties>
</widget>
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="organizations_common">shortIdentifier</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="refName" type="text">
<labels>
<label mode="any">refName</label>
<!-- Organization Information Group -->
<!-- inAuthority is the csid of the owning OrgAuthority -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
<!-- OrgAuthority Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
<artifactId>org.collectionspace.services.organization.jaxb</artifactId>\r
<version>${project.version}</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.common</artifactId>\r
+ <optional>true</optional>\r
+ <version>${project.version}</version>\r
+ </dependency> \r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.client</artifactId>\r
return orgAuthorityProxy.readItem(vcsid, csid);
}
+ /**
+ * Read named item.
+ *
+ * @param vcsid the vcsid
+ * @param shortId the shortIdentifier
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readNamedItem(String vcsid, String shortId) {
+ return orgAuthorityProxy.readNamedItem(vcsid, shortId);
+ }
+
+ /**
+ * Read item in Named Authority.
+ *
+ * @param authShortId the shortIdentifier for the Authority
+ * @param csid the csid
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readItemInNamedAuthority(String authShortId, String csid) {
+ return orgAuthorityProxy.readItemInNamedAuthority(authShortId, csid);
+ }
+
+ /**
+ * Read named item in Named Authority.
+ *
+ * @param authShortId the shortIdentifier for the Authority
+ * @param itemShortId the shortIdentifier for the item
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
+ return orgAuthorityProxy.readNamedItem(authShortId, itemShortId);
+ }
+
/**
* Creates the item.
*
import org.collectionspace.services.client.test.ServiceRequestType;\r
import org.collectionspace.services.organization.OrganizationsCommon;\r
import org.collectionspace.services.organization.OrgauthoritiesCommon;\r
+import org.collectionspace.services.person.PersonauthoritiesCommon;\r
+import org.collectionspace.services.person.PersonsCommon;\r
import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
import org.slf4j.Logger;\r
/** The Constant logger. */\r
private static final Logger logger =\r
LoggerFactory.getLogger(OrgAuthorityClientUtils.class);\r
+ private static final ServiceRequestType READ_REQ = ServiceRequestType.READ;\r
+\r
+ /**\r
+ * @param csid the id of the OrgAuthority\r
+ * @param client if null, creates a new client\r
+ * @return\r
+ */\r
+ public static String getAuthorityRefName(String csid, OrgAuthorityClient client){\r
+ if(client==null)\r
+ client = new OrgAuthorityClient();\r
+ ClientResponse<MultipartInput> res = client.read(csid);\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ if(!READ_REQ.isValidStatusCode(statusCode)\r
+ ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+ throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+ }\r
+ //FIXME: remove the following try catch once Aron fixes signatures\r
+ try {\r
+ MultipartInput input = (MultipartInput) res.getEntity();\r
+ OrgauthoritiesCommon orgAuthority = \r
+ (OrgauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input,\r
+ client.getCommonPartName(), OrgauthoritiesCommon.class);\r
+ if(orgAuthority==null) {\r
+ throw new RuntimeException("Null orgAuthority returned from service.");\r
+ }\r
+ return orgAuthority.getRefName();\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ } finally {\r
+ res.releaseConnection();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @param csid the id of the PersonAuthority\r
+ * @param client if null, creates a new client\r
+ * @return\r
+ */\r
+ public static String getOrgRefName(String inAuthority, String csid, OrgAuthorityClient client){\r
+ if(client==null)\r
+ client = new OrgAuthorityClient();\r
+ ClientResponse<MultipartInput> res = client.readItem(inAuthority, csid);\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ if(!READ_REQ.isValidStatusCode(statusCode)\r
+ ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+ throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+ }\r
+ //FIXME: remove the following try catch once Aron fixes signatures\r
+ try {\r
+ MultipartInput input = (MultipartInput) res.getEntity();\r
+ OrganizationsCommon org = \r
+ (OrganizationsCommon) CollectionSpaceClientUtils.extractPart(input,\r
+ client.getItemCommonPartName(), OrganizationsCommon.class);\r
+ if(org==null) {\r
+ throw new RuntimeException("Null Organization returned from service.");\r
+ }\r
+ return org.getRefName();\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ } finally {\r
+ res.releaseConnection();\r
+ }\r
+ }\r
\r
/**\r
* Creates the org authority instance.\r
*\r
* @param displayName the display name\r
- * @param refName the ref name\r
+ * @param shortIdentifier the short Id \r
* @param headerLabel the header label\r
* @return the multipart output\r
*/\r
public static MultipartOutput createOrgAuthorityInstance(\r
- String displayName, String refName, String headerLabel ) {\r
+ String displayName, String shortIdentifier, String headerLabel ) {\r
OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon();\r
orgAuthority.setDisplayName(displayName);\r
- orgAuthority.setRefName(refName);\r
+ orgAuthority.setShortIdentifier(shortIdentifier);\r
+ String refName = createOrgAuthRefName(shortIdentifier, displayName);\r
orgAuthority.setVocabType("OrgAuthority");\r
MultipartOutput multipart = new MultipartOutput();\r
OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);\r
/**\r
* Creates the item in authority.\r
*\r
- * @param vcsid the vcsid\r
- * @param orgAuthorityRefName the org authority ref name\r
- * @param orgInfo the org info\r
+ * @param inAuthority the owning authority\r
+ * @param orgAuthorityRefName the owning Authority ref name\r
+ * @param orgInfo the org info. OrganizationJAXBSchema.SHORT_IDENTIFIER is REQUIRED.\r
* @param client the client\r
* @return the string\r
*/\r
- public static String createItemInAuthority(String vcsid, \r
+ public static String createItemInAuthority(String inAuthority, \r
String orgAuthorityRefName, Map<String, String> orgInfo,\r
OrgAuthorityClient client) {\r
// Expected status code: 201 Created\r
// Type of service request being tested\r
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
String displayName = createDisplayName(orgInfo);\r
- String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true);\r
\r
if(logger.isDebugEnabled()){\r
logger.debug("Import: Create Item: \""+displayName\r
+"\" in orgAuthority: \"" + orgAuthorityRefName +"\"");\r
}\r
MultipartOutput multipart =\r
- createOrganizationInstance(vcsid, refName, orgInfo, client.getItemCommonPartName());\r
- ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+ createOrganizationInstance(inAuthority, orgAuthorityRefName, \r
+ orgInfo, client.getItemCommonPartName());\r
+ ClientResponse<Response> res = client.createItem(inAuthority, multipart);\r
String result;\r
try { \r
int statusCode = res.getStatus();\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
- throw new RuntimeException("Could not create Item: \""+displayName\r
+ throw new RuntimeException("Could not create Item: \""+orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in orgAuthority: \"" + orgAuthorityRefName\r
+"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
- throw new RuntimeException("Unexpected Status when creating Item: \""+ displayName\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+ orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode);\r
}\r
\r
* Creates the organization instance.\r
*\r
* @param inAuthority the in authority\r
- * @param orgRefName the org ref name\r
+ * @param orgAuthRefName the owning Authority ref name\r
* @param orgInfo the org info\r
* @param headerLabel the header label\r
* @return the multipart output\r
*/\r
public static MultipartOutput createOrganizationInstance(String inAuthority, \r
- String orgRefName, Map<String, String> orgInfo, String headerLabel){\r
+ String orgAuthRefName, Map<String, String> orgInfo, String headerLabel){\r
OrganizationsCommon organization = new OrganizationsCommon();\r
organization.setInAuthority(inAuthority);\r
- organization.setRefName(orgRefName);\r
+ String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER);\r
+ if (shortId == null || shortId.isEmpty()) {\r
+ throw new IllegalArgumentException("shortIdentifier cannot be null or empty");\r
+ } \r
+ organization.setShortIdentifier(shortId);\r
String value = null;\r
value = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); \r
organization.setDisplayNameComputed(displayNameComputed);\r
- if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null)\r
+ if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME))!=null)\r
organization.setDisplayName(value);\r
+ \r
+ String refName = createOrganizationRefName(orgAuthRefName, shortId, value);\r
+ organization.setRefName(refName);\r
+\r
if((value = (String)orgInfo.get(OrganizationJAXBSchema.SHORT_NAME))!=null)\r
organization.setShortName(value);\r
if((value = (String)orgInfo.get(OrganizationJAXBSchema.LONG_NAME))!=null)\r
/**\r
* Creates the org auth ref name.\r
*\r
- * @param orgAuthorityName the org authority name\r
- * @param withDisplaySuffix the with display suffix\r
+ * @param shortId the orgAuthority shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
* @return the string\r
*/\r
- public static String createOrgAuthRefName(String orgAuthorityName, boolean withDisplaySuffix) {\r
+ public static String createOrgAuthRefName(String shortId, String displaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:orgauthority:name("\r
- +orgAuthorityName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+orgAuthorityName+"'";\r
+ +shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
* Creates the organization ref name.\r
*\r
* @param orgAuthRefName the org auth ref name\r
- * @param orgName the org name\r
- * @param withDisplaySuffix the with display suffix\r
+ * @param shortId the person shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
* @return the string\r
*/\r
public static String createOrganizationRefName(\r
- String orgAuthRefName, String orgName, boolean withDisplaySuffix) {\r
- String refName = orgAuthRefName+":organization:name("+orgName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+orgName+"'";\r
+ String orgAuthRefName, String shortId, String displaySuffix) {\r
+ String refName = orgAuthRefName+":organization:name("+shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
+import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.contact.ContactsCommonList;
@GET
@Produces({"application/xml"})
@Path("/urn:cspace:name({specifier})/items/")
- ClientResponse<OrganizationsCommonList> readItemListForNamedAuthority(@PathParam("specifier") String specifier);
+ ClientResponse<OrganizationsCommonList> readItemListForNamedAuthority(
+ @PathParam("specifier") String specifier);
+
+ // List Items for a named authority matching a partial term.
+ @GET
+ @Produces({"application/xml"})
+ @Path("/urn:cspace:name({specifier})/items/")
+ ClientResponse<OrganizationsCommonList> readItemListForNamedAuthority(
+ @PathParam("specifier") String specifier,
+ @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm);
// List Item Authority References
@GET
@Path("/{vcsid}/items/{csid}")
ClientResponse<MultipartInput> readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid);
+ //(R)ead Named Item
+ @GET
+ @Path("/{vcsid}/items/urn:cspace:name({specifier})")
+ ClientResponse<MultipartInput> readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier);
+
+ //(R)ead Item In Named Authority
+ @GET
+ @Path("/urn:cspace:name({specifier})/items/{csid}")
+ ClientResponse<MultipartInput> readItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("csid") String csid);
+
+ //(R)ead Named Item In Named Authority
+ @GET
+ @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})")
+ ClientResponse<MultipartInput> readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier);
+
//(U)pdate Item
@PUT
@Path("/{vcsid}/items/{csid}")
private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
// Instance variables specific to this test.
- /** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "orgauthorities";
-
- // Temporary Person and Organization Authority names, used for test purposes.
final String PERSON_AUTHORITY_NAME = "TestPersonAuth";
final String ORG_AUTHORITY_NAME = "TestOrgAuth";
- /** The known resource ref name. */
+
+ private String knownResourceId = null;
private String knownResourceRefName = null;
- /** The known auth resource id. */
- private String knownAuthResourceId = null;
-
/** The known item id. */
- private String knownItemId = null;
+ private String knownItemResourceId = null;
/** The all resource ids created. */
private List<String> allResourceIdsCreated = new ArrayList<String>();
/** The number of authorityreferences expected. */
private final int NUM_AUTH_REFS_EXPECTED = 2;
+ protected void setKnownResource( String id, String refName ) {
+ knownResourceId = id;
+ knownResourceRefName = refName;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
// Create a new Organization Authority resource.
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();
- String identifier = createIdentifier();
- String displayName = "TestOrgAuth-" + identifier;
- boolean createWithDisplayName = false;
- knownResourceRefName =
- OrgAuthorityClientUtils.createOrgAuthRefName(displayName, createWithDisplayName);
+ String shortId = createIdentifier();
+ String displayName = "TestOrgAuth-" + shortId;
+ String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrgAuthorityInstance(
- displayName, knownResourceRefName, orgAuthClient.getCommonPartName());
+ displayName, shortId, orgAuthClient.getCommonPartName());
// Submit the request to the service and store the response.
ClientResponse<Response> res = orgAuthClient.create(multipart);
try {
- int statusCode = res.getStatus();
- // Check the status code of the response: does it match
- // the expected response(s)?
- //
- // Specifically:
- // Does it fall within the set of valid status codes?
- // Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-
- // Store the IDs from every resource created by tests,
- // so they can be deleted after tests have been run.
- knownAuthResourceId = extractId(res);
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ //
+ // Specifically:
+ // Does it fall within the set of valid status codes?
+ // Does it exactly match the expected status code?
+ if(logger.isDebugEnabled()){
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+ // Store the IDs from every resource created by tests,
+ // so they can be deleted after tests have been run.
+ String newId = extractId(res);
+ if (knownResourceId == null){
+ setKnownResource( newId, baseRefName );
+ }
+ allResourceIdsCreated.add(newId);
} finally {
res.releaseConnection();
}
- allResourceIdsCreated.add(knownAuthResourceId);
// Create all the person refs and entities
createPersonRefs();
// contain references to Persons, via their refNames, as
// per the initialization(s) below.
Map<String, String> testOrgMap = new HashMap<String,String>();
+ testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME,
- "Test Organization-" + identifier);
+ "Test Organization-" + shortId);
testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Test Organization Name");
testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Anytown, USA");
testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, organizationContactPersonRefName);
// Finishing creating the new Organization item, then
// submit the request to the service and store the response.
- knownItemId = OrgAuthorityClientUtils.createItemInAuthority(
- knownAuthResourceId, knownResourceRefName, testOrgMap, orgAuthClient);
+ knownItemResourceId = OrgAuthorityClientUtils.createItemInAuthority(
+ knownResourceId, knownResourceRefName, testOrgMap, orgAuthClient);
// Store the IDs from every item created by tests,
// so they can be deleted after tests have been run.
- allItemResourceIdsCreated.put(knownItemId, knownAuthResourceId);
+ allItemResourceIdsCreated.put(knownItemResourceId, knownResourceId);
}
/**
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
// Create a temporary PersonAuthority resource, and its corresponding
// refName by which it can be identified.
- String personAuthRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- PERSON_AUTHORITY_NAME, personAuthRefName, personAuthClient.getCommonPartName());
+ PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName());
ClientResponse<Response> res = personAuthClient.create(multipart);
try {
res.releaseConnection();
}
- // Create a temporary Person resource, and its corresponding refName
- // by which it can be identified.
- organizationContactPersonRefName =
- PersonAuthorityClientUtils.createPersonRefName(personAuthRefName, "Charlie Orgcontact", true);
- personIdsCreated.add(createPerson("Charlie", "Orgcontact", organizationContactPersonRefName));
-
+ String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null);
+
+ // Create temporary Person resources, and their corresponding refNames
+ // by which they can be identified.
+ String csid = createPerson("Charlie", "Orgcontact", "charlieOrgcontact", authRefName);
+ personIdsCreated.add(csid);
+ organizationContactPersonRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null);
}
/**
*
* @param firstName the first name
* @param surName the sur name
- * @param refName the ref name
+ * @param shortId
+ * @param authRefName
* @return the string
*/
- protected String createPerson(String firstName, String surName, String refName ) {
+ protected String createPerson(String firstName, String surName, String shortId, String authRefName ) {
PersonAuthorityClient personAuthClient = new PersonAuthorityClient();
Map<String, String> personInfo = new HashMap<String,String>();
personInfo.put(PersonJAXBSchema.FORE_NAME, firstName);
personInfo.put(PersonJAXBSchema.SUR_NAME, surName);
+ personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(personAuthCSID,
- refName, personInfo, personAuthClient.getItemCommonPartName());
+ authRefName, personInfo, personAuthClient.getItemCommonPartName());
String result = null;
ClientResponse<Response> res = personAuthClient.createItem(personAuthCSID, multipart);
// This sub-body Organization resource will be created in the same
// Organization authority as its parent Organization resource.
- String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization", subBodyRefName);
- allItemResourceIdsCreated.put(subBodyResourceId, knownAuthResourceId);
+ String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization");
+ allItemResourceIdsCreated.put(subBodyResourceId, knownResourceId);
+ subBodyRefName = OrgAuthorityClientUtils.getOrgRefName(knownResourceId, subBodyResourceId, null);
}
- protected String createSubBodyOrganization(String subBodyName, String refName) {
+ protected String createSubBodyOrganization(String subBodyName) {
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();
Map<String, String> subBodyOrgMap = new HashMap<String,String>();
+ String shortId = createIdentifier();
+ subBodyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId );
subBodyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME,
- subBodyName + "-" + createIdentifier());
+ subBodyName + "-" + shortId);
subBodyOrgMap.put(OrganizationJAXBSchema.LONG_NAME, subBodyName + " Long Name");
subBodyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, subBodyName + " Founding Place");
- String subBodyDisplayName = OrgAuthorityClientUtils.createDisplayName(subBodyOrgMap);
- subBodyRefName =
- OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, subBodyDisplayName, true);
MultipartOutput multipart =
- OrgAuthorityClientUtils.createOrganizationInstance(knownAuthResourceId,
- subBodyRefName, subBodyOrgMap, orgAuthClient.getItemCommonPartName());
+ OrgAuthorityClientUtils.createOrganizationInstance(knownResourceId,
+ knownResourceRefName, subBodyOrgMap, orgAuthClient.getItemCommonPartName());
String result = null;
- ClientResponse<Response> res = orgAuthClient.createItem(knownAuthResourceId, multipart);
+ ClientResponse<Response> res = orgAuthClient.createItem(knownResourceId, multipart);
try {
int statusCode = res.getStatus();
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Submit the request to the service and store the response.
OrgAuthorityClient orgAuthClient = new OrgAuthorityClient();
ClientResponse<MultipartInput> res =
- orgAuthClient.readItem(knownAuthResourceId, knownItemId);
+ orgAuthClient.readItem(knownResourceId, knownItemResourceId);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// FIXME - need to create this method in the client
// and get the ID for the organization item
ClientResponse<AuthorityRefList> res2 =
- orgAuthClient.getItemAuthorityRefs(knownAuthResourceId, knownItemId);
+ orgAuthClient.getItemAuthorityRefs(knownResourceId, knownItemResourceId);
statusCode = res2.getStatus();
if(logger.isDebugEnabled()){
}
// Delete PersonAuthority resource(s).
// Note: Any non-success response is ignored and not reported.
- personAuthClient.delete(personAuthCSID).releaseConnection();
+ if(personAuthCSID!=null) {
+ personAuthClient.delete(personAuthCSID).releaseConnection();
+ }
String parentResourceId;
String itemResourceId;
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
-
- /**
- * Creates the org authority instance.
- *
- * @param identifier the identifier
- * @return the multipart output
- */
- private MultipartOutput createOrgAuthorityInstance(String identifier) {
- String displayName = "displayName-" + identifier;
- String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
- return OrgAuthorityClientUtils.createOrgAuthorityInstance(
- displayName, refName,
- new OrgAuthorityClient().getCommonPartName());
- }
-
}
/** The test organization founding place. */
private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
- /** The known resource id. */
+ // Hold some values for a recently created item to verify upon read.
private String knownResourceId = null;
-
- /** The known resource display name. */
- private String knownResourceDisplayName = null;
-
- /** The known resource ref name. */
+ private String knownResourceShortIdentifer = null;
private String knownResourceRefName = null;
-
- /** The known item resource id. */
private String knownItemResourceId = null;
+ private String knownItemResourceShortIdentifer = null;
/** The known contact resource id. */
private String knownContactResourceId = null;
private Map<String, String> allContactResourceIdsCreated =
new HashMap<String, String>();
+ protected void setKnownResource( String id, String shortIdentifer,
+ String refName ) {
+ knownResourceId = id;
+ knownResourceShortIdentifer = shortIdentifer;
+ knownResourceRefName = refName;
+ }
+
+ protected void setKnownItemResource( String id, String shortIdentifer ) {
+ knownItemResourceId = id;
+ knownItemResourceShortIdentifer = shortIdentifer;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
- String identifier = createIdentifier();
- String displayName = "displayName-" + identifier;
- String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
+ String shortId = createIdentifier();
+ String displayName = "displayName-" + shortId;
+ String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrgAuthorityInstance(
- displayName, refName, client.getCommonPartName());
+ displayName, shortId, client.getCommonPartName());
String newID = null;
ClientResponse<Response> res = client.create(multipart);
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- // Store the refname from the first resource created
- // for additional tests below.
- knownResourceRefName = refName;
-
newID = OrgAuthorityClientUtils.extractId(res);
} finally {
res.releaseConnection();
// Store the ID returned from the first resource created
// for additional tests below.
if (knownResourceId == null){
- knownResourceId = newID;
- knownResourceDisplayName = displayName;
+ setKnownResource( newID, shortId, baseRefName );
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
- String identifier = createIdentifier();
- String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
+ String shortId = "testOrg";
Map<String, String> testOrgMap = new HashMap<String,String>();
+ testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
// Store the ID returned from the first item resource created
// for additional tests below.
if (knownItemResourceId == null){
- knownItemResourceId = newID;
+ setKnownItemResource(newID, shortId);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
}
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
public void read(String testName) throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName, CLASS_NAME));
- }
- // Perform setup.
- setupRead();
-
- // Submit the request to the service and store the response.
- OrgAuthorityClient client = new OrgAuthorityClient();
- ClientResponse<MultipartInput> res = client.read(knownResourceId);
- try {
- int statusCode = res.getStatus();
-
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- MultipartInput input = (MultipartInput) res.getEntity();
- OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), OrgauthoritiesCommon.class);
- Assert.assertNotNull(orgAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- } finally {
- res.releaseConnection();
- }
+ readInternal(testName, knownResourceId, null);
}
/**
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
public void readByName(String testName) throws Exception {
+ readInternal(testName, null, knownResourceShortIdentifer);
+ }
+
+ protected void readInternal(String testName, String CSID, String shortId) {
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
- ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
+ ClientResponse<MultipartInput> res = null;
+ if(CSID!=null) {
+ res = client.read(CSID);
+ } else if(shortId!=null) {
+ res = client.readByName(shortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
try {
int statusCode = res.getStatus();
}
}
-/*
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- groups = {"read"}, dependsOnMethods = {"read"})
- public void readByName(String testName) throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName, CLASS_NAME));
- }
- // Perform setup.
- setupRead();
+ /**
+ * Read item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readItem(String testName) throws Exception {
+ readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
+ }
- // Submit the request to the service and store the response.
- ClientResponse<MultipartInput> res = client.read(knownResourceId);
- int statusCode = res.getStatus();
+ /**
+ * Read item in Named Auth.
+ *
+ * TODO Enable this if we really need this - it is a funky case, where we would have
+ * the shortId of the item, but the CSID of the parent authority!? Unlikely.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readItemInNamedAuth(String testName) throws Exception {
+ readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
+ }
+ */
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- MultipartInput input = (MultipartInput) res.getEntity();
- OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), OrgauthoritiesCommon.class);
- Assert.assertNotNull(orgAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ /**
+ * Read named item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readNamedItem(String testName) throws Exception {
+ readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
}
-*/
/**
- * Read item.
- *
- * @param testName the test name
- * @throws Exception the exception
- */
-@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"read"})
- public void readItem(String testName) throws Exception {
+ * Read Named item in Named Auth.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readNamedItemInNamedAuth(String testName) throws Exception {
+ readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
+ }
+
+ protected void readItemInternal(String testName,
+ String authCSID, String authShortId, String itemCSID, String itemShortId)
+ throws Exception {
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
// Submit the request to the service and store the response.
OrgAuthorityClient client = new OrgAuthorityClient();
- ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
+ ClientResponse<MultipartInput> res = null;
+ if(authCSID!=null) {
+ if(itemCSID!=null) {
+ res = client.readItem(authCSID, itemCSID);
+ } else if(itemShortId!=null) {
+ res = client.readNamedItem(authCSID, itemShortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
+ } else if(authShortId!=null) {
+ if(itemCSID!=null) {
+ res = client.readItemInNamedAuthority(authShortId, itemCSID);
+ } else if(itemShortId!=null) {
+ res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
+ } else {
+ Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
+ }
try {
int statusCode = res.getStatus();
boolean showFull = true;
if(showFull && logger.isDebugEnabled()){
logger.debug(testName + ": returned payload:");
- logger.debug(objectAsXmlString(organization,
- OrganizationsCommon.class));
+ logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
}
Assert.assertEquals(organization.getInAuthority(), knownResourceId);
} finally {
* @throws Exception the exception
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readItem"})
+ groups = {"readItem"}, dependsOnMethods = {"readItem"})
public void readContact(String testName) throws Exception {
if (logger.isDebugEnabled()) {
* @param testName the test name
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readItem"})
+ groups = {"readItem"}, dependsOnMethods = {"readItem"})
public void readItemNonExistent(String testName) {
if (logger.isDebugEnabled()) {
* @param testName the test name
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readContact"})
+ groups = {"readItem"}, dependsOnMethods = {"readContact"})
public void readContactNonExistent(String testName) {
if (logger.isDebugEnabled()) {
*/
@Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
public void readItemListByAuthorityName() {
- readItemList(null, knownResourceDisplayName);
+ readItemList(null, knownResourceShortIdentifer);
}
/**
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in update(), below.
OrgAuthorityClient client = new OrgAuthorityClient();
- MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
+ MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
+ NON_EXISTENT_ID, NON_EXISTENT_ID,
+ new OrgAuthorityClient().getCommonPartName());
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
int statusCode = res.getStatus();
// The only relevant ID may be the one used in update(), below.
OrgAuthorityClient client = new OrgAuthorityClient();
Map<String, String> nonexOrgMap = new HashMap<String,String>();
+ nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
- String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
MultipartOutput multipart =
OrgAuthorityClientUtils.createOrganizationInstance(
- NON_EXISTENT_ID, refName,
+ NON_EXISTENT_ID, knownResourceRefName,
nonexOrgMap, client.getItemCommonPartName() );
ClientResponse<MultipartInput> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
return getContactServiceRootURL(parentResourceIdentifier,
itemResourceIdentifier) + "/" + contactResourceIdentifier;
}
-
- /**
- * Creates the org authority instance.
- *
- * @param identifier the identifier
- * @return the multipart output
- */
- private MultipartOutput createOrgAuthorityInstance(String identifier) {
- String displayName = "displayName-" + identifier;
- String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
- return OrgAuthorityClientUtils.createOrgAuthorityInstance(
- displayName, refName,
- new OrgAuthorityClient().getCommonPartName());
- }
}
final String SERVICE_PATH_COMPONENT = "orgauthorities";
final String ITEM_SERVICE_PATH_COMPONENT = "items";
- public void createOrgAuthority(String orgAuthorityName,
+ public void createOrgAuthority(String orgAuthorityDisplayName, String orgAuthorityShortId,
List<Map<String,String>> orgInfos ) {
// Expected status code: 201 Created
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
if(logger.isDebugEnabled()){
- logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\"");
+ logger.debug("Import: Create orgAuthority: \"" + orgAuthorityShortId +"\"");
}
- String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, false);
- String fullOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, true);
+ String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityShortId, null);
MultipartOutput multipart =
- OrgAuthorityClientUtils.createOrgAuthorityInstance(
- orgAuthorityName, fullOrgAuthRefName,
- client.getCommonPartName());
+ OrgAuthorityClientUtils.createOrgAuthorityInstance(
+ orgAuthorityDisplayName, orgAuthorityShortId, client.getCommonPartName());
ClientResponse<Response> res = client.create(multipart);
int statusCode = res.getStatus();
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName
+ throw new RuntimeException("Could not create enumeration: \""+orgAuthorityShortId
+"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
}
if(statusCode != EXPECTED_STATUS_CODE) {
throw new RuntimeException("Unexpected Status when creating enumeration: \""
- +orgAuthorityName +"\", Status:"+ statusCode);
+ +orgAuthorityShortId +"\", Status:"+ statusCode);
}
// Store the ID returned from this create operation
// for additional tests below.
String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res);
if(logger.isDebugEnabled()){
- logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:"
+ logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityShortId +"\" ID:"
+newOrgAuthorityId );
}
for(Map<String,String> orgInfo : orgInfos){
OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport();
final String demoOrgAuthorityName = "Demo Org Authority";
+ final String demoOrgAuthorityShortId = "demoOrgAuth";
Map<String, String> mmiOrgMap = new HashMap<String,String>();
+ mmiOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "mmi");
mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI");
mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image");
mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes");
mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984");
mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY");
Map<String, String> pahmaOrgMap = new HashMap<String,String>();
+ pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "pahma");
pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA");
pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology");
pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley");
pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901");
pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA");
Map<String, String> savoyOrgMap = new HashMap<String,String>();
+ savoyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "savoyTh");
savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre");
savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900");
savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952");
List<Map<String, String>> orgMaps =
Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap );
- oabi.createOrgAuthority(demoOrgAuthorityName, orgMaps);
+ oabi.createOrgAuthority(demoOrgAuthorityName, demoOrgAuthorityShortId, orgMaps);
logger.info("OrgAuthorityBaseImport complete.");
}
public interface OrgAuthorityJAXBSchema {\r
final static String ORGAUTHORITIES_COMMON = "orgauthorities_common";\r
final static String DISPLAY_NAME = "displayName";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String REF_NAME = "refName";\r
final static String VOCAB_TYPE = "vocabType";\r
final static String CSID = "csid";\r
final static String CSID = "csid";\r
final static String IN_AUTHORITY = "inAuthority";\r
final static String REF_NAME = "refName";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String DISPLAY_NAME = "displayName";\r
final static String DISPLAY_NAME_COMPUTED = "displayNameComputed";\r
final static String SHORT_NAME = "shortName";\r
<xs:element name="csid" type="xs:string" />
<!-- Organization Information Group -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
<xs:element name="csid" type="xs:string" />
<!-- OrgAuthority Information Group -->
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
}
String whereClause =
OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
- ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
+ ":"+OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+
"='"+specifier+"'";
// We only get a single doc - if there are multiple,
// it is an error in use.
return result;
}
+ /**
+ * Gets the person by name.
+ *
+ * @param parentcsid the parentcsid
+ * @param itemspecifier the shrotId of the person
+ *
+ * @return the person
+ */
+ @GET
+ @Path("{csid}/items/urn:cspace:name({itemspecifier})")
+ public MultipartOutput getOrganizationByName(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemspecifier") String itemspecifier) {
+ if (parentcsid == null || "".equals(parentcsid)
+ || itemspecifier == null || "".equals(itemspecifier)) {
+ logger.error("getOrganizationByName: missing parentcsid or itemspecifier!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Organization with parentcsid="
+ + parentcsid + " and itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ String whereClause =
+ OrganizationJAXBSchema.ORGANIZATIONS_COMMON+
+ ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+
+ "='"+itemspecifier+"'";
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganizationByName with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).get(ctx, handler);
+ // TODO should we assert that the item is in the passed personAuthority?
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganization", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on Organization itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganizationByName", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Organization itemspecifier:" + itemspecifier + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
+
+ /**
+ * Gets the person by name, in a named authority.
+ *
+ * @param parentspecifier the shortId of the parent
+ * @param itemspecifier the shortId of the person
+ *
+ * @return the person
+ */
+ @GET
+ @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})")
+ public MultipartOutput getOrganizationByNameInNamedAuthority(
+ @PathParam("parentspecifier") String parentspecifier,
+ @PathParam("itemspecifier") String itemspecifier) {
+ if (parentspecifier == null || "".equals(parentspecifier)
+ || itemspecifier == null || "".equals(itemspecifier)) {
+ logger.error("getOrganizationByNameInNamedAuthority: missing parentcsid or itemspecifier!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Organization with parentspecifier="
+ + parentspecifier + " and itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ String whereClause =
+ OrganizationJAXBSchema.ORGANIZATIONS_COMMON+
+ ":"+OrganizationJAXBSchema.SHORT_IDENTIFIER+
+ "='"+itemspecifier+"'";
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganizationByNameInNamedAuthority with parentspecifier="
+ + parentspecifier + " and itemspecifier=" + itemspecifier);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
+ // HACK HACK Since we do not use the parent CSID yet this should work.
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier);
+ DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).get(ctx, handler);
+ // TODO should we assert that the item is in the passed personAuthority?
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganizationByNameInNamedAuthority", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on Person itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getOrganizationByNameInNamedAuthority", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
+
/**
* Gets the authority refs for an Organization item.
* @param parentcsid
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String whereClause =
OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
- ":" + OrgAuthorityJAXBSchema.DISPLAY_NAME+
+ ":" + OrgAuthorityJAXBSchema.SHORT_IDENTIFIER+
"='" + parentSpecifier+"'";
// Need to get an Authority by name
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
-
- ctx = createServiceContext(getItemServiceName(), queryParams);
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- DocumentFilter myFilter = handler.getDocumentFilter();// new DocumentFilter();
-
- // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'"
- myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
- OrganizationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
-
- // AND organizations_common:displayName LIKE '%partialTerm%'
- if (partialTerm != null && !partialTerm.isEmpty()) {
- String ptClause = OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
- OrganizationJAXBSchema.DISPLAY_NAME +
- " LIKE " +
- "'%" + partialTerm + "%'";
- myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
- }
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- personObjectList = (OrganizationsCommonList) handler.getCommonPartList();
+ return getOrganizationList(parentcsid, partialTerm, ui);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
throw new WebApplicationException(response);
}
- return personObjectList;
}
/**
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *//**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.organization.nuxeo;
+
+import java.util.regex.Pattern;
+
+import org.collectionspace.services.organization.OrgauthoritiesCommon;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.document.InvalidDocumentException;
+import org.collectionspace.services.common.document.ValidatorHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class OrgAuthorityValidatorHandler implements ValidatorHandler {
+
+ final Logger logger = LoggerFactory.getLogger(OrgAuthorityValidatorHandler.class);
+ private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
+
+ @Override
+ public void validate(Action action, ServiceContext ctx)
+ throws InvalidDocumentException {
+ if(logger.isDebugEnabled()) {
+ logger.debug("validate() action=" + action.name());
+ }
+ try {
+ MultipartServiceContext mctx = (MultipartServiceContext) ctx;
+ OrgauthoritiesCommon organizationAuth =
+ (OrgauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+ OrgauthoritiesCommon.class);
+ String msg = "";
+ boolean invalid = false;
+ String shortId = organizationAuth.getShortIdentifier();
+ if(shortId==null){
+ invalid = true;
+ msg += "shortIdentifier must be non-null";
+ } else if(shortIdBadPattern.matcher(shortId).find()) {
+ invalid = true;
+ msg += "shortIdentifier must only contain standard word characters";
+ }
+ /*
+ if(action.equals(Action.CREATE)) {
+ //create specific validation here
+ } else if(action.equals(Action.UPDATE)) {
+ //update specific validation here
+ }
+ */
+
+ if (invalid) {
+ logger.error(msg);
+ throw new InvalidDocumentException(msg);
+ }
+ } catch (InvalidDocumentException ide) {
+ throw ide;
+ } catch (Exception e) {
+ throw new InvalidDocumentException(e);
+ }
+ }
+}
import org.collectionspace.services.common.document.ValidatorHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.regex.Pattern;
/**
*
public class OrganizationValidatorHandler implements ValidatorHandler {
final Logger logger = LoggerFactory.getLogger(OrganizationValidatorHandler.class);
+ private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
@Override
public void validate(Action action, ServiceContext ctx)
if(!org.isDisplayNameComputed() && (org.getDisplayName()==null)) {
invalid = true;
msg += "displayName must be non-null if displayNameComputed is false!";
+ }
+ String shortId = org.getShortIdentifier();
+ if(shortId==null){
+ invalid = true;
+ msg += "shortIdentifier must be non-null";
+ } else if(shortIdBadPattern.matcher(shortId).find()) {
+ invalid = true;
+ msg += "shortIdentifier must only contain standard word characters";
}
/*
if(action.equals(Action.CREATE)) {
</templates>
<rows>
<row><widget>displayName</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>refName</widget></row>
<row><widget>vocabType</widget></row>
</rows>
</properties>
</widget>
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="personauthorities_common">shortIdentifier</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
<widget name="refName" type="text">
<labels>
<label mode="any">RefName</label>
</templates>
<rows>
<row><widget>displayName</widget></row>
+ <row><widget>shortIdentifier</widget></row>
<row><widget>refName</widget></row>
<row><widget>inAuthority</widget></row>
<row><widget>foreName</widget></row>
</labels>
<translated>true</translated>
<fields>
- <field schema="personauthorities_common">displayName</field>
+ <field schema="persons_common">displayName</field>
+ </fields>
+ <properties widgetMode="edit">
+ <property name="styleClass">dataInputText</property>
+ </properties>
+ </widget>
+
+ <widget name="shortIdentifier" type="text">
+ <labels>
+ <label mode="any">Short Identifier</label>
+ </labels>
+ <translated>true</translated>
+ <fields>
+ <field schema="persons_common">shortIdentifier</field>
</fields>
<properties widgetMode="edit">
<property name="styleClass">dataInputText</property>
<!-- PersonAuthority Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
<!-- Person Information Group -->
<!-- inAuthority is the csid of the owning PersonAuthority -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
return personAuthorityProxy.delete(csid);
}
+ /**
+ * Gets the referencing objects.
+ *
+ * @param parentcsid the parentcsid
+ * @param csid the csid
+ * @return the referencing objects
+ */
+ public ClientResponse<AuthorityRefDocList> getReferencingObjects(String parentcsid, String csid) {
+ return personAuthorityProxy.getReferencingObjects(parentcsid, csid);
+ }
+
/**
* Read item list.
*
return personAuthorityProxy.readItemList(vcsid, partialTerm);
}
- /**
- * Gets the referencing objects.
- *
- * @param parentcsid the parentcsid
- * @param csid the csid
- * @return the referencing objects
- */
- public ClientResponse<AuthorityRefDocList> getReferencingObjects(String parentcsid, String csid) {
- return personAuthorityProxy.getReferencingObjects(parentcsid, csid);
- }
-
/**
* Read item list for named authority.
*
return personAuthorityProxy.readItem(vcsid, csid);
}
+ /**
+ * Read named item.
+ *
+ * @param vcsid the vcsid
+ * @param shortId the shortIdentifier
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readNamedItem(String vcsid, String shortId) {
+ return personAuthorityProxy.readNamedItem(vcsid, shortId);
+ }
+
+ /**
+ * Read item in Named Authority.
+ *
+ * @param authShortId the shortIdentifier for the Authority
+ * @param csid the csid
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readItemInNamedAuthority(String authShortId, String csid) {
+ return personAuthorityProxy.readItemInNamedAuthority(authShortId, csid);
+ }
+
+ /**
+ * Read named item in Named Authority.
+ *
+ * @param authShortId the shortIdentifier for the Authority
+ * @param itemShortId the shortIdentifier for the item
+ * @return the client response
+ */
+ public ClientResponse<MultipartInput> readNamedItemInNamedAuthority(String authShortId, String itemShortId) {
+ return personAuthorityProxy.readNamedItem(authShortId, itemShortId);
+ }
+
/**
* Creates the item.
*
import org.collectionspace.services.person.PersonsCommon;\r
import org.collectionspace.services.person.PersonauthoritiesCommon;\r
import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
import org.slf4j.Logger;\r
/** The Constant logger. */\r
private static final Logger logger =\r
LoggerFactory.getLogger(PersonAuthorityClientUtils.class);\r
+ private static final ServiceRequestType READ_REQ = ServiceRequestType.READ;\r
+\r
+ /**\r
+ * @param csid the id of the PersonAuthority\r
+ * @param client if null, creates a new client\r
+ * @return\r
+ */\r
+ public static String getAuthorityRefName(String csid, PersonAuthorityClient client){\r
+ if(client==null)\r
+ client = new PersonAuthorityClient();\r
+ ClientResponse<MultipartInput> res = client.read(csid);\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ if(!READ_REQ.isValidStatusCode(statusCode)\r
+ ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+ throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+ }\r
+ //FIXME: remove the following try catch once Aron fixes signatures\r
+ try {\r
+ MultipartInput input = (MultipartInput) res.getEntity();\r
+ PersonauthoritiesCommon personAuthority = \r
+ (PersonauthoritiesCommon) CollectionSpaceClientUtils.extractPart(input,\r
+ client.getCommonPartName(), PersonauthoritiesCommon.class);\r
+ if(personAuthority==null) {\r
+ throw new RuntimeException("Null personAuthority returned from service.");\r
+ }\r
+ return personAuthority.getRefName();\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ } finally {\r
+ res.releaseConnection();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @param csid the id of the PersonAuthority\r
+ * @param client if null, creates a new client\r
+ * @return\r
+ */\r
+ public static String getPersonRefName(String inAuthority, String csid, PersonAuthorityClient client){\r
+ if(client==null)\r
+ client = new PersonAuthorityClient();\r
+ ClientResponse<MultipartInput> res = client.readItem(inAuthority, csid);\r
+ try {\r
+ int statusCode = res.getStatus();\r
+ if(!READ_REQ.isValidStatusCode(statusCode)\r
+ ||(statusCode != CollectionSpaceClientUtils.STATUS_OK)) {\r
+ throw new RuntimeException("Invalid status code returned: "+statusCode);\r
+ }\r
+ //FIXME: remove the following try catch once Aron fixes signatures\r
+ try {\r
+ MultipartInput input = (MultipartInput) res.getEntity();\r
+ PersonsCommon person = \r
+ (PersonsCommon) CollectionSpaceClientUtils.extractPart(input,\r
+ client.getItemCommonPartName(), PersonsCommon.class);\r
+ if(person==null) {\r
+ throw new RuntimeException("Null person returned from service.");\r
+ }\r
+ return person.getRefName();\r
+ } catch (Exception e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ } finally {\r
+ res.releaseConnection();\r
+ }\r
+ }\r
\r
/**\r
* Creates the person authority instance.\r
*\r
* @param displayName the display name\r
- * @param refName the ref name\r
+ * @param shortIdentifier the short Id \r
* @param headerLabel the header label\r
* @return the multipart output\r
*/\r
public static MultipartOutput createPersonAuthorityInstance(\r
- String displayName, String refName, String headerLabel ) {\r
+ String displayName, String shortIdentifier, String headerLabel ) {\r
PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
personAuthority.setDisplayName(displayName);\r
+ personAuthority.setShortIdentifier(shortIdentifier);\r
+ String refName = createPersonAuthRefName(shortIdentifier, displayName);\r
personAuthority.setRefName(refName);\r
personAuthority.setVocabType("PersonAuthority");\r
MultipartOutput multipart = new MultipartOutput();\r
/**\r
* Creates the person instance.\r
*\r
- * @param inAuthority the in authority\r
- * @param personRefName the person ref name\r
+ * @param inAuthority the owning authority\r
+ * @param personAuthRefName the owning Authority ref name\r
* @param personInfo the person info\r
* @param headerLabel the header label\r
* @return the multipart output\r
*/\r
public static MultipartOutput createPersonInstance(String inAuthority, \r
- String personRefName, Map<String, String> personInfo, String headerLabel){\r
+ String personAuthRefName, Map<String, String> personInfo, String headerLabel){\r
PersonsCommon person = new PersonsCommon();\r
person.setInAuthority(inAuthority);\r
- person.setRefName(personRefName);\r
+ String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER);\r
+ if (shortId == null || shortId.isEmpty()) {\r
+ throw new IllegalArgumentException("shortIdentifier cannot be null or empty");\r
+ } \r
+ person.setShortIdentifier(shortId);\r
\r
//\r
// If the 'DISPLAY_NAME_COMPUTED' property is null or empty then\r
if (displayNameComputed == false && displayName == null) {\r
throw new IllegalArgumentException("displayName cannot be null when displayComputed is 'false'");\r
} \r
+ String refName = createPersonRefName(personAuthRefName, shortId, displayName);\r
+ person.setRefName(refName);\r
\r
String value;\r
if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) //FIXME: REM - I don't think we need to check for null -null is a valid value and won't cause any problems. \r
*\r
* @param vcsid the vcsid\r
* @param personAuthorityRefName the person authority ref name\r
- * @param personMap the person map\r
+ * @param personMap the person map. PersonJAXBSchema.SHORT_IDENTIFIER is REQUIRED.\r
* @param client the client\r
* @return the string\r
*/\r
personMap.get(PersonJAXBSchema.SUR_NAME),\r
personMap.get(PersonJAXBSchema.BIRTH_DATE),\r
personMap.get(PersonJAXBSchema.DEATH_DATE));\r
+ personMap.put(PersonJAXBSchema.DISPLAY_NAME, displayName);\r
}\r
\r
- String refName = createPersonRefName(personAuthorityRefName, displayName, true);\r
-\r
if(logger.isDebugEnabled()){\r
logger.debug("Import: Create Item: \"" + displayName\r
+"\" in personAuthorityulary: \"" + personAuthorityRefName +"\"");\r
}\r
MultipartOutput multipart = \r
- createPersonInstance(vcsid, refName,\r
+ createPersonInstance(vcsid, personAuthorityRefName,\r
personMap, client.getItemCommonPartName());\r
\r
String result = null;\r
int statusCode = res.getStatus();\r
\r
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
- throw new RuntimeException("Could not create Item: \""+refName\r
+ throw new RuntimeException("Could not create Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in personAuthority: \"" + personAuthorityRefName\r
+"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
}\r
if(statusCode != EXPECTED_STATUS_CODE) {\r
- throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+personMap.get(PersonJAXBSchema.SHORT_IDENTIFIER)\r
+"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
}\r
\r
}\r
\r
/**\r
- * Creates the person auth ref name.\r
+ * Creates the personAuthority ref name.\r
*\r
- * @param personAuthorityName the person authority name\r
- * @param withDisplaySuffix the with display suffix\r
+ * @param shortId the personAuthority shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
* @return the string\r
*/\r
- public static String createPersonAuthRefName(String personAuthorityName, boolean withDisplaySuffix) {\r
+ public static String createPersonAuthRefName(String shortId, String displaySuffix) {\r
String refName = "urn:cspace:org.collectionspace.demo:personauthority:name("\r
- +personAuthorityName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+personAuthorityName+"'";\r
+ +shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
* Creates the person ref name.\r
*\r
* @param personAuthRefName the person auth ref name\r
- * @param personName the person name\r
- * @param withDisplaySuffix the with display suffix\r
+ * @param shortId the person shortIdentifier\r
+ * @param displaySuffix displayName to be appended, if non-null\r
* @return the string\r
*/\r
public static String createPersonRefName(\r
- String personAuthRefName, String personName, boolean withDisplaySuffix) {\r
- String refName = personAuthRefName+":person:name("+personName+")";\r
- if(withDisplaySuffix)\r
- refName += "'"+personName+"'";\r
+ String personAuthRefName, String shortId, String displaySuffix) {\r
+ String refName = personAuthRefName+":person:name("+shortId+")";\r
+ if(displaySuffix!=null&&!displaySuffix.isEmpty())\r
+ refName += "'"+displaySuffix+"'";\r
return refName;\r
}\r
\r
@GET
@Produces({"application/xml"})
@Path("/urn:cspace:name({specifier})/items/")
- ClientResponse<PersonsCommonList> readItemListForNamedAuthority(@PathParam("specifier") String specifier);
+ ClientResponse<PersonsCommonList> readItemListForNamedAuthority(
+ @PathParam("specifier") String specifier);
+
+ // List Items for a named authority matching a partial term.
+ @GET
+ @Produces({"application/xml"})
+ @Path("/urn:cspace:name({specifier})/items/")
+ ClientResponse<PersonsCommonList> readItemListForNamedAuthority(
+ @PathParam("specifier") String specifier,
+ @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm);
//(C)reate Item
@POST
@Path("/{vcsid}/items/{csid}")
ClientResponse<MultipartInput> readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid);
+ //(R)ead Named Item
+ @GET
+ @Path("/{vcsid}/items/urn:cspace:name({specifier})")
+ ClientResponse<MultipartInput> readNamedItem(@PathParam("vcsid") String vcsid, @PathParam("specifier") String specifier);
+
+ //(R)ead Item In Named Authority
+ @GET
+ @Path("/urn:cspace:name({specifier})/items/{csid}")
+ ClientResponse<MultipartInput> readItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("csid") String csid);
+
+ //(R)ead Named Item In Named Authority
+ @GET
+ @Path("/urn:cspace:name({specifier})/items/urn:cspace:name({itemspecifier})")
+ ClientResponse<MultipartInput> readNamedItemInNamedAuthority(@PathParam("specifier") String specifier, @PathParam("itemspecifier") String itemspecifier);
+
//(U)pdate Item
@PUT
@Path("/{vcsid}/items/{csid}")
// Displayname
final String TEST_PARTIAL_TERM_DISPLAY_NAME =
TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME;
+ //
+ // shortId
+ final String TEST_SHORT_ID = "lechWalesa";
// Non-existent partial term name (first letters of each of the words
// in a pangram for the English alphabet).
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- String identifier = createIdentifier();
- String displayName = "displayName-" + identifier;
- String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
- String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
+ String shortId = createIdentifier();
+ String displayName = "displayName-" + shortId;
+ String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonAuthorityInstance(
- displayName, fullRefName, client.getCommonPartName());
+ displayName, shortId, client.getCommonPartName());
String newID = null;
ClientResponse<Response> res = client.create(multipart);
* @param authorityCsid The CSID of the Authority in which the term will be created.
* @param authRefName The refName of the Authority in which the term will be created.
*/
- private void createItemInAuthorityForPartialTermMatch(String authorityCsid, String authRefName)
+ private void createItemInAuthorityForPartialTermMatch(
+ String authorityCsid, String authRefName)
throws Exception {
String testName = "createItemInAuthorityForPartialTermMatch";
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName,
- TEST_PARTIAL_TERM_DISPLAY_NAME, true);
Map<String, String> partialTermPersonMap = new HashMap<String,String>();
//
// Fill the property map
//
+ partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID );
partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
MultipartOutput multipart =
- PersonAuthorityClientUtils.createPersonInstance(authorityCsid, refName, partialTermPersonMap,
+ PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, partialTermPersonMap,
client.getItemCommonPartName() );
String newID = null;
/** The test death date. */
final String TEST_DEATH_DATE = "June 11, 1979";
-
- /** The known resource id. */
+
+ // Hold some values for a recently created item to verify upon read.
private String knownResourceId = null;
-
- /** The known resource display name. */
- private String knownResourceDisplayName = null;
-
- /** The known resource ref name. */
+ private String knownResourceShortIdentifer = null;
private String knownResourceRefName = null;
-
- /** The known item resource id. */
private String knownItemResourceId = null;
+ private String knownItemResourceShortIdentifer = null;
// The resource ID of an item resource used for partial term matching tests.
private String knownItemPartialTermResourceId = null;
private Map<String, String> allContactResourceIdsCreated =
new HashMap<String, String>();
+ protected void setKnownResource( String id, String shortIdentifer,
+ String refName ) {
+ knownResourceId = id;
+ knownResourceShortIdentifer = shortIdentifer;
+ knownResourceRefName = refName;
+ }
+
+ protected void setKnownItemResource( String id, String shortIdentifer ) {
+ knownItemResourceId = id;
+ knownItemResourceShortIdentifer = shortIdentifer;
+ }
+
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
*/
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- String identifier = createIdentifier();
- String displayName = "displayName-" + identifier;
- String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
- String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
+ String shortId = createIdentifier();
+ String displayName = "displayName-" + shortId;
+ String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonAuthorityInstance(
- displayName, fullRefName, client.getCommonPartName());
+ displayName, shortId, client.getCommonPartName());
String newID = null;
ClientResponse<Response> res = client.create(multipart);
} finally {
res.releaseConnection();
}
- // Store the refname from the first resource created
- // for additional tests below.
- knownResourceRefName = baseRefName;
- // Store the ID returned from the first resource created
- // for additional tests below.
+ // Save values for additional tests
if (knownResourceId == null){
- knownResourceId = newID;
- knownResourceDisplayName = displayName;
- if (logger.isDebugEnabled()) {
+ setKnownResource( newID, shortId, baseRefName );
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
}
}
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
+
Map<String, String> johnWayneMap = new HashMap<String,String>();
//
// Fill the property map
//
+ String shortId = "johnWayneActor";
johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
+ johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
"He was also known for his conservative political views and his support in " +
"the 1950s for anti-communist positions.");
MultipartOutput multipart =
- PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
+ PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
client.getItemCommonPartName() );
String newID = null;
// Store the ID returned from the first item resource created
// for additional tests below.
if (knownItemResourceId == null){
- knownItemResourceId = newID;
+ setKnownItemResource(newID, shortId);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
}
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
public void read(String testName) throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName, CLASS_NAME));
- }
- // Perform setup.
- setupRead();
-
- // Submit the request to the service and store the response.
- PersonAuthorityClient client = new PersonAuthorityClient();
- ClientResponse<MultipartInput> res = client.read(knownResourceId);
- try {
- int statusCode = res.getStatus();
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- MultipartInput input = (MultipartInput) res.getEntity();
- PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), PersonauthoritiesCommon.class);
- Assert.assertNotNull(personAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- } finally {
- res.releaseConnection();
- }
+ readInternal(testName, knownResourceId, null);
}
/**
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
groups = {"read"}, dependsOnGroups = {"create"})
public void readByName(String testName) throws Exception {
-
+ readInternal(testName, null, knownResourceShortIdentifer);
+ }
+
+ protected void readInternal(String testName, String CSID, String shortId) {
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
+ ClientResponse<MultipartInput> res = null;
+ if(CSID!=null) {
+ res = client.read(CSID);
+ } else if(shortId!=null) {
+ res = client.readByName(shortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
try {
int statusCode = res.getStatus();
// Check the status code of the response: does it match
}
}
-/*
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- groups = {"read"}, dependsOnMethods = {"read"})
- public void readByName(String testName) throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug(testBanner(testName, CLASS_NAME));
- }
- // Perform setup.
- setupRead();
+ /**
+ * Read item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readItem(String testName) throws Exception {
+ readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
+ }
- // Submit the request to the service and store the response.
- ClientResponse<MultipartInput> res = client.read(knownResourceId);
- int statusCode = res.getStatus();
+ /**
+ * Read item in Named Auth.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readItemInNamedAuth(String testName) throws Exception {
+ readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
+ }
- // Check the status code of the response: does it match
- // the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug(testName + ": status = " + statusCode);
- }
- Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
- invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
- Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
- //FIXME: remove the following try catch once Aron fixes signatures
- try {
- MultipartInput input = (MultipartInput) res.getEntity();
- PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
- client.getCommonPartName(), PersonauthoritiesCommon.class);
- Assert.assertNotNull(personAuthority);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ /**
+ * Read named item.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readNamedItem(String testName) throws Exception {
+ readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
}
-*/
/**
- * Read item.
- *
- * @param testName the test name
- * @throws Exception the exception
- */
-@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"read"})
- public void readItem(String testName) throws Exception {
-
+ * Read Named item in Named Auth.
+ *
+ * @param testName the test name
+ * @throws Exception the exception
+ */
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readItem"}, dependsOnGroups = {"read"})
+ public void readNamedItemInNamedAuth(String testName) throws Exception {
+ readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
+ }
+
+ protected void readItemInternal(String testName,
+ String authCSID, String authShortId, String itemCSID, String itemShortId)
+ throws Exception {
+
if (logger.isDebugEnabled()) {
logger.debug(testBanner(testName, CLASS_NAME));
}
// Submit the request to the service and store the response.
PersonAuthorityClient client = new PersonAuthorityClient();
- ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
+ ClientResponse<MultipartInput> res = null;
+ if(authCSID!=null) {
+ if(itemCSID!=null) {
+ res = client.readItem(authCSID, itemCSID);
+ } else if(itemShortId!=null) {
+ res = client.readNamedItem(authCSID, itemShortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
+ } else if(authShortId!=null) {
+ if(itemCSID!=null) {
+ res = client.readItemInNamedAuthority(authShortId, itemCSID);
+ } else if(itemShortId!=null) {
+ res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
+ } else {
+ Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
+ }
+ } else {
+ Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
+ }
try {
int statusCode = res.getStatus();
* @throws Exception the exception
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readItem"})
+ groups = {"readItem"}, dependsOnMethods = {"readItem"})
public void readContact(String testName) throws Exception {
if (logger.isDebugEnabled()) {
* @param testName the test name
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readItem"})
+ groups = {"readItem"}, dependsOnMethods = {"readItem"})
public void readItemNonExistent(String testName) {
if (logger.isDebugEnabled()) {
* @param testName the test name
*/
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- groups = {"read"}, dependsOnMethods = {"readContact"})
+ groups = {"readItem"}, dependsOnMethods = {"readContact"})
public void readContactNonExistent(String testName) {
if (logger.isDebugEnabled()) {
item.getDisplayName());
logger.debug(testName + ": list-item[" + i + "] URI=" +
item.getUri());
- readItemList(csid, null);
+ readItemList(csid, null, testName);
i++;
}
}
/**
* Read item list.
*/
- @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
- public void readItemList() {
- readItemList(knownResourceId, null);
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readList"}, dependsOnMethods = {"readList"})
+ public void readItemList(String testName) {
+ readItemList(knownResourceId, null, testName);
}
/**
* Read item list by authority name.
*/
- @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
- public void readItemListByAuthorityName() {
- readItemList(null, knownResourceDisplayName);
+ @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+ groups = {"readList"}, dependsOnMethods = {"readItemList"})
+ public void readItemListByAuthorityName(String testName) {
+ readItemList(null, knownResourceShortIdentifer, testName);
}
/**
* @param vcsid the vcsid
* @param name the name
*/
- private void readItemList(String vcsid, String name) {
-
- final String testName = "readItemList";
+ private void readItemList(String vcsid, String name, String testName) {
// Perform setup.
setupReadList();
// The only relevant ID may be the one used in update(), below.
PersonAuthorityClient client = new PersonAuthorityClient();
String displayName = "displayName-NON_EXISTENT_ID";
- String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
- displayName, fullRefName, client.getCommonPartName());
+ displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
try {
// The only relevant ID may be the one used in update(), below.
PersonAuthorityClient client = new PersonAuthorityClient();
Map<String, String> nonexMap = new HashMap<String,String>();
+ nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
nonexMap.put(PersonJAXBSchema.GENDER, "male");
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
- PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
- client.getItemCommonPartName() );
+ PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
+ nonexMap, client.getItemCommonPartName() );
ClientResponse<MultipartInput> res =
client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
try {
// Instance variables specific to this test.
private PersonAuthorityClient client = new PersonAuthorityClient();
- public void createPersonAuthority(String personAuthorityName,
+ public void createPersonAuthority(String displayName, String shortId,
List<Map<String, String>> personMaps ) {
// Expected status code: 201 Created
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
if(logger.isDebugEnabled()){
- logger.debug("Import: Create personAuthority: \"" + personAuthorityName +"\"");
+ logger.debug("Import: Create personAuthority: \"" + displayName +"\"");
}
String basePersonRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, false);
- String fullPersonRefName =
- PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, true);
+ PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
MultipartOutput multipart =
PersonAuthorityClientUtils.createPersonAuthorityInstance(
- personAuthorityName, fullPersonRefName, client.getCommonPartName());
+ displayName, shortId, client.getCommonPartName());
ClientResponse<Response> res = client.create(multipart);
int statusCode = res.getStatus();
if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
- throw new RuntimeException("Could not create enumeration: \""+personAuthorityName
+ throw new RuntimeException("Could not create enumeration: \""+displayName
+"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
}
if(statusCode != EXPECTED_STATUS_CODE) {
throw new RuntimeException("Unexpected Status when creating enumeration: \""
- +personAuthorityName +"\", Status:"+ statusCode);
+ +displayName +"\", Status:"+ statusCode);
}
// Store the ID returned from this create operation
// for additional tests below.
String newPersonAuthorityId = PersonAuthorityClientUtils.extractId(res);
if(logger.isDebugEnabled()){
- logger.debug("Import: Created personAuthorityulary: \"" + personAuthorityName +"\" ID:"
+ logger.debug("Import: Created personAuthorityulary: \"" + displayName +"\" ID:"
+newPersonAuthorityId );
}
for(Map<String,String> personMap : personMaps){
PersonAuthorityBaseImport pabi = new PersonAuthorityBaseImport();
final String demoPersonAuthorityName = "Demo Person Authority";
+ final String demoPersonAuthorityShortId = "demoPersonAuth";
/* Strings are:
shortName, longName, nameAdditions, contactName,
foundingDate, dissolutionDate, foundingPlace, function, description
*/
Map<String, String> johnWayneMap = new HashMap<String,String>();
+ johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "johnWayne_Actor");
johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");
johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
"He was also known for his conservative political views and his support in " +
"the 1950s for anti-communist positions.");
Map<String, String> patrickSchmitzMap = new HashMap<String,String>();
+ patrickSchmitzMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "plSchmitz_Geek");
patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick");
patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz");
patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male");
List<Map<String, String>> personsMaps =
Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );
- pabi.createPersonAuthority(demoPersonAuthorityName, personsMaps);
+ pabi.createPersonAuthority(demoPersonAuthorityName,
+ demoPersonAuthorityShortId, personsMaps);
logger.info("PersonAuthorityBaseImport complete.");
}
public interface PersonAuthorityJAXBSchema {\r
final static String PERSONAUTHORITIES_COMMON = "personauthorities_common";\r
final static String DISPLAY_NAME = "displayName";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String REF_NAME = "refName";\r
final static String VOCAB_TYPE = "vocabType";\r
final static String CSID = "csid";\r
final static String PERSONS_COMMON = "persons_common";\r
final static String CSID = "csid";\r
final static String IN_AUTHORITY = "inAuthority";\r
+ final static String SHORT_IDENTIFIER = "shortIdentifier";\r
final static String REF_NAME = "refName";\r
final static String DISPLAY_NAME = "displayName";\r
final static String DISPLAY_NAME_COMPUTED = "displayNameComputed";\r
<!-- Person Information Group -->
<xs:element name="inAuthority" type="xs:string" />
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string" />
<xs:element name="displayName" type="xs:string"/>
<xs:element name="displayNameComputed" type="xs:boolean"/>
<!-- PersonAuthority Information Group -->
<xs:element name="displayName" type="xs:string"/>
+ <xs:element name="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
<xs:element name="vocabType" type="xs:string"/>
}
String whereClause =
PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+
- ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+
+ ":"+PersonAuthorityJAXBSchema.SHORT_IDENTIFIER+
"='"+specifier+"'";
// We only get a single doc - if there are multiple,
// it is an error in use.
if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority with name=" + specifier);
+ logger.debug("getPersonAuthorityByName with name=" + specifier);
}
MultipartOutput result = null;
try {
throw new WebApplicationException(response);
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority", dnfe);
+ logger.debug("getPersonAuthorityByName", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed on PersonAuthority spec=" + specifier).type(
throw new WebApplicationException(response);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
- logger.debug("getPersonAuthority", e);
+ logger.debug("getPersonAuthorityByName", e);
}
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
return result;
}
+ /**
+ * Gets the person by name.
+ *
+ * @param parentcsid the parentcsid
+ * @param itemspecifier the shrotId of the person
+ *
+ * @return the person
+ */
+ @GET
+ @Path("{csid}/items/urn:cspace:name({itemspecifier})")
+ public MultipartOutput getPersonByName(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemspecifier") String itemspecifier) {
+ if (parentcsid == null || "".equals(parentcsid)
+ || itemspecifier == null || "".equals(itemspecifier)) {
+ logger.error("getPersonByName: missing parentcsid or itemspecifier!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Person with parentcsid="
+ + parentcsid + " and itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ String whereClause =
+ PersonJAXBSchema.PERSONS_COMMON+
+ ":"+PersonJAXBSchema.SHORT_IDENTIFIER+
+ "='"+itemspecifier+"'";
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPerson with parentcsid=" + parentcsid + " and itemspecifier=" + itemspecifier);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).get(ctx, handler);
+ // TODO should we assert that the item is in the passed personAuthority?
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPerson", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on Person itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPerson", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
+
+ /**
+ * Gets the person by name, in a named authority.
+ *
+ * @param parentspecifier the shortId of the parent
+ * @param itemspecifier the shortId of the person
+ *
+ * @return the person
+ */
+ @GET
+ @Path("urn:cspace:name({parentspecifier})/items/urn:cspace:name({itemspecifier})")
+ public MultipartOutput getPersonByNameInNamedAuthority(
+ @PathParam("parentspecifier") String parentspecifier,
+ @PathParam("itemspecifier") String itemspecifier) {
+ if (parentspecifier == null || "".equals(parentspecifier)
+ || itemspecifier == null || "".equals(itemspecifier)) {
+ logger.error("getPersonByNameInNamedAuthority: missing parentcsid or itemspecifier!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on Person with parentspecifier="
+ + parentspecifier + " and itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ String whereClause =
+ PersonJAXBSchema.PERSONS_COMMON+
+ ":"+PersonJAXBSchema.SHORT_IDENTIFIER+
+ "='"+itemspecifier+"'";
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPersonByNameInNamedAuthority with parentspecifier="
+ + parentspecifier + " and itemspecifier=" + itemspecifier);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
+ // HACK HACK Since we do not use the parent CSID yet this should work.
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentspecifier);
+ DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).get(ctx, handler);
+ // TODO should we assert that the item is in the passed personAuthority?
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (UnauthorizedException ue) {
+ Response response = Response.status(
+ Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPersonByNameInNamedAuthority", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on Person itemspecifier=" + itemspecifier).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getPersonByNameInNamedAuthority", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested Person itemspecifier:" + itemspecifier + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
+
/**
* Gets the person list.
*
@Context UriInfo ui) {
PersonsCommonList personObjectList = new PersonsCommonList();
try {
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
String whereClause = PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON +
- ":" + PersonAuthorityJAXBSchema.DISPLAY_NAME +
+ ":" + PersonAuthorityJAXBSchema.SHORT_IDENTIFIER +
"='" + parentSpecifier+"'";
// Need to get an Authority by name
- MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
String parentcsid =
getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
- ctx = createServiceContext(getItemServiceName(), queryParams);
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-
- // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
- handler.getDocumentFilter().setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
- PersonJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'");
-
- // AND persons_common:displayName LIKE '%partialTerm%'
- if (partialTerm != null && !partialTerm.isEmpty()) {
- String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" +
- PersonJAXBSchema.DISPLAY_NAME +
- " LIKE " +
- "'%" + partialTerm + "%'";
- handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
- }
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- personObjectList = (PersonsCommonList) handler.getCommonPartList();
+ return getPersonList(parentcsid, partialTerm, ui);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
throw new WebApplicationException(response);
}
- return personObjectList;
}
/**
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *//**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.person.nuxeo;
+
+import java.util.regex.Pattern;
+
+import org.collectionspace.services.person.PersonauthoritiesCommon;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.document.InvalidDocumentException;
+import org.collectionspace.services.common.document.ValidatorHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class PersonAuthorityValidatorHandler implements ValidatorHandler {
+
+ final Logger logger = LoggerFactory.getLogger(PersonAuthorityValidatorHandler.class);
+ private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
+
+ @Override
+ public void validate(Action action, ServiceContext ctx)
+ throws InvalidDocumentException {
+ if(logger.isDebugEnabled()) {
+ logger.debug("validate() action=" + action.name());
+ }
+ try {
+ MultipartServiceContext mctx = (MultipartServiceContext) ctx;
+ PersonauthoritiesCommon personAuth =
+ (PersonauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+ PersonauthoritiesCommon.class);
+ String msg = "";
+ boolean invalid = false;
+ String shortId = personAuth.getShortIdentifier();
+ if(shortId==null){
+ invalid = true;
+ msg += "shortIdentifier must be non-null";
+ } else if(shortIdBadPattern.matcher(shortId).find()) {
+ invalid = true;
+ msg += "shortIdentifier must only contain standard word characters";
+ }
+ /*
+ if(action.equals(Action.CREATE)) {
+ //create specific validation here
+ } else if(action.equals(Action.UPDATE)) {
+ //update specific validation here
+ }
+ */
+
+ if (invalid) {
+ logger.error(msg);
+ throw new InvalidDocumentException(msg);
+ }
+ } catch (InvalidDocumentException ide) {
+ throw ide;
+ } catch (Exception e) {
+ throw new InvalidDocumentException(e);
+ }
+ }
+}
*/
package org.collectionspace.services.person.nuxeo;
+import java.util.regex.Pattern;
+
import org.collectionspace.services.person.PersonsCommon;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
public class PersonValidatorHandler implements ValidatorHandler {
final Logger logger = LoggerFactory.getLogger(PersonValidatorHandler.class);
+ private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
@Override
public void validate(Action action, ServiceContext ctx)
if(!person.isDisplayNameComputed() && (person.getDisplayName()==null)) {
invalid = true;
msg += "displayName must be non-null if displayNameComputed is false!";
+ }
+ String shortId = person.getShortIdentifier();
+ if(shortId==null){
+ invalid = true;
+ msg += "shortIdentifier must be non-null";
+ } else if(shortIdBadPattern.matcher(shortId).find()) {
+ invalid = true;
+ msg += "shortIdentifier must only contain standard word characters";
}
/*
if(action.equals(Action.CREATE)) {