KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > workflowtool > function > UserCreator


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.cms.applications.workflowtool.function;
24
25 import java.util.List JavaDoc;
26
27 import org.apache.log4j.Logger;
28 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy;
29 import org.infoglue.cms.entities.management.SystemUserVO;
30 import org.infoglue.cms.security.InfoGlueGroup;
31 import org.infoglue.cms.security.InfoGlueRole;
32
33 import com.opensymphony.workflow.WorkflowException;
34
35 public class UserCreator extends InfoglueFunction
36 {
37     private final static Logger logger = Logger.getLogger(UserCreator.class.getName());
38
39     /**
40      *
41      */

42     private static final String JavaDoc STATUS_OK = "status.user.ok";
43     
44     /**
45      *
46      */

47     private static final String JavaDoc STATUS_NOK = "status.user.nok";
48
49     /**
50      *
51      */

52     private SystemUserVO systemUserVO;
53     
54     /**
55      *
56      */

57     private String JavaDoc[] roleNames;
58     
59     /**
60      *
61      */

62     private String JavaDoc[] groupNames;
63     
64     /**
65      *
66      */

67     public UserCreator()
68     {
69         super();
70     }
71     
72     
73     /**
74      * Executes this function.
75      *
76      * @throws WorkflowException if an error occurs during the execution.
77      */

78     protected void execute() throws WorkflowException
79     {
80         setFunctionStatus(STATUS_NOK);
81         if(systemUserVO.validate().isEmpty())
82         {
83             try
84             {
85                 final UserControllerProxy controller = UserControllerProxy.getController(getDatabase());
86                 controller.createUser(systemUserVO);
87                 controller.updateUser(systemUserVO, roleNames, groupNames);
88                 setFunctionStatus(STATUS_OK);
89             }
90             catch(Exception JavaDoc e)
91             {
92                 throwException(e);
93             }
94         }
95     }
96
97     /**
98      *
99      */

100     private String JavaDoc[] getRoleNames(final List JavaDoc roles)
101     {
102         final String JavaDoc[] names = new String JavaDoc[roles.size()];
103         for(int i=0; i<roles.size(); ++i)
104         {
105             final InfoGlueRole role = (InfoGlueRole) roles.get(i);
106             names[i] = role.getName();
107             logger.debug("Adding role [" + role.getName() + "]");
108         }
109         return names;
110     }
111     
112     /**
113      *
114      */

115     private String JavaDoc[] getGroupNames(final List JavaDoc groups)
116     {
117         final String JavaDoc[] names = new String JavaDoc[groups.size()];
118         for(int i=0; i<groups.size(); ++i)
119         {
120             final InfoGlueGroup group = (InfoGlueGroup) groups.get(i);
121             names[i] = group.getName();
122             logger.debug("Adding group [" + group.getName() + "]");
123         }
124         return names;
125     }
126     
127     /**
128      * Method used for initializing the function; will be called before <code>execute</code> is called.
129      * <p><strong>Note</strong>! You must call <code>super.initialize()</code> first.</p>
130      *
131      * @throws WorkflowException if an error occurs during the initialization.
132      */

133     protected void initialize() throws WorkflowException
134     {
135         super.initialize();
136         this.systemUserVO = (SystemUserVO) getParameter(UserProvider.USER_PARAMETER);
137         this.roleNames = getRoleNames((List JavaDoc) getParameter(RolesProvider.ROLES_PARAMETER));
138         this.groupNames = getGroupNames((List JavaDoc) getParameter(GroupsProvider.GROUPS_PARAMETER));
139     }
140 }
141
Popular Tags