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

📄 teamservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
字号:
/* * Copyright (C) 2006  Open Source Strategies, Inc. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *//* Copyright (c) 2005-2006 Open Source Strategies, Inc. *//* *  Copyright (c) 2001-2005 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 com.opensourcestrategies.crmsfa.teams;import java.util.Map;import java.util.Locale;import java.util.List;import java.util.Iterator;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;import org.ofbiz.security.Security;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;import com.opensourcestrategies.crmsfa.party.PartyHelper;import com.opensourcestrategies.crmsfa.util.UtilCommon;/** * Team services. The service documentation is in services_teams.xml. * * @author     <a href="mailto:leon@opensourcestrategies.com">Leon Torres</a> * @version    $Rev: 1 $ */public class TeamServices {    public static final String module = TeamServices.class.getName();    // TODO: if duplicates become an issue with this service, first ensure there are no ASSIGNED_TO relationships before proceeding    public static Map assignTeamToAccount(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        Locale locale = (Locale) context.get("locale");        GenericValue userLogin = (GenericValue) context.get("userLogin");        String accountPartyId = (String) context.get("accountPartyId");        String teamPartyId = (String) context.get("teamPartyId");        // ensure team assign permission on this account        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_TEAM", "_ASSIGN", userLogin, accountPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        try {            // assign the team            PartyHelper.copyToPartyRelationships(teamPartyId, "ACCOUNT_TEAM", accountPartyId, "ACCOUNT", userLogin, delegator, dispatcher);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map addTeamMember(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        Locale locale = (Locale) context.get("locale");        GenericValue userLogin = (GenericValue) context.get("userLogin");        String teamMemberPartyId = (String) context.get("teamMemberPartyId");        String accountTeamPartyId = (String) context.get("accountTeamPartyId");        String securityGroupId = (String) context.get("securityGroupId");        // ensure team assign permission on this account        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_TEAM", "_ASSIGN", userLogin, accountTeamPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        try {            // get the first valid role for the accountTeamPartyId (which could be either ACCOUNT or ACCOUT_TEAM)            String roleTypeIdFrom = PartyHelper.getFirstValidRoleTypeId(accountTeamPartyId, UtilMisc.toList("ACCOUNT", "ACCOUNT_TEAM"), delegator);            // the the first valid role for the team member (which could be either ACCOUNT_MANAGER, ACCOUNT_REP, or CUST_SERVICE_REP)            String roleTypeIdTo = PartyHelper.getFirstValidRoleTypeId(teamMemberPartyId, UtilMisc.toList("ACCOUNT_MANAGER", "ACCOUNT_REP", "CUS_SERVICE_REP"), delegator);            // find out if the candidate is already a member in this role            List relationships = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", accountTeamPartyId, "partyRelationshipTypeId", "ASSIGNED_TO",                         "roleTypeIdFrom", roleTypeIdFrom, "partyIdTo", teamMemberPartyId, "roleTypeIdFrom", roleTypeIdFrom));            List activeRelations = EntityUtil.filterByDate(relationships, UtilDateTime.nowTimestamp()); // filter out expired relationships            if (activeRelations.size() > 0) {                return UtilCommon.createAndLogServiceError("CrmErrorAlreadyMember", locale, module);            }            // create the PartyRelationship            Map input = UtilMisc.toMap("partyIdFrom", accountTeamPartyId,"roleTypeIdFrom", roleTypeIdFrom , "partyIdTo", teamMemberPartyId, "roleTypeIdTo", roleTypeIdTo);            input.put("partyRelationshipTypeId", "ASSIGNED_TO");            input.put("securityGroupId", securityGroupId);            input.put("fromDate", UtilDateTime.nowTimestamp());            input.put("userLogin", userLogin);            Map serviceResults = dispatcher.runSync("createPartyRelationship", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorAssignFail", locale, module);            }        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map removeTeamMember(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        Locale locale = (Locale) context.get("locale");        GenericValue userLogin = (GenericValue) context.get("userLogin");        String teamMemberPartyId = (String) context.get("teamMemberPartyId");        String accountTeamPartyId = (String) context.get("accountTeamPartyId");        // ensure team remove permission on this account        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_TEAM", "_REMOVE", userLogin, accountTeamPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        try {            // get the first valid role for the accountTeamPartyId (which could be either ACCOUNT or ACCOUT_TEAM)            String roleTypeIdFrom = PartyHelper.getFirstValidRoleTypeId(accountTeamPartyId, UtilMisc.toList("ACCOUNT", "ACCOUNT_TEAM"), delegator);            // find all relationships where partyIdFrom = accountTeamPartyId, partyIdTo=teamMemberPartyId, roleTypeIdFrom = one just found            List relationships = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", accountTeamPartyId,                         "roleTypeIdFrom", roleTypeIdFrom, "partyIdTo", teamMemberPartyId));            // expire them as of now            PartyHelper.expirePartyRelationships(relationships, UtilDateTime.nowTimestamp(), dispatcher, userLogin);                    } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map setTeamMemberSecurityGroup(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        Locale locale = (Locale) context.get("locale");        GenericValue userLogin = (GenericValue) context.get("userLogin");        String teamMemberPartyId = (String) context.get("teamMemberPartyId");        String accountTeamPartyId = (String) context.get("accountTeamPartyId");        String securityGroupId = (String) context.get("securityGroupId");        // ensure team update permission on this account        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_TEAM", "_UPDATE", userLogin, accountTeamPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        try {            // find the relationships of this team member on this account of relationship type ASSIGNED_TO            List relationships = delegator.findByAnd("PartyRelationship", UtilMisc.toMap("partyIdFrom", accountTeamPartyId,                         "partyRelationshipTypeId", "ASSIGNED_TO", "partyIdTo", teamMemberPartyId));            // get the active relationships as of now            List activeRelations = EntityUtil.filterByDate(relationships, UtilDateTime.nowTimestamp());            // expire them as of now            PartyHelper.expirePartyRelationships(activeRelations, UtilDateTime.nowTimestamp(), dispatcher, userLogin);            // for each _active_ relationship (which is why we filtered them), create a new one with the changed securityGroupId            for (Iterator iter = activeRelations.iterator(); iter.hasNext(); ) {                GenericValue relationship = (GenericValue) iter.next();                Map input = UtilMisc.toMap("partyIdFrom", accountTeamPartyId, "roleTypeIdFrom", relationship.getString("roleTypeIdFrom"), "partyIdTo", teamMemberPartyId, "roleTypeIdTo", relationship.getString("roleTypeIdTo"));                input.put("partyRelationshipTypeId", "ASSIGNED_TO");                input.put("securityGroupId", securityGroupId);                input.put("fromDate", UtilDateTime.nowTimestamp());                input.put("userLogin", userLogin);                Map serviceResults = dispatcher.runSync("createPartyRelationship", input);                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorAssignFail", locale, module);                }            }        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorAssignFail", locale, module);        }        return ServiceUtil.returnSuccess();    }}

⌨️ 快捷键说明

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