You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/01/04 17:45:32 UTC
svn commit: r124117 - lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases
Author: andreas
Date: Tue Jan 4 08:45:28 2005
New Revision: 124117
URL: http://svn.apache.org/viewcvs?view=rev&rev=124117
Log:
group admin using usecase framework
Added:
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddGroup.java
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddIPRange.java
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/DeleteUser.java
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupMembers.java
lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupProfile.java
Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddGroup.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddGroup.java?view=auto&rev=124117
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddGroup.java Tue Jan 4 08:45:28 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import java.io.File;
+
+import org.apache.lenya.ac.Group;
+import org.apache.lenya.ac.file.FileGroup;
+import org.apache.lenya.ac.file.FileGroupManager;
+import org.apache.lenya.ac.impl.AbstractItem;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to add a group.
+ *
+ * @version $Id:$
+ */
+public class AddGroup extends AccessControlUsecase {
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
+ */
+ protected void doCheckExecutionConditions() throws Exception {
+ validate();
+ }
+
+ /**
+ * Validates the request parameters.
+ * @throws UsecaseException if an error occurs.
+ */
+ void validate() throws UsecaseException {
+
+ String groupId = getParameterAsString(GroupProfile.ID);
+
+ Group existingGroup = getGroupManager().getGroup(groupId);
+
+ if (existingGroup != null) {
+ addErrorMessage("This group already exists.");
+ }
+
+ if (!AbstractItem.isValidId(groupId)) {
+ addErrorMessage("This is not a valid group ID.");
+ }
+
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ String id = getParameterAsString(GroupProfile.ID);
+ String name = getParameterAsString(GroupProfile.NAME);
+ String description = getParameterAsString(GroupProfile.DESCRIPTION);
+
+ File configDir = ((FileGroupManager) getGroupManager()).getConfigurationDirectory();
+ Group group = new FileGroup(configDir, id);
+ group.setName(name);
+ group.setDescription(description);
+
+ group.save();
+ getGroupManager().add(group);
+ }
+
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddIPRange.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddIPRange.java?view=auto&rev=124117
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/AddIPRange.java Tue Jan 4 08:45:28 2005
@@ -0,0 +1,79 @@
+/*
+ * Created on 04.01.2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import java.io.File;
+
+import org.apache.lenya.ac.IPRange;
+import org.apache.lenya.ac.file.FileIPRange;
+import org.apache.lenya.ac.file.FileIPRangeManager;
+import org.apache.lenya.ac.impl.AbstractItem;
+import org.apache.lenya.cms.ac.usecases.IPRangeProfile.Part;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to add an IP range.
+ *
+ * @version $Id:$
+ */
+public class AddIPRange extends AccessControlUsecase {
+
+ /**
+ * Validates the request parameters.
+ * @throws UsecaseException if an error occurs.
+ */
+ void validate() throws UsecaseException {
+
+ String id = getParameterAsString(IPRangeProfile.ID);
+
+ IPRange existingIPRange = getIpRangeManager().getIPRange(id);
+
+ if (existingIPRange != null) {
+ addErrorMessage("This IP range already exists.");
+ }
+
+ if (!AbstractItem.isValidId(id)) {
+ addErrorMessage("This is not a valid IP range ID.");
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
+ */
+ protected void doCheckExecutionConditions() throws Exception {
+ validate();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ File configDir = ((FileIPRangeManager) getIpRangeManager()).getConfigurationDirectory();
+
+ String id = getParameterAsString(IPRangeProfile.ID);
+ String name = getParameterAsString(IPRangeProfile.NAME);
+ String description = getParameterAsString(IPRangeProfile.DESCRIPTION);
+
+ IPRange ipRange = new FileIPRange(configDir, id);
+ ipRange.setName(name);
+
+ ipRange.setDescription(description);
+ ipRange.save();
+ getIpRangeManager().add(ipRange);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+ */
+ protected void initParameters() {
+ super.initParameters();
+ for (byte i = 0; i < 4; i++) {
+ setParameter(IPRangeProfile.NETWORK_ADDRESS + "-" + i, new Part(i));
+ setParameter(IPRangeProfile.SUBNET_MASK + "-" + i, new Part(i));
+ }
+ }
+}
\ No newline at end of file
Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/DeleteUser.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/DeleteUser.java?view=auto&rev=124117
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/DeleteUser.java Tue Jan 4 08:45:28 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import org.apache.lenya.ac.User;
+
+/**
+ * Usecase to delete a user.
+ *
+ * @version $Id:$
+ */
+public class DeleteUser extends AccessControlUsecase {
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ String userId = getParameterAsString(UserProfile.USER_ID);
+ User user = getUserManager().getUser(userId);
+ if (user == null) {
+ throw new RuntimeException("User [" + userId + "] not found.");
+ }
+
+ getUserManager().remove(user);
+ user.delete();
+ }
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupMembers.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupMembers.java?view=auto&rev=124117
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupMembers.java Tue Jan 4 08:45:28 2005
@@ -0,0 +1,141 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.lenya.ac.Group;
+import org.apache.lenya.ac.Groupable;
+import org.apache.lenya.ac.User;
+
+/**
+ * Usecase to change the members of a group.
+ *
+ * @version $Id:$
+ */
+public class GroupMembers extends AccessControlUsecase {
+
+ private Group group;
+
+ protected static final String GROUP_USERS = "groupUsers";
+ protected static final String OTHER_USERS = "otherUsers";
+ protected static final String ADD = "add";
+ protected static final String REMOVE = "remove";
+ protected static final String GROUP_USER = "groupUser";
+ protected static final String OTHER_USER = "otherUser";
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ this.group.removeAllMembers();
+
+ List groupUsers = (List) getParameter(GROUP_USERS);
+ for (Iterator i = groupUsers.iterator(); i.hasNext(); ) {
+ User user = (User) i.next();
+ this.group.add(user);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#advance()
+ */
+ public void advance() {
+ super.advance();
+
+ String add = getParameterAsString(ADD);
+ String remove = getParameterAsString(REMOVE);
+ if (add != null || remove != null) {
+
+ List groupUsers = (List) getParameter(GROUP_USERS);
+ List otherUsers = (List) getParameter(OTHER_USERS);
+
+ if (add != null) {
+ String userId = getParameterAsString(OTHER_USER);
+ if (userId != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("add user [" + userId + "]");
+ }
+ User user = getUserManager().getUser(userId);
+ groupUsers.add(user);
+ otherUsers.remove(user);
+ }
+ }
+
+ if (remove != null) {
+ String userId = getParameterAsString(GROUP_USER);
+ if (userId != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("remove user [" + userId + "]");
+ }
+ User user = getUserManager().getUser(userId);
+ otherUsers.add(user);
+ groupUsers.remove(user);
+ }
+ }
+
+ deleteParameter(ADD);
+ deleteParameter(REMOVE);
+ deleteParameter(GROUP_USER);
+ deleteParameter(OTHER_USER);
+ }
+
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String,
+ * java.lang.Object)
+ */
+ public void setParameter(String name, Object value) {
+ super.setParameter(name, value);
+ if (name.equals(GroupProfile.ID)) {
+ String groupId = (String) value;
+ this.group = getGroupManager().getGroup(groupId);
+ if (this.group == null) {
+ throw new RuntimeException("Group [" + groupId + "] not found.");
+ }
+
+ Groupable[] members = this.group.getMembers();
+ List groupUsers = new ArrayList();
+ for (int i = 0; i < members.length; i++) {
+ if (members[i] instanceof User) {
+ groupUsers.add(members[i]);
+ }
+ }
+ setParameter(GROUP_USERS, groupUsers);
+
+ User[] allUsers = getUserManager().getUsers();
+
+ List otherUsers = new ArrayList();
+
+ for (int i = 0; i < allUsers.length; i++) {
+ if (!groupUsers.contains(allUsers[i])) {
+ otherUsers.add(allUsers[i]);
+ }
+ }
+
+ setParameter(OTHER_USERS, otherUsers);
+ }
+
+ }
+
+
+}
Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupProfile.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupProfile.java?view=auto&rev=124117
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/GroupProfile.java Tue Jan 4 08:45:28 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.ac.usecases;
+
+import org.apache.lenya.ac.Group;
+
+/**
+ * Usecase to change the profile of a group.
+ *
+ * @version $Id:$
+ */
+public class GroupProfile extends AccessControlUsecase {
+
+ protected static final String ID = "groupId";
+ protected static final String NAME = "name";
+ protected static final String DESCRIPTION = "description";
+
+ private Group group;
+
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ String name = getParameterAsString(NAME);
+ String description = getParameterAsString(DESCRIPTION);
+
+ this.group.setName(name);
+ this.group.setDescription(description);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
+ */
+ public void setParameter(String name, Object value) {
+ super.setParameter(name, value);
+
+ if (name.equals(ID)) {
+ String id = (String) value;
+ this.group = getGroupManager().getGroup(id);
+ if (this.group == null) {
+ throw new RuntimeException("Group [" + id + "] not found.");
+ }
+
+ setParameter(DESCRIPTION, this.group.getDescription());
+ setParameter(NAME, this.group.getName());
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org