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

📄 workflowservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: WorkflowServices.java 5462 2005-08-05 18:35:48Z jonesde $ * * Copyright (c) 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.client;import java.sql.Timestamp;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.List;import java.util.Map;import org.ofbiz.base.util.Debug;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.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.security.Security;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.workflow.WfException;import org.ofbiz.workflow.WfFactory;import org.ofbiz.workflow.WfProcess;/** * Workflow Services - 'Services' and 'Workers' for interaction with Workflow API * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 5462 $ * @since      2.0 */public class WorkflowServices {        public static final String module = WorkflowServices.class.getName();    // -------------------------------------------------------------------    // Client 'Service' Methods    // -------------------------------------------------------------------    /** Cancel Workflow */    public static Map cancelWorkflow(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");                // if we passed in an activity id, lets get the process id instead        try {            GenericValue testObject = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));            if (testObject == null) {                result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);                result.put(ModelService.ERROR_MESSAGE, "Not a valid workflow runtime identifier");                return result;            } else if (testObject.get("workEffortTypeId") != null && testObject.getString("workEffortTypeId").equals("WORK_FLOW")) {                // we are a valid process - do nothing            } else if (testObject.get("workEffortTypeId") != null && testObject.getString("workEffortTypeId").equals("ACTIVITY")) {                // we are a valid activitiy; get the process id                workEffortId = testObject.getString("workEffortParentId");            } else {                result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);                result.put(ModelService.ERROR_MESSAGE, "Not a valid workflow runtime identifier");                return result;            }        } catch (GenericEntityException e) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "Problems looking up runtime object; invalid id");            return result;        }                                           GenericValue userLogin = (GenericValue) context.get("userLogin");        if (!hasPermission(security, workEffortId, userLogin)) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this workflow");            return result;        }        try {            WfProcess process = WfFactory.getWfProcess(delegator, workEffortId);            process.abort();        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }        /** Suspend activity */      public static Map suspendActivity(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");               GenericValue userLogin = (GenericValue) context.get("userLogin");        if (!hasPermission(security, workEffortId, userLogin)) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");            return result;        }        try {            WorkflowClient client = WfFactory.getClient(ctx);            client.suspend(workEffortId);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }        /** Resume activity */    public static Map resumeActivity(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        GenericValue userLogin = (GenericValue) context.get("userLogin");        if (!hasPermission(security, workEffortId, userLogin)) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");            return result;        }        try {            WorkflowClient client = WfFactory.getClient(ctx);            client.resume(workEffortId);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }        /** Change the state of an activity */    public static Map changeActivityState(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        String newState = (String) context.get("newState");        GenericValue userLogin = (GenericValue) context.get("userLogin");        if (!hasPermission(security, workEffortId, userLogin)) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");            return result;        }        try {            WorkflowClient client = WfFactory.getClient(ctx);            client.setState(workEffortId, newState);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }    /** Check the state of an activity */    public static Map checkActivityState(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        try {            WorkflowClient client = WfFactory.getClient(ctx);            result.put("activityState", client.getState(workEffortId));            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }    /** Get the current activity context */    public static Map getActivityContext(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        try {            WorkflowClient client = WfFactory.getClient(ctx);            result.put("activityContext", client.getContext(workEffortId));            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }    /** Appends data to the activity context */    public static Map appendActivityContext(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        Map appendContext = (Map) context.get("currentContext");        if (appendContext == null || appendContext.size() == 0) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "The passed context is empty");        }        GenericValue userLogin = (GenericValue) context.get("userLogin");        if (!hasPermission(security, workEffortId, userLogin)) {            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, "You do not have permission to access this activity");            return result;        }        try {            WorkflowClient client = WfFactory.getClient(ctx);            client.appendContext(workEffortId, appendContext);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (WfException we) {            we.printStackTrace();            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, we.getMessage());        }        return result;    }    /** Assign activity to a new or additional party */    public static Map assignActivity(DispatchContext ctx, Map context) {        Map result = new HashMap();        GenericDelegator delegator = ctx.getDelegator();        Security security = ctx.getSecurity();        String workEffortId = (String) context.get("workEffortId");        String partyId = (String) context.get("partyId");

⌨️ 快捷键说明

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