KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
44 import java.util.Locale JavaDoc;
45 import java.util.Iterator JavaDoc;
46
47 import org.ofbiz.base.util.Debug;
48 import org.ofbiz.base.util.UtilMisc;
49 import org.ofbiz.base.util.UtilDateTime;
50 import org.ofbiz.entity.GenericDelegator;
51 import org.ofbiz.entity.GenericEntityException;
52 import org.ofbiz.entity.GenericValue;
53 import org.ofbiz.entity.util.EntityUtil;
54 import org.ofbiz.service.DispatchContext;
55 import org.ofbiz.service.GenericServiceException;
56 import org.ofbiz.service.LocalDispatcher;
57 import org.ofbiz.service.ServiceUtil;
58 import org.ofbiz.security.Security;
59
60 import com.opensourcestrategies.crmsfa.party.PartyHelper;
61 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;
62 import com.opensourcestrategies.crmsfa.util.UtilCommon;
63
64 /**
65  * DataSource services. The service documentation is in services_notes.xml.
66  *
67  * @author <a HREF="mailto:leon@opensourcestrategies.com">Leon Torres</a>
68  * @version $Rev: 312 $
69  */

70
71 public class DataSourceServices {
72
73     public static final String JavaDoc module = DataSourceServices.class.getName();
74
75     public static Map JavaDoc addAccountDataSource(DispatchContext dctx, Map JavaDoc context) {
76         return addDataSourceWithPermission(dctx, context, "CRMSFA_ACCOUNT", "_UPDATE");
77     }
78
79     public static Map JavaDoc addLeadDataSource(DispatchContext dctx, Map JavaDoc context) {
80         return addDataSourceWithPermission(dctx, context, "CRMSFA_LEAD", "_UPDATE");
81     }
82
83     /**
84      * Parametrized service to add a data source to a party. Pass in the security to check.
85      */

86     private static Map JavaDoc addDataSourceWithPermission(DispatchContext dctx, Map JavaDoc context, String JavaDoc module, String JavaDoc operation) {
87         GenericDelegator delegator = dctx.getDelegator();
88         LocalDispatcher dispatcher = dctx.getDispatcher();
89         Security security = dctx.getSecurity();
90         GenericValue userLogin = (GenericValue) context.get("userLogin");
91         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
92
93         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
94         String JavaDoc dataSourceId = (String JavaDoc) context.get("dataSourceId");
95
96         // check parametrized security
97
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, module, operation, userLogin, partyId)) {
98             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
99         }
100         try {
101             // create the PartyDataSource to relate the optional data source to this party
102
Map JavaDoc serviceResults = dispatcher.runSync("createPartyDataSource", UtilMisc.toMap("partyId", partyId , "dataSourceId", dataSourceId, "userLogin", userLogin));
103             if (ServiceUtil.isError(serviceResults)) {
104                 return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorAddDataSource", locale, module);
105             }
106         } catch (GenericServiceException e) {
107             return UtilCommon.createAndLogServiceError(e, "CrmErrorAddDataSource", locale, module);
108         }
109         return ServiceUtil.returnSuccess();
110     }
111
112     public static Map JavaDoc removeAccountDataSource(DispatchContext dctx, Map JavaDoc context) {
113         return removeDataSourceWithPermission(dctx, context, "CRMSFA_ACCOUNT", "_UPDATE");
114     }
115
116     public static Map JavaDoc removeLeadDataSource(DispatchContext dctx, Map JavaDoc context) {
117         return removeDataSourceWithPermission(dctx, context, "CRMSFA_LEAD", "_UPDATE");
118     }
119
120     /**
121      * Parametrized method to remove a data source from a party. Pass in the security to check.
122      * TODO: this isn't implemented until necessary
123      */

124     private static Map JavaDoc removeDataSourceWithPermission(DispatchContext dctx, Map JavaDoc context, String JavaDoc module, String JavaDoc operation) {
125         GenericDelegator delegator = dctx.getDelegator();
126         LocalDispatcher dispatcher = dctx.getDispatcher();
127         Security security = dctx.getSecurity();
128         GenericValue userLogin = (GenericValue) context.get("userLogin");
129         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
130
131         String JavaDoc partyId = (String JavaDoc) context.get("partyId");
132         String JavaDoc dataSourceId = (String JavaDoc) context.get("dataSourceId");
133
134         // check parametrized security
135
if (!CrmsfaSecurity.hasPartyRelationSecurity(security, module, operation, userLogin, partyId)) {
136             return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);
137         }
138
139         // don't do anything yet
140
return ServiceUtil.returnSuccess();
141     }
142 }
143
Popular Tags