Author: hansbak
Date: Thu Jan  6 02:15:55 2011
New Revision: 1055711

URL: http://svn.apache.org/viewvc?rev=1055711&view=rev
Log:
when subscribing to a mailing list, the emailaddress is checked if already 
extsts and will be using that party.

Modified:
    
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java

Modified: 
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java?rev=1055711&r1=1055710&r2=1055711&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
 (original)
+++ 
ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
 Thu Jan  6 02:15:55 2011
@@ -19,6 +19,7 @@
 package org.ofbiz.marketing.marketing;
 
 import java.sql.Timestamp;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -30,6 +31,9 @@ import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
@@ -75,7 +79,19 @@ public class MarketingServices {
 
             // associate the email with anonymous user TODO: do we need a 
custom contact mech purpose type, say MARKETING_EMAIL?
             if (partyId == null) {
-                partyId = "_NA_";
+                // Check existing email
+                List conds = 
UtilMisc.toList(EntityCondition.makeCondition("infoString", 
EntityOperator.EQUALS, email));
+                conds.add(EntityCondition.makeCondition("contactMechTypeId", 
EntityOperator.EQUALS, "EMAIL_ADDRESS"));
+                
conds.add(EntityCondition.makeCondition("contactMechPurposeTypeId", 
EntityOperator.EQUALS, "PRIMARY_EMAIL"));
+                conds.add(EntityUtil.getFilterByDateExpr("purposeFromDate", 
"purposeThruDate"));
+                conds.add(EntityUtil.getFilterByDateExpr());
+                List<GenericValue> contacts = 
delegator.findList("PartyContactDetailByPurpose", 
EntityCondition.makeCondition(conds), null, UtilMisc.toList("-fromDate"), null, 
false);
+                if (UtilValidate.isNotEmpty(contacts)) {
+                    GenericValue contact = EntityUtil.getFirst(contacts);
+                    partyId = contact.getString("partyId");
+                } else {
+                    partyId = "_NA_";
+                }
             }
             input = UtilMisc.toMap("userLogin", userLogin, "emailAddress", 
email, "partyId", partyId, "fromDate", fromDate, "contactMechPurposeTypeId", 
"OTHER_EMAIL");
             Map<String, Object> serviceResults = 
dispatcher.runSync("createPartyEmailAddress", input);


Reply via email to