KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensourcestrategies > crmsfa > party > PartyContactServices


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

41 package com.opensourcestrategies.crmsfa.party;
42
43 import java.util.Map JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.Locale JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.sql.Timestamp JavaDoc;
49
50 import javolution.util.FastMap;
51
52 import org.ofbiz.base.util.Debug;
53 import org.ofbiz.base.util.UtilMisc;
54 import org.ofbiz.base.util.UtilDateTime;
55 import org.ofbiz.entity.GenericDelegator;
56 import org.ofbiz.entity.GenericEntityException;
57 import org.ofbiz.entity.GenericValue;
58 import org.ofbiz.service.DispatchContext;
59 import org.ofbiz.service.GenericServiceException;
60 import org.ofbiz.service.LocalDispatcher;
61 import org.ofbiz.service.ServiceUtil;
62 import org.ofbiz.security.Security;
63
64 import com.opensourcestrategies.crmsfa.party.PartyHelper;
65 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;
66 import com.opensourcestrategies.crmsfa.util.UtilCommon;
67
68 /**
69  * PartyContact services. The service documentation is in services_party.xml.
70  *
71  * @author <a HREF="mailto:leon@opensourcestrategies.com">Leon Torres</a>
72  * @version $Rev: 312 $
73  */

74
75 public class PartyContactServices {
76
77     public static final String JavaDoc module = PartyContactServices.class.getName();
78
79     public static Map JavaDoc createBasicContactInfoForParty(DispatchContext dctx, Map JavaDoc context) {
80         GenericDelegator delegator = dctx.getDelegator();
81         LocalDispatcher dispatcher = dctx.getDispatcher();
82         Security security = dctx.getSecurity();
83         GenericValue userLogin = (GenericValue) context.get("userLogin");
84         Map JavaDoc serviceResults = null; // for collecting service results
85

86         // security
87
if (!security.hasEntityPermission("PARTYMGR", "_PCM_CREATE", userLogin)) {
88             return ServiceUtil.returnError("You do not have permission to update contact information.");
89         }
90         
91         // input
92
String JavaDoc partyId = (String JavaDoc) context.get("partyId");
93         String JavaDoc primaryEmail = (String JavaDoc) context.get("primaryEmail");
94         String JavaDoc primaryWebUrl = (String JavaDoc) context.get("primaryWebUrl");
95         String JavaDoc primaryPhoneCountryCode = (String JavaDoc) context.get("primaryPhoneCountryCode");
96         String JavaDoc primaryPhoneAreaCode = (String JavaDoc) context.get("primaryPhoneAreaCode");
97         String JavaDoc primaryPhoneNumber = (String JavaDoc) context.get("primaryPhoneNumber");
98         String JavaDoc primaryPhoneExtension = (String JavaDoc) context.get("primaryPhoneExtension");
99         String JavaDoc primaryPhoneAskForName = (String JavaDoc) context.get("primaryPhoneAskForName");
100         String JavaDoc generalToName = (String JavaDoc) context.get("generalToName");
101         String JavaDoc generalAttnName = (String JavaDoc) context.get("generalAttnName");
102         String JavaDoc generalAddress1 = (String JavaDoc) context.get("generalAddress1");
103         String JavaDoc generalAddress2 = (String JavaDoc) context.get("generalAddress2");
104         String JavaDoc generalCity = (String JavaDoc) context.get("generalCity");
105         String JavaDoc generalStateProvinceGeoId = (String JavaDoc) context.get("generalStateProvinceGeoId");
106         String JavaDoc generalPostalCode = (String JavaDoc) context.get("generalPostalCode");
107         String JavaDoc generalCountryGeoId = (String JavaDoc) context.get("generalCountryGeoId");
108
109         try {
110             // create primary email
111
if ((primaryEmail != null) && !primaryEmail.equals("")) {
112                 serviceResults = dispatcher.runSync("createPartyEmailAddress", UtilMisc.toMap("partyId", partyId, "userLogin", userLogin,
113                             "contactMechTypeId", "EMAIL_ADDRESS", "contactMechPurposeTypeId", "PRIMARY_EMAIL", "emailAddress", primaryEmail));
114                 if (ServiceUtil.isError(serviceResults)) {
115                     return serviceResults;
116                 }
117             }
118
119             // create primary web url
120
if ((primaryWebUrl != null) && !primaryWebUrl.equals("")) {
121                 serviceResults = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", partyId, "userLogin", userLogin,
122                             "contactMechTypeId", "WEB_ADDRESS", "contactMechPurposeTypeId", "PRIMARY_WEB_URL", "infoString", primaryWebUrl));
123                 if (ServiceUtil.isError(serviceResults)) {
124                     return serviceResults;
125                 }
126             }
127
128             // create primary telecom number
129
if (((primaryPhoneNumber != null) && !primaryPhoneNumber.equals(""))) {
130                 Map JavaDoc input = UtilMisc.toMap("partyId", partyId, "userLogin", userLogin, "contactMechPurposeTypeId", "PRIMARY_PHONE");
131                 input.put("countryCode", primaryPhoneCountryCode);
132                 input.put("areaCode", primaryPhoneAreaCode);
133                 input.put("contactNumber", primaryPhoneNumber);
134                 input.put("extension", primaryPhoneExtension);
135                 input.put("askForName", primaryPhoneAskForName);
136                 serviceResults = dispatcher.runSync("createPartyTelecomNumber", input);
137                 if (ServiceUtil.isError(serviceResults)) {
138                     return serviceResults;
139                 }
140             }
141
142             // create general correspondence postal address
143
if ((generalAddress1 != null) && !generalAddress1.equals("")) {
144                 Map JavaDoc input = UtilMisc.toMap("partyId", partyId, "userLogin", userLogin, "contactMechPurposeTypeId", "GENERAL_LOCATION");
145                 input.put("toName", generalToName);
146                 input.put("attnName", generalAttnName);
147                 input.put("address1", generalAddress1);
148                 input.put("address2", generalAddress2);
149                 input.put("city", generalCity);
150                 input.put("stateProvinceGeoId", generalStateProvinceGeoId);
151                 input.put("postalCode", generalPostalCode);
152                 input.put("countryGeoId", generalCountryGeoId);
153                 serviceResults = dispatcher.runSync("createPartyPostalAddress", input);
154                 if (ServiceUtil.isError(serviceResults)) {
155                     return serviceResults;
156                 }
157                 String JavaDoc contactMechId = (String JavaDoc) serviceResults.get("contactMechId");
158
159                 // also make this address the SHIPPING_LOCATION
160
input = UtilMisc.toMap("partyId", partyId, "userLogin", userLogin, "contactMechId", contactMechId, "contactMechPurposeTypeId", "SHIPPING_LOCATION");
161                 serviceResults = dispatcher.runSync("createPartyContactMechPurpose", input);
162                 if (ServiceUtil.isError(serviceResults)) {
163                     return serviceResults;
164                 }
165             }
166
167         } catch (GenericServiceException e) {
168             Debug.logError(e, e.getMessage(), module);
169             return ServiceUtil.returnError("Unable to create basic contact info: " + e.getMessage());
170         }
171         return ServiceUtil.returnSuccess();
172     }
173
174 }
175
Popular Tags