⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wfprocessimpl.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        setSerializedData(context);    }        /**     * @see org.ofbiz.workflow.WfProcess#activityComplete(org.ofbiz.workflow.WfActivity)     */    public synchronized void activityComplete(WfActivity activity) throws WfException {        if (!activity.state().equals("closed.completed"))            throw new WfException("Activity state is not completed");        if (Debug.verboseOn()) Debug.logVerbose("[WfProcess.activityComplete] : Activity (" + activity.name() + ") is complete", module);        queueNext(activity);    }    /**     * @see org.ofbiz.workflow.impl.WfExecutionObjectImpl#executionObjectType()     */    public String executionObjectType() {        return "WfProcess";    }    // Queues the next activities for processing    private void queueNext(WfActivity fromActivity) throws WfException {        List nextTrans = getTransFrom(fromActivity);        if (nextTrans.size() > 0) {            Iterator i = nextTrans.iterator();            while (i.hasNext()) {                GenericValue trans = (GenericValue) i.next();                // Get the activity definition                GenericValue toActivity = null;                try {                    toActivity = trans.getRelatedOne("ToWorkflowActivity");                } catch (GenericEntityException e) {                    throw new WfException(e.getMessage(), e);                }                // check for a join                String join = "WJT_AND"; // default join is AND                if (toActivity.get("joinTypeEnumId") != null)                    join = toActivity.getString("joinTypeEnumId");                if (Debug.verboseOn()) Debug.logVerbose("[WfProcess.queueNext] : " + join + " join.", module);                // activate if XOR or test the join transition(s)                if (join.equals("WJT_XOR"))                    startActivity(toActivity);                else                    joinTransition(toActivity, trans);            }        } else {            if (Debug.verboseOn())                 Debug.logVerbose("[WfProcess.queueNext] : No transitions left to follow.", module);            this.finishProcess();        }    }    // Follows the and-join transition    private void joinTransition(GenericValue toActivity,        GenericValue transition) throws WfException {        // get all TO transitions to this activity        GenericValue dataObject = getRuntimeObject();        Collection toTrans = null;        try {            toTrans = toActivity.getRelated("ToWorkflowTransition");        } catch (GenericEntityException e) {            throw new WfException(e.getMessage(), e);        }        // get a list of followed transition to this activity        Collection followed = null;        try {            Map fields = new HashMap();            fields.put("processWorkEffortId", dataObject.getString("workEffortId"));            fields.put("toActivityId", toActivity.getString("activityId"));            followed = getDelegator().findByAnd("WorkEffortTransBox", fields);        } catch (GenericEntityException e) {            throw new WfException(e.getMessage(), e);        }        if (Debug.verboseOn()) Debug.logVerbose("[WfProcess.joinTransition] : toTrans (" + toTrans.size() + ") followed (" +                (followed.size() + 1) + ")", module);        // check to see if all transition requirements are met        if (toTrans.size() == (followed.size() + 1)) {            Debug.logVerbose("[WfProcess.joinTransition] : All transitions have followed.", module);            startActivity(toActivity);            try {                Map fields = new HashMap();                fields.put("processWorkEffortId", dataObject.getString("workEffortId"));                fields.put("toActivityId", toActivity.getString("activityId"));                getDelegator().removeByAnd("WorkEffortTransBox", fields);            } catch (GenericEntityException e) {                throw new WfException(e.getMessage(), e);            }        } else {            Debug.logVerbose("[WfProcess.joinTransition] : Waiting for transitions to finish.", module);            try {                Map fields = new HashMap();                fields.put("processWorkEffortId", dataObject.getString("workEffortId"));                fields.put("toActivityId", toActivity.getString("activityId"));                fields.put("transitionId", transition.getString("transitionId"));                GenericValue obj = getDelegator().makeValue("WorkEffortTransBox", fields);                getDelegator().create(obj);            } catch (GenericEntityException e) {                throw new WfException(e.getMessage(), e);            }        }    }    // Activates an activity object    private void startActivity(GenericValue value) throws WfException {        WfActivity activity = WfFactory.getWfActivity(value, workEffortId);        GenericResultWaiter req = new GenericResultWaiter();        if (Debug.verboseOn()) Debug.logVerbose("[WfProcess.startActivity] : Attempting to start activity (" + activity.name() + ")", module);                // locate the dispatcher to use        LocalDispatcher dispatcher = this.getDispatcher();                // get the job manager        JobManager jm = dispatcher.getJobManager();        if (jm == null) {            throw new WfException("No job manager found on the service dispatcher; cannot start activity");        }                  // using the StartActivityJob class to run the activity within its own thread                      try {                        Job activityJob = new StartActivityJob(activity, req);                                               jm.runJob(activityJob);          } catch (JobManagerException e) {            throw new WfException("JobManager error", e);        }                 // the GenericRequester object will hold any exceptions; and report the job as failed               if (req.status() == GenericResultWaiter.SERVICE_FAILED) {            Throwable reqt = req.getThrowable();            if (reqt instanceof CannotStart)                Debug.logVerbose("[WfProcess.startActivity] : Cannot start activity. Waiting for manual start.", module);            else if (reqt instanceof AlreadyRunning)                throw new WfException("Activity already running", reqt);            else                            throw new WfException("Activity error", reqt);        }                            }    // Determine the next activity or activities    private List getTransFrom(WfActivity fromActivity) throws WfException {        List transList = new ArrayList();        // get the from transitions        Collection fromCol = null;        try {            fromCol = fromActivity.getDefinitionObject().getRelated("FromWorkflowTransition");        } catch (GenericEntityException e) {            throw new WfException(e.getMessage(), e);        }        // check for a split        String split = "WST_AND"; // default split is AND        if (fromActivity.getDefinitionObject().get("splitTypeEnumId") != null)            split = fromActivity.getDefinitionObject().getString("splitTypeEnumId");        // the default value is TRUE, so if no expression is supplied we evaluate as true        boolean transitionOk = true;                // the otherwise condition (only used by XOR splits)         GenericValue otherwise = null;        // iterate through the possible transitions        Iterator fromIt = fromCol.iterator();        while (fromIt.hasNext()) {            GenericValue transition = (GenericValue) fromIt.next();            // if this transition is OTHERWISE store it for later and continue on            if (transition.get("conditionTypeEnumId") != null && transition.getString("conditionTypeEnumId").equals("WTC_OTHERWISE")) {                // there should be only one of these, if there is more then one we will use the last one defined                otherwise = transition;                continue;            }                        // get the condition body from the condition tag            String conditionBody = transition.getString("conditionExpr");                        // get the extended attributes for the transition            Map extendedAttr = StringUtil.strToMap(transition.getString("extendedAttributes"));                         // check for a conditionClassName attribute if exists use it            if (extendedAttr != null && extendedAttr.get("conditionClassName") != null) {                String conditionClassName = (String) extendedAttr.get("conditionClassName");                  transitionOk = this.evalConditionClass(conditionClassName, conditionBody, this.processContext(), extendedAttr);                          } else {                // since no condition class is supplied, evaluate the expression using bsh                if (conditionBody != null) {                    transitionOk = this.evalBshCondition(conditionBody, this.processContext());                }            }                                               if (transitionOk) {                transList.add(transition);                if (split.equals("WST_XOR"))                    break;            }        }        // we only use the otherwise transition for XOR splits        if (split.equals("WST_XOR") && transList.size() == 0 && otherwise != null) {            transList.add(otherwise);            Debug.logVerbose("Used OTHERWISE Transition.", module);        }        if (Debug.verboseOn()) Debug.logVerbose("[WfProcess.getTransFrom] : Transitions: " + transList.size(), module);        return transList;    }    // Gets a specific activity by its key    private WfActivity getActivity(String key) throws WfException {        Iterator i = getIteratorStep();        while (i.hasNext()) {            WfActivity a = (WfActivity) i.next();            if (a.key().equals(key))                return a;        }        throw new WfException("Activity not an active member of this process");    }    // Complete this workflow    private void finishProcess() throws WfException {        changeState("closed.completed");        Debug.logVerbose("[WfProcess.finishProcess] : Workflow Complete. Calling back to requester.", module);        if (requester != null) {            WfEventAudit audit = WfFactory.getWfEventAudit(this, null); // this will need to be updated            try {                requester.receiveEvent(audit);            } catch (InvalidPerformer e) {                throw new WfException(e.getMessage(), e);            }        }    }    // Get the active process activities    private List activeSteps() throws WfException {        List steps = new ArrayList();        Collection c = null;        try {            c = getDelegator().findByAnd("WorkEffort", UtilMisc.toMap("workEffortParentId", runtimeKey()));        } catch (GenericEntityException e) {            throw new WfException(e.getMessage(), e);        }        if (c == null)            return steps;        Iterator i = c.iterator();        while (i.hasNext()) {            GenericValue v = (GenericValue) i.next();            if (v.get("currentStatusId") != null &&                WfUtil.getOMGStatus(v.getString("currentStatusId")).startsWith("open."))                steps.add(WfFactory.getWfActivity(getDelegator(), v.getString("workEffortId")));        }        return steps;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -