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 * 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:
28 * http://www.collectionspace.org
29 * http://wiki.collectionspace.org
31 * Copyright 2009 University of California at Berkeley
33 * Licensed under the Educational Community License (ECL), Version 2.0.
34 * You may not use this file except in compliance with this License.
36 * You may obtain a copy of the ECL 2.0 License at
38 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
47 * To change this template, choose Tools | Templates
48 * and open the template in the editor.
50 package org.collectionspace.services.authorization.storage;
52 import org.collectionspace.services.authorization.Role;
53 import org.collectionspace.services.common.context.ServiceContext;
54 import org.collectionspace.services.common.document.DocumentHandler.Action;
55 import org.collectionspace.services.common.document.InvalidDocumentException;
56 import org.collectionspace.services.common.document.ValidatorHandler;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
61 * RoleValidatorHandler executes validation rules for role
64 public class RoleValidatorHandler implements ValidatorHandler {
66 final Logger logger = LoggerFactory.getLogger(RoleValidatorHandler.class);
69 public void validate(Action action, ServiceContext ctx)
70 throws InvalidDocumentException {
71 if (logger.isDebugEnabled()) {
72 logger.debug("validate() action=" + action.name());
75 Role role = (Role) ctx.getInput();
76 StringBuilder msgBldr = new StringBuilder("validate() ");
77 boolean invalid = false;
79 if (action.equals(Action.CREATE)) {
81 //create specific validation here
82 if (role.getRoleName() == null || role.getRoleName().isEmpty()) {
84 msgBldr.append("\nroleName : missing");
86 } else if (action.equals(Action.UPDATE)) {
87 //update specific validation here
88 if (role.getRoleName() != null && role.getRoleName().isEmpty()) {
90 msgBldr.append("\nroleName : cannot be changed!");
94 String msg = msgBldr.toString();
96 throw new InvalidDocumentException(msg);
98 } catch (InvalidDocumentException ide) {
100 } catch (Exception e) {
101 throw new InvalidDocumentException(e);