KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > util > BonitaProjectLocator


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: BonitaProjectLocator.java,v 1.3 2005/03/30 15:19:45 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.util;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.util.HashMap JavaDoc;
37
38 import hero.interfaces.BnEdgeLocal;
39 import hero.interfaces.BnIterationLocal;
40 import hero.interfaces.BnNodeHookLocal;
41 import hero.interfaces.BnNodeInterHookLocal;
42 import hero.interfaces.BnNodeLocal;
43 import hero.interfaces.BnNodePropertyLocal;
44 import hero.interfaces.BnProjectHookLocal;
45 import hero.interfaces.BnProjectInterHookLocal;
46 import hero.interfaces.BnProjectLocal;
47 import hero.interfaces.BnProjectLocalHome;
48 import hero.interfaces.BnProjectPropertyLocal;
49 import hero.interfaces.BnRoleLocal;
50 import hero.interfaces.BnUserLocal;
51 import hero.interfaces.BnUserLocalHome;
52 import hero.interfaces.Constants;
53 import hero.util.values.BonitaConfigValue;
54 import hero.util.values.BonitaEdgeValue;
55 import hero.util.values.BonitaHookValue;
56 import hero.util.values.BonitaInterHookValue;
57 import hero.util.values.BonitaIterationValue;
58 import hero.util.values.BonitaMapperValue;
59 import hero.util.values.BonitaNodeValue;
60 import hero.util.values.BonitaPerformerValue;
61 import hero.util.values.BonitaProjectValue;
62 import hero.util.values.BonitaPropertyValue;
63 import hero.util.values.BonitaRoleValue;
64 import hero.util.values.BonitaUserValue;
65
66 import javax.ejb.FinderException JavaDoc;
67
68 public class BonitaProjectLocator {
69      
70     public static BonitaProjectValue generateProjectValue(String JavaDoc projectName) throws BonitaServiceException
71     {
72         BnProjectLocalHome pHome=null;
73         BnProjectLocal projectModel=null;
74         BonitaProjectValue pv = null;
75         try {
76             pHome = hero.interfaces.BnProjectUtil.getLocalHome();
77             projectModel = pHome.findByName(projectName);
78         } catch (javax.naming.NamingException JavaDoc ne) {
79             throw new BonitaServiceException(ne.getMessage());
80         } catch (javax.ejb.FinderException JavaDoc fe) {throw new BonitaServiceException(fe.getMessage());}
81     
82         try{
83             pv = getProjectData(projectModel);
84         } catch (HeroException he) {
85             throw new BonitaServiceException(he.getMessage());
86         }
87       return pv;
88      }
89         
90     private static synchronized BonitaProjectValue getProjectData(BnProjectLocal projectModel) throws HeroException
91     {
92         BonitaProjectValue pv = new BonitaProjectValue();
93         pv.setName(projectModel.getName());
94         pv.setType(projectModel.getType());
95         pv.setStatus(projectModel.getStatus());
96         
97         // Project Iterations
98
Collection JavaDoc iterations = projectModel.getBnIterations();
99         Iterator JavaDoc iter = iterations.iterator();
100         Collection JavaDoc iterPro = new ArrayList JavaDoc();
101         while (iter.hasNext())
102         {
103             BnIterationLocal it = (BnIterationLocal)iter.next();
104             BonitaIterationValue iteration = new BonitaIterationValue();
105             iteration.setCondition(it.getCondition());
106             iteration.setFromNode(it.getFromNode());
107             iteration.setToNode(it.getToNode());
108             iterPro.add(iteration);
109         }
110         pv.setIterations(iterPro);
111         
112         // Project Nodes
113
Collection JavaDoc nodesPro = new ArrayList JavaDoc();
114         Collection JavaDoc nodes = projectModel.getBnNodes();
115         Iterator JavaDoc nodesI = nodes.iterator();
116         while (nodesI.hasNext())
117         {
118             BnNodeLocal nd = (BnNodeLocal)nodesI.next();
119             BonitaNodeValue node = new BonitaNodeValue();
120             node.setProjectName(projectModel.getName());
121             node.setDescription(nd.getDescription());
122             node.setDeadlines(nd.getDeadlines());
123             node.setRelativeDeadlines(nd.getRelativeDeadlines());
124             node.setCreator(nd.getCreator());
125             node.setExecutor(nd.getExecutor());
126             node.setName(nd.getName());
127             node.setRole(nd.getBnRole().getName());
128             node.setType(nd.getType());
129             node.setProjectParent(nd.getBnProject().getParent());
130             node.setAnticipable(nd.getAnticipable());
131             
132             // Node inEdges
133
Collection JavaDoc inEdges = nd.getInBnEdges();
134             Iterator JavaDoc inEdgesI = inEdges.iterator();
135             Collection JavaDoc nodeInEdges = new ArrayList JavaDoc();
136             while(inEdgesI.hasNext())
137             {
138                 BnEdgeLocal el = (BnEdgeLocal)inEdgesI.next();
139                 BonitaEdgeValue inEdge = new BonitaEdgeValue();
140                 inEdge.setName(el.getName());
141                 inEdge.setCondition(el.getCondition());
142                 inEdge.setState(el.getState());
143                 inEdge.setInNode(el.getInBnNode().getName());
144                 inEdge.setOutNode(el.getOutBnNode().getName());
145                 nodeInEdges.add(inEdge);
146             }
147             node.setInEdges(nodeInEdges);
148             
149             // Node outEdges
150
Collection JavaDoc outEdges = nd.getOutBnEdges();
151             Iterator JavaDoc outEdgesI = outEdges.iterator();
152             Collection JavaDoc nodeOutEdges = new ArrayList JavaDoc();
153             while(outEdgesI.hasNext())
154             {
155                 BnEdgeLocal el = (BnEdgeLocal)outEdgesI.next();
156                 BonitaEdgeValue outEdge = new BonitaEdgeValue();
157                 outEdge.setName(el.getName());
158                 outEdge.setCondition(el.getCondition());
159                 outEdge.setState(el.getState());
160                 outEdge.setInNode(el.getInBnNode().getName());
161                 outEdge.setOutNode(el.getOutBnNode().getName());
162                 nodeOutEdges.add(outEdge);
163             }
164             node.setOutEdges(nodeOutEdges);
165             
166             // Node properties
167
Collection JavaDoc props = nd.getBnProperties();
168             Iterator JavaDoc propsI = props.iterator();
169             Collection JavaDoc nodeProps = new ArrayList JavaDoc();
170             while(propsI.hasNext())
171             {
172                 BnNodePropertyLocal pl = (BnNodePropertyLocal)propsI.next();
173                 BonitaPropertyValue property = new BonitaPropertyValue();
174                 property.setKey(pl.getTheKey());
175                 property.setValue(pl.getTheValue());
176                 property.setPropagate(pl.getPropagate());
177                 //if (pl.getPossibleValues()!=null)
178
property.setPossibleValues(pl.getPossibleValues());
179                 nodeProps.add(property);
180             }
181             node.setProperties(nodeProps);
182             BonitaPerformerValue performer = new BonitaPerformerValue();
183             performer.setNodeName(nd.getName());
184             if (nd.getBnNodePerformerAssign()!=null)
185             {
186                 performer.setName(nd.getBnNodePerformerAssign().getName());
187                 performer.setType(nd.getBnNodePerformerAssign().getType());
188                 performer.setPropertyName(nd.getBnNodePerformerAssign().getPropertyName());
189                 node.setPerformer(performer);
190             }
191             
192             // Node Hooks
193
Collection JavaDoc nodeHooks = projectModel.getBnNode(nd.getName()).getBnHooks();
194             Iterator JavaDoc nodeHooksI = nodeHooks.iterator();
195             Collection JavaDoc nodeHks = new ArrayList JavaDoc();
196             while(nodeHooksI.hasNext())
197             {
198                 BnNodeHookLocal ph = (BnNodeHookLocal)nodeHooksI.next();
199                 BonitaHookValue hook = new BonitaHookValue();
200                 hook.setName(ph.getName());
201                 hook.setEvent(ph.getEvent());
202                 hook.setType(ph.getType());
203                 nodeHks.add(hook);
204             }
205             node.setHooks(nodeHks);
206             
207             // Node InterHooks
208
Collection JavaDoc nodeInterHooks = projectModel.getBnNode(nd.getName()).getBnInterHooks();
209             Iterator JavaDoc nodeInterHooksI = nodeInterHooks.iterator();
210             Collection JavaDoc nodeInterHks = new ArrayList JavaDoc();
211             while(nodeInterHooksI.hasNext())
212             {
213                 BnNodeInterHookLocal pih = (BnNodeInterHookLocal)nodeInterHooksI.next();
214                 BonitaInterHookValue interHook = new BonitaInterHookValue();
215                 interHook.setName(pih.getName());
216                 interHook.setEvent(pih.getEvent());
217                 interHook.setType(pih.getType());
218                 interHook.setScript(pih.getScript());
219                 nodeInterHks.add(interHook);
220             }
221             node.setInterHooks(nodeInterHks);
222             
223             nodesPro.add(node);
224             
225         }
226         pv.setNodes(nodesPro);
227         
228         // Project Config
229

230         BonitaConfigValue cv = new BonitaConfigValue();
231         cv.setJms(projectModel.getBnProjectConfig().getJMS());
232         cv.setTrace(projectModel.getBnProjectConfig().getTrace());
233         cv.setLog(projectModel.getBnProjectConfig().getLog());
234         cv.setHistoric(projectModel.getBnProjectConfig().getHistoric());
235         cv.setLogLevel(projectModel.getBnProjectConfig().getLogLevel());
236         cv.setTraceLevel(projectModel.getBnProjectConfig().getTraceLevel());
237         pv.setProjectConfig(cv);
238         
239         // Project Properties
240
Collection JavaDoc projectProps = projectModel.getBnProperties();
241         Iterator JavaDoc projectPropsI = projectProps.iterator();
242         Collection JavaDoc projectPrs = new ArrayList JavaDoc();
243         while(projectPropsI.hasNext())
244         {
245             BnProjectPropertyLocal pl = (BnProjectPropertyLocal)projectPropsI.next();
246             BonitaPropertyValue property = new BonitaPropertyValue();
247             property.setKey(pl.getTheKey());
248             property.setValue(pl.getTheValue());
249             //if (pl.getPossibleValues()!=null)
250
property.setPossibleValues(pl.getPossibleValues());
251             projectPrs.add(property);
252         }
253         pv.setProperties(projectPrs);
254         
255         // Project Hooks
256
Collection JavaDoc projectHooks = projectModel.getBnHooks();
257         Iterator JavaDoc projectHooksI = projectHooks.iterator();
258         Collection JavaDoc projectHks = new ArrayList JavaDoc();
259         while(projectHooksI.hasNext())
260         {
261             BnProjectHookLocal ph = (BnProjectHookLocal)projectHooksI.next();
262             BonitaHookValue hook = new BonitaHookValue();
263             hook.setName(ph.getName());
264             hook.setEvent(ph.getEvent());
265             hook.setType(ph.getType());
266             projectHks.add(hook);
267         }
268         pv.setHooks(projectHks);
269         
270         // Project InterHooks
271
Collection JavaDoc projectInterHooks = projectModel.getBnInterHooks();
272         Iterator JavaDoc projectInterHooksI = projectInterHooks.iterator();
273         Collection JavaDoc projectInterHks = new ArrayList JavaDoc();
274         while(projectInterHooksI.hasNext())
275         {
276             BnProjectInterHookLocal pih = (BnProjectInterHookLocal)projectInterHooksI.next();
277             BonitaInterHookValue interHook = new BonitaInterHookValue();
278             interHook.setName(pih.getName());
279             interHook.setEvent(pih.getEvent());
280             interHook.setType(pih.getType());
281             interHook.setScript(pih.getScript());
282             projectInterHks.add(interHook);
283         }
284         pv.setInterHooks(projectInterHks);
285         
286         // Project Roles
287
Collection JavaDoc roles = projectModel.getBnRoles();
288         Iterator JavaDoc rolesI = roles.iterator();
289         Collection JavaDoc rolesP = new ArrayList JavaDoc();
290         while(rolesI.hasNext())
291         {
292             BnRoleLocal rl = (BnRoleLocal)rolesI.next();
293             BonitaRoleValue role = new BonitaRoleValue();
294             role.setName(rl.getName());
295             role.setDescription(rl.getDescription());
296             
297             if (rl.getBnRoleMapper()!=null)
298             {
299                 BonitaMapperValue mapper = new BonitaMapperValue();
300                 mapper.setRoleName(rl.getName());
301                 mapper.setName(rl.getBnRoleMapper().getName());
302                 mapper.setType(rl.getBnRoleMapper().getType());
303             
304                 role.setMapper(mapper);
305             }
306             
307             rolesP.add(role);
308         }
309         pv.setRoles(rolesP);
310         
311         // Project
312

313         Collection JavaDoc users = projectModel.getBnUsers();
314         Iterator JavaDoc usersI = users.iterator();
315         Collection JavaDoc usersP = new ArrayList JavaDoc();
316         while(usersI.hasNext())
317         {
318             BnUserLocal ul = (BnUserLocal)usersI.next();
319             BonitaUserValue user = new BonitaUserValue();
320             user.setName(ul.getName());
321             Collection JavaDoc userRoles = getUserRolesInProjectNames(projectModel, ul.getName());
322                         
323             Iterator JavaDoc uRolesI = userRoles.iterator();
324             Collection JavaDoc uRolesP = new ArrayList JavaDoc();
325             while(uRolesI.hasNext())
326             {
327                 String JavaDoc roleName = (String JavaDoc)uRolesI.next();
328                 uRolesP.add(roleName);
329             }
330             user.setRoles(uRolesP);
331             usersP.add(user);
332         }
333         pv.setUsers(usersP);
334         return pv;
335     }
336     
337     private static Collection JavaDoc getUserRolesInProjectNames(BnProjectLocal mProject, String JavaDoc userName)
338     throws HeroException {
339         BnUserLocalHome uHome;
340         BnUserLocal user;
341         ArrayList JavaDoc result = new ArrayList JavaDoc();
342         try {
343             uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome();
344         } catch (javax.naming.NamingException JavaDoc be) {
345             throw new HeroException(be.getMessage());
346         }
347         try {
348             user = uHome.findByName(userName);
349         } catch (FinderException JavaDoc f) {
350             throw new HeroException("FinderException");
351         }
352         Collection JavaDoc userRoles = user.getBnRoles();
353         Collection JavaDoc projectRoles = mProject.getBnRoles();
354         for (Iterator JavaDoc i = userRoles.iterator(); i.hasNext();) {
355             BnRoleLocal ur = (BnRoleLocal) i.next();
356             for (Iterator JavaDoc j = projectRoles.iterator(); j.hasNext();) {
357                 BnRoleLocal up = (BnRoleLocal) j.next();
358                 if (ur.getId().equals(up.getId()))
359                     result.add(ur.getBnRoleValue().getName());
360             }
361         }
362         return result;
363     }
364 }
365
Popular Tags