2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.taxonomy.nuxeo;
26 import org.collectionspace.services.taxonomy.TaxonCommon;
27 import org.collectionspace.services.common.context.MultipartServiceContext;
28 import org.collectionspace.services.common.context.ServiceContext;
29 import org.collectionspace.services.common.document.DocumentHandler.Action;
30 import org.collectionspace.services.common.document.InvalidDocumentException;
31 import org.collectionspace.services.common.document.ValidatorHandler;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
39 public class TaxonomyValidatorHandler implements ValidatorHandler {
41 final Logger logger = LoggerFactory.getLogger(TaxonomyValidatorHandler.class);
44 public void validate(Action action, ServiceContext ctx)
45 throws InvalidDocumentException {
46 if(logger.isDebugEnabled()) {
47 logger.debug("validate() action=" + action.name());
50 MultipartServiceContext mctx = (MultipartServiceContext) ctx;
51 TaxonCommon taxonomy = (TaxonCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
54 boolean invalid = false;
55 if(!taxonomy.isDisplayNameComputed() && (taxonomy.getDisplayName()==null)) {
57 msg += "displayName must be non-null if displayNameComputed is false!";
60 if(action.equals(Action.CREATE)) {
61 //create specific validation here
62 } else if(action.equals(Action.UPDATE)) {
63 //update specific validation here
69 throw new InvalidDocumentException(msg);
71 } catch (InvalidDocumentException ide) {
73 } catch (Exception e) {
74 throw new InvalidDocumentException(e);