KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > party > contact > ContactMechServices


1 /*
2  * $Id: ContactMechServices.java 6486 2006-01-10 00:58:40Z sichen $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.party.contact;
25
26 import java.sql.Timestamp JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.LinkedList JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.Locale JavaDoc;
33
34 import org.ofbiz.base.util.Debug;
35 import org.ofbiz.base.util.UtilDateTime;
36 import org.ofbiz.base.util.UtilMisc;
37 import org.ofbiz.base.util.UtilProperties;
38 import org.ofbiz.base.util.UtilValidate;
39 import org.ofbiz.entity.GenericDelegator;
40 import org.ofbiz.entity.GenericEntityException;
41 import org.ofbiz.entity.GenericValue;
42 import org.ofbiz.entity.util.EntityUtil;
43 import org.ofbiz.security.Security;
44 import org.ofbiz.service.DispatchContext;
45 import org.ofbiz.service.ModelService;
46 import org.ofbiz.service.ServiceUtil;
47 import org.ofbiz.service.LocalDispatcher;
48 import org.ofbiz.service.GenericServiceException;
49
50
51 /**
52  * Services for Contact Mechanism maintenance
53  *
54  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
55  * @version $Rev: 6486 $
56  * @since 2.0
57  */

58 public class ContactMechServices {
59
60     public static final String JavaDoc module = ContactMechServices.class.getName();
61     public static final String JavaDoc resource = "PartyUiLabels";
62
63     /**
64      * Creates a ContactMech
65      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission
66      *@param ctx The DispatchContext that this service is operating in
67      *@param context Map containing the input parameters
68      *@return Map with the result of the service, the output parameters
69      */

70     public static Map JavaDoc createContactMech(DispatchContext ctx, Map JavaDoc context) {
71         Map JavaDoc result = new HashMap JavaDoc();
72         GenericDelegator delegator = ctx.getDelegator();
73         Security security = ctx.getSecurity();
74         GenericValue userLogin = (GenericValue) context.get("userLogin");
75         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
76         List JavaDoc toBeStored = new LinkedList JavaDoc();
77
78         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_CREATE");
79         String JavaDoc errMsg = null;
80         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
81
82
83         if (result.size() > 0)
84             return result;
85
86         String JavaDoc contactMechTypeId = (String JavaDoc) context.get("contactMechTypeId");
87
88         String JavaDoc newCmId = null;
89         try {
90             newCmId = delegator.getNextSeqId("ContactMech");
91         } catch (IllegalArgumentException JavaDoc e) {
92             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_id_generation_failure", locale);
93             return ServiceUtil.returnError(errMsg);
94         }
95
96         GenericValue tempContactMech = delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", newCmId.toString(), "contactMechTypeId", contactMechTypeId));
97         toBeStored.add(tempContactMech);
98
99         if (!partyId.equals("_NA_")) {
100             toBeStored.add(delegator.makeValue("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", newCmId.toString(),
101                     "fromDate", now, "roleTypeId", context.get("roleTypeId"), "allowSolicitation", context.get("allowSolicitation"), "extension", context.get("extension"))));
102         }
103
104         if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
105             errMsg = UtilProperties.getMessage(resource,"contactmechservices.service_createContactMech_not_be_used_for_POSTAL_ADDRESS", locale);
106             return ServiceUtil.returnError(errMsg);
107         } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
108             errMsg = UtilProperties.getMessage(resource,"contactmechservices.service_createContactMech_not_be_used_for_TELECOM_NUMBER", locale);
109             return ServiceUtil.returnError(errMsg);
110         } else {
111             tempContactMech.set("infoString", context.get("infoString"));
112         }
113
114         try {
115             delegator.storeAll(toBeStored);
116         } catch (GenericEntityException e) {
117             Debug.logWarning(e.toString(), module);
118             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
119             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_write", messageMap, locale);
120             return ServiceUtil.returnError(errMsg);
121         }
122
123         result.put("contactMechId", newCmId.toString());
124         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
125         return result;
126     }
127
128     /**
129      * Updates a ContactMech
130      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_UPDATE permission
131      *@param ctx The DispatchContext that this service is operating in
132      *@param context Map containing the input parameters
133      *@return Map with the result of the service, the output parameters
134      */

