svn commit: r440802 - in /incubator/ofbiz/trunk/applications/marketing: config/MarketingUiLabels.properties servicedef/services.xml src/org/ofbiz/marketing/marketing/ src/org/ofbiz/marketing/marketing/MarketingServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r440802 - in /incubator/ofbiz/trunk/applications/marketing: config/MarketingUiLabels.properties servicedef/services.xml src/org/ofbiz/marketing/marketing/ src/org/ofbiz/marketing/marketing/MarketingServices.java

sichen
Author: sichen
Date: Wed Sep  6 10:38:20 2006
New Revision: 440802

URL: http://svn.apache.org/viewvc?view=rev&rev=440802
Log:
Added service that allows anonymous email sign up for contact lists.  The email is associated with _NA_ party and is distinguished from other anonymous emails by the fromDate of signup.

Added:
    incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/
    incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
Modified:
    incubator/ofbiz/trunk/applications/marketing/config/MarketingUiLabels.properties
    incubator/ofbiz/trunk/applications/marketing/servicedef/services.xml

Modified: incubator/ofbiz/trunk/applications/marketing/config/MarketingUiLabels.properties
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/marketing/config/MarketingUiLabels.properties?view=diff&rev=440802&r1=440801&r2=440802
==============================================================================
--- incubator/ofbiz/trunk/applications/marketing/config/MarketingUiLabels.properties (original)
+++ incubator/ofbiz/trunk/applications/marketing/config/MarketingUiLabels.properties Wed Sep  6 10:38:20 2006
@@ -29,6 +29,7 @@
 ContactListCreate=Create New Contact List
 ContactListIsPublic=Is Public ?
 ContactListIsSingleUse=Is Single Use ?
+ContactListNotFound=Could not find email list [${contactListId}].
 ContactListOptInVerifyCode=Opt-In Verify Code
 ContactListOwnerPartyId=Owner Party Id
 ContactListParty=Contact List Party
@@ -43,12 +44,14 @@
 MarketingCampaign=Marketing Campaign
 MarketingCampaignCreate=Create Marketing Campaign
 MarketingCampaignId=Marketing Campaign Id
+MarketingCampaignInvalidEmailInput=Invalid email address entered.
 MarketingCampaignName=Campaign Name
 MarketingCampaignRoleCreate=Create Marketing Campaign Role
 MarketingCampaignSummary=Campaign Summary
 MarketingMainPage=Main
 MarketingManagerApplication=Marketing Manager Application
 MarketingParentCampaignId=Parent Campaign Id
+MarketingServiceError=There was a problem processing your request.  Please try again.  If the problem persists, please contact us.
 MarketingViewPermissionError=View Permission Error
 
 

Modified: incubator/ofbiz/trunk/applications/marketing/servicedef/services.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/marketing/servicedef/services.xml?view=diff&rev=440802&r1=440801&r2=440802
==============================================================================
--- incubator/ofbiz/trunk/applications/marketing/servicedef/services.xml (original)
+++ incubator/ofbiz/trunk/applications/marketing/servicedef/services.xml Wed Sep  6 10:38:20 2006
@@ -65,6 +65,13 @@
         <description>Remove Promo from MarketingCampaign</description>
         <auto-attributes include="pk" mode="IN" optional="false"/>
     </service>
+    <service name="signUpForContactList" engine="java"
+            location="org.ofbiz.marketing.marketing.MarketingServices" invoke="signUpForContactList" auth="false">
+        <description>Signs an input email up for a ContactList with _NA_ party using the system userLogin.  
+            The intent is for anonymous sign ups to email lists.  Also validates email format.</description>
+        <attribute name="contactListId" type="String" mode="IN" optional="false"/>
+        <attribute name="email" type="String" mode="IN" optional="false"/>
+    </service>
 
     <!-- MarketingCampaignRole Services -->
     <service name="addRoleToMarketingCampaign" default-entity-name="MarketingCampaignRole" engine="simple"

Added: incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java?view=auto&rev=440802
==============================================================================
--- incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java (added)
+++ incubator/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java Wed Sep  6 10:38:20 2006
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2001-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.marketing.marketing;
+
+import java.util.Locale;
+import java.util.Map;
+import java.sql.Timestamp;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.*;
+
+/**
+ * MarketingServices contains static service methods for Marketing Campaigns and Contact Lists.
+ * See the documentation in marketing/servicedef/services.xml and use the service reference in
+ * webtools.  Comments in this file are implemntation notes and technical details.
+ *
+ * @author     <a href="mailto:[hidden email]">Leon Torres</a>
+ */
+public class MarketingServices {
+
+    public static final String module = MarketingServices.class.getName();
+    public static final String resourceMarketing = "MarketingUiLabels";
+    public static final String resourceOrder = "OrderUiLabels";
+
+    public static Map signUpForContactList(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+
+        Timestamp fromDate = UtilDateTime.nowTimestamp();
+        String contactListId = (String) context.get("contactListId");
+        String email = (String) context.get("email");
+
+        if (!UtilValidate.isEmail(email)) {
+            String error = UtilProperties.getMessage(resourceMarketing, "MarketingInvalidEmailInput", locale);
+            return ServiceUtil.returnError(error);
+        }
+
+        try {
+            // locate the contact list
+            Map input = UtilMisc.toMap("contactListId", contactListId);
+            GenericValue contactList = delegator.findByPrimaryKey("ContactList", input);
+            if (contactList == null) {
+                String error = UtilProperties.getMessage(resourceMarketing, "ContactListNotFound", input, locale);
+                return ServiceUtil.returnError(error);
+            }
+
+            // perform actions as the system user
+            GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
+
+            // associate the email with anonymous user TODO: do we need a custom contact mech purpose type, say MARKETING_EMAIL?
+            input = UtilMisc.toMap("userLogin", userLogin, "emailAddress", email, "partyId", "_NA_", "fromDate", fromDate, "contactMechPurposeTypeId", "OTHER_EMAIL");
+            Map serviceResults = dispatcher.runSync("createPartyEmailAddress", input);
+            if (ServiceUtil.isError(serviceResults)) {
+                throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));
+            }
+            String contactMechId = (String) serviceResults.get("contactMechId");
+
+            // create a new association at this fromDate to the anonymous party with status accepted
+            input = UtilMisc.toMap("userLogin", userLogin, "contactListId", contactList.get("contactListId"),
+                    "partyId", "_NA_", "fromDate", fromDate, "statusId", "CLPT_ACCEPTED", "preferredContactMechId", contactMechId);
+            serviceResults = dispatcher.runSync("createContactListParty", input);
+            if (ServiceUtil.isError(serviceResults)) {
+                throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));
+            }
+        } catch (GenericEntityException e) {
+            String error = UtilProperties.getMessage(resourceOrder, "checkhelper.problems_reading_database", locale);
+            Debug.log(e, error + e.getMessage(), module);
+            return ServiceUtil.returnError(error);
+        } catch (GenericServiceException e) {
+            String error = UtilProperties.getMessage(resourceMarketing, "MarketingServiceError", locale);
+            Debug.log(e, error + e.getMessage(), module);
+            return ServiceUtil.returnError(error);
+        }
+        return ServiceUtil.returnSuccess();
+    }
+}