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.
26 package org.collectionspace.services.authorization.storage;
28 import org.collectionspace.services.authorization.Role;
29 import org.collectionspace.services.common.ServiceMessages;
30 import org.collectionspace.services.common.context.ServiceContext;
31 import org.collectionspace.services.common.document.DocumentHandler.Action;
32 import org.collectionspace.services.common.document.InvalidDocumentException;
33 import org.collectionspace.services.common.document.ValidatorHandler;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * RoleValidatorHandler executes validation rules for role
41 public class RoleValidatorHandler implements ValidatorHandler {
43 final Logger logger = LoggerFactory.getLogger(RoleValidatorHandler.class);
46 public void validate(Action action, ServiceContext ctx)
47 throws InvalidDocumentException {
48 if (logger.isDebugEnabled()) {
49 logger.debug("validate() action=" + action.name());
52 Role role = (Role) ctx.getInput();
53 StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE);
54 boolean invalid = false;
56 if (action.equals(Action.CREATE)) {
58 //create specific validation here
59 if (role.getRoleName() == null || role.getRoleName().isEmpty()) {
61 msgBldr.append("\nroleName : missing or empty");
63 } else if (action.equals(Action.UPDATE)) {
64 //update specific validation here
65 if (role.getRoleName() == null || role.getRoleName().isEmpty()) {
67 msgBldr.append("\nroleName : cannot be missing or empty");
71 String msg = msgBldr.toString();
73 throw new InvalidDocumentException(msg);
75 } catch (InvalidDocumentException ide) {
77 } catch (Exception e) {
78 throw new InvalidDocumentException(e);