135     public static Map JavaDoc updateContactMech(DispatchContext ctx, Map JavaDoc context) {
136         Map JavaDoc result = new HashMap JavaDoc();
137         GenericDelegator delegator = ctx.getDelegator();
138         Security security = ctx.getSecurity();
139         GenericValue userLogin = (GenericValue) context.get("userLogin");
140         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
141         List JavaDoc toBeStored = new LinkedList JavaDoc();
142         boolean isModified = false;
143
144         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_UPDATE");
145         String JavaDoc errMsg = null;
146         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
147
148         if (result.size() > 0)
149             return result;
150
151         String JavaDoc newCmId = null;
152         try {
153             newCmId = delegator.getNextSeqId("ContactMech");
154         } catch (IllegalArgumentException JavaDoc e) {
155             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_id_generation_failure", locale);
156             return ServiceUtil.returnError(errMsg);
157         }
158
159         String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
160         GenericValue contactMech = null;
161         GenericValue partyContactMech = null;
162
163         try {
164             contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
165         } catch (GenericEntityException e) {
166             Debug.logWarning(e.getMessage(), module);
167             contactMech = null;
168         }
169
170         if (!partyId.equals("_NA_")) {
171             // try to find a PartyContactMech with a valid date range
172
try {
173                 List JavaDoc partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true);
174                 partyContactMech = EntityUtil.getFirst(partyContactMechs);
175                 if (partyContactMech == null) {
176                     errMsg = UtilProperties.getMessage(resource,"contactmechservices.cannot_update_specified_contact_info_not_corresponds", locale);
177                     return ServiceUtil.returnError(errMsg);
178                 } else {
179                     toBeStored.add(partyContactMech);
180                 }
181             } catch (GenericEntityException e) {
182                 Debug.logWarning(e.getMessage(), module);
183                 contactMech = null;
184             }
185         }
186         if (contactMech == null) {
187             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_find_specified_contact_info_read", locale);
188             return ServiceUtil.returnError(errMsg);
189         }
190
191         String JavaDoc contactMechTypeId = contactMech.getString("contactMechTypeId");
192
193         // never change a contact mech, just create a new one with the changes
194
GenericValue newContactMech = GenericValue.create(contactMech);
195         GenericValue newPartyContactMech = GenericValue.create(partyContactMech);
196         GenericValue relatedEntityToSet = null;
197
198         if ("POSTAL_ADDRESS".equals(contactMechTypeId)) {
199             errMsg = UtilProperties.getMessage(resource,"contactmechservices.service_updateContactMech_not_be_used_for_POSTAL_ADDRESS", locale);
200             return ServiceUtil.returnError(errMsg);
201         } else if ("TELECOM_NUMBER".equals(contactMechTypeId)) {
202             errMsg = UtilProperties.getMessage(resource,"contactmechservices.service_updateContactMech_not_be_used_for_TELECOM_NUMBER", locale);
203             return ServiceUtil.returnError(errMsg);
204         } else {
205             newContactMech.set("infoString", context.get("infoString"));
206         }
207
208         newPartyContactMech.set("roleTypeId", context.get("roleTypeId"));
209         newPartyContactMech.set("allowSolicitation", context.get("allowSolicitation"));
210
211         if (!newContactMech.equals(contactMech)) isModified = true;
212         if (!newPartyContactMech.equals(partyContactMech)) isModified = true;
213
214         toBeStored.add(newContactMech);
215         toBeStored.add(newPartyContactMech);
216
217         if (isModified) {
218             if (relatedEntityToSet != null) toBeStored.add(relatedEntityToSet);
219
220             newContactMech.set("contactMechId", newCmId.toString());
221             newPartyContactMech.set("contactMechId", newCmId.toString());
222             newPartyContactMech.set("fromDate", now);
223             newPartyContactMech.set("thruDate", null);
224
225             try {
226                 Iterator JavaDoc partyContactMechPurposes = UtilMisc.toIterator(partyContactMech.getRelated("PartyContactMechPurpose"));
227
228                 while (partyContactMechPurposes != null && partyContactMechPurposes.hasNext()) {
229                     GenericValue tempVal = GenericValue.create((GenericValue) partyContactMechPurposes.next());
230
231                     tempVal.set("contactMechId", newCmId.toString());
232                     toBeStored.add(tempVal);
233                 }
234             } catch (GenericEntityException e) {
235                 Debug.logWarning(e.toString(), module);
236                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
237                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_read", messageMap, locale);
238                 return ServiceUtil.returnError(errMsg);
239             }
240
241             partyContactMech.set("thruDate", now);
242             try {
243                 delegator.storeAll(toBeStored);
244             } catch (GenericEntityException e) {
245                 Debug.logWarning(e.toString(), module);
246                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
247                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_write", messageMap, locale);
248                 return ServiceUtil.returnError(errMsg);
249             }
250         } else {
251             String JavaDoc sucMsg = UtilProperties.getMessage(resource,"contactmechservices.no_changes_made_not_updating", locale);
252             result.put("newContactMechId", contactMechId);
253             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
254             result.put(ModelService.SUCCESS_MESSAGE, sucMsg);
255             return result;
256         }
257
258         result.put("newContactMechId", newCmId.toString());
259         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
260         return result;
261     }
262
263     /**
264      * Deletes a ContactMech
265      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_DELETE permission
266      *@param ctx The DispatchContext that this service is operating in
267      *@param context Map containing the input parameters
268      *@return Map with the result of the service, the output parameters
269      */

