📄 noteservices.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.common;import java.util.Map;import java.util.Locale;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.GenericDelegator;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.util.UtilCommon;/** * Note services. The service documentation is in services_notes.xml. * * @author <a href="mailto:leon@opensourcestrategies.com">Leon Torres</a> * @version $Rev: 1 $ */public class NoteServices { public static final String module = NoteServices.class.getName(); public static Map createAccountNote(DispatchContext dctx, Map context) { return createNoteWithPermission(dctx, context, "CRMSFA_ACCOUNT", "_UPDATE"); } public static Map createContactNote(DispatchContext dctx, Map context) { return createNoteWithPermission(dctx, context, "CRMSFA_CONTACT", "_UPDATE"); } public static Map createLeadNote(DispatchContext dctx, Map context) { return createNoteWithPermission(dctx, context, "CRMSFA_LEAD", "_UPDATE"); } /** * Common createNote method that does everything necessary for note creation. * @param module - Check that user has permission in this module * @param operation - Check that user has permission to perform this action */ private static Map createNoteWithPermission(DispatchContext dctx, Map context, String module, String operation) { LocalDispatcher dispatcher = dctx.getDispatcher(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); // what party this note is for String partyId = (String) context.get("partyId"); // make sure userLogin has permission (module, operation) for this party if (!CrmsfaSecurity.hasPartyRelationSecurity(security, module, operation, userLogin, partyId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } // create the note try { Map serviceResult = dispatcher.runSync("createPartyNote", context); if (ServiceUtil.isError(serviceResult)) { return UtilCommon.createAndLogServiceError(serviceResult, "CrmErrorCreateNoteFail", locale, module); } } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateNoteFail", locale, module); } return ServiceUtil.returnSuccess(); } public static Map createCaseNote(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); Security security = dctx.getSecurity(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); // what CustRequest this note is for String custRequestId = (String) context.get("custRequestId"); // make sure userLogin has permission for this case if (!CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, custRequestId)) { return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module); } // create the note try { Map serviceResult = dispatcher.runSync("createCustRequestNote", context); if (ServiceUtil.isError(serviceResult)) { return UtilCommon.createAndLogServiceError(serviceResult, "CrmErrorCreateNoteFail", locale, module); } } catch (GenericServiceException e) { return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateNoteFail", locale, module); } return ServiceUtil.returnSuccess(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -