Entity : Location
Part : Common
Used for: Nuxeo EP core document type
-
- $LastChangedRevision: 860 $
- $LastChangedDate: 2009-10-14 14:48:05 -0700 (Wed, 14 Oct 2009) $
-->
<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:ns="http://collectionspace.org/services/location"
- xmlns="http://collectionspace.org/services/location"
- targetNamespace="http://collectionspace.org/services/location"
- version="0.1"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:ns="http://collectionspace.org/services/location"
+ xmlns="http://collectionspace.org/services/location"
+ targetNamespace="http://collectionspace.org/services/location"
+ version="0.1"
>
<!-- See http://wiki.collectionspace.org/display/collectionspace/Location+Service+Home -->
<!-- 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="shortIdentifier" type="xs:string"/>
<xs:element name="refName" type="xs:string"/>
- <xs:element name="termStatus" type="xs:string"/>
- <xs:element name="displayName" type="xs:string"/>
- <xs:element name="displayNameComputed" type="xs:boolean"/>
- <xs:element name="shortDisplayName" type="xs:string"/>
- <xs:element name="shortDisplayNameComputed" type="xs:boolean"/>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="conditionGroupList" type="conditionGroupList"/>
- <xs:element name="securityNote" type="xs:string"/>
+
+ <!-- Term Information repeatable group -->
+ <xs:element name="locTermGroupList" type="locTermGroupList"/>
+
<xs:element name="accessNote" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
+ <xs:element name="conditionGroupList" type="conditionGroupList"/>
+ <xs:element name="securityNote" type="xs:string"/>
<xs:element name="locationType" type="xs:string"/>
- <xs:element name="source" type="xs:string"/>
- <xs:element name="sourcePage" type="xs:string"/>
- <xs:element name="description" type="xs:string"/>
<xs:complexType name="conditionGroupList">
<xs:sequence>
<xs:complexType name="conditionGroup">
<xs:sequence>
- <xs:element name="conditionNote" type="xs:string"/>
- <xs:element name="conditionNoteDate" type="xs:date"/>
+ <xs:element name="conditionNote" type="xs:string"/>
+ <xs:element name="conditionNoteDate" type="xs:date"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="locTermGroupList">
+ <xs:sequence>
+ <xs:element name="locTermGroup" type="locTermGroup" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="locTermGroup">
+ <xs:sequence>
+ <!-- Common across all authority item terms -->
+ <xs:element name="termDisplayName" type="xs:string"/>
+ <xs:element name="termName" type="xs:string"/>
+ <xs:element name="termType" type="xs:string"/>
+ <xs:element name="termStatus" type="xs:string"/>
+ <xs:element name="termQualifier" type="xs:string"/>
+ <xs:element name="termLanguage" type="xs:string"/>
+ <xs:element name="termPrefForLang" type="xs:boolean"/>
+ <xs:element name="termSource" type="xs:string"/>
+ <xs:element name="termSourceDetail" type="xs:string"/>
+ <xs:element name="termSourceID" type="xs:string"/>
+ <xs:element name="termSourceNote" type="xs:string"/>
+ <!-- Specific to Storage Location terms -->
+ <!-- (None at present) -->
</xs:sequence>
</xs:complexType>
-/**
+/**
* LocationAuthorityClient.java
*
* {Purpose of This Class}
*
* {Other Notes Relating to This Class (Optional)}
*
- * $LastChangedBy: $
- * $LastChangedRevision: $
- * $LastChangedDate: $
+ * $LastChangedBy: $ $LastChangedRevision: $ $LastChangedDate: $
*
- * 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:
+ * 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
+ * http://www.collectionspace.org http://wiki.collectionspace.org
*
* Copyright © 2009 {Contributing Institution}
*
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
+ * 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
* The Class LocationAuthorityClient.
*/
public class LocationAuthorityClient extends AuthorityClientImpl<LocationsCommon, LocationAuthorityProxy> {
- public static final String SERVICE_NAME = "locationauthorities";
- public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
- public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
- public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
- public static final String TERM_INFO_GROUP_XPATH_BASE = "locationTermGroup";
- //
- // Subitem constants
- //
- public static final String SERVICE_ITEM_NAME = "locations";
- public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
- //
- // Payload Part/Schema part names
- //
- public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
- public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
-
- @Override
- public String getServiceName() {
- return SERVICE_NAME;
- }
+
+ public static final String SERVICE_NAME = "locationauthorities";
+ public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
+ public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
+ public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+ public static final String TERM_INFO_GROUP_XPATH_BASE = "locTermGroupList";
+ //
+ // Subitem constants
+ //
+ public static final String SERVICE_ITEM_NAME = "locations";
+ public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
+ //
+ // Payload Part/Schema part names
+ //
+ public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+ public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+
+ @Override
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
@Override
public String getServicePathComponent() {
return getCommonPartName(SERVICE_ITEM_NAME);
}
- @Override
- public Class<LocationAuthorityProxy> getProxyClass() {
- return LocationAuthorityProxy.class;
- }
+ @Override
+ public Class<LocationAuthorityProxy> getProxyClass() {
+ return LocationAuthorityProxy.class;
+ }
- @Override
- public String getInAuthority(LocationsCommon item) {
- return item.getInAuthority();
- }
+ @Override
+ public String getInAuthority(LocationsCommon item) {
+ return item.getInAuthority();
+ }
- @Override
- public void setInAuthority(LocationsCommon item, String inAuthorityCsid) {
- item.setInAuthority(inAuthorityCsid);
- }
+ @Override
+ public void setInAuthority(LocationsCommon item, String inAuthorityCsid) {
+ item.setInAuthority(inAuthorityCsid);
+ }
}
\r
import java.io.File;\r
import java.util.ArrayList;\r
+import java.util.Date;\r
import java.util.List;\r
import java.util.Map;\r
-\r
import javax.ws.rs.core.MediaType;\r
import javax.ws.rs.core.MultivaluedMap;\r
import javax.ws.rs.core.Response;\r
-\r
import org.apache.commons.io.FileUtils;\r
import org.collectionspace.services.LocationJAXBSchema;\r
import org.collectionspace.services.client.test.ServiceRequestType;\r
-import org.collectionspace.services.location.LocationsCommon;\r
-import org.collectionspace.services.location.ConditionGroupList;\r
-import org.collectionspace.services.location.ConditionGroup;\r
-import org.collectionspace.services.location.LocationauthoritiesCommon;\r
+import org.collectionspace.services.location.*;\r
import org.dom4j.DocumentException;\r
import org.jboss.resteasy.client.ClientResponse;\r
import org.slf4j.Logger;\r
*/\r
public static PoxPayloadOut createLocationInstance( \r
String locationAuthRefName, Map<String, String> locationInfo, \r
- String headerLabel){\r
+ List<LocTermGroup> terms, 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.setRefName(locationRefName);\r
String value = null;\r
value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
- boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); \r
- location.setDisplayNameComputed(displayNameComputed);\r
- if((value = (String)locationInfo.get(LocationJAXBSchema.NAME))!=null)\r
- location.setName(value);\r
+ boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true");\r
+ \r
+ // Set values in the Term Information Group\r
+ LocTermGroupList termList = new LocTermGroupList();\r
+ if (terms == null || terms.isEmpty()) {\r
+ terms = getTermGroupInstance(getGeneratedIdentifier());\r
+ }\r
+ termList.getLocTermGroup().addAll(terms); \r
+ location.setLocTermGroupList(termList);\r
+ \r
if((value = (String)locationInfo.get(LocationJAXBSchema.CONDITION_NOTE))!=null) {\r
ConditionGroupList conditionGroupList = new ConditionGroupList();\r
List<ConditionGroup> conditionGroups = conditionGroupList.getConditionGroup();\r
location.setLocationType(value);\r
if((value = (String)locationInfo.get(LocationJAXBSchema.ADDRESS))!=null)\r
location.setAddress(value);\r
- if((value = (String)locationInfo.get(LocationJAXBSchema.TERM_STATUS))!=null)\r
- location.setTermStatus(value);\r
\r
PoxPayloadOut multipart = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);\r
PayloadOutputPart commonPart = multipart.addPart(location,\r
*/\r
public static String createItemInAuthority(String vcsid, \r
String locationAuthorityRefName, Map<String,String> locationMap,\r
- LocationAuthorityClient client ) {\r
+ List<LocTermGroup> terms, LocationAuthorityClient client ) {\r
// Expected status code: 201 Created\r
int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
// Type of service request being tested\r
ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
- \r
- String displayName = locationMap.get(LocationJAXBSchema.DISPLAY_NAME);\r
- String displayNameComputedStr = locationMap.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED);\r
- boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true");\r
- if( displayName == null ) {\r
- if(!displayNameComputed) {\r
- throw new RuntimeException(\r
- "CreateItem: Must supply a displayName if displayNameComputed is set to false.");\r
- }\r
- displayName = \r
- prepareDefaultDisplayName(\r
- locationMap.get(LocationJAXBSchema.NAME));\r
- }\r
+ \r
+ String displayName = "";\r
+ if (terms !=null && terms.size() > 0) {\r
+ displayName = terms.get(0).getTermDisplayName();\r
+ }\r
\r
if(logger.isDebugEnabled()){\r
- logger.debug("Import: Create Item: \""+displayName\r
- +"\" in locationAuthority: \"" + locationAuthorityRefName +"\"");\r
+ logger.debug("Creating item with display name: \"" + displayName\r
+ +"\" in locationAuthority: \"" + vcsid +"\"");\r
}\r
+ \r
PoxPayloadOut multipart = \r
createLocationInstance( locationAuthorityRefName,\r
- locationMap, client.getItemCommonPartName() );\r
+ locationMap, terms, client.getItemCommonPartName() );\r
String newID = null;\r
ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
try {\r
return newStr.toString();\r
}\r
\r
-\r
+ public static List<LocTermGroup> getTermGroupInstance(String identifier) {\r
+ List<LocTermGroup> terms = new ArrayList<LocTermGroup>();\r
+ LocTermGroup term = new LocTermGroup();\r
+ term.setTermDisplayName(identifier);\r
+ term.setTermName(identifier);\r
+ terms.add(term);\r
+ return terms;\r
+ }\r
+ \r
+ private static String getGeneratedIdentifier() {\r
+ return "id" + new Date().getTime(); \r
+ }\r
\r
}\r
xmlns="http://collectionspace.org/services/location"
targetNamespace="http://collectionspace.org/services/location"
version="0.1"
- >
+>
<!-- avoid XmlRootElement nightnmare, see http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html-->
<xs:element name="csid" 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="termStatus" type="xs:string"/>
- <xs:element name="displayName" type="xs:string"/>
- <xs:element name="displayNameComputed" type="xs:boolean"/>
- <xs:element name="shortDisplayName" type="xs:string"/>
- <xs:element name="shortDisplayNameComputed" type="xs:boolean"/>
- <xs:element name="source" type="xs:string"/>
- <xs:element name="sourcePage" type="xs:string"/>
- <xs:element name="description" type="xs:string"/>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="conditionGroupList" type="conditionGroupList"/>
- <xs:element name="securityNote" type="xs:string"/>
+
+ <!-- Term Information repeatable group -->
+ <xs:element name="locTermGroupList" type="locTermGroupList"/>
+
<xs:element name="accessNote" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
+ <xs:element name="conditionGroupList" type="conditionGroupList"/>
+ <xs:element name="securityNote" type="xs:string"/>
<xs:element name="locationType" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="conditionGroup">
<xs:sequence>
- <xs:element name="conditionNote" type="xs:string"/>
- <xs:element name="conditionNoteDate" type="xs:string"/>
+ <xs:element name="conditionNote" type="xs:string"/>
+ <xs:element name="conditionNoteDate" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="locTermGroupList">
+ <xs:sequence>
+ <xs:element name="locTermGroup" type="locTermGroup" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="locTermGroup">
+ <xs:sequence>
+ <!-- Common across all authority item terms -->
+ <xs:element name="termDisplayName" type="xs:string"/>
+ <xs:element name="termName" type="xs:string"/>
+ <xs:element name="termType" type="xs:string"/>
+ <xs:element name="termStatus" type="xs:string"/>
+ <xs:element name="termQualifier" type="xs:string"/>
+ <xs:element name="termLanguage" type="xs:string"/>
+ <xs:element name="termPrefForLang" type="xs:boolean"/>
+ <xs:element name="termSource" type="xs:string"/>
+ <xs:element name="termSourceDetail" type="xs:string"/>
+ <xs:element name="termSourceID" type="xs:string"/>
+ <xs:element name="termSourceNote" type="xs:string"/>
+ <!-- Specific to Storage Location terms -->
+ <!-- (None at present) -->
</xs:sequence>
</xs:complexType>
*/
package org.collectionspace.services.location.nuxeo;
+import java.util.List;
import java.util.regex.Pattern;
-
-import org.collectionspace.services.location.LocationsCommon;
-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.api.Tools;
import org.collectionspace.services.common.document.InvalidDocumentException;
-import org.collectionspace.services.common.document.ValidatorHandler;
+import org.collectionspace.services.common.document.ValidatorHandlerImpl;
+import org.collectionspace.services.location.LocTermGroup;
+import org.collectionspace.services.location.LocTermGroupList;
+import org.collectionspace.services.location.LocationsCommon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* LocationValidatorHandler
*
* Validates data supplied when attempting to create and/or update Location records.
- *
- * $LastChangedRevision: $
- * $LastChangedDate: $
*/
-public class LocationValidatorHandler implements ValidatorHandler {
+public class LocationValidatorHandler extends ValidatorHandlerImpl {
final Logger logger = LoggerFactory.getLogger(LocationValidatorHandler.class);
- private static final Pattern shortIdBadPattern = Pattern.compile("[\\W]"); //.matcher(input).matches()
+ // 'Bad pattern' for shortIdentifiers matches any non-word characters
+ private static final Pattern SHORT_ID_BAD_PATTERN = Pattern.compile("[\\W]"); //.matcher(input).matches()
+ private static final String VALIDATION_ERROR = "The record payload was invalid. See log file for more details.";
+ private static final String SHORT_ID_BAD_CHARS_ERROR =
+ "shortIdentifier must only contain standard word characters";
+ private static final String HAS_NO_TERMS_ERROR =
+ "Authority items must contain at least one term.";
+ private static final String HAS_AN_EMPTY_TERM_ERROR =
+ "Each term group in an authority item must contain "
+ + "a non-empty term name or "
+ + "a non-empty term display name.";
@Override
- public void validate(Action action, ServiceContext ctx)
- throws InvalidDocumentException {
- if (logger.isDebugEnabled()) {
- logger.debug("validate() action=" + action.name());
- }
-
- // Bail out if the validation action is for delete.
- if (action.equals(Action.DELETE)) {
- return;
- }
-
- try {
- MultipartServiceContext mctx = (MultipartServiceContext) ctx;
- LocationsCommon location = (LocationsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
- LocationsCommon.class);
- String msg = "";
- boolean invalid = false;
-
- // Validation occurring on both creates and updates
- String displayName = location.getDisplayName();
- if (!location.isDisplayNameComputed() && ((displayName == null) || displayName.trim().isEmpty())) {
- invalid = true;
- msg += "displayName must be non-null and non-blank if displayNameComputed is false";
- }
+ protected Class getCommonPartClass() {
+ return LocationsCommon.class;
+ }
- // Validation specific to creates or updates
- if (action.equals(Action.CREATE)) {
+ @Override
+ protected void handleCreate() throws InvalidDocumentException {
+ LocationsCommon location = (LocationsCommon) getCommonPart();
+ // No guarantee that there is a common part in every post/update.
+ if (location != null) {
+ try {
String shortId = location.getShortIdentifier();
- // Per CSPACE-2215, shortIdentifier values that are null (missing)
- // oe the empty string are now legally accepted in create payloads.
- // In either of those cases, a short identifier will be synthesized from
- // a display name or supplied in another manner.
- if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) {
- invalid = true;
- msg += "shortIdentifier must only contain standard word characters";
+ if (shortId != null) {
+ CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR);
+ }
+ CS_ASSERT(containsAtLeastOneTerm(location), HAS_NO_TERMS_ERROR);
+ CS_ASSERT(allTermsContainNameOrDisplayName(location), HAS_AN_EMPTY_TERM_ERROR);
+ } catch (AssertionError e) {
+ if (logger.isErrorEnabled()) {
+ logger.error(e.getMessage(), e);
+ }
+ throw new InvalidDocumentException(VALIDATION_ERROR, e);
+ }
+ }
+ }
+
+ @Override
+ protected void handleGet() throws InvalidDocumentException {
+ }
+
+ @Override
+ protected void handleGetAll() throws InvalidDocumentException {
+ }
+
+ @Override
+ protected void handleUpdate() throws InvalidDocumentException {
+ LocationsCommon location = (LocationsCommon) getCommonPart();
+ // No guarantee that there is a common part in every post/update.
+ if (location != null) {
+ try {
+ // shortIdentifier is among a set of fields that are
+ // prevented from being changed on an update, and thus
+ // we don't need to check its value here.
+ CS_ASSERT(containsAtLeastOneTerm(location), HAS_NO_TERMS_ERROR);
+ CS_ASSERT(allTermsContainNameOrDisplayName(location), HAS_AN_EMPTY_TERM_ERROR);
+ } catch (AssertionError e) {
+ if (logger.isErrorEnabled()) {
+ logger.error(e.getMessage(), e);
}
- } else if (action.equals(Action.UPDATE)) {
+ throw new InvalidDocumentException(VALIDATION_ERROR, e);
}
+ }
+ }
+
+ @Override
+ protected void handleDelete() throws InvalidDocumentException {
+ }
+
+ private boolean shortIdentifierContainsOnlyValidChars(String shortId) {
+ // Check whether any characters match the 'bad' pattern
+ if (SHORT_ID_BAD_PATTERN.matcher(shortId).find()) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean containsAtLeastOneTerm(LocationsCommon person) {
+ LocTermGroupList termGroupList = person.getLocTermGroupList();
+ if (termGroupList == null) {
+ return false;
+ }
+ List<LocTermGroup> termGroups = termGroupList.getLocTermGroup();
+ if ((termGroups == null) || (termGroups.isEmpty())) {
+ return false;
+ }
+ return true;
+ }
- if (invalid) {
- logger.error(msg);
- throw new InvalidDocumentException(msg);
+ private boolean allTermsContainNameOrDisplayName(LocationsCommon person) {
+ LocTermGroupList termGroupList = person.getLocTermGroupList();
+ List<LocTermGroup> termGroups = termGroupList.getLocTermGroup();
+ for (LocTermGroup termGroup : termGroups) {
+ if (Tools.isBlank(termGroup.getTermName()) || Tools.isBlank(termGroup.getTermDisplayName())) {
+ return false;
}
- } catch (InvalidDocumentException ide) {
- throw ide;
- } catch (Exception e) {
- throw new InvalidDocumentException(e);
}
+ return true;
}
-}
+}
\ No newline at end of file
-/**
+/**
* OrgAuthorityClient.java
*
* {Purpose of This Class}
*
* {Other Notes Relating to This Class (Optional)}
*
- * $LastChangedBy: $
- * $LastChangedRevision$
- * $LastChangedDate$
+ * $LastChangedBy: $ $LastChangedRevision$ $LastChangedDate$
*
- * 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:
+ * 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
+ * http://www.collectionspace.org http://wiki.collectionspace.org
*
* Copyright © 2009 {Contributing Institution}
*
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
+ * 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
* The Class OrgAuthorityClient.
*/
public class OrgAuthorityClient extends AuthorityWithContactsClientImpl<OrganizationsCommon, OrgAuthorityProxy> {
- public static final String SERVICE_NAME = "orgauthorities";
- public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
- public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
- public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+
+ public static final String SERVICE_NAME = "orgauthorities";
+ public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
+ public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
+ public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
public static final String TERM_INFO_GROUP_XPATH_BASE = "orgTermGroupList";
- //
- // Subitem constants
- //
- public static final String SERVICE_ITEM_NAME = "organizations";
- public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
- //
- // Payload Part/Schema part names
- //
- public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
- public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
-
+ //
+ // Subitem constants
+ //
+ public static final String SERVICE_ITEM_NAME = "organizations";
+ public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
+ //
+ // Payload Part/Schema part names
+ //
+ public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+ public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+
+ @Override
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
+
@Override
- public String getServiceName() {
- return SERVICE_NAME;
- }
-
- @Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
-
- @Override
- public Class<OrgAuthorityProxy> getProxyClass() {
- return OrgAuthorityProxy.class;
- }
-
- @Override
+
+ @Override
+ public Class<OrgAuthorityProxy> getProxyClass() {
+ return OrgAuthorityProxy.class;
+ }
+
+ @Override
public String getItemCommonPartName() {
return getCommonPartName(SERVICE_ITEM_NAME);
}
- @Override
- public String getInAuthority(OrganizationsCommon item) {
- return item.getInAuthority();
- }
+ @Override
+ public String getInAuthority(OrganizationsCommon item) {
+ return item.getInAuthority();
+ }
- @Override
- public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) {
- item.setInAuthority(inAuthorityCsid);
- }
+ @Override
+ public void setInAuthority(OrganizationsCommon item, String inAuthorityCsid) {
+ item.setInAuthority(inAuthorityCsid);
+ }
}
package org.collectionspace.services.client;\r
\r
import java.util.ArrayList;\r
+import java.util.Date;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
-\r
import javax.ws.rs.core.MediaType;\r
import javax.ws.rs.core.MultivaluedMap;\r
import javax.ws.rs.core.Response;\r
-\r
import org.collectionspace.services.OrganizationJAXBSchema;\r
import org.collectionspace.services.client.test.ServiceRequestType;\r
import org.collectionspace.services.organization.ContactNameList;\r
\r
// Set values in the Term Information Group\r
OrgTermGroupList termList = new OrgTermGroupList();\r
- termList.getOrgTermGroup().addAll(terms);\r
+ if (terms == null || terms.isEmpty()) {\r
+ terms = getTermGroupInstance(getGeneratedIdentifier());\r
+ }\r
+ termList.getOrgTermGroup().addAll(terms); \r
organization.setOrgTermGroupList(termList);\r
\r
if((values = (List<String>)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) {\r
return terms;\r
}\r
\r
+ private static String getGeneratedIdentifier() {\r
+ return "id" + new Date().getTime(); \r
+ }\r
+ \r
}\r
"Each term group in an authority item must contain "
+ "a non-empty term name or "
+ "a non-empty term display name.";
- boolean invalid = false;
- String msg = "";
@Override
protected Class getCommonPartClass() {
@Override
protected void handleCreate() throws InvalidDocumentException {
- OrganizationsCommon person = (OrganizationsCommon) getCommonPart();
+ OrganizationsCommon organization = (OrganizationsCommon) getCommonPart();
// No guarantee that there is a common part in every post/update.
- if (person != null) {
+ if (organization != null) {
try {
- String shortId = person.getShortIdentifier();
+ String shortId = organization.getShortIdentifier();
if (shortId != null) {
CS_ASSERT(shortIdentifierContainsOnlyValidChars(shortId), SHORT_ID_BAD_CHARS_ERROR);
}
- CS_ASSERT(containsAtLeastOneTerm(person), HAS_NO_TERMS_ERROR);
- CS_ASSERT(allTermsContainNameOrDisplayName(person), HAS_AN_EMPTY_TERM_ERROR);
+ CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR);
+ CS_ASSERT(allTermsContainNameOrDisplayName(organization), HAS_AN_EMPTY_TERM_ERROR);
} catch (AssertionError e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
@Override
protected void handleUpdate() throws InvalidDocumentException {
- OrganizationsCommon person = (OrganizationsCommon) getCommonPart();
+ OrganizationsCommon organization = (OrganizationsCommon) getCommonPart();
// No guarantee that there is a common part in every post/update.
- if (person != null) {
+ if (organization != null) {
try {
// shortIdentifier is among a set of fields that are
// prevented from being changed on an update, and thus
// we don't need to check its value here.
- CS_ASSERT(containsAtLeastOneTerm(person), HAS_NO_TERMS_ERROR);
- CS_ASSERT(allTermsContainNameOrDisplayName(person), HAS_AN_EMPTY_TERM_ERROR);
+ CS_ASSERT(containsAtLeastOneTerm(organization), HAS_NO_TERMS_ERROR);
+ CS_ASSERT(allTermsContainNameOrDisplayName(organization), HAS_AN_EMPTY_TERM_ERROR);
} catch (AssertionError e) {
if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e);
return true;
}
- private boolean containsAtLeastOneTerm(OrganizationsCommon person) {
- OrgTermGroupList termGroupList = person.getOrgTermGroupList();
+ private boolean containsAtLeastOneTerm(OrganizationsCommon organization) {
+ OrgTermGroupList termGroupList = organization.getOrgTermGroupList();
if (termGroupList == null) {
return false;
}
List<OrgTermGroup> termGroups = termGroupList.getOrgTermGroup();
- if ((termGroups == null) || (termGroups.size() == 0)) {
+ if ((termGroups == null) || (termGroups.isEmpty())){
return false;
}
return true;
}
- private boolean allTermsContainNameOrDisplayName(OrganizationsCommon person) {
- OrgTermGroupList termGroupList = person.getOrgTermGroupList();
+ private boolean allTermsContainNameOrDisplayName(OrganizationsCommon organization) {
+ OrgTermGroupList termGroupList = organization.getOrgTermGroupList();
List<OrgTermGroup> termGroups = termGroupList.getOrgTermGroup();
for (OrgTermGroup termGroup : termGroups) {
if (Tools.isBlank(termGroup.getTermName()) || Tools.isBlank(termGroup.getTermDisplayName())) {
-/**
+/**
* PersonAuthorityClient.java
*
- * 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:
+ * 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
+ * http://www.collectionspace.org http://wiki.collectionspace.org
*
* Copyright © 2009 University of California, Berkeley
*
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
+ * 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
* The Class PersonAuthorityClient.
*/
public class PersonAuthorityClient extends AuthorityWithContactsClientImpl<PersonsCommon, PersonAuthorityProxy> {
- public static final String SERVICE_NAME = "personauthorities";
- public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
- public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
- public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
- public static final String TERM_INFO_GROUP_XPATH_BASE = "personTermGroupList";
- //
- // Subitem constants
- //
- public static final String SERVICE_ITEM_NAME = "persons";
- public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
- //
- // Payload Part/Schema part names
- //
- public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
- public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME +
- PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
-
+
+ public static final String SERVICE_NAME = "personauthorities";
+ public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
+ public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
+ public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME;
+ public static final String TERM_INFO_GROUP_XPATH_BASE = "personTermGroupList";
+ //
+ // Subitem constants
+ //
+ public static final String SERVICE_ITEM_NAME = "persons";
+ public static final String SERVICE_ITEM_PAYLOAD_NAME = SERVICE_ITEM_NAME;
+ //
+ // Payload Part/Schema part names
+ //
+ public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+ public static final String SERVICE_ITEM_COMMON_PART_NAME = SERVICE_ITEM_NAME
+ + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+
+ @Override
+ public String getServiceName() {
+ return SERVICE_NAME;
+ }
+
@Override
- public String getServiceName() {
- return SERVICE_NAME;
- }
-
- @Override
public String getServicePathComponent() {
return SERVICE_PATH_COMPONENT;
}
- @Override
+ @Override
public String getItemCommonPartName() {
return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME);
}
-
- @Deprecated // Use getItemCommonPartName() instead
+
+ @Deprecated // Use getItemCommonPartName() instead
public String getCommonPartItemName() {
return getCommonPartName(SERVICE_ITEM_PAYLOAD_NAME);
}
-
- @Override
- public Class<PersonAuthorityProxy> getProxyClass() {
- return PersonAuthorityProxy.class;
- }
- @Override
- public String getInAuthority(PersonsCommon item) {
- return item.getInAuthority();
- }
+ @Override
+ public Class<PersonAuthorityProxy> getProxyClass() {
+ return PersonAuthorityProxy.class;
+ }
- @Override
- public void setInAuthority(PersonsCommon item, String inAuthorityCsid) {
- item.setInAuthority(inAuthorityCsid);
- }
+ @Override
+ public String getInAuthority(PersonsCommon item) {
+ return item.getInAuthority();
+ }
+
+ @Override
+ public void setInAuthority(PersonsCommon item, String inAuthorityCsid) {
+ item.setInAuthority(inAuthorityCsid);
+ }
}
Map<String, String> personInfo,\r
List<PersonTermGroup> terms,\r
String headerLabel){\r
- final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO =\r
- new HashMap<String, List<String>>();\r
- if (terms == null || terms.size() == 0) {\r
+ if (terms == null || terms.isEmpty()) {\r
terms = getTermGroupInstance(getGeneratedIdentifier());\r
}\r
+ final Map<String, List<String>> EMPTY_PERSON_REPEATABLES_INFO =\r
+ new HashMap<String, List<String>>();\r
return createPersonInstance(inAuthority, null /*personAuthRefName*/,\r
personInfo, terms, EMPTY_PERSON_REPEATABLES_INFO, headerLabel);\r
}\r
\r
// Set values in the Term Information Group\r
PersonTermGroupList termList = new PersonTermGroupList();\r
- termList.getPersonTermGroup().addAll(terms);\r
+ if (terms == null || terms.isEmpty()) {\r
+ terms = getTermGroupInstance(getGeneratedIdentifier());\r
+ }\r
+ termList.getPersonTermGroup().addAll(terms); \r
person.setPersonTermGroupList(termList);\r
\r
- \r
if (personRepeatablesInfo != null) {\r
if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) {\r
GroupList groupsList = new GroupList();\r
"Each term group in an authority item must contain "
+ "a non-empty term name or "
+ "a non-empty term display name.";
- boolean invalid = false;
- String msg = "";
@Override
protected Class getCommonPartClass() {
return false;
}
List<PersonTermGroup> termGroups = termGroupList.getPersonTermGroup();
- if ((termGroups == null) || (termGroups.size() == 0)) {
+ if ((termGroups == null) || (termGroups.isEmpty())) {
return false;
}
return true;