270     public static Map JavaDoc deleteContactMech(DispatchContext ctx, Map JavaDoc context) {
271         Map JavaDoc result = new HashMap JavaDoc();
272         GenericDelegator delegator = ctx.getDelegator();
273         Security security = ctx.getSecurity();
274         GenericValue userLogin = (GenericValue) context.get("userLogin");
275         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
276
277         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_DELETE");
278         String JavaDoc errMsg = null;
279         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
280
281         if (result.size() > 0)
282             return result;
283
284         // never delete a contact mechanism, just put a to date on the link to the party
285
String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
286         GenericValue partyContactMech = null;
287
288         try {
289             // try to find a PartyContactMech with a valid date range
290
List JavaDoc partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true);
291
292             partyContactMech = EntityUtil.getFirst(partyContactMechs);
293         } catch (GenericEntityException e) {
294             Debug.logWarning(e.toString(), module);
295             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
296             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_read", messageMap, locale);
297             return ServiceUtil.returnError(errMsg);
298         }
299
300         if (partyContactMech == null) {
301             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_no_contact_found", locale);
302             return ServiceUtil.returnError(errMsg);
303         }
304
305         partyContactMech.set("thruDate", UtilDateTime.nowTimestamp());
306         try {
307             partyContactMech.store();
308         } catch (GenericEntityException e) {
309             Debug.logWarning(e.toString(), module);
310             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_contact_info_write", locale);
311             return ServiceUtil.returnError(errMsg);
312         }
313
314         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
315         return result;
316     }
317
318     // ============================================================================
319
// ============================================================================
320

321     /**
322      * Creates a PostalAddress
323      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission
324      *@param ctx The DispatchContext that this service is operating in
325      *@param context Map containing the input parameters
326      *@return Map with the result of the service, the output parameters
327      */

328     public static Map JavaDoc createPostalAddress(DispatchContext ctx, Map JavaDoc context) {
329         Map JavaDoc result = new HashMap JavaDoc();
330         GenericDelegator delegator = ctx.getDelegator();
331         Security security = ctx.getSecurity();
332         GenericValue userLogin = (GenericValue) context.get("userLogin");
333         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
334         List JavaDoc toBeStored = new LinkedList JavaDoc();
335
336         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_CREATE");
337         String JavaDoc errMsg = null;
338         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
339
340         if (result.size() > 0)
341             return result;
342
343         String JavaDoc contactMechTypeId = "POSTAL_ADDRESS";
344
345         String JavaDoc newCmId = null;
346         try {
347             newCmId = delegator.getNextSeqId("ContactMech");
348         } catch (IllegalArgumentException JavaDoc e) {
349             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_id_generation_failure", locale);
350             return ServiceUtil.returnError(errMsg);
351         }
352
353         GenericValue tempContactMech = delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", newCmId.toString(), "contactMechTypeId", contactMechTypeId));
354         toBeStored.add(tempContactMech);
355
356         // don't create a PartyContactMech if there is no party; we define no party as sending _NA_ as partyId
357
if (!partyId.equals("_NA_")) {
358             toBeStored.add(delegator.makeValue("PartyContactMech",
359                     UtilMisc.toMap("partyId", partyId, "contactMechId", newCmId.toString(),
360                         "fromDate", now, "roleTypeId", context.get("roleTypeId"), "allowSolicitation",
361                         context.get("allowSolicitation"), "extension", context.get("extension"))));
362         }
363
364         GenericValue newAddr = delegator.makeValue("PostalAddress", null);
365
366         newAddr.set("contactMechId", newCmId.toString());
367         newAddr.set("toName", context.get("toName"));
368         newAddr.set("attnName", context.get("attnName"));
369         newAddr.set("address1", context.get("address1"));
370         newAddr.set("address2", context.get("address2"));
371         newAddr.set("directions", context.get("directions"));
372         newAddr.set("city", context.get("city"));
373         newAddr.set("postalCode", context.get("postalCode"));
374         newAddr.set("postalCodeExt", context.get("postalCodeExt"));
375         newAddr.set("stateProvinceGeoId", context.get("stateProvinceGeoId"));
376         newAddr.set("countryGeoId", context.get("countryGeoId"));
377         newAddr.set("postalCodeGeoId", context.get("postalCodeGeoId"));
378         toBeStored.add(newAddr);
379
380         try {
381             delegator.storeAll(toBeStored);
382         } catch (GenericEntityException e) {
383             Debug.logWarning(e.toString(), module);
384             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
385             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_write", messageMap, locale);
386             return ServiceUtil.returnError(errMsg);
387         }
388
389         result.put("contactMechId", newCmId.toString());
390         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
391         return result;
392     }
393
394     /**
395      * Updates a PostalAddress
396      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_UPDATE permission
397      *@param ctx The DispatchContext that this service is operating in
398      *@param context Map containing the input parameters
399      *@return Map with the result of the service, the output parameters
400      */

