]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6fa78a93e5736bec9e2a623f898c90548b7717fe
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.taxonomy.nuxeo;
25
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;
34
35 /**
36  *
37  * @author 
38  */
39 public class TaxonValidatorHandler implements ValidatorHandler {
40
41     final Logger logger = LoggerFactory.getLogger(TaxonValidatorHandler.class);
42
43     @Override
44     public void validate(Action action, ServiceContext ctx)
45             throws InvalidDocumentException {
46         if(logger.isDebugEnabled()) {
47             logger.debug("validate() action=" + action.name());
48         }
49         try {
50             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
51             TaxonCommon taxonomy = (TaxonCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
52                     TaxonCommon.class);
53             String msg = "";
54             boolean invalid = false;
55             if(!taxonomy.isDisplayNameComputed() && (taxonomy.getDisplayName()==null)) {
56                 invalid = true;
57                 msg += "displayName must be non-null if displayNameComputed is false!";
58             }
59             /*
60             if(action.equals(Action.CREATE)) {
61                 //create specific validation here
62             } else if(action.equals(Action.UPDATE)) {
63                 //update specific validation here
64             }
65             */
66
67             if (invalid) {
68                 logger.error(msg);
69                 throw new InvalidDocumentException(msg);
70             }
71         } catch (InvalidDocumentException ide) {
72             throw ide;
73         } catch (Exception e) {
74             throw new InvalidDocumentException(e);
75         }
76     }
77 }