01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.ac.usecases;
19:
20: import org.apache.lenya.ac.Group;
21: import org.apache.lenya.ac.ItemUtil;
22: import org.apache.lenya.cms.usecase.UsecaseException;
23:
24: /**
25: * Usecase to add a group.
26: *
27: * @version $Id: AddGroup.java 407305 2006-05-17 16:21:49Z andreas $
28: */
29: public class AddGroup extends AccessControlUsecase {
30:
31: /**
32: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
33: */
34: protected void doCheckExecutionConditions() throws Exception {
35: validate();
36: }
37:
38: /**
39: * Validates the request parameters.
40: * @throws UsecaseException if an error occurs.
41: */
42: void validate() throws UsecaseException {
43:
44: String groupId = getParameterAsString(GroupProfile.ID);
45:
46: Group existingGroup = getGroupManager().getGroup(groupId);
47:
48: if (existingGroup != null) {
49: addErrorMessage("This group already exists.");
50: }
51:
52: if (!ItemUtil.isValidId(groupId)) {
53: addErrorMessage("This is not a valid group ID.");
54: }
55:
56: }
57:
58: /**
59: * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
60: */
61: protected void doExecute() throws Exception {
62: super .doExecute();
63:
64: String id = getParameterAsString(GroupProfile.ID);
65: String name = getParameterAsString(GroupProfile.NAME);
66: String description = getParameterAsString(GroupProfile.DESCRIPTION);
67:
68: Group group = getGroupManager().add(id);
69: group.setName(name);
70: group.setDescription(description);
71:
72: group.save();
73:
74: setExitParameter(GroupProfile.ID, id);
75: }
76:
77: }
|