401     public static Map JavaDoc updatePostalAddress(DispatchContext ctx, Map JavaDoc context) {
402         Map JavaDoc result = new HashMap JavaDoc();
403         GenericDelegator delegator = ctx.getDelegator();
404         Security security = ctx.getSecurity();
405         GenericValue userLogin = (GenericValue) context.get("userLogin");
406         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
407         List JavaDoc toBeStored = new LinkedList JavaDoc();
408         boolean isModified = false;
409
410         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_UPDATE");
411         String JavaDoc errMsg = null;
412         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
413
414
415         if (result.size() > 0) {
416             return result;
417         }
418
419         String JavaDoc newCmId = null;
420         try {
421             newCmId = delegator.getNextSeqId("ContactMech");
422         } catch (IllegalArgumentException JavaDoc e) {
423             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_id_generation_failure", locale);
424             return ServiceUtil.returnError(errMsg);
425         }
426
427         String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
428         GenericValue contactMech = null;
429         GenericValue partyContactMech = null;
430
431         try {
432             contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
433         } catch (GenericEntityException e) {
434             Debug.logWarning(e.getMessage(), module);
435             contactMech = null;
436         }
437
438         if (!partyId.equals("_NA_")) {
439             // try to find a PartyContactMech with a valid date range
440
try {
441                 List JavaDoc partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true);
442                 partyContactMech = EntityUtil.getFirst(partyContactMechs);
443                 if (partyContactMech == null) {
444                     errMsg = UtilProperties.getMessage(resource,"contactmechservices.cannot_update_specified_contact_info_not_corresponds", locale);
445                     return ServiceUtil.returnError(errMsg);
446                 } else {
447                     toBeStored.add(partyContactMech);
448                 }
449             } catch (GenericEntityException e) {
450                 Debug.logWarning(e.getMessage(), module);
451                 contactMech = null;
452             }
453         }
454         if (contactMech == null) {
455             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_find_specified_contact_info_read", locale);
456             return ServiceUtil.returnError(errMsg);
457         }
458
459         // never change a contact mech, just create a new one with the changes
460
GenericValue newContactMech = GenericValue.create(contactMech);
461         GenericValue newPartyContactMech = null;
462         if (partyContactMech != null)
463             newPartyContactMech = GenericValue.create(partyContactMech);
464         GenericValue relatedEntityToSet = null;
465
466         if ("POSTAL_ADDRESS".equals(contactMech.getString("contactMechTypeId"))) {
467             GenericValue addr = null;
468
469             try {
470                 addr = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", contactMechId));
471             } catch (GenericEntityException e) {
472                 Debug.logWarning(e.toString(), module);
473                 addr = null;
474             }
475             relatedEntityToSet = GenericValue.create(addr);
476             relatedEntityToSet.set("toName", context.get("toName"));
477             relatedEntityToSet.set("attnName", context.get("attnName"));
478             relatedEntityToSet.set("address1", context.get("address1"));
479             relatedEntityToSet.set("address2", context.get("address2"));
480             relatedEntityToSet.set("directions", context.get("directions"));
481             relatedEntityToSet.set("city", context.get("city"));
482             relatedEntityToSet.set("postalCode", context.get("postalCode"));
483             relatedEntityToSet.set("postalCodeExt", context.get("postalCodeExt"));
484             relatedEntityToSet.set("stateProvinceGeoId", context.get("stateProvinceGeoId"));
485             relatedEntityToSet.set("countryGeoId", context.get("countryGeoId"));
486             relatedEntityToSet.set("postalCodeGeoId", context.get("postalCodeGeoId"));
487             if (addr == null || !relatedEntityToSet.equals(addr)) {
488                 isModified = true;
489             }
490             relatedEntityToSet.set("contactMechId", newCmId.toString());
491         } else {
492             Map JavaDoc messageMap = UtilMisc.toMap("contactMechTypeId", contactMech.getString("contactMechTypeId"));
493             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_update_contact_as_POSTAL_ADDRESS_specified", messageMap, locale);
494             return ServiceUtil.returnError(errMsg);
495         }
496
497         if (newPartyContactMech != null) {
498             newPartyContactMech.set("roleTypeId", context.get("roleTypeId"));
499             newPartyContactMech.set("allowSolicitation", context.get("allowSolicitation"));
500         }
501
502         if (!newContactMech.equals(contactMech)) isModified = true;
503         if (newPartyContactMech != null && !newPartyContactMech.equals(partyContactMech)) isModified = true;
504
505         toBeStored.add(newContactMech);
506         if (newPartyContactMech != null)
507             toBeStored.add(newPartyContactMech);
508
509         if (isModified) {
510             if (relatedEntityToSet != null) toBeStored.add(relatedEntityToSet);
511
512             newContactMech.set("contactMechId", newCmId.toString());
513             if (newPartyContactMech != null) {
514                 newPartyContactMech.set("contactMechId", newCmId.toString());
515                 newPartyContactMech.set("fromDate", now);
516                 newPartyContactMech.set("thruDate", null);
517
518                 try {
519                     Iterator JavaDoc partyContactMechPurposes = UtilMisc.toIterator(partyContactMech.getRelated("PartyContactMechPurpose"));
520
521                     while (partyContactMechPurposes != null && partyContactMechPurposes.hasNext()) {
522                         GenericValue tempVal = GenericValue.create((GenericValue) partyContactMechPurposes.next());
523
524                         tempVal.set("contactMechId", newCmId.toString());
525                         toBeStored.add(tempVal);
526                     }
527                 } catch (GenericEntityException e) {
528                     Debug.logWarning(e.toString(), module);
529                     Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
530                     errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_read", messageMap, locale);
531                     return ServiceUtil.returnError(errMsg);
532                 }
533
534                 partyContactMech.set("thruDate", now);
535             }
536
537             try {
538                 delegator.storeAll(toBeStored);
539             } catch (GenericEntityException e) {
540                 Debug.logWarning(e.toString(), module);
541                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
542                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_write", messageMap, locale);
543                 return ServiceUtil.returnError(errMsg);
544             }
545         } else {
546             String JavaDoc sucMsg = UtilProperties.getMessage(resource,"contactmechservices.no_changes_made_not_updating", locale);
547             result.put("newContactMechId", contactMechId);
548             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
549             result.put(ModelService.SUCCESS_MESSAGE, sucMsg);
550             return result;
551         }
552
553         result.put("newContactMechId", newCmId.toString());
554         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
555         return result;
556     }
557
558     // ============================================================================
559
// ============================================================================
560

