]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5121,CSPACE-4844,CSPACE-5137: Updated Storage Location schema with repeatable...
authorAron Roberts <aron@socrates.berkeley.edu>
Mon, 7 May 2012 19:31:41 +0000 (12:31 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Mon, 7 May 2012 19:31:41 +0000 (12:31 -0700)
services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd
services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java
services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java
services/location/jaxb/src/main/resources/location_common.xsd
services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java
services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java

index d0c24796d62b98aa80a3b813270c96559947a25c..88c1fe827033286f0a0ca0e260665e32e353d5da 100644 (file)
@@ -6,39 +6,31 @@
     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>
     
index 26270907f88639a7211bc2b025402ec7dffcc73b..9fe643945ed76b0abb71c9f873e22c75f3e93275 100644 (file)
@@ -1,25 +1,22 @@
-/**    
+/**
  * 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
@@ -32,28 +29,29 @@ import org.collectionspace.services.location.LocationsCommon;
  * 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() {
@@ -65,18 +63,18 @@ public class LocationAuthorityClient extends AuthorityClientImpl<LocationsCommon
         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);
+    }
 }
index 6490045501d427e713ded4bd4aec4a2338abea73..992cedae807d99ee5c9f93adaa75dfbb09b8f919 100644 (file)
@@ -2,20 +2,16 @@ package org.collectionspace.services.client;
 \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
@@ -62,7 +58,7 @@ public class LocationAuthorityClientUtils {
      */\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
@@ -71,10 +67,16 @@ public class LocationAuthorityClientUtils {
                // 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
@@ -93,8 +95,6 @@ public class LocationAuthorityClientUtils {
                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
@@ -117,32 +117,25 @@ public class LocationAuthorityClientUtils {
      */\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
@@ -306,6 +299,17 @@ public class LocationAuthorityClientUtils {
                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
index a6f77b668a62512579c0d80dc9aff428ef5dd060..eaa7294b2c2ce22745dbdc1f6e456787b46423dd 100644 (file)
@@ -7,7 +7,7 @@
     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>
 
index 5c120d5f4554e465916aecf7bb3d823fd03a47d4..0c6345969f569e4b7f92c3f469b7d7a94ab31b38 100644 (file)
  */
 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;
 
@@ -38,63 +38,108 @@ 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
index 79f5f5f0bc7b18916a4d50725317c427e5e74f97..eab94bc6221ac35ec3e23447394694245cbd0436 100644 (file)
@@ -1,25 +1,22 @@
-/**    
+/**
  * 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
@@ -32,51 +29,52 @@ import org.collectionspace.services.organization.OrganizationsCommon;
  * 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);
+    }
 }
index 38a8e6cf7c5e86a2c3960d7bd3408d5ee7d8f7c9..8c60df3b7cd9adaf8386f82196b19f36105f237a 100644 (file)
 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
@@ -239,7 +238,10 @@ public class OrgAuthorityClientUtils {
         \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
@@ -395,4 +397,8 @@ public class OrgAuthorityClientUtils {
         return terms;\r
     }\r
     \r
+    private static String getGeneratedIdentifier() {\r
+        return "id" + new Date().getTime(); \r
+   }\r
+    \r
 }\r
index 10ea216f9dbb3348aed4fd9bdb4b1e74a29fb8a8..524e2ee713b86add1c2bcef02121f18a9ba2f154 100644 (file)
@@ -53,8 +53,6 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl {
             "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() {
@@ -63,16 +61,16 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl {
 
     @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);
@@ -92,15 +90,15 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl {
 
     @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);
@@ -122,20 +120,20 @@ public class OrganizationValidatorHandler extends ValidatorHandlerImpl {
         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())) {
index ac2b502cacd838e9a4c005c857a3383bbf318531..47c12677fb8522a824477f3b56d00f49a7e07634 100644 (file)
@@ -1,17 +1,16 @@
-/**    
+/**
  * 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
@@ -24,56 +23,57 @@ import org.collectionspace.services.person.PersonsCommon;
  * 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);
+    }
 }
index 6507fbece2785c569ed70e505edc7f1c4f01913a..50563e42c2c29e66d9225c00143400d353cc1ced 100644 (file)
@@ -167,11 +167,11 @@ public class PersonAuthorityClientUtils {
                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
@@ -219,10 +219,12 @@ public class PersonAuthorityClientUtils {
         \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
index b088b4e900620c07537178660ce03304a2fb03bc..19ba74b1a56ac0bf38206c20c15b35050b0bd6fb 100644 (file)
@@ -55,8 +55,6 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl {
             "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() {
@@ -130,7 +128,7 @@ public class PersonValidatorHandler extends ValidatorHandlerImpl {
             return false;
         }
         List<PersonTermGroup> termGroups = termGroupList.getPersonTermGroup();
-        if ((termGroups == null) || (termGroups.size() == 0)) {
+        if ((termGroups == null) || (termGroups.isEmpty())) {
             return false;
         }
         return true;