]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2a5b61e05ee5b7b5c38e132a76dad90264b074df
[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  *  This document is a part of the source code and related artifacts
25  *  for CollectionSpace, an open source collections management system
26  *  for museums and related institutions:
27
28  *  http://www.collectionspace.org
29  *  http://wiki.collectionspace.org
30
31  *  Copyright 2009 University of California at Berkeley
32
33  *  Licensed under the Educational Community License (ECL), Version 2.0.
34  *  You may not use this file except in compliance with this License.
35
36  *  You may obtain a copy of the ECL 2.0 License at
37
38  *  https://source.collectionspace.org/collection-space/LICENSE.txt
39
40  *  Unless required by applicable law or agreed to in writing, software
41  *  distributed under the License is distributed on an "AS IS" BASIS,
42  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43  *  See the License for the specific language governing permissions and
44  *  limitations under the License.
45  */
46 /*
47  * To change this template, choose Tools | Templates
48  * and open the template in the editor.
49  */
50 package org.collectionspace.services.account.storage;
51
52 import java.util.List;
53 import java.util.regex.Matcher;
54 import java.util.regex.Pattern;
55
56 import org.apache.commons.lang.StringUtils;
57 import org.collectionspace.services.account.Tenant;
58 import org.collectionspace.services.common.ServiceMessages;
59 import org.collectionspace.services.common.context.ServiceContext;
60 import org.collectionspace.services.common.document.DocumentHandler.Action;
61 import org.collectionspace.services.common.document.DocumentNotFoundException;
62 import org.collectionspace.services.common.document.InvalidDocumentException;
63 import org.collectionspace.services.common.document.ValidatorHandler;
64 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68 /**
69  *
70  * @author 
71  */
72 public class TenantValidatorHandler implements ValidatorHandler {
73
74     final Logger logger = LoggerFactory.getLogger(AccountValidatorHandler.class);
75
76     @Override
77     public void validate(Action action, ServiceContext ctx)
78             throws InvalidDocumentException {
79         if (logger.isDebugEnabled()) {
80             logger.debug("validate() action=" + action.name());
81         }
82         try {
83             Tenant tenant = (Tenant) ctx.getInput();
84             StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE);
85             boolean invalid = false;
86
87             if (action.equals(Action.CREATE)) {
88
89                 //create specific validation here
90                 if (StringUtils.isEmpty(tenant.getId())) {
91                     invalid = true;
92                     msgBldr.append("\nId : missing");
93                 }
94                 if (StringUtils.isEmpty(tenant.getName())) {
95                     invalid = true;
96                     msgBldr.append("\nName : missing");
97                 }
98             } else if (action.equals(Action.UPDATE)) {
99                 //update specific validation here
100                 if (StringUtils.isEmpty(tenant.getName())) {
101                     invalid = true;
102                     msgBldr.append("\nName : missing");
103                 }
104             }
105             if (invalid) {
106                 String msg = msgBldr.toString();
107                 logger.error(msg);
108                 throw new InvalidDocumentException(msg);
109             }
110         } catch (InvalidDocumentException ide) {
111             throw ide;
112         } catch (Exception e) {
113             throw new InvalidDocumentException(e);
114         }
115     }
116
117
118 }