561     /**
562      * Creates a TelecomNumber
563      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission
564      *@param ctx The DispatchContext that this service is operating in
565      *@param context Map containing the input parameters
566      *@return Map with the result of the service, the output parameters
567      */

568     public static Map JavaDoc createTelecomNumber(DispatchContext ctx, Map JavaDoc context) {
569         Map JavaDoc result = new HashMap JavaDoc();
570         GenericDelegator delegator = ctx.getDelegator();
571         Security security = ctx.getSecurity();
572         GenericValue userLogin = (GenericValue) context.get("userLogin");
573         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
574         List JavaDoc toBeStored = new LinkedList JavaDoc();
575
576         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_CREATE");
577         String JavaDoc errMsg = null;
578         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
579
580         if (result.size() > 0)
581             return result;
582
583         String JavaDoc contactMechTypeId = "TELECOM_NUMBER";
584
585         String JavaDoc newCmId = null;
586         try {
587             newCmId = delegator.getNextSeqId("ContactMech");
588         } catch (IllegalArgumentException JavaDoc e) {
589             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_id_generation_failure", locale);
590             return ServiceUtil.returnError(errMsg);
591         }
592
593         GenericValue tempContactMech = delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", newCmId.toString(), "contactMechTypeId", contactMechTypeId));
594         toBeStored.add(tempContactMech);
595
596         toBeStored.add(delegator.makeValue("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", newCmId.toString(),
597                     "fromDate", now, "roleTypeId", context.get("roleTypeId"), "allowSolicitation", context.get("allowSolicitation"), "extension", context.get("extension"))));
598
599         toBeStored.add(delegator.makeValue("TelecomNumber", UtilMisc.toMap("contactMechId", newCmId.toString(),
600                     "countryCode", context.get("countryCode"), "areaCode", context.get("areaCode"), "contactNumber", context.get("contactNumber"))));
601
602         try {
603             delegator.storeAll(toBeStored);
604         } catch (GenericEntityException e) {
605             Debug.logWarning(e.toString(), module);
606             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
607             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_contact_info_write", messageMap, locale);
608             return ServiceUtil.returnError(errMsg);
609         }
610
611         result.put("contactMechId", newCmId.toString());
612         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
613         return result;
614     }
615
616     /**
617      * Updates a TelecomNumber
618      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_UPDATE permission
619      *@param ctx The DispatchContext that this service is operating in
620      *@param context Map containing the input parameters
621      *@return Map with the result of the service, the output parameters
622      */

