]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3178: Vocabulary service and various authority services now accept null or...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 1 Oct 2011 00:49:43 +0000 (00:49 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 1 Oct 2011 00:49:43 +0000 (00:49 +0000)
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java
services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java

index eb2ee39bc482e41ed23a5f7c995b41261936421d..8d923fd103bb6e0166bdd790a758572e50203a3e 100644 (file)
@@ -109,8 +109,9 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
     }
 
     /**
-     * Filters out values supplied in the request
-     * @param objectProps the properties parsed from the update payload
+     * Filters out selected values supplied in an update request.
+     * 
+     * @param objectProps the properties filtered out from the update payload
      * @param partMeta metadata for the object to fill
      */
     @Override
@@ -120,6 +121,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
         String commonPartLabel = getServiceContext().getCommonPartLabel();
         if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
             objectProps.remove(AuthorityJAXBSchema.CSID);
+            objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
             // Enable when clients should no longer supply refName values
             // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178
 
index 865d7c62e4282df63b27a8cb3588f213972d6f47..4a8ea3ad47343752630dee7effe389fc50f8515f 100644 (file)
@@ -219,10 +219,12 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     }
 
     /**
-     * Filters out values supplied in the request; e.g.:
-     * AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure that
-     * the parent link remains untouched.
-     * @param objectProps the properties parsed from the update payload
+     * Filters out selected values supplied in an update request.
+     * 
+     * For example, filters out AuthorityItemJAXBSchema.IN_AUTHORITY, to ensure
+     * that the link to the item's parent remains untouched.
+     * 
+     * @param objectProps the properties filtered out from the update payload
      * @param partMeta metadata for the object to fill
      */
     @Override
@@ -233,6 +235,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
             objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
             objectProps.remove(AuthorityItemJAXBSchema.CSID);
+            objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
             // Enable when clients should no longer supply refName values
             // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178
 
index 50b2c4db254f519d07551d3ceb21b45f0483954a..5aa5ec9af2e5fb79b026731efa5d81b88acabc21 100644 (file)
  *  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.location.nuxeo;
 
