From: Aron Roberts Date: Sat, 1 Oct 2011 00:49:43 +0000 (+0000) Subject: CSPACE-3178: Vocabulary service and various authority services now accept null or... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=d98339153d56fcd454e9b54855f4efa7e4f6884c;p=tmp%2Fjakarta-migration.git CSPACE-3178: Vocabulary service and various authority services now accept null or blank short identifiers in create payloads, when creating items (terms) in a vocabulary or authority, because (per other recent work on this issue) short identifiers are now generated if not supplied. When creating vocabularies (as opposed to terms within a vocabulary), short identifiers are still required, per Patrick. Short identifiers provided in update payloads are now ignored. --- diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index eb2ee39bc..8d923fd10 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -109,8 +109,9 @@ public abstract class AuthorityDocumentModelHandler } /** - * 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 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 diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 865d7c62e..4a8ea3ad4 100644 --- a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -219,10 +219,12 @@ public abstract class AuthorityItemDocumentModelHandler } /** - * 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 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 diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java index 50b2c4db2..5aa5ec9af 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java @@ -20,35 +20,11 @@ * 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); diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java index ba8f36684..09a4aa0bc 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java @@ -20,37 +20,10 @@ * 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); diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java index f20d9464b..88909ebd9 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationValidatorHandler.java @@ -15,40 +15,15 @@ * 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); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java index decd75b27..48c4ff7c6 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java @@ -15,38 +15,12 @@ * 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); diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java index ade5d8457..cde5cf21b 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonValidatorHandler.java @@ -15,43 +15,15 @@ * 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); diff --git a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java index 6fa78a93e..8a87d4f44 100644 --- a/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java +++ b/services/taxonomy/service/src/main/java/org/collectionspace/services/taxonomy/nuxeo/TaxonValidatorHandler.java @@ -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); diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java index 606351afc..f30b652f9 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyItemValidatorHandler.java @@ -20,32 +20,6 @@ * 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); diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java index d2681fb8e..02b06dd17 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java @@ -15,38 +15,12 @@ * 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);