623     public static Map JavaDoc updateTelecomNumber(DispatchContext ctx, Map JavaDoc context) {
624         Map JavaDoc result = new HashMap JavaDoc();
625         GenericDelegator delegator = ctx.getDelegator();
626         Security security = ctx.getSecurity();
627         GenericValue userLogin = (GenericValue) context.get("userLogin");
628         Timestamp JavaDoc now = UtilDateTime.nowTimestamp();
629         List JavaDoc toBeStored = new LinkedList JavaDoc();
630         boolean isModified = false;
631
632         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_UPDATE");
633         String JavaDoc errMsg = null;
634         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
635
636         if (result.size() > 0)
637             return result;
638
639         String JavaDoc newCmId = null;
640         try {
641             newCmId = delegator.getNextSeqId("ContactMech");
642         } catch (IllegalArgumentException JavaDoc e) {
643             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_id_generation_failure", locale);
644             return ServiceUtil.returnError(errMsg);
645         }
646
647         String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
648         GenericValue contactMech = null;
649         GenericValue partyContactMech = null;
650
651         try {
652             contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
653             // try to find a PartyContactMech with a valid date range
654
List JavaDoc partyContactMechs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId), UtilMisc.toList("fromDate")), true);
655
656             partyContactMech = EntityUtil.getFirst(partyContactMechs);
657         } catch (GenericEntityException e) {
658             Debug.logWarning(e.getMessage(), module);
659             contactMech = null;
660             partyContactMech = null;
661         }
662         if (contactMech == null) {
663             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_find_specified_contact_info_read", locale);
664             return ServiceUtil.returnError(errMsg);
665         }
666         if (partyContactMech == null) {
667             errMsg = UtilProperties.getMessage(resource,"contactmechservices.cannot_update_specified_contact_info_not_corresponds", locale);
668             return ServiceUtil.returnError(errMsg);
669         }
670         toBeStored.add(partyContactMech);
671
672         // never change a contact mech, just create a new one with the changes
673
GenericValue newContactMech = GenericValue.create(contactMech);
674         GenericValue newPartyContactMech = GenericValue.create(partyContactMech);
675         GenericValue relatedEntityToSet = null;
676
677         if ("TELECOM_NUMBER".equals(contactMech.getString("contactMechTypeId"))) {
678             GenericValue telNum = null;
679
680             try {
681                 telNum = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
682             } catch (GenericEntityException e) {
683                 Debug.logWarning(e.toString(), module);
684                 telNum = null;
685             }
686             relatedEntityToSet = GenericValue.create(telNum);
687             relatedEntityToSet.set("countryCode", context.get("countryCode"));
688             relatedEntityToSet.set("areaCode", context.get("areaCode"));
689             relatedEntityToSet.set("contactNumber", context.get("contactNumber"));
690
691             if (telNum == null || !relatedEntityToSet.equals(telNum)) {
692                 isModified = true;
693             }
694             relatedEntityToSet.set("contactMechId", newCmId.toString());
695             newPartyContactMech.set("extension", context.get("extension"));
696         } else {
697             Map JavaDoc messageMap = UtilMisc.toMap("contactMechTypeId", contactMech.getString("contactMechTypeId"));
698             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_update_contact_as_TELECOM_NUMBER_specified", messageMap, locale);
699             return ServiceUtil.returnError(errMsg);
700         }
701
702         newPartyContactMech.set("roleTypeId", context.get("roleTypeId"));
703         newPartyContactMech.set("allowSolicitation", context.get("allowSolicitation"));
704
705         if (!newContactMech.equals(contactMech)) isModified = true;
706         if (!newPartyContactMech.equals(partyContactMech)) isModified = true;
707
708         toBeStored.add(newContactMech);
709         toBeStored.add(newPartyContactMech);
710
711         if (isModified) {
712             if (relatedEntityToSet != null) toBeStored.add(relatedEntityToSet);
713
714             newContactMech.set("contactMechId", newCmId.toString());
715             newPartyContactMech.set("contactMechId", newCmId.toString());
716             newPartyContactMech.set("fromDate", now);
717             newPartyContactMech.set("thruDate", null);
718
719             try {
720                 Iterator JavaDoc partyContactMechPurposes = UtilMisc.toIterator(partyContactMech.getRelated("PartyContactMechPurpose"));
721
722                 while (partyContactMechPurposes != null && partyContactMechPurposes.hasNext()) {
723                     GenericValue tempVal = GenericValue.create((GenericValue) partyContactMechPurposes.next());
724
725                     tempVal.set("contactMechId", newCmId.toString());
726                     toBeStored.add(tempVal);
727                 }
728             } catch (GenericEntityException e) {
729                 Debug.logWarning(e.toString(), module);
730                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
731                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_read", messageMap, locale);
732                 return ServiceUtil.returnError(errMsg);
733             }
734
735             partyContactMech.set("thruDate", now);
736             try {
737                 delegator.storeAll(toBeStored);
738             } catch (GenericEntityException e) {
739                 Debug.logWarning(e.toString(), module);
740                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
741                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_change_contact_info_write", messageMap, locale);
742                 return ServiceUtil.returnError(errMsg);
743             }
744         } else {
745             String JavaDoc sucMsg = UtilProperties.getMessage(resource,"contactmechservices.no_changes_made_not_updating", locale);
746             result.put("newContactMechId", contactMechId);
747             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
748             result.put(ModelService.SUCCESS_MESSAGE, sucMsg);
749             return result;
750         }
751
752         result.put("newContactMechId", newCmId.toString());
753         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
754         return result;
755     }
756
757     // ============================================================================
758
// ============================================================================
759

760     /**
761      * Creates a EmailAddress
762      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission
763      *@param ctx The DispatchContext that this service is operating in
764      *@param context Map containing the input parameters
765      *@return Map with the result of the service, the output parameters
766      */

