[OFBiz] SVN: r6486 - trunk/applications/party/src/org/ofbiz/party/contact

sichen@svn.ofbiz.org sichen at svn.ofbiz.org
Mon Jan 9 18:58:43 CST 2006


Author: sichen
Date: 2006-01-09 18:58:40 -0600 (Mon, 09 Jan 2006)
New Revision: 6486

Modified:
   trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java
Log:
Updated copyPartyContactMech to use services instead of creating entities. This fixes a misunderstanding in the way contact mechs work. (Note: they are immutable, hence updating them actually creates new ones. In this case, we just needed new party associations to the same contact mechs. The previous copy method was redundant.)

Modified: trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java
===================================================================
--- trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java	2006-01-09 22:45:28 UTC (rev 6485)
+++ trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java	2006-01-10 00:58:40 UTC (rev 6486)
@@ -958,50 +958,30 @@
                 GenericValue contactMech = (GenericValue) thisMap.get("contactMech");
                 GenericValue partyContactMech = (GenericValue) thisMap.get("partyContactMech");
                 List partyContactMechPurposes = (List) thisMap.get("partyContactMechPurposes");
-                List toBeStored = new LinkedList();
 
-                // only one of these will be set
-                GenericValue postalAddress = (GenericValue) thisMap.get("postalAddress");
-                GenericValue telecomNumber = (GenericValue) thisMap.get("telecomNumber");
+                // get the contactMechId
+                String contactMechId = contactMech.getString("contactMechId");
 
-                // generate the new contactMechId
-                String contactMechId = delegator.getNextSeqId("ContactMech");
-
-                // copy the contact mech
-                GenericValue contactMechNew = delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
-                contactMechNew.setNonPKFields(contactMech.getAllFields());
-                toBeStored.add(contactMechNew);
-
-                // copy the party contact mech for the partyIdTo effective now
-                GenericValue partyContactMechNew = delegator.makeValue("PartyContactMech", UtilMisc.toMap("partyId", partyIdTo, 
-                            "contactMechId", contactMechId, "fromDate", UtilDateTime.nowTimestamp()));
-                partyContactMechNew.setNonPKFields(partyContactMech.getAllFields());
-                toBeStored.add(partyContactMechNew);
-
-                // copy postal address or telecom number if exists
-                if (postalAddress != null) {
-                    GenericValue newPostalAddress = delegator.makeValue("PostalAddress", UtilMisc.toMap("contactMechId", contactMechId));
-                    newPostalAddress.setNonPKFields(postalAddress.getAllFields());
-                    toBeStored.add(newPostalAddress);
-                } else if (telecomNumber != null) {
-                    GenericValue newTelecomNumber = delegator.makeValue("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
-                    newTelecomNumber.setNonPKFields(telecomNumber.getAllFields());
-                    toBeStored.add(newTelecomNumber);
+                // create a new party contact mech for the partyIdTo
+                Map serviceResults = dispatcher.runSync("createPartyContactMech", UtilMisc.toMap("partyId", partyIdTo, "userLogin", userLogin,
+                            "contactMechId", contactMechId, "fromDate", UtilDateTime.nowTimestamp(), 
+                            "allowSolicitation", partyContactMech.getString("allowSolicitation")));
+                if (ServiceUtil.isError(serviceResults)) {
+                    return serviceResults;
                 }
 
-                // loop through purposes and copy each 
+                // loop through purposes and copy each as a new purpose for the partyIdTo
                 for (Iterator piter = partyContactMechPurposes.iterator(); piter.hasNext(); ) {
                     GenericValue purpose = (GenericValue) piter.next();
-                    Map input = UtilMisc.toMap("partyId", partyIdTo, "contactMechId", contactMechId, "fromDate", UtilDateTime.nowTimestamp());
+                    Map input = UtilMisc.toMap("partyId", partyIdTo, "contactMechId", contactMechId, "userLogin", userLogin);
                     input.put("contactMechPurposeTypeId", purpose.getString("contactMechPurposeTypeId"));
-                    GenericValue newPurpose = delegator.makeValue("PartyContactMechPurpose", input); 
-                    toBeStored.add(newPurpose);
+                    serviceResults = dispatcher.runSync("createPartyContactMechPurpose", input);
+                    if (ServiceUtil.isError(serviceResults)) {
+                        return serviceResults;
+                    }
                 }
-
-                // store them all
-                delegator.storeAll(toBeStored);
             }
-        } catch (GenericEntityException e) {
+        } catch (GenericServiceException e) {
             Debug.logError(e, e.getMessage(), module);
             return ServiceUtil.returnError("Failed to copy contact mechs. Error: " + e.getMessage());
         }



More information about the Svn mailing list