KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensourcestrategies > crmsfa > common > NoteServices


1 /*
2  * Copyright (c) 2006 - 2007 Open Source Strategies, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the Honest Public License.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * Honest Public License for more details.
11  *
12  * You should have received a copy of the Honest Public License
13  * along with this program; if not, write to Funambol,
14  * 643 Bair Island Road, Suite 305 - Redwood City, CA 94063, USA
15  */

16 /* Copyright (c) 2005-2006 Open Source Strategies, Inc. */
17
18 /*
19  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining a
22  * copy of this software and associated documentation files (the "Software"),
23  * to deal in the Software without restriction, including without limitation
24  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
25  * and/or sell copies of the Software, and to permit persons to whom the
26  * Software is furnished to do so, subject to the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be included
29  * in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
36  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
37  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */

39
40 package com.opensourcestrategies.crmsfa.common;
41
42 import java.util.Map JavaDoc;
43 import java.util.Locale JavaDoc;
44
45 import org.ofbiz.entity.GenericValue;
46 import org.ofbiz.entity.GenericDelegator;
47 import org.ofbiz.service.DispatchContext;
48 import org.ofbiz.service.GenericServiceException;
49 import org.ofbiz.service.LocalDispatcher;
50 import org.ofbiz.service.ServiceUtil;
51 import org.ofbiz.security.Security;
52
53 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;
54 import com.opensourcestrategies.crmsfa.util.UtilCommon;
55
56 /**
57  * Note services. The service documentation is in services_notes.xml.
58  *
59  * @author <a HREF="mailto:leon@opensourcestrategies.com">Leon Torres</a>
60  * @version $Rev: 312 $
61  */

62
63 public class NoteServices {
64
65     public static final String JavaDoc module = NoteServices.class.getName();
66
67     public static Map JavaDoc createAccountNote(DispatchContext dctx, Map JavaDoc context) {
68         return createNoteWithPermission(dctx, context, "CRMSFA_ACCOUNT", "_UPDATE");
69     }
70
71     public static Map JavaDoc createContactNote(DispatchContext dctx, Map JavaDoc context) {
72         return createNoteWithPermission(dctx, context, "CRMSFA_CONTACT", "_UPDATE");
73     }
74
75     public static Map JavaDoc createLeadNote(DispatchContext dctx, Map JavaDoc context) {
76         return createNoteWithPermission(dctx, context, "CRMSFA_LEAD", "_UPDATE");
77     }
78
79     /**
80      * Common createNote method that does everything necessary for note creation.
81      * @param module - Check that user has permission in this module
82      * @param operation - Check that user has permission to perform this action
83      */

84     private static Map JavaDoc createNoteWithPermission(DispatchContext dctx, Map JavaDoc context, String JavaDoc module, String JavaDoc operation) {
85         LocalDispatcher dispatcher = dctx.getDispatcher();
86         Security security = dctx.getSecurity();
87         GenericValue userLogin = (GenericValue) context.get("userLogin");
88         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
89
90         // what party this note is for
91
String JavaDoc partyId = (String JavaDoc) context.get("partyId");
92
93         // make sure userLogin has permission (module, operation) for this party
94
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, module, operation, userLogin, partyId)) {
95             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
96         }
97
98         // create the note
99
try {
100             Map JavaDoc serviceResult = dispatcher.runSync("createPartyNote", context);
101             if (ServiceUtil.isError(serviceResult)) {
102                 return UtilCommon.createAndLogServiceError(serviceResult, "CrmErrorCreateNoteFail", locale, module);
103             }
104         } catch (GenericServiceException e) {
105             return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateNoteFail", locale, module);
106         }
107         return ServiceUtil.returnSuccess();
108     }
109
110     public static Map JavaDoc createCaseNote(DispatchContext dctx, Map JavaDoc context) {
111         LocalDispatcher dispatcher = dctx.getDispatcher();
112         GenericDelegator delegator = dctx.getDelegator();
113         Security security = dctx.getSecurity();
114         GenericValue userLogin = (GenericValue) context.get("userLogin");
115         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
116
117         // what CustRequest this note is for
118
String JavaDoc custRequestId = (String JavaDoc) context.get("custRequestId");
119
120         // make sure userLogin has permission for this case
121
if (!CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, custRequestId)) {
122             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
123         }
124
125         // create the note
126
try {
127             Map JavaDoc serviceResult = dispatcher.runSync("createCustRequestNote", context);
128             if (ServiceUtil.isError(serviceResult)) {
129                 return UtilCommon.createAndLogServiceError(serviceResult, "CrmErrorCreateNoteFail", locale, module);
130             }
131         } catch (GenericServiceException e) {
132             return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateNoteFail", locale, module);
133         }
134         return ServiceUtil.returnSuccess();
135     }
136 }
137
Popular Tags