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

📄 abstractworkflow.java

📁 Java编译osworkflow工作流系统的安装和源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        List actions = s.getActions();        if ((actions == null) || (actions.size() == 0)) {            return l;        }        for (Iterator iterator2 = actions.iterator(); iterator2.hasNext();) {            ActionDescriptor action = (ActionDescriptor) iterator2.next();            transientVars.put("actionId", new Integer(action.getId()));            //check auto            if (action.getAutoExecute()) {                if (isActionAvailable(action, transientVars, ps, s.getId())) {                    l.add(new Integer(action.getId()));                }            }        }        return l;    }    protected WorkflowStore getPersistence() throws StoreException {        return getConfiguration().getWorkflowStore();    }    protected void checkImplicitFinish(ActionDescriptor action, long id) throws WorkflowException {        WorkflowStore store = getPersistence();        WorkflowEntry entry = store.findEntry(id);        WorkflowDescriptor wf = getConfiguration().getWorkflow(entry.getWorkflowName());        Collection currentSteps = store.findCurrentSteps(id);        boolean isCompleted = true;        for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) {            Step step = (Step) iterator.next();            StepDescriptor stepDes = wf.getStep(step.getStepId());            // if at least on current step have an available action            if (stepDes.getActions().size() > 0) {                isCompleted = false;            }        }        if (isCompleted) {            completeEntry(action, id, currentSteps, WorkflowEntry.COMPLETED);        }    }    /**     * Mark the specified entry as completed, and move all current steps to history.     */    protected void completeEntry(ActionDescriptor action, long id, Collection currentSteps, int state) throws StoreException {        getPersistence().setEntryState(id, state);        Iterator i = new ArrayList(currentSteps).iterator();        while (i.hasNext()) {            Step step = (Step) i.next();            String oldStatus = (action != null) ? action.getUnconditionalResult().getOldStatus() : "Finished";            getPersistence().markFinished(step, (action != null) ? action.getId() : (-1), new Date(), oldStatus, context.getCaller());            getPersistence().moveToHistory(step);        }    }    /**     * Executes a function.     *     * @param function the function to execute     * @param transientVars the transientVars given by the end-user     * @param ps the persistence variables     */    protected void executeFunction(FunctionDescriptor function, Map transientVars, PropertySet ps) throws WorkflowException {        if (function != null) {            String type = function.getType();            Map args = new HashMap(function.getArgs());            for (Iterator iterator = args.entrySet().iterator();                    iterator.hasNext();) {                Map.Entry mapEntry = (Map.Entry) iterator.next();                mapEntry.setValue(getConfiguration().getVariableResolver().translateVariables((String) mapEntry.getValue(), transientVars, ps));            }            FunctionProvider provider = getResolver().getFunction(type, args);            if (provider == null) {                String message = "Could not load FunctionProvider class";                context.setRollbackOnly();                throw new WorkflowException(message);            }            try {                provider.execute(transientVars, args, ps);            } catch (WorkflowException e) {                context.setRollbackOnly();                throw e;            }        }    }    protected boolean passesCondition(ConditionDescriptor conditionDesc, Map transientVars, PropertySet ps, int currentStepId) throws WorkflowException {        String type = conditionDesc.getType();        Map args = new HashMap(conditionDesc.getArgs());        for (Iterator iterator = args.entrySet().iterator();                iterator.hasNext();) {            Map.Entry mapEntry = (Map.Entry) iterator.next();            mapEntry.setValue(getConfiguration().getVariableResolver().translateVariables((String) mapEntry.getValue(), transientVars, ps));        }        if (currentStepId != -1) {            Object stepId = args.get("stepId");            if ((stepId != null) && stepId.equals("-1")) {                args.put("stepId", String.valueOf(currentStepId));            }        }        Condition condition = getResolver().getCondition(type, args);        if (condition == null) {            context.setRollbackOnly();            throw new WorkflowException("Could not load condition");        }        try {            boolean passed = condition.passesCondition(transientVars, args, ps);            if (conditionDesc.isNegate()) {                passed = !passed;            }            return passed;        } catch (Exception e) {            context.setRollbackOnly();            if (e instanceof WorkflowException) {                throw (WorkflowException) e;            }            throw new WorkflowException("Unknown exception encountered when checking condition " + condition, e);        }    }    protected boolean passesConditions(String conditionType, List conditions, Map transientVars, PropertySet ps, int currentStepId) throws WorkflowException {        if ((conditions == null) || (conditions.size() == 0)) {            return true;        }        boolean and = "AND".equals(conditionType);        boolean or = !and;        for (Iterator iterator = conditions.iterator(); iterator.hasNext();) {            AbstractDescriptor descriptor = (AbstractDescriptor) iterator.next();            boolean result;            if (descriptor instanceof ConditionsDescriptor) {                ConditionsDescriptor conditionsDescriptor = (ConditionsDescriptor) descriptor;                result = passesConditions(conditionsDescriptor.getType(), conditionsDescriptor.getConditions(), transientVars, ps, currentStepId);            } else {                result = passesCondition((ConditionDescriptor) descriptor, transientVars, ps, currentStepId);            }            if (and && !result) {                return false;            } else if (or && result) {                return true;            }        }        if (and) {            return true;        } else if (or) {            return false;        } else {            return false;        }    }    protected boolean passesConditions(ConditionsDescriptor descriptor, Map transientVars, PropertySet ps, int currentStepId) throws WorkflowException {        if (descriptor == null) {            return true;        }        return passesConditions(descriptor.getType(), descriptor.getConditions(), transientVars, ps, currentStepId);    }    protected void populateTransientMap(WorkflowEntry entry, Map transientVars, List registers, Integer actionId, Collection currentSteps, PropertySet ps) throws WorkflowException {        transientVars.put("context", context);        transientVars.put("entry", entry);        transientVars.put("store", getPersistence());        transientVars.put("configuration", getConfiguration());        transientVars.put("descriptor", getConfiguration().getWorkflow(entry.getWorkflowName()));        if (actionId != null) {            transientVars.put("actionId", actionId);        }        transientVars.put("currentSteps", new ArrayList(currentSteps));        // now talk to the registers for any extra objects needed in scope        for (Iterator iterator = registers.iterator(); iterator.hasNext();) {            RegisterDescriptor register = (RegisterDescriptor) iterator.next();            Map args = register.getArgs();            String type = register.getType();            Register r = getResolver().getRegister(type, args);            if (r == null) {                String message = "Could not load register class";                context.setRollbackOnly();                throw new WorkflowException(message);            }            try {                transientVars.put(register.getVariableName(), r.registerVariable(context, entry, args, ps));            } catch (Exception e) {                context.setRollbackOnly();                if (e instanceof WorkflowException) {                    throw (WorkflowException) e;                }                throw new WorkflowException("An unknown exception occured while registering variable using register " + r, e);            }        }    }    /**     * @return true if the instance has been explicitly completed is this transition, false otherwise     * @throws WorkflowException     */    protected boolean transitionWorkflow(WorkflowEntry entry, List currentSteps, WorkflowStore store, WorkflowDescriptor wf, ActionDescriptor action, Map transientVars, Map inputs, PropertySet ps) throws WorkflowException {        Map cache = (Map) stateCache.get();        if (cache != null) {            cache.clear();        } else {            stateCache.set(new HashMap());        }        Step step = getCurrentStep(wf, action.getId(), currentSteps, transientVars, ps);        if (action.getValidators().size() > 0) {            verifyInputs(entry, action.getValidators(), Collections.unmodifiableMap(transientVars), ps);        }        //we're leaving the current step, so let's execute its post-functions        //check if we actually have a current step        if (step != null) {            List stepPostFunctions = wf.getStep(step.getStepId()).getPostFunctions();            for (Iterator iterator = stepPostFunctions.iterator();                    iterator.hasNext();) {                FunctionDescriptor function = (FunctionDescriptor) iterator.next();                executeFunction(function, transientVars, ps);            }        }        // preFunctions        List preFunctions = action.getPreFunctions();        for (Iterator iterator = preFunctions.iterator(); iterator.hasNext();) {            FunctionDescriptor function = (FunctionDescriptor) iterator.next();            executeFunction(function, transientVars, ps);        }        // check each conditional result        List conditionalResults = action.getConditionalResults();        List extraPreFunctions = null;        List extraPostFunctions = null;        ResultDescriptor[] theResults = new ResultDescriptor[1];        for (Iterator iterator = conditionalResults.iterator();                iterator.hasNext();) {            ConditionalResultDescriptor conditionalResult = (ConditionalResultDescriptor) iterator.next();            if (passesConditions(null, conditionalResult.getConditions(), Collections.unmodifiableMap(transientVars), ps, (step != null) ? step.getStepId() : (-1))) {                //if (evaluateExpression(conditionalResult.getCondition(), entry, wf.getRegisters(), null, transientVars)) {                theResults[0] = conditionalResult;                if (conditionalResult.getValidators().size() > 0) {                    verifyInputs(entry, conditionalResult.getValidators(), Collections.unmodifiableMap(transientVars), ps);                }                extraPreFunctions = conditionalResult.getPreFunctions();                extraPostFunctions = conditionalResult.getPostFunctions();                break;            }        }        // use unconditional-result if a condition hasn't been met        if (theResults[0] == null) {            theResults[0] = action.getUnconditionalResult();            verifyInputs(entry, theResults[0].getValidators(), Collections.unmodifiableMap(transientVars), ps);            extraPreFunctions = theResults[0].getPreFunctions();            extraPostFunctions = theResults[0].getPostFunctions();        }        if (log.isDebugEnabled()) {            log.debug("theResult=" + theResults[0].getStep() + ' ' + theResults[0].getStatus());        }        if ((extraPreFunctions != null) && (extraPreFunctions.size() > 0)) {            // run any extra pre-functions that haven't been run already            for (Iterator iterator = extraPreFunctions.iterator();                    iterator.hasNext();) {                FunctionDescriptor function = (FunctionDescriptor) iterator.next();                executeFunction(function, transientVars, ps);            }        }        // go to next step        if (theResults[0].getSplit() != 0) {            // the result is a split request, handle it correctly            SplitDescriptor splitDesc = wf.getSplit(theResults[0].getSplit());            Collection results = splitDesc.getResults();            List splitPreFunctions = new ArrayList();            List splitPostFunctions = new ArrayList();            //check all results in the split and verify the input against any validators specified            //also build up all the pre and post functions that should be called.            for (Iterator iterator = results.iterator(); iterator.hasNext();) {                ResultDescriptor resultDescriptor = (ResultDescriptor) iterator.next();                if (resultDescriptor.getValidators().size() > 0) {                    verifyInputs(entry, resultDescriptor.getValidators(), Collections.unmodifiableMap(transientVars), ps);                }                splitPreFunctions.addAll(resultDescriptor.getPreFunctions());                splitPostFunctions.addAll(resultDescriptor.getPostFunctions());            }            // now execute the pre-functions            for (Iterator iterator = splitPreFunctions.iterator();                    iterator.hasNext();) {                FunctionDescriptor function = (FunctionDescriptor) iterator.next();                executeFunction(function, transientVars, ps);            }            if (!action.isFinish()) {                // now make these steps...                boolean moveFirst = true;                theResults = new ResultDescriptor[results.size()];                results.toArray(theResults);                for (Iterator iterator = results.iterator();                        iterator.hasNext();) {                    ResultDescriptor resultDescriptor = (ResultDescriptor) iterator.next();                    Step moveToHistoryStep = null;                    if (moveFirst) {                        moveToHistoryStep = step;                    }                    long[] previousIds = null;                    if (step != null) {                        previousIds = new long[] {step.getId()};                    }                    createNewCurrentStep(resultDescriptor, entry, store, action.getId(), moveToHistoryStep, previousIds, transientVars, ps);                    moveFirst = false;                }            }            // now execute the post-functions            for (Iterator iterator = splitPostFunctions.iterator();                    iterator.hasNext();) {                FunctionDescriptor function = (FunctionDescriptor) iterator.next();                executeFunction(function, transientVars, ps);            }        } else if (theResults[0].getJoin() != 0) {            // this is a join, finish this step...            JoinDescriptor joinDesc = wf.getJoin(theResults[0].getJoin());            step = store.markFinished(step, action.getId(), new Date(), theResults[0].getOldStatus(), context.getCaller());            store.moveToHistory(step);            // ... now check to see if the expression evaluates

⌨️ 快捷键说明

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