From: Patrick Schmitz Date: Mon, 14 Jun 2010 05:30:06 +0000 (+0000) Subject: CSPACE-1152 and CSPACE-2126. Changed Vocabulary schema to include a shortIdentifier... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=32811b65e83b44240bea24891a6c13bd1069c96c;p=tmp%2Fjakarta-migration.git CSPACE-1152 and CSPACE-2126. Changed Vocabulary schema to include a shortIdentifier. This is now used as the basis of the refName. Added support to vocabulary for readByName. Added validatorHandler to require that shortIdentifier only contain word chars. --- 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 new file mode 100644 index 000000000..d2681fb8e --- /dev/null +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/nuxeo/VocabularyValidatorHandler.java @@ -0,0 +1,115 @@ +/** + * 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. + *//** + * 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.collectionspace.services.vocabulary.VocabulariesCommon; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class VocabularyValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(VocabularyValidatorHandler.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()) { + logger.debug("validate() action=" + action.name()); + } + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + VocabulariesCommon vocab = (VocabulariesCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + 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()) { + 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 + } + */ + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +}