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

📄 wfprocessimpl.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: WfProcessImpl.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2001 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.workflow.impl;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.StringUtil;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.service.GenericResultWaiter;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.job.Job;import org.ofbiz.service.job.JobManager;import org.ofbiz.service.job.JobManagerException;import org.ofbiz.workflow.AlreadyRunning;import org.ofbiz.workflow.CannotChangeRequester;import org.ofbiz.workflow.CannotStart;import org.ofbiz.workflow.CannotStop;import org.ofbiz.workflow.InvalidData;import org.ofbiz.workflow.InvalidPerformer;import org.ofbiz.workflow.InvalidState;import org.ofbiz.workflow.NotRunning;import org.ofbiz.workflow.ResultNotAvailable;import org.ofbiz.workflow.WfActivity;import org.ofbiz.workflow.WfEventAudit;import org.ofbiz.workflow.WfException;import org.ofbiz.workflow.WfFactory;import org.ofbiz.workflow.WfProcess;import org.ofbiz.workflow.WfProcessMgr;import org.ofbiz.workflow.WfRequester;import org.ofbiz.workflow.WfUtil;import org.ofbiz.workflow.client.StartActivityJob;/** * WfProcessImpl - Workflow Process Object implementation * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     David Ostrovsky (d.ostrovsky@gmx.de)  * @version    $Rev: 5462 $ * @since      2.0 */public class WfProcessImpl extends WfExecutionObjectImpl implements WfProcess {    public static final String module = WfProcessImpl.class.getName();    protected WfRequester requester = null;    protected WfProcessMgr manager = null;           public WfProcessImpl(GenericValue valueObject, WfProcessMgr manager) throws WfException {        super(valueObject, null);        this.manager = manager;                   this.requester = null;        init();    }            /**     * @see org.ofbiz.workflow.impl.WfExecutionObjectImpl#WfExecutionObjectImpl(org.ofbiz.entity.GenericDelegator, java.lang.String)     */    public WfProcessImpl(GenericDelegator delegator, String workEffortId) throws WfException {        super(delegator, workEffortId);        if (activityId != null && activityId.length() > 0)            throw new WfException("Execution object is not of type WfProcess.");        this.manager = WfFactory.getWfProcessMgr(delegator, packageId, packageVersion, processId, processVersion);        this.requester = null;            }        private void init() throws WfException {        // since we are a process we don't have a context yet        // get the context to use with parsing descriptions from the manager        Map context = manager.getInitialContext();        this.parseDescriptions(context);            }    /**     * @see org.ofbiz.workflow.WfProcess#setRequester(org.ofbiz.workflow.WfRequester)     */    public void setRequester(WfRequester newValue) throws WfException, CannotChangeRequester {        if (requester != null)            throw new CannotChangeRequester();        requester = newValue;    }    /**     * @see org.ofbiz.workflow.WfProcess#getSequenceStep(int)     */    public List getSequenceStep(int maxNumber) throws WfException {        if (maxNumber > 0)            return new ArrayList(activeSteps().subList(0, maxNumber - 1));        return activeSteps();    }        /**     * @see org.ofbiz.workflow.WfExecutionObject#abort()     */    public void abort() throws WfException, CannotStop, NotRunning {        super.abort();                // cancel the active activities        Iterator activities = this.activeSteps().iterator();        while (activities.hasNext()) {            WfActivity activity = (WfActivity) activities.next();            activity.abort();        }                    }      /**     * @see org.ofbiz.workflow.WfProcess#start()     */    public void start() throws WfException, CannotStart, AlreadyRunning {        start(null);    }         /**     * @see org.ofbiz.workflow.WfProcess#start()     */    public void start(String activityId) throws WfException, CannotStart, AlreadyRunning {        if (state().equals("open.running"))            throw new AlreadyRunning("Process is already running");        if (activityId == null && getDefinitionObject().get("defaultStartActivityId") == null)            throw new CannotStart("Initial activity is not defined.");        changeState("open.running");        // start the first activity (using the defaultStartActivityId)        GenericValue start = null;        try {            if (activityId != null) {                GenericValue processDef = getDefinitionObject();                Map fields = UtilMisc.toMap("packageId", processDef.getString("packageId"), "packageVersion",                         processDef.getString("packageVersion"), "processId", processDef.getString("processId"),                         "processVersion", processDef.getString("processVersion"), "activityId", activityId);                                         start = getDelegator().findByPrimaryKey("WorkflowActivity", fields);                                // here we must check and make sure this activity is defined to as a starting activity                if (!start.getBoolean("canStart").booleanValue())                    throw new CannotStart("The specified activity cannot initiate the workflow process");            } else {                // this is either the first activity defined or specified as an ExtendedAttribute                // since this is defined in XPDL, we don't care if canStart is set.                start = getDefinitionObject().getRelatedOne("DefaultStartWorkflowActivity");            }        } catch (GenericEntityException e) {            throw new WfException(e.getMessage(), e.getNested());        }        if (start == null)            throw new CannotStart("No initial activity available");        if (Debug.verboseOn())             Debug.logVerbose("[WfProcess.start] : Started the workflow process.", module);                    // set the actualStartDate        try {            GenericValue v = getRuntimeObject();            v.set("actualStartDate", UtilDateTime.nowTimestamp());            v.store();        } catch (GenericEntityException e) {            Debug.logWarning("Could not set 'actualStartDate'.", module);            e.printStackTrace();        }                    startActivity(start);    }      /**     * @see org.ofbiz.workflow.WfProcess#manager()     */    public WfProcessMgr manager() throws WfException {        return manager;    }        /**     * @see org.ofbiz.workflow.WfProcess#requester()     */    public WfRequester requester() throws WfException {        return requester;    }       /**     * @see org.ofbiz.workflow.WfProcess#getIteratorStep()     */    public Iterator getIteratorStep() throws WfException {        return activeSteps().iterator();    }       /**     * @see org.ofbiz.workflow.WfProcess#isMemberOfStep(org.ofbiz.workflow.WfActivity)     */    public boolean isMemberOfStep(WfActivity member) throws WfException {        return activeSteps().contains(member);    }        /**     * @see org.ofbiz.workflow.WfProcess#getActivitiesInState(java.lang.String)     */    public Iterator getActivitiesInState(String state) throws WfException, InvalidState {        ArrayList res = new ArrayList();        Iterator i = getIteratorStep();        while (i.hasNext()) {            WfActivity a = (WfActivity) i.next();            if (a.state().equals(state))                res.add(a);        }        return res.iterator();    }      /**     * @see org.ofbiz.workflow.WfProcess#result()     */    public Map result() throws WfException, ResultNotAvailable {        Map resultSig = manager().resultSignature();        Map results = new HashMap();        Map context = processContext();        if (resultSig != null) {            Set resultKeys = resultSig.keySet();            Iterator i = resultKeys.iterator();            while (i.hasNext()) {                Object key = i.next();                if (context.containsKey(key))                    results.put(key, context.get(key));            }        }        return results;    }       /**     * @see org.ofbiz.workflow.WfProcess#howManyStep()     */    public int howManyStep() throws WfException {        return activeSteps().size();    }      /**     * @see org.ofbiz.workflow.WfProcess#receiveResults(org.ofbiz.workflow.WfActivity, java.util.Map)     */    public synchronized void receiveResults(WfActivity activity, Map results) throws WfException, InvalidData {        Map context = processContext();        context.putAll(results);

⌨️ 快捷键说明

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