+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;
@@ -59,17 +35,22 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * LocationValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update Location records.
+ * 
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
  */
 public class LocationValidatorHandler implements ValidatorHandler {
 
     final Logger logger = LoggerFactory.getLogger(LocationValidatorHandler.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()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
@@ -78,17 +59,27 @@ public class LocationValidatorHandler implements ValidatorHandler {
                     LocationsCommon.class);
             String msg = "";
             boolean invalid = false;
-            if(!location.isDisplayNameComputed() && (location.getDisplayName()==null)) {
+
+            // 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 if displayNameComputed is false!";
+                msg += "displayName must be non-null and non-blank if displayNameComputed is false";
             }
-            /*
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
+
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                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";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index ba8f366843fe8957f95abe9a4cf06ae55e6b2b4a..09a4aa0bc342fb6bbd48259ce68093cc2cc7c083 100644 (file)
  *  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;
@@ -61,8 +34,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * OrgAuthorityValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update OrgAuthority records.
+ * 
+ * $LastChangedRevision$
+ * $LastChangedDate$
  */
 public class OrgAuthorityValidatorHandler implements ValidatorHandler {
 
@@ -72,32 +49,34 @@ public class OrgAuthorityValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
-            OrgauthoritiesCommon organizationAuth = 
-                                                       (OrgauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+            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
-            }
-            */
 
+            // Create-specific validation here
+            if (action.equals(Action.CREATE)) {
+                String shortId = organizationAuth.getShortIdentifier();
+                if (shortId == null) {
+                    invalid = true;
+                    msg += "shortIdentifier must be non-null";
+                } else if (shortId.trim().isEmpty()) {
+                    invalid = true;
+                    msg += "shortIdentifier must have a non-empty value";
+                } else if (shortIdBadPattern.matcher(shortId).find()) {
+                    invalid = true;
+                    msg += "shortIdentifier must only contain standard word characters";
+                }
+            // Update-specific validation here
+            } else if (action.equals(Action.UPDATE)) {
+            }
+            
             if (invalid) {
                 logger.error(msg);
                 throw new InvalidDocumentException(msg);
index f20d9464b4010d33c5872aba96c5f2ac1d34688f..88909ebd96590e49d729fbf0e05c24cf057eba12 100644 (file)
 
  *  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.OrganizationsCommon;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -57,11 +32,14 @@ import org.collectionspace.services.common.document.InvalidDocumentException;
 import org.collectionspace.services.common.document.ValidatorHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import java.util.regex.Pattern;
 
 /**
- *
- * @author 
+ * OrganizationValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update Organization records.
+ * 
+ * $LastChangedRevision$
+ * $LastChangedDate$
  */
 public class OrganizationValidatorHandler implements ValidatorHandler {
 
@@ -71,7 +49,7 @@ public class OrganizationValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
@@ -80,25 +58,27 @@ public class OrganizationValidatorHandler implements ValidatorHandler {
                     OrganizationsCommon.class);
             String msg = "";
             boolean invalid = false;
-            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()) {
+            
+            // Validation occurring on both creates and updates
+            String displayName = org.getDisplayName();
+            if (!org.isDisplayNameComputed()  && ((displayName == null) || displayName.trim().isEmpty())) {
                 invalid = true;
-                msg += "shortIdentifier must only contain standard word characters";
+                msg += "displayName must be non-null and non-blank if displayNameComputed is false";
             }
-            /*
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
+            
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = org.getShortIdentifier();
+                // Per CSPACE-2215, shortIdentifier values that are null (missing)
+                // or 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";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index decd75b270f382b8728ebc72bea643c6ac69751f..48c4ff7c634fac213429e93d8198843cd12c852d 100644 (file)
 
  *  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;
@@ -61,8 +35,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * PersonAuthorityValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update PersonAuthority records.
+ * 
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
  */
 public class PersonAuthorityValidatorHandler implements ValidatorHandler {
 
@@ -72,31 +50,32 @@ public class PersonAuthorityValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
-            PersonauthoritiesCommon personAuth = 
-                                                       (PersonauthoritiesCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+            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
+
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = personAuth.getShortIdentifier();
+                if (shortId == null) {
+                    invalid = true;
+                    msg += "shortIdentifier must be non-null";
+                } else if (shortId.trim().isEmpty()) {
+                    invalid = true;
+                    msg += "shortIdentifier must have a non-empty value";
+                } else if (shortIdBadPattern.matcher(shortId).find()) {
+                    invalid = true;
+                    msg += "shortIdentifier must only contain standard word characters";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index ade5d8457c31de076ac16e749c81ff91b1b2b4e8..cde5cf21b4d8be9f86e97430a9e2a7ee7bacbdc4 100644 (file)
 
  *  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.common.api.Tools;
 import org.collectionspace.services.person.PersonsCommon;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -62,8 +34,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * PersonValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update Person records.
+ * 
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
  */
 public class PersonValidatorHandler implements ValidatorHandler {
 
@@ -73,7 +49,7 @@ public class PersonValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
@@ -81,33 +57,28 @@ public class PersonValidatorHandler implements ValidatorHandler {
             PersonsCommon person = (PersonsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
                     PersonsCommon.class);
             String msg = "";
-            String displayName = person.getDisplayName();
             boolean invalid = false;
-            if(!person.isDisplayNameComputed() && (displayName==null)) {
+            
+            // Validation occurring on both creates and updates
+            String displayName = person.getDisplayName();
+            if (!person.isDisplayNameComputed() && ((displayName == null) || displayName.trim().isEmpty())) {
                 invalid = true;
-                msg += "displayName must be non-null if displayNameComputed is false!";
+                msg += "displayName must be non-null and non-blank if displayNameComputed is false!";
             }
-            String shortId = person.getShortIdentifier();
-
-            if(shortId==null){
-                if (Tools.notEmpty(displayName)){  //TODO: && action == CREATE   ......
-                    //CSPACE-3178  OK to have null shortIdentifier if displayName set, because we will compute the shortIdentifier before storing.
-                    invalid = false;
-                } else {
+            
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = person.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 be non-null";
+                    msg += "shortIdentifier must only contain standard word characters";
                 }
-            } 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
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index 6fa78a93e5736bec9e2a623f898c90548b7717fe..8a87d4f44d92f4f0356a560fd982c98845c7bd72 100644 (file)
@@ -23,6 +23,7 @@
  */
 package org.collectionspace.services.taxonomy.nuxeo;
 
+import java.util.regex.Pattern;
 import org.collectionspace.services.taxonomy.TaxonCommon;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -33,36 +34,51 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * TaxonValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update Taxon records.
+ * 
+ * $LastChangedRevision$
+ * $LastChangedDate$
  */
 public class TaxonValidatorHandler implements ValidatorHandler {
 
     final Logger logger = LoggerFactory.getLogger(TaxonValidatorHandler.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()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
-            TaxonCommon taxonomy = (TaxonCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+            TaxonCommon taxon = (TaxonCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
                     TaxonCommon.class);
             String msg = "";
             boolean invalid = false;
-            if(!taxonomy.isDisplayNameComputed() && (taxonomy.getDisplayName()==null)) {
+
+            // Validation occurring on both creates and updates
+            String displayName = taxon.getDisplayName();
+            if (!taxon.isDisplayNameComputed() && ((displayName == null) || displayName.trim().isEmpty())) {
                 invalid = true;
-                msg += "displayName must be non-null if displayNameComputed is false!";
+                msg += "displayName must be non-null and non-blank if displayNameComputed is false";
             }
-            /*
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
+
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = taxon.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";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index 606351afc0ac8ee235d4376adfd8644a6310b75a..f30b652f923b6c054889690ae0acc4d54306ff8b 100644 (file)
  *  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.vocabulary.nuxeo;
 
@@ -61,8 +35,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * VocabularyItemValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update VocabularyItem records.
+ * 
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
  */
 public class VocabularyItemValidatorHandler implements ValidatorHandler {
 
@@ -72,7 +50,7 @@ public class VocabularyItemValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
@@ -81,26 +59,27 @@ public class VocabularyItemValidatorHandler implements ValidatorHandler {
                     VocabularyitemsCommon.class);
             String msg = "";
             boolean invalid = false;
-                       String displayName = vocabItem.getDisplayName();
-            if((displayName==null)||(displayName.length()<2)) {
-                invalid = true;
-                msg += "displayName must be non-null, and at least 2 chars long!";
-            }
-                       String shortId = vocabItem.getShortIdentifier();
-            if(shortId==null){
-                invalid = true;
-                msg += "shortIdentifier must be non-null";
-            } else if(shortIdBadPattern.matcher(shortId).find()) {
+            
+            // Validation occurring on both creates and updates
+            String displayName = vocabItem.getDisplayName();
+            if ((displayName == null) || (displayName.trim().length() < 2)) {
                 invalid = true;
-                msg += "shortIdentifier must only contain standard word characters";
+                msg += "displayName must be non-null and contain at least 2 non-whitespace characters";
             }
-            /*
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
+            
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = vocabItem.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";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);
index d2681fb8e48fb24bec41d5d311d656eeb1fceab0..02b06dd1765dccdd9cdd3eaa088a82377e221749 100644 (file)
 
  *  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.vocabulary.nuxeo;
 
 import java.util.regex.Pattern;
@@ -61,8 +35,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- *
- * @author 
+ * VocabularyValidatorHandler
+ * 
+ * Validates data supplied when attempting to create and/or update Vocabulary records.
+ * 
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
  */
 public class VocabularyValidatorHandler implements ValidatorHandler {
 
@@ -72,7 +50,7 @@ public class VocabularyValidatorHandler implements ValidatorHandler {
     @Override
     public void validate(Action action, ServiceContext ctx)
             throws InvalidDocumentException {
-        if(logger.isDebugEnabled()) {
+        if (logger.isDebugEnabled()) {
             logger.debug("validate() action=" + action.name());
         }
         try {
@@ -81,26 +59,27 @@ public class VocabularyValidatorHandler implements ValidatorHandler {
                     VocabulariesCommon.class);
             String msg = "";
             boolean invalid = false;
-                       String displayName = vocab.getDisplayName();
-            if((displayName==null)||(displayName.length()<2)) {
-                invalid = true;
-                msg += "displayName must be non-null, and at least 2 chars long!";
-            }
-                       String shortId = vocab.getShortIdentifier();
-            if(shortId==null){
-                invalid = true;
-                msg += "shortIdentifier must be non-null";
-            } else if(shortIdBadPattern.matcher(shortId).find()) {
+
+            // Validation occurring on both creates and updates
+            String displayName = vocab.getDisplayName();
+            if ((displayName == null) || (displayName.trim().length() < 2)) {
                 invalid = true;
-                msg += "shortIdentifier must only contain standard word characters";
+                msg += "displayName must be non-null and contain at least 2 non-whitespace characters";
             }
-            /*
-            if(action.equals(Action.CREATE)) {
-                //create specific validation here
-            } else if(action.equals(Action.UPDATE)) {
-                //update specific validation here
+
+            // Validation specific to creates or updates
+            if (action.equals(Action.CREATE)) {
+                String shortId = vocab.getShortIdentifier();
+                // Per CSPACE-2215, shortIdentifier values that are null (missing)
+                // or 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";
+                }
+            } else if (action.equals(Action.UPDATE)) {
             }
-            */
 
             if (invalid) {
                 logger.error(msg);