📄 wfexecutionobjectimpl.java
字号:
public void setProcessContext(String contextKey) throws WfException, InvalidData, UpdateNotAllowed { GenericValue dataObject = getRuntimeObject(); try { dataObject.set("runtimeDataId", contextKey); dataObject.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } /** * @see org.ofbiz.workflow.WfExecutionObject#contextKey() */ public String contextKey() throws WfException { if (getRuntimeObject().get("runtimeDataId") == null) return null; else return getRuntimeObject().getString("runtimeDataId"); } /** * @see org.ofbiz.workflow.WfExecutionObject#processContext() */ public Map processContext() throws WfException { return getContext(); } /** * @see org.ofbiz.workflow.WfExecutionObject#workflowStateType() */ public List workflowStateType() throws WfException { String[] list = {"open", "closed"}; return Arrays.asList(list); } /** * @see org.ofbiz.workflow.WfExecutionObject#terminate() */ public void terminate() throws WfException, CannotStop, NotRunning { String stateStr = "closed.terminated"; if (!state().equals("open.running")) throw new NotRunning(); if (!validStates().contains(stateStr)) throw new CannotStop(); changeState(stateStr); } /** * @see org.ofbiz.workflow.WfExecutionObject#setDescription(java.lang.String) */ public void setDescription(String newValue) throws WfException { GenericValue valueObject = getDefinitionObject(); try { valueObject.set("description", newValue); valueObject.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } /** * @see org.ofbiz.workflow.WfExecutionObject#description() */ public String description() throws WfException { return getDefinitionObject().getString("description"); } /** * @see org.ofbiz.workflow.WfExecutionObject#lastStateTime() */ public Timestamp lastStateTime() throws WfException { GenericValue dataObject = getRuntimeObject(); if (dataObject == null || dataObject.get("lastStatusUpdate") == null) throw new WfException("No runtime object or status has never been set."); return dataObject.getTimestamp("lastStatusUpdate"); } /** * @see org.ofbiz.workflow.WfExecutionObject#getSequenceHistory(int) */ public List getSequenceHistory(int maxNumber) throws WfException, HistoryNotAvailable { return history; } /** * @see org.ofbiz.workflow.WfExecutionObject#getIteratorHistory(java.lang.String, java.util.Map) */ public Iterator getIteratorHistory(String query, Map namesInQuery) throws WfException, HistoryNotAvailable { return history.iterator(); } /** * @see org.ofbiz.workflow.WfExecutionObject#resume() */ public void resume() throws WfException, CannotResume, NotRunning, NotSuspended { if (!state().equals("open.not_running.suspended")) { if (state().equals("open.not_running.not_started")) { throw new NotRunning(); } else if (state().startsWith("closed")) { throw new CannotResume(); } else { throw new NotSuspended(); } } else { changeState("open.running"); } } /** * @see org.ofbiz.workflow.WfExecutionObject#howClosedType() */ public List howClosedType() throws WfException { String[] list = {"completed", "terminated", "aborted"}; return Arrays.asList(list); } /** * @see org.ofbiz.workflow.WfExecutionObject#changeState(java.lang.String) */ public void changeState(String newState) throws WfException, InvalidState, TransitionNotAllowed { // Test is transaction is allowed??? GenericValue dataObject = getRuntimeObject(); if (validStates().contains(newState)) { try { long now = (new Date()).getTime(); dataObject.set("currentStatusId", WfUtil.getOFBStatus(newState)); dataObject.set("lastStatusUpdate", new Timestamp(now)); dataObject.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } } else { throw new InvalidState(); } } /** * @see org.ofbiz.workflow.WfExecutionObject#suspend() */ public void suspend() throws WfException, CannotSuspend, NotRunning, AlreadySuspended { changeState("open.not_running.suspended"); } /** * @see org.ofbiz.workflow.WfExecutionObject#getDelegator() */ public GenericDelegator getDelegator() throws WfException { return delegator; } /** * @see org.ofbiz.workflow.WfExecutionObject#getDefinitionObject() */ public GenericValue getDefinitionObject() throws WfException { String entityName = activityId != null ? "WorkflowActivity" : "WorkflowProcess"; GenericValue value = null; Map fields = UtilMisc.toMap("packageId", packageId, "packageVersion", packageVersion, "processId", processId, "processVersion", processVersion); if (activityId != null) fields.put("activityId", activityId); try { value = getDelegator().findByPrimaryKey(entityName, fields); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } return value; } public GenericValue getRuntimeObject() throws WfException { GenericValue value = null; try { value = getDelegator().findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } return value; } /** * Getter for this type of execution object. * @return String */ public abstract String executionObjectType(); /** * Updates the runtime data entity * @param field The field name of the entity (resultDataId,contextDataId) * @param value The value to serialize and set * @throws WfException */ protected void setSerializedData(Map value) throws WfException, InvalidData { GenericValue runtimeData = null; GenericValue dataObject = getRuntimeObject(); try { if (dataObject.get("runtimeDataId") == null) { String seqId = getDelegator().getNextSeqId("RuntimeData").toString(); runtimeData = getDelegator().makeValue("RuntimeData", UtilMisc.toMap("runtimeDataId", seqId)); getDelegator().create(runtimeData); dataObject.set("runtimeDataId", seqId); dataObject.store(); } else { runtimeData = dataObject.getRelatedOne("RuntimeData"); } // String serialized = XmlSerializer.serialize(value); // System.out.println(serialized); runtimeData.set("runtimeInfo", XmlSerializer.serialize(value)); runtimeData.store(); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } catch (SerializeException e) { throw new InvalidData(e.getMessage(), e); } catch (FileNotFoundException e) { throw new InvalidData(e.getMessage(), e); } catch (IOException e) { throw new InvalidData(e.getMessage(), e); } } /** * Get an instance of the local dispatcher * @return LocalDispatcher instance for use with this workflow * @throws WfException */ protected LocalDispatcher getDispatcher() throws WfException { try { return GenericDispatcher.getLocalDispatcher(dispatcherName, getDelegator()); } catch (GenericServiceException e) { throw new WfException("No workflow service dispatcher", e); } } private Map getContext() throws WfException { GenericValue dataObject = getRuntimeObject(); String contextXML = null; Map context = null; if (dataObject.get("runtimeDataId") == null) return context; try { GenericValue runtimeData = dataObject.getRelatedOne("RuntimeData"); contextXML = runtimeData.getString("runtimeInfo"); } catch (GenericEntityException e) { throw new WfException(e.getMessage(), e); } // De-serialize the context if (contextXML != null) { try { context = (Map) XmlSerializer.deserialize(contextXML, getDelegator()); } catch (SerializeException e) { throw new WfException(e.getMessage(), e); } catch (IOException e) { throw new WfException(e.getMessage(), e); } catch (Exception e) { throw new WfException(e.getMessage(), e); } } return context; } private GenericValue getWorkEffort(String workEffortId) throws WfException { GenericValue we = null; try { we = getDelegator().findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId)); } catch (GenericEntityException e) { throw new WfException("Problem getting WorkEffort entity (" + workEffortId + ")", e); } return we; } /** * Evaluate a condition expression using an implementation of TransitionCondition * @param className The class name of the TransitionCondition implementation * @param expression The expression to evaluate * @return The result of the evaluation (True/False) * @throws WfException */ protected boolean evalConditionClass(String className, String expression, Map context, Map attrs) throws WfException { // attempt to load and instance of the class Object conditionObject = null; try { conditionObject = ObjectType.getInstance(className); } catch (ClassNotFoundException e) { Debug.logError(e, "Cannot load class " + className, module); return false; } catch (InstantiationException e) { Debug.logError(e, "Cannot get instance of class " + className, module); return false; } catch (IllegalAccessException e) { Debug.logError(e, "Cannot access class " + className, module); return false; } // make sure we implement the TransitionCondition interface if (!ObjectType.instanceOf(conditionObject, "org.ofbiz.workflow.TransitionCondition")) { Debug.logError("Class " + className + " is not an instance of TransitionCondition", module); return false; } // cast to the interface TransitionCondition cond = (TransitionCondition) conditionObject; // trim up the expression if it isn't empty if (expression != null) expression = expression.trim(); // get a DispatchContext object to pass over to the eval DispatchContext dctx = this.getDispatcher().getDispatchContext(); // evaluate the condition Boolean evaluation = null; try { evaluation = cond.evaluateCondition(context, attrs, expression, dctx); } catch (EvaluationException e) { throw new WfException("Problems evaluating condition", e); } return evaluation.booleanValue(); } /** * Evaluate a condition expression using BeanShell * @param expression The expression to evaluate * @param context The context to use in evaluation * @return The result of the evaluation (True/False) * @throws WfException */ protected boolean evalBshCondition(String expression, Map context) throws WfException { if (expression == null || expression.length() == 0) { Debug.logVerbose("Null or empty expression, returning true.", module); return true; } Object o = null; try { o = BshUtil.eval(expression.trim(), context); } catch (bsh.EvalError e) { throw new WfException("Bsh evaluation error.", e); } if (o == null) return false; else if (o instanceof Number) return (((Number) o).doubleValue() == 0) ? false : true; else return (!o.toString().equalsIgnoreCase("true")) ? false : true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -