1 29 30 package hero.util; 31 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.Iterator ; 35 import java.util.Map ; 36 import java.util.HashMap ; 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 ; 67 68 public class BonitaProjectLocator { 69 70 public static BonitaProjectValue generateProjectValue(String 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 ne) { 79 throw new BonitaServiceException(ne.getMessage()); 80 } catch (javax.ejb.FinderException 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 Collection iterations = projectModel.getBnIterations(); 99 Iterator iter = iterations.iterator(); 100 Collection iterPro = new ArrayList (); 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 Collection nodesPro = new ArrayList (); 114 Collection nodes = projectModel.getBnNodes(); 115 Iterator 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 Collection inEdges = nd.getInBnEdges(); 134 Iterator inEdgesI = inEdges.iterator(); 135 Collection nodeInEdges = new ArrayList (); 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 Collection outEdges = nd.getOutBnEdges(); 151 Iterator outEdgesI = outEdges.iterator(); 152 Collection nodeOutEdges = new ArrayList (); 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 Collection props = nd.getBnProperties(); 168 Iterator propsI = props.iterator(); 169 Collection nodeProps = new ArrayList (); 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 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 Collection nodeHooks = projectModel.getBnNode(nd.getName()).getBnHooks(); 194 Iterator nodeHooksI = nodeHooks.iterator(); 195 Collection nodeHks = new ArrayList (); 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 Collection nodeInterHooks = projectModel.getBnNode(nd.getName()).getBnInterHooks(); 209 Iterator nodeInterHooksI = nodeInterHooks.iterator(); 210 Collection nodeInterHks = new ArrayList (); 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 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 Collection projectProps = projectModel.getBnProperties(); 241 Iterator projectPropsI = projectProps.iterator(); 242 Collection projectPrs = new ArrayList (); 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 property.setPossibleValues(pl.getPossibleValues()); 251 projectPrs.add(property); 252 } 253 pv.setProperties(projectPrs); 254 255 Collection projectHooks = projectModel.getBnHooks(); 257 Iterator projectHooksI = projectHooks.iterator(); 258 Collection projectHks = new ArrayList (); 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 Collection projectInterHooks = projectModel.getBnInterHooks(); 272 Iterator projectInterHooksI = projectInterHooks.iterator(); 273 Collection projectInterHks = new ArrayList (); 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 Collection roles = projectModel.getBnRoles(); 288 Iterator rolesI = roles.iterator(); 289 Collection rolesP = new ArrayList (); 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 313 Collection users = projectModel.getBnUsers(); 314 Iterator usersI = users.iterator(); 315 Collection usersP = new ArrayList (); 316 while(usersI.hasNext()) 317 { 318 BnUserLocal ul = (BnUserLocal)usersI.next(); 319 BonitaUserValue user = new BonitaUserValue(); 320 user.setName(ul.getName()); 321 Collection userRoles = getUserRolesInProjectNames(projectModel, ul.getName()); 322 323 Iterator uRolesI = userRoles.iterator(); 324 Collection uRolesP = new ArrayList (); 325 while(uRolesI.hasNext()) 326 { 327 String roleName = (String )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 getUserRolesInProjectNames(BnProjectLocal mProject, String userName) 338 throws HeroException { 339 BnUserLocalHome uHome; 340 BnUserLocal user; 341 ArrayList result = new ArrayList (); 342 try { 343 uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome(); 344 } catch (javax.naming.NamingException be) { 345 throw new HeroException(be.getMessage()); 346 } 347 try { 348 user = uHome.findByName(userName); 349 } catch (FinderException f) { 350 throw new HeroException("FinderException"); 351 } 352 Collection userRoles = user.getBnRoles(); 353 Collection projectRoles = mProject.getBnRoles(); 354 for (Iterator i = userRoles.iterator(); i.hasNext();) { 355 BnRoleLocal ur = (BnRoleLocal) i.next(); 356 for (Iterator 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 |