767     public static Map JavaDoc createEmailAddress(DispatchContext ctx, Map JavaDoc context) {
768         Map JavaDoc newContext = new HashMap JavaDoc(context);
769
770         newContext.put("infoString", newContext.get("emailAddress"));
771         newContext.remove("emailAddress");
772         newContext.put("contactMechTypeId", "EMAIL_ADDRESS");
773
774         return createContactMech(ctx, newContext);
775     }
776
777     /**
778      * Updates a EmailAddress
779      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_UPDATE permission
780      *@param ctx The DispatchContext that this service is operating in
781      *@param context Map containing the input parameters
782      *@return Map with the result of the service, the output parameters
783      */

784     public static Map JavaDoc updateEmailAddress(DispatchContext ctx, Map JavaDoc context) {
785         Map JavaDoc newContext = new HashMap JavaDoc(context);
786
787         newContext.put("infoString", newContext.get("emailAddress"));
788         newContext.remove("emailAddress");
789         return updateContactMech(ctx, newContext);
790     }
791
792     // ============================================================================
793
// ============================================================================
794

795     /**
796      * Creates a PartyContactMechPurpose
797      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_CREATE permission
798      *@param ctx The DispatchContext that this service is operating in
799      *@param context Map containing the input parameters
800      *@return Map with the result of the service, the output parameters
801      */

802     public static Map JavaDoc createPartyContactMechPurpose(DispatchContext ctx, Map JavaDoc context) {
803         Map JavaDoc result = new HashMap JavaDoc();
804         GenericDelegator delegator = ctx.getDelegator();
805         Security security = ctx.getSecurity();
806         GenericValue userLogin = (GenericValue) context.get("userLogin");
807
808         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_CREATE");
809         String JavaDoc errMsg = null;
810         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
811
812         if (result.size() > 0)
813             return result;
814
815         // required parameters
816
String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
817         String JavaDoc contactMechPurposeTypeId = (String JavaDoc) context.get("contactMechPurposeTypeId");
818
819         GenericValue tempVal = null;
820
821         try {
822             List JavaDoc allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId), null), true);
823
824             tempVal = EntityUtil.getFirst(allPCMPs);
825         } catch (GenericEntityException e) {
826             Debug.logWarning(e.getMessage(), module);
827             tempVal = null;
828         }
829
830         Timestamp JavaDoc fromDate = UtilDateTime.nowTimestamp();
831
832         if (tempVal != null) {
833             // exists already with valid date, show warning
834
errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_create_new_purpose_already_exists", locale);
835             return ServiceUtil.returnError(errMsg);
836         } else {
837             // no entry with a valid date range exists, create new with open thruDate
838
GenericValue newPartyContactMechPurpose = delegator.makeValue("PartyContactMechPurpose",
839                     UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId,
840                         "fromDate", fromDate));
841
842             try {
843                 delegator.create(newPartyContactMechPurpose);
844             } catch (GenericEntityException e) {
845                 Debug.logWarning(e.getMessage(), module);
846                 Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
847                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_add_purpose_write", messageMap, locale);
848                 return ServiceUtil.returnError(errMsg);
849             }
850         }
851
852         result.put("fromDate", fromDate);
853         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
854         return result;
855     }
856
857     /**
858      * Deletes the PartyContactMechPurpose corresponding to the parameters in the context
859      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_DELETE permission
860      *@param ctx The DispatchContext that this service is operating in
861      *@param context Map containing the input parameters
862      *@return Map with the result of the service, the output parameters
863      */

864     public static Map JavaDoc deletePartyContactMechPurpose(DispatchContext ctx, Map JavaDoc context) {
865         Map JavaDoc result = new HashMap JavaDoc();
866         GenericDelegator delegator = ctx.getDelegator();
867         Security security = ctx.getSecurity();
868         GenericValue userLogin = (GenericValue) context.get("userLogin");
869
870         String JavaDoc partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_DELETE");
871         String JavaDoc errMsg = null;
872         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
873
874         if (result.size() > 0)
875             return result;
876
877         // required parameters
878
String JavaDoc contactMechId = (String JavaDoc) context.get("contactMechId");
879         String JavaDoc contactMechPurposeTypeId = (String JavaDoc) context.get("contactMechPurposeTypeId");
880         Timestamp JavaDoc fromDate = (Timestamp JavaDoc) context.get("fromDate");
881
882         GenericValue pcmp = null;
883
884         try {
885             pcmp = delegator.findByPrimaryKey("PartyContactMechPurpose", UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId, "fromDate", fromDate));
886             if (pcmp == null) {
887                 errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_not_found", locale);
888                 return ServiceUtil.returnError(errMsg);
889             }
890         } catch (GenericEntityException e) {
891             Debug.logWarning(e.getMessage(), module);
892             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
893             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_read", messageMap, locale);
894             return ServiceUtil.returnError(errMsg);
895         }
896
897         pcmp.set("thruDate", UtilDateTime.nowTimestamp());
898         try {
899             pcmp.store();
900         } catch (GenericEntityException e) {
901             Debug.logWarning(e.getMessage(), module);
902             Map JavaDoc messageMap = UtilMisc.toMap("errMessage", e.getMessage());
903             errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_write", messageMap, locale);
904             return ServiceUtil.returnError(errMsg);
905         }
906
907         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
908         return result;
909     }
910     
911     /**
912      * Just wraps the ContactMechWorker method of the same name.
913      *
914      *@param ctx The DispatchContext that this service is operating in
915      *@param context Map containing the input parameters
916      *@return Map with the result of the service, the output parameters
917      */

918     public static Map JavaDoc getPartyContactMechValueMaps(DispatchContext ctx, Map JavaDoc context) {
919         Map JavaDoc result = ServiceUtil.returnSuccess();
920         GenericDelegator delegator = ctx.getDelegator();
921         GenericValue userLogin = (GenericValue) context.get("userLogin");
922         String JavaDoc partyId = (String JavaDoc)context.get("partyId");
923         if (UtilValidate.isEmpty(partyId) ) {
924             if (userLogin != null) {
925                 partyId = userLogin.getString("partyId");
926             } else {
927                 return ServiceUtil.returnError("Both 'partyId' and 'userLogin' are empty.");
928             }
929         }
930         Boolean JavaDoc bShowOld = (Boolean JavaDoc)context.get("showOld");
931         boolean showOld = (bShowOld != null && bShowOld.booleanValue()) ? true : false;
932         String JavaDoc contactMechTypeId = (String JavaDoc)context.get("contactMechTypeId");
933         List JavaDoc valueMaps = ContactMechWorker.getPartyContactMechValueMaps(delegator, partyId, showOld, contactMechTypeId);
934         result.put("valueMaps", valueMaps );
935         return result;
936     }
937
938     /**
939      * Copies all contact mechs from one party to another. Does not delete or overwrite any contact mechs.
940      */

941     public static Map JavaDoc copyPartyContactMechs(DispatchContext dctx, Map JavaDoc context) {
942         GenericDelegator delegator = dctx.getDelegator();
943         LocalDispatcher dispatcher = dctx.getDispatcher();
944         Security security = dctx.getSecurity();
945         GenericValue userLogin = (GenericValue) context.get("userLogin");
946         Locale JavaDoc locale = (Locale JavaDoc) context.get("locale");
947
948         String JavaDoc partyIdFrom = (String JavaDoc) context.get("partyIdFrom");
949         String JavaDoc partyIdTo = (String JavaDoc) context.get("partyIdTo");
950
951         try {
952             // grab all of the non-expired contact mechs using this party worker method
953
List JavaDoc valueMaps = ContactMechWorker.getPartyContactMechValueMaps(delegator, partyIdFrom, false);
954
955             // loop through results
956
for (Iterator JavaDoc iter = valueMaps.iterator(); iter.hasNext(); ) {
957                 Map JavaDoc thisMap = (Map JavaDoc) iter.next();
958                 GenericValue contactMech = (GenericValue) thisMap.get("contactMech");
959                 GenericValue partyContactMech = (GenericValue) thisMap.get("partyContactMech");
960                 List JavaDoc partyContactMechPurposes = (List JavaDoc) thisMap.get("partyContactMechPurposes");
961
962                 // get the contactMechId
963
String JavaDoc contactMechId = contactMech.getString("contactMechId");
964
965                 // create a new party contact mech for the partyIdTo
966
Map JavaDoc serviceResults = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", partyIdTo, "userLogin", userLogin,
967                             "contactMechId", contactMechId, "fromDate", UtilDateTime.nowTimestamp(),
968                             "allowSolicitation", partyContactMech.getString("allowSolicitation"), "extension", partyContactMech.getString("extension")));
969                 if (ServiceUtil.isError(serviceResults)) {
970                     return serviceResults;
971                 }
972
973                 // loop through purposes and copy each as a new purpose for the partyIdTo
974
for (Iterator JavaDoc piter = partyContactMechPurposes.iterator(); piter.hasNext(); ) {
975                     GenericValue purpose = (GenericValue) piter.next();
976                     Map JavaDoc input = UtilMisc.toMap("partyId", partyIdTo, "contactMechId", contactMechId, "userLogin", userLogin);
977                     input.put("contactMechPurposeTypeId", purpose.getString("contactMechPurposeTypeId"));
978                     serviceResults = dispatcher.runSync("createPartyContactMechPurpose", input);
979                     if (ServiceUtil.isError(serviceResults)) {
980                         return serviceResults;
981                     }
982                 }
983             }
984         } catch (GenericServiceException e) {
985             Debug.logError(e, e.getMessage(), module);
986             return ServiceUtil.returnError("Failed to copy contact mechs. Error: " + e.getMessage());
987         }
988         return ServiceUtil.returnSuccess();
989     }
990 }
991
Popular Tags