📄 wfexecutionobjectimpl.java
字号:
/* * $Id: WfExecutionObjectImpl.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 2001, 2002 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.io.FileNotFoundException;import java.io.IOException;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.ofbiz.base.util.BshUtil;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.ObjectType;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.string.FlexibleStringExpander;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.serialize.SerializeException;import org.ofbiz.entity.serialize.XmlSerializer;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericDispatcher;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.workflow.AlreadySuspended;import org.ofbiz.workflow.CannotResume;import org.ofbiz.workflow.CannotStop;import org.ofbiz.workflow.CannotSuspend;import org.ofbiz.workflow.EvaluationException;import org.ofbiz.workflow.HistoryNotAvailable;import org.ofbiz.workflow.InvalidData;import org.ofbiz.workflow.InvalidState;import org.ofbiz.workflow.NotRunning;import org.ofbiz.workflow.NotSuspended;import org.ofbiz.workflow.TransitionCondition;import org.ofbiz.workflow.TransitionNotAllowed;import org.ofbiz.workflow.UpdateNotAllowed;import org.ofbiz.workflow.WfException;import org.ofbiz.workflow.WfExecutionObject;import org.ofbiz.workflow.WfUtil;/** * WfExecutionObjectImpl - Workflow Execution 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 abstract class WfExecutionObjectImpl implements WfExecutionObject { public static final String module = WfExecutionObjectImpl.class.getName(); public static final String dispatcherName = "WFDispatcher"; protected String packageId = null; protected String packageVersion = null; protected String processId = null; protected String processVersion = null; protected String activityId = null; protected String workEffortId = null; protected GenericDelegator delegator = null; protected List history = null; public WfExecutionObjectImpl(GenericValue valueObject, String parentId) throws WfException { this.packageId = valueObject.getString("packageId"); this.packageVersion = valueObject.getString("packageVersion"); this.processId = valueObject.getString("processId"); this.processVersion = valueObject.getString("processVersion"); if (valueObject.getEntityName().equals("WorkflowActivity")) { this.activityId = valueObject.getString("activityId"); } else { this.activityId = null; } this.delegator = valueObject.getDelegator(); createRuntime(parentId); } public WfExecutionObjectImpl(GenericDelegator delegator, String workEffortId) throws WfException { this.delegator = delegator; this.workEffortId = workEffortId; this.packageId = getRuntimeObject().getString("workflowPackageId"); this.packageVersion = getRuntimeObject().getString("workflowPackageVersion"); this.processId = getRuntimeObject().getString("workflowProcessId"); this.processVersion = getRuntimeObject().getString("workflowProcessVersion"); this.activityId = getRuntimeObject().getString("workflowActivityId"); this.history = null; if (Debug.verboseOn()) Debug.logVerbose(" Package ID: " + packageId + " V: " + packageVersion, module); if (Debug.verboseOn()) Debug.logVerbose(" Process ID: " + processId + " V: " + processVersion, module); if (Debug.verboseOn()) Debug.logVerbose("Activity ID: " + activityId, module); } // creates the stored runtime workeffort data. private void createRuntime(String parentId) throws WfException { GenericValue valueObject = getDefinitionObject(); GenericValue dataObject = null; workEffortId = getDelegator().getNextSeqId("WorkEffort").toString(); Map dataMap = new HashMap(); String weType = activityId != null ? "ACTIVITY" : "WORK_FLOW"; dataMap.put("workEffortId", workEffortId); dataMap.put("workEffortTypeId", weType); dataMap.put("workEffortParentId", parentId); dataMap.put("workflowPackageId", packageId); dataMap.put("workflowPackageVersion", packageVersion); dataMap.put("workflowProcessId", processId); dataMap.put("workflowProcessVersion", processVersion); dataMap.put("workEffortName", valueObject.getString("objectName")); dataMap.put("description", valueObject.getString("description")); dataMap.put("createdDate", new Timestamp((new Date()).getTime())); dataMap.put("estimatedStartDate", dataMap.get("createdDate")); dataMap.put("lastModifiedDate", dataMap.get("createdDate")); dataMap.put("priority", valueObject.getLong("objectPriority")); dataMap.put("currentStatusId", WfUtil.getOFBStatus("open.not_running.not_started")); if (activityId != null) dataMap.put("workflowActivityId", activityId); if (activityId != null && parentId != null) { GenericValue parentWorkEffort = getWorkEffort(parentId); if (parentWorkEffort != null && parentWorkEffort.get("sourceReferenceId") != null) dataMap.put("sourceReferenceId", parentWorkEffort.getString("sourceReferenceId")); } try { dataObject = getDelegator().makeValue("WorkEffort", dataMap); getDelegator().create(dataObject); String objectId = activityId != null ? activityId : processId; if (Debug.verboseOn()) Debug.logVerbose("Created new runtime object [" + objectId + "] (Workeffort: " + runtimeKey() + ")", module); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } protected void parseDescriptions(Map parseContext) throws WfException { GenericValue runtime = getRuntimeObject(); String name = runtime.getString("workEffortName"); String desc = runtime.getString("description"); String nameExp = FlexibleStringExpander.expandString(name, parseContext); String descExp = FlexibleStringExpander.expandString(desc, parseContext); boolean changed = false; if (nameExp != null && !nameExp.equals(name)) { changed = true; runtime.set("workEffortName", nameExp); } if (descExp != null && !descExp.equals(desc)) { changed = true; runtime.set("description", descExp); } if (changed) { try { runtime.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } } /** * @see org.ofbiz.workflow.WfExecutionObject#name() */ public String name() throws WfException { return getRuntimeObject().getString("workEffortName"); } /** * @see org.ofbiz.workflow.WfExecutionObject#setName(java.lang.String) */ public void setName(String newValue) throws WfException { GenericValue dataObject = getRuntimeObject(); try { dataObject.set("workEffortName", newValue); dataObject.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } /** * @see org.ofbiz.workflow.WfExecutionObject#setPriority(long) */ public void setPriority(long newValue) throws WfException { GenericValue dataObject = getRuntimeObject(); try { dataObject.set("priority", new Long(newValue)); dataObject.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } /** * @see org.ofbiz.workflow.WfExecutionObject#priority() */ public long priority() throws WfException { if (getRuntimeObject().get("priority") != null) return getRuntimeObject().getLong("priority").longValue(); return 0; // change to default priority value } /** * @see org.ofbiz.workflow.WfExecutionObject#state() */ public String state() throws WfException { GenericValue statusObj = null; String stateStr = null; try { statusObj = getRuntimeObject().getRelatedOne("CurrentStatusItem"); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } if (statusObj != null) stateStr = statusObj.getString("statusCode"); if (stateStr == null) throw new WfException("Stored state is not a valid type."); if (Debug.verboseOn()) Debug.logVerbose("Current state: " + stateStr, module); return stateStr; } /** * @see org.ofbiz.workflow.WfExecutionObject#validStates() */ public List validStates() throws WfException { String statesArr[] = {"open.running", "open.not_running.not_started", "open.not_running.suspended", "closed.completed", "closed.terminated", "closed.aborted"}; ArrayList possibleStates = new ArrayList(Arrays.asList(statesArr)); String currentState = state(); if (currentState.startsWith("closed")) return new ArrayList(); if (!currentState.startsWith("open")) throw new WfException("Currently in an unknown state."); if (currentState.equals("open.running")) { possibleStates.remove("open.running"); possibleStates.remove("open.not_running.not_started"); return possibleStates; } if (currentState.equals("open.not_running.not_started")) { possibleStates.remove("open.not_running.not_started"); possibleStates.remove("open.not_running.suspended"); possibleStates.remove("closed.completed"); possibleStates.remove("closed.terminated"); return possibleStates; } if (currentState.equals("open.not_running.suspended")) { possibleStates.remove("open.not_running.suspended"); possibleStates.remove("open.not_running.not_started"); possibleStates.remove("closed.complete"); possibleStates.remove("closed.terminated"); return possibleStates; } return new ArrayList(); } /** * @see org.ofbiz.workflow.WfExecutionObject#howManyHistory() */ public int howManyHistory() throws WfException, HistoryNotAvailable { if (history.size() < 1) throw new HistoryNotAvailable(); return history.size(); } /** * @see org.ofbiz.workflow.WfExecutionObject#abort() */ public void abort() throws WfException, CannotStop, NotRunning { Debug.logInfo("Aborting current state : " + state(), module); String stateStr = "closed.aborted"; if (!state().startsWith("open")) { throw new NotRunning(); } if (!validStates().contains(stateStr)) { throw new CannotStop(); } changeState(stateStr); } /** * @see org.ofbiz.workflow.WfExecutionObject#whileOpenType() */ public List whileOpenType() throws WfException { String[] list = {"running", "not_running"}; return Arrays.asList(list); } /** * @see org.ofbiz.workflow.WfExecutionObject#whyNotRunningType() */ public List whyNotRunningType() throws WfException { String[] list = {"not_started", "suspended"}; return Arrays.asList(list); } /** * @see org.ofbiz.workflow.WfExecutionObject#runtimeKey() */ public String runtimeKey() throws WfException { return getRuntimeObject().getString("workEffortId"); } /** * @see org.ofbiz.workflow.WfExecutionObject#key() */ public String key() throws WfException { if (activityId != null) return activityId; else return processId; } /** * @see org.ofbiz.workflow.WfExecutionObject#isMemberOfHistory(org.ofbiz.workflow.WfExecutionObject) */ public boolean isMemberOfHistory(WfExecutionObject member) throws WfException { return false; } /** * @see org.ofbiz.workflow.WfExecutionObject#setProcessContext(java.util.Map) */ public void setProcessContext(Map newValue) throws WfException, InvalidData, UpdateNotAllowed { setSerializedData(newValue); } /** * @see org.ofbiz.workflow.WfExecutionObject#setProcessContext(java.lang.String) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -