]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9686fc6175fa9b50b585a552473ecb34a4833c44
[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 package org.collectionspace.services.authorization.storage;
48
49 import org.collectionspace.services.authorization.Role;
50 import org.collectionspace.services.common.context.ServiceContext;
51 import org.collectionspace.services.common.document.DocumentHandler.Action;
52 import org.collectionspace.services.common.document.InvalidDocumentException;
53 import org.collectionspace.services.common.document.ValidatorHandler;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56
57 /**
58  * RoleValidatorHandler executes validation rules for role
59  * @author 
60  */
61 public class RoleValidatorHandler implements ValidatorHandler {
62
63     final Logger logger = LoggerFactory.getLogger(RoleValidatorHandler.class);
64
65     @Override
66     public void validate(Action action, ServiceContext ctx)
67             throws InvalidDocumentException {
68         if (logger.isDebugEnabled()) {
69             logger.debug("validate() action=" + action.name());
70         }
71         try {
72             Role role = (Role) ctx.getInput();
73             StringBuilder msgBldr = new StringBuilder("validate() ");
74             boolean invalid = false;
75
76             if (action.equals(Action.CREATE)) {
77
78                 //create specific validation here
79                 if (role.getRoleName() == null || role.getRoleName().isEmpty()) {
80                     invalid = true;
81                     msgBldr.append("\nroleName : missing");
82                 }
83             } else if (action.equals(Action.UPDATE)) {
84                 //update specific validation here
85                 if (role.getRoleName() != null && role.getRoleName().isEmpty()) {
86                     invalid = true;
87                     msgBldr.append("\nroleName : cannot be changed!");
88                 }
89             }
90             if (invalid) {
91                 String msg = msgBldr.toString();
92                 logger.error(msg);
93                 throw new InvalidDocumentException(msg);
94             }
95         } catch (InvalidDocumentException ide) {
96             throw ide;
97         } catch (Exception e) {
98             throw new InvalidDocumentException(e);
99         }
100     }
101
102 }