}
/**
- * 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
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
}
/**
- * 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
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
* 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;
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 {
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);
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *//**
- * This document is a part of the source code and related artifacts
- * for CollectionSpace, an open source collections management system
- * for museums and related institutions:
-
- * http://www.collectionspace.org
- * http://wiki.collectionspace.org
-
- * Copyright 2009 University of California at Berkeley
-
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
-
- * You may obtain a copy of the ECL 2.0 License at
-
- * https://source.collectionspace.org/collection-space/LICENSE.txt
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
*/
package org.collectionspace.services.organization.nuxeo;
import java.util.regex.Pattern;
-
import org.collectionspace.services.organization.OrgauthoritiesCommon;
import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
import org.slf4j.LoggerFactory;
/**
- *
- * @author
+ * OrgAuthorityValidatorHandler
+ *
+ * Validates data supplied when attempting to create and/or update OrgAuthority records.
+ *
+ * $LastChangedRevision$
+ * $LastChangedDate$
*/
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);
* 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;
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 {
@Override
public void validate(Action action, ServiceContext ctx)
throws InvalidDocumentException {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("validate() action=" + action.name());
}
try {
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);
* 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.slf4j.LoggerFactory;
/**
- *
- * @author
+ * PersonAuthorityValidatorHandler
+ *
+ * Validates data supplied when attempting to create and/or update PersonAuthority records.
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
*/
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);
* 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;
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 {
@Override
public void validate(Action action, ServiceContext ctx)
throws InvalidDocumentException {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("validate() action=" + action.name());
}
try {
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);
*/
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;
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);
* 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 org.slf4j.LoggerFactory;
/**
- *
- * @author
+ * VocabularyItemValidatorHandler
+ *
+ * Validates data supplied when attempting to create and/or update VocabularyItem records.
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
*/
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 {
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);
* 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;
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 {
@Override
public void validate(Action action, ServiceContext ctx)
throws InvalidDocumentException {
- if(logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("validate() action=" + action.name());
}
try {
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);