001: package hero.util;
002:
003: /*
004: *
005: * SoapClient.java -
006: * Copyright (C) 2003 Ecoo Team
007: * valdes@loria.fr
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
022: */
023:
024: import java.net.URL;
025: import java.util.ArrayList;
026: import java.util.Arrays;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: import org.apache.axis.client.Service;
031:
032: import hero.interfaces.Constants;
033:
034: import org.apache.axis.client.Stub;
035:
036: import hero.net.UserSession.UserSession_PortType;
037: import hero.net.UserSession.UserSessionService;
038: import hero.net.UserSession.UserSessionServiceLocator;
039:
040: import hero.net.ProjectSession.ProjectSession_PortType;
041: import hero.net.ProjectSession.ProjectSessionService;
042: import hero.net.ProjectSession.ProjectSessionServiceLocator;
043:
044: public class BonitaClient {
045: // end points
046: private final String userSession = "UserSession";
047: private final String projectSession = "ProjectSession";
048:
049: //private ProjectSoapXML projectSoapClient;
050: private ProjectSession_PortType projectSessionClient;
051: private UserSession_PortType userSessionClient;
052:
053: // Network information
054: private String host;
055: private int port;
056: private String baseUrl = "/bonita_ws/services/";
057:
058: // User information
059: private String userName = null;
060: private String userPassword = null;
061:
062: // manage transport to soap server...
063: private Service service;
064: private URL defaultUri;
065: private URL userUri;
066: private URL projectUri;
067: //private URL projectXMLUri;
068:
069: // Persitance
070: private String currentProject;
071: private boolean permission = false;
072:
073: //====================================================
074: private void createUserSoapCall() throws Exception {
075: Stub stub = ((Stub) userSessionClient);
076: stub.setUsername(this .userName);
077: stub.setPassword(this .userPassword);
078: }
079:
080: private void createProjectSoapCall() throws Exception {
081: Stub stub = ((Stub) projectSessionClient);
082: stub.setUsername(this .userName);
083: stub.setPassword(this .userPassword);
084: stub.setMaintainSession(true);
085: }
086:
087: //=========== Local ==================================
088: public void login(String user, String pass) throws Exception {
089: this .userName = user;
090: this .userPassword = pass;
091:
092: UserSessionService serviceUS = new UserSessionServiceLocator();
093: userSessionClient = serviceUS.getUserSession(userUri);
094:
095: ProjectSessionService servicePSS = new ProjectSessionServiceLocator();
096: projectSessionClient = servicePSS.getProjectSession(projectUri);
097:
098: this .createUserSoapCall();
099: this .createProjectSoapCall();
100: }
101:
102: public String getUser() throws Exception {
103: return (this .userName);
104: }
105:
106: public String getProjectName() {
107: return this .currentProject;
108: }
109:
110: public boolean hasPermission() {
111: return permission;
112: }
113:
114: //====================================================
115:
116: public BonitaClient(String host, int port, String urlBase)
117: throws Exception {
118: this .host = host;
119: this .port = port;
120: this .baseUrl = urlBase;
121: // set all the possible endpoint
122: userUri = new URL("http://" + host + ":" + port + baseUrl
123: + userSession);
124: projectUri = new URL("http://" + host + ":" + port + baseUrl
125: + projectSession);
126: }
127:
128: // SOAP ===============================================
129:
130: public void initProject(String managerProject) throws Exception {
131: this .currentProject = managerProject;
132: projectSessionClient.initProject(currentProject);
133:
134: // Check the permission
135: permission = isInRole(userName, "admin");
136: }
137:
138: public void initModel(String managerProject) throws Exception {
139: this .currentProject = managerProject;
140: projectSessionClient.initModel(currentProject);
141:
142: // Check the permission
143: permission = isInRole(userName, "admin");
144: }
145:
146: public void initProject(String src, String dest) throws Exception {
147: this .login(this .userName, this .userPassword);
148: projectSessionClient.initProject(src, dest);
149: // Set the local var
150: this .currentProject = dest;
151: }
152:
153: public void instantiateProject(String src) throws Exception {
154: this .login(this .userName, this .userPassword);
155: projectSessionClient.instantiateProject(src);
156: }
157:
158: public boolean openProject(String projectName) throws Exception {
159: initProject(projectName);
160: return true;
161: }
162:
163: public boolean createProject(String projectName) throws Exception {
164: if (exists(projectName)) {
165: return false;
166: }
167: initProject(projectName);
168: return true;
169: }
170:
171: public boolean createModel(String modelName) throws Exception {
172: if (exists(modelName)) {
173: return false;
174: }
175: initModel(modelName);
176: return true;
177: }
178:
179: public boolean cloneProject(String projectSrc, String projectDest)
180: throws Exception {
181: if (exists(projectDest)) {
182: return false;
183: }
184: initProject(projectSrc, projectDest);
185: return true;
186: }
187:
188: private boolean exists(String name) throws Exception {
189: Collection projects = getProjects();
190: Iterator i = projects.iterator();
191: while (i.hasNext()) {
192: String prj = (String) i.next();
193: if (prj.equalsIgnoreCase(name)) {
194: return true;
195: }
196: }
197: return false;
198: }
199:
200: public Collection getProjects() throws Exception {
201: ArrayList result = new ArrayList();
202: Object[] projects = userSessionClient.getProjectListNames();
203: Iterator i = ((java.util.List) Arrays.asList(projects))
204: .iterator();
205: while (i.hasNext()) {
206: result.add(i.next());
207: }
208: return result;
209: }
210:
211: public Collection getProjectsList() throws Exception {
212: ArrayList result = new ArrayList();
213: Object[] projects = userSessionClient.getProjectList();
214: Iterator i = ((java.util.List) Arrays.asList(projects))
215: .iterator();
216: while (i.hasNext()) {
217: result.add((hero.net.UserSession.BnProjectLightValue) i
218: .next());
219: }
220: return result;
221: }
222:
223: public Collection getProjectInstances(String projectName)
224: throws Exception {
225: ArrayList result = new ArrayList();
226: Object[] instances = userSessionClient
227: .getProjectInstancesNames(projectName);
228: Iterator i = ((java.util.List) Arrays.asList(instances))
229: .iterator();
230: while (i.hasNext()) {
231: result.add(i.next());
232: }
233: return result;
234: }
235:
236: public Collection getInstances() throws Exception {
237: ArrayList result = new ArrayList();
238: Object[] instances = userSessionClient.getInstancesListNames();
239: Iterator i = ((java.util.List) Arrays.asList(instances))
240: .iterator();
241: while (i.hasNext()) {
242: result.add(i.next());
243: }
244: return result;
245: }
246:
247: public boolean containsNode(String value) throws Exception {
248: Collection nodes = getNodes();
249:
250: Iterator i = nodes.iterator();
251: while (i.hasNext()) {
252: String nodeName = (String) i.next();
253: if (value.equalsIgnoreCase(nodeName)) {
254: return true;
255: }
256: }
257: return false;
258: }
259:
260: public String getType() throws Exception {
261: return (projectSessionClient.getType());
262: }
263:
264: public String getStatus() throws Exception {
265: return (projectSessionClient.getStatus());
266: }
267:
268: public void setStatus(String status) throws Exception {
269: if (status.equals(Constants.Pj.ACTIVE))
270: projectSessionClient.activeProcess();
271: else
272: projectSessionClient.hideProcess();
273: }
274:
275: public Collection getNodes() throws Exception {
276: ArrayList result = new ArrayList();
277: Object[] nodes = projectSessionClient.getNodesNames();
278: Iterator i = ((java.util.List) Arrays.asList(nodes)).iterator();
279: while (i.hasNext()) {
280: result.add(i.next());
281: }
282: return (result);
283: }
284:
285: public Collection getEdges() throws Exception {
286: ArrayList result = new ArrayList();
287: Object[] edges = projectSessionClient.getEdgesNames();
288:
289: Iterator i = ((java.util.List) Arrays.asList(edges)).iterator();
290: while (i.hasNext()) {
291: result.add(i.next());
292: }
293:
294: return result;
295: }
296:
297: public void addNodeProperty(String node, String key, String value,
298: boolean propagate) throws Exception {
299:
300: projectSessionClient.setNodeProperty(node, key, value,
301: propagate);
302: }
303:
304: public void addIteration(String from, String to, String condition)
305: throws Exception {
306: projectSessionClient.addIteration(from, to, condition);
307: }
308:
309: public Collection getIterations() throws Exception {
310: ArrayList result = new ArrayList();
311: Object[] ite = projectSessionClient.getIterations();
312:
313: Iterator i = ((java.util.List) Arrays.asList(ite)).iterator();
314: while (i.hasNext()) {
315: result
316: .add((hero.net.ProjectSession.BnIterationLightValue) i
317: .next());
318: }
319:
320: return result;
321: }
322:
323: public void addProjectProperty(String key, String value)
324: throws Exception {
325: projectSessionClient.setProperty(key, value);
326: }
327:
328: public void addNodeInterHook(String node, String hook,
329: String event, String value) throws Exception {
330:
331: projectSessionClient.addNodeInterHook(node, hook, event, 6,
332: value);
333: }
334:
335: public void addProjectInterHook(String hook, String event,
336: String value) throws Exception {
337: projectSessionClient.addInterHook(hook, event, 6, value);
338: }
339:
340: public void addNode(String name, String type) throws Exception {
341: int nodeType = 0;
342: if (type.equals("AND JOIN"))
343: nodeType = Constants.Nd.AND_JOIN_NODE;
344: if (type.equals("OR JOIN"))
345: nodeType = Constants.Nd.OR_JOIN_NODE;
346: if (type.equals("AND JOIN AUTO"))
347: nodeType = Constants.Nd.AND_JOIN_AUTOMATIC_NODE;
348: if (type.equals("OR JOIN AUTO"))
349: nodeType = Constants.Nd.OR_JOIN_AUTOMATIC_NODE;
350: if (type.equals("SUB PROCESS"))
351: nodeType = Constants.Nd.SUB_PROCESS_NODE;
352: projectSessionClient.addNode(name, nodeType);
353:
354: }
355:
356: public void addNodeSubProcess(String name, String projectName)
357: throws Exception {
358: projectSessionClient.addNodeSubProcess(name, projectName);
359: }
360:
361: public boolean deleteNode(String node) throws Exception {
362: projectSessionClient.deleteNode(node);
363: return true;
364: }
365:
366: public boolean deleteProject(String projectName) throws Exception {
367: if (projectName.matches(".*_instance.*"))
368: userSessionClient.removeInstance(projectName);
369: else
370: userSessionClient.removeProject(projectName);
371: return true;
372: }
373:
374: public void deleteEdges(Object[] edges) throws Exception {
375: for (int i = 0; i < edges.length; i++) {
376: projectSessionClient.deleteEdge((String) edges[i]);
377: }
378: }
379:
380: public String addEdge(String src, String dest) throws Exception {
381: String name = null;
382: name = projectSessionClient.addEdge(src, dest);
383: return name;
384: }
385:
386: public String setEdgeCondition(String edgeName, String condition)
387: throws Exception {
388: projectSessionClient.setEdgeCondition(edgeName, condition);
389: return edgeName;
390: }
391:
392: public String getEdgeCondition(String edgeName) throws Exception {
393: return (projectSessionClient.getEdgeCondition(edgeName));
394: }
395:
396: public String getState(String name) throws Exception {
397: int state = getNodeState(name);
398: switch (state) {
399: case Constants.Nd.INITIAL:
400: return ("Initial");
401: case Constants.Nd.READY:
402: return ("Ready");
403: case Constants.Nd.ANTICIPABLE:
404: return ("Anticipable");
405: case Constants.Nd.ANTICIPATING:
406: return ("Anticipating");
407: case Constants.Nd.EXECUTING:
408: return ("Executing");
409: case Constants.Nd.EXECUTED:
410: return ("Executed");
411: case Constants.Nd.TERMINATED:
412: return ("Terminated");
413: case Constants.Nd.ANT_SUSPENDED:
414: return ("Ant_suspended");
415: case Constants.Nd.EXEC_SUSPENDED:
416: return ("Exec_suspended");
417: }
418: return ("");
419: }
420:
421: public int getNodeState(String name) throws Exception {
422: return (projectSessionClient.getNodeState(name));
423: }
424:
425: public int getNodeType(String name) throws Exception {
426: return (projectSessionClient.getNodeType(name));
427: }
428:
429: public boolean getNodeAnticipable(String name) throws Exception {
430: return (projectSessionClient.getNodeAnticipable(name));
431: }
432:
433: public String getNodeInterHookValue(String nodeName, String hookName)
434: throws Exception {
435: return (projectSessionClient.getNodeInterHookValue(nodeName,
436: hookName));
437: }
438:
439: public void setNodeInterHookValue(String nodeName, String hookName,
440: String value) throws Exception {
441: projectSessionClient.setNodeInterHookValue(nodeName, hookName,
442: value);
443: }
444:
445: public String getProjectInterHookValue(String hookName)
446: throws Exception {
447: return (projectSessionClient.getInterHookValue(hookName));
448: }
449:
450: public void setProjectInterHookValue(String hookName, String value)
451: throws Exception {
452: projectSessionClient.setInterHookValue(hookName, value);
453: }
454:
455: public String getNodeDescription(String nodeName) throws Exception {
456: return (projectSessionClient.getNodeDescription(nodeName));
457: }
458:
459: public void setNodeDescription(String nodeName, String description)
460: throws Exception {
461: projectSessionClient.setNodeDescription(nodeName, description);
462: }
463:
464: public void setNodeTraditional(String nodeName) throws Exception {
465: projectSessionClient.setNodeTraditional(nodeName);
466: }
467:
468: public void setNodeAnticipable(String nodeName) throws Exception {
469: projectSessionClient.setNodeAnticipable(nodeName);
470: }
471:
472: public String getEdgeInNode(String name) throws Exception {
473: return (projectSessionClient.getEdgeInNode(name));
474: }
475:
476: public String getEdgeOutNode(String name) throws Exception {
477: return (projectSessionClient.getEdgeOutNode(name));
478: }
479:
480: public boolean isActive(String name) throws Exception { //Only used by WFmanager.updateStatus
481: int state = getNodeState(name);
482: switch (state) {
483: case Constants.Nd.INITIAL:
484: return false;
485: case Constants.Nd.READY:
486: return false;
487: case Constants.Nd.ANTICIPABLE:
488: return false;
489: case Constants.Nd.ANTICIPATING:
490: return true;
491: case Constants.Nd.EXECUTING:
492: return true;
493: case Constants.Nd.EXECUTED:
494: return false;
495: case Constants.Nd.TERMINATED:
496: return true;
497: case Constants.Nd.ANT_SUSPENDED:
498: return false;
499: case Constants.Nd.EXEC_SUSPENDED:
500: return false;
501: }
502: return false;
503: }
504:
505: public String getType(String name) throws Exception {
506: int type = projectSessionClient.getNodeType(name);
507: switch (type) {
508: case Constants.Nd.AND_JOIN_NODE:
509: return ("And Join");
510: case Constants.Nd.OR_JOIN_NODE:
511: return ("Or Join");
512: case Constants.Nd.AND_JOIN_AUTOMATIC_NODE:
513: return ("And Join Automatic");
514: case Constants.Nd.OR_JOIN_AUTOMATIC_NODE:
515: return ("Or Join Automatic");
516: case Constants.Nd.SUB_PROCESS_NODE:
517: return ("Sub Procss");
518: }
519: return ("");
520: }
521:
522: public String getRole(String name) throws Exception {
523: return (projectSessionClient.getNodeRoleName(name));
524: }
525:
526: public void setNodeRole(String node, String newRole)
527: throws Exception {
528: projectSessionClient.setNodeRole(node, newRole);
529: }
530:
531: public String getDeadline(String name) throws Exception {
532: return (projectSessionClient.getNodeDeadline(name));
533: }
534:
535: public void setDeadline(String node, long dl) throws Exception {
536: projectSessionClient.setNodeDeadline(node, dl);
537: }
538:
539: public Collection getRoles() throws Exception {
540: ArrayList result = new ArrayList();
541: Object[] roles = projectSessionClient.getRolesNames();
542: Iterator i = ((java.util.List) Arrays.asList(roles)).iterator();
543: while (i.hasNext()) {
544: result.add(i.next());
545: }
546: return (result);
547: }
548:
549: public Collection getUsersInProject() throws Exception {
550: ArrayList result = new ArrayList();
551: Object[] users = projectSessionClient.getUsers();
552: Iterator i = ((java.util.List) Arrays.asList(users)).iterator();
553: while (i.hasNext()) {
554: result.add(i.next());
555: }
556: return (result);
557: }
558:
559: public Collection getAllUsers() throws Exception {
560: ArrayList result = new ArrayList();
561: Object[] users = projectSessionClient.getAllUsers();
562: Iterator i = ((java.util.List) Arrays.asList(users)).iterator();
563: while (i.hasNext()) {
564: result.add(i.next());
565: }
566: return (result);
567: }
568:
569: public void addUser(String name) throws Exception {
570: projectSessionClient.addUser(name);
571: }
572:
573: public void addRole(String name, String desc) throws Exception {
574: projectSessionClient.addRole(name, desc);
575: }
576:
577: public void setUserRole(String name, String role) throws Exception {
578: projectSessionClient.setUserRole(name, role);
579: }
580:
581: public void addRoleMapper(String role, String mapper, String type)
582: throws Exception {
583: int mapperType = 0;
584: if (type.equals(Constants.Mapper.PROPERTIESMAPPER))
585: mapperType = 1;
586: if (type.equals(Constants.Mapper.CUSTOMMAPPER))
587: mapperType = 2;
588: projectSessionClient.addRoleMapper(role, mapper, mapperType);
589: }
590:
591: public void addNodePerformerAssigment(String node, String name,
592: String type, String property) throws Exception {
593: int performerType = 0;
594: if (type.equals(Constants.PerformerAssigment.PROPERTIESPA))
595: performerType = 1;
596: projectSessionClient.addNodePerformerAssign(node, name,
597: performerType, property);
598: }
599:
600: public boolean isInRole(String name, String role) throws Exception {
601: Object[] projects = projectSessionClient
602: .getUserRolesInProjectNames(name);
603:
604: Iterator i = ((java.util.List) Arrays.asList(projects))
605: .iterator();
606: while (i.hasNext()) {
607: String roleName = (String) i.next();
608: if (roleName.equals(role))
609: return true;
610: }
611: return false;
612: }
613:
614: public Collection getToDoList(String project) throws Exception {
615: ArrayList result = new ArrayList();
616: Object[] activity = userSessionClient.getToDoList(project);
617: Iterator i = ((java.util.List) Arrays.asList(activity))
618: .iterator();
619: while (i.hasNext()) {
620: result.add(i.next());
621: }
622: return result;
623: }
624:
625: public Collection getActivityList(String project) throws Exception {
626: ArrayList result = new ArrayList();
627: Object[] activity = userSessionClient.getActivityList(project);
628: Iterator i = ((java.util.List) Arrays.asList(activity))
629: .iterator();
630: while (i.hasNext()) {
631: result.add(i.next());
632: }
633: return result;
634: }
635:
636: public Object[] getProjectNodes() throws Exception {
637: return (projectSessionClient.getNodes());
638: }
639:
640: public Collection getProperties() throws Exception {
641: ArrayList result = new ArrayList();
642: Object[] prop = projectSessionClient.getPropertiesKey();
643: Iterator i = ((java.util.List) Arrays.asList(prop)).iterator();
644: while (i.hasNext()) {
645: result.add(i.next());
646: }
647: return result;
648: }
649:
650: public void setEditNode(String node, String role,
651: String description, long date) throws Exception {
652: projectSessionClient.setEditNode(node, role, description, date);
653: }
654:
655: public void startActivity(String project, String activity)
656: throws Exception {
657: userSessionClient.startActivity(project, activity);
658: }
659:
660: public void terminateActivity(String project, String activity)
661: throws Exception {
662: userSessionClient.terminateActivity(project, activity);
663: }
664:
665: public void cancelActivity(String project, String activity)
666: throws Exception {
667: userSessionClient.cancelActivity(project, activity);
668: }
669:
670: public void terminateProject(String project) throws Exception {
671: userSessionClient.terminate(project);
672: }
673:
674: public hero.net.ProjectSession.StrutsNodeValue getStrutsNode(
675: String name) throws Exception {
676: return (projectSessionClient.getStrutsNode(name));
677: }
678:
679: }
|