📄 contactsservices.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.contacts;import java.util.Map;import java.util.List;import java.util.Locale;import java.sql.Date;import java.sql.Timestamp;import javolution.util.FastMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;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.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;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.party.PartyHelper;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;import com.opensourcestrategies.crmsfa.util.UtilCommon;/** * Contacts services. The service documentation is in services_contacts.xml. * * @author <a href="mailto:leon@opensourcestrategies.com">Leon Torres</a> */public class ContactsServices { public static final String module = ContactsServices.class.getName(); public static Map createContact(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); if (!security.hasPermission("CRMSFA_CONTACT_CREATE", userLogin)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } // the net result of creating an contact is the generation of a Contact partyId String contactPartyId = null; try { // create the Party and Person, which results in a partyId Map input = UtilMisc.toMap("firstName", context.get("firstName"), "lastName", context.get("lastName")); input.put("firstNameLocal", context.get("firstNameLocal")); input.put("lastNameLocal", context.get("lastNameLocal")); input.put("personalTitle", context.get("personalTitle")); input.put("preferredCurrencyUomId", context.get("preferredCurrencyUomId")); input.put("description", context.get("description")); input.put("birthDate", context.get("birthDate")); Map serviceResults = dispatcher.runSync("createPerson", input); if (ServiceUtil.isError(serviceResults)) { return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateContactFail", locale, module); } contactPartyId = (String) serviceResults.get("partyId"); // create a PartyRole for the resulting Contact partyId with roleTypeId = CONTACT serviceResults = dispatcher.runSync("createPartyRole", UtilMisc.toMap("partyId", contactPartyId, "roleTypeId", "CONTACT", "userLogin", userLogin)); if (ServiceUtil.isError(serviceResults)) { return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateContactFail", locale, module); } // create PartySupplementalData GenericValue partyData = delegator.makeValue("PartySupplementalData", UtilMisc.toMap("partyId", contactPartyId)); partyData.setNonPKFields(context); partyData.create(); // create a party relationship between the userLogin and the Contact with partyRelationshipTypeId RESPONSIBLE_FOR createResponsibleContactRelationshipForParty(userLogin.getString("partyId"), contactPartyId, userLogin, delegator, dispatcher); } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateContactFail", locale, module); } catch (GenericEntityException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateContactFail", locale, module); } // return the partyId of the newly created Contact Map results = ServiceUtil.returnSuccess(); results.put("partyId", contactPartyId); results.put("contactPartyId", contactPartyId); return results; } public static Map updateContact(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); String contactPartyId = (String) context.get("partyId"); // make sure userLogin has CRMSFA_CONTACT_UPDATE permission for this contact if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, contactPartyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } try { // update the Party and Person Map input = UtilMisc.toMap("partyId", contactPartyId, "firstName", context.get("firstName"), "lastName", context.get("lastName")); input.put("firstNameLocal", context.get("firstNameLocal")); input.put("lastNameLocal", context.get("lastNameLocal")); input.put("personalTitle", context.get("personalTitle")); input.put("preferredCurrencyUomId", context.get("preferredCurrencyUomId")); input.put("description", context.get("description")); input.put("birthDate", context.get("birthDate")); input.put("userLogin", userLogin); Map serviceResults = dispatcher.runSync("updatePerson", input); if (ServiceUtil.isError(serviceResults)) { return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateContactFail", locale, module); } // update PartySupplementalData
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -