0001: package hero.session;
0002:
0003: /*
0004: * 02/01/2002 - 15:24:07
0005: *
0006: * ProjectSessionEJB.java -
0007: * Copyright (C) 2002 Ecoo Team
0008: * valdes@loria.fr
0009: *
0010: * This program is free software; you can redistribute it and/or
0011: * modify it under the terms of the GNU Lesser General Public License
0012: * as published by the Free Software Foundation; either version 2
0013: * of the License, or (at your option) any later version.
0014: *
0015: * This program is distributed in the hope that it will be useful,
0016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0018: * GNU Lesser General Public License for more details.
0019: *
0020: * You should have received a copy of the GNU Lesser General Public License
0021: * along with this program; if not, write to the Free Software
0022: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0023: */
0024:
0025: import hero.entity.EdgeState;
0026: import hero.entity.NodeState;
0027: import hero.interfaces.BnAgentEdgeLocal;
0028: import hero.interfaces.BnAgentEdgeLocalHome;
0029: import hero.interfaces.BnAgentEdgeValue;
0030: import hero.interfaces.BnAgentLocal;
0031: import hero.interfaces.BnAgentLocalHome;
0032: import hero.interfaces.BnAgentValue;
0033: import hero.interfaces.BnEdgeLocal;
0034: import hero.interfaces.BnEdgeLocalHome;
0035: import hero.interfaces.BnEdgeUtil;
0036: import hero.interfaces.BnEdgeValue;
0037: import hero.interfaces.BnNodeHookLocal;
0038: import hero.interfaces.BnNodeHookLocalHome;
0039: import hero.interfaces.BnNodeHookUtil;
0040: import hero.interfaces.BnNodeInterHookLocal;
0041: import hero.interfaces.BnNodeInterHookValue;
0042: import hero.interfaces.BnNodeInterHookLocalHome;
0043: import hero.interfaces.BnNodeInterHookUtil;
0044: import hero.interfaces.BnNodeLightValue;
0045: import hero.interfaces.BnNodeLocal;
0046: import hero.interfaces.BnNodeLocalHome;
0047: import hero.interfaces.BnNodePropertyLocal;
0048: import hero.interfaces.BnNodePropertyValue;
0049: import hero.interfaces.BnNodePropertyLocalHome;
0050: import hero.interfaces.BnNodePropertyUtil;
0051: import hero.interfaces.BnNodeUtil;
0052: import hero.interfaces.BnNodeValue;
0053: import hero.interfaces.BnIterationLocal;
0054: import hero.interfaces.BnIterationLocalHome;
0055: import hero.interfaces.BnIterationUtil;
0056: import hero.interfaces.BnIterationLightValue;
0057: import hero.interfaces.BnProjectHookLocal;
0058: import hero.interfaces.BnProjectHookLocalHome;
0059: import hero.interfaces.BnProjectHookUtil;
0060: import hero.interfaces.BnProjectInterHookLocal;
0061: import hero.interfaces.BnProjectInterHookLocalHome;
0062: import hero.interfaces.BnProjectInterHookUtil;
0063: import hero.interfaces.BnProjectLightValue;
0064: import hero.interfaces.BnProjectLocal;
0065: import hero.interfaces.BnProjectLocalHome;
0066: import hero.interfaces.BnProjectPropertyLocal;
0067: import hero.interfaces.BnProjectPropertyLocalHome;
0068: import hero.interfaces.BnProjectPropertyUtil;
0069: import hero.interfaces.BnProjectPropertyValue;
0070: import hero.interfaces.BnProjectUtil;
0071: import hero.interfaces.BnProjectValue;
0072: import hero.interfaces.BnRoleLocal;
0073: import hero.interfaces.BnRoleLocalHome;
0074: import hero.interfaces.BnRoleUtil;
0075: import hero.interfaces.BnRoleValue;
0076: import hero.interfaces.BnUserLightValue;
0077: import hero.interfaces.BnUserLocal;
0078: import hero.interfaces.BnUserLocalHome;
0079: import hero.interfaces.BnUserUtil;
0080: import hero.interfaces.DeadlineEjbTimerSessionLocal;
0081: import hero.interfaces.DeadlineEjbTimerSessionLocalHome;
0082: import hero.interfaces.DeadlineEjbTimerSessionUtil;
0083: import hero.interfaces.EngineLocal;
0084: import hero.interfaces.EngineLocalHome;
0085: import hero.interfaces.InvalidValueException;
0086: import hero.interfaces.Constants;
0087: import hero.interfaces.ProjectSessionLocal;
0088:
0089: import hero.interfaces.UserServiceLocal;
0090: import hero.interfaces.UserServiceLocalHome;
0091: import hero.interfaces.BnInitiatorMapperLocal;
0092: import hero.interfaces.BnInitiatorMapperLocalHome;
0093: import hero.interfaces.BnInitiatorMapperUtil;
0094:
0095: import hero.util.BonitaParsing;
0096: import hero.util.BonitaConfig;
0097: import hero.util.BonitaProjectLocator;
0098: import hero.util.BonitaServiceException;
0099: import hero.util.DeleteEdgeException;
0100: import hero.util.EventConstants;
0101: import hero.util.HeroException;
0102: import hero.util.AdminException;
0103: import hero.util.AccessException;
0104: import hero.util.NodeExecutingException;
0105: import hero.util.ServerType;
0106: import hero.util.StrutsEdgeValue;
0107: import hero.util.StrutsNodeValue;
0108: import hero.util.values.BonitaEdgeValue;
0109: import hero.util.values.BonitaHookValue;
0110: import hero.util.values.BonitaIterationValue;
0111: import hero.util.values.BonitaNodeValue;
0112: import hero.util.values.BonitaProjectValue;
0113: import hero.util.values.BonitaPropertyValue;
0114: import hero.util.values.BonitaRoleValue;
0115: import hero.util.values.BonitaUserValue;
0116: import hero.interfaces.JMSServicesSessionUtil;
0117: import hero.interfaces.JMSServicesSessionLocalHome;
0118: import hero.interfaces.JMSServicesSessionLocal;
0119:
0120: import hero.interfaces.BnRoleMapperLocal;
0121: import hero.interfaces.BnRoleMapperLocalHome;
0122: import hero.interfaces.BnRoleMapperUtil;
0123:
0124: import hero.interfaces.BnNodePerformerAssignLocal;
0125: import hero.interfaces.BnNodePerformerAssignLocalHome;
0126: import hero.interfaces.BnNodePerformerAssignUtil;
0127: import hero.interfaces.BnNodePerformerAssignValue;
0128: import hero.interfaces.Constants.Nd;
0129:
0130: import java.rmi.RemoteException;
0131: import java.util.ArrayList;
0132:
0133: import java.util.Collection;
0134: import java.util.Comparator;
0135: import java.util.Date;
0136: import java.util.Enumeration;
0137: import java.util.Hashtable;
0138: import java.util.Iterator;
0139: import java.util.Map;
0140: import java.util.SortedSet;
0141: import java.util.TreeSet;
0142:
0143: import javax.ejb.CreateException;
0144: import javax.ejb.FinderException;
0145: import javax.ejb.RemoveException;
0146: import javax.ejb.SessionBean;
0147: import javax.ejb.SessionContext;
0148: import javax.ejb.EJBException;
0149: import javax.naming.Context;
0150:
0151: import org.apache.log4j.Logger;
0152: import org.apache.log4j.Level;
0153:
0154: /**
0155: *
0156: * Project Session Bean is an stateful session bean that provides the interface for workflow process
0157: * definition. By means of this API we can create workflow processes, project activities, transitions between activities ,
0158: * users and roles, properties, hooks, external agents...<br><br>
0159: *
0160: * A Bonita Workflow process is composed by the activities (nodes) and the connections between these
0161: * activities (edges). For each project, the administrator/s set the list of responsibles to execute these
0162: * activites (users and roles). In the same way, the Project Session Bean API offers a great number of
0163: * functionalities for working with activities behaviors (hooks) and workflow relevant data (properties).<br><br>
0164: *
0165: * This API can be used on different contexts depending on the needs of your application, so you can instantiate
0166: * an existing project in order to perform set, get, update and remove operations, you can create a new workflow
0167: * project (by instantiating a project that does not exists), you can clone an existing project or creates a
0168: * new workflow instante of a project.
0169: *
0170: * <strong>The following lines shows a sample code to use this API in your application:<br><br></strong>
0171: * <br>
0172: * First of all you have to import the Project Session files:<br>
0173: * <br>
0174: * import hero.interfaces.ProjectSessionLocalHome;<br>
0175: * import hero.interfaces.ProjectSessionLocal;<br>
0176: * import hero.interfaces.ProjectSessionHome;<br>
0177: * import hero.interfaces.ProjectSession;<br>
0178: * import hero.interfaces.ProjectSessionUtil;<br>
0179: * <br>
0180: * Now, it is time to create the Project Session instance:<br>
0181: * <br>
0182: * Like this if you want to use local interfaces:<br><br>
0183: * ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome();<br>
0184: * ProjectSessionLocal projectsession = projecth.create();<br>
0185: * <br>
0186: * or like this if you use remote interfaces:<br>
0187: * <br>
0188: * ProjectSessionHome userh = (ProjectSessionHome)hero.interfaces.ProjectSessionUtil.getHome();<br>
0189: * ProjectSession projectsession = projecth.create();<br>
0190: * <br>
0191: * <br>
0192: * - If you want to use Project Session API for a specific project, you have to init this project.<br><br>
0193: * Depending of the workflow process type you want, use:<br><br>
0194: *
0195: * projectsession.initProject("yourProject"); // for cooperative projects<br>
0196: * <br>or<br>
0197: * projectsession.initModel("yourProject"); // for workflow models<br>
0198: * <br>
0199: * - In order to clone an existing project, you have to call the initProject method:<br><br>
0200: * projectsession.initProject("Project","CloneProject");<br><br>
0201: *
0202: * - If you want to instantiate a project, you have to do the following:<br><br>
0203: * projectsession.instantiateProject("Project");<br><br>
0204: *
0205: * Now you can use Project Session methods...
0206: *
0207: *
0208: * @ejb:bean name="ProjectSession"
0209: * display-name="ProjectSession Bean"
0210: * type="Stateful"
0211: * transaction-type="Container"
0212: * jndi-name="ejb/hero/ProjectSession"
0213: * local-jndi-name="ejb/hero/ProjectSession_L"
0214: * reentrant="true"
0215: *
0216: * @ejb:ejb-ref ejb-name="ProjectSession"
0217: * view-type="remote"
0218: * ref-name="ProjectSession"
0219: *
0220: * @ejb:ejb-ref ejb-name="BnProject"
0221: * ref-name="myhero/BnProject"
0222: * @ejb:transaction type="Supports"
0223: *
0224: * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
0225: * @jonas.bean
0226: * ejb-name="ProjectSession"
0227: * jndi-name="ejb/hero/ProjectSession"
0228: *
0229: * @jboss.container-configuration name="Standard Stateful SessionBean for Bonita"
0230: *
0231: * @copyright INRIA
0232: * @author Miguel Valdes
0233: *
0234: **/
0235:
0236: public class ProjectSessionBean implements SessionBean, EventConstants {
0237:
0238: // -------------------------------------------------------------------------
0239: // Static
0240: // -------------------------------------------------------------------------
0241: // Utility variable
0242: private static final Logger trace = Logger
0243: .getLogger(ProjectSessionBean.class);
0244: private static final Logger thelog = Logger.getLogger("log");
0245:
0246: // -------------------------------------------------------------------------
0247: // Members
0248: // -------------------------------------------------------------------------
0249:
0250: private SessionContext mContext;
0251:
0252: private BnProjectLocalHome pHome;
0253: private BnProjectLocal mProject = null;
0254: private JMSServicesSessionLocal jms = null;
0255: private DeadlineEjbTimerSessionLocal dlSession;
0256: private String caller = null;
0257:
0258: // -------------------------------------------------------------------------
0259: // Methods
0260: // -------------------------------------------------------------------------
0261:
0262: // -------------------------------------------------------------------------
0263: // Add business methods
0264: // -------------------------------------------------------------------------
0265:
0266: /**
0267: * Add a user to this project (This user must exist at bonita database)
0268: *
0269: * @param userName The name of the user to associate to the project
0270: *
0271: * @ejb:interface-method view-type="both"
0272: * @ejb:transaction type="Required"
0273: * @throws HeroException
0274: *
0275: **/
0276: public void addUser(String userName) throws HeroException {
0277:
0278: trace.debug(" Parameter: name=" + userName + " process name = "
0279: + this .getName() + " started by " + this .getCaller());
0280: UserServiceLocalHome ushome;
0281: UserServiceLocal ul;
0282: if (!isAdminOfProject()) {
0283: trace
0284: .error("Only the Admin of the project is allowed to do this operation... ");
0285: throw new AdminException(
0286: "Only the Admin of the project is allowed to do this operation... ");
0287: }
0288: BnUserLocalHome uHome;
0289: BnRoleLocalHome rHome;
0290: BnRoleLocal mRole;
0291: BnUserLocal mUser;
0292: try {
0293: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
0294: uHome = hero.interfaces.BnUserUtil.getLocalHome();
0295: rHome = hero.interfaces.BnRoleUtil.getLocalHome();
0296: } catch (javax.naming.NamingException be) {
0297:
0298: trace.error(be.getMessage());
0299: throw new HeroException(be.getMessage());
0300: }
0301: try {
0302: ul = ushome.create();
0303: mUser = ul.findUser(userName);
0304: } catch (Exception fe) {
0305:
0306: trace.error("User does not exist " + fe.getMessage());
0307: throw new HeroException("User does not exist");
0308: }
0309: Collection cUsers = mProject.getBnUsers();
0310: if (!cUsers.contains(mUser)) {
0311: cUsers.add(mUser);
0312: if (!userName.equals(Constants.ADMIN))
0313: this .addRole(userName, "BnUser BnRole");
0314: this .setUserRole(userName, userName);
0315: if (jms != null)
0316: jms.sendProjectEvent(ADDUSERPROJECT, this .getName(),
0317: userName);
0318: }
0319: }
0320:
0321: /**
0322: * Add a node to the project. This method creates a node with the corresponding
0323: * node type and assign to it the hero.interfaces.Constants.InitialRole role.<br><br>
0324: *
0325: * Possible node types are:<br>
0326: * <br>
0327: * hero.interfaces.Constants.Nd.AND_JOIN_NODE // Manual and join node <br>
0328: * hero.interfaces.Constants.Nd.OR_JOIN_NODE // Manual or join node <br>
0329: * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE // Automatic and join node <br>
0330: * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE // Automatic or join node <br>
0331: *
0332: * @param name The name of the node to add to the project
0333: * @param nodeType The type of the node to add to the project
0334: *
0335: * @ejb:interface-method view-type="both"
0336: * @ejb:transaction type="Required"
0337: * @throws HeroException
0338: *
0339: **/
0340:
0341: public void addNode(String name, int nodeType) throws HeroException {
0342:
0343: trace.debug("parameter: name= " + name + " nodeType= " + name
0344: + " process name = " + this .getName() + " started by "
0345: + this .getCaller());
0346: BnNodeLocalHome nHome;
0347: BnNodeLocal mNode;
0348: if (!isAdminOfProject()) {
0349:
0350: trace
0351: .error("Only the Admin of the project is allowed to do this operation... ");
0352: throw new AdminException(
0353: "Only the Admin of the project is allowed to do this operation... ");
0354: }
0355:
0356: try {
0357: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
0358: } catch (javax.naming.NamingException be) {
0359:
0360: trace.error(be.getMessage());
0361: throw new HeroException(be.getMessage());
0362: }
0363:
0364: try {
0365: BnNodeLocal nf = nHome.findByName(name, mProject.getId());
0366: throw new HeroException("Node " + name
0367: + " already exist in project " + mProject.getName());
0368: } catch (javax.ejb.FinderException nn) {
0369: try {
0370: if (name.equals(""))
0371: throw new HeroException(
0372: "Node name can not be empty...");
0373: BnNodeLocal nd = nHome.create(name, nodeType);
0374: // Models are not executable
0375: if (mProject.getType().equals(Constants.Pj.MODEL))
0376: nd.setState(Constants.Nd.INITIAL);
0377: BnNodeValue ndata = nd.getBnNodeValue();
0378: ndata.setCreationDate(new java.util.Date());
0379: nd.setBnNodeValue(ndata);
0380:
0381: Collection cNodes = mProject.getBnNodes();
0382: cNodes.add(nd);
0383: //nd.setBnProject(mProject);
0384:
0385: String creator = this .getCaller();
0386: nd.setCreator(creator);
0387: nd.setExecutor(creator); // Only for JOnAS consistency
0388: BnRoleLocalHome rHome = BnRoleUtil.getLocalHome();
0389: BnRoleLocal role = rHome.findByName(
0390: hero.interfaces.Constants.INITIALROLE, mProject
0391: .getId());
0392: nd.setBnRole(role);
0393:
0394: // Tell the world
0395: if (jms != null)
0396: jms.sendNodeEvent(ADDNODE, this .getName(), name,
0397: nodeType, ndata.getState(), this
0398: .getCaller());
0399: } catch (InvalidValueException ie) {
0400:
0401: trace.error(ie.getMessage());
0402: throw new HeroException(ie.getMessage());
0403: } catch (CreateException ce) {
0404:
0405: trace.error(ce.getMessage());
0406: throw new HeroException(ce.getMessage());
0407: } catch (FinderException fe) {
0408: fe.printStackTrace();
0409:
0410: trace.error(fe.getMessage());
0411: throw new HeroException(fe.getMessage());
0412: } catch (javax.naming.NamingException ne) {
0413:
0414: trace.error(ne.getMessage());
0415: throw new HeroException(ne.getMessage());
0416: }
0417: }
0418: }
0419:
0420: /**
0421: * Add a subProcess node to the project. This method creates the subProject from an existing
0422: * project and creates the node associated to it. The type of created node is
0423: * hero.interfaces.Constants.Nd.SUB_PROCESS_NODE
0424: *
0425: * @param name The name of the node to add to the project
0426: * @param projectName the name of the subProcess
0427: *
0428: * @ejb:interface-method view-type="both"
0429: * @ejb:transaction type="Required"
0430: * @throws HeroException
0431: *
0432: **/
0433:
0434: public void addNodeSubProcess(String name, String projectName)
0435: throws HeroException {
0436: this .addNodeSubProcess(name, projectName,
0437: EventConstants.DEFAULTPROJECTVERSION);
0438: }
0439:
0440: /**
0441: * Add a subProcess node to the project. This method creates the subProject from an existing
0442: * project and creates the node associated to it. The type of created node is
0443: * hero.interfaces.Constants.Nd.SUB_PROCESS_NODE
0444: *
0445: * @param name The name of the node to add to the project
0446: * @param projectName the name of the subProcess
0447: * @param projectVersion the version of the subProcess
0448: *
0449: * @ejb:interface-method view-type="both"
0450: * @ejb:transaction type="Required"
0451: * @throws HeroException
0452: *
0453: **/
0454:
0455: public void addNodeSubProcess(String name, String projectName,
0456: String projectVersion) throws HeroException {
0457:
0458: trace.debug("parameters : name=" + name + " project="
0459: + projectName + " version = " + projectVersion
0460: + " process name = " + this .getName() + " started by "
0461: + this .getCaller());
0462: if (!isAdminOfProject()) {
0463:
0464: trace
0465: .error("Only the Admin of the project is allowed to do this operation... ");
0466: throw new AdminException(
0467: "Only the Admin of the project is allowed to do this operation... ");
0468: }
0469: try {
0470: // A cooperative project can only add subProcess activities pointing to another cooperative project
0471: if (mProject.getType().equals(Constants.Pj.COOPERATIVE)) {
0472: BnProjectLocalHome pHome;
0473: try {
0474: pHome = hero.interfaces.BnProjectUtil
0475: .getLocalHome();
0476: } catch (javax.naming.NamingException be) {
0477: trace.error(be.getMessage());
0478: throw new HeroException(be.getMessage());
0479: }
0480:
0481: try {
0482: BnProjectLocal pl = pHome.findByName(projectName);
0483: pl.setParent(mProject.getName() + "_node-" + name);
0484: if (!pl.getType().equals(Constants.Pj.COOPERATIVE))
0485: throw new HeroException(
0486: "Cooperatives projects can only reference to cooperative subprocesses !");
0487: } catch (javax.ejb.FinderException nn) {
0488: throw new HeroException(
0489: "This cooperative project does not exist or is not a cooperative one !");
0490: }
0491: }
0492:
0493: this .addNode(name, Constants.Nd.SUB_PROCESS_NODE);
0494: mProject.setParent(mProject.getName());
0495: BnNodeLocal nd = mProject.getBnNode(name);
0496: nd.setReference(projectName + "_version" + projectVersion);
0497:
0498: } catch (Exception ans) {
0499: ans.printStackTrace();
0500: trace.error("Error in addNodeSubProcess "
0501: + ans.getMessage());
0502: throw new HeroException("Error in addNodeSubProcess");
0503: }
0504: }
0505:
0506: /**
0507: * Add an Agent to the Project
0508: *
0509: * @param name The name of the Agent to add to the project
0510: *
0511: * @ejb:interface-method view-type="both"
0512: * @ejb:transaction type="Required"
0513: * @throws HeroException
0514: *
0515: **/
0516: public void addAgent(String name) throws HeroException {
0517:
0518: trace.debug("parameter: name=" + name + " process name = "
0519: + this .getName() + " started by " + this .getCaller());
0520: BnAgentLocalHome nHome;
0521: BnAgentLocal mAgent;
0522: if (!isAdminOfProject()) {
0523:
0524: trace
0525: .error("Only the Admin of the project is allowed to do this operation... ");
0526: throw new AdminException(
0527: "Only the Admin of the project is allowed to do this operation... ");
0528: }
0529: try {
0530: nHome = hero.interfaces.BnAgentUtil.getLocalHome();
0531: } catch (javax.naming.NamingException be) {
0532:
0533: trace.error(be.getMessage());
0534: throw new HeroException(be.getMessage());
0535: }
0536:
0537: try {
0538: BnAgentLocal nf = nHome.findByName(name, mProject.getId());
0539: throw new HeroException("BnAgent " + name
0540: + " already exist in project " + mProject.getName());
0541: } catch (javax.ejb.FinderException nn) {
0542:
0543: trace.error(nn.getMessage());
0544:
0545: try {
0546: BnAgentLocal ag = nHome.create(name);
0547: BnAgentValue adata = ag.getBnAgentValue();
0548: adata.setCreationDate(new java.util.Date());
0549: ag.setBnAgentValue(adata);
0550: Collection cAgents = mProject.getBnAgents();
0551: cAgents.add(ag);
0552: String creator = this .getCaller();
0553: BnUserLocalHome uHome = hero.interfaces.BnUserUtil
0554: .getLocalHome();
0555: BnUserLocal user = uHome.findByName(creator);
0556: ag.setCreator(user);
0557:
0558: } catch (InvalidValueException ie) {
0559:
0560: trace.error(ie.getMessage());
0561: throw new HeroException(ie.getMessage());
0562: } catch (CreateException ce) {
0563:
0564: trace.error(ce.getMessage());
0565: throw new HeroException(ce.getMessage());
0566: } catch (FinderException fe) {
0567:
0568: trace.error(fe.getMessage());
0569: throw new HeroException(fe.getMessage());
0570: } catch (javax.naming.NamingException ne) {
0571:
0572: trace.error(ne.getMessage());
0573: throw new HeroException(ne.getMessage());
0574: }
0575: }
0576: }
0577:
0578: /**
0579: * Add an edge to the project. Creates a transition between two nodes by specifying
0580: * the name of this edge. <strong> No more implemented </strong>
0581: *
0582: * @param name the name ot the edge
0583: *
0584: * @ejb:interface-method view-type="both"
0585: * @ejb:transaction type="Required"
0586: * @throws HeroException
0587: *
0588: **/
0589: public void addEdge(String name, String in, String out)
0590: throws HeroException {
0591:
0592: trace.error("parameters: name=" + name + " in=" + in + " out="
0593: + out + " process name = " + this .getName()
0594: + " started by " + this .getCaller());
0595: throw new HeroException("no more implemented");
0596: }
0597:
0598: /**
0599: * Add an edge between two nodes of the project [in] ---- [out]. This operation refresh
0600: * the out node state. If new edge forms a cycle an exception is throwed.
0601: *
0602: * @param in the name of the in Node
0603: * @param out the name of the out Node
0604: *
0605: * @ejb:interface-method view-type="both"
0606: * @ejb:transaction type="Required"
0607: *
0608: * @throws HeroException
0609: *
0610: **/
0611: public String addEdge(String in, String out) throws HeroException {
0612: ArrayList visited = new ArrayList();
0613:
0614: trace.debug("parameters: in=" + in + " out:" + out
0615: + " process name = " + this .getName() + " started by "
0616: + this .getCaller());
0617: BnEdgeLocalHome eHome;
0618: BnNodeLocalHome nHome;
0619: BnNodeLocal mInNode;
0620: BnNodeLocal mOutNode;
0621: BnEdgeLocal mEdge;
0622: if (!isAdminOfProject()) {
0623:
0624: trace
0625: .error("Only the Admin of the project is allowed to do this operation... ");
0626: throw new AdminException(
0627: "Only the Admin of the project is allowed to do this operation... ");
0628: }
0629: try {
0630: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
0631: } catch (javax.naming.NamingException be) {
0632:
0633: trace.error(be.getMessage());
0634: throw new HeroException(be.getMessage());
0635: }
0636: try {
0637: mInNode = nHome.findByName(in, mProject.getId());
0638: } catch (FinderException fe) {
0639:
0640: trace.error("In Node does not exist " + fe.getMessage());
0641: throw new HeroException("In Node does not exist");
0642: }
0643: try {
0644: mOutNode = nHome.findByName(out, mProject.getId());
0645: } catch (FinderException fe) {
0646:
0647: trace.error("Out Node does not exist " + fe.getMessage());
0648: throw new HeroException("Out Node does not exist");
0649: }
0650: try {
0651: eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
0652: } catch (javax.naming.NamingException be) {
0653:
0654: trace.error(be.getMessage());
0655: throw new HeroException(be.getMessage());
0656: }
0657:
0658: if (checkStructuralConstraints(visited, in, out))
0659: throw new hero.util.EdgeCycleException(
0660: "This edge add a cycle");
0661:
0662: if (checkDynamics(out)) { // check state of Nodes
0663: if (checkDuplicateEdge(in, out)) {
0664: try {
0665: mEdge = eHome.create();
0666: mEdge.setBnProject(mProject);
0667: mEdge.setInBnNode(mInNode);
0668: mEdge.setOutBnNode(mOutNode);
0669:
0670: if (jms != null)
0671: jms.sendEdgeEvent(ADDEDGE, this .getName(),
0672: mEdge.getName(), mInNode.getName(),
0673: mOutNode.getName(), this .getCaller());
0674:
0675: } catch (InvalidValueException ie) {
0676:
0677: trace.error(ie.getMessage());
0678: throw new HeroException(ie.getMessage());
0679: } catch (CreateException ce) {
0680:
0681: trace.error(ce.getMessage());
0682: throw new HeroException(ce.getMessage());
0683: }
0684: } else {
0685: throw new hero.util.DuplicatedEdgeException(
0686: "Cannot add edge. BnEdge between nodes already exist");
0687: }
0688: } else {
0689: throw new hero.util.NodeStartedException(
0690: "Cannot add edge. " + out + " is already started");
0691: }
0692:
0693: // update the current graph state
0694: int edgeState = hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][mInNode
0695: .getState()];
0696: this .setEdgeState(mEdge, edgeState);
0697: /*if (mOutNode.getState()==Constants.Nd.READY)
0698: this.setNodeState(mOutNode, Constants.Nd.INITIAL);*/
0699:
0700: EdgeState edgeStateClass = EdgeState.make(mOutNode.getType());
0701: int newOperation = edgeStateClass.state(mOutNode);
0702: // It doesn't consider CANCEL operation. CANCEL propagation is done by the EngineBean
0703: if (newOperation != Constants.Nd.CANCEL) {
0704: NodeState nodeState = NodeState.make(mOutNode.getType(),
0705: mOutNode.getAnticipable());
0706: int newState = nodeState.computeState(mOutNode,
0707: newOperation);
0708:
0709: if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
0710: throw new HeroException(
0711: "AddEdge generated a bad Node transition");
0712: }
0713: this .setNodeState(mOutNode, newState);
0714: }
0715: return mEdge.getName();
0716: }
0717:
0718: /**
0719: * Add an AgentEdge to the Project [in] ---- [out]
0720: *
0721: * @param in the name of the in Agent
0722: * @param out the name of the out Node
0723: *
0724: * @ejb:interface-method view-type="both"
0725: * @ejb:transaction type="Required"
0726: *
0727: * @throws HeroException
0728: *
0729: **/
0730: public String addAgentEdge(String in, String out)
0731: throws HeroException {
0732:
0733: trace.debug("parameters: in=" + in + " out:" + out
0734: + " process name = " + this .getName() + " started by "
0735: + this .getCaller());
0736: BnAgentEdgeLocalHome eHome;
0737: BnNodeLocalHome nHome;
0738: BnAgentLocalHome aHome;
0739: BnAgentLocal mInAgent;
0740: BnNodeLocal mOutNode;
0741: BnAgentEdgeLocal mEdge;
0742: if (!isAdminOfProject()) {
0743:
0744: trace
0745: .error("Only the Admin of the project is allowed to do this operation... ");
0746: throw new AdminException(
0747: "Only the Admin of the project is allowed to do this operation... ");
0748: }
0749: try {
0750: aHome = hero.interfaces.BnAgentUtil.getLocalHome();
0751: } catch (javax.naming.NamingException be) {
0752:
0753: trace.error(be.getMessage());
0754: throw new HeroException(be.getMessage());
0755: }
0756: try {
0757: mInAgent = aHome.findByName(in, mProject.getId());
0758: } catch (FinderException fe) {
0759:
0760: trace.error("In Agent does not exist " + fe.getMessage());
0761: throw new HeroException("In Agent does not exist");
0762: }
0763: try {
0764: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
0765: } catch (javax.naming.NamingException be) {
0766:
0767: trace.error(be.getMessage());
0768: throw new HeroException(be.getMessage());
0769: }
0770: try {
0771: mOutNode = nHome.findByName(out, mProject.getId());
0772: } catch (FinderException fe) {
0773:
0774: trace.error("Out Node does not exist " + fe.getMessage());
0775: throw new HeroException("Out Node does not exist");
0776: }
0777: try {
0778: eHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome();
0779: } catch (javax.naming.NamingException be) {
0780:
0781: trace.error(be.getMessage());
0782: throw new HeroException(be.getMessage());
0783: }
0784: if (checkDynamics(out)) { // check state of Nodes
0785: if (checkDuplicateAgentEdge(in, out)) {
0786: try {
0787: mEdge = eHome.create();
0788: mEdge.setBnProject(mProject);
0789: mEdge.setInBnAgent(mInAgent);
0790: mEdge.setOutBnNode(mOutNode);
0791:
0792: } catch (InvalidValueException ie) {
0793:
0794: trace.error(ie.getMessage());
0795: throw new HeroException(ie.getMessage());
0796: } catch (CreateException ce) {
0797:
0798: trace.error(ce.getMessage());
0799: throw new HeroException(ce.getMessage());
0800: }
0801: } else {
0802: throw new hero.util.DuplicatedEdgeException(
0803: "Cannot add agentEdge. AgentEdge between nodes already exist");
0804: }
0805: } else {
0806: throw new hero.util.NodeStartedException(
0807: "Cannot add agentEdge. " + out
0808: + " is already started");
0809: }
0810:
0811: // update the current graph state
0812: this .setAgentEdgeState(mEdge,
0813: hero.interfaces.Constants.Ed.INITIAL);
0814:
0815: EdgeState edgeState = EdgeState.make(mOutNode.getType());
0816: int newOperation = edgeState.state(mOutNode);
0817:
0818: NodeState nodeState = NodeState.make(mOutNode.getType(),
0819: mOutNode.getAnticipable());
0820: int newState = nodeState.computeState(mOutNode, newOperation);
0821:
0822: if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
0823: throw new HeroException(
0824: "AddEdge generated a bad Node transition");
0825: }
0826: this .setNodeState(mOutNode, newState);
0827: return mEdge.getName();
0828: }
0829:
0830: /**
0831: * Add a role to the project. Creates a role within this project. The role is specific of this project
0832: *
0833: * @param name the name of the role
0834: * @param description the description of the role
0835: *
0836: * @ejb:interface-method view-type="both"
0837: * @ejb:transaction type="Required"
0838: *
0839: * @throws HeroException
0840: *
0841: **/
0842: public void addRole(String roleName, String description)
0843: throws HeroException {
0844: BnRoleLocalHome roleh;
0845:
0846: trace.debug("parameters: roleName=" + roleName
0847: + " description=" + description + " process name = "
0848: + this .getName() + " started by " + this .getCaller());
0849: if (!isAdminOfProject()) {
0850:
0851: trace
0852: .error("Only the Admin of the project is allowed to do this operation... ");
0853: throw new AdminException(
0854: "Only the Admin of the project is allowed to do this operation... ");
0855: }
0856: try {
0857: roleh = BnRoleUtil.getLocalHome();
0858: } catch (javax.naming.NamingException ne) {
0859:
0860: trace.error(ne.getMessage());
0861: throw new HeroException(ne.getMessage());
0862: }
0863:
0864: try {
0865: BnRoleLocal nf = roleh.findByName(roleName, mProject
0866: .getId());
0867: } catch (javax.ejb.FinderException nn) {
0868: BnRoleValue rv = new BnRoleValue();
0869: rv.setName(roleName);
0870: rv.setDescription(description);
0871: try {
0872: BnRoleLocal rl = roleh.create(rv);
0873: mProject.getBnRoles().add(rl);
0874: //rl.setBnProject(mProject);
0875: if (jms != null)
0876: jms
0877: .sendRoleEvent(ADDROLE, this .getName(),
0878: roleName);
0879: } catch (javax.ejb.CreateException ce) {
0880:
0881: trace.error(ce.getMessage());
0882: throw new HeroException(ce.getMessage());
0883: }
0884: }
0885: }
0886:
0887: /**
0888: * Add a new iteration between two nodes. This methods sets an iteration which is stopped when
0889: * the lastNode property "iterate" is false.
0890: *
0891: * @param from the name of the first node
0892: * @param to the name of the last node
0893: *
0894: * @ejb:interface-method view-type="both"
0895: * @ejb:transaction type="Required"
0896: *
0897: * @throws HeroException
0898: *
0899: **/
0900: public void addIteration(String from, String to, String condition)
0901: throws HeroException {
0902: ArrayList visited = new ArrayList();
0903:
0904: trace.debug("parameters: from=" + from + " to=" + to
0905: + " condition=" + condition + " process name = "
0906: + this .getName() + " started by " + this .getCaller());
0907: if (!isAdminOfProject()) {
0908: trace
0909: .error("Only the Admin of the project is allowed to do this operation... ");
0910: throw new AdminException(
0911: "Only the Admin of the project is allowed to do this operation... ");
0912: }
0913: if (this .checkStructuralConstraints(visited, from, to)) {
0914: this .copyIteration(from, to, condition);
0915: } else {
0916: throw new HeroException("This iteration is not possible...");
0917: }
0918: }
0919:
0920: /**
0921: * Internal method used in processes instantiation.
0922: *
0923: * @param from
0924: * @param to
0925: * @param condition
0926: * @throws HeroException
0927: * @ejb:interface-method view-type="local"
0928: * @ejb:transaction type="Required"
0929: */
0930: public void copyIteration(String from, String to, String condition)
0931: throws HeroException {
0932: BnIterationLocalHome iteh;
0933:
0934: try {
0935: iteh = BnIterationUtil.getLocalHome();
0936: } catch (javax.naming.NamingException ne) {
0937: trace.error(ne.getMessage());
0938: throw new HeroException(ne.getMessage());
0939: }
0940: try {
0941: iteh.findByFromTo(from, to, mProject.getId());
0942: throw new HeroException("Iteration already exist between: "
0943: + from + " and " + to + " nodes, in project "
0944: + mProject.getName());
0945: } catch (javax.ejb.FinderException nn) {
0946: BnIterationLightValue iv = new BnIterationLightValue();
0947: iv.setFromNode(from);
0948: iv.setToNode(to);
0949: iv.setCondition(condition);
0950: try {
0951: BnIterationLocal il = iteh.create(iv);
0952: mProject.getBnIterations().add(il);
0953: if (jms != null) {
0954: jms.sendIterationEvent(ADDITERATION,
0955: this .getName(), from, to);
0956: }
0957: } catch (Exception ce) {
0958: trace.error(ce.getMessage());
0959: throw new HeroException(ce.getMessage());
0960: }
0961: }
0962: }
0963:
0964: /**
0965: * Delete an iteration between two nodes.
0966: *
0967: * @param from the name of the first node
0968: * @param to the name of the last node
0969: *
0970: * @ejb:interface-method view-type="both"
0971: * @ejb:transaction type="Required"
0972: *
0973: * @throws HeroException
0974: *
0975: **/
0976: public void deleteIteration(String from, String to)
0977: throws HeroException {
0978:
0979: trace.debug("parameters: from=" + from + " to=" + to
0980: + " process name = " + this .getName() + " started by "
0981: + this .getCaller());
0982: BnIterationLocalHome iteh;
0983: if (!isAdminOfProject()) {
0984:
0985: trace
0986: .error("Only the Admin of the project is allowed to do this operation... ");
0987: throw new AdminException(
0988: "Only the Admin of the project is allowed to do this operation... ");
0989: }
0990: try {
0991: iteh = BnIterationUtil.getLocalHome();
0992: } catch (javax.naming.NamingException ne) {
0993:
0994: trace.error(ne.getMessage());
0995: throw new HeroException(ne.getMessage());
0996: }
0997: try {
0998: BnIterationLocal it = iteh.findByFromTo(from, to, mProject
0999: .getId());
1000: it.remove();
1001: } catch (javax.ejb.FinderException nn) {
1002:
1003: trace.error("Iteration does not exist: " + from + " and "
1004: + to + " nodes, in project " + mProject.getName());
1005: throw new HeroException("Iteration does not exist: " + from
1006: + " and " + to + " nodes, in project "
1007: + mProject.getName());
1008: } catch (javax.ejb.RemoveException rn) {
1009:
1010: trace.error("Error when deleting activity iteration: "
1011: + from + " and " + to + " nodes, in project "
1012: + mProject.getName());
1013: throw new HeroException(
1014: "Error when deleting activity iteration: " + from
1015: + " and " + to + " nodes, in project "
1016: + mProject.getName());
1017: }
1018: }
1019:
1020: /**
1021: * Add hook to project. Add an existing hook file to the project. This hook type uses a
1022: * Java file loaded at run time. The hookName represents the class java file to be loaded by the system at run time.
1023: * These classes must be in the application server classpath to be correctly executed.<br>
1024: *
1025: * The possible values of the argumets are:<br><br>
1026: * <strong>eventName:<br></strong>
1027: * hero.interfaces.Constants.Pj.ONINSTANTIATE<br><br>
1028: * hero.interfaces.Constants.Pj.ONTERMINATE<br><br>
1029: *
1030: * @param hookName the name of the hook
1031: * @param eventName the event
1032: * @param hookType the type
1033: * @ejb:interface-method view-type="both"
1034: * @ejb:transaction type="Required"
1035: * @throws HeroException
1036: *
1037: **/
1038: public void addHook(String hookName, String eventName, int hookType)
1039: throws HeroException {
1040:
1041: trace.debug("parameters: hookName=" + hookName + " eventName="
1042: + eventName + " process name = " + this .getName()
1043: + " started by " + this .getCaller());
1044: BnProjectHookLocalHome pHome;
1045: BnProjectHookLocal ppLocal;
1046: if (!isAdminOfProject()) {
1047:
1048: trace
1049: .error("Only the Admin of the project is allowed to do this operation... ");
1050: throw new AdminException(
1051: "Only the Admin of the project is allowed to do this operation... ");
1052: }
1053: try {
1054: pHome = BnProjectHookUtil.getLocalHome();
1055: } catch (javax.naming.NamingException ne) {
1056:
1057: trace.error(ne.getMessage());
1058: throw new HeroException(ne.getMessage());
1059: }
1060:
1061: try {
1062: BnProjectHookLocal pf = pHome.findByName(mProject.getId(),
1063: hookName);
1064: throw new HeroException("BnProject hook " + hookName
1065: + " already exist in project " + mProject.getName());
1066: } catch (javax.ejb.FinderException pn) {
1067: try {
1068: BnProjectHookLocal h = pHome.create(hookName,
1069: eventName, hookType);
1070: h.setBnProject(mProject);
1071: } catch (CreateException fe) {
1072:
1073: trace.error(fe.getMessage());
1074: throw new HeroException(fe.getMessage());
1075: } catch (InvalidValueException ie) {
1076:
1077: trace.error(ie.getMessage());
1078: throw new HeroException(ie.getMessage());
1079: }
1080: }
1081: }
1082:
1083: /**
1084: * Add hook to a node. Add an existing hook file to the node. This type of hook use a
1085: * Java file loaded at run time. The hookName represents the class java file to be loaded by the system at run time.
1086: * These classes must be in the application server classpath to be correctly executed.<br>
1087: * The possible values of the arguments are:<br><br>
1088: * <strong>eventName:<br></strong>
1089: * hero.interfaces.Constants.Nd.BEFORESTART<br>
1090: * hero.interfaces.Constants.Nd.AFTERSTART<br>
1091: * hero.interfaces.Constants.Nd.BEFORETERMINATE<br>
1092: * hero.interfaces.Constants.Nd.AFTERTERMINATE<br>
1093: * hero.interfaces.Constants.Nd.ONCANCEL<br>
1094: * hero.interfaces.Constants.Nd.ANTICIPATE<br><br>
1095: * hero.interfaces.Constants.Nd.ONDEADLINE<br><br>
1096: * hero.interfaces.Constants.Nd.ONREADY<br><br>
1097: *
1098: *<br><br>
1099: * <strong>hookType:<br></strong>
1100: * hero.interfaces.Constants.Hook.JAVA<br><br>
1101: * hero.interfaces.Constants.Hook.BSINTERACTIVE<br><br>
1102: *
1103: * @param nodeName the name of the node
1104: * @param hookName the name of the hook
1105: * @param eventName the name of the event
1106: * @param hookType the type of the hook
1107: * @ejb:interface-method view-type="both"
1108: * @ejb:transaction type="Required"
1109: * @throws HeroException
1110: *
1111: **/
1112: public void addNodeHook(String nodeName, String hookName,
1113: String eventName, int hookType) throws HeroException {
1114:
1115: trace.debug("parameters: node=" + nodeName + " hookName="
1116: + hookName + " eventName=" + eventName
1117: + " process name = " + this .getName() + " started by "
1118: + this .getCaller());
1119: BnNodeHookLocalHome pHome;
1120: BnNodeHookLocal ppLocal;
1121: if (!isAdminOfProject()) {
1122:
1123: trace
1124: .error("Only the Admin of the project is allowed to do this operation... ");
1125: throw new AdminException(
1126: "Only the Admin of the project is allowed to do this operation... ");
1127: }
1128: BnNodeLocal nd = mProject.getBnNode(nodeName);
1129: try {
1130: pHome = BnNodeHookUtil.getLocalHome();
1131: } catch (javax.naming.NamingException ne) {
1132:
1133: trace.error(ne.getMessage());
1134: throw new HeroException(ne.getMessage());
1135: }
1136:
1137: try {
1138: BnNodeHookLocal nf = pHome.findByName(nd.getId(), hookName);
1139: throw new HeroException("BnNode hook " + hookName
1140: + " already exist in node " + nodeName);
1141: } catch (javax.ejb.FinderException nn) {
1142: try {
1143: BnNodeHookLocal h = pHome.create(hookName, eventName,
1144: hookType);
1145: h.setBnNode(nd);
1146: } catch (CreateException fe) {
1147:
1148: trace.error(fe.getMessage());
1149: throw new HeroException(fe.getMessage());
1150: } catch (InvalidValueException ie) {
1151:
1152: trace.error(ie.getMessage());
1153: throw new HeroException(ie.getMessage());
1154: }
1155: }
1156: }
1157:
1158: /**
1159: * Add/Update a mapper for the INITIATOR role. This type of mapper use a
1160: * Java file loaded at run time.
1161: *
1162: * @param mapperName the name of the mapper
1163: * @param mapperType the type of the mapper
1164: * @ejb:interface-method view-type="both"
1165: * @ejb:transaction type="Required"
1166: * @throws HeroException
1167: *
1168: **/
1169: public void addInitiatorMapper(String mapperName, int mapperType)
1170: throws HeroException {
1171:
1172: trace.debug("addInitiatorMapper/parameters: projectName="
1173: + mProject.getName() + " mapperName=" + mapperName
1174: + " mapperType=" + mapperType + " process name = "
1175: + this .getName() + " started by " + this .getCaller());
1176:
1177: BnInitiatorMapperLocalHome mapperh;
1178: BnInitiatorMapperLocal ppLocal = null;
1179: BnProjectLocal project = null;
1180: if (!isAdminOfProject()) {
1181:
1182: trace
1183: .error("Only the Admin of the project is allowed to do this operation... ");
1184: throw new AdminException(
1185: "Only the Admin of the project is allowed to do this operation... ");
1186: }
1187: try {
1188: mapperh = BnInitiatorMapperUtil.getLocalHome();
1189: } catch (javax.naming.NamingException ne) {
1190:
1191: trace.error(ne.getMessage());
1192: throw new HeroException(ne.getMessage());
1193: }
1194: // if the project has not already an initiator mapper put one. Otherwise update it.
1195: ppLocal = mProject.getBnInitiatorMapper();
1196: if (ppLocal != null) {
1197: ppLocal.setName(mapperName);
1198: ppLocal.setType(mapperType);
1199: } else {
1200: try {
1201: ppLocal = mapperh.create(mapperName, mapperType);
1202: ppLocal.setBnProject(mProject);
1203: } catch (CreateException fe) {
1204:
1205: trace.error(fe.getMessage());
1206: throw new HeroException(fe.getMessage());
1207: } catch (InvalidValueException ie) {
1208:
1209: trace.error(ie.getMessage());
1210: throw new HeroException(ie.getMessage());
1211: }
1212: }
1213: }
1214:
1215: /**
1216: * Add/Update an existing mapper to the role. This type of mapper use a
1217: * Java file loaded at run time.
1218: *
1219: * @param roleName the name of the role
1220: * @param mapperName the name of the mapper
1221: * @param mapperType the type of the mapper
1222: * @ejb:interface-method view-type="both"
1223: * @ejb:transaction type="Required"
1224: * @throws HeroException
1225: *
1226: **/
1227: public void addRoleMapper(String roleName, String mapperName,
1228: int mapperType) throws HeroException {
1229: // logs trace
1230:
1231: trace.debug("parameters: roleName=" + roleName + " mapperName="
1232: + mapperName + " mapperType=" + mapperType
1233: + " process name = " + this .getName() + " started by "
1234: + this .getCaller());
1235:
1236: BnRoleMapperLocalHome mapperh;
1237: BnRoleLocalHome roleh;
1238: BnRoleMapperLocal ppLocal = null;
1239: BnRoleLocal role = null;
1240: if (!isAdminOfProject()) {
1241: trace
1242: .error("Only the Admin of the project is allowed to do this operation... ");
1243: throw new AdminException(
1244: "Only the Admin of the project is allowed to do this operation... ");
1245: }
1246: try {
1247: mapperh = BnRoleMapperUtil.getLocalHome();
1248: roleh = BnRoleUtil.getLocalHome();
1249: } catch (javax.naming.NamingException ne) {
1250:
1251: trace.error(ne.getMessage());
1252: throw new HeroException(ne.getMessage());
1253: }
1254: // Get objet role local with findByName from BnRoleBean
1255: try {
1256: role = roleh.findByName(roleName, mProject.getId());
1257: } catch (FinderException pfe) {
1258:
1259: trace.error(pfe.getMessage());
1260: throw new HeroException(
1261: "The bnRole does not exist for role : " + roleName);
1262: }
1263: // if the role has not already a mapper put one. Otherwise update it.
1264: ppLocal = role.getBnRoleMapper();
1265: if (ppLocal != null) {
1266: ppLocal.setName(mapperName);
1267: ppLocal.setType(mapperType);
1268: } else {
1269: try {
1270: ppLocal = mapperh.create(mapperName, mapperType);
1271: ppLocal.setBnRole(role);
1272: } catch (CreateException fe) {
1273:
1274: trace.error(fe.getMessage());
1275: throw new HeroException(fe.getMessage());
1276: } catch (InvalidValueException ie) {
1277:
1278: trace.error(ie.getMessage());
1279: throw new HeroException(ie.getMessage());
1280: }
1281: }
1282: }
1283:
1284: /**
1285: * Add/Update an existing performerAssign to the node. This type of performerAssign use a
1286: * Java file loaded at run time.
1287: *
1288: * @param nodeName the name of the node
1289: * @param performerAssignName the name of the performerAssign
1290: * @param performerAssignType the type of the performerAssign
1291: * @ejb:interface-method view-type="both"
1292: * @ejb:transaction type="Required"
1293: * @throws HeroException
1294: *
1295: **/
1296: public void addNodePerformerAssign(String nodeName,
1297: String performerAssignName, int performerAssignType,
1298: String propertyName) throws HeroException {
1299: // logs trace
1300:
1301: trace.debug("addNodePerformerAssign: node = " + nodeName
1302: + " performerAssignName = " + performerAssignName);
1303:
1304: BnNodePerformerAssignLocalHome performerAssignh;
1305: BnNodeLocalHome nodeh;
1306: BnNodePerformerAssignLocal ppLocal = null;
1307: BnNodeLocal node = null;
1308: if (!isAdminOfProject()) {
1309:
1310: trace
1311: .error("Only the Admin of the project is allowed to do this operation... ");
1312: throw new AdminException(
1313: "Only the Admin of the project is allowed to do this operation... ");
1314: }
1315: try {
1316: performerAssignh = BnNodePerformerAssignUtil.getLocalHome();
1317: nodeh = BnNodeUtil.getLocalHome();
1318: } catch (javax.naming.NamingException ne) {
1319: throw new HeroException(ne.getMessage());
1320: }
1321: // Get object node local with findByName from BnNodeBean
1322: try {
1323: node = nodeh.findByName(nodeName, mProject.getId());
1324: } catch (FinderException pfe) {
1325: throw new HeroException(
1326: "The bnNode does not exist for node : " + nodeName);
1327: }
1328: // if the node has not already a performerAssign put one. Otherwise update it.
1329: ppLocal = node.getBnNodePerformerAssign();
1330: if (ppLocal != null) {
1331: ppLocal.setName(performerAssignName);
1332: ppLocal.setType(performerAssignType);
1333: ppLocal.setPropertyName(propertyName);
1334: } else {
1335: try {
1336: ppLocal = performerAssignh.create(performerAssignName,
1337: performerAssignType, propertyName);
1338: ppLocal.setBnNode(node);
1339: } catch (CreateException fe) {
1340: throw new HeroException(fe.getMessage());
1341: } catch (InvalidValueException ie) {
1342: throw new HeroException(ie.getMessage());
1343: }
1344: }
1345: }
1346:
1347: /**
1348: * Remove the performer assign defined for this node
1349: *
1350: * @param nodeName the name of the node
1351: * @ejb:interface-method view-type="both"
1352: * @ejb:transaction type="Required"
1353: * @throws HeroException
1354: * @throws RemoveException
1355: * @throws EJBException
1356: *
1357: **/
1358: public void removeNodePerformerAssign(String nodeName)
1359: throws HeroException, EJBException, RemoveException {
1360: // logs trace
1361: trace.debug("removeNodePerformerAssign: node = " + nodeName
1362: + " performerAssignName = ");
1363:
1364: BnNodePerformerAssignLocalHome performerAssignh;
1365: BnNodeLocalHome nodeh;
1366: BnNodePerformerAssignLocal ppLocal = null;
1367: BnNodeLocal node = null;
1368: if (!isAdminOfProject()) {
1369: trace
1370: .error("Only the Admin of the project is allowed to do this operation... ");
1371: throw new AdminException(
1372: "Only the Admin of the project is allowed to do this operation... ");
1373: }
1374: try {
1375: performerAssignh = BnNodePerformerAssignUtil.getLocalHome();
1376: nodeh = BnNodeUtil.getLocalHome();
1377: } catch (javax.naming.NamingException ne) {
1378: throw new HeroException(ne.getMessage());
1379: }
1380: // Get object node local with findByName from BnNodeBean
1381: try {
1382: node = nodeh.findByName(nodeName, mProject.getId());
1383: } catch (FinderException pfe) {
1384: throw new HeroException(
1385: "The bnNode does not exist for node : " + nodeName);
1386: }
1387: // if the node has a performer assign remove it.
1388: ppLocal = node.getBnNodePerformerAssign();
1389: if (ppLocal != null) {
1390: ppLocal.remove();
1391: }
1392: }
1393:
1394: /**
1395: * Add interhook to a node. Set a new hook to this node by setting the eventName, hookType and
1396: * script values.<br><br>
1397: *
1398: * The possible values of the argumets are:<br><br>
1399: * <strong>eventName:<br></strong>
1400: * hero.interfaces.Constants.Nd.BEFORESTART<br>
1401: * hero.interfaces.Constants.Nd.AFTERSTART<br>
1402: * hero.interfaces.Constants.Nd.BEFORETERMINATE<br>
1403: * hero.interfaces.Constants.Nd.AFTERTERMINATE<br>
1404: * hero.interfaces.Constants.Nd.ONCANCEL<br>
1405: * hero.interfaces.Constants.Nd.ANTICIPATE<br><br>
1406: * hero.interfaces.Constants.Nd.ONDEADLINE<br><br>
1407: * hero.interfaces.Constants.Nd.ONREADY<br><br>
1408: *
1409: * <strong>hookType:<br></strong>
1410: *
1411: * hero.hook.Hook.BSINTERACTIVE<br><br>
1412: *
1413: * <strong>script:<br></strong>
1414: * The beanshell source code associated to this hook.<br><br>
1415: *
1416: * <strong>The following sample code illustrates how to use this method:<br><br></strong>
1417: *
1418: * ...<br>
1419: * String script = "import hero.interfaces.*;\n"<br>
1420: * + "import hero.interfaces.BnNodeLocal;\n"<br>
1421: * + "beforeStart (Object b,Object n) {\n\n\n"<br>
1422: * + "System.out.println(\"Hook Test\");\n"<br>
1423: * + "}";<br>
1424: * <strong>yourProjectSessionInstance</strong>.addNodeInterHook("NodeName","Hook_Name",Constants.Nd.BEFORESTART,hero.hook.Hook.BSINTERACTIVE,script);
1425: *
1426: * @param nodeName the name of the node
1427: * @param hookName the name of the hook
1428: * @param eventName the name of the event
1429: * @param hookType the type of the hook
1430: * @param script the value of the script
1431: * @ejb:interface-method view-type="both"
1432: * @ejb:transaction type="Required"
1433: * @throws HeroException
1434: *
1435: **/
1436: public void addNodeInterHook(String nodeName, String hookName,
1437: String eventName, int hookType, String value)
1438: throws HeroException {
1439:
1440: trace.debug("parameters: node=" + nodeName + " hookName="
1441: + hookName + " eventName=" + eventName + " value="
1442: + value + " process name = " + this .getName()
1443: + " started by " + this .getCaller());
1444: BnNodeInterHookLocalHome pHome;
1445: BnNodeInterHookLocal ppLocal;
1446: if (!isAdminOfProject()) {
1447:
1448: trace
1449: .error("Only the Admin of the project is allowed to do this operation... ");
1450: throw new AdminException(
1451: "Only the Admin of the project is allowed to do this operation... ");
1452: }
1453:
1454: BnNodeLocal nd = mProject.getBnNode(nodeName);
1455: try {
1456: pHome = BnNodeInterHookUtil.getLocalHome();
1457: } catch (javax.naming.NamingException ne) {
1458:
1459: trace.error(ne.getMessage());
1460: throw new HeroException(ne.getMessage());
1461: }
1462:
1463: try {
1464: BnNodeInterHookLocal nf = pHome.findByName(nd.getId(),
1465: hookName);
1466: throw new HeroException("Interactive node hook " + hookName
1467: + " already exist in node " + nodeName);
1468: } catch (javax.ejb.FinderException nn) {
1469: try {
1470: BnNodeInterHookLocal h = pHome.create(hookName,
1471: eventName, hookType, value);
1472: h.setBnNode(nd);
1473: } catch (CreateException fe) {
1474:
1475: trace.error(fe.getMessage());
1476: throw new HeroException(fe.getMessage());
1477: } catch (InvalidValueException ie) {
1478:
1479: trace.error(ie.getMessage());
1480: throw new HeroException(ie.getMessage());
1481: }
1482: }
1483: }
1484:
1485: /**
1486: * Add interhook to the project. Creates new hook associated to all project activites.
1487: * See the {@link #addNodeInterHook(String,String,String,int,String) addNodeInterHook} method in order
1488: * to identify arguments values.
1489: *
1490: * @param hookName the name of the hook
1491: * @param eventName the name of the event
1492: * @param hookType the type of the hook
1493: * @param script the value of the script
1494: * @ejb:interface-method view-type="both"
1495: * @ejb:transaction type="Required"
1496: * @throws HeroException
1497: *
1498: **/
1499: public void addInterHook(String hookName, String eventName,
1500: int hookType, String value) throws HeroException {
1501:
1502: trace.debug("parameters: hookName=" + hookName + " eventName="
1503: + eventName + " value=" + value + " process name = "
1504: + this .getName() + " started by " + this .getCaller());
1505: BnProjectInterHookLocalHome pHome;
1506: BnProjectInterHookLocal ppLocal;
1507: if (!isAdminOfProject()) {
1508:
1509: trace
1510: .error("Only the Admin of the project is allowed to do this operation... ");
1511: throw new AdminException(
1512: "Only the Admin of the project is allowed to do this operation... ");
1513: }
1514: try {
1515: pHome = BnProjectInterHookUtil.getLocalHome();
1516: } catch (javax.naming.NamingException ne) {
1517:
1518: trace.error(ne.getMessage());
1519: throw new HeroException(ne.getMessage());
1520: }
1521:
1522: try {
1523: BnProjectInterHookLocal nf = pHome.findByName(mProject
1524: .getId(), hookName);
1525: throw new HeroException("Interactive hook " + hookName
1526: + " already exist in project " + mProject.getName());
1527: } catch (javax.ejb.FinderException nn) {
1528: try {
1529: BnProjectInterHookLocal h = pHome.create(hookName,
1530: eventName, hookType, value);
1531: h.setBnProject(mProject);
1532: } catch (CreateException fe) {
1533:
1534: trace.error(fe.getMessage());
1535: throw new HeroException(fe.getMessage());
1536: } catch (InvalidValueException ie) {
1537:
1538: trace.error(ie.getMessage());
1539: throw new HeroException(ie.getMessage());
1540: }
1541: }
1542: }
1543:
1544: /**
1545: * Active a workflow process (model/cooperative)
1546: *
1547: * @param name the name of the workflow process
1548: *
1549: * @ejb:interface-method view-type="both"
1550: * @ejb:transaction type="Required"
1551: * @throws HeroException
1552: *
1553: **/
1554: public void activeProcess() throws HeroException {
1555: if (!isAdminOfProject()) {
1556:
1557: trace
1558: .error("Only the Admin of the project is allowed to do this operation... ");
1559: throw new AdminException(
1560: "Only the Admin of the project is allowed to do this operation... ");
1561: }
1562: if ((mProject.getStatus().equals(Constants.Pj.HIDDEN))
1563: || (mProject.getStatus()
1564: .equals(Constants.Pj.UNDEPLOYED))) {
1565: mProject.setStatus(Constants.Pj.ACTIVE);
1566: try {
1567: if (mProject.getType().equals(Constants.Pj.MODEL))
1568: BonitaProjectLocator.getInstance().cleanModelValue(
1569: this .getName(), this .getVersion());
1570: } catch (BonitaServiceException se) {
1571: throw new HeroException(se.getMessage());
1572: }
1573: } else
1574: throw new HeroException("This project is already ACTIVE...");
1575: }
1576:
1577: /**
1578: * Hide a workflow process (model/cooperative).
1579: * This method also clean the associated cache to this model.
1580: *
1581: * @param name the name of the workflow process
1582: *
1583: * @ejb:interface-method view-type="both"
1584: * @ejb:transaction type="Required"
1585: * @throws HeroException
1586: *
1587: **/
1588: public void hideProcess() throws HeroException {
1589: if (!isAdminOfProject()) {
1590:
1591: trace
1592: .error("Only the Admin of the project is allowed to do this operation... ");
1593: throw new AdminException(
1594: "Only the Admin of the project is allowed to do this operation... ");
1595: }
1596: if (mProject.getStatus().equals(Constants.Pj.ACTIVE)) {
1597: mProject.setStatus(Constants.Pj.HIDDEN);
1598: try {
1599: if (mProject.getType().equals(Constants.Pj.MODEL))
1600: BonitaProjectLocator.getInstance().cleanModelValue(
1601: this .getName(), this .getVersion());
1602: } catch (BonitaServiceException se) {
1603: throw new HeroException(se.getMessage());
1604: }
1605: }
1606:
1607: else
1608: throw new HeroException(
1609: "This projects is already HIDDEN...");
1610: }
1611:
1612: /**
1613: * Undeploy a workflow process (model/cooperative).
1614: * This method does not clean the associated cache to this model.
1615: *
1616: * @param name the name of the workflow process
1617: *
1618: * @ejb:interface-method view-type="both"
1619: * @ejb:transaction type="Required"
1620: * @throws HeroException
1621: *
1622: **/
1623: public void unDeployProcess() throws HeroException {
1624: if (!isAdminOfProject()) {
1625:
1626: trace
1627: .error("Only the Admin of the project is allowed to do this operation... ");
1628: throw new AdminException(
1629: "Only the Admin of the project is allowed to do this operation... ");
1630: }
1631: if (mProject.getStatus().equals(Constants.Pj.ACTIVE)) {
1632: mProject.setStatus(Constants.Pj.UNDEPLOYED);
1633: try {
1634: if (mProject.getType().equals(Constants.Pj.MODEL))
1635: BonitaProjectLocator.getInstance().cleanModelValue(
1636: this .getName(), this .getVersion());
1637: } catch (BonitaServiceException se) {
1638: throw new HeroException(se.getMessage());
1639: }
1640: }
1641: }
1642:
1643: // -------------------------------------------------------------------------
1644: // Delete business methods
1645: // -------------------------------------------------------------------------
1646:
1647: /**
1648: * Delete a node from the project. If this node is in executing state, the
1649: * method throws an execption
1650: *
1651: * @param name the name of the edge
1652: *
1653: * @ejb:interface-method view-type="both"
1654: * @ejb:transaction type="Required"
1655: * @throws HeroException
1656: *
1657: **/
1658: public void deleteNode(String name) throws HeroException {
1659: // check deletion conditions
1660:
1661: trace.debug("parameter: name=" + name + " process name = "
1662: + this .getName() + " started by " + this .getCaller());
1663: if (!isAdminOfProject()) {
1664:
1665: trace
1666: .error("Only the Admin of the project is allowed to do this operation... ");
1667: throw new AdminException(
1668: "Only the Admin of the project is allowed to do this operation... ");
1669: }
1670: BnNodeLocal nd = mProject.getBnNode(name);
1671: if (nd.isExecuting()) {
1672: throw new NodeExecutingException(
1673: "Cannot delete node. It is executing");
1674: }
1675: /* if (nd.isTerminated()) {
1676: throw new NodeTerminatedException("Cannot delete node. It is terminated");
1677: }
1678: if (nd.isCancelled()) {
1679: throw new NodeCancelledException("Cannot delete node. It is cancelled");
1680: }*/
1681: if (this .getNodeType(name) == Constants.Nd.SUB_PROCESS_NODE) {
1682: try {
1683: BnProjectLocal plocal = pHome.findByNameVersion(name,
1684: EventConstants.DEFAULTPROJECTVERSION);
1685: Collection nodes = plocal.getBnNodes();
1686: Iterator nds = nodes.iterator();
1687: while (nds.hasNext()) // Verifies if the project has any subProcesses
1688: {
1689: BnNodeLocal nod = (BnNodeLocal) nds.next();
1690: if (nod.getType() == Constants.Nd.SUB_PROCESS_NODE)
1691: throw new HeroException(
1692: "Error in delete project: You have to delete subProcesses first !!");
1693: }
1694: plocal.remove();
1695: if (jms != null)
1696: jms.sendProjectEvent(DELETEPROJECT, name);
1697: } catch (RemoveException pre) {
1698:
1699: trace
1700: .error("Cannot remove project "
1701: + pre.getMessage());
1702: throw new HeroException("Cannot remove project "
1703: + pre.getMessage());
1704: } catch (FinderException pfe) {
1705:
1706: trace.error("Cannot find project " + pfe.getMessage());
1707: throw new HeroException("Cannot find project "
1708: + pfe.getMessage());
1709: }
1710: }
1711:
1712: Collection edgesIn = nd.getInBnEdges();
1713: Object[] edai = edgesIn.toArray();
1714: for (int i = 0; i < edai.length; i++) {
1715: edgeDeletion((BnEdgeLocal) edai[i]);
1716: }
1717: Collection edgesOut = nd.getOutBnEdges();
1718: Object[] edao = edgesOut.toArray();
1719: for (int i = 0; i < edao.length; i++) {
1720: edgeDeletion((BnEdgeLocal) edao[i]);
1721: }
1722: try {
1723: int state = nd.getState();
1724: int type = nd.getType();
1725: nd.remove();
1726: if (jms != null)
1727: jms.sendNodeEvent(DELETENODE, this .getName(), name,
1728: type, state, this .getCaller());
1729: } catch (RemoveException re) {
1730:
1731: trace.error("Cannot remove node " + re.getMessage());
1732: throw new HeroException("Cannot remove node "
1733: + re.getMessage());
1734: }
1735: }
1736:
1737: /**
1738: * Delete a node with type subProcess from the project. If this node is in executing state, the
1739: * method throws an execption
1740: *
1741: * @param name the name of the edge
1742: *
1743: * @ejb:interface-method view-type="both"
1744: * @ejb:transaction type="Required"
1745: * @throws HeroException
1746: *
1747: **/
1748: public void deleteSubProcessNode(String name, String version)
1749: throws HeroException {
1750: // check deletion conditions
1751:
1752: trace.debug("parameter: name=" + name + " process name = "
1753: + this .getName() + " started by " + this .getCaller());
1754: if (!isAdminOfProject()) {
1755:
1756: trace
1757: .error("Only the Admin of the project is allowed to do this operation... ");
1758: throw new AdminException(
1759: "Only the Admin of the project is allowed to do this operation... ");
1760: }
1761: BnNodeLocal nd = mProject.getBnNode(name);
1762: if (nd.isExecuting()) {
1763: throw new NodeExecutingException(
1764: "Cannot delete node. It is executing");
1765: }
1766: /* if (nd.isTerminated()) {
1767: throw new NodeTerminatedException("Cannot delete node. It is terminated");
1768: }
1769: if (nd.isCancelled()) {
1770: throw new NodeCancelledException("Cannot delete node. It is cancelled");
1771: }*/
1772: if (this .getNodeType(name) == Constants.Nd.SUB_PROCESS_NODE) {
1773: try {
1774: BnProjectLocal plocal = pHome.findByNameVersion(name,
1775: version);
1776: Collection nodes = plocal.getBnNodes();
1777: Iterator nds = nodes.iterator();
1778: while (nds.hasNext()) // Verifies if the project has any subProcesses
1779: {
1780: BnNodeLocal nod = (BnNodeLocal) nds.next();
1781: if (nod.getType() == Constants.Nd.SUB_PROCESS_NODE)
1782: throw new HeroException(
1783: "Error in delete project: You have to delete subProcesses first !!");
1784: }
1785: plocal.remove();
1786: if (jms != null)
1787: jms.sendProjectEvent(DELETEPROJECT, name);
1788: } catch (RemoveException pre) {
1789:
1790: trace
1791: .error("Cannot remove project "
1792: + pre.getMessage());
1793: throw new HeroException("Cannot remove project "
1794: + pre.getMessage());
1795: } catch (FinderException pfe) {
1796:
1797: trace.error("Cannot find project " + pfe.getMessage());
1798: throw new HeroException("Cannot find project "
1799: + pfe.getMessage());
1800: }
1801: }
1802:
1803: Collection edgesIn = nd.getInBnEdges();
1804: Object[] edai = edgesIn.toArray();
1805: for (int i = 0; i < edai.length; i++) {
1806: edgeDeletion((BnEdgeLocal) edai[i]);
1807: }
1808: Collection edgesOut = nd.getOutBnEdges();
1809: Object[] edao = edgesOut.toArray();
1810: for (int i = 0; i < edao.length; i++) {
1811: edgeDeletion((BnEdgeLocal) edao[i]);
1812: }
1813: try {
1814: int state = nd.getState();
1815: int type = nd.getType();
1816: nd.remove();
1817: if (jms != null)
1818: jms.sendNodeEvent(DELETENODE, this .getName(), name,
1819: type, state, this .getCaller());
1820: } catch (RemoveException re) {
1821:
1822: trace.error("Cannot remove node " + re.getMessage());
1823: throw new HeroException("Cannot remove node "
1824: + re.getMessage());
1825: }
1826: }
1827:
1828: /**
1829: * Delete an edge to the project. If out node of this edge is in executing, terminated or cancelled state, the
1830: * method throws an execption.
1831: *
1832: * @param name the name ot the edge
1833: *
1834: * @ejb:interface-method view-type="both"
1835: * @ejb:transaction type="Required"
1836: * @throws HeroException
1837: *
1838: **/
1839: public void deleteEdge(String name) throws HeroException {
1840: // check deletion conditions
1841:
1842: trace.debug("parameter: name=" + name + " process name = "
1843: + this .getName() + " started by " + this .getCaller());
1844: BnEdgeLocalHome eh;
1845: BnEdgeLocal ed;
1846: if (!isAdminOfProject()) {
1847:
1848: trace
1849: .error("Only the Admin of the project is allowed to do this operation... ");
1850: throw new AdminException(
1851: "Only the Admin of the project is allowed to do this operation... ");
1852: }
1853: try {
1854: eh = BnEdgeUtil.getLocalHome();
1855: } catch (javax.naming.NamingException ne) {
1856:
1857: trace.error(ne.getMessage());
1858: throw new HeroException(ne.getMessage());
1859: }
1860: try {
1861: ed = eh.findByName(name, mProject.getId());
1862: } catch (FinderException fe) {
1863:
1864: trace.error("edge does not exists " + fe.getMessage());
1865: throw new HeroException("edge does not exists " + name);
1866: }
1867: String nodeIn = ed.getInBnNode().getName();
1868: String nodeOut = ed.getOutBnNode().getName();
1869: edgeDeletion(ed);
1870: if (jms != null)
1871: jms.sendEdgeEvent(DELETEEDGE, this .getName(), name, nodeIn,
1872: nodeOut, this .getCaller());
1873: }
1874:
1875: /** Actually deletes an edge and restore the state of the outgoing node
1876: * <strong>Not a business method</strong>
1877: **/
1878:
1879: public void edgeDeletion(BnEdgeLocal ed) throws HeroException {
1880: BnNodeLocal nd = ed.getOutBnNode();
1881:
1882: trace.debug(" process name = " + this .getName()
1883: + " started by " + this .getCaller());
1884: if (!isAdminOfProject()) {
1885:
1886: trace
1887: .error("Only the Admin of the project is allowed to do this operation... ");
1888: throw new AdminException(
1889: "Only the Admin of the project is allowed to do this operation... ");
1890: }
1891: if (nd.isExecuting()) {
1892: throw new DeleteEdgeException(
1893: "Cannot delete edge. Out node executing");
1894: }
1895: /* if (nd.isTerminated()) {
1896: throw new DeleteEdgeException("Cannot delete edge. Out node terminated");
1897: }
1898: if (nd.isCancelled()) {
1899: throw new DeleteEdgeException("Cannot delete edge. Out node cancelled");
1900: }*/
1901: try {
1902: ed.remove();
1903:
1904: EdgeState edgeState = EdgeState.make(nd.getType());
1905: int newOperation = edgeState.state(nd);
1906:
1907: NodeState nodeState = NodeState.make(nd.getType(), nd
1908: .getAnticipable());
1909: int newState = nodeState.computeState(nd, newOperation);
1910:
1911: if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
1912: throw new HeroException(
1913: "AddEdge generated a bad BnNode transition");
1914: }
1915: if (!mProject.getType().equals(Constants.Pj.MODEL))
1916: this .setNodeState(nd, newState);
1917: } catch (RemoveException e) {
1918:
1919: trace.error("deleteNode failed " + e.getMessage());
1920: throw new HeroException("deleteNode failed "
1921: + e.getMessage());
1922: }
1923: }
1924:
1925: /**
1926: * Detete a hook. Delete a Java or aTCL hook of this project. </strong>
1927: *
1928: * @param hookName the name of the hook
1929: * @ejb:interface-method view-type="both"
1930: * @ejb:transaction type="Required"
1931: * @throws HeroException
1932: *
1933: **/
1934: public void deleteHook(String hookName) throws HeroException {
1935:
1936: trace.debug(" process name = " + this .getName()
1937: + " started by " + this .getCaller());
1938: BnProjectHookLocalHome pHome;
1939: BnProjectHookLocal ppLocal;
1940: if (!isAdminOfProject()) {
1941:
1942: trace
1943: .error("Only the Admin of the project is allowed to do this operation... ");
1944: throw new AdminException(
1945: "Only the Admin of the project is allowed to do this operation... ");
1946: }
1947: try {
1948: pHome = BnProjectHookUtil.getLocalHome();
1949: } catch (javax.naming.NamingException ne) {
1950:
1951: trace.error(ne.getMessage());
1952: throw new HeroException(ne.getMessage());
1953: }
1954:
1955: try {
1956: BnProjectHookLocal ph = pHome.findByName(mProject.getId(),
1957: hookName);
1958: ph.remove();
1959: } catch (FinderException fe) {
1960:
1961: trace.error(fe.getMessage());
1962: throw new HeroException(fe.getMessage());
1963: } catch (RemoveException rm) {
1964:
1965: trace.error(rm.getMessage());
1966: throw new HeroException(rm.getMessage());
1967: }
1968: }
1969:
1970: /**
1971: * Delete a node hook. Delete a Java or a TCL hook of this node. </strong>
1972: *
1973: * @param nodeName the name of the node
1974: * @param hookName the name
1975: * @ejb:interface-method view-type="both"
1976: * @ejb:transaction type="Required"
1977: * @throws HeroException
1978: *
1979: **/
1980: public void deleteNodeHook(String nodeName, String hookName)
1981: throws HeroException {
1982:
1983: trace.debug("parameters: nodename=" + nodeName + "Hookname="
1984: + hookName + " process name = " + this .getName()
1985: + " started by " + this .getCaller());
1986: BnNodeHookLocalHome pHome;
1987: BnNodeHookLocal ppLocal;
1988: BnNodeLocal nd = mProject.getBnNode(nodeName);
1989: if (!isAdminOfProject()) {
1990:
1991: trace
1992: .error("Only the Admin of the project is allowed to do this operation... ");
1993: throw new AdminException(
1994: "Only the Admin of the project is allowed to do this operation... ");
1995: }
1996: try {
1997: pHome = BnNodeHookUtil.getLocalHome();
1998: } catch (javax.naming.NamingException ne) {
1999:
2000: trace.error(ne.getMessage());
2001: throw new HeroException(ne.getMessage());
2002: }
2003: try {
2004: BnNodeHookLocal nh = pHome.findByName(nd.getId(), hookName);
2005: nh.remove();
2006: } catch (FinderException fe) {
2007:
2008: trace.error(fe.getMessage());
2009: throw new HeroException(fe.getMessage());
2010: } catch (RemoveException rm) {
2011:
2012: trace.error(rm.getMessage());
2013: throw new HeroException(rm.getMessage());
2014: }
2015: }
2016:
2017: /**
2018: * Delete a node interHook.
2019: *
2020: * @param nodeName the name of the node
2021: * @param hookName the name of the interHook
2022: * @ejb:interface-method view-type="both"
2023: * @ejb:transaction type="Required"
2024: * @throws HeroException
2025: *
2026: **/
2027: public void deleteNodeInterHook(String nodeName,
2028: String interHookName) throws HeroException {
2029:
2030: trace.debug("parameters: nodename=" + nodeName
2031: + "InerhookName=" + interHookName + " process name = "
2032: + this .getName() + " started by " + this .getCaller());
2033: BnNodeInterHookLocalHome pHome;
2034: BnNodeInterHookLocal ppLocal;
2035: BnNodeLocal nd = mProject.getBnNode(nodeName);
2036: if (!isAdminOfProject()) {
2037:
2038: trace
2039: .error("Only the Admin of the project is allowed to do this operation... ");
2040: throw new AdminException(
2041: "Only the Admin of the project is allowed to do this operation... ");
2042: }
2043: try {
2044: pHome = BnNodeInterHookUtil.getLocalHome();
2045: } catch (javax.naming.NamingException ne) {
2046:
2047: trace.error(ne.getMessage());
2048: throw new HeroException(ne.getMessage());
2049: }
2050: try {
2051: BnNodeInterHookLocal nh = pHome.findByName(nd.getId(),
2052: interHookName);
2053: nh.remove();
2054: } catch (FinderException fe) {
2055:
2056: trace.error(fe.getMessage());
2057: throw new HeroException(fe.getMessage());
2058: } catch (RemoveException rm) {
2059:
2060: trace.error(rm.getMessage());
2061: throw new HeroException(rm.getMessage());
2062: }
2063: }
2064:
2065: /**
2066: * Detete a interHook of this project. This method deletes this hook from all projects nodes.
2067: *
2068: * @param hookName the name of the hook
2069: * @ejb:interface-method view-type="both"
2070: * @ejb:transaction type="Required"
2071: * @throws HeroException
2072: *
2073: **/
2074: public void deleteInterHook(String interHookName)
2075: throws HeroException {
2076: BnProjectInterHookLocalHome pHome;
2077: BnProjectInterHookLocal ppLocal;
2078:
2079: trace.debug("parameter: interhookName=" + interHookName
2080: + " process name = " + this .getName() + " started by "
2081: + this .getCaller());
2082: if (!isAdminOfProject()) {
2083:
2084: trace
2085: .error("Only the Admin of the project is allowed to do this operation... ");
2086: throw new AdminException(
2087: "Only the Admin of the project is allowed to do this operation... ");
2088: }
2089: try {
2090: pHome = BnProjectInterHookUtil.getLocalHome();
2091: } catch (javax.naming.NamingException ne) {
2092:
2093: trace.error(ne.getMessage());
2094: throw new HeroException(ne.getMessage());
2095: }
2096:
2097: try {
2098: BnProjectInterHookLocal ph = pHome.findByName(mProject
2099: .getId(), interHookName);
2100: ph.remove();
2101: } catch (FinderException fe) {
2102:
2103: trace.error(fe.getMessage());
2104: throw new HeroException(fe.getMessage());
2105: } catch (RemoveException rm) {
2106:
2107: trace.error(rm.getMessage());
2108: throw new HeroException(rm.getMessage());
2109: }
2110: }
2111:
2112: /**
2113: * Delete a role mapper.
2114: *
2115: * @param roleName the name of the node
2116: * @param roleName name
2117: * @ejb:interface-method view-type="both"
2118: * @ejb:transaction type="Required"
2119: * @throws HeroException
2120: *
2121: **/
2122: public void deleteRoleMapper(String roleName) throws HeroException {
2123:
2124: trace.debug("parameter: roleName=" + roleName
2125: + " process name = " + this .getName() + " started by "
2126: + this .getCaller());
2127: BnRoleLocalHome pHome;
2128: BnRoleMapperLocal mapperL;
2129: BnRoleLocal roleL;
2130: if (!isAdminOfProject()) {
2131:
2132: trace
2133: .error("Only the Admin of the project is allowed to do this operation... ");
2134: throw new AdminException(
2135: "Only the Admin of the project is allowed to do this operation... ");
2136: }
2137: try {
2138: pHome = BnRoleUtil.getLocalHome();
2139: } catch (javax.naming.NamingException ne) {
2140:
2141: trace.error(ne.getMessage());
2142: throw new HeroException(ne.getMessage());
2143: }
2144:
2145: try {
2146: roleL = pHome.findByName(roleName, mProject.getId());
2147: mapperL = roleL.getBnRoleMapper();
2148: } catch (FinderException fe) {
2149:
2150: trace.error(fe.getMessage());
2151: throw new HeroException(fe.getMessage());
2152: }
2153:
2154: try {
2155: mapperL.remove();
2156: } catch (RemoveException rm) {
2157:
2158: trace.error(rm.getMessage());
2159: throw new HeroException(rm.getMessage());
2160: }
2161: }
2162:
2163: /**
2164: * Delete a role (and the Role mapper if it exists).
2165: *
2166: * @param roleName the name of the node
2167: * @param roleName name
2168: * @ejb:interface-method view-type="both"
2169: * @ejb:transaction type="Required"
2170: * @throws HeroException
2171: *
2172: **/
2173: public void deleteRole(String roleName) throws HeroException {
2174:
2175: trace.debug("parameter: roleName=" + roleName
2176: + " process name = " + this .getName() + " started by "
2177: + this .getCaller());
2178: BnRoleLocalHome pHome;
2179: BnRoleMapperLocal mapperL;
2180: BnRoleLocal roleL;
2181: if (!isAdminOfProject()) {
2182:
2183: trace
2184: .error("Only the Admin of the project is allowed to do this operation... ");
2185: throw new AdminException(
2186: "Only the Admin of the project is allowed to do this operation... ");
2187: }
2188: try {
2189: pHome = BnRoleUtil.getLocalHome();
2190: } catch (javax.naming.NamingException ne) {
2191:
2192: trace.error(ne.getMessage());
2193: throw new HeroException(ne.getMessage());
2194: }
2195:
2196: try {
2197: roleL = pHome.findByName(roleName, mProject.getId());
2198: mapperL = roleL.getBnRoleMapper();
2199: } catch (FinderException fe) {
2200:
2201: trace.error(fe.getMessage());
2202: throw new HeroException(fe.getMessage());
2203: }
2204:
2205: try {
2206: if (mapperL != null)
2207: mapperL.remove();
2208: roleL.remove();
2209: } catch (RemoveException rm) {
2210:
2211: trace.error(rm.getMessage());
2212: throw new HeroException(rm.getMessage());
2213: }
2214: }
2215:
2216: /**
2217: * Delete a property of the project. Deletes the project property associated to this key.
2218: *
2219: * @param key the key of the property
2220: * @ejb:interface-method view-type="both"
2221: * @ejb:transaction type="Required"
2222: * @throws HeroException
2223: *
2224: **/
2225: public void deleteProperty(String key) throws HeroException {
2226:
2227: trace.debug("parameter: key=" + key + " process name = "
2228: + this .getName() + " started by " + this .getCaller());
2229:
2230: BnProjectPropertyLocalHome pHome;
2231: BnProjectPropertyLocal ppLocal;
2232: if (!isAdminOfProject()) {
2233:
2234: trace
2235: .error("Only the Admin of the project is allowed to do this operation... ");
2236: throw new AdminException(
2237: "Only the Admin of the project is allowed to do this operation... ");
2238: }
2239: try {
2240: pHome = BnProjectPropertyUtil.getLocalHome();
2241: } catch (javax.naming.NamingException ne) {
2242:
2243: trace.error(ne.getMessage());
2244: throw new HeroException(ne.getMessage());
2245: }
2246: Collection c = null;
2247: try {
2248: c = pHome.findByTheKey(mProject.getId(), key);
2249: } catch (FinderException fe) {
2250:
2251: trace.error(fe.getMessage());
2252: throw new HeroException(fe.getMessage());
2253: }
2254:
2255: if (!c.isEmpty()) {
2256: try {
2257: ppLocal = (BnProjectPropertyLocal) (c.toArray())[0];
2258: ppLocal.remove();
2259: } catch (RemoveException rm) {
2260:
2261: trace.error(rm.getMessage());
2262: throw new HeroException(rm.getMessage());
2263: }
2264:
2265: } else {
2266: throw new HeroException("Property not found :" + key);
2267: }
2268: }
2269:
2270: /**
2271: * Delete a property of a node. Deletes the node property associated to this key
2272: *
2273: * @param nodeName the name of the node
2274: * @param key the key of the property
2275: * @ejb:interface-method view-type="both"
2276: * @ejb:transaction type="Required"
2277: * @throws HeroException
2278: *
2279: **/
2280: public void deleteNodeProperty(String nodeName, String key)
2281: throws HeroException {
2282:
2283: trace.debug("parameters: node=" + nodeName + " key=" + key
2284: + " process name = " + this .getName() + " started by "
2285: + this .getCaller());
2286:
2287: BnNodePropertyLocalHome pHome;
2288: BnNodePropertyLocal propertyLocal = null;
2289: if (!isAdminOfProject()) {
2290:
2291: trace
2292: .error("Only the Admin of the project is allowed to do this operation... ");
2293: throw new AdminException(
2294: "Only the Admin of the project is allowed to do this operation... ");
2295: }
2296: BnNodeLocal nd = mProject.getBnNode(nodeName);
2297:
2298: try {
2299: pHome = BnNodePropertyUtil.getLocalHome();
2300: } catch (javax.naming.NamingException ne) {
2301:
2302: trace.error(ne.getMessage());
2303: throw new HeroException(ne.getMessage());
2304: }
2305: Collection c = null;
2306: try {
2307: c = pHome.findByTheKey(nd.getId(), key);
2308: } catch (FinderException fe) {
2309:
2310: trace.error(fe.getMessage());
2311: throw new HeroException(fe.getMessage());
2312: }
2313:
2314: if (!c.isEmpty()) {
2315: try {
2316: propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
2317: propertyLocal.remove();
2318: } catch (RemoveException rm) {
2319:
2320: trace.error(rm.getMessage());
2321: throw new HeroException(rm.getMessage());
2322: }
2323:
2324: } else {
2325: throw new HeroException("Property not found :" + key);
2326: }
2327: }
2328:
2329: // -------------------------------------------------------------------------
2330: // Set business methods
2331: // -------------------------------------------------------------------------
2332:
2333: /**
2334: * Set a trace level of the actual project.
2335: *
2336: * @param level the trace level
2337: *
2338: * @ejb:interface-method view-type="local"
2339: * @ejb:transaction type="Required"
2340: * @throws HeroException
2341: *
2342: **/
2343: public void setTraceLevel(String level) throws HeroException {
2344:
2345: trace.debug("parameters: level=" + level + " process name = "
2346: + this .getName() + " started by " + this .getCaller());
2347: if (!isAdminOfProject()) {
2348:
2349: trace
2350: .error("Only the Admin of the project is allowed to do this operation... ");
2351: throw new AdminException(
2352: "Only the Admin of the project is allowed to do this operation... ");
2353: }
2354: if (level.equals(Constants.INFO))
2355: trace.setLevel(Level.INFO);
2356: else if (level.equals(Constants.DEBUG))
2357: trace.setLevel(Level.DEBUG);
2358: else if (level.equals(Constants.ERROR))
2359: trace.setLevel(Level.ERROR);
2360: }
2361:
2362: /**
2363: * Set a log level of the actual project.
2364: *
2365: * @param level the log level
2366: *
2367: * @ejb:interface-method view-type="local"
2368: * @ejb:transaction type="Required"
2369: * @throws HeroException
2370: *
2371: **/
2372: public void setLogLevel(String level) throws HeroException {
2373:
2374: trace.debug("parameters: level=" + level + " process name = "
2375: + this .getName() + " started by " + this .getCaller());
2376: if (!isAdminOfProject()) {
2377:
2378: trace
2379: .error("Only the Admin of the project is allowed to do this operation... ");
2380: throw new AdminException(
2381: "Only the Admin of the project is allowed to do this operation... ");
2382: }
2383: if (level.equals(Constants.INFO))
2384: thelog.setLevel(Level.INFO);
2385: else if (level.equals(Constants.DEBUG))
2386: thelog.setLevel(Level.DEBUG);
2387: else if (level.equals(Constants.ERROR))
2388: thelog.setLevel(Level.ERROR);
2389: }
2390:
2391: /**
2392: * Set a role to this user. This role is assigned to the user in the context of
2393: * the actual project.
2394: *
2395: * @param userName the name of the user
2396: * @param roleName the name of the role
2397: *
2398: * @ejb:interface-method view-type="both"
2399: * @ejb:transaction type="Required"
2400: * @throws HeroException
2401: *
2402: **/
2403: public void setUserRole(String userName, String roleName)
2404: throws HeroException {
2405:
2406: trace.debug("parameters: user=" + userName + " role="
2407: + roleName + " process name = " + this .getName()
2408: + " started by " + this .getCaller());
2409: BnRoleLocalHome roleh;
2410: BnUserLocalHome userh;
2411: UserServiceLocalHome ushome;
2412: UserServiceLocal ul;
2413: if (!isAdminOfProject()) {
2414:
2415: trace
2416: .error("Only the Admin of the project is allowed to do this operation... ");
2417: throw new AdminException(
2418: "Only the Admin of the project is allowed to do this operation... ");
2419: }
2420: try {
2421: roleh = BnRoleUtil.getLocalHome();
2422: userh = BnUserUtil.getLocalHome();
2423: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
2424: } catch (javax.naming.NamingException ne) {
2425:
2426: trace.error(ne.getMessage());
2427: throw new HeroException(ne.getMessage());
2428: }
2429: try {
2430: ul = ushome.create();
2431: BnUserLocal user = ul.findUser(userName);
2432:
2433: BnRoleLocal role = roleh.findByName(roleName, mProject
2434: .getId());
2435: user.getBnRoles().add(role);
2436: if (jms != null)
2437: jms.sendUserRoleEvent(SETUSERROLE, this .getName(),
2438: userName, roleName);
2439: } catch (Exception fe) {
2440:
2441: trace.error(fe.getMessage());
2442: throw new HeroException(fe.getMessage());
2443: }
2444: }
2445:
2446: /**
2447: * Sets the role of an activity. Changes the role of this activity
2448: *
2449: * @param name the name of the activity
2450: * @param role the name of the role
2451: *
2452: * @ejb:interface-method view-type="both"
2453: * @ejb:transaction type="Required"
2454: * @throws HeroException
2455: *
2456: **/
2457: public void setNodeRole(String name, String role)
2458: throws HeroException {
2459:
2460: trace.debug("parameters: name=" + name + " role=" + role
2461: + " process name = " + this .getName() + " started by "
2462: + this .getCaller());
2463: BnRoleLocalHome rh;
2464: BnNodeLocalHome nh;
2465: BnNodeLocal nl;
2466: BnRoleLocal rl;
2467: if (!isAdminOfProject()) {
2468: trace
2469: .error("Only the Admin of the project is allowed to do this operation... ");
2470: throw new AdminException(
2471: "Only the Admin of the project is allowed to do this operation... ");
2472: }
2473: try {
2474: rh = BnRoleUtil.getLocalHome();
2475: nh = BnNodeUtil.getLocalHome();
2476: } catch (javax.naming.NamingException ne) {
2477: trace.error(ne.getMessage());
2478: throw new HeroException(ne.getMessage());
2479: }
2480: try {
2481: nl = nh.findByName(name, mProject.getId());
2482: } catch (FinderException fe) {
2483: trace.error("BnNode does not exists " + fe.getMessage());
2484: throw new HeroException("BnNode does not exists " + name);
2485: }
2486: try {
2487: rl = rh.findByName(role, mProject.getId());
2488: } catch (FinderException fe) {
2489: trace.error("BnRole does not exists " + fe.getMessage());
2490: throw new HeroException("BnRole does not exists " + role);
2491: }
2492: nl.setBnRole(rl);
2493: if (jms != null)
2494: jms.sendProjectEvent(CHANGEROLE, this .getName());
2495: }
2496:
2497: /**
2498: * Set edit node changes. Only for GraphEditor client
2499: *
2500: * @param name of the node
2501: * @param role of the node
2502: * @param description of the node
2503: * @param deadline of the node
2504: * @ejb:interface-method view-type="both"
2505: * @ejb:transaction type="Required"
2506: *
2507: **/
2508: public void setEditNode(String node, String role,
2509: String description, long deadline) throws HeroException {
2510:
2511: trace.debug("setEditNode: node=" + node + " role=" + role
2512: + " description=" + description + " deadline="
2513: + deadline);
2514: if (!isAdminOfProject()) {
2515:
2516: trace
2517: .error("Only the Admin of the project is allowed to do this operation... ");
2518: throw new AdminException(
2519: "Only the Admin of the project is allowed to do this operation... ");
2520: }
2521: this .setNodeDeadline(node, deadline);
2522: this .setNodeDescription(node, description);
2523: this .setNodeRole(node, role);
2524: }
2525:
2526: /**
2527: * Set the edge condition. This condition is evaluated at run-time in order to perform activity transition.
2528: * To set the condition you have to use beanshell language (Lightweight Scripting for Java).<br>
2529: * <strong>The next line illustrates the use of setEdgeCondition method:<br><br></strong>
2530: *
2531: * ...<br>
2532: * String condition = "partial_status.equals(\"ok\")";<br>
2533: * <strong>yourProjectSessionInstance</strong>.setEdgeCondition("edgeName",condition);<br><br>
2534: *
2535: * The engine evaluates on the fly the condition by using the If statement. In the previous sample,
2536: * if the value of the property "partial_status" is equals to "ok" the result of this condition is true.
2537: *
2538: * @param edge edge name
2539: * @param condition condition of the edge
2540: * @ejb:interface-method view-type="both"
2541: * @ejb:transaction type="Required"
2542: * @throws HeroException
2543: *
2544: **/
2545: public void setEdgeCondition(String edge, String condition)
2546: throws HeroException {
2547:
2548: trace.debug("parameters: name=" + edge + " condition="
2549: + condition + " process name = " + this .getName()
2550: + " started by " + this .getCaller());
2551: if (!isAdminOfProject()) {
2552:
2553: trace
2554: .error("Only the Admin of the project is allowed to do this operation... ");
2555: throw new AdminException(
2556: "Only the Admin of the project is allowed to do this operation... ");
2557: }
2558: BnEdgeLocal e = mProject.getBnEdge(edge);
2559: e.setCondition(condition);
2560: }
2561:
2562: /**
2563: * Set the node deadline. Activity deadline is the lastest date in which the activity must be finished.
2564: *
2565: * @param name the name of the node
2566: * @param date date of the deadline
2567: * @ejb:interface-method view-type="both"
2568: * @ejb:transaction type="Required"
2569: * @throws HeroException
2570: * @deprecated replaced by setDeadlines(String name, Collection co)
2571: *
2572: **/
2573: public void setNodeDeadline(String name, long date)
2574: throws HeroException {
2575:
2576: trace.debug("parameters: name=" + name + " deadline=" + date
2577: + " process name = " + this .getName() + " started by "
2578: + this .getCaller());
2579: if (!isAdminOfProject()) {
2580:
2581: trace
2582: .error("Only the Admin of the project is allowed to do this operation... ");
2583: throw new AdminException(
2584: "Only the Admin of the project is allowed to do this operation... ");
2585: }
2586: if (new java.sql.Date(date).before(new Date()))
2587: throw new HeroException(
2588: "This date is before the current date !!");
2589:
2590: //Call setNodeDeadlines()
2591: ArrayList ar = new ArrayList();
2592: ar.add(new Long(date));
2593: setNodeDeadlines(name, ar);
2594: }
2595:
2596: /**
2597: * Set a collection of deadlines for the node.
2598: * Activity deadline is the lastest date in which the activity must be finished.
2599: *
2600: * @param name the name of the node
2601: * @param co collection of dates of the deadline
2602: * @ejb:interface-method view-type="both"
2603: * @ejb:transaction type="Required"
2604: * @throws HeroException
2605: *
2606: **/
2607: public void setNodeDeadlines(String name, Collection co)
2608: throws HeroException {
2609: Iterator it = co.iterator();
2610: //for deadline based on EJB timers
2611: DeadlineEjbTimerSessionLocalHome dlHome;
2612: DeadlineEjbTimerSessionLocal dlSession;
2613: try {
2614: dlHome = DeadlineEjbTimerSessionUtil.getLocalHome();
2615: } catch (javax.naming.NamingException ne) {
2616: throw new HeroException(ne.getMessage());
2617: }
2618: try {
2619: dlSession = dlHome.create();
2620:
2621: } catch (CreateException he) {
2622: throw new HeroException(
2623: "setNodeDeadlines Error creating DeadlineEjbTimerSessionLocal");
2624: }
2625:
2626: trace.debug("parameters: name=" + name
2627: + " collection of deadlines " + " process name = "
2628: + this .getName() + " started by " + this .getCaller());
2629: while (it.hasNext()) {
2630: trace.debug("deadline = " + ((Long) it.next()).longValue());
2631: }
2632: if (!isAdminOfProject()) {
2633:
2634: trace
2635: .error("Only the Admin of the project is allowed to do this operation... ");
2636: throw new AdminException(
2637: "Only the Admin of the project is allowed to do this operation... ");
2638: }
2639: // set the collection of deadlines
2640: it = co.iterator();
2641: ArrayList ar = new ArrayList();
2642: BnNodeLocal nd = mProject.getBnNode(name);
2643: while (it.hasNext()) {
2644: long d = ((Long) it.next()).longValue();
2645: java.sql.Timestamp dt = new java.sql.Timestamp(d);
2646: long t = new Date().getTime();
2647: java.sql.Timestamp ct = new java.sql.Timestamp(t);
2648: if (dt.before(ct))
2649: throw new HeroException("The date of the deadline : "
2650: + dt.toString()
2651: + " is before the current date !!");
2652: ar.add(dt);
2653: }
2654: nd.setDeadlines(ar);
2655:
2656: if (nd.getState() == Constants.Nd.READY
2657: && nd.getBnProject().getType().equals(
2658: Constants.Pj.COOPERATIVE))
2659: //BonitaDeadline.getInstance().startDeadlines(name, mProject.getId());
2660: dlSession.startDeadlineEjbTimers(name, mProject.getId());
2661:
2662: String projectName = this .getName();
2663: if (jms != null)
2664: jms.sendNodeEvent(SETNODEDEADLINES, projectName, name, nd
2665: .getType(), nd.getState(), this .getCaller());
2666:
2667: }
2668:
2669: /**
2670: * Set a collection of relativeDeadlines for the node.
2671: *
2672: * @param name the name of the node
2673: * @param co collection of dates of the deadline
2674: * @ejb:interface-method view-type="both"
2675: * @ejb:transaction type="Required"
2676: * @throws HeroException
2677: *
2678: **/
2679: public void setNodeRelativeDeadlines(String name, Collection co)
2680: throws HeroException {
2681: Iterator it = co.iterator();
2682:
2683: //for deadline based on EJB timers
2684: DeadlineEjbTimerSessionLocalHome dlHome;
2685: DeadlineEjbTimerSessionLocal dlSession;
2686: try {
2687: dlHome = DeadlineEjbTimerSessionUtil.getLocalHome();
2688: } catch (javax.naming.NamingException ne) {
2689: throw new HeroException(ne.getMessage());
2690: }
2691: try {
2692: dlSession = dlHome.create();
2693:
2694: } catch (CreateException he) {
2695: throw new HeroException(
2696: "setNodeRelativeDeadlines Error creating DeadlineEjbTimerSessionLocal");
2697: }
2698:
2699: trace.debug("parameters: name=" + name
2700: + " collection of relativeDeadlines "
2701: + " process name = " + this .getName() + " started by "
2702: + this .getCaller());
2703: while (it.hasNext()) {
2704: trace.debug("deadline = " + ((Long) it.next()).longValue());
2705: }
2706: if (!isAdminOfProject()) {
2707:
2708: trace
2709: .error("Only the Admin of the project is allowed to do this operation... ");
2710: throw new AdminException(
2711: "Only the Admin of the project is allowed to do this operation... ");
2712: }
2713: // set the collection of relativeDeadlines
2714: it = co.iterator();
2715: ArrayList ar = new ArrayList();
2716: BnNodeLocal nd = mProject.getBnNode(name);
2717: while (it.hasNext()) {
2718: long d = ((Long) it.next()).longValue();
2719: java.sql.Timestamp dt = new java.sql.Timestamp(d);
2720: ar.add(dt);
2721: }
2722: nd.setRelativeDeadlines(ar);
2723:
2724: if (nd.getState() == Constants.Nd.READY
2725: && nd.getBnProject().getType().equals(
2726: Constants.Pj.COOPERATIVE))
2727: //BonitaDeadline.getInstance().startDeadlines(name, mProject.getId());
2728: dlSession.startDeadlineEjbTimers(name, mProject.getId());
2729:
2730: String projectName = this .getName();
2731: if (jms != null)
2732: jms.sendNodeEvent(SETNODEDEADLINES, projectName, name, nd
2733: .getType(), nd.getState(), this .getCaller());
2734:
2735: }
2736:
2737: /**
2738: * Set the node relative deadline. Activity deadline is the lastest date in which the activity must be finished.
2739: *
2740: * @param name the name of the node
2741: * @param date date of the deadline
2742: * @ejb:interface-method view-type="both"
2743: * @ejb:transaction type="Required"
2744: * @throws HeroException
2745: * @deprecated replaced by setRelativeDeadlines(String name, Collection co)
2746: *
2747: **/
2748: public void setNodeRelativeDeadline(String name, long date)
2749: throws HeroException {
2750:
2751: trace.debug("parameters: name=" + name + " deadline=" + date
2752: + " process name = " + this .getName() + " started by "
2753: + this .getCaller());
2754: if (!isAdminOfProject()) {
2755:
2756: trace
2757: .error("Only the Admin of the project is allowed to do this operation... ");
2758: throw new AdminException(
2759: "Only the Admin of the project is allowed to do this operation... ");
2760: }
2761: //Call setNodeRelativeDeadlines()
2762: ArrayList ar = new ArrayList();
2763: ar.add(new Long(date));
2764: setNodeRelativeDeadlines(name, ar);
2765: }
2766:
2767: /**
2768: * Set the node description. Node description represents, explicity, execution related information
2769: * of this task.
2770: *
2771: * @param name the name of the node
2772: * @param descriptio description of the node
2773: * @ejb:interface-method view-type="both"
2774: * @ejb:transaction type="Required"
2775: * @throws HeroException
2776: *
2777: **/
2778: public void setNodeDescription(String name, String description)
2779: throws HeroException {
2780:
2781: trace.debug("parameters: name=" + name + " description="
2782: + description + " process name = " + this .getName()
2783: + " started by " + this .getCaller());
2784: if (!isAdminOfProject()) {
2785:
2786: trace
2787: .error("Only the Admin of the project is allowed to do this operation... ");
2788: throw new AdminException(
2789: "Only the Admin of the project is allowed to do this operation... ");
2790: }
2791: BnNodeLocal nd = mProject.getBnNode(name);
2792: nd.setDescription(description);
2793: }
2794:
2795: /**
2796: * Set the node hook value.
2797: *
2798: * @param name name of the node
2799: * @param hook hookName of the node
2800: * @param value new script value of this hook
2801: * @ejb:interface-method view-type="both"
2802: * @ejb:transaction type="Required"
2803: * @throws HeroException
2804: *
2805: **/
2806: public void setNodeInterHookValue(String node, String hook,
2807: String value) throws HeroException {
2808:
2809: trace.debug("parameters: node=" + node + " hook=" + hook
2810: + " value=" + value + " process name = "
2811: + this .getName() + " started by " + this .getCaller());
2812: if (!isAdminOfProject()) {
2813:
2814: trace
2815: .error("Only the Admin of the project is allowed to do this operation... ");
2816: throw new AdminException(
2817: "Only the Admin of the project is allowed to do this operation... ");
2818: }
2819: BnNodeLocal nd = mProject.getBnNode(node);
2820: Collection hooks = nd.getBnInterHooks();
2821: for (Iterator ih = hooks.iterator(); ih.hasNext();) {
2822: BnNodeInterHookLocal hk = (BnNodeInterHookLocal) ih.next();
2823: if (hk.getName().equals(hook)) {
2824: hk.setScript(value);
2825: }
2826: }
2827: }
2828:
2829: /**
2830: * Set the hook value. This value is the new hook script associated to all project nodes
2831: *
2832: * @param hook hookName of the node
2833: * @param value new script value of this hook
2834: * @ejb:interface-method view-type="both"
2835: * @ejb:transaction type="Required"
2836: * @throws HeroException
2837: *
2838: **/
2839: public void setInterHookValue(String hook, String value)
2840: throws HeroException {
2841:
2842: trace.debug("parameters: hook=" + hook + " value=" + value
2843: + " process name = " + this .getName() + " started by "
2844: + this .getCaller());
2845: if (!isAdminOfProject()) {
2846:
2847: trace
2848: .error("Only the Admin of the project is allowed to do this operation... ");
2849: throw new AdminException(
2850: "Only the Admin of the project is allowed to do this operation... ");
2851: }
2852: Collection hooks = mProject.getBnInterHooks();
2853: for (Iterator ih = hooks.iterator(); ih.hasNext();) {
2854: BnProjectInterHookLocal hk = (BnProjectInterHookLocal) ih
2855: .next();
2856: if (hk.getName().equals(hook)) {
2857: hk.setScript(value);
2858: }
2859: }
2860: }
2861:
2862: /**
2863: * Unset a user role in this project.
2864: *
2865: * @param userName name of the user
2866: * @param roleName name of the role
2867: * @ejb:interface-method view-type="both"
2868: * @ejb:transaction type="Required"
2869: * @throws HeroException
2870: *
2871: **/
2872:
2873: public void unsetUserRole(String userName, String roleName)
2874: throws HeroException {
2875:
2876: trace.debug("parameters: userName=" + userName + " roleName="
2877: + roleName + " process name = " + this .getName()
2878: + " started by " + this .getCaller());
2879: BnUserLocal mUser;
2880: BnUserLocalHome uHome;
2881: BnRoleLocalHome rHome;
2882: BnRoleLocal mRole;
2883: UserServiceLocalHome ushome;
2884: UserServiceLocal ul;
2885: if (!isAdminOfProject()) {
2886:
2887: trace
2888: .error("Only the Admin of the project is allowed to do this operation... ");
2889: throw new AdminException(
2890: "Only the Admin of the project is allowed to do this operation... ");
2891: }
2892: try {
2893: uHome = hero.interfaces.BnUserUtil.getLocalHome();
2894: rHome = hero.interfaces.BnRoleUtil.getLocalHome();
2895: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
2896: } catch (javax.naming.NamingException be) {
2897:
2898: trace.error(be.getMessage());
2899: throw new HeroException(be.getMessage());
2900: }
2901: try {
2902: ul = ushome.create();
2903: mUser = ul.findUser(userName);
2904: } catch (Exception fe) {
2905:
2906: trace.error("User does not exist " + fe.getMessage());
2907: throw new HeroException("User does not exist");
2908: }
2909:
2910: Collection userRoles = this .getUserRolesInProject(userName);
2911: Iterator i = userRoles.iterator();
2912: while (i.hasNext()) {
2913: BnRoleValue role = (BnRoleValue) i.next();
2914: if (role.getName().equals(roleName)) {
2915: try {
2916: mRole = rHome.findByName(role.getName(), mProject
2917: .getId());
2918: mUser.getBnRoles().remove(mRole);
2919: } catch (javax.ejb.FinderException fe) {
2920:
2921: trace.error("Role does not exist "
2922: + fe.getMessage());
2923: throw new HeroException("Role does not exist");
2924: }
2925: }
2926: }
2927:
2928: if (jms != null)
2929: jms.sendUserRoleEvent(UNSETUSERROLE, this .getName(),
2930: userName, roleName);
2931: }
2932:
2933: /**
2934: * Unset a user for this project
2935: *
2936: * @param userName The name of the user
2937: *
2938: * @ejb:interface-method view-type="both"
2939: * @ejb:transaction type="Required"
2940: * @throws HeroException
2941: *
2942: **/
2943: public void unsetUser(String userName) throws HeroException {
2944:
2945: trace.debug(" Parameter: name=" + userName + " process name = "
2946: + this .getName() + " started by " + this .getCaller());
2947: UserServiceLocalHome ushome;
2948: UserServiceLocal ul;
2949: if (!isAdminOfProject()) {
2950:
2951: trace
2952: .error("Only the Admin of the project is allowed to do this operation... ");
2953: throw new AdminException(
2954: "Only the Admin of the project is allowed to do this operation... ");
2955: }
2956: BnUserLocalHome uHome;
2957: BnRoleLocalHome rHome;
2958: BnUserLocal mUser;
2959: try {
2960: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
2961: uHome = hero.interfaces.BnUserUtil.getLocalHome();
2962: rHome = hero.interfaces.BnRoleUtil.getLocalHome();
2963: } catch (javax.naming.NamingException be) {
2964:
2965: trace.error(be.getMessage());
2966: throw new HeroException(be.getMessage());
2967: }
2968: try {
2969: ul = ushome.create();
2970: mUser = ul.findUser(userName);
2971: } catch (Exception fe) {
2972:
2973: trace.error("User does not exist " + fe.getMessage());
2974: throw new HeroException("User does not exist");
2975: }
2976: Collection cUsers = mProject.getBnUsers();
2977: if (cUsers.contains(mUser))
2978: mProject.getBnUsers().remove(mUser);
2979: else {
2980:
2981: trace.error("User does not exist in the project...");
2982: throw new HeroException(
2983: "User does not exist in the project");
2984: }
2985:
2986: }
2987:
2988: /**
2989: * Set the node in traditional mode. When a node is traditional the anticipable attribute is false. This
2990: * method must be used if you want to execute this activity in a traditional model.
2991: *
2992: * @param name name of the node
2993: * @ejb:interface-method view-type="both"
2994: * @ejb:transaction type="Required"
2995: * @throws HeroException
2996: *
2997: **/
2998: public void setNodeTraditional(String name) throws HeroException {
2999:
3000: trace.debug("parameter: name=" + name + " process name = "
3001: + this .getName() + " started by " + this .getCaller());
3002: if (!isAdminOfProject()) {
3003:
3004: trace
3005: .error("Only the Admin of the project is allowed to do this operation... ");
3006: throw new AdminException(
3007: "Only the Admin of the project is allowed to do this operation... ");
3008: }
3009: BnNodeLocal nd = mProject.getBnNode(name);
3010: nd.setAnticipable(false);
3011: }
3012:
3013: /**
3014: * Set the node in anticipable mode.
3015: *
3016: * @param name the name of the node
3017: * @ejb:interface-method view-type="both"
3018: * @ejb:transaction type="Required"
3019: * @throws HeroException
3020: *
3021: **/
3022: public void setNodeAnticipable(String name) throws HeroException {
3023:
3024: trace.debug("parameter: name=" + name + " process name = "
3025: + this .getName() + " started by " + this .getCaller());
3026: if (!isAdminOfProject()) {
3027:
3028: trace
3029: .error("Only the Admin of the project is allowed to do this operation... ");
3030: throw new AdminException(
3031: "Only the Admin of the project is allowed to do this operation... ");
3032: }
3033: BnNodeLocal nd = mProject.getBnNode(name);
3034: nd.setAnticipable(true);
3035: }
3036:
3037: /**
3038: * Set the node in automatic mode. The responsible of the activity execution is now the engine.
3039: *
3040: * @param name the name of the node
3041: * @ejb:interface-method view-type="both"
3042: * @ejb:transaction type="Required"
3043: * @throws HeroException
3044: * @deprecated replaced by setNodeType
3045: *
3046: **/
3047: public void setNodeAutomatic(String name) throws HeroException {
3048: }
3049:
3050: /**
3051: * Set the node type. Change the current type of the node (if node is not executing).<br><br>
3052: *
3053: * Possibles node types are:<br>
3054: * hero.interfaces.Constants.Nd.AND_JOIN_NODE<br>
3055: * hero.interfaces.Constants.Nd.OR_JOIN_NODE<br>
3056: * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE<br>
3057: * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE<br>
3058: *
3059: * @param name the name of the node
3060: * @ejb:interface-method view-type="both"
3061: * @ejb:transaction type="Required"
3062: * @throws HeroException
3063: *
3064: **/
3065: public void setNodeType(String name, int type) throws HeroException {
3066:
3067: trace.debug("parameters: name=" + name + " type" + type
3068: + " process name = " + this .getName() + " started by "
3069: + this .getCaller());
3070: if (!isAdminOfProject()) {
3071:
3072: trace
3073: .error("Only the Admin of the project is allowed to do this operation... ");
3074: throw new AdminException(
3075: "Only the Admin of the project is allowed to do this operation... ");
3076: }
3077: BnNodeLocal nd = mProject.getBnNode(name);
3078: nd.setType(type);
3079: }
3080:
3081: /**
3082: * Set a property of a node. A property is a pair key/value representing workflow relevant data. By using
3083: * propagate argument we can specify if we want to propagate this property.
3084: *
3085: * @param nodeName the name of the node
3086: * @param key the key of the property
3087: * @param value the name of the property
3088: * @param propagate if it is a propagation property
3089: * @ejb:interface-method view-type="both"
3090: * @ejb:transaction type="Required"
3091: * @throws HeroException
3092: *
3093: **/
3094: public void setNodeProperty(String nodeName, String key,
3095: String value, boolean propagate) throws HeroException {
3096:
3097: BnNodePropertyLocalHome pHome;
3098: BnNodePropertyLocal propertyLocal;
3099: if (!isAdminOfProject()) {
3100: if (mProject.getName().matches(".*_instance.*")
3101: && !isUserInNodeRole(nodeName)) {
3102:
3103: trace
3104: .error("You are not allowed to set/update properties of this node... ");
3105: throw new HeroException(
3106: "You are not allowed to set/update properties of this node... ");
3107: }
3108: }
3109:
3110: trace.debug("parameters: node=" + nodeName + " key=" + key
3111: + " value=" + value + " process name = "
3112: + this .getName() + " started by " + this .getCaller());
3113:
3114: BnNodeLocal nd = mProject.getBnNode(nodeName);
3115:
3116: try {
3117: pHome = BnNodePropertyUtil.getLocalHome();
3118: } catch (javax.naming.NamingException ne) {
3119:
3120: trace.error(ne.getMessage());
3121: throw new HeroException(ne.getMessage());
3122: }
3123: Collection c = null;
3124: try {
3125: c = pHome.findByTheKey(nd.getId(), key);
3126: } catch (FinderException fe) {
3127:
3128: trace.error(fe.getMessage());
3129: throw new HeroException(fe.getMessage());
3130: }
3131: if (!c.isEmpty()) {
3132: propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
3133: // Check the value of an enumerated property contains only possible values
3134: boolean allcontains = false;
3135: if (propertyLocal.getPossibleValues() != null) {
3136: Collection ar_pv = propertyLocal.getPossibleValues();
3137: String current = value;
3138: SortedSet sort_pv = new TreeSet(new Comparator() {
3139: public int compare(Object a, Object b) {
3140: if ((a.toString().length()) < (b.toString()
3141: .length()))
3142: return 1;
3143: else if ((a.toString().length()) > (b
3144: .toString().length()))
3145: return -1;
3146: else {
3147: int re = a.toString().compareTo(
3148: b.toString());
3149: if (re > 0)
3150: return 1;
3151: else if (re < 0)
3152: return -1;
3153: else
3154: return 0;
3155: }
3156: }
3157: });
3158:
3159: Iterator it_pv = ar_pv.iterator();
3160: while (it_pv.hasNext()) {
3161: String val = (String) it_pv.next();
3162: sort_pv.add(val);
3163: }
3164: boolean found = true;
3165: boolean not_end = true;
3166: while (found && not_end) {
3167: Iterator it_check = sort_pv.iterator();
3168: found = false;
3169: while (it_check.hasNext()) {
3170: String val = (String) it_check.next();
3171: if (current.startsWith(val)) {
3172: found = true;
3173: current = current.replaceFirst(val, "");
3174: if (current.length() != 0) {
3175: current = current.substring(1);
3176: }
3177: if (current.length() == 0) {
3178: allcontains = true;
3179: not_end = false;
3180: }
3181: break;
3182: }
3183: }
3184: }
3185: }
3186: if (propertyLocal.getPossibleValues() == null
3187: || allcontains) {
3188: propertyLocal.setTheValue(value);
3189: } else
3190: throw new HeroException(
3191: "Error: This value is not one of possibles values defined for the property = "
3192: + key);
3193:
3194: //propertyLocal.setTheValue(value);
3195: propertyLocal.setPropagate(propagate);
3196: } else {
3197: try {
3198: propertyLocal = pHome.create(key, value);
3199: propertyLocal.setBnNode(nd);
3200: propertyLocal.setPropagate(propagate);
3201: } catch (InvalidValueException ie) {
3202:
3203: trace.error(ie.getMessage());
3204: throw new HeroException(ie.getMessage());
3205: } catch (javax.ejb.CreateException ce) {
3206:
3207: trace.error(ce.getMessage());
3208: throw new HeroException(ce.getMessage());
3209: }
3210: }
3211: }
3212:
3213: /**
3214: * Set a property of a node. A property is a pair key/value representing workflow relevant data. With
3215: * this method the property is propagated within others nodes.
3216: *
3217: * @param nodeName the name of the node
3218: * @param key the key of the property
3219: * @param value the name of the property
3220: * @ejb:interface-method view-type="both"
3221: * @ejb:transaction type="Required"
3222: * @throws HeroException
3223: *
3224: **/
3225:
3226: public void setNodeProperty(String nodeName, String key,
3227: String value) throws HeroException {
3228: BnNodePropertyLocalHome pHome;
3229: BnNodePropertyLocal propertyLocal = null;
3230:
3231: if (!isAdminOfProject()) {
3232: if (mProject.getName().matches(".*_instance.*")
3233: && !isUserInNodeRole(nodeName)) {
3234:
3235: trace
3236: .error("You are not allowed to set/update properties of this node... ");
3237: throw new HeroException(
3238: "You are not allowed to set/update properties of this node... ");
3239: }
3240: }
3241:
3242: trace.debug("parameters: node=" + nodeName + " key=" + key
3243: + " value=" + value + " process name = "
3244: + this .getName() + " started by " + this .getCaller());
3245: BnNodeLocal nd = mProject.getBnNode(nodeName);
3246:
3247: try {
3248: pHome = BnNodePropertyUtil.getLocalHome();
3249: } catch (javax.naming.NamingException ne) {
3250:
3251: trace.error(ne.getMessage());
3252: throw new HeroException(ne.getMessage());
3253: }
3254: Collection c = null;
3255: try {
3256: c = pHome.findByTheKey(nd.getId(), key);
3257: } catch (FinderException fe) {
3258:
3259: trace.error(fe.getMessage());
3260: throw new HeroException(fe.getMessage());
3261: }
3262:
3263: if (!c.isEmpty()) {
3264:
3265: propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
3266:
3267: //Check the value of an enumerated property contains only possible values
3268: boolean allcontains = false;
3269: if (propertyLocal.getPossibleValues() != null) {
3270: Collection ar_pv = propertyLocal.getPossibleValues();
3271: String current = value;
3272: SortedSet sort_pv = new TreeSet(new Comparator() {
3273: public int compare(Object a, Object b) {
3274: if ((a.toString().length()) < (b.toString()
3275: .length()))
3276: return 1;
3277: else if ((a.toString().length()) > (b
3278: .toString().length()))
3279: return -1;
3280: else {
3281: int re = a.toString().compareTo(
3282: b.toString());
3283: if (re > 0)
3284: return 1;
3285: else if (re < 0)
3286: return -1;
3287: else
3288: return 0;
3289: }
3290: }
3291: });
3292:
3293: Iterator it_pv = ar_pv.iterator();
3294: while (it_pv.hasNext()) {
3295: String val = (String) it_pv.next();
3296: sort_pv.add(val);
3297: }
3298: boolean found = true;
3299: boolean not_end = true;
3300: while (found && not_end) {
3301: Iterator it_check = sort_pv.iterator();
3302: found = false;
3303: while (it_check.hasNext()) {
3304: String val = (String) it_check.next();
3305: if (current.startsWith(val)) {
3306: found = true;
3307: current = current.replaceFirst(val, "");
3308: if (current.length() != 0) {
3309: current = current.substring(1);
3310: }
3311: if (current.length() == 0) {
3312: allcontains = true;
3313: not_end = false;
3314: }
3315: break;
3316: }
3317: }
3318: }
3319: }
3320:
3321: //if (propertyLocal.getPossibleValues() == null || propertyLocal.getPossibleValues().contains(value))
3322: if (propertyLocal.getPossibleValues() == null
3323: || allcontains)
3324: propertyLocal.setTheValue(value);
3325: else
3326: throw new HeroException(
3327: "Error: This value is not one of possibles values defined for the property = "
3328: + key);
3329:
3330: } else {
3331: try {
3332: propertyLocal = pHome.create(key, value);
3333: propertyLocal.setBnNode(nd);
3334:
3335: } catch (InvalidValueException ie) {
3336:
3337: trace.error(ie.getMessage());
3338: throw new HeroException(ie.getMessage());
3339: } catch (javax.ejb.CreateException ce) {
3340:
3341: trace.error(ce.getMessage());
3342: throw new HeroException(ce.getMessage());
3343: }
3344: }
3345: }
3346:
3347: /**
3348: * Set a property of the project. A property is a pair key/value representing workflow relevant data. This
3349: * methods creates a new property that can be accessed from all activites of the project.
3350: *
3351: * @param key the key of the property
3352: * @param value the name of the property
3353: * @ejb:interface-method view-type="both"
3354: * @ejb:transaction type="Required"
3355: * @throws HeroException
3356: *
3357: **/
3358: public void setProperty(String key, String value)
3359: throws HeroException {
3360:
3361: trace.debug("parameters: key=" + key + " value=" + value
3362: + " process name = " + this .getName() + " started by "
3363: + this .getCaller());
3364: // MBL: change and may be error ????
3365: //if (!isInProject(this.getCaller()))
3366: if (!isInProject(this .getName(), this .getVersion())) {
3367:
3368: trace
3369: .error("You don't have access to this project, only project users are allowed to set/update properties !!");
3370: throw new AdminException(
3371: "You don't have access to this project, only project users are allowed to set/update properties !!");
3372: }
3373: BnProjectPropertyLocalHome pHome;
3374: BnProjectPropertyLocal ppLocal = null;
3375:
3376: try {
3377: pHome = BnProjectPropertyUtil.getLocalHome();
3378: } catch (javax.naming.NamingException ne) {
3379:
3380: trace.error(ne.getMessage());
3381: throw new HeroException(ne.getMessage());
3382: }
3383: Collection c = null;
3384: try {
3385: c = pHome.findByTheKey(mProject.getId(), key);
3386: } catch (FinderException fe) {
3387:
3388: trace.error(fe.getMessage());
3389: throw new HeroException(fe.getMessage());
3390: }
3391:
3392: if (!c.isEmpty()) {
3393:
3394: ppLocal = (BnProjectPropertyLocal) (c.toArray())[0];
3395: //Check the value of an enumerated property contains only possible values
3396: boolean allcontains = false;
3397: if (ppLocal.getPossibleValues() != null) {
3398: Collection ar_pv = ppLocal.getPossibleValues();
3399: String current = value;
3400: SortedSet sort_pv = new TreeSet(new Comparator() {
3401: public int compare(Object a, Object b) {
3402: if ((a.toString().length()) < (b.toString()
3403: .length()))
3404: return 1;
3405: else if ((a.toString().length()) > (b
3406: .toString().length()))
3407: return -1;
3408: else {
3409: int re = a.toString().compareTo(
3410: b.toString());
3411: if (re > 0)
3412: return 1;
3413: else if (re < 0)
3414: return -1;
3415: else
3416: return 0;
3417: }
3418: }
3419: });
3420:
3421: Iterator it_pv = ar_pv.iterator();
3422: while (it_pv.hasNext()) {
3423: String val = (String) it_pv.next();
3424: sort_pv.add(val);
3425: }
3426: boolean found = true;
3427: boolean not_end = true;
3428: while (found && not_end) {
3429: Iterator it_check = sort_pv.iterator();
3430: found = false;
3431: while (it_check.hasNext()) {
3432: String val = (String) it_check.next();
3433: if (current.startsWith(val)) {
3434: found = true;
3435: current = current.replaceFirst(val, "");
3436: if (current.length() != 0) {
3437: current = current.substring(1);
3438: }
3439: if (current.length() == 0) {
3440: allcontains = true;
3441: not_end = false;
3442: }
3443: break;
3444: }
3445: }
3446: }
3447: }
3448: if (ppLocal.getPossibleValues() == null || allcontains)
3449: ppLocal.setTheValue(value);
3450: else
3451: throw new HeroException(
3452: "Error: This value is not one of possibles values defined for the property = "
3453: + key);
3454:
3455: } else {
3456: try {
3457: ppLocal = pHome.create(key, value);
3458: ppLocal.setBnProject(mProject);
3459:
3460: } catch (InvalidValueException ie) {
3461:
3462: trace.error(ie.getMessage());
3463: throw new HeroException(ie.getMessage());
3464: } catch (javax.ejb.CreateException ce) {
3465:
3466: trace.error(ce.getMessage());
3467: throw new HeroException(ce.getMessage());
3468: }
3469: }
3470: }
3471:
3472: /**
3473: * Set property possible values for a specific node. Values argument represent the values which are accepted
3474: * as possible property values.
3475: *
3476: * @param nodeName the name of the node
3477: * @param key property key
3478: * @param values possible values
3479: * @ejb:interface-method view-type="both"
3480: * @ejb:transaction type="Required"
3481: * @throws HeroException
3482: *
3483: **/
3484: public void setNodePropertyPossibleValues(String nodeName,
3485: String key, Collection values) throws HeroException {
3486: BnNodePropertyLocalHome pHome;
3487: BnNodePropertyLocal propertyLocal;
3488: if (!isAdminOfProject()) {
3489: if (mProject.getName().matches(".*_instance.*")
3490: && !isUserInNodeRole(nodeName)) {
3491: trace
3492: .error("You are not allowed to set/update properties of this node... ");
3493: throw new HeroException(
3494: "You are not allowed to set/update properties of this node... ");
3495: }
3496: }
3497:
3498: trace.debug("parameters: node=" + nodeName + " key=" + key
3499: + " values=" + values + " process name = "
3500: + this .getName() + " started by " + this .getCaller());
3501:
3502: BnNodeLocal nd = mProject.getBnNode(nodeName);
3503:
3504: try {
3505: pHome = BnNodePropertyUtil.getLocalHome();
3506: } catch (javax.naming.NamingException ne) {
3507:
3508: trace.error(ne.getMessage());
3509: throw new HeroException(ne.getMessage());
3510: }
3511: Collection c = null;
3512: try {
3513: c = pHome.findByTheKey(nd.getId(), key);
3514: } catch (FinderException fe) {
3515:
3516: trace.error(fe.getMessage());
3517: throw new HeroException(fe.getMessage());
3518: }
3519: if (c.isEmpty()) {
3520: try {
3521: propertyLocal = pHome.create(key, values);
3522: propertyLocal.setBnNode(nd);
3523: } catch (InvalidValueException ie) {
3524:
3525: trace.error(ie.getMessage());
3526: throw new HeroException(ie.getMessage());
3527: } catch (javax.ejb.CreateException ce) {
3528:
3529: trace.error(ce.getMessage());
3530: throw new HeroException(ce.getMessage());
3531: }
3532: }
3533: }
3534:
3535: /**
3536: * This method allows users to change dynamically the possible values defined for this property.
3537: * Only used for enumeration types.
3538: * A default value is mandatory for this method.
3539: *
3540: * @param nodeName the name of the node
3541: * @param key property key
3542: * @param values possible values
3543: * @param defaultValues Collection of default values
3544: * @ejb:interface-method view-type="both"
3545: * @ejb:transaction type="Required"
3546: * @throws HeroException
3547: *
3548: **/
3549: public void updateNodePropertyPossibleValues(String nodeName,
3550: String key, Collection values, Collection defaultValues)
3551: throws HeroException {
3552: BnNodePropertyLocalHome pHome;
3553: BnNodePropertyLocal propertyLocal;
3554: if (!isAdminOfProject()) {
3555: if (mProject.getName().matches(".*_instance.*")
3556: && !isUserInNodeRole(nodeName)) {
3557:
3558: trace
3559: .error("You are not allowed to set/update properties of this node... ");
3560: throw new HeroException(
3561: "You are not allowed to set/update properties of this node... ");
3562: }
3563: }
3564:
3565: trace.debug("parameters: node=" + nodeName + " key=" + key
3566: + " values=" + values + " defaultValue "
3567: + defaultValues + " process name = " + this .getName()
3568: + " started by " + this .getCaller());
3569:
3570: BnNodeLocal nd = mProject.getBnNode(nodeName);
3571:
3572: try {
3573: pHome = BnNodePropertyUtil.getLocalHome();
3574: } catch (javax.naming.NamingException ne) {
3575:
3576: trace.error(ne.getMessage());
3577: throw new HeroException(ne.getMessage());
3578: }
3579: Collection c;
3580: try {
3581: c = pHome.findByTheKey(nd.getId(), key);
3582: } catch (FinderException fe) {
3583:
3584: trace.error(fe.getMessage());
3585: throw new HeroException(fe.getMessage());
3586: }
3587: if (!c.isEmpty()) {
3588: propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
3589: //Check the value of an enumerated property contains only possible values
3590: Iterator it_defaultValues = defaultValues.iterator();
3591: boolean allcontains = true;
3592: String defaultValue = "";
3593: String currentValue = "";
3594: while (it_defaultValues.hasNext()) {
3595: currentValue = (String) it_defaultValues.next();
3596: if (values.contains(currentValue)) {
3597: defaultValue = defaultValue + " " + currentValue;
3598: } else {
3599: allcontains = false;
3600: break;
3601: }
3602: }
3603: if (propertyLocal.getPossibleValues() == null
3604: || allcontains) {
3605: propertyLocal.setPossibleValues(values);
3606: if (!"".equals(defaultValue))
3607: defaultValue = defaultValue.substring(1);
3608: propertyLocal.setTheValue(defaultValue);
3609: } else
3610: throw new HeroException(
3611: "Error: value in the collection of defaultValues is not one of possibles values defined for the property...");
3612: } else
3613: throw new HeroException(
3614: "An Error occurs when updating possible values...");
3615: }
3616:
3617: /**
3618: * Set property possible values. Values argument represent the values which are accepted
3619: * as possible property values.
3620: *
3621: * @param key property key
3622: * @param values possible values
3623: * @ejb:interface-method view-type="both"
3624: * @ejb:transaction type="Required"
3625: * @throws HeroException
3626: *
3627: **/
3628: public void setPropertyPossibleValues(String key, Collection values)
3629: throws HeroException {
3630: BnProjectPropertyLocalHome pHome;
3631: BnProjectPropertyLocal propertyLocal;
3632: //MBL: change and may be error ????
3633: //if (!isInProject(this.getCaller()))
3634: if (!isInProject(this .getName(), this .getVersion())) {
3635:
3636: trace
3637: .error("You don't have access to this project, only project users are allowed to set/update properties !!");
3638: throw new AdminException(
3639: "You don't have access to this project, only project users are allowed to set/update properties !!");
3640: }
3641:
3642: trace.debug("parameters: key=" + key + " values=" + values
3643: + " process name = " + this .getName() + " started by "
3644: + this .getCaller());
3645:
3646: try {
3647: pHome = BnProjectPropertyUtil.getLocalHome();
3648: } catch (javax.naming.NamingException ne) {
3649:
3650: trace.error(ne.getMessage());
3651: throw new HeroException(ne.getMessage());
3652: }
3653: Collection c = null;
3654: try {
3655: c = pHome.findByTheKey(mProject.getId(), key);
3656: } catch (FinderException fe) {
3657:
3658: trace.error(fe.getMessage());
3659: throw new HeroException(fe.getMessage());
3660: }
3661: if (c.isEmpty()) {
3662: try {
3663: propertyLocal = pHome.create(key, values);
3664: propertyLocal.setBnProject(mProject);
3665: } catch (InvalidValueException ie) {
3666:
3667: trace.error(ie.getMessage());
3668: throw new HeroException(ie.getMessage());
3669: } catch (javax.ejb.CreateException ce) {
3670:
3671: trace.error(ce.getMessage());
3672: throw new HeroException(ce.getMessage());
3673: }
3674: }
3675: }
3676:
3677: /**
3678: * This method allows users to change dynamically the possible values defined for this property.
3679: * Only used for enumeration types.
3680: * A default value is mandatory for this method.
3681: *
3682: * @param key property key
3683: * @param values possible values
3684: * @param defaultValues Collection of default values
3685: * @ejb:interface-method view-type="both"
3686: * @ejb:transaction type="Required"
3687: * @throws HeroException
3688: *
3689: **/
3690: public void updatePropertyPossibleValues(String key,
3691: Collection values, Collection defaultValues)
3692: throws HeroException {
3693: BnProjectPropertyLocalHome pHome;
3694: BnProjectPropertyLocal propertyLocal;
3695: //MBL: change and may be error ????
3696: //if (!isInProject(this.getCaller()))
3697: if (!isInProject(this .getName(), this .getVersion())) {
3698:
3699: trace
3700: .error("You don't have access to this project, only project users are allowed to set/update properties !!");
3701: throw new AdminException(
3702: "You don't have access to this project, only project users are allowed to set/update properties !!");
3703: }
3704:
3705: trace.debug("parameters: key=" + key + " values=" + values
3706: + " defaultValue=" + defaultValues + " process name = "
3707: + this .getName() + " started by " + this .getCaller());
3708:
3709: try {
3710: pHome = BnProjectPropertyUtil.getLocalHome();
3711: } catch (javax.naming.NamingException ne) {
3712:
3713: trace.error(ne.getMessage());
3714: throw new HeroException(ne.getMessage());
3715: }
3716: Collection c;
3717: try {
3718: c = pHome.findByTheKey(mProject.getId(), key);
3719: } catch (FinderException fe) {
3720:
3721: trace.error(fe.getMessage());
3722: throw new HeroException(fe.getMessage());
3723: }
3724: if (!c.isEmpty()) {
3725: propertyLocal = (BnProjectPropertyLocal) (c.toArray())[0];
3726: //Check the value of an enumerated property contains only possible values
3727: Iterator it_defaultValues = defaultValues.iterator();
3728: boolean allcontains = true;
3729: String defaultValue = "";
3730: String currentValue = "";
3731: while (it_defaultValues.hasNext()) {
3732: currentValue = (String) it_defaultValues.next();
3733: if (values.contains(currentValue)) {
3734: defaultValue = defaultValue + " " + currentValue;
3735: } else {
3736: allcontains = false;
3737: break;
3738: }
3739: }
3740: if (propertyLocal.getPossibleValues() == null
3741: || allcontains) {
3742: propertyLocal.setPossibleValues(values);
3743: if (!"".equals(defaultValue))
3744: defaultValue = defaultValue.substring(1);
3745:
3746: propertyLocal.setTheValue(defaultValue);
3747: } else
3748: throw new HeroException(
3749: "Error: value in the collection of defaultValues is not one of possibles values defined for the property...");
3750: } else
3751: throw new HeroException(
3752: "An Error occurs when updating possible values...");
3753: }
3754:
3755: // -------------------------------------------------------------------------
3756: // Set Methods only accessibles by the workflow Engine
3757: // -------------------------------------------------------------------------
3758:
3759: /**
3760: * Execute a node hook.
3761: *
3762: * @param nodeName the name of the node
3763: * @param event the event
3764: * @ejb:interface-method view-type="local"
3765: * @ejb:transaction type="Supports"
3766: * @throws HeroException
3767: *
3768: **/
3769: public void hookEvent(String nodeName, String event)
3770: throws HeroException {
3771:
3772: trace.debug("parameters: node=" + nodeName + " event=" + event
3773: + " process name = " + this .getName() + " started by "
3774: + this .getCaller());
3775: if (!isAdminOfProject()) {
3776:
3777: trace
3778: .error("Only the Admin of the project is allowed to do this operation... ");
3779: throw new AdminException(
3780: "Only the Admin of the project is allowed to do this operation... ");
3781: }
3782: Collection hooks;
3783: BnNodeLocal node;
3784:
3785: node = mProject.getBnNode(nodeName);
3786: hooks = node.getBnHooks();
3787: for (Iterator i = hooks.iterator(); i.hasNext();) {
3788: BnNodeHookLocal hk = (BnNodeHookLocal) i.next();
3789: if (hk.getEvent().equalsIgnoreCase(event)) {
3790: hero.hook.Hook h = hero.hook.Hook.make(hk.getName(),
3791: event, hk.getType());
3792: h.execute(this , event, node);
3793: }
3794: }
3795: }
3796:
3797: /**
3798: * Propagate node properties. Propagates all node properties to connected nodes.
3799: * @param nodeName the name of the Node
3800: * @ejb:interface-method view-type="local"
3801: * @ejb:transaction type="Required"
3802: * @throws HeroException
3803: *
3804: **/
3805: public void propagateNodeProperties(String nodeName)
3806: throws HeroException {
3807:
3808: trace.debug("parameter: name=" + nodeName + " process name = "
3809: + this .getName() + " started by " + this .getCaller());
3810:
3811: BnNodePropertyLocalHome pHome;
3812: BnNodePropertyLocal propertyLocal = null;
3813:
3814: BnNodeLocal nd = mProject.getBnNode(nodeName);
3815:
3816: Collection c = nd.getBnProperties();
3817: Collection c2 = nd.getOutBnEdges();
3818:
3819: if ((!c.isEmpty()) && (!c2.isEmpty())) {
3820: BnNodePropertyLocal p;
3821: BnEdgeLocal ed;
3822: for (Iterator i = c.iterator(); i.hasNext();) {
3823: p = (BnNodePropertyLocal) i.next();
3824: for (Iterator i2 = c2.iterator(); i2.hasNext();) {
3825: ed = (BnEdgeLocal) i2.next();
3826: if (p.getPropagate()) {
3827: this .setNodePropertyPossibleValues((ed
3828: .getOutBnNode()).getName(), p
3829: .getTheKey(), p.getPossibleValues());
3830: if (p.getTheValue() != null
3831: || p.getPossibleValues() == null
3832: || p.getPossibleValues().size() == 0)
3833: this .setNodeProperty((ed.getOutBnNode())
3834: .getName(), p.getTheKey(), p
3835: .getTheValue(), true);
3836: }
3837: }
3838: }
3839: }
3840: }
3841:
3842: /**
3843: * Set the node state. Set start date of this node when starts the execution and the end date when node
3844: * is terminated.
3845: *
3846: * @param name name of the node
3847: * @param state new state of the node
3848: * @ejb:interface-method view-type="local"
3849: * @ejb:transaction type="Required"
3850: * @throws HeroException
3851: *
3852: **/
3853: public void setNodeState(BnNodeLocal node, int state)
3854: throws HeroException {
3855:
3856: trace.debug("parameters: name=" + node.getName() + " state="
3857: + state + " process name = " + this .getName()
3858: + " started by " + this .getCaller());
3859:
3860: node.setState(state);
3861: if (state == hero.interfaces.Constants.Nd.EXECUTING
3862: || state == hero.interfaces.Constants.Nd.ANTICIPATING) {
3863: node.setStartDate(new java.util.Date());
3864: } else if (state == hero.interfaces.Constants.Nd.TERMINATED) {
3865: if (!(node.getStartDate() != null))
3866: node.setStartDate(new java.util.Date());
3867: node.setEndDate(new java.util.Date());
3868: } else if (state == hero.interfaces.Constants.Nd.DEAD) {
3869: if (!(node.getStartDate() != null))
3870: node.setStartDate(new java.util.Date());
3871: node.setEndDate(new java.util.Date());
3872: }
3873:
3874: // Managing deadlines
3875: if (state == hero.interfaces.Constants.Nd.READY
3876: && (node.getDeadlines().size() != 0 || node
3877: .getRelativeDeadlines().size() != 0)) {
3878: dlSession.startDeadlineEjbTimers(node.getName(), node
3879: .getBnProject().getId());
3880:
3881: } else {
3882: // For absolute deadlines
3883: if ((state == hero.interfaces.Constants.Nd.TERMINATED || state == hero.interfaces.Constants.Nd.DEAD)
3884: && node.getDeadlines().size() != 0) {
3885: Collection co = node.getDeadlines();
3886: Iterator it = co.iterator();
3887: while (it.hasNext()) {
3888: long date = ((java.sql.Timestamp) it.next())
3889: .getTime();
3890: if (date > new Date().getTime())
3891: ;
3892: dlSession.stopDeadlineEjbTimer(mProject.getName(),
3893: node.getName(), date);
3894: }
3895: }
3896: // For relative deadlines
3897: if ((state == hero.interfaces.Constants.Nd.TERMINATED || state == hero.interfaces.Constants.Nd.DEAD)
3898: && node.getRelativeDeadlines().size() != 0) {
3899: Collection co = node.getRelativeDeadlines();
3900: Iterator it = co.iterator();
3901: while (it.hasNext()) {
3902: long date = ((java.sql.Timestamp) it.next())
3903: .getTime();
3904: if (new Date().getTime() + date > new Date()
3905: .getTime())
3906: ;
3907: dlSession.stopDeadlineEjbTimer(mProject.getName(),
3908: node.getName(), date);
3909: }
3910: }
3911: }
3912: if (jms != null)
3913: jms
3914: .sendNodeEvent(SETNODESTATE, this .getName(), node
3915: .getName(), node.getType(), state, this
3916: .getCaller());
3917: }
3918:
3919: /**
3920: * Set all initial roles to ready if node does not has in edges.
3921: *
3922: * @ejb:interface-method view-type="local"
3923: * @ejb:transaction type="Required"
3924: * @throws HeroException
3925: *
3926: **/
3927: public void setNodesReady() throws HeroException {
3928:
3929: trace.debug(" process name = " + this .getName()
3930: + " started by " + this .getCaller());
3931: try {
3932: Collection nodes = mProject.getBnNodes();
3933: Iterator nds = nodes.iterator();
3934: while (nds.hasNext()) // first activities are initial
3935: {
3936: BnNodeLocal subNode = (BnNodeLocal) nds.next();
3937: if (this .getNodeInEdges(subNode.getName()).size() == 0
3938: && subNode.getState() == Constants.Nd.INITIAL
3939: && (subNode.getType() == Constants.Nd.AND_JOIN_AUTOMATIC_NODE || subNode
3940: .getType() == Constants.Nd.OR_JOIN_AUTOMATIC_NODE)) {
3941: this .setNodeState(subNode, Constants.Nd.READY);
3942: EngineLocalHome enghome;
3943: try {
3944: enghome = hero.interfaces.EngineUtil
3945: .getLocalHome();
3946: EngineLocal engine = enghome.create();
3947: engine.startActivity(mProject.getName(),
3948: subNode.getName());
3949: } catch (javax.naming.NamingException ne) {
3950: throw new HeroException(ne.getMessage());
3951: }
3952: } else if (this .getNodeInEdges(subNode.getName())
3953: .size() == 0
3954: && subNode.getState() == Constants.Nd.INITIAL)
3955: this .setNodeState(subNode, Constants.Nd.READY);
3956: }
3957: } catch (Exception ans) {
3958:
3959: trace.error("Error in setNodeReady " + ans.getMessage());
3960: throw new HeroException("Error in setNodeReady");
3961: }
3962: }
3963:
3964: /**
3965: * Propagate subProcess activity properties to subProcess
3966: *
3967: * @param node the name of the node
3968: * @ejb:interface-method view-type="local"
3969: * @ejb:transaction type="Required"
3970: * @throws HeroException
3971: *
3972: **/
3973: public void propagatesParentProperties(String node)
3974: throws HeroException {
3975:
3976: trace.debug("parameter: nodeName=" + node + " process name = "
3977: + this .getName() + " started by " + this .getCaller());
3978: BnProjectLocal pl = mProject;
3979: try {
3980: BnNodeLocal nd = mProject.getBnNode(node);
3981: Collection props = nd.getBnProperties();
3982: if (nd.getBnProject().getType().equals(
3983: Constants.Pj.INSTANCE))
3984: this .initProject(nd.getReference());
3985: else
3986: this .initProject(BonitaParsing.getSubProcessName(nd
3987: .getReference()));
3988: Iterator i = props.iterator();
3989: while (i.hasNext()) {
3990: BnNodePropertyLocal prop = (BnNodePropertyLocal) i
3991: .next();
3992: this .setPropertyPossibleValues(prop.getTheKey(), prop
3993: .getPossibleValues());
3994: if (prop.getTheValue() != null
3995: || prop.getPossibleValues() == null
3996: || prop.getPossibleValues().size() == 0)
3997: this .setProperty(prop.getTheKey(), prop
3998: .getTheValue());
3999: }
4000: this .setNodesReady();
4001: mProject = pl;
4002: } catch (Exception ans) {
4003: ans.printStackTrace();
4004: mProject = pl;
4005:
4006: trace.error("Error in propagatesParentProperties "
4007: + ans.getMessage());
4008: throw new HeroException(
4009: "Error in propagatesParentProperties");
4010: }
4011: }
4012:
4013: /**
4014: * Propagate subProcess properties to subProcess activity.
4015: *
4016: * @param node the name of the node
4017: * @ejb:interface-method view-type="local"
4018: * @ejb:transaction type="Required"
4019: * @throws HeroException
4020: *
4021: **/
4022:
4023: public void propagatesSubProcessProperties(BnNodeLocal node)
4024: throws HeroException {
4025:
4026: trace.debug("parameter: nodeName=" + node.getName()
4027: + " process name = " + this .getName() + " started by "
4028: + this .getCaller());
4029: BnProjectLocal pl = mProject;
4030: try {
4031: this .initProject(node.getReference());
4032: Collection props = this .getProperties();
4033: mProject = pl;
4034: Iterator i = props.iterator();
4035: while (i.hasNext()) {
4036: BnProjectPropertyValue prop = (BnProjectPropertyValue) i
4037: .next();
4038: this .setNodePropertyPossibleValues(node.getName(), prop
4039: .getTheKey(), prop.getPossibleValues());
4040: if (prop.getTheValue() != null
4041: || prop.getPossibleValues() == null
4042: || prop.getPossibleValues().size() == 0)
4043: this .setNodeProperty(node.getName(), prop
4044: .getTheKey(), prop.getTheValue(), true);
4045: }
4046: } catch (Exception ans) {
4047: ans.printStackTrace();
4048: mProject = pl;
4049:
4050: trace.error("Error in propagatesSubProcessProperties "
4051: + ans.getMessage());
4052: throw new HeroException(
4053: "Error in propagatesSubProcessProperties ");
4054: }
4055: }
4056:
4057: /**
4058: * Set the edge state
4059: *
4060: * @param bean of the edge
4061: * @param new state of the edge
4062: * @ejb:interface-method view-type="local"
4063: * @ejb:transaction type="Required"
4064: * @throws HeroException
4065: *
4066: **/
4067: public void setEdgeState(BnEdgeLocal edge, int state)
4068: throws HeroException {
4069:
4070: trace.debug("parameters: name=" + edge.getName() + " state="
4071: + state + " process name = " + this .getName()
4072: + " started by " + this .getCaller());
4073: edge.setState(state);
4074: if (jms != null)
4075: jms.sendEdgeEvent(SETEDGESTATE, this .getName(), edge
4076: .getName(), edge.getInBnNode().getName(), edge
4077: .getOutBnNode().getName(), this .getCaller());
4078: }
4079:
4080: /**
4081: * Set the agent state
4082: *
4083: * @param agent bean of the Agent
4084: * @param new state of the Agent
4085: * @ejb:interface-method view-type="both"
4086: * @ejb:transaction type="Required"
4087: * @throws HeroException
4088: *
4089: **/
4090: public void setAgentState(BnAgentLocal agent, int state)
4091: throws HeroException {
4092:
4093: trace.debug("parameters: name=" + agent.getName() + " state="
4094: + state + " state=" + state + " process name = "
4095: + this .getName() + " started by " + this .getCaller());
4096: agent.setState(state);
4097: }
4098:
4099: /**
4100: * Set the agentEdge state
4101: *
4102: * @param agentEdge bean of the BnAgentEdge
4103: * @param new state of the BnAgentEdge
4104: * @ejb:interface-method view-type="local"
4105: * @ejb:transaction type="Required"
4106: * @throws HeroException
4107: *
4108: **/
4109: public void setAgentEdgeState(BnAgentEdgeLocal agentEdge, int state)
4110: throws HeroException {
4111:
4112: trace.debug("parameters: name=" + agentEdge.getName()
4113: + " state=" + state + " state=" + state
4114: + " process name = " + this .getName() + " started by "
4115: + this .getCaller());
4116: agentEdge.setState(state);
4117: }
4118:
4119: /**
4120: * Set the name of the node executor. Set the name of the user which is executing the activity.
4121: *
4122: * @param name the name of the node
4123: * @ejb:interface-method view-type="local"
4124: * @ejb:transaction type="Required"
4125: * @throws HeroException
4126: *
4127: **/
4128: public void setNodeExecutor(String name) throws HeroException {
4129:
4130: trace.debug("parameter: name=" + name + " process name = "
4131: + this .getName() + " started by " + this .getCaller());
4132:
4133: BnUserLocalHome uHome;
4134: BnUserLocal user;
4135: try {
4136: uHome = BnUserUtil.getLocalHome();
4137: } catch (javax.naming.NamingException ne) {
4138:
4139: trace.error(ne.getMessage());
4140: throw new HeroException(ne.getMessage());
4141: }
4142: BnNodeLocal nd = mProject.getBnNode(name);
4143: String executor = this .getCaller();
4144: Collection users = mProject.getBnUsers();
4145: Iterator i = users.iterator();
4146: while (i.hasNext()) {
4147: BnUserLocal ul = (BnUserLocal) i.next();
4148: if (ul.getName().equals(executor)) {
4149: nd.setExecutor(executor);
4150: break;
4151: }
4152: }
4153: /*try {
4154: user = uHome.findByName(executor);
4155: } catch (FinderException fe) {
4156:
4157: trace.error("BnUser " + executor + " does not exists " + fe.getMessage());
4158: throw new HeroException("BnUser " + executor + " does not exists");
4159: }
4160: nd.setExecutor(user);*/
4161: if (jms != null)
4162: jms.sendNodeEvent(SETNODEEXECUTOR, this .getName(), name, nd
4163: .getType(), nd.getState(), this .getCaller());
4164: }
4165:
4166: // -------------------------------------------------------------------------
4167: // Get business methods
4168: // -------------------------------------------------------------------------
4169:
4170: /**
4171: * Get the list of choices into the value of the enumerated property .
4172: *
4173: * @param value the value of the enumerated property
4174: * @param possiblesValues collection of the enumerated property
4175: * @return Collection of choices of the enumerated property into the value
4176: * @ejb:interface-method view-type="both"
4177: * @ejb:transaction type="Supports"
4178: * @throws HeroException
4179: *
4180: **/
4181: public ArrayList getChoices(String value, Collection possibleValues)
4182: throws HeroException {
4183: ArrayList ar_mv = new ArrayList();
4184: boolean allcontains = false;
4185: if (possibleValues != null) {
4186: String current = value;
4187: SortedSet sort_pv = new TreeSet(new Comparator() {
4188: public int compare(Object a, Object b) {
4189: if ((a.toString().length()) < (b.toString()
4190: .length()))
4191: return 1;
4192: else if ((a.toString().length()) > (b.toString()
4193: .length()))
4194: return -1;
4195: else {
4196: int re = a.toString().compareTo(b.toString());
4197: if (re > 0)
4198: return 1;
4199: else if (re < 0)
4200: return -1;
4201: else
4202: return 0;
4203: }
4204: }
4205: });
4206: // get sorted possible values
4207: Iterator it_pv = possibleValues.iterator();
4208: while (it_pv.hasNext()) {
4209: String val = (String) it_pv.next();
4210: sort_pv.add(val);
4211: }
4212:
4213: boolean found = true;
4214: boolean not_end = true;
4215: while (found && not_end) {
4216: Iterator it_check = sort_pv.iterator();
4217: found = false;
4218: while (it_check.hasNext()) {
4219: String val = (String) it_check.next();
4220: if (current.startsWith(val)) {
4221: found = true;
4222: current = current.replaceFirst(val, "");
4223: ar_mv.add(val);
4224: if (current.length() != 0) {
4225: current = current.substring(1);
4226: }
4227: if (current.length() == 0) {
4228: allcontains = true;
4229: not_end = false;
4230: }
4231: break;
4232: }
4233: }
4234: }
4235:
4236: }
4237: return ar_mv;
4238: }
4239:
4240: /**
4241: * Get the node description. Node description represents, explicity, execution related information
4242: * of this task.
4243: *
4244: * @param name of the node
4245: * @return String - description of the node
4246: * @ejb:interface-method view-type="both"
4247: * @ejb:transaction type="Supports"
4248: * @throws HeroException
4249: *
4250: **/
4251: public String getNodeDescription(String name) throws HeroException {
4252:
4253: trace.debug("parameter: name=" + name + " process name = "
4254: + this .getName() + " started by " + this .getCaller());
4255: BnNodeLocal nd = mProject.getBnNode(name);
4256: return (nd.getDescription());
4257: }
4258:
4259: /**
4260: * Get the node hook value. This method returns the hook script associated to this node
4261: *
4262: * @param name the name of the node
4263: * @param hook hookName of the node
4264: * @return String - script associated to this hook
4265: * @ejb:interface-method view-type="both"
4266: * @ejb:transaction type="Supports"
4267: * @throws HeroException
4268: *
4269: **/
4270: public String getNodeInterHookValue(String node, String hook)
4271: throws HeroException {
4272: if (!isAdminOfProject()) {
4273:
4274: trace
4275: .error("Only the Admin of the project is allowed to do this operation... ");
4276: throw new AdminException(
4277: "Only the Admin of the project is allowed to do this operation... ");
4278: }
4279: String value = null;
4280:
4281: trace.debug("parameters: node=" + node + " hook=" + hook
4282: + " process name = " + this .getName() + " started by "
4283: + this .getCaller());
4284: BnNodeLocal nd = mProject.getBnNode(node);
4285: Collection hooks = nd.getBnInterHooks();
4286: for (Iterator ih = hooks.iterator(); ih.hasNext();) {
4287: BnNodeInterHookLocal hk = (BnNodeInterHookLocal) ih.next();
4288: if (hk.getName().equals(hook)) {
4289: value = hk.getScript();
4290: }
4291: }
4292: return value;
4293: }
4294:
4295: /**
4296: * Get the inter hook value script. This method returns the hook script associated to all project nodes.
4297: *
4298: * @param hook hook name
4299: * @return String - script associated to this hook
4300: * @ejb:interface-method view-type="both"
4301: * @ejb:transaction type="Supports"
4302: * @throws HeroException
4303: *
4304: **/
4305: public String getInterHookValue(String hook) throws HeroException {
4306: String value = null;
4307: if (!isAdminOfProject()) {
4308:
4309: trace
4310: .error("Only the Admin of the project is allowed to do this operation... ");
4311: throw new AdminException(
4312: "Only the Admin of the project is allowed to do this operation... ");
4313: }
4314:
4315: trace.debug("parameter: hook=" + hook + " process name = "
4316: + this .getName() + " started by " + this .getCaller());
4317: Collection hooks = mProject.getBnInterHooks();
4318: for (Iterator ih = hooks.iterator(); ih.hasNext();) {
4319: BnProjectInterHookLocal hk = (BnProjectInterHookLocal) ih
4320: .next();
4321: if (hk.getName().equals(hook)) {
4322: value = hk.getScript();
4323: }
4324: }
4325: return value;
4326: }
4327:
4328: /**
4329: * Get the ProjectValue (historique). Returns project information: project attributes, nodes, edges,
4330: * hooks, properties...
4331: *
4332: * @return BnProjectValue object - project data
4333: * @ejb:interface-method view-type="both"
4334: * @ejb:transaction type="Required"
4335: * @throws HeroException
4336: *
4337: **/
4338: public BnProjectValue getDetails() throws HeroException {
4339:
4340: trace.debug(" process name = " + this .getName()
4341: + " started by " + this .getCaller());
4342: return mProject.getBnProjectValue();
4343: }
4344:
4345: /**
4346: * Get the ProjectLightValue. Returns the basic project information: project attributes (without relationships)
4347: *
4348: * @return BnProjectLightValue object - project data
4349: * @ejb:interface-method view-type="both"
4350: * @ejb:transaction type="Required"
4351: * @throws HeroException
4352: *
4353: **/
4354: public BnProjectLightValue getLightDetails() throws HeroException {
4355:
4356: trace.debug(" process name = " + this .getName()
4357: + " started by " + this .getCaller());
4358: return mProject.getBnProjectLightValue();
4359: }
4360:
4361: /**
4362: * Get ProjectName
4363: * @return String - project name
4364: *
4365: * @ejb:interface-method view-type="both"
4366: * @ejb:transaction type="Supports"
4367: * @throws HeroException
4368: *
4369: **/
4370: public String getName() throws HeroException {
4371: if (mProject != null) {
4372: trace.debug(" process name = " + mProject.getName()
4373: + " started by " + this .getCaller());
4374: return mProject.getName();
4375: }
4376: return null;
4377: }
4378:
4379: /**
4380: * Get ProjectVersion
4381: * @return String - project version
4382: *
4383: * @ejb:interface-method view-type="both"
4384: * @ejb:transaction type="Supports"
4385: * @throws HeroException
4386: *
4387: **/
4388: public String getVersion() throws HeroException {
4389: if (mProject != null) {
4390: trace.debug(" process name = " + mProject.getVersion()
4391: + " started by " + this .getCaller());
4392: return mProject.getVersion();
4393: }
4394: return null;
4395: }
4396:
4397: /**
4398: * Get creator of the project. The user that created the project
4399: * @return String - project creator
4400: *
4401: * @ejb:interface-method view-type="both"
4402: * @ejb:transaction type="Supports"
4403: * @throws HeroException
4404: *
4405: **/
4406:
4407: public String getCreator() throws HeroException {
4408:
4409: trace.debug(" process name = " + this .getName()
4410: + " started by " + this .getCaller());
4411: return mProject.getCreator();
4412: }
4413:
4414: /**
4415: * Get status of the project. Active/Hidden
4416: * @return String - project status
4417: *
4418: * @ejb:interface-method view-type="both"
4419: * @ejb:transaction type="Supports"
4420: * @throws HeroException
4421: *
4422: **/
4423:
4424: public String getStatus() throws HeroException {
4425:
4426: trace.debug(" process name = " + this .getName()
4427: + " started by " + this .getCaller());
4428: return mProject.getStatus();
4429: }
4430:
4431: /**
4432: * Get type of the project. Cooperative/Model/Instance
4433: * @return String - project type
4434: *
4435: * @ejb:interface-method view-type="both"
4436: * @ejb:transaction type="Supports"
4437: * @throws HeroException
4438: *
4439: **/
4440:
4441: public String getType() throws HeroException {
4442:
4443: trace.debug(" process name = " + this .getName()
4444: + " started by " + this .getCaller());
4445: return mProject.getType();
4446: }
4447:
4448: /**
4449: * Get all roles of the project
4450: * @return Collection of BnRoleLocal objects - roles of the project
4451: *
4452: * @ejb:interface-method view-type="both"
4453: * @ejb:transaction type="Supports"
4454: * @throws HeroException
4455: *
4456: **/
4457: public Collection getRoles() throws HeroException {
4458:
4459: trace.debug(" process name = " + this .getName()
4460: + " started by " + this .getCaller());
4461: Collection roles = mProject.getBnRoles();
4462: ArrayList result = new ArrayList();
4463: for (Iterator i = roles.iterator(); i.hasNext();) {
4464: result.add((BnRoleLocal) i.next());
4465: }
4466: return result;
4467: }
4468:
4469: /**
4470: * Get all roles values of the project
4471: * @return Collection of BnRoleValue objects - roles of the project
4472: *
4473: * @ejb:interface-method view-type="both"
4474: * @ejb:transaction type="Supports"
4475: * @throws HeroException
4476: *
4477: **/
4478: public Collection getRolesValue() throws HeroException {
4479:
4480: trace.debug(" process name = " + this .getName()
4481: + " started by " + this .getCaller());
4482: Collection roles = mProject.getBnRoles();
4483: ArrayList result = new ArrayList();
4484: for (Iterator i = roles.iterator(); i.hasNext();) {
4485: BnRoleLocal rl = (BnRoleLocal) i.next();
4486: result.add(rl.getBnRoleValue());
4487: }
4488: return result;
4489: }
4490:
4491: /**
4492: * Get the value of this role in the project
4493: * @return BnRoleValue - role of the project
4494: *
4495: * @ejb:interface-method view-type="both"
4496: * @ejb:transaction type="Supports"
4497: * @throws HeroException
4498: *
4499: **/
4500: public BnRoleValue getRoleValue(String roleName)
4501: throws HeroException {
4502:
4503: trace.debug(" process name = " + this .getName()
4504: + " started by " + this .getCaller());
4505: try {
4506: BnRoleLocalHome roleh = (BnRoleLocalHome) BnRoleUtil
4507: .getLocalHome();
4508: BnRoleLocal rolel = roleh.findByName(roleName, mProject
4509: .getId());
4510: return (rolel.getBnRoleValue());
4511: } catch (Exception pfe) {
4512: throw new HeroException(
4513: "This Role does not exist in this project : "
4514: + roleName);
4515: }
4516: }
4517:
4518: /**
4519: * Get performer assign of this node.
4520: *
4521: * @return BnNodePerformerAssignValue of this node
4522: *
4523: * @param nodeName the name of the node
4524: * @ejb:interface-method view-type="both"
4525: * @ejb:transaction type="Required"
4526: * @throws HeroException
4527: *
4528: **/
4529: public BnNodePerformerAssignValue getNodePerformerAssign(
4530: String nodeName) throws HeroException {
4531: // logs trace
4532:
4533: trace.debug("parameter: nodeName=" + nodeName
4534: + " process name = " + this .getName() + " started by "
4535: + this .getCaller());
4536:
4537: BnNodeLocal node = null;
4538:
4539: // Get objet node local with findByName from BnNodeBean
4540: try {
4541: BnNodeLocalHome nodeh = (BnNodeLocalHome) BnNodeUtil
4542: .getLocalHome();
4543: node = nodeh.findByName(nodeName, mProject.getId());
4544: } catch (Exception pfe) {
4545: throw new HeroException(
4546: "The bnNode does not exist for node : " + nodeName);
4547: }
4548: if (node.getBnNodePerformerAssign() != null)
4549: return (node.getBnNodePerformerAssign()
4550: .getBnNodePerformerAssignValue());
4551: else
4552: return null;
4553: }
4554:
4555: /**
4556: * Get all roles names of the project
4557: * @return String Collection - roles names of this projects
4558: *
4559: * @ejb:interface-method view-type="both"
4560: * @ejb:transaction type="Supports"
4561: * @throws HeroException
4562: *
4563: **/
4564: public Collection getRolesNames() throws HeroException {
4565:
4566: trace.debug(" process name = " + this .getName()
4567: + " started by " + this .getCaller());
4568: Collection roles = mProject.getBnRoles();
4569: ArrayList result = new ArrayList();
4570: Iterator i = roles.iterator();
4571: while (i.hasNext()) {
4572: result.add(((BnRoleLocal) i.next()).getName());
4573: }
4574: return result;
4575: }
4576:
4577: /**
4578: * Get all user roles. This method returns all the roles for this user in differents projects.
4579: *
4580: * @param userName The name of the user
4581: * @return Collection of BnRoleValue objects - roles of the user in differents projects
4582: *
4583: * @ejb:interface-method view-type="both"
4584: * @ejb:transaction type="Supports"
4585: * @throws HeroException
4586: *
4587: **/
4588: public Collection getUserRoles(String userName)
4589: throws HeroException {
4590:
4591: trace.debug("parameter: userName=" + userName
4592: + " process name = " + this .getName() + " started by "
4593: + this .getCaller());
4594: BnUserLocalHome uHome;
4595: BnUserLocal user;
4596: try {
4597: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
4598: .getLocalHome();
4599: } catch (javax.naming.NamingException be) {
4600:
4601: trace.error(be.getMessage());
4602: throw new HeroException(be.getMessage());
4603: }
4604: try {
4605: user = uHome.findByName(userName);
4606: } catch (FinderException f) {
4607:
4608: trace.error("FinderException " + f.getMessage());
4609: throw new HeroException("FinderException");
4610: }
4611: Collection roles = user.getBnRoles();
4612: ArrayList result = new ArrayList();
4613: for (Iterator i = roles.iterator(); i.hasNext();) {
4614: BnRoleLocal rl = (BnRoleLocal) i.next();
4615: result.add(rl.getBnRoleValue());
4616: }
4617: return result;
4618: }
4619:
4620: /**
4621: * Get user roles in the current project. Returns the roles of this user in the current project.
4622: *
4623: * @param userName The name of the user
4624: * @return Collection of BnRoleValue objects - roles of the user in this project
4625: *
4626: * @ejb:interface-method view-type="both"
4627: * @ejb:transaction type="Supports"
4628: * @throws HeroException
4629: *
4630: **/
4631: public Collection getUserRolesInProject(String userName)
4632: throws HeroException {
4633:
4634: trace.debug("parameter: userName=" + userName
4635: + " process name = " + this .getName() + " started by "
4636: + this .getCaller());
4637: BnUserLocalHome uHome;
4638: BnUserLocal user;
4639: ArrayList result = new ArrayList();
4640: try {
4641: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
4642: .getLocalHome();
4643: } catch (javax.naming.NamingException be) {
4644:
4645: trace.error(be.getMessage());
4646: throw new HeroException(be.getMessage());
4647: }
4648: try {
4649: user = uHome.findByName(userName);
4650: } catch (FinderException f) {
4651:
4652: trace.error("FinderException " + f.getMessage());
4653: throw new HeroException("FinderException");
4654: }
4655: Collection userRoles = user.getBnRoles();
4656: Collection projectRoles = mProject.getBnRoles();
4657: for (Iterator i = userRoles.iterator(); i.hasNext();) {
4658: BnRoleLocal ur = (BnRoleLocal) i.next();
4659: for (Iterator j = projectRoles.iterator(); j.hasNext();) {
4660: BnRoleLocal up = (BnRoleLocal) j.next();
4661: if (ur.getId() == up.getId())
4662: result.add(ur.getBnRoleValue());
4663: }
4664: }
4665: return result;
4666: }
4667:
4668: /**
4669: * Get users matching with given role in the current project.
4670: *
4671: * @param roleName The name of the role
4672: * @return Collection of String - users matching with this role
4673: *
4674: * @ejb:interface-method view-type="both"
4675: * @ejb:transaction type="Supports"
4676: * @throws HeroException
4677: *
4678: **/
4679: public Collection getUsersRole(String roleName)
4680: throws HeroException {
4681:
4682: trace.debug("parameter: roleName=" + roleName
4683: + " process name = " + this .getName() + " started by "
4684: + this .getCaller());
4685: BnRoleLocalHome rHome;
4686: BnRoleLocal role;
4687: ArrayList result = new ArrayList();
4688: try {
4689: rHome = (BnRoleLocalHome) hero.interfaces.BnRoleUtil
4690: .getLocalHome();
4691: } catch (javax.naming.NamingException be) {
4692:
4693: trace.error(be.getMessage());
4694: throw new HeroException(be.getMessage());
4695: }
4696: try {
4697: role = rHome.findByName(roleName, mProject.getId());
4698: } catch (FinderException f) {
4699:
4700: trace.error("FinderException " + f.getMessage());
4701: throw new HeroException("FinderException");
4702: }
4703: Collection usersR = role.getBnUsers();
4704: Iterator users = usersR.iterator();
4705: while (users.hasNext()) {
4706: BnUserLocal user = (BnUserLocal) users.next();
4707: result.add(user.getName());
4708: }
4709: return result;
4710: }
4711:
4712: /**
4713: * Get user roles in project names. Returns the role names of the user in the current project
4714: *
4715: * @param userName The name of the user
4716: * @return String Collection - role names of this user in the current project
4717: *
4718: * @ejb:interface-method view-type="both"
4719: * @ejb:transaction type="Supports"
4720: * @throws HeroException
4721: *
4722: **/
4723: public Collection getUserRolesInProjectNames(String userName)
4724: throws HeroException {
4725:
4726: trace.debug("parameter: userName=" + userName
4727: + " process name = " + this .getName() + " started by "
4728: + this .getCaller());
4729: BnUserLocalHome uHome;
4730: BnUserLocal user;
4731: ArrayList result = new ArrayList();
4732: try {
4733: uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
4734: .getLocalHome();
4735: } catch (javax.naming.NamingException be) {
4736:
4737: trace.error(be.getMessage());
4738: throw new HeroException(be.getMessage());
4739: }
4740: try {
4741: user = uHome.findByName(userName);
4742: } catch (FinderException f) {
4743:
4744: trace.error("FinderException " + f.getMessage());
4745: throw new HeroException("FinderException");
4746: }
4747:
4748: Collection userRoles = user.getBnRoles();
4749: Collection projectRoles = mProject.getBnRoles();
4750: for (Iterator i = userRoles.iterator(); i.hasNext();) {
4751: BnRoleLocal ur = (BnRoleLocal) i.next();
4752: for (Iterator j = projectRoles.iterator(); j.hasNext();) {
4753: BnRoleLocal up = (BnRoleLocal) j.next();
4754: if (ur.getId().equals(up.getId()))
4755: result.add(ur.getBnRoleValue().getName());
4756: }
4757: }
4758: return result;
4759: }
4760:
4761: /**
4762: * Get node role. Returns the role information.
4763: *
4764: * @param nodeName The name of the node
4765: * @return BnRoleLocal object - the role data
4766: * @ejb:interface-method view-type="both"
4767: * @ejb:transaction type="Supports"
4768: * @throws HeroException
4769: *
4770: **/
4771: public BnRoleLocal getNodeRole(String nodeName)
4772: throws HeroException {
4773:
4774: trace.debug("parameter: nodeName=" + nodeName
4775: + " process name = " + this .getName() + " started by "
4776: + this .getCaller());
4777: BnNodeLocal nd = mProject.getBnNode(nodeName);
4778: return ((BnRoleLocal) nd.getBnRole());
4779: }
4780:
4781: /**
4782: * Get the edge Condition. This condition is evaluated at run-time in order to perform activity transition.
4783: * This condition follows the beanshell syntax (Lightweight Scripting for Java).<br>
4784: *
4785: * @param edge the edge/transition name
4786: * @return String - edge condition
4787: * @ejb:interface-method view-type="both"
4788: * @ejb:transaction type="Supports"
4789: * @throws HeroException
4790: *
4791: **/
4792: public String getEdgeCondition(String edge) throws HeroException {
4793:
4794: trace.debug("parameter: name=" + edge + " process name = "
4795: + this .getName() + " started by " + this .getCaller());
4796: BnEdgeLocal e = mProject.getBnEdge(edge);
4797: return (e.getCondition());
4798: }
4799:
4800: /**
4801: * Returns if the node is set to be executed in anticipated mode.
4802: *
4803: * @param name name of the node
4804: * @return boolean - if anticipable node is set to this node.
4805: * @ejb:interface-method view-type="both"
4806: * @ejb:transaction type="Required"
4807: * @throws HeroException
4808: *
4809: **/
4810: public boolean getNodeAnticipable(String name) throws HeroException {
4811:
4812: trace.debug("parameter: name=" + name + " process name = "
4813: + this .getName() + " started by " + this .getCaller());
4814: BnNodeLocal nd = mProject.getBnNode(name);
4815: return (nd.getAnticipable());
4816: }
4817:
4818: /**
4819: * Get node role name. Obtains the role name of this node.
4820: *
4821: * @param nodeName The name of the node
4822: * @return String - the role name of this node
4823: *
4824: * @ejb:interface-method view-type="both"
4825: * @ejb:transaction type="Supports"
4826: * @throws HeroException
4827: *
4828: **/
4829: public String getNodeRoleName(String nodeName) throws HeroException {
4830:
4831: trace.debug("parameter: nodeName=" + nodeName
4832: + " process name = " + this .getName() + " started by "
4833: + this .getCaller());
4834: BnNodeLocal nd = mProject.getBnNode(nodeName);
4835: return (((BnRoleLocal) nd.getBnRole()).getName());
4836: }
4837:
4838: /**
4839: * Get node deadline. Activity deadline is the lastest date in which the activity must be finished.
4840: *
4841: * @param nodeName The name of the node
4842: * @return String - deadline of this node
4843: *
4844: * @ejb:interface-method view-type="both"
4845: * @ejb:transaction type="Supports"
4846: * @throws HeroException
4847: * @deprecated replaced by getNodeDeadlines(String name, Collection co)
4848: *
4849: **/
4850: public String getNodeDeadline(String nodeName) throws HeroException {
4851:
4852: trace.debug("parameter: nodeName=" + nodeName
4853: + " process name = " + this .getName() + " started by "
4854: + this .getCaller());
4855: BnNodeLocal nd = mProject.getBnNode(nodeName);
4856: if (nd.getDeadlines().size() != 0) {
4857: Collection co = nd.getDeadlines();
4858: Iterator it = co.iterator();
4859: Date date = null;
4860: while (it.hasNext()) {
4861: date = (Date) it.next();
4862: }
4863: return (date.toString());
4864: } else
4865: return (null);
4866: /*
4867: if (nd.getDeadline() != null)
4868: return (nd.getDeadline().toString());
4869: else
4870: return (null);
4871: */
4872: }
4873:
4874: /**
4875: * Get collection of absolute deadlines for the node. Activity deadline is the lastest date in which the activity must be finished.
4876: *
4877: * @param nodeName The name of the node
4878: * @return Collection - collection of deadlines of this node
4879: *
4880: * @ejb:interface-method view-type="both"
4881: * @ejb:transaction type="Supports"
4882: * @throws HeroException
4883: *
4884: **/
4885: public Collection getNodeDeadlines(String nodeName)
4886: throws HeroException {
4887:
4888: trace.debug("parameter: nodeName=" + nodeName
4889: + " process name = " + this .getName() + " started by "
4890: + this .getCaller());
4891: BnNodeLocal nd = mProject.getBnNode(nodeName);
4892: if (nd.getDeadlines() != null)
4893: return (nd.getDeadlines());
4894: else
4895: return (null);
4896: }
4897:
4898: /**
4899: * Get collection of relative deadlines for the node. Activity deadline is the lastest date in which the activity must be finished.
4900: *
4901: * @param nodeName The name of the node
4902: * @return Collection - collection of deadlines of this node
4903: *
4904: * @ejb:interface-method view-type="both"
4905: * @ejb:transaction type="Supports"
4906: * @throws HeroException
4907: *
4908: **/
4909: public Collection getNodeRelativeDeadlines(String nodeName)
4910: throws HeroException {
4911:
4912: trace.debug("parameter: nodeName=" + nodeName
4913: + " process name = " + this .getName() + " started by "
4914: + this .getCaller());
4915: BnNodeLocal nd = mProject.getBnNode(nodeName);
4916: if (nd.getRelativeDeadlines() != null)
4917: return (nd.getRelativeDeadlines());
4918: else
4919: return (null);
4920: }
4921:
4922: /**
4923: * Get the node Value. Returns node information.
4924: *
4925: * @param name the name of the Node
4926: * @return BnNodeValue object - node data.
4927: *
4928: * @ejb:interface-method view-type="both"
4929: * @ejb:transaction type="Supports"
4930: * @throws HeroException
4931: *
4932: **/
4933: public BnNodeValue getNodeValue(String name) throws HeroException {
4934:
4935: trace.debug("parameter: name=" + name + " process name = "
4936: + this .getName() + " started by " + this .getCaller());
4937: BnNodeLocalHome nHome;
4938: BnNodeLocal mNode;
4939: BnNodeValue nv;
4940: try {
4941: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
4942: } catch (javax.naming.NamingException be) {
4943:
4944: trace.error(be.getMessage());
4945: throw new HeroException(be.getMessage());
4946: }
4947: try {
4948: mNode = nHome.findByName(name, mProject.getId());
4949: } catch (FinderException fe) {
4950:
4951: trace.error("In Node does not exist " + fe.getMessage());
4952: throw new HeroException("In Node does not exist");
4953: }
4954: nv = mNode.getBnNodeValue();
4955: return nv;
4956: }
4957:
4958: /**
4959: * Get the Agent Value.
4960: *
4961: * @param name the name of the Agent
4962: * @return BnAgentValue object - agent data.
4963: *
4964: * @ejb:interface-method view-type="both"
4965: * @ejb:transaction type="Supports"
4966: * @throws HeroException
4967: *
4968: **/
4969: public BnAgentValue getAgentValue(String name) throws HeroException {
4970:
4971: trace.debug("parameter: name=" + name + " process name = "
4972: + this .getName() + " started by " + this .getCaller());
4973: BnAgentLocalHome nHome;
4974: BnAgentLocal mAgent;
4975: BnAgentValue av;
4976: try {
4977: nHome = hero.interfaces.BnAgentUtil.getLocalHome();
4978: } catch (javax.naming.NamingException be) {
4979:
4980: trace.error(be.getMessage());
4981: throw new HeroException(be.getMessage());
4982: }
4983: try {
4984: mAgent = nHome.findByName(name, mProject.getId());
4985: } catch (FinderException fe) {
4986:
4987: trace.error("In BnAgent does not exist " + fe.getMessage());
4988: throw new HeroException("In BnAgent does not exist");
4989: }
4990: av = mAgent.getBnAgentValue();
4991: return av;
4992: }
4993:
4994: /**
4995: * Get the AgentEdge Value
4996: *
4997: * @param name the name of the BnAgentEdge
4998: * @return BnAgentEdgeValue object - agentEdge data.
4999: *
5000: * @ejb:interface-method view-type="both"
5001: * @ejb:transaction type="Supports"
5002: * @throws HeroException
5003: *
5004: **/
5005: public BnAgentEdgeValue getAgentEdgeValue(String name)
5006: throws HeroException {
5007:
5008: trace.debug("parameter: name=" + name);
5009: BnAgentEdgeLocalHome nHome;
5010: BnAgentEdgeLocal mAgentEdge;
5011: BnAgentEdgeValue av;
5012: try {
5013: nHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome();
5014: } catch (javax.naming.NamingException be) {
5015:
5016: trace.error(be.getMessage());
5017: throw new HeroException(be.getMessage());
5018: }
5019: try {
5020: mAgentEdge = nHome.findByName(name, mProject.getId());
5021: } catch (FinderException fe) {
5022:
5023: trace.error("In BnAgentEdge does not exist "
5024: + fe.getMessage());
5025: throw new HeroException("In BnAgentEdge does not exist");
5026: }
5027: av = mAgentEdge.getBnAgentEdgeValue();
5028:
5029: trace.debug(" process name = " + this .getName()
5030: + " started by " + this .getCaller());
5031: return av;
5032: }
5033:
5034: /**
5035: * Get the node Light Value. Returns node basic information.
5036: *
5037: * @param name the name of the Node
5038: * @return BnNodeLightValue object - agentEdge data.
5039: *
5040: * @ejb:interface-method view-type="both"
5041: * @ejb:transaction type="Supports"
5042: * @throws HeroException
5043: *
5044: **/
5045: public BnNodeLightValue getNodeLightValue(String name)
5046: throws HeroException {
5047:
5048: trace.debug("parameter: name=" + name);
5049: BnNodeLocalHome nHome;
5050: BnNodeLocal mNode;
5051: BnNodeLightValue nv;
5052: try {
5053: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
5054: } catch (javax.naming.NamingException be) {
5055:
5056: trace.error(be.getMessage());
5057: throw new HeroException(be.getMessage());
5058: }
5059: try {
5060: mNode = nHome.findByName(name, mProject.getId());
5061: } catch (FinderException fe) {
5062:
5063: trace.error("In Node does not exist " + fe.getMessage());
5064: throw new HeroException("In Node does not exist");
5065: }
5066: nv = mNode.getBnNodeLightValue();
5067: return nv;
5068: }
5069:
5070: /**
5071: * Get the edge value.
5072: *
5073: * @param name the name of the edge
5074: * @return BnEdgeValue object - edge data.
5075: *
5076: * @ejb:interface-method view-type="both"
5077: * @ejb:transaction type="Supports"
5078: * @throws HeroException
5079: *
5080: **/
5081: public BnEdgeValue getEdgeValue(String name) throws HeroException {
5082:
5083: trace.debug("parameter: name=" + name + " process name = "
5084: + this .getName() + " started by " + this .getCaller());
5085: BnEdgeLocalHome eHome;
5086: BnEdgeLocal mEdge;
5087: BnEdgeValue ev;
5088: try {
5089: eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
5090: } catch (javax.naming.NamingException be) {
5091:
5092: trace.error(be.getMessage());
5093: throw new HeroException(be.getMessage());
5094: }
5095: try {
5096: mEdge = eHome.findByName(name, mProject.getId());
5097: } catch (FinderException fe) {
5098:
5099: trace.error("BnEdge does not exist " + fe.getMessage());
5100: throw new HeroException("BnEdge does not exist");
5101: }
5102: ev = mEdge.getBnEdgeValue();
5103: return ev;
5104: }
5105:
5106: /**
5107: * Get the node executor. Get the name of the user which is executing the activity.
5108: *
5109: * @param name the name of the node
5110: * @return String - the user executor of this node
5111: * @ejb:interface-method view-type="both"
5112: * @ejb:transaction type="Supports"
5113: * @throws HeroException
5114: *
5115: **/
5116: public String getNodeExecutor(String name) throws HeroException {
5117:
5118: trace.debug("parameter: name=" + name + " process name = "
5119: + this .getName() + " started by " + this .getCaller());
5120: BnNodeLocal nd = mProject.getBnNode(name);
5121: //BnUserLocal ul = nd.getExecutor();
5122: //return (ul.getName());
5123: return nd.getExecutor();
5124: }
5125:
5126: /**
5127: * Get the state of the node. The possible states for a node are:<br><br>
5128: *
5129: * hero.interfaces.Constants.Nd.INITIAL<br>
5130: * hero.interfaces.Constants.Nd.READY<br>
5131: * hero.interfaces.Constants.Nd.DEAD<br>
5132: * hero.interfaces.Constants.Nd.ANTICIPABLE<br>
5133: * hero.interfaces.Constants.Nd.ANTICIPATING<br>
5134: * hero.interfaces.Constants.Nd.EXECUTING<br>
5135: * hero.interfaces.Constants.Nd.TERMINATED<br>
5136: *
5137: * @param name of the node
5138: * @return int - The state of the node
5139: * @ejb:interface-method view-type="both"
5140: * @ejb:transaction type="Supports"
5141: * @throws HeroException
5142: *
5143: **/
5144: public int getNodeState(String name) throws HeroException {
5145:
5146: trace.debug("parameter: name=" + name + " process name = "
5147: + this .getName() + " started by " + this .getCaller());
5148: BnNodeLocal nd = mProject.getBnNode(name);
5149: return (nd.getState());
5150: }
5151:
5152: /**
5153: * Get the type of the node. Possibles node types are:<br><br>
5154: *
5155: * hero.interfaces.Constants.Nd.AND_JOIN_NODE<br>
5156: * hero.interfaces.Constants.Nd.OR_JOIN_NODE<br>
5157: * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE<br>
5158: * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE<br>
5159: *
5160: * @param name of the node
5161: * @return int - The type of the node
5162: * @ejb:interface-method view-type="both"
5163: * @ejb:transaction type="Supports"
5164: * @throws HeroException
5165: *
5166: **/
5167: public int getNodeType(String name) throws HeroException {
5168:
5169: trace.debug("parameter: name=" + name + " process name = "
5170: + this .getName() + " started by " + this .getCaller());
5171: BnNodeLocal nd = mProject.getBnNode(name);
5172: return (nd.getType());
5173: }
5174:
5175: /**
5176: * Get all users of the project. Obtains the user names of the project
5177: * @return String Collection - user names in project
5178: *
5179: * @ejb:interface-method view-type="both"
5180: * @ejb:transaction type="Supports"
5181: * @throws HeroException
5182: *
5183: **/
5184: public Collection getUsers() throws HeroException {
5185:
5186: trace.debug(" process name = " + this .getName()
5187: + " started by " + this .getCaller());
5188: Collection users = mProject.getBnUsers();
5189: ArrayList result = new ArrayList();
5190: for (Iterator i = users.iterator(); i.hasNext();) {
5191: result.add(((BnUserLocal) i.next()).getName());
5192: }
5193: return result;
5194: }
5195:
5196: /**
5197: * Return all registered users. Get user names of Bonita System
5198: * @return String Collection - all user names
5199: *
5200: * @ejb:interface-method view-type="both"
5201: * @ejb:transaction type="Supports"
5202: * @throws HeroException
5203: *
5204: **/
5205: public Collection getAllUsers() throws HeroException {
5206:
5207: trace.debug(" process name = " + this .getName()
5208: + " started by " + this .getCaller());
5209: UserServiceLocalHome ushome;
5210: UserServiceLocal ul;
5211: Collection users;
5212: try {
5213: ushome = (UserServiceLocalHome) hero.interfaces.UserServiceUtil
5214: .getLocalHome();
5215: } catch (javax.naming.NamingException be) {
5216:
5217: trace.error(be.getMessage());
5218: throw new HeroException(be.getMessage());
5219: }
5220: try {
5221: ul = ushome.create();
5222: users = ul.findUsers();
5223: } catch (Exception fe) {
5224:
5225: trace.error("Error in find users " + fe.getMessage());
5226: throw new HeroException("Error in find users ");
5227: }
5228: ArrayList result = new ArrayList();
5229: for (Iterator i = users.iterator(); i.hasNext();) {
5230: Map user = (Map) i.next();
5231: result.add(user.get("name"));
5232: }
5233: return result;
5234: }
5235:
5236: /**
5237: * Get all node names of the project
5238: *
5239: * @return String Collection - all node names
5240: * @ejb:interface-method view-type="both"
5241: * @ejb:transaction type="Supports"
5242: * @throws HeroException
5243: *
5244: **/
5245: public Collection getNodesNames() throws HeroException {
5246:
5247: trace.debug(" process name = " + this .getName()
5248: + " started by " + this .getCaller());
5249:
5250: // Vector names = new Vector();
5251: ArrayList names = new ArrayList();
5252: Collection nodes = mProject.getBnNodes();
5253: Iterator i = nodes.iterator();
5254: while (i.hasNext()) {
5255: BnNodeLocal n = (BnNodeLocal) i.next();
5256: names.add(n.getName());
5257: }
5258: return ((Collection) names);
5259: }
5260:
5261: /**
5262: * Get all edges names of the project
5263: * @return String Collection - all edges names of the project
5264: *
5265: * @ejb:interface-method view-type="both"
5266: * @ejb:transaction type="Supports"
5267: * @throws HeroException
5268: *
5269: **/
5270: public Collection getEdgesNames() throws HeroException {
5271:
5272: trace.debug(" process name = " + this .getName()
5273: + " started by " + this .getCaller());
5274: // Vector names = new Vector();
5275: ArrayList names = new ArrayList();
5276: Collection edges = mProject.getBnEdges();
5277: Iterator i = edges.iterator();
5278: while (i.hasNext()) {
5279: BnEdgeLocal n = (BnEdgeLocal) i.next();
5280: names.add(n.getName());
5281: }
5282: return ((Collection) names);
5283: }
5284:
5285: /**
5286: * Get edge in node. Returns the name of in node
5287: * @param edgeName the name ot the edge
5288: * @return String - the name of in node
5289: *
5290: * @ejb:interface-method view-type="both"
5291: * @ejb:transaction type="Supports"
5292: * @throws HeroException
5293: *
5294: **/
5295: public String getEdgeInNode(String edgeName) throws HeroException {
5296:
5297: trace.debug("parameter: edgeName" + edgeName
5298: + " process name = " + this .getName() + " started by "
5299: + this .getCaller());
5300: BnEdgeLocal e = mProject.getBnEdge(edgeName);
5301: return (((BnNodeLocal) e.getInBnNode()).getName());
5302: }
5303:
5304: /**
5305: * Get edge out node. Returns the name of out node
5306: * @param edgeName the name ot the edge
5307: * @return String - the name of out node
5308: *
5309: * @ejb:interface-method view-type="both"
5310: * @ejb:transaction type="Supports"
5311: * @throws HeroException
5312: *
5313: **/
5314: public String getEdgeOutNode(String edgeName) throws HeroException {
5315:
5316: trace.debug("parameter: edgeName" + edgeName
5317: + " process name = " + this .getName() + " started by "
5318: + this .getCaller());
5319: BnEdgeLocal e = mProject.getBnEdge(edgeName);
5320: return (((BnNodeLocal) e.getOutBnNode()).getName());
5321: }
5322:
5323: /**
5324: * Get all in edges of the node
5325: *
5326: * @param name the name ot the node
5327: * @return String Collection - get in edges of the node
5328: *
5329: * @ejb:interface-method view-type="both"
5330: * @ejb:transaction type="Supports"
5331: * @throws HeroException
5332: *
5333: **/
5334: public Collection getNodeInEdges(String name) throws HeroException {
5335:
5336: trace.debug("parameter: name=" + name + " process name = "
5337: + this .getName() + " started by " + this .getCaller());
5338:
5339: Collection in = new ArrayList();
5340: BnNodeLocal nd = mProject.getBnNode(name);
5341:
5342: Collection edgesIn = nd.getInBnEdges();
5343: Iterator i = edgesIn.iterator();
5344: while (i.hasNext())
5345: in.add(((BnEdgeLocal) i.next()).getName());
5346: return (in);
5347: }
5348:
5349: /**
5350: * Get all out edges of the node
5351:
5352: * @param name the name ot the node
5353: * @return String Collection - get out edges of the node
5354: *
5355: * @ejb:interface-method view-type="both"
5356: * @ejb:transaction type="Supports"
5357: * @throws HeroException
5358: *
5359: **/
5360: public Collection getNodeOutEdges(String name) throws HeroException {
5361:
5362: trace.debug("parameter: name=" + name + " process name = "
5363: + this .getName() + " started by " + this .getCaller());
5364:
5365: Collection out = new ArrayList();
5366: BnNodeLocal nd = mProject.getBnNode(name);
5367:
5368: Collection edgesOut = nd.getOutBnEdges();
5369: Iterator i = edgesOut.iterator();
5370: while (i.hasNext())
5371: out.add(((BnEdgeLocal) i.next()).getName());
5372: return (out);
5373: }
5374:
5375: /**
5376: * Get Node properties. Get a list of pair key/value properties associated to the node.
5377: *
5378: * @param nodeName the name of the node
5379: * @return Collection of BnNodePropertyValue objects - all node properties
5380: * @ejb:interface-method view-type="both"
5381: * @ejb:transaction type="Supports"
5382: * @throws HeroException
5383: *
5384: **/
5385: public Collection getNodeProperties(String nodeName)
5386: throws HeroException {
5387:
5388: trace.debug("parameter: name=" + nodeName + " process name = "
5389: + this .getName() + " started by " + this .getCaller());
5390: Collection prp = new ArrayList();
5391: BnNodePropertyLocal pl;
5392:
5393: BnNodeLocal nd = mProject.getBnNode(nodeName);
5394:
5395: Collection pls = nd.getBnProperties();
5396:
5397: for (Iterator i = pls.iterator(); i.hasNext();) {
5398: pl = (BnNodePropertyLocal) i.next();
5399: prp.add(pl.getBnNodePropertyValue());
5400: }
5401: return (prp);
5402: }
5403:
5404: /**
5405: * Get Node property value. Get a pair key/value properties associated to the node.
5406: *
5407: * @param nodeName the name of the node
5408: * @param key Property key
5409: * @return BnNodePropertyValue object - node property data
5410: * @ejb:interface-method view-type="both"
5411: * @ejb:transaction type="Supports"
5412: * @throws HeroException
5413: *
5414: **/
5415: public BnNodePropertyValue getNodeProperty(String nodeName,
5416: String key) throws HeroException {
5417:
5418: trace.debug("parameters: node=" + nodeName + " key=" + key
5419: + " process name = " + this .getName() + " started by "
5420: + this .getCaller());
5421: BnNodePropertyLocal pl;
5422: BnNodeLocal nd = mProject.getBnNode(nodeName);
5423: Collection pls = nd.getBnProperties();
5424:
5425: for (Iterator i = pls.iterator(); i.hasNext();) {
5426: pl = (BnNodePropertyLocal) i.next();
5427: if (pl.getTheKey().equals(key))
5428: return (pl.getBnNodePropertyValue());
5429:
5430: }
5431: return (null);
5432: }
5433:
5434: /**
5435: * Get property value of the project. Get a pair key/value properties associated to this project.
5436: *
5437: * @param key Property key
5438: * @return BnProjectPropertyValue object - property data
5439: * @ejb:interface-method view-type="both"
5440: * @ejb:transaction type="Supports"
5441: * @throws HeroException
5442: *
5443: **/
5444: public BnProjectPropertyValue getProperty(String key)
5445: throws HeroException {
5446:
5447: trace.debug("parameter: key=" + key + " process name = "
5448: + this .getName() + " started by " + this .getCaller());
5449: BnProjectPropertyLocal pl;
5450: Collection pls = mProject.getBnProperties();
5451:
5452: for (Iterator i = pls.iterator(); i.hasNext();) {
5453: pl = (BnProjectPropertyLocal) i.next();
5454: if (pl.getTheKey().equals(key))
5455: return (pl.getBnProjectPropertyValue());
5456: }
5457: return (null);
5458: }
5459:
5460: /**
5461: * Get Node hooks of the project. Get hooks of the node. Method to get the list of Java or TCL hooks of the node.
5462: *
5463: * @param nodeName the name of the node
5464: * @return Collection of BnNodeHookValue - all node hooks
5465: * @ejb:interface-method view-type="both"
5466: * @ejb:transaction type="Supports"
5467: * @throws HeroException
5468: *
5469: **/
5470: public Collection getNodeHooks(String nodeName)
5471: throws HeroException {
5472:
5473: trace.debug("parameter: node=" + nodeName + " process name = "
5474: + this .getName() + " started by " + this .getCaller());
5475: Collection hk = new ArrayList();
5476: BnNodeHookLocal pl;
5477:
5478: BnNodeLocal nd = mProject.getBnNode(nodeName);
5479:
5480: Collection pls = nd.getBnHooks();
5481:
5482: for (Iterator i = pls.iterator(); i.hasNext();) {
5483: pl = (BnNodeHookLocal) i.next();
5484: hk.add(pl.getBnNodeHookValue());
5485: }
5486: return (hk);
5487: }
5488:
5489: /**
5490: * Get Interactive Node hooks of the project
5491: *
5492: * @param nodeName the name of the node
5493: * @return Collection of BnNodeInterHookValue objects - all node hooks
5494: * @ejb:interface-method view-type="both"
5495: * @ejb:transaction type="Supports"
5496: * @throws HeroException
5497: *
5498: **/
5499: public Collection getNodeInterHooks(String nodeName)
5500: throws HeroException {
5501:
5502: trace.debug("parameter: node=" + nodeName + " process name = "
5503: + this .getName() + " started by " + this .getCaller());
5504:
5505: Collection hk = new ArrayList();
5506: BnNodeInterHookLocal pl;
5507:
5508: BnNodeLocal nd = mProject.getBnNode(nodeName);
5509:
5510: Collection pls = nd.getBnInterHooks();
5511:
5512: for (Iterator i = pls.iterator(); i.hasNext();) {
5513: pl = (BnNodeInterHookLocal) i.next();
5514: hk.add(pl.getBnNodeInterHookValue());
5515: }
5516: return (hk);
5517: }
5518:
5519: /**
5520: * Get role mappers of the project.
5521: *
5522: * @return Collection of BnRoleMapperValue - all role mappers
5523: * @ejb:interface-method view-type="both"
5524: * @ejb:transaction type="Supports"
5525: * @throws HeroException
5526: *
5527: **/
5528: public Collection getRoleMappers() throws HeroException {
5529:
5530: trace.debug(" process name = " + this .getName()
5531: + " started by " + this .getCaller());
5532:
5533: Collection cm = new ArrayList();
5534: BnRoleMapperLocal mapperL = null;
5535: BnRoleLocal roleL = null;
5536: Collection cr = mProject.getBnRoles();
5537:
5538: for (Iterator i = cr.iterator(); i.hasNext();) {
5539: roleL = (BnRoleLocal) i.next();
5540: // get the mapper if exists
5541: mapperL = roleL.getBnRoleMapper();
5542: if (mapperL != null) {
5543: cm.add(mapperL.getBnRoleMapperValue());
5544: }
5545: }
5546: return (cm);
5547: }
5548:
5549: /**
5550: * Get Interactive hooks of the project. Returns hooks assigned to project nodes.
5551: *
5552: * @return Collection of ProjectInterHookValue - project inter hooks
5553: * @ejb:interface-method view-type="both"
5554: * @ejb:transaction type="Supports"
5555: * @throws HeroException
5556: *
5557: **/
5558: public Collection getInterHooks() throws HeroException {
5559:
5560: trace.debug(" process name = " + this .getName()
5561: + " started by " + this .getCaller());
5562:
5563: Collection hk = new ArrayList();
5564: BnProjectInterHookLocal pl;
5565: Collection pls = mProject.getBnInterHooks();
5566:
5567: for (Iterator i = pls.iterator(); i.hasNext();) {
5568: pl = (BnProjectInterHookLocal) i.next();
5569: hk.add(pl.getBnProjectInterHookValue());
5570: }
5571: return (hk);
5572: }
5573:
5574: /**
5575: * Get Node inter hook of the project
5576: *
5577: * @param nodeName the name of the node
5578: * @param interHook name of the hooks
5579: * @return BnNodeInterHookValue object - node hook data
5580: * @ejb:interface-method view-type="both"
5581: * @ejb:transaction type="Supports"
5582: * @throws HeroException
5583: *
5584: **/
5585: public BnNodeInterHookValue getNodeInterHook(String nodeName,
5586: String interHook) throws HeroException {
5587:
5588: trace.debug("parameters: node=" + nodeName + " key="
5589: + interHook + " process name = " + this .getName()
5590: + " started by " + this .getCaller());
5591: BnNodeInterHookLocal hl;
5592: BnNodeLocal nd = mProject.getBnNode(nodeName);
5593: Collection hls = nd.getBnInterHooks();
5594:
5595: for (Iterator i = hls.iterator(); i.hasNext();) {
5596: hl = (BnNodeInterHookLocal) i.next();
5597: if (hl.getName().equals(interHook))
5598: return (hl.getBnNodeInterHookValue());
5599: }
5600: return (null);
5601: }
5602:
5603: /**
5604: * Get properties key of the project. A property is a pair key/value representing workflow relevant data. This
5605: * methods obtains properties key of the project.
5606: * @return Collection of String - all project properties
5607: * @ejb:interface-method view-type="both"
5608: * @ejb:transaction type="Supports"
5609: * @throws HeroException
5610: *
5611: **/
5612: public Collection getPropertiesKey() throws HeroException {
5613:
5614: trace.debug("started by " + this .getCaller());
5615: Collection prp = new ArrayList();
5616: BnProjectPropertyLocal ppl;
5617:
5618: Collection pls = mProject.getBnProperties();
5619: for (Iterator i = pls.iterator(); i.hasNext();) {
5620: ppl = (BnProjectPropertyLocal) i.next();
5621: prp.add(ppl.getBnProjectPropertyValue().getTheKey());
5622: }
5623: return (prp);
5624: }
5625:
5626: /**
5627: * Get ALL project iterations.
5628: *
5629: * @return Collection of BnIterationLightValue - all project iterations
5630: * @ejb:interface-method view-type="both"
5631: * @ejb:transaction type="Supports"
5632: * @throws HeroException
5633: *
5634: **/
5635: public Object[] getIterations() throws HeroException {
5636:
5637: trace.debug("started by " + this .getCaller());
5638: Collection ite = new ArrayList();
5639: BnIterationLocal itel;
5640:
5641: Collection itls = mProject.getBnIterations();
5642: for (Iterator i = itls.iterator(); i.hasNext();) {
5643: itel = (BnIterationLocal) i.next();
5644: BnIterationLightValue iv = (BnIterationLightValue) itel
5645: .getBnIterationLightValue();
5646: ite.add(iv);
5647: }
5648: return (ite.toArray());
5649: }
5650:
5651: /**
5652: * Get nodes destinations of this iteration. <br>
5653: * We can have more than 1 iteration starting in the same node.
5654: *
5655: * @return Collection
5656: * @ejb:interface-method view-type="both"
5657: * @ejb:transaction type="Supports"
5658: * @throws HeroException
5659: *
5660: **/
5661: public Collection getIterations(String from) throws HeroException {
5662:
5663: trace.debug("parameters: from=" + from + "started by "
5664: + this .getCaller());
5665: BnIterationLocalHome iteh;
5666:
5667: try {
5668: iteh = BnIterationUtil.getLocalHome();
5669: } catch (javax.naming.NamingException ne) {
5670:
5671: trace.error(ne.getMessage());
5672: throw new HeroException(ne.getMessage());
5673: }
5674: try {
5675: Collection iterations = iteh.findByFrom(mProject.getId(),
5676: from);
5677: return (iterations);
5678: } catch (FinderException fe) {
5679:
5680: trace.error(fe.getMessage());
5681: return (null);
5682: }
5683: }
5684:
5685: /**
5686: * Verifies if this node starts one iteration or more iterations
5687: *
5688: * @return boolean
5689: * @ejb:interface-method view-type="both"
5690: * @ejb:transaction type="Supports"
5691: * @throws HeroException
5692: *
5693: **/
5694: public boolean getIterationExist(String from) throws HeroException {
5695:
5696: trace.debug("parameters: from=" + from + "started by "
5697: + this .getCaller());
5698: BnIterationLocalHome iteh;
5699:
5700: try {
5701: iteh = BnIterationUtil.getLocalHome();
5702: } catch (javax.naming.NamingException ne) {
5703:
5704: trace.error(ne.getMessage());
5705: throw new HeroException(ne.getMessage());
5706: }
5707: try {
5708: Collection iterations = iteh.findByFrom(mProject.getId(),
5709: from);
5710: if (iterations.isEmpty()) {
5711: return false;
5712: } else {
5713: return true;
5714: }
5715: } catch (FinderException fe) {
5716: return (false);
5717: }
5718: }
5719:
5720: /**
5721: * Verifies if an iteration exist between both nodes
5722: *
5723: * @return boolean
5724: * @ejb:interface-method view-type="both"
5725: * @ejb:transaction type="Supports"
5726: * @throws HeroException
5727: *
5728: **/
5729: public boolean getIterationExist(String from, String to)
5730: throws HeroException {
5731:
5732: trace.debug("parameters: from=" + from + " to=" + to
5733: + " started by " + this .getCaller());
5734: BnIterationLocalHome iteh;
5735:
5736: try {
5737: iteh = BnIterationUtil.getLocalHome();
5738: } catch (javax.naming.NamingException ne) {
5739:
5740: trace.error(ne.getMessage());
5741: throw new HeroException(ne.getMessage());
5742: }
5743: try {
5744: iteh.findByFromTo(mProject.getId(), from, to);
5745: } catch (FinderException fe) {
5746: return (false);
5747: }
5748: return true;
5749: }
5750:
5751: /**
5752: * Get iterations conditions <br>
5753: * We can have more than 1 iteration starting in the same node.
5754: *
5755: * @return Collection - collection of conditions that starts in node from
5756: * @ejb:interface-method view-type="both"
5757: * @ejb:transaction type="Supports"
5758: * @throws HeroException
5759: *
5760: **/
5761: public Collection getIterationConditions(String from)
5762: throws HeroException {
5763:
5764: trace.debug("parameters: from=" + from + "started by "
5765: + this .getCaller());
5766: BnIterationLocalHome iteh;
5767:
5768: try {
5769: iteh = BnIterationUtil.getLocalHome();
5770: } catch (javax.naming.NamingException ne) {
5771:
5772: trace.error(ne.getMessage());
5773: throw new HeroException(ne.getMessage());
5774: }
5775: try {
5776: Collection iterations = iteh.findByFrom(mProject.getId(),
5777: from);
5778: return (iterations);
5779: } catch (FinderException fe) {
5780: trace.error(fe.getMessage());
5781: return (null);
5782: }
5783: }
5784:
5785: /**
5786: * Get properties of the project. A property is a pair key/value representing workflow relevant data. This
5787: * method obtains properties of the project.
5788: * @return Collection of ProjectPropertyValue - all project properties
5789: * @ejb:interface-method view-type="both"
5790: * @ejb:transaction type="Supports"
5791: * @throws HeroException
5792: *
5793: **/
5794: public Collection getProperties() throws HeroException {
5795:
5796: trace.debug(" process name = " + this .getName()
5797: + " started by " + this .getCaller());
5798: Collection prp = new ArrayList();
5799: BnProjectPropertyLocal ppl;
5800:
5801: Collection pls = mProject.getBnProperties();
5802: for (Iterator i = pls.iterator(); i.hasNext();) {
5803: ppl = (BnProjectPropertyLocal) i.next();
5804: prp.add(ppl.getBnProjectPropertyValue());
5805: }
5806: return (prp);
5807: }
5808:
5809: /**
5810: * Get hooks of the project. Method to get the list of Java or TCL hooks of the project
5811: *
5812: * @return Collection of BnProjectHooksValue - all project hook
5813: * @ejb:interface-method view-type="both"
5814: * @ejb:transaction type="Supports"
5815: * @throws HeroException
5816: *
5817: **/
5818: public Collection getHooks() throws HeroException {
5819:
5820: trace.debug(" process name = " + this .getName()
5821: + " started by " + this .getCaller());
5822: Collection hooks = new ArrayList();
5823: BnProjectHookLocal phl;
5824:
5825: Collection hks = mProject.getBnHooks();
5826: for (Iterator i = hks.iterator(); i.hasNext();) {
5827: phl = (BnProjectHookLocal) i.next();
5828: hooks.add(phl.getBnProjectHookValue());
5829: }
5830: return (hooks);
5831: }
5832:
5833: /**
5834: * Get the project name of this instance
5835: *
5836: * @param instanceName the name of the instance
5837: * @return String - the project name
5838: * @ejb:interface-method view-type="both"
5839: * @ejb:transaction type="Supports"
5840: * @throws HeroException
5841: *
5842: **/
5843: public String getProjectNameOfInstance(String instanceName)
5844: throws HeroException {
5845:
5846: trace.debug("parameters: instanceName=" + instanceName
5847: + " process name = " + this .getName() + " started by "
5848: + this .getCaller());
5849: if (instanceName.matches(".*" + "_instance" + ".*")) {
5850: int i = instanceName.indexOf("_instance");
5851: return (instanceName.substring(0, i));
5852: } else {
5853: throw new HeroException(instanceName
5854: + " is not a project instance...");
5855: }
5856: }
5857:
5858: /**
5859: * Get the parent project of this project
5860: *
5861: * @return String - the parent project of this project
5862: * @ejb:interface-method view-type="both"
5863: * @ejb:transaction type="Supports"
5864: * @throws HeroException
5865: *
5866: **/
5867: public String getParent() throws HeroException {
5868:
5869: trace.debug(" process name = " + this .getName()
5870: + " started by " + this .getCaller());
5871: return (mProject.getParent());
5872: }
5873:
5874: /**
5875: * Test if projects nodes are terminated
5876: *
5877: * @return boolean - the result of the test
5878: * @ejb:interface-method view-type="both"
5879: * @ejb:transaction type="Supports"
5880: * @throws HeroException
5881: *
5882: **/
5883: public boolean isTerminated() {
5884: Collection nodes = mProject.getBnNodes();
5885: Iterator i = nodes.iterator();
5886: while (i.hasNext()) {
5887: BnNodeLocal node = (BnNodeLocal) i.next();
5888: int state = node.getState();
5889: if (state != hero.interfaces.Constants.Nd.TERMINATED
5890: && state != hero.interfaces.Constants.Nd.EXPIRED
5891: && state != hero.interfaces.Constants.Nd.DEAD)
5892: return false;
5893: }
5894: return true;
5895: }
5896:
5897: // -------------------------------------------------------------------------
5898: // Struts business methods
5899: // -------------------------------------------------------------------------
5900:
5901: /**
5902: * Get the StrutsNode. Returns node information with a specific java bean structure (useful in
5903: * struts web applications).
5904: *
5905: * @param nodeName the name of the Node
5906: * @return BnStrutsNodeValue object - node data.
5907: * @ejb:interface-method view-type="both"
5908: * @ejb:transaction type="Supports"
5909: * @throws HeroException
5910: *
5911: **/
5912: public StrutsNodeValue getStrutsNode(String nodeName)
5913: throws HeroException {
5914:
5915: trace.debug("parameter: nodeName=" + nodeName
5916: + " process name = " + this .getName() + " started by "
5917: + this .getCaller());
5918:
5919: BnNodeLocalHome nHome;
5920: BnNodeLocal n;
5921: try {
5922: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
5923: } catch (javax.naming.NamingException be) {
5924:
5925: trace.error(be.getMessage());
5926: throw new HeroException(be.getMessage());
5927: }
5928: try {
5929:
5930: trace.debug("getStrutsNode: nodeName=" + nodeName);
5931: n = nHome.findByName(nodeName, mProject.getId());
5932:
5933: StrutsNodeValue snv = new StrutsNodeValue();
5934: snv.setProjectName(mProject.getName());
5935: snv.setName(n.getName());
5936: snv.setCreator(n.getCreator());
5937: snv.setRole(n.getBnRole().getName());
5938: snv.setState(hero.interfaces.Constants.Nd.nodeStateName[n
5939: .getState()]);
5940: snv.setType(hero.interfaces.Constants.Nd.nodeTypeName[n
5941: .getType()]);
5942: if (n.getDescription() != null)
5943: snv.setDescription(n.getDescription());
5944: if (n.getExecutor() != null)
5945: snv.setExecutor(n.getExecutor());
5946: snv.setAnticipable(n.getAnticipable());
5947: /* Modif MBL
5948: if (n.getDeadline() != null)
5949: snv.setDeadline(n.getDeadline().toString());
5950: */
5951:
5952: if (n.getDeadlines().size() != 0) {
5953: Collection co = n.getDeadlines();
5954: Iterator it = co.iterator();
5955: Date date = null;
5956: while (it.hasNext()) {
5957: date = (Date) it.next();
5958: }
5959: snv.setDeadline(date.toString());
5960: }
5961: return (snv);
5962: } catch (FinderException fe) {
5963:
5964: trace.error("In BnNode does not exist " + fe.getMessage());
5965: throw new HeroException("In BnNode does not exist");
5966: }
5967: }
5968:
5969: /**
5970: * Get the project nodes. Returns project nodes data.
5971: *
5972: * @return Array of StrutsNodeValue - all project nodes
5973: * @ejb:interface-method view-type="both"
5974: * @ejb:transaction type="Supports"
5975: * @throws HeroException
5976: *
5977: **/
5978: public Object[] getNodes() throws HeroException {
5979:
5980: trace.debug(" process name = " + this .getName()
5981: + " started by " + this .getCaller());
5982: //ProjectNodes nb = new ProjectNodes();
5983: ArrayList ns = new ArrayList();
5984: Collection nodes = new ArrayList();
5985:
5986: nodes = mProject.getBnNodes();
5987: Iterator i = nodes.iterator();
5988: while (i.hasNext()) {
5989: BnNodeLocal n = (BnNodeLocal) i.next();
5990: StrutsNodeValue snv = new StrutsNodeValue();
5991: snv.setProjectName(mProject.getName());
5992: snv.setName(n.getName());
5993: snv.setCreator(n.getCreator());
5994: snv.setRole(n.getBnRole().getName());
5995: snv.setState(Constants.Nd.nodeStateName[n.getState()]);
5996: snv.setType(Constants.Nd.nodeTypeName[n.getType()]);
5997: if (n.getDescription() != null)
5998: snv.setDescription(n.getDescription());
5999: if (n.getExecutor() != null)
6000: snv.setExecutor(n.getExecutor());
6001: snv.setAnticipable(n.getAnticipable());
6002: /* Modif MBL
6003: if (n.getDeadline() != null)
6004: snv.setDeadline(n.getDeadline().toString());
6005: */
6006: if (n.getDeadlines().size() != 0) {
6007: Collection co = n.getDeadlines();
6008: Iterator it = co.iterator();
6009: Date date = null;
6010: while (it.hasNext()) {
6011: date = (Date) it.next();
6012: }
6013: snv.setDeadline(date.toString());
6014: }
6015:
6016: ns.add(snv);
6017: }
6018: return (ns.toArray());
6019: }
6020:
6021: /**
6022: * Get the StrutsNodes. Returns nodes information with a specific java bean structure (useful in
6023: * struts web applications).
6024: *
6025: * @return Collection of StrutsNodeValue - all project nodes
6026: * @ejb:interface-method view-type="both"
6027: * @ejb:transaction type="Supports"
6028: * @throws HeroException
6029: *
6030: **/
6031: public Collection getStrutsNodes() throws HeroException {
6032:
6033: trace.debug(" process name = " + this .getName()
6034: + " started by " + this .getCaller());
6035:
6036: //ctor strutsNodes = new Vector();
6037: ArrayList strutsNodes = new ArrayList();
6038: Collection nodes = mProject.getBnNodes();
6039: Iterator i = nodes.iterator();
6040: while (i.hasNext()) {
6041: BnNodeLocal n = (BnNodeLocal) i.next();
6042: StrutsNodeValue snv = new StrutsNodeValue();
6043: snv.setName(n.getName());
6044: snv.setCreator(n.getCreator());
6045: snv.setRole(n.getBnRole().getName());
6046: snv.setState(hero.interfaces.Constants.Nd.nodeStateName[n
6047: .getState()]);
6048: snv.setType(hero.interfaces.Constants.Nd.nodeTypeName[n
6049: .getType()]);
6050: snv.setDescription(n.getDescription());
6051: if (n.getExecutor() != null)
6052: snv.setExecutor(n.getExecutor());
6053: snv.setAnticipable(n.getAnticipable());
6054: /* modif MBL
6055: if (n.getDeadline() != null)
6056: snv.setDeadline(n.getDeadline().toString());
6057: */
6058: if (n.getDeadlines().size() != 0) {
6059: Collection co = n.getDeadlines();
6060: Iterator it = co.iterator();
6061: Date date = null;
6062: while (it.hasNext()) {
6063: date = (Date) it.next();
6064: }
6065: snv.setDeadline(date.toString());
6066: }
6067: strutsNodes.add(snv);
6068: }
6069: return ((Collection) strutsNodes);
6070: }
6071:
6072: /**
6073: * Get the Edges of the Node. Returns node edges information with a specific java bean structure (useful in
6074: * struts web applications).
6075: *
6076: * @param nodeName the name of the Node
6077: * @return Collection of StrutsEdgeValue - all node edges
6078: * @ejb:interface-method view-type="both"
6079: * @ejb:transaction type="Supports"
6080: * @throws HeroException
6081: *
6082: **/
6083: public Collection getStrutsNodeEdges(String nodeName)
6084: throws HeroException {
6085:
6086: trace.debug("parameter: nodeName=" + nodeName
6087: + " process name = " + this .getName() + " started by "
6088: + this .getCaller());
6089:
6090: BnNodeLocalHome nHome;
6091: BnNodeLocal mNode;
6092: BnNodeValue nv;
6093:
6094: // Vector edges = new Vector();
6095: ArrayList edges = new ArrayList();
6096:
6097: try {
6098: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
6099: } catch (javax.naming.NamingException be) {
6100:
6101: trace.error(be.getMessage());
6102: throw new HeroException(be.getMessage());
6103: }
6104: try {
6105: mNode = nHome.findByName(nodeName, mProject.getId());
6106: } catch (FinderException fe) {
6107:
6108: trace.error("In Node does not exist " + fe.getMessage());
6109: throw new HeroException("In Node does not exist");
6110: }
6111: Collection in = mNode.getInBnEdges();
6112: Collection out = mNode.getOutBnEdges();
6113:
6114: Iterator iin = in.iterator();
6115: while (iin.hasNext()) {
6116: StrutsEdgeValue sev = new StrutsEdgeValue();
6117: hero.interfaces.BnEdgeLocal actualEdge = (hero.interfaces.BnEdgeLocal) iin
6118: .next();
6119: sev
6120: .setState(hero.interfaces.Constants.Ed.edgeStateName[actualEdge
6121: .getState()]);
6122: sev.setInNode(((BnNodeLocal) actualEdge.getInBnNode())
6123: .getName());
6124: sev.setOutNode(((BnNodeLocal) actualEdge.getOutBnNode())
6125: .getName());
6126: edges.add(sev);
6127: }
6128:
6129: Iterator iout = out.iterator();
6130: while (iout.hasNext()) {
6131: StrutsEdgeValue sev = new StrutsEdgeValue();
6132: BnEdgeLocal actualEdge = (BnEdgeLocal) iout.next();
6133: sev
6134: .setState(hero.interfaces.Constants.Ed.edgeStateName[actualEdge
6135: .getState()]);
6136: sev.setInNode(((BnNodeLocal) actualEdge.getInBnNode())
6137: .getName());
6138: sev.setOutNode(((BnNodeLocal) actualEdge.getOutBnNode())
6139: .getName());
6140: edges.add(sev);
6141: }
6142: return ((Collection) edges);
6143: }
6144:
6145: /**
6146: * Get the StrutsEdges. Returns project edges information with a specific java bean structure (useful in
6147: * struts web applications).
6148: *
6149: * @return Collection of StrutsEdgeValue - all project edges
6150: * @ejb:interface-method view-type="both"
6151: * @ejb:transaction type="Supports"
6152: * @throws HeroException
6153: *
6154: **/
6155: public Collection getStrutsEdges() throws HeroException {
6156:
6157: trace.debug(" process name = " + this .getName()
6158: + " started by " + this .getCaller());
6159:
6160: // Vector strutsEdges = new Vector();
6161: ArrayList strutsEdges = new ArrayList();
6162: Collection edges = mProject.getBnEdges();
6163: Iterator i = edges.iterator();
6164: while (i.hasNext()) {
6165: BnEdgeLocal e = (BnEdgeLocal) i.next();
6166: StrutsEdgeValue sev = new StrutsEdgeValue();
6167: sev.setName(e.getName());
6168: sev.setState(hero.interfaces.Constants.Ed.edgeStateName[e
6169: .getState()]);
6170: sev.setInNode(e.getInBnNode().getName());
6171: sev.setOutNode(e.getOutBnNode().getName());
6172: strutsEdges.add(sev);
6173: }
6174: return ((Collection) strutsEdges);
6175: }
6176:
6177: /**
6178: * Import all the nodes, hooks and edges of a project to the current project
6179: *
6180: * @param projectname the name of the project
6181: * @ejb:interface-method view-type="both"
6182: * @ejb:transaction type="Required"
6183: * @throws HeroException
6184: *
6185: **/
6186: public void importProject(String projectName, String projectVersion)
6187: throws HeroException {
6188:
6189: trace.debug("parameter: project=" + projectName
6190: + " process name = " + this .getName() + " started by "
6191: + this .getCaller());
6192: importProject(projectName, projectVersion, "");
6193: }
6194:
6195: // -------------------------------------------------------------------------
6196: // ejbCreate and initProject business methods
6197: // -------------------------------------------------------------------------
6198:
6199: /**
6200: * Import all the nodes, hooks, properties and edges of a project to the current project
6201: *
6202: * @param projectname the name of the project
6203: * @param prefix the prefix of names for the project
6204: * @ejb:interface-method view-type="both"
6205: * @ejb:transaction type="Required"
6206: * @throws HeroException
6207: *
6208: **/
6209: public void importProject(String projectName,
6210: String projectVersion, String prefix) throws HeroException {
6211:
6212: trace.debug("parameters: project=" + projectName + " prefix="
6213: + prefix + " process name = " + this .getName()
6214: + " started by " + this .getCaller());
6215: try {
6216: BnProjectLocalHome opHome = hero.interfaces.BnProjectUtil
6217: .getLocalHome();
6218: //MBL changed
6219: BnProjectLocal oldProject = opHome.findByNameVersion(
6220: projectName, projectVersion);
6221: String actualProject = this .getName();
6222: //MBL changed
6223: String actualProjectVersion = this .getVersion();
6224: BnProjectValue pv = oldProject.getBnProjectValue();
6225:
6226: mProject.setType(oldProject.getType());
6227: mProject.setStatus(Constants.Pj.ACTIVE);
6228:
6229: // Project Properties (default value)
6230: Collection props = oldProject.getBnProperties();
6231: for (Iterator i = props.iterator(); i.hasNext();) {
6232: BnProjectPropertyLocal prop = (BnProjectPropertyLocal) i
6233: .next();
6234: this .setPropertyPossibleValues(prop.getTheKey(), prop
6235: .getPossibleValues());
6236: if (prop.getTheValue() != null
6237: || prop.getPossibleValues() == null
6238: || prop.getPossibleValues().size() == 0)
6239: this .setProperty(prop.getTheKey(), prop
6240: .getTheValue());
6241: }
6242:
6243: //Project InterHooks
6244: Collection hooks = oldProject.getBnInterHooks();
6245: for (Iterator i = hooks.iterator(); i.hasNext();) {
6246: BnProjectInterHookLocal hk = (BnProjectInterHookLocal) i
6247: .next();
6248: this .addInterHook(hk.getName(), hk.getEvent(), hk
6249: .getType(), hk.getScript());
6250: }
6251:
6252: //Project Hooks
6253: Collection pHooks = oldProject.getBnHooks();
6254: for (Iterator i = pHooks.iterator(); i.hasNext();) {
6255: BnProjectHookLocal hk = (BnProjectHookLocal) i.next();
6256: this .addHook(hk.getName(), hk.getEvent(), hk.getType());
6257: }
6258:
6259: // Add role and roleMappers
6260: Collection roles = oldProject.getBnRoles();
6261: for (Iterator i = roles.iterator(); i.hasNext();) {
6262: BnRoleLocal ro = (BnRoleLocal) i.next();
6263: String roleName = ro.getName();
6264: // add mapper for the instance
6265: if (!containsRole(roleName))
6266: this .addRole(roleName, ro.getDescription());
6267: if (ro.getBnRoleMapper() != null)
6268: this .addRoleMapper(ro.getName(), ro
6269: .getBnRoleMapper().getName(), ro
6270: .getBnRoleMapper().getType());
6271: }
6272:
6273: // Add the InitiatorMapper
6274: if (oldProject.getBnInitiatorMapper() != null)
6275: this .addInitiatorMapper(oldProject
6276: .getBnInitiatorMapper().getName(), oldProject
6277: .getBnInitiatorMapper().getType());
6278:
6279: // Copy not connected nodes
6280: Collection allNodes = oldProject.getBnNodes();
6281: Iterator no = allNodes.iterator();
6282: while (no.hasNext()) {
6283: BnNodeLocal node = (BnNodeLocal) no.next();
6284: if (node.getInBnEdges().isEmpty()
6285: && node.getOutBnEdges().isEmpty()) {
6286: // New Instance if activity is a subProcess
6287: String newNodeName = node.getName();
6288: String instName = null;
6289: if (node.getType() == Constants.Nd.SUB_PROCESS_NODE) // First activity is a subProcess
6290: this .addNodeSubProcess(newNodeName,
6291: BonitaParsing.getSubProcessName(node
6292: .getReference()), BonitaParsing
6293: .getSubProcessVersion(node
6294: .getReference()));
6295: else
6296: this .addNode(newNodeName, node.getType());
6297:
6298: //this.addNode(newNodeName, node.getType());
6299: if (!node.getAnticipable())
6300: this .setNodeTraditional(newNodeName);
6301:
6302: // For deadlines
6303: if (node.getDeadlines().size() != 0) {
6304: Collection co = node.getDeadlines();
6305: Iterator it = co.iterator();
6306: ArrayList ar = new ArrayList();
6307: while (it.hasNext()) {
6308: Date date = (Date) it.next();
6309: ar.add(new Long(date.getTime()));
6310: }
6311: this .setNodeDeadlines(newNodeName, ar);
6312: }
6313: // For relative deadlines
6314: if (node.getRelativeDeadlines().size() != 0) {
6315: Collection co = node.getRelativeDeadlines();
6316: Iterator it = co.iterator();
6317: ArrayList ar = new ArrayList();
6318: while (it.hasNext()) {
6319: Date date = (Date) it.next();
6320: ar.add(new Long(date.getTime()));
6321: }
6322: this .setNodeRelativeDeadlines(newNodeName, ar);
6323: }
6324: this .setNodeRole(newNodeName, node.getBnRole()
6325: .getName());
6326: this .setNodeDescription(newNodeName, node
6327: .getDescription());
6328:
6329: if (node.getBnNodePerformerAssign() != null) {
6330: this .addNodePerformerAssign(newNodeName, node
6331: .getBnNodePerformerAssign().getName(),
6332: node.getBnNodePerformerAssign()
6333: .getType(), node
6334: .getBnNodePerformerAssign()
6335: .getPropertyName());
6336: }
6337:
6338: //Node InterHooks
6339: Collection nodeHooks = node.getBnInterHooks();
6340: for (Iterator j = nodeHooks.iterator(); j.hasNext();) {
6341: BnNodeInterHookLocal nh = (BnNodeInterHookLocal) j
6342: .next();
6343: try {
6344: this .addNodeInterHook(newNodeName, nh
6345: .getName(), nh.getEvent(), nh
6346: .getType(), nh.getScript());
6347: } catch (Exception ih) {
6348:
6349: trace.error(ih.getMessage());
6350: }
6351: ; // For subProcess Instance consistency
6352: }
6353:
6354: // Node Properties
6355: Collection nodeprops = node.getBnProperties();
6356: for (Iterator i = nodeprops.iterator(); i.hasNext();) {
6357: BnNodePropertyLocal prop = (BnNodePropertyLocal) i
6358: .next();
6359: this .setNodePropertyPossibleValues(newNodeName,
6360: prop.getTheKey(), prop
6361: .getPossibleValues());
6362: if (prop.getTheValue() != null
6363: || prop.getPossibleValues() == null
6364: || prop.getPossibleValues().size() == 0)
6365: this .setNodeProperty(newNodeName, prop
6366: .getTheKey(), prop.getTheValue(),
6367: false);
6368: }
6369:
6370: //Node Hooks
6371: Collection nHooks = node.getBnHooks();
6372: for (Iterator j = nHooks.iterator(); j.hasNext();) {
6373: BnNodeHookLocal nh = (BnNodeHookLocal) j.next();
6374: try {
6375: this .addNodeHook(newNodeName, nh.getName(),
6376: nh.getEvent(), nh.getType());
6377: } catch (Exception ih) {
6378: }
6379: ; // For subProcess Instance consistency
6380: }
6381: }
6382: }
6383:
6384: Collection edges = oldProject.getBnEdges();
6385: Iterator e = edges.iterator();
6386: while (e.hasNext()) {
6387: BnEdgeLocal ed = (BnEdgeLocal) e.next();
6388: BnNodeLocal nodeIn = ed.getInBnNode();
6389: BnNodeLocal nodeOut = ed.getOutBnNode();
6390: BnNodeLocal[] nodes = { nodeIn, nodeOut };
6391: String newNodeNameIn = null;
6392: String newNodeNameOut = null;
6393: for (int n = 0; n < nodes.length; n++) {
6394: String newNodeName = nodes[n].getName();
6395: try {
6396: if (nodes[n].getType() == Constants.Nd.SUB_PROCESS_NODE) // First activity is a subProcess
6397: this
6398: .addNodeSubProcess(
6399: newNodeName,
6400: BonitaParsing
6401: .getSubProcessName(nodes[n]
6402: .getReference()),
6403: BonitaParsing
6404: .getSubProcessVersion(nodes[n]
6405: .getReference()));
6406: else
6407: this .addNode(newNodeName, nodes[n]
6408: .getType());
6409: if (!nodes[n].getAnticipable())
6410: this .setNodeTraditional(newNodeName);
6411:
6412: // For deadlines
6413: if (nodes[n].getDeadlines().size() != 0) {
6414: Collection co = nodes[n].getDeadlines();
6415: Iterator it = co.iterator();
6416: ArrayList ar = new ArrayList();
6417: while (it.hasNext()) {
6418: Date date = (Date) it.next();
6419: ar.add(new Long(date.getTime()));
6420: }
6421: this .setNodeDeadlines(newNodeName, ar);
6422: }
6423: // For relative deadlines
6424: if (nodes[n].getRelativeDeadlines().size() != 0) {
6425: Collection co = nodes[n]
6426: .getRelativeDeadlines();
6427: Iterator it = co.iterator();
6428: ArrayList ar = new ArrayList();
6429: while (it.hasNext()) {
6430: Date date = (Date) it.next();
6431: ar.add(new Long(date.getTime()));
6432: }
6433: this .setNodeRelativeDeadlines(newNodeName,
6434: ar);
6435: }
6436: this .setNodeRole(newNodeName, nodes[n]
6437: .getBnRole().getName());
6438: this .setNodeDescription(newNodeName, nodes[n]
6439: .getDescription());
6440:
6441: if (nodes[n].getBnNodePerformerAssign() != null) {
6442: this .addNodePerformerAssign(newNodeName,
6443: nodes[n].getBnNodePerformerAssign()
6444: .getName(), nodes[n]
6445: .getBnNodePerformerAssign()
6446: .getType(), nodes[n]
6447: .getBnNodePerformerAssign()
6448: .getPropertyName());
6449: }
6450:
6451: //Node InterHooks
6452: BnNodeLocal nd = oldProject.getBnNode(nodes[n]
6453: .getName());
6454: Collection nodeHooks = nd.getBnInterHooks();
6455: for (Iterator j = nodeHooks.iterator(); j
6456: .hasNext();) {
6457: BnNodeInterHookLocal nh = (BnNodeInterHookLocal) j
6458: .next();
6459: try {
6460: this .addNodeInterHook(newNodeName, nh
6461: .getName(), nh.getEvent(), nh
6462: .getType(), nh.getScript());
6463: } catch (Exception ih) {
6464:
6465: trace.error(ih.getMessage());
6466: }
6467: ; // For subProcess Instance consistency
6468: }
6469:
6470: // Node Properties
6471: Collection nodeprops = nodes[n]
6472: .getBnProperties();
6473: for (Iterator i = nodeprops.iterator(); i
6474: .hasNext();) {
6475: BnNodePropertyLocal prop = (BnNodePropertyLocal) i
6476: .next();
6477: this .setNodePropertyPossibleValues(
6478: newNodeName, prop.getTheKey(), prop
6479: .getPossibleValues());
6480: if (prop.getTheValue() != null
6481: || prop.getPossibleValues() == null
6482: || prop.getPossibleValues().size() == 0)
6483: this .setNodeProperty(newNodeName, prop
6484: .getTheKey(), prop
6485: .getTheValue(), false);
6486: }
6487:
6488: //Node Hooks
6489: Collection nHooks = nd.getBnHooks();
6490: for (Iterator j = nHooks.iterator(); j
6491: .hasNext();) {
6492: BnNodeHookLocal nh = (BnNodeHookLocal) j
6493: .next();
6494: try {
6495: this .addNodeHook(newNodeName, nh
6496: .getName(), nh.getEvent(), nh
6497: .getType());
6498: } catch (Exception ih) {
6499: }
6500: ; // For subProcess Instance consistency
6501: }
6502:
6503: } catch (Exception an) {
6504:
6505: trace.error(an.getMessage());
6506: }
6507: ; // Node already exist
6508: if (n == 0)
6509: newNodeNameIn = newNodeName;
6510: else
6511: newNodeNameOut = newNodeName;
6512: }
6513:
6514: String edgeName = this .addEdge(newNodeNameIn,
6515: newNodeNameOut);
6516: this .setEdgeCondition(edgeName, ed.getCondition());
6517: }
6518:
6519: // Project Iterations
6520: Collection ites = oldProject.getBnIterations();
6521: Iterator iterations = ites.iterator();
6522: while (iterations.hasNext()) {
6523: BnIterationLocal ite = (BnIterationLocal) iterations
6524: .next();
6525: this .addIteration(ite.getFromNode(), ite.getToNode(),
6526: ite.getCondition());
6527: }
6528:
6529: // Users and roles
6530:
6531: BnUserLightValue[] users = pv.getBnUsers();
6532: int uIndex = 0;
6533: for (uIndex = 0; uIndex < users.length; uIndex++) {
6534: BnUserLightValue userP = users[uIndex];
6535: try {
6536: this .addUser(userP.getName());
6537: } catch (Exception eUser) {
6538:
6539: trace.error(eUser.getMessage());
6540: if (jms != null)
6541: jms.sendProjectEvent(ADDUSERPROJECT, mProject
6542: .getName(), userP.getName());
6543: }
6544: mProject = oldProject;
6545: Collection userRoles = this
6546: .getUserRolesInProjectNames(userP.getName());
6547: mProject = opHome.findByNameVersion(actualProject,
6548: actualProjectVersion);
6549: Iterator ir = userRoles.iterator();
6550: while (ir.hasNext())
6551: this .setUserRole(userP.getName(), (String) ir
6552: .next());
6553: }
6554:
6555: } catch (FinderException e) {
6556:
6557: trace.error("Cannot find project " + e.getMessage());
6558: throw new HeroException("Cannot find project "
6559: + e.getMessage());
6560: } catch (javax.naming.NamingException ne) {
6561:
6562: trace.error(ne.getMessage());
6563: throw new HeroException(ne.getMessage());
6564: }
6565: }
6566:
6567: /**
6568: * Import Project instance. Import all the nodes, hooks, properties,edges and users of a project instant to the
6569: * current project
6570: *
6571: * @param projectname the name of the project
6572: * @param instance the instance name of the project
6573: * @ejb:interface-method view-type="both"
6574: * @ejb:transaction type="Required"
6575: * @throws HeroException
6576: *
6577: **/
6578: public String importInstance(BonitaProjectValue pv,
6579: String instance, String version, Hashtable initProperties)
6580: throws HeroException {
6581: BnUserLocalHome uhome = null;
6582: BnRoleLocalHome rhome = null;
6583: BnProjectLocalHome opHome = null;
6584: UserServiceLocalHome ushome;
6585: //for deadline based on EJB timers
6586: DeadlineEjbTimerSessionLocalHome dlHome;
6587: DeadlineEjbTimerSessionLocal dlSession;
6588: try {
6589: dlHome = DeadlineEjbTimerSessionUtil.getLocalHome();
6590: } catch (javax.naming.NamingException ne) {
6591: throw new HeroException(ne.getMessage());
6592: }
6593: try {
6594: dlSession = dlHome.create();
6595:
6596: } catch (CreateException he) {
6597: throw new HeroException(
6598: "importInstance: Error creating DeadlineEjbTimerSessionLocal");
6599: }
6600:
6601: trace.debug("parameter: project=" + pv.getName()
6602: + " started by " + this .getCaller());
6603: try {
6604: uhome = hero.interfaces.BnUserUtil.getLocalHome();
6605: rhome = hero.interfaces.BnRoleUtil.getLocalHome();
6606: opHome = hero.interfaces.BnProjectUtil.getLocalHome();
6607:
6608: String creator = this .getCaller();
6609: mProject = opHome.create(instance, version, creator);
6610: mProject.setType(Constants.Pj.INSTANCE);
6611: mProject.setStatus(Constants.Pj.ACTIVE);
6612:
6613: instance = mProject.getName();
6614: version = mProject.getVersion();
6615: mProject.setParent(mProject.getName()); // Only for subprocesses
6616:
6617: BnUserLocal user = uhome.findByName(creator);
6618: mProject.getBnUsers().add(user);
6619: // role admin is added
6620: BnRoleValue rv = new BnRoleValue();
6621: rv.setName(hero.interfaces.Constants.ADMIN);
6622: rv.setDescription("the admin role");
6623: BnRoleLocal role = rhome.create(rv);
6624: mProject.getBnRoles().add(role);
6625: // Set User Role
6626: user.getBnRoles().add(role);
6627:
6628: // role InitialRole is added
6629: rv = new BnRoleValue();
6630: rv.setName(hero.interfaces.Constants.INITIALROLE);
6631: rv.setDescription("the initial role for nodes");
6632: role = rhome.create(rv);
6633: mProject.getBnRoles().add(role);
6634:
6635: if (!creator.equals(Constants.ADMIN)) {
6636: // role username is added
6637: rv = new BnRoleValue();
6638: rv.setName(creator);
6639: rv.setDescription(creator + " user role");
6640: role = rhome.create(rv);
6641: mProject.getBnRoles().add(role);
6642: // Set User Role
6643: user.getBnRoles().add(role);
6644: }
6645:
6646: // Project Properties
6647: Collection propers = pv.getProperties();
6648: Iterator props = propers.iterator();
6649: while (props.hasNext()) {
6650: BonitaPropertyValue prop = (BonitaPropertyValue) props
6651: .next();
6652: this .setPropertyPossibleValues(prop.getKey(), prop
6653: .getPossibleValues());
6654: if (prop.getValue() != null
6655: || prop.getPossibleValues() == null
6656: || prop.getPossibleValues().size() == 0)
6657: this .setProperty(prop.getKey(), prop.getValue());
6658:
6659: }
6660:
6661: // Default properties (if needed)
6662: Iterator initProps = initProperties.keySet().iterator();
6663: while (initProps.hasNext()) {
6664: String key = (String) initProps.next();
6665: if (initProperties.get(key) != null)
6666: this .setProperty(key, (String) initProperties
6667: .get(key));
6668:
6669: }
6670:
6671: // Project Roles
6672: Collection roles = pv.getRoles();
6673: Iterator allRoles = roles.iterator();
6674: while (allRoles.hasNext()) {
6675: BonitaRoleValue ro = (BonitaRoleValue) allRoles.next();
6676: String roleName = ro.getName();
6677: // add mapper for the instance
6678: if (!containsRole(roleName))
6679: this .addRole(roleName, ro.getDescription());
6680: if (ro.getMapper() != null)
6681: this .addRoleMapper(ro.getName(), ro.getMapper()
6682: .getName(), ro.getMapper().getType());
6683: }
6684:
6685: // First activity/ies
6686: Collection nds = pv.getNodes();
6687: Iterator nodes = nds.iterator();
6688: while (nodes.hasNext()) {
6689: BonitaNodeValue nd = (BonitaNodeValue) nodes.next();
6690: if (nd.getInEdges().isEmpty()) {
6691: String instName = null;
6692: String newNodeName = nd.getName();
6693: if (nd.getType() == Constants.Nd.SUB_PROCESS_NODE) // First activity is a subProcess
6694: {
6695: String subProcessName = BonitaParsing
6696: .getSubProcessName(nd.getReference());
6697: String subProcessVersion = BonitaParsing
6698: .getSubProcessVersion(nd.getReference());
6699:
6700: instName = this .instantiateProject(
6701: subProcessName, subProcessVersion);
6702: BnProjectLocal newInstance = opHome
6703: .findByName(instName);
6704: newInstance.setParent(instance + "_node-"
6705: + newNodeName);
6706: this .initProject(instance);
6707:
6708: }
6709:
6710: this .addNode(newNodeName, nd.getType());
6711:
6712: if (nd.getType() == Nd.SUB_PROCESS_NODE) {
6713: BnNodeLocal newNode = mProject.getBnNode(nd
6714: .getName());
6715: newNode.setReference(instName);
6716: }
6717:
6718: if (!nd.getAnticipable())
6719: this .setNodeTraditional(newNodeName);
6720:
6721: // For Deadlines
6722: if (nd.getDeadlines().size() != 0) {
6723: Collection co = nd.getDeadlines();
6724: Iterator it = co.iterator();
6725: ArrayList ar = new ArrayList();
6726: while (it.hasNext()) {
6727: Date date = (Date) it.next();
6728: ar.add(new Long(date.getTime()));
6729: }
6730: this .setNodeDeadlines(newNodeName, ar);
6731: }
6732: // For relative Deadlines
6733: if (nd.getRelativeDeadlines().size() != 0) {
6734: Collection co = nd.getRelativeDeadlines();
6735: Iterator it = co.iterator();
6736: ArrayList ar = new ArrayList();
6737: while (it.hasNext()) {
6738: Date date = (Date) it.next();
6739: ar.add(new Long(date.getTime()));
6740: }
6741: this .setNodeRelativeDeadlines(newNodeName, ar);
6742: }
6743: this .setNodeRole(newNodeName, nd.getRole());
6744: this .setNodeDescription(newNodeName, nd
6745: .getDescription());
6746: if (!nd.getProjectParent().equals(
6747: nd.getProjectName()))
6748: this .setNodeState(mProject
6749: .getBnNode(newNodeName),
6750: Constants.Nd.INITIAL);
6751:
6752: Collection nodeProp = nd.getProperties();
6753: Iterator nodeProps = nodeProp.iterator();
6754: while (nodeProps.hasNext()) {
6755: BonitaPropertyValue ndProp = (BonitaPropertyValue) nodeProps
6756: .next();
6757: this .setNodePropertyPossibleValues(newNodeName,
6758: ndProp.getKey(), ndProp
6759: .getPossibleValues());
6760: if (ndProp.getValue() != null
6761: || ndProp.getPossibleValues() == null
6762: || ndProp.getPossibleValues().size() == 0)
6763: this .setNodeProperty(newNodeName, ndProp
6764: .getKey(), ndProp.getValue(),
6765: ndProp.getPropagate());
6766: }
6767:
6768: if (nd.getPerformer() != null) {
6769: this .addNodePerformerAssign(newNodeName, nd
6770: .getPerformer().getName(), nd
6771: .getPerformer().getType(), nd
6772: .getPerformer().getPropertyName());
6773: }
6774:
6775: // For Deadlines or relative deadlines
6776: if (nd.getDeadlines().size() != 0
6777: || nd.getRelativeDeadlines().size() != 0)
6778: dlSession.startDeadlineEjbTimers(newNodeName,
6779: mProject.getId());
6780:
6781: // Project Iterations
6782: Collection iterations = pv.getIterations();
6783: Iterator iter = iterations.iterator();
6784: while (iter.hasNext()) {
6785: BonitaIterationValue iteration = (BonitaIterationValue) iter
6786: .next();
6787: String from = iteration.getFromNode();
6788: if (newNodeName.matches(from + "_instance.*")
6789: || newNodeName.equals(from)) {
6790: this .addIteration(newNodeName, newNodeName,
6791: iteration.getCondition());
6792: break;
6793: }
6794: }
6795: if ((nd.getType() == Constants.Nd.SUB_PROCESS_NODE
6796: || nd.getType() == Constants.Nd.AND_JOIN_AUTOMATIC_NODE || nd
6797: .getType() == Constants.Nd.OR_JOIN_AUTOMATIC_NODE)
6798: && (nd.getProjectParent().equals(nd
6799: .getProjectName()))) {
6800: EngineLocalHome enghome;
6801: try {
6802: enghome = hero.interfaces.EngineUtil
6803: .getLocalHome();
6804: EngineLocal engine = enghome.create();
6805: engine.startActivity(mProject.getName(),
6806: newNodeName);
6807: } catch (javax.naming.NamingException ne) {
6808: throw new HeroException(ne.getMessage());
6809: }
6810: }
6811:
6812: }
6813: }
6814: Collection users = pv.getUsers();
6815: Iterator usersI = users.iterator();
6816: while (usersI.hasNext()) {
6817: BonitaUserValue userP = (BonitaUserValue) usersI.next();
6818: try {
6819: this .addUserLocal(userP.getName());
6820: } catch (Exception eUser) {
6821:
6822: trace.error(eUser.getMessage());
6823: }
6824: Collection userRoles = userP.getRoles();
6825: Iterator ir = userRoles.iterator();
6826: while (ir.hasNext()) {
6827: String roleName = (String) ir.next();
6828: this .setUserRoleLocal(userP.getName(), roleName);
6829: }
6830: }
6831: mProject.setCreationDate(new Date());
6832:
6833: // mapper execution
6834: this .mapRole();
6835:
6836: this .executeOnReadyHook();
6837: if (jms != null)
6838: jms.sendProjectEvent(ADDUSERPROJECT, instance, creator);
6839: return instance;
6840: } catch (javax.naming.NamingException ne) {
6841:
6842: trace.error(ne.getMessage());
6843: throw new HeroException(ne.getMessage());
6844: } catch (Exception ce) {
6845: ce.printStackTrace();
6846:
6847: trace.error("Instantiate process error " + ce.getMessage());
6848: throw new HeroException("Instantiate process error "
6849: + ce.getMessage());
6850: }
6851: }
6852:
6853: /**
6854: * Test if the project with projectName name exists.
6855: *
6856: * @param projectName project name
6857: * @ejb:interface-method view-type="both"
6858: * @ejb:transaction type="Required"
6859: * @throws HeroException
6860: **/
6861: public boolean existingProject(String projectName)
6862: throws HeroException {
6863: UserServiceLocalHome ushome = null;
6864: mProject = null;
6865:
6866: trace.debug("parameter: project=" + projectName
6867: + " started by " + this .getCaller());
6868: if (projectName.equals(""))
6869: throw new HeroException("Project name can not be empty...");
6870: try {
6871: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
6872:
6873: UserServiceLocal ul = ushome.create();
6874: ul.findUserLocal(this .getCaller());
6875: } catch (Exception ce) {
6876:
6877: trace.error(ce.getMessage());
6878: throw new HeroException(ce.getMessage());
6879: }
6880: try {
6881: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
6882: pHome.findByNameVersion(projectName,
6883: EventConstants.DEFAULTPROJECTVERSION);
6884: } catch (javax.naming.NamingException ne) {
6885:
6886: trace.error(ne.getMessage());
6887: throw new HeroException(ne.getMessage());
6888: } catch (javax.ejb.FinderException fe) {
6889: return false;
6890:
6891: }
6892: return true;
6893: }
6894:
6895: /**
6896: * Test if the project with projectName and projectVersion name exists.
6897: *
6898: * @param projectName project name
6899: * @param projectName project name
6900: * @ejb:interface-method view-type="both"
6901: * @ejb:transaction type="Required"
6902: * @throws HeroException
6903: **/
6904: public boolean existingProject(String projectName,
6905: String projectVersion) throws HeroException {
6906: UserServiceLocalHome ushome = null;
6907: mProject = null;
6908:
6909: trace.debug("parameter: project=" + projectName
6910: + " started by " + this .getCaller());
6911: if (projectName.equals(""))
6912: throw new HeroException("Project name can not be empty...");
6913: try {
6914: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
6915:
6916: UserServiceLocal ul = ushome.create();
6917: ul.findUserLocal(this .getCaller());
6918: } catch (Exception ce) {
6919:
6920: trace.error(ce.getMessage());
6921: throw new HeroException(ce.getMessage());
6922: }
6923: try {
6924: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
6925: pHome.findByNameVersion(projectName, projectVersion);
6926: } catch (javax.naming.NamingException ne) {
6927:
6928: trace.error(ne.getMessage());
6929: throw new HeroException(ne.getMessage());
6930: } catch (javax.ejb.FinderException fe) {
6931: return false;
6932:
6933: }
6934: return true;
6935: }
6936:
6937: /**
6938: * Creates a cooperative workflow or creates a pointer to the Project Session Bean for this cooperative/instance
6939: * element. You have to call this method after "create" call. After that
6940: * all methods of ProjectSession API are available.
6941: *
6942: * @param projectName project name
6943: * @ejb:interface-method view-type="both"
6944: * @ejb:transaction type="Required"
6945: * @throws HeroException
6946: **/
6947: public void initProject(String projectName) throws HeroException {
6948: Context lContext;
6949: UserServiceLocalHome ushome = null;
6950: mProject = null;
6951:
6952: trace.debug("parameter: project=" + projectName
6953: + " started by " + this .getCaller());
6954: if (projectName.equals(""))
6955: throw new HeroException("Project name can not be empty...");
6956: try {
6957: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
6958:
6959: UserServiceLocal ul = ushome.create();
6960: ul.findUserLocal(this .getCaller());
6961: } catch (Exception ce) {
6962:
6963: trace.error(ce.getMessage());
6964: throw new HeroException(ce.getMessage());
6965: }
6966: try {
6967: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
6968: //this.mProject = pHome.findByNameVersion(projectName, EventConstants.DEFAULTPROJECTVERSION);
6969: this .mProject = pHome.findByName(projectName);
6970: } catch (javax.naming.NamingException ne) {
6971: trace.error(ne.getMessage());
6972: throw new HeroException(ne.getMessage());
6973: } catch (javax.ejb.FinderException fe) {
6974: try {
6975: // for compatibility set default version
6976: this .createProcess(projectName,
6977: EventConstants.DEFAULTPROJECTVERSION); // Create Process
6978: mProject.setType(Constants.Pj.COOPERATIVE);
6979: mProject.setStatus(Constants.Pj.ACTIVE);
6980: } catch (CreateException ce) {
6981:
6982: trace.error(ce.getMessage());
6983: throw new HeroException(ce.getMessage());
6984: }
6985: }
6986: }
6987:
6988: /**
6989: * Executes the OnInstatiate hook associated to this process. This method can only be called before
6990: * a workflow model is instantiated.
6991: *
6992: * @ejb:interface-method view-type="both"
6993: * @ejb:transaction type="Supports"
6994: * @throws HeroException
6995: **/
6996: public void executeProcessHook() throws HeroException {
6997: if (mProject.getType().equals(Constants.Pj.MODEL)) {
6998: Collection pHooks = mProject.getBnHooks();
6999: Iterator i = pHooks.iterator();
7000: while (i.hasNext()) {
7001: BnProjectHookLocal ph = (BnProjectHookLocal) i.next();
7002: if (ph.getEvent().equalsIgnoreCase(
7003: Constants.Pj.ONINSTANTIATE)) {
7004: hero.hook.ProcessHook h = hero.hook.ProcessHook
7005: .make(ph.getName(), ph.getEvent(), ph
7006: .getType());
7007: h.execute(this , ph.getEvent(), mProject);
7008: }
7009: }
7010: } else {
7011: throw new HeroException(
7012: "This method is not available for workflow instances...");
7013: }
7014: }
7015:
7016: /**
7017: * Executes the OnReady hook associated to the first activities of the process (those ones
7018: * for which there is no ingoing transitions). This method must only be called after
7019: * a workflow model is instantiated.
7020: **/
7021: public void executeOnReadyHook() throws HeroException {
7022:
7023: try {
7024: BnNodeLocalHome nHome = null;
7025: if (mProject.getType().equals(Constants.Pj.INSTANCE)) {
7026: performAssign();
7027: // First activity/ies
7028: // BonitaProjectValue pv = BonitaProjectLocator.getInstance().getModelValue(this.getModel(this.getName()), this.getModel(this.getVersion()) );
7029: BonitaProjectValue pv = BonitaProjectLocator
7030: .getInstance().getModelValue(
7031: this .getModel(this .getName()),
7032: this .getVersion());
7033:
7034: Collection nds = pv.getNodes();
7035: Iterator nodes = nds.iterator();
7036: while (nodes.hasNext()) {
7037: BonitaNodeValue nd = (BonitaNodeValue) nodes.next();
7038: if (nd.getInEdges().isEmpty()) {
7039: Collection hks = nd.getHooks();
7040: Iterator i = hks.iterator();
7041: while (i.hasNext()) {
7042: BonitaHookValue bh = (BonitaHookValue) i
7043: .next();
7044: if (bh.getEvent().equalsIgnoreCase(
7045: Constants.Nd.ONREADY)) {
7046: hero.hook.Hook h = hero.hook.Hook.make(
7047: bh.getName(), bh.getEvent(), bh
7048: .getType());
7049: try {
7050: nHome = hero.interfaces.BnNodeUtil
7051: .getLocalHome();
7052: } catch (javax.naming.NamingException be) {
7053: trace.error(be.getMessage());
7054: throw new HeroException(be
7055: .getMessage());
7056: }
7057: try {
7058: BnNodeLocal nf = nHome.findByName(
7059: nd.getName(), mProject
7060: .getId());
7061: h.execute(this , bh.getEvent(), nf);
7062: } catch (javax.ejb.FinderException nn) {
7063: throw new HeroException(
7064: "This node does not exist...");
7065: }
7066: }
7067: }
7068: }
7069: }
7070: } else
7071: throw new HeroException(
7072: "This method is not available for workflow models...");
7073: } catch (Exception e) {
7074: e.printStackTrace();
7075: throw new HeroException(e.getMessage());
7076: }
7077: }
7078:
7079: /**
7080: * Creates a workflow process model or Init the Project Session Bean for this model. You have to call this method after "create" call. After that
7081: * all methods of ProjectSession API are available.
7082: *
7083: * @param modelName model name
7084: * @ejb:interface-method view-type="both"
7085: * @ejb:transaction type="Required"
7086: * @throws HeroException
7087: **/
7088: public void initModel(String modelName) throws HeroException {
7089: Context lContext;
7090: UserServiceLocalHome ushome = null;
7091: mProject = null;
7092:
7093: trace.debug("parameter: project=" + modelName + " started by "
7094: + this .getCaller());
7095: if (modelName.equals(""))
7096: throw new HeroException("Project name can not be empty...");
7097: try {
7098: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
7099: UserServiceLocal ul = ushome.create();
7100: ul.findUserLocal(this .getCaller());
7101: } catch (Exception ce) {
7102:
7103: trace.error(ce.getMessage());
7104: throw new HeroException(ce.getMessage());
7105: }
7106: try {
7107: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7108: this .mProject = pHome.findByNameVersion(modelName,
7109: EventConstants.DEFAULTPROJECTVERSION);
7110:
7111: } catch (javax.naming.NamingException ne) {
7112: trace.error(ne.getMessage());
7113: throw new HeroException(ne.getMessage());
7114: } catch (javax.ejb.FinderException fe) {
7115: try {
7116: this .createProcess(modelName,
7117: EventConstants.DEFAULTPROJECTVERSION); // Create Process
7118: mProject.setType(Constants.Pj.MODEL);
7119: mProject.setStatus(Constants.Pj.ACTIVE);
7120: } catch (CreateException ce) {
7121:
7122: trace.error(ce.getMessage());
7123: throw new HeroException(ce.getMessage());
7124: }
7125: }
7126: }
7127:
7128: /**
7129: * Creates a workflow process model or Init the Project Session Bean for this model. You have to call this method after "create" call. After that
7130: * all methods of ProjectSession API are available.
7131: *
7132: * @param modelName model name
7133: * @param modelVersion model version
7134: * @ejb:interface-method view-type="both"
7135: * @ejb:transaction type="Required"
7136: * @throws HeroException
7137: **/
7138: public void initModelWithVersion(String modelName,
7139: String modelVersion) throws HeroException {
7140: Context lContext;
7141: UserServiceLocalHome ushome = null;
7142: mProject = null;
7143:
7144: trace.debug("parameter: project=" + modelName + " started by "
7145: + this .getCaller());
7146: if (modelName.equals(""))
7147: throw new HeroException("Project name can not be empty...");
7148: try {
7149: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
7150: UserServiceLocal ul = ushome.create();
7151: ul.findUserLocal(this .getCaller());
7152: } catch (Exception ce) {
7153:
7154: trace.error(ce.getMessage());
7155: throw new HeroException(ce.getMessage());
7156: }
7157: try {
7158: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7159: this .mProject = pHome.findByNameVersion(modelName,
7160: modelVersion);
7161:
7162: } catch (javax.naming.NamingException ne) {
7163: trace.error(ne.getMessage());
7164: throw new HeroException(ne.getMessage());
7165: } catch (javax.ejb.FinderException fe) {
7166: try {
7167: this .createProcess(modelName, modelVersion); // Create Process
7168: mProject.setType(Constants.Pj.MODEL);
7169: mProject.setStatus(Constants.Pj.ACTIVE);
7170: } catch (CreateException ce) {
7171:
7172: trace.error(ce.getMessage());
7173: throw new HeroException(ce.getMessage());
7174: }
7175: }
7176: }
7177:
7178: /**
7179: * init the Project Session Bean (clone project).You have to call this method after "create" call. After that
7180: * the project is cloned and all methods of ProjectSession API are available.
7181: *
7182: * @throws HeroException
7183: * @param oldProject the name of the project to clone
7184: * @param newProject the name of the project clone.
7185: * @ejb:interface-method view-type="both"
7186: * @ejb:transaction type="Required"
7187: * @throws CreateException
7188: **/
7189: public void initProject(String oldProject, String newProject)
7190: throws CreateException {
7191: try {
7192:
7193: trace.debug("parameters: oldProject=" + oldProject
7194: + " newProject=" + newProject + " started by "
7195: + this .getCaller());
7196: Context lContext;
7197: BnUserLocalHome uhome = null;
7198: BnRoleLocalHome rhome = null;
7199: UserServiceLocalHome ushome;
7200: try {
7201: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
7202: UserServiceLocal ul = ushome.create();
7203: ul.findUserLocal(this .getCaller());
7204: } catch (Exception ce) {
7205:
7206: trace.error(ce.getMessage());
7207: throw new HeroException(ce.getMessage());
7208: }
7209: if (oldProject.equals("") || newProject.equals(""))
7210: throw new CreateException(
7211: "Project name can not be empty...");
7212: try {
7213: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7214: uhome = hero.interfaces.BnUserUtil.getLocalHome();
7215: rhome = hero.interfaces.BnRoleUtil.getLocalHome();
7216: mProject = pHome.findByNameVersion(newProject,
7217: EventConstants.DEFAULTPROJECTVERSION);
7218: } catch (javax.naming.NamingException ne) {
7219:
7220: trace.error(ne.getMessage());
7221: throw new CreateException(ne.getMessage());
7222: } catch (javax.ejb.FinderException fe) {
7223: // The project has to be created
7224: try {
7225: String creator = this .getCaller();
7226: mProject = pHome.create(newProject,
7227: EventConstants.DEFAULTPROJECTVERSION,
7228: creator);
7229: mProject.setParent(newProject);
7230: BonitaProjectValue pv = new BonitaProjectValue();
7231: pv.setName(newProject);
7232:
7233: BnUserLocal user = uhome.findByName(creator);
7234: mProject.getBnUsers().add(user);
7235:
7236: // role admin is added
7237: BnRoleValue rv = new BnRoleValue();
7238: rv.setName(hero.interfaces.Constants.ADMIN);
7239: rv.setDescription("the admin role");
7240: BnRoleLocal role = rhome.create(rv);
7241: mProject.getBnRoles().add(role);
7242: // Set User Role
7243: user.getBnRoles().add(role);
7244:
7245: // role InitialRole is added
7246: rv = new BnRoleValue();
7247: rv.setName(hero.interfaces.Constants.INITIALROLE);
7248: rv.setDescription("the initial role for nodes");
7249: role = rhome.create(rv);
7250: mProject.getBnRoles().add(role);
7251:
7252: if (!creator.equals(Constants.ADMIN)) {
7253: // role username is added
7254: rv = new BnRoleValue();
7255: rv.setName(creator);
7256: rv.setDescription(creator + " user role");
7257: role = rhome.create(rv);
7258: mProject.getBnRoles().add(role);
7259: // Set User Role
7260: user.getBnRoles().add(role);
7261: }
7262:
7263: importProject(oldProject,
7264: EventConstants.DEFAULTPROJECTVERSION);
7265: mProject.setCreationDate(new Date());
7266:
7267: if (jms != null)
7268: jms.sendProjectEvent(ADDUSERPROJECT,
7269: newProject, creator);
7270:
7271: } catch (FinderException fie) {
7272:
7273: trace.error(fie.getMessage());
7274: throw new CreateException(fie.getMessage());
7275: } catch (InvalidValueException ie) {
7276:
7277: trace.error(ie.getMessage());
7278: throw new CreateException(ie.getMessage());
7279: } catch (HeroException he) {
7280:
7281: trace.error(he.getMessage());
7282: throw new CreateException(he.getMessage());
7283: }
7284: }
7285: } catch (HeroException traceEx) {
7286: traceEx.printStackTrace();
7287: }
7288: }
7289:
7290: /**
7291: * init the Project Session Bean (clone project).You have to call this method after "create" call. After that
7292: * the project is cloned and all methods of ProjectSession API are available.
7293: *
7294: * @throws HeroException
7295: * @param oldProject the name of the project to clone
7296: * @param oldVersion the version of the project to clone
7297: * @param newProject the name of the project clone.
7298: * @ejb:interface-method view-type="both"
7299: * @ejb:transaction type="Required"
7300: * @throws CreateException
7301: **/
7302: public void initProjectWithVersion(String oldProject,
7303: String oldVersion, String newProject)
7304: throws CreateException {
7305: try {
7306:
7307: trace.debug("parameters: oldProject=" + oldProject
7308: + " newProject=" + newProject + " started by "
7309: + this .getCaller());
7310: Context lContext;
7311: BnUserLocalHome uhome = null;
7312: BnRoleLocalHome rhome = null;
7313: UserServiceLocalHome ushome;
7314: try {
7315: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
7316: UserServiceLocal ul = ushome.create();
7317: ul.findUserLocal(this .getCaller());
7318: } catch (Exception ce) {
7319:
7320: trace.error(ce.getMessage());
7321: throw new HeroException(ce.getMessage());
7322: }
7323: if (oldProject.equals("") || newProject.equals(""))
7324: throw new CreateException(
7325: "Project name can not be empty...");
7326: try {
7327: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7328: uhome = hero.interfaces.BnUserUtil.getLocalHome();
7329: rhome = hero.interfaces.BnRoleUtil.getLocalHome();
7330: mProject = pHome.findByNameVersion(newProject,
7331: oldVersion);
7332: } catch (javax.naming.NamingException ne) {
7333:
7334: trace.error(ne.getMessage());
7335: throw new CreateException(ne.getMessage());
7336: } catch (javax.ejb.FinderException fe) {
7337: // The project has to be created
7338: try {
7339: String creator = this .getCaller();
7340: mProject = pHome.create(newProject, oldVersion,
7341: creator);
7342: mProject.setParent(newProject);
7343: BonitaProjectValue pv = new BonitaProjectValue();
7344: pv.setName(newProject);
7345:
7346: BnUserLocal user = uhome.findByName(creator);
7347: mProject.getBnUsers().add(user);
7348:
7349: // role admin is added
7350: BnRoleValue rv = new BnRoleValue();
7351: rv.setName(hero.interfaces.Constants.ADMIN);
7352: rv.setDescription("the admin role");
7353: BnRoleLocal role = rhome.create(rv);
7354: mProject.getBnRoles().add(role);
7355: // Set User Role
7356: user.getBnRoles().add(role);
7357:
7358: // role InitialRole is added
7359: rv = new BnRoleValue();
7360: rv.setName(hero.interfaces.Constants.INITIALROLE);
7361: rv.setDescription("the initial role for nodes");
7362: role = rhome.create(rv);
7363: mProject.getBnRoles().add(role);
7364:
7365: if (!creator.equals(Constants.ADMIN)) {
7366: // role username is added
7367: rv = new BnRoleValue();
7368: rv.setName(creator);
7369: rv.setDescription(creator + " user role");
7370: role = rhome.create(rv);
7371: mProject.getBnRoles().add(role);
7372: // Set User Role
7373: user.getBnRoles().add(role);
7374: }
7375:
7376: //importProject(oldProject);
7377: importProject(oldProject, oldVersion);
7378: mProject.setCreationDate(new Date());
7379:
7380: if (jms != null)
7381: jms.sendProjectEvent(ADDUSERPROJECT,
7382: newProject, creator);
7383:
7384: } catch (FinderException fie) {
7385:
7386: trace.error(fie.getMessage());
7387: throw new CreateException(fie.getMessage());
7388: } catch (InvalidValueException ie) {
7389:
7390: trace.error(ie.getMessage());
7391: throw new CreateException(ie.getMessage());
7392: } catch (HeroException he) {
7393:
7394: trace.error(he.getMessage());
7395: throw new CreateException(he.getMessage());
7396: }
7397: }
7398: } catch (HeroException traceEx) {
7399: traceEx.printStackTrace();
7400: }
7401: }
7402:
7403: /**
7404: * Project instance. You have to call this method after "create" call. After that
7405: * you have an instance of the project and all methods of ProjectSession API are available.
7406: *
7407: * @param project the name of the project to instance
7408: * @return String - the name of the project instance
7409: * @return Hashtable - default value for properties defined at process level
7410: * @ejb:interface-method view-type="both"
7411: * @ejb:transaction type="Supports"
7412: * @throws CreateException
7413: **/
7414: public String instantiateProject(String project,
7415: Hashtable initProperties) throws CreateException {
7416: String instance = null;
7417: try {
7418: BonitaProjectValue pv = this .instantiateInit(project,
7419: EventConstants.DEFAULTPROJECTVERSION);
7420: instance = project + "_instance";
7421: if (ServerType.isJonas()) {
7422: instance = ((ProjectSessionLocal) mContext
7423: .getEJBLocalObject()).importInstance(pv,
7424: instance, EventConstants.DEFAULTPROJECTVERSION,
7425: initProperties);
7426: } else {
7427: /* JBoss does not support Stateful Session Bean reentrance
7428: * even if the Thread is the same one. So we need to
7429: * invoke the method directly. This *should* work as a
7430: * transaction is already begun, as "Support" transaction
7431: * attribute is switched to "Required" during deployment
7432: * descriptor post processing.
7433: */
7434: instance = this .importInstance(pv, instance,
7435: EventConstants.DEFAULTPROJECTVERSION,
7436: initProperties);
7437: }
7438: thelog.info("User: " + this .getCaller()
7439: + " instantiates project: " + project + ". "
7440: + instance + " is created");
7441: } catch (HeroException traceEx) {
7442: traceEx.printStackTrace();
7443: throw new CreateException(traceEx.getMessage());
7444: }
7445: return (instance);
7446: }
7447:
7448: /**
7449: * Project instance. You have to call this method after "create" call. After that
7450: * you have an instance of the project and all methods of ProjectSession API are available.
7451: *
7452: * @param project the name of the project to instance
7453: * @param version the version of the project to instance
7454: * @return String - the name of the project instance
7455: * @return Hashtable - default value for properties defined at process level
7456: * @ejb:interface-method view-type="both"
7457: * @ejb:transaction type="Supports"
7458: * @throws CreateException
7459: **/
7460: public String instantiateProject(String project, String version,
7461: Hashtable initProperties) throws CreateException {
7462: String instance = null;
7463: try {
7464: BonitaProjectValue pv = this .instantiateInit(project,
7465: version);
7466: instance = project + "_instance";
7467: if (ServerType.isJonas()) {
7468: instance = ((ProjectSessionLocal) mContext
7469: .getEJBLocalObject()).importInstance(pv,
7470: instance, version, initProperties);
7471: } else {
7472: /* JBoss does not support Stateful Session Bean reentrance
7473: * even if the Thread is the same one. So we need to
7474: * invoke the method directly. This *should* work as a
7475: * transaction is already begun, as "Support" transaction
7476: * attribute is switched to "Required" during deployment
7477: * descriptor post processing.
7478: */
7479: instance = this .importInstance(pv, instance, version,
7480: initProperties);
7481: }
7482: thelog.info("User: " + this .getCaller()
7483: + " instantiates project: " + project
7484: + " version: " + version + ". " + instance
7485: + " is created");
7486: } catch (HeroException traceEx) {
7487: traceEx.printStackTrace();
7488: throw new CreateException(traceEx.getMessage());
7489: }
7490: return (instance);
7491: }
7492:
7493: /**
7494: * Project instance. You have to call this method after "create" call. After that
7495: * you have an instance of the project and all methods of ProjectSession API are available.
7496: *
7497: * @param project the name of the project to instance
7498: * @return String - the name of the project instance
7499: * @ejb:interface-method view-type="both"
7500: * @ejb:transaction type="Supports"
7501: * @throws CreateException
7502: **/
7503: public String instantiateProject(String project)
7504: throws CreateException {
7505: String instance = null;
7506: try {
7507: BonitaProjectValue pv = this .instantiateInit(project,
7508: EventConstants.DEFAULTPROJECTVERSION);
7509: instance = project + "_instance";
7510: if (ServerType.isJonas()) {
7511: instance = ((ProjectSessionLocal) mContext
7512: .getEJBLocalObject()).importInstance(pv,
7513: instance, EventConstants.DEFAULTPROJECTVERSION,
7514: new Hashtable());
7515: } else {
7516: /* JBoss does not support Stateful Session Bean reentrance
7517: * even if the Thread is the same one. So we need to
7518: * invoke the method directly. This *should* work as a
7519: * transaction is already begun, as "Support" transaction
7520: * attribute is switched to "Required" during deployment
7521: * descriptor post processing.
7522: */
7523: instance = this .importInstance(pv, instance,
7524: EventConstants.DEFAULTPROJECTVERSION,
7525: new Hashtable());
7526: }
7527: thelog.info("User: " + this .getCaller()
7528: + " instantiates project: " + project + ". "
7529: + instance + " is created");
7530: } catch (HeroException traceEx) {
7531: traceEx.printStackTrace();
7532: throw new CreateException(traceEx.getMessage());
7533: }
7534: return (instance);
7535: }
7536:
7537: /**
7538: * Project instance. You have to call this method after "create" call. After that
7539: * you have an instance of the project and all methods of ProjectSession API are available.
7540: *
7541: * @param project the name of the project to instance
7542: * @param version the version of the project to instance
7543: * @return String - the name of the project instance
7544: * @ejb:interface-method view-type="both"
7545: * @ejb:transaction type="Supports"
7546: * @throws CreateException
7547: **/
7548: public String instantiateProject(String project, String version)
7549: throws CreateException {
7550: String instance = null;
7551: try {
7552: BonitaProjectValue pv = this .instantiateInit(project,
7553: version);
7554: instance = project + "_instance";
7555: if (ServerType.isJonas()) {
7556: instance = ((ProjectSessionLocal) mContext
7557: .getEJBLocalObject()).importInstance(pv,
7558: instance, version, new Hashtable());
7559: } else {
7560: /* JBoss does not support Stateful Session Bean reentrance
7561: * even if the Thread is the same one. So we need to
7562: * invoke the method directly. This *should* work as a
7563: * transaction is already begun, as "Support" transaction
7564: * attribute is switched to "Required" during deployment
7565: * descriptor post processing.
7566: */
7567: instance = this .importInstance(pv, instance, version,
7568: new Hashtable());
7569: }
7570: thelog.info("User: " + this .getCaller()
7571: + " instantiates project: " + project
7572: + " version: " + version + ". " + instance
7573: + " is created");
7574: } catch (HeroException traceEx) {
7575: traceEx.printStackTrace();
7576: throw new CreateException(traceEx.getMessage());
7577: }
7578: return (instance);
7579: }
7580:
7581: private BonitaProjectValue instantiateInit(String project,
7582: String version) throws CreateException {
7583: Context lContext;
7584: String instance = null;
7585: UserServiceLocalHome ushome;
7586: BonitaProjectValue pv = null;
7587: try {
7588: trace.debug("parameter: project=" + project
7589: + " started by " + this .getCaller());
7590: try {
7591: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7592: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
7593: UserServiceLocal ul = ushome.create();
7594: ul.findUserLocal(this .getCaller());
7595: } catch (Exception ce) {
7596: trace.error(ce.getMessage());
7597: throw new HeroException(ce.getMessage());
7598: }
7599: if (project.equals(""))
7600: throw new CreateException(
7601: "Project name can not be empty !!");
7602: if (project.matches(".*_instance.*"))
7603: throw new CreateException(
7604: "You cannot instantiate an instance !!");
7605: try {
7606: try {
7607: pHome = hero.interfaces.BnProjectUtil
7608: .getLocalHome();
7609: mProject = pHome
7610: .findByNameVersion(project, version);
7611: } catch (javax.naming.NamingException ne) {
7612: throw new BonitaServiceException(ne.getMessage());
7613: } catch (javax.ejb.FinderException fe) {
7614: throw new BonitaServiceException(fe.getMessage());
7615: }
7616:
7617: pv = BonitaProjectLocator.getInstance().getModelValue(
7618: project, version);
7619:
7620: if (!pv.getType().equals(Constants.Pj.MODEL))
7621: throw new BonitaServiceException(
7622: "This process is not instantiable. Only model processes can be instantiated !!");
7623:
7624: if (pv.getStatus().equals(Constants.Pj.HIDDEN))
7625: throw new BonitaServiceException(
7626: "This model is not ACTIVE. Activate the model before instantiating it !!");
7627:
7628: } catch (BonitaServiceException e) {
7629: throw new CreateException(e.getMessage());
7630: }
7631: } catch (HeroException traceEx) {
7632: traceEx.printStackTrace();
7633: throw new CreateException(traceEx.getMessage());
7634: }
7635: return pv;
7636: }
7637:
7638: /**
7639: * Creates the Project Session Bean. This method is the first one to invoke in order to
7640: * use ProjectSession API. If the user is not authorized this method throws an exception.
7641: *
7642: * @throws CreateException
7643: *
7644: * @ejb:create-method view-type="both"
7645: **/
7646:
7647: public void ejbCreate() throws CreateException {
7648: }
7649:
7650: /**
7651: * Internal Enterprise Java Beans method.
7652: **/
7653: public void ejbPostCreate(String oldProject, String newProject)
7654: throws CreateException, RemoteException {
7655: }
7656:
7657: /**
7658: * Internal Enterprise Java Beans method.
7659: **/
7660: public void setSessionContext(final javax.ejb.SessionContext context) {
7661: mContext = context;
7662: try {
7663: BonitaConfig bonitaConfig = BonitaConfig.getInstance();
7664: if (bonitaConfig.getJms()) {
7665: JMSServicesSessionLocalHome home = JMSServicesSessionUtil
7666: .getLocalHome();
7667: this .jms = home.create();
7668: }
7669:
7670: // To use Ejb timers
7671: DeadlineEjbTimerSessionLocalHome dlHome;
7672: try {
7673: dlHome = DeadlineEjbTimerSessionUtil.getLocalHome();
7674: } catch (javax.naming.NamingException ne) {
7675: throw new HeroException(ne.getMessage());
7676: }
7677: try {
7678: this .dlSession = dlHome.create();
7679: } catch (CreateException he) {
7680: throw new HeroException(
7681: "Execute: Error to create DeadlineEjbTimerSessionLocal");
7682: }
7683:
7684: } catch (Exception e) {
7685: throw new EJBException(e.getMessage());
7686: }
7687: }
7688:
7689: /**
7690: * Internal Enterprise Java Beans method.
7691: **/
7692:
7693: public void ejbRemove() {
7694: }
7695:
7696: /**
7697: * Internal Enterprise Java Beans method.
7698: **/
7699:
7700: public void ejbActivate() {
7701: }
7702:
7703: /**
7704: * Internal Enterprise Java Beans method.
7705: **/
7706:
7707: public void ejbPassivate() {
7708: }
7709:
7710: // Utility methods
7711:
7712: /*
7713: private void createProcess(String projectName)throws HeroException, CreateException
7714: {
7715: trace.info("User: "+ this.getCaller() + " creates workflow process: " + projectName);
7716: BnUserLocalHome uhome = null;
7717: BnRoleLocalHome rhome = null;
7718: try {
7719: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7720: uhome = hero.interfaces.BnUserUtil.getLocalHome();
7721: rhome = hero.interfaces.BnRoleUtil.getLocalHome();
7722: } catch (javax.naming.NamingException ne) {
7723:
7724: trace.error(ne.getMessage());
7725: throw new CreateException(ne.getMessage());
7726: }
7727: // The project has to be created
7728: try {
7729: String creator = this.getCaller();
7730: mProject = pHome.create(projectName, creator);
7731: mProject.setParent(projectName);
7732: BonitaProjectValue pv = new BonitaProjectValue();
7733: pv.setName(projectName);
7734:
7735: BnUserLocal user = uhome.findByName(creator);
7736: mProject.getBnUsers().add(user);
7737:
7738: // role admin is added
7739: BnRoleValue rv = new BnRoleValue();
7740: rv.setName(hero.interfaces.Constants.ADMIN);
7741: rv.setDescription("the admin role");
7742: BnRoleLocal role = rhome.create(rv);
7743: mProject.getBnRoles().add(role);
7744:
7745: // Set User Role
7746: user.getBnRoles().add(role);
7747:
7748: // role InitialRole is added
7749: rv = new BnRoleValue();
7750: rv.setName(hero.interfaces.Constants.INITIALROLE);
7751: rv.setDescription("the initial role for nodes");
7752: role = rhome.create(rv);
7753: mProject.getBnRoles().add(role);
7754:
7755: if (!creator.equals(Constants.ADMIN))
7756: {
7757: // role username is added
7758: rv = new BnRoleValue();
7759: rv.setName(creator);
7760: rv.setDescription(creator+" user role");
7761: role = rhome.create(rv);
7762: mProject.getBnRoles().add(role);
7763: // Set User Role
7764: user.getBnRoles().add(role);
7765: }
7766:
7767: mProject.setCreationDate(new Date());
7768:
7769: if (jms!=null)
7770: jms.sendProjectEvent(ADDUSERPROJECT, projectName, creator);
7771: } catch (FinderException fie) {
7772:
7773: trace.error(fie.getMessage());
7774: throw new HeroException(fie.getMessage());
7775: } catch (InvalidValueException ie) {
7776:
7777: trace.error(ie.getMessage());
7778: throw new HeroException(ie.getMessage());
7779: } catch (Exception he) {
7780:
7781: trace.error(he.getMessage());
7782: throw new HeroException(he.getMessage());
7783: }
7784: }
7785: */
7786: private void createProcess(String projectName, String projectVersion)
7787: throws HeroException, CreateException {
7788: trace.info("User: " + this .getCaller()
7789: + " creates workflow process: name = " + projectName
7790: + " version = " + projectVersion);
7791: BnUserLocalHome uhome = null;
7792: BnRoleLocalHome rhome = null;
7793: try {
7794: pHome = hero.interfaces.BnProjectUtil.getLocalHome();
7795: uhome = hero.interfaces.BnUserUtil.getLocalHome();
7796: rhome = hero.interfaces.BnRoleUtil.getLocalHome();
7797: } catch (javax.naming.NamingException ne) {
7798:
7799: trace.error(ne.getMessage());
7800: throw new CreateException(ne.getMessage());
7801: }
7802: // The project has to be created
7803: try {
7804: String creator = this .getCaller();
7805: mProject = pHome.create(projectName, projectVersion,
7806: creator);
7807: mProject.setParent(projectName);
7808: BonitaProjectValue pv = new BonitaProjectValue();
7809: pv.setName(projectName);
7810:
7811: BnUserLocal user = uhome.findByName(creator);
7812: mProject.getBnUsers().add(user);
7813:
7814: // role admin is added
7815: BnRoleValue rv = new BnRoleValue();
7816: rv.setName(hero.interfaces.Constants.ADMIN);
7817: rv.setDescription("the admin role");
7818: BnRoleLocal role = rhome.create(rv);
7819: mProject.getBnRoles().add(role);
7820:
7821: // Set User Role
7822: user.getBnRoles().add(role);
7823:
7824: // role InitialRole is added
7825: rv = new BnRoleValue();
7826: rv.setName(hero.interfaces.Constants.INITIALROLE);
7827: rv.setDescription("the initial role for nodes");
7828: role = rhome.create(rv);
7829: mProject.getBnRoles().add(role);
7830:
7831: if (!creator.equals(Constants.ADMIN)) {
7832: // role username is added
7833: rv = new BnRoleValue();
7834: rv.setName(creator);
7835: rv.setDescription(creator + " user role");
7836: role = rhome.create(rv);
7837: mProject.getBnRoles().add(role);
7838: // Set User Role
7839: user.getBnRoles().add(role);
7840: }
7841:
7842: mProject.setCreationDate(new Date());
7843:
7844: if (jms != null)
7845: jms.sendProjectEvent(ADDUSERPROJECT, projectName,
7846: creator);
7847: } catch (FinderException fie) {
7848:
7849: trace.error(fie.getMessage());
7850: throw new HeroException(fie.getMessage());
7851: } catch (InvalidValueException ie) {
7852:
7853: trace.error(ie.getMessage());
7854: throw new HeroException(ie.getMessage());
7855: } catch (Exception he) {
7856:
7857: trace.error(he.getMessage());
7858: throw new HeroException(he.getMessage());
7859: }
7860: }
7861:
7862: private boolean isInProject(String projectName,
7863: String projectVersion) throws HeroException {
7864: if (mContext.getCallerPrincipal().getName().equals(
7865: Constants.SECURITY_ROLE))
7866: return true;
7867: BnProjectLocalHome phome = null;
7868: BnProjectLocal plocal = null;
7869: try {
7870: phome = hero.interfaces.BnProjectUtil.getLocalHome();
7871: plocal = phome.findByNameVersion(projectName,
7872: projectVersion);
7873: Collection users = plocal.getBnUsers();
7874: Iterator usrs = users.iterator();
7875: while (usrs.hasNext()) {
7876: if (((BnUserLocal) usrs.next()).getName().equals(
7877: this .getCaller()))
7878: return true;
7879: }
7880: return false;
7881:
7882: } catch (javax.naming.NamingException ne) {
7883: throw new HeroException(ne.getMessage());
7884: } catch (FinderException fie) {
7885: return true;
7886: } // The project does not exist
7887: }
7888:
7889: /**
7890: * Verifies whether the user is admin of this project/instance
7891: *
7892: * @ejb:interface-method view-type="both"
7893: * @ejb:transaction type="Supports"
7894: * @throws CreateException
7895: **/
7896: public boolean isAdminOfProject() throws HeroException {
7897: if (mContext.getCallerPrincipal().getName().equals(
7898: Constants.SECURITY_ROLE))
7899: return true;
7900: Collection projects = this .getUserRolesInProjectNames(this
7901: .getCaller());
7902: Iterator i = projects.iterator();
7903: while (i.hasNext()) {
7904: String roleName = (String) i.next();
7905: if (roleName.equals(Constants.ADMIN))
7906: return true;
7907: }
7908: return false;
7909: }
7910:
7911: private boolean isProjectHidden() throws HeroException {
7912: if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
7913: return true;
7914: else
7915: return false;
7916: }
7917:
7918: /**
7919: * Returns whether the user belongs to the activity role
7920: *
7921: * @param nodeName the name of the node
7922: * @ejb:interface-method view-type="both"
7923: * @ejb:transaction type="Supports"
7924: * @throws CreateException
7925: **/
7926: public boolean isUserInNodeRole(String nodeName)
7927: throws HeroException {
7928: BnNodeLocalHome nhome = null;
7929: BnNodeLocal nlocal = null;
7930: try {
7931: nhome = hero.interfaces.BnNodeUtil.getLocalHome();
7932: nlocal = nhome.findByName(nodeName, mProject.getId());
7933: if (nlocal.getActivityPerformer() != null)
7934: return (this .getCaller().equals(nlocal
7935: .getActivityPerformer()));
7936: else {
7937: Collection users = nlocal.getBnRole().getBnUsers();
7938:
7939: Iterator i = users.iterator();
7940: while (i.hasNext()) {
7941: BnUserLocal user = (BnUserLocal) i.next();
7942: String userName = user.getName();
7943: if (userName.equals(this .getCaller()))
7944: return true;
7945: }
7946: }
7947: } catch (javax.naming.NamingException ne) {
7948: throw new HeroException(ne.getMessage());
7949: } catch (FinderException fie) {
7950: throw new HeroException(fie.getMessage());
7951: }
7952: return false;
7953: }
7954:
7955: private boolean checkDynamics(String out) throws HeroException {
7956: BnNodeLocal nodeout = mProject.getBnNode(out);
7957: if ((nodeout.getState() == hero.interfaces.Constants.Nd.INITIAL)
7958: || (nodeout.getState() == hero.interfaces.Constants.Nd.READY)
7959: || (nodeout.getState() == hero.interfaces.Constants.Nd.ANTICIPABLE))
7960: return true;
7961: return false;
7962: }
7963:
7964: // Execute RoleMappers for this instance. This method obtain the users list matching with a
7965: // specific role and add them to the instance. To improuve performance, this method uses the
7966: // adduserlocal and setUserRoleLocal methods below.
7967: private void mapRole() throws HeroException {
7968: try {
7969: String creator = this .getCaller();
7970: Collection mappers = new ArrayList();
7971: Collection roles = mProject.getBnRoles();
7972: BnRoleMapperLocal mapper = null;
7973: Iterator it = roles.iterator();
7974: it = roles.iterator();
7975: while (it.hasNext()) {
7976: BnRoleLocal role = (BnRoleLocal) it.next();
7977: mapper = role.getBnRoleMapper();
7978: if (mapper != null) {
7979: hero.mapper.Mapper h = hero.mapper.Mapper.make(
7980: mapper.getName(), mapper.getType());
7981: Collection users = h.execute(this ,
7982: mapper.getType(), role, creator);
7983: if (mapper.getType() == (Constants.Mapper.PROPERTIES))
7984: this .setUserRoleLocal(creator, role.getName());
7985: else {
7986: Iterator i = users.iterator();
7987: while (i.hasNext()) {
7988: String userName = (String) i.next();
7989: this .addUserLocal(userName);
7990: this .setUserRoleLocal(userName, role
7991: .getName());
7992: }
7993: }
7994: }
7995: }
7996: } catch (HeroException he) {
7997: throw new HeroException(he.getMessage());
7998: }
7999: }
8000:
8001: private void addUserLocal(String userName) throws HeroException {
8002: BnUserLocalHome uHome;
8003: BnRoleLocalHome rHome;
8004: BnUserLocal mUser;
8005: UserServiceLocalHome ushome;
8006: try {
8007: uHome = hero.interfaces.BnUserUtil.getLocalHome();
8008: rHome = hero.interfaces.BnRoleUtil.getLocalHome();
8009: } catch (javax.naming.NamingException be) {
8010: throw new HeroException(be.getMessage());
8011: }
8012: try {
8013: ushome = hero.interfaces.UserServiceUtil.getLocalHome();
8014: UserServiceLocal ul = ushome.create();
8015: mUser = ul.findUserLocal(userName);
8016: } catch (Exception ce) {
8017: throw new HeroException(ce.getMessage());
8018: }
8019: Collection cUsers = mProject.getBnUsers();
8020: if (!cUsers.contains(mUser)) {
8021: cUsers.add(mUser);
8022: if (!userName.equals(Constants.ADMIN))
8023: this .addRole(userName, "BnUser BnRole");
8024: this .setUserRoleLocal(userName, userName);
8025: }
8026: }
8027:
8028: private void setUserRoleLocal(String userName, String roleName)
8029: throws HeroException {
8030: BnRoleLocalHome roleh;
8031: BnUserLocalHome userh;
8032: try {
8033: roleh = BnRoleUtil.getLocalHome();
8034: userh = BnUserUtil.getLocalHome();
8035: } catch (javax.naming.NamingException ne) {
8036: throw new HeroException(ne.getMessage());
8037: }
8038: try {
8039: BnUserLocal user = userh.findByName(userName);
8040: BnRoleLocal role = roleh.findByName(roleName, mProject
8041: .getId());
8042: user.getBnRoles().add(role);
8043: } catch (Exception fe) {
8044: throw new HeroException(fe.getMessage());
8045: }
8046:
8047: }
8048:
8049: private void performAssign() throws HeroException {
8050: // logs trace
8051:
8052: trace.debug("perform assign ");
8053: try {
8054: String creator = this .getCaller();
8055: Collection performers = new ArrayList();
8056: Collection nodes = mProject.getBnNodes();
8057: BnNodePerformerAssignLocal performerAssign = null;
8058: Iterator it = nodes.iterator();
8059:
8060: it = nodes.iterator();
8061: while (it.hasNext()) {
8062: BnNodeLocal node = (BnNodeLocal) it.next();
8063: performerAssign = node.getBnNodePerformerAssign();
8064: if (performerAssign != null) {
8065: hero.performerAssign.PerformerAssign h = hero.performerAssign.PerformerAssign
8066: .make(performerAssign.getName(),
8067: performerAssign.getType());
8068: h.execute(this , performerAssign.getType(), node,
8069: creator);
8070: }
8071: }
8072: } catch (HeroException he) {
8073: throw new HeroException(he.getMessage());
8074: }
8075:
8076: }
8077:
8078: /**
8079: * Checks recursively if toIterationNode is reachable.
8080: *
8081: * @param visited
8082: * @param currentNode
8083: * @param toIterationNode
8084: * @return 'true' if exists a path from fromIterationNode to toIterationNode. Otherwise it returns 'false'
8085: * @throws HeroException
8086: */
8087: private boolean checkStructuralConstraints(ArrayList visited,
8088: String currentNode, String toIterationNode)
8089: throws HeroException {
8090: if (currentNode.equals(toIterationNode)) {
8091: return true;
8092: }
8093:
8094: if (!visited.contains(currentNode)) {
8095: visited.add(currentNode);
8096: }
8097:
8098: BnNodeLocal currentBnNode = mProject.getBnNode(currentNode);
8099: Collection inEdges = currentBnNode.getInBnEdges();
8100: Iterator it = inEdges.iterator();
8101: while (it.hasNext()) {
8102: BnEdgeLocal nextEdge = (BnEdgeLocal) it.next();
8103: BnNodeLocal nextNode = nextEdge.getInBnNode();
8104: String nextNodeName = nextNode.getName();
8105: if ((!visited.contains(nextNodeName))
8106: && (checkStructuralConstraints(visited,
8107: nextNodeName, toIterationNode))) {
8108: return true;
8109: }
8110: }
8111: return false;
8112: }
8113:
8114: private boolean checkDuplicateEdge(String in, String out)
8115: throws HeroException {
8116: Collection edges = mProject.getBnEdges();
8117: Iterator i = edges.iterator();
8118: while (i.hasNext()) {
8119: BnEdgeLocal edge = (BnEdgeLocal) i.next();
8120: if ((edge.getInBnNode().getName()).equals(in)
8121: && (edge.getOutBnNode().getName()).equals(out))
8122: return false;
8123: }
8124: return true;
8125: }
8126:
8127: private boolean checkDuplicateAgentEdge(String in, String out)
8128: throws HeroException {
8129: Collection edges = mProject.getBnAgentEdges();
8130: Iterator i = edges.iterator();
8131: while (i.hasNext()) {
8132: BnAgentEdgeLocal edge = (BnAgentEdgeLocal) i.next();
8133: if ((edge.getInBnAgent().getName()).equals(in)
8134: && (edge.getOutBnNode().getName()).equals(out))
8135: return false;
8136: }
8137: return true;
8138: }
8139:
8140: /**
8141: * Copy node. Internal method used in processes instantiation.
8142: *
8143: * @param name of the new node
8144: * @param node the BnNodeLocal object of the copied node.
8145: * @param inNode the BnNodeLocal in node object of the new node.
8146: * @ejb:interface-method view-type="local"
8147: * @ejb:transaction type="Required"
8148: *
8149: **/
8150: public void copyNode(String nodeName, BonitaNodeValue node)
8151: throws HeroException {
8152:
8153: trace.debug("copyNode: nodeName=" + nodeName + " node="
8154: + node.getName() + " inNode=");
8155: BnNodeLocalHome nHome;
8156: BnNodeLocal mNode;
8157: BnUserLocalHome uHome;
8158: BnNodePerformerAssignLocal ppLocal;
8159: BnNodePerformerAssignLocalHome performerAssignh;
8160:
8161: try {
8162: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
8163: uHome = hero.interfaces.BnUserUtil.getLocalHome();
8164: performerAssignh = BnNodePerformerAssignUtil.getLocalHome();
8165: } catch (javax.naming.NamingException be) {
8166:
8167: trace.error(be.getMessage());
8168: throw new HeroException(be.getMessage());
8169: }
8170: try {
8171: if (nodeName.equals(""))
8172: throw new HeroException("Node name can not be empty...");
8173:
8174: // Creates node and set the role
8175: BnNodeLocal nd = nHome.create(nodeName, node.getType());
8176: BnNodeValue ndata = nd.getBnNodeValue();
8177: ndata.setCreationDate(new java.util.Date());
8178: nd.setBnNodeValue(ndata);
8179: Collection cNodes = mProject.getBnNodes();
8180: cNodes.add(nd);
8181:
8182: nd.setCreator(node.getCreator());
8183: nd.setExecutor(node.getExecutor()); // Only for JOnAS consistency
8184:
8185: BnRoleLocalHome rHome = BnRoleUtil.getLocalHome();
8186: BnRoleLocal role = rHome.findByName(node.getRole(),
8187: mProject.getId());
8188: nd.setBnRole(role);
8189:
8190: if (!node.getAnticipable()) // Anticipable/traditional mode
8191: {
8192: nd.setAnticipable(false);
8193: }
8194: nd.setDescription(node.getDescription()); // Node description
8195:
8196: //For Deadlines
8197: if (node.getDeadlines().size() != 0)
8198: nd.setDeadlines(node.getDeadlines());
8199: //For relative Deadlines
8200: if (node.getRelativeDeadlines().size() != 0)
8201: nd.setRelativeDeadlines(node.getRelativeDeadlines());
8202:
8203: if (node.getPerformer() != null) // Node Performer assignment
8204: {
8205: ppLocal = performerAssignh.create(node.getPerformer()
8206: .getName(), node.getPerformer().getType(), node
8207: .getPerformer().getPropertyName());
8208: ppLocal.setBnNode(nd);
8209: }
8210: // Tell the world
8211: if (jms != null)
8212: jms.sendNodeEvent(ADDNODE, this .getName(), nodeName, nd
8213: .getType(), nd.getState(), this .getCaller());
8214:
8215: } catch (InvalidValueException ie) {
8216:
8217: trace.error(ie.getMessage());
8218: throw new HeroException(ie.getMessage());
8219: } catch (CreateException ce) {
8220:
8221: trace.error(ce.getMessage());
8222: throw new HeroException(ce.getMessage());
8223: } catch (FinderException fe) {
8224:
8225: trace.error(fe.getMessage());
8226: throw new HeroException(fe.getMessage());
8227: } catch (javax.naming.NamingException ne) {
8228:
8229: trace.error(ne.getMessage());
8230: throw new HeroException(ne.getMessage());
8231: }
8232: }
8233:
8234: /**
8235: * Copy node edge. Internal method used in processes instantiation.
8236: *
8237: * @param name of the new node
8238: * @param inNode the BnNodeLocal in node object of the new node.
8239: * @param edge the BnEdgeLocal edge object from the project model.
8240: * @ejb:interface-method view-type="local"
8241: * @ejb:transaction type="Required"
8242: *
8243: **/
8244: public void copyEdge(String nodeName, BnNodeLocal inNode,
8245: BonitaEdgeValue edge) throws HeroException {
8246:
8247: trace.debug("copyEdge: nodeName=" + nodeName + " inNode="
8248: + inNode.getName() + " edge=" + edge.getName());
8249: BnEdgeLocalHome eHome;
8250: BnEdgeLocal mEdge;
8251: BnNodeLocalHome nHome;
8252: BnNodeLocal mNode;
8253:
8254: try {
8255: nHome = hero.interfaces.BnNodeUtil.getLocalHome();
8256: eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
8257: } catch (javax.naming.NamingException be) {
8258:
8259: trace.error(be.getMessage());
8260: throw new HeroException(be.getMessage());
8261: }
8262: try {
8263: BnNodeLocal nd = nHome.findByName(nodeName, mProject
8264: .getId());
8265:
8266: try {
8267: mEdge = eHome.create();
8268: mEdge.setBnProject(mProject);
8269: mEdge.setInBnNode(inNode);
8270: mEdge.setOutBnNode(nd);
8271: mEdge.setCondition(edge.getCondition());
8272:
8273: int inState = Constants.Nd.READY;
8274: if (inNode.getState() == Constants.Nd.ANTICIPATING)
8275: inState = Constants.Nd.ANTICIPABLE;
8276:
8277: int edgeState = hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][inState];
8278: this .setEdgeState(mEdge, edgeState);
8279: // mEdge.setState(edgeState);
8280:
8281: EdgeState edgeStateClass = EdgeState.make(nd.getType());
8282: int newOperation = edgeStateClass.state(nd);
8283:
8284: // It doesn't consider CANCEL operation. CANCEL propagation is done by the EngineBean
8285: if (newOperation != Constants.Nd.CANCEL) {
8286: NodeState nodeState = NodeState.make(nd.getType(),
8287: nd.getAnticipable());
8288: int newState = nodeState.computeState(nd,
8289: newOperation);
8290:
8291: if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
8292: throw new HeroException(
8293: "AddEdge generated a bad Node transition");
8294: }
8295: this .setNodeState(nd, newState);
8296: }
8297:
8298: if (jms != null)
8299: jms.sendEdgeEvent(ADDEDGE, this .getName(), mEdge
8300: .getName(), inNode.getName(), nd.getName(),
8301: this .getCaller());
8302: } catch (hero.util.NodeStartedException nse) {
8303: } // Instances execution consistency
8304: } catch (InvalidValueException ie) {
8305:
8306: trace.error(ie.getMessage());
8307: throw new HeroException(ie.getMessage());
8308: } catch (CreateException ce) {
8309:
8310: trace.error(ce.getMessage());
8311: throw new HeroException(ce.getMessage());
8312: } catch (FinderException fe) {
8313:
8314: trace.error(fe.getMessage());
8315: throw new HeroException(fe.getMessage());
8316: }
8317: }
8318:
8319: /**
8320: * Test if the project contains this user
8321: * @param userName The name of the user to associate to the project
8322: * @return boolean - true is the user belongs to the project
8323: *
8324: * @ejb:interface-method view-type="both"
8325: * @ejb:transaction type="Supports"
8326: * @throws HeroException
8327: *
8328: **/
8329: public boolean containsUser(String userName) throws HeroException {
8330:
8331: trace.debug("containsUser : name=" + userName);
8332: BnUserLightValue[] uv = mProject.getBnProjectValue()
8333: .getBnUsers();
8334: for (int i = 0; i < uv.length; i++) {
8335: if (uv[i].getName().equalsIgnoreCase(userName))
8336: return true;
8337: }
8338: return false;
8339: }
8340:
8341: private boolean containsRole(String roleName) {
8342: BnRoleValue[] rv = mProject.getBnProjectValue().getBnRoles();
8343: for (int i = 0; i < rv.length; i++) {
8344: if (rv[i].getName().equalsIgnoreCase(roleName))
8345: return true;
8346: }
8347: return false;
8348: }
8349:
8350: private Collection getNodeInEdges(BnNodeLocal nd) {
8351: Collection edgeValues = new ArrayList();
8352: Collection edges = nd.getInBnEdges();
8353: Iterator nodeEdges = edges.iterator();
8354: while (nodeEdges.hasNext())
8355: edgeValues.add(((BnEdgeLocal) nodeEdges.next())
8356: .getBnEdgeValue());
8357: return edgeValues;
8358:
8359: }
8360:
8361: private void addIterationInstance(String from, String to,
8362: String condition) throws HeroException {
8363: BnIterationLocalHome iteh;
8364: try {
8365: iteh = BnIterationUtil.getLocalHome();
8366: } catch (javax.naming.NamingException ne) {
8367: throw new HeroException(ne.getMessage());
8368: }
8369:
8370: BnIterationLightValue iv = new BnIterationLightValue();
8371: iv.setFromNode(from);
8372: iv.setToNode(to);
8373: iv.setCondition(condition);
8374: try {
8375: BnIterationLocal il = iteh.create(iv);
8376: mProject.getBnIterations().add(il);
8377: if (jms != null)
8378: jms.sendIterationEvent(ADDITERATION, this .getName(),
8379: from, to);
8380: } catch (Exception ce) {
8381: throw new HeroException(ce.getMessage());
8382: }
8383: }
8384:
8385: private String getModel(String instanceName) {
8386: int i = instanceName.indexOf("_instance");
8387: return (instanceName.substring(0, i));
8388: }
8389:
8390: /**
8391: * Local method
8392: * @ejb:interface-method view-type="local"
8393: * @ejb:transaction type="Supports"
8394: * @throws HeroException
8395: *
8396: **/
8397: public String getCaller() {
8398: /*
8399: * Previously, mContext.getCallerPrincipal() was invoked from
8400: * ejbCreate(). This was not working in some application servers
8401: * such as JBoss. For this reason, the caller field is set in this
8402: * method on first call.
8403: */
8404: if (this .caller == null) {
8405: this .setCaller(mContext.getCallerPrincipal().getName());
8406: }
8407:
8408: return this .caller;
8409: }
8410:
8411: /**
8412: * Local method
8413: * @ejb:interface-method view-type="local"
8414: * @ejb:transaction type="Supports"
8415: * @throws HeroException
8416: *
8417: **/
8418: public void setCaller(String user) {
8419: this .caller = user;
8420: }
8421:
8422: /**
8423: * Checks: <br>
8424: * - 1st: checks if iterations conditions are not empty <br>
8425: * - 2nd: if we have more than one iteration starting in the same node -> checks that the iterations conditions are different <br>
8426: *
8427: * @throws HeroException
8428: */
8429: private void checkIterationConstrains() throws HeroException {
8430: Collection projectIterations = mProject.getBnIterations();
8431: Iterator iterationsIt = projectIterations.iterator();
8432: while (iterationsIt.hasNext()) {
8433: BnIterationLocal iteration = (BnIterationLocal) iterationsIt
8434: .next();
8435: BnNodeLocal fromNodeLocal = mProject.getBnNode(iteration
8436: .getFromNode());
8437: BnNodeLocal toNodeLocal = mProject.getBnNode(iteration
8438: .getToNode());
8439: String iterationCondition = iteration.getCondition();
8440:
8441: // 1st: checks if iterations conditions are not empty
8442: if (iterationCondition.equals("")) {
8443: throw new HeroException(
8444: "ERROR in checkIterationConstrains() : Condition in iteration "
8445: + fromNodeLocal.getName() + "--->"
8446: + toNodeLocal.getName()
8447: + " cannot be \"\" (nothing)");
8448: }
8449:
8450: // 2nd: checks if exists a path between from--->to
8451: ArrayList visited = new ArrayList();
8452: if (!this .checkStructuralConstraints(visited, fromNodeLocal
8453: .getName(), toNodeLocal.getName())) {
8454: throw new HeroException(
8455: "ERROR in checkIterationConstrains() : There isn't any path between "
8456: + toNodeLocal.getName() + "--->"
8457: + fromNodeLocal.getName());
8458: }
8459:
8460: // 3rd: if we have more than one iteration starting in the same node -> checks that the iterations conditions are different
8461: Iterator anotherIterationsIt = projectIterations.iterator();
8462: while (anotherIterationsIt.hasNext()) {
8463: BnIterationLocal iterationToCompare = (BnIterationLocal) anotherIterationsIt
8464: .next();
8465: if (!(iterationToCompare.isIdentical(iteration)) // If they are different iterations
8466: && (iterationToCompare.getFromNode()
8467: .equals(iteration.getFromNode())) // If they start in the same node
8468: && (iterationToCompare.getCondition()
8469: .equals(iterationCondition))) { // and they have the same condition
8470: throw new HeroException(
8471: "ERROR in checkIterationConstrains() : Two iterations starting in the same node ("
8472: + fromNodeLocal.getName()
8473: + "--->"
8474: + toNodeLocal.getName()
8475: + " & "
8476: + iterationToCompare.getFromNode()
8477: + "--->"
8478: + iterationToCompare.getToNode()
8479: + ") cannot have the same condition ("
8480: + iterationCondition + ")");
8481: }
8482: }
8483: }
8484: }
8485:
8486: /**
8487: * Gets in a recursive way the nodes inside the iteration.<br>
8488: * Extra entry points are no returned (because they are not inside the iteration)
8489: *
8490: * @param nodesInIteration initially is an empty list and at the end contains the nodes inside the iteration
8491: * @param currentNode
8492: * @param toIterationNode
8493: * @return true if current node is inside the iteration and false otherwise
8494: * @throws HeroException
8495: */
8496: private boolean getNodesInsideIteration(ArrayList nodesInIteration,
8497: BnNodeLocal currentNode, BnNodeLocal toIterationNode)
8498: throws HeroException {
8499: boolean pathExists = false;
8500:
8501: if (currentNode.equals(toIterationNode)) {
8502: nodesInIteration.add(currentNode);
8503: return true;
8504: } else {
8505: Collection inEdges = currentNode.getInBnEdges();
8506: Iterator it = inEdges.iterator();
8507: while (it.hasNext()) {
8508: BnEdgeLocal nextEdge = (BnEdgeLocal) it.next();
8509: BnNodeLocal nextNode = nextEdge.getInBnNode();
8510: if (nodesInIteration.contains(nextNode)) {
8511: pathExists = true;
8512: } else {
8513: if (getNodesInsideIteration(nodesInIteration,
8514: nextNode, toIterationNode)) {
8515: pathExists = true;
8516: }
8517: }
8518: }
8519: }
8520: if (pathExists) {
8521: if (!nodesInIteration.contains(currentNode)) {
8522: nodesInIteration.add(currentNode);
8523: }
8524: return true;
8525: } else {
8526: return false;
8527: }
8528: }
8529:
8530: /**
8531: * Checks: <br>
8532: * - 1st: checks mandatory conditions over the out edges of the nodes that create and extra exit point from the iteration <br>
8533: * - 2nd: checks mandatory conditions over the out edges from the node that starts the iteration are different from the iteration's condition <br>
8534: * @throws HeroException
8535: **/
8536: private void checkMandatoryIterationConditions()
8537: throws HeroException {
8538: Collection projectIterations = mProject.getBnIterations();
8539: Iterator iterationsIt = projectIterations.iterator();
8540: while (iterationsIt.hasNext()) {
8541: BnIterationLocal iteration = (BnIterationLocal) iterationsIt
8542: .next();
8543: ArrayList nodeList = new ArrayList();
8544: BnNodeLocal fromNodeLocal = mProject.getBnNode(iteration
8545: .getFromNode());
8546: BnNodeLocal toNodeLocal = mProject.getBnNode(iteration
8547: .getToNode());
8548: String iterationCondition = iteration.getCondition();
8549:
8550: // 1st: checks mandatory conditions over the out edges of the nodes that create and extra exit point from the iteration
8551: this .getNodesInsideIteration(nodeList, fromNodeLocal,
8552: toNodeLocal);
8553:
8554: // check if some out egde of the nodeList point to node that is not in the list (it's an extra exit point)
8555: Iterator nodeListIterator = nodeList.iterator();
8556: while (nodeListIterator.hasNext()) {
8557: BnNodeLocal node = (BnNodeLocal) nodeListIterator
8558: .next();
8559: Collection outEdges = node.getOutBnEdges();
8560: Iterator outEdgesIt = outEdges.iterator();
8561: while (outEdgesIt.hasNext()) {
8562: BnEdgeLocal edge = (BnEdgeLocal) outEdgesIt.next();
8563: BnNodeLocal outNode = edge.getOutBnNode();
8564: if (!nodeList.contains(outNode)) { // outNode is outside iteration
8565: // All out edges of the "inNode" has to have a condition
8566: Collection outNodeEdges = edge.getInBnNode()
8567: .getOutBnEdges();
8568: Iterator outNodeEdgesIt = outNodeEdges
8569: .iterator();
8570: while (outNodeEdgesIt.hasNext()) {
8571: BnEdgeLocal nextEdge = (BnEdgeLocal) outNodeEdgesIt
8572: .next();
8573: String edgeTmpCondition = nextEdge
8574: .getCondition();
8575: if (edgeTmpCondition == null) {
8576: throw new HeroException(
8577: "ERROR in checkMandatoryIterationConditions() : It has to be a condition in transition "
8578: + nextEdge
8579: .getInBnNode()
8580: .getName()
8581: + "--->"
8582: + nextEdge
8583: .getOutBnNode()
8584: .getName());
8585: } else if (edgeTmpCondition.equals("")) {
8586: throw new HeroException(
8587: "ERROR in checkMandatoryIterationConditions() : Condition in transition "
8588: + nextEdge
8589: .getInBnNode()
8590: .getName()
8591: + "--->"
8592: + nextEdge
8593: .getOutBnNode()
8594: .getName()
8595: + " cannot be \"\" (nothing)");
8596: } else if (edgeTmpCondition.equals("true")) {
8597: throw new HeroException(
8598: "ERROR in checkMandatoryIterationConditions() : Condition in transition "
8599: + nextEdge
8600: .getInBnNode()
8601: .getName()
8602: + "--->"
8603: + nextEdge
8604: .getOutBnNode()
8605: .getName()
8606: + " cannot be \"true\"");
8607: }
8608: }
8609: }
8610: }
8611: } // End 1st checking
8612:
8613: // 2nd: checks mandatory conditions over the out edges from the node that starts the iteration are different from the iteration's condition
8614: Collection outEdges = fromNodeLocal.getOutBnEdges();
8615: Iterator outEdgesIt = outEdges.iterator();
8616: while (outEdgesIt.hasNext()) {
8617: BnEdgeLocal nextEdge = (BnEdgeLocal) outEdgesIt.next();
8618: String edgeCondition = nextEdge.getCondition();
8619: if (edgeCondition.equals(iterationCondition)) {
8620: throw new HeroException(
8621: "ERROR in checkMandatoryIterationConditions() : Condition in transition "
8622: + nextEdge.getInBnNode().getName()
8623: + "--->"
8624: + nextEdge.getOutBnNode().getName()
8625: + " cannot be equal to iteration condition");
8626: }
8627: } // End 2nd checking
8628: }
8629: }
8630:
8631: /**
8632: * Checks if the project model is correctly defined.
8633: *
8634: * @ejb:interface-method view-type="both"
8635: * @ejb:transaction type="Required"
8636: * @throws HeroException
8637: **/
8638: public void checkModelDefinition() throws HeroException {
8639: this.checkIterationConstrains();
8640: this.checkMandatoryIterationConditions();
8641: }
8642:
8643: }
|