ofbiz-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacques Le Roux (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OFBIZ-7966) remove build dependency of Order on Marketing
Date Mon, 22 Aug 2016 14:17:20 GMT

    [ https://issues.apache.org/jira/browse/OFBIZ-7966?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15430840#comment-15430840
] 

Jacques Le Roux commented on OFBIZ-7966:
----------------------------------------

Pierre,

OK I missed that this issue depends upon OFBIZ-7967, please make it more explicit than simply
creating the link. Also Jira is a trap for those cases, even if you specify it in a commit,
because it does not refresh the issue on other machines so if you forget to refresh yourself
you miss the information.

Anyway I guess it was not the reason Jacopo complained on the dev ML. More because you called
an event as it was a service. Here is my take. I did it fast between, because I must go now.
Please apply and test with a real case, thanks!
{code}
Index: applications/marketing/servicedef/services.xml
===================================================================
--- applications/marketing/servicedef/services.xml	(revision 1757130)
+++ applications/marketing/servicedef/services.xml	(working copy)
@@ -419,7 +419,7 @@
         <attribute type="String" mode="IN" name="returnId" optional="false"/>
     </service>
 
-    <service name="makeTrackingCodeOrders" engine="java" location="org.apache.ofbiz.marketing.tracking.TrackingCodeEvents"
invoke="makeTrackingCodeOrders" auth="true">
+    <service name="makeTrackingCodeOrders" engine="java" location="org.apache.ofbiz.marketing.marketing.MarketingServices"
invoke="makeTrackingCodeOrders"> 
         <description>Makes a list of TrackingCodeOrder entities to be attached to the
current order</description>
         <attribute name="request" mode="IN" type="javax.servlet.http.HttpServletRequest"/>
         <attribute name="trackingCodeOrders" type="List" mode="OUT" optional="false"/>
Index: applications/marketing/src/main/java/org/apache/ofbiz/marketing/marketing/MarketingServices.java
===================================================================
--- applications/marketing/src/main/java/org/apache/ofbiz/marketing/marketing/MarketingServices.java
(revision 1757074)
+++ applications/marketing/src/main/java/org/apache/ofbiz/marketing/marketing/MarketingServices.java
(working copy)
@@ -19,9 +19,14 @@
 package org.apache.ofbiz.marketing.marketing;
 
 import java.sql.Timestamp;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilDateTime;
 import org.apache.ofbiz.base.util.UtilMisc;
@@ -113,4 +118,96 @@
         }
         return ServiceUtil.returnSuccess();
     }
+    
+    /** Makes a list of TrackingCodeOrder entities to be attached to the current order; called
by the createOrder event; the values in the returned List will not have the orderId set */
+    public static Map<String, Object> makeTrackingCodeOrders(DispatchContext dctx,
Map<String, Object> context) {
+        Delegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        HttpServletRequest request = (HttpServletRequest) context.get("request");
+    
+        java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();
+        List<GenericValue> trackingCodeOrders = new LinkedList<GenericValue>();
+
+        Cookie[] cookies = request.getCookies();
+        Timestamp affiliateReferredTimeStamp = null;
+        String siteId = null;
+        String isBillable = null;
+        String trackingCodeId = null;
+        if (cookies != null && cookies.length > 0) {
+            for (int i = 0; i < cookies.length; i++) {
+                String cookieName = cookies[i].getName();
+
+                //Debug.logInfo(" cookieName is " + cookieName, module);
+                //Debug.logInfo(" cookieValue is " + cookies[i].getValue(), module);
+                // find the siteId cookie if it exists
+                if ("Ofbiz.TKCD.SiteId".equals(cookieName)) {
+                    siteId = cookies[i].getValue();
+                }
+
+                // find the referred timestamp cookie if it exists
+                if ("Ofbiz.TKCD.UpdatedTimeStamp".equals(cookieName)) {
+                    String affiliateReferredTime = cookies[i].getValue();
+                    if (affiliateReferredTime !=null && !affiliateReferredTime.equals(""))
{
+                        try {
+                            affiliateReferredTimeStamp = Timestamp.valueOf(affiliateReferredTime);
+                        } catch (IllegalArgumentException  e) {
+                            Debug.logError(e, "Error parsing affiliateReferredTimeStamp value
from cookie", module);
+                            String error = UtilProperties.getMessage(resourceMarketing, "MarketingServiceError",
locale);
+                            Debug.logInfo(e, error + e.getMessage(), module);
+                            return ServiceUtil.returnError(error);
+                        }
+                    }
+                }
+
+                // find any that start with TKCDB_ for billable tracking code cookies with
isBillable=Y
+                // also and for each TKCDT_ cookie that doesn't have a corresponding billable
code add it to the list with isBillable=N
+                // This cookie value keeps trackingCodeId
+                if (cookieName.startsWith("TKCDB_")) {
+                    isBillable = "Y";
+                    trackingCodeId = cookies[i].getValue();
+                } else if (cookieName.startsWith("TKCDT_")) {
+                    isBillable = "N";
+                    trackingCodeId = cookies[i].getValue();
+                }
+
+            }
+        }
+        GenericValue trackingCode = null;
+        try {
+            trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId
+ "], ignoring this trackingCodeId", module);
+            String error = UtilProperties.getMessage(resourceMarketing, "MarketingServiceError",
locale);
+            Debug.logInfo(e, error + e.getMessage(), module);
+            return ServiceUtil.returnError(error);
+        }
+
+        if (trackingCode != null) {
+            //check effective dates
+            if (trackingCode.get("fromDate") != null && nowStamp.before(trackingCode.getTimestamp("fromDate")))
{
+                if (Debug.infoOn()) Debug.logInfo("The TrackingCode with ID [" + trackingCodeId
+ "] has not yet gone into effect, ignoring this trackingCodeId", module);
+            }
+            if (trackingCode.get("thruDate") != null && nowStamp.after(trackingCode.getTimestamp("thruDate")))
{
+                if (Debug.infoOn()) Debug.logInfo("The TrackingCode with ID [" + trackingCodeId
+ "] has expired, ignoring this trackingCodeId", module);
+            }
+            GenericValue trackingCodeOrder = delegator.makeValue("TrackingCodeOrder",
+                    UtilMisc.toMap("trackingCodeTypeId", trackingCode.get("trackingCodeTypeId"),
+                    "trackingCodeId", trackingCodeId, "isBillable", isBillable, "siteId",
siteId,
+                    "hasExported", "N", "affiliateReferredTimeStamp",affiliateReferredTimeStamp));
+
+            Debug.logInfo(" trackingCodeOrder is " + trackingCodeOrder, module);
+            trackingCodeOrders.add(trackingCodeOrder);
+        } else {
+            // Only log an error if there was a trackingCodeId to begin with
+            if (trackingCodeId != null) {
+                Debug.logError("TrackingCode not found for trackingCodeId [" + trackingCodeId
+ "], ignoring this trackingCodeId.", module);
+                String error = UtilProperties.getMessage(resourceMarketing, "MarketingServiceError",
locale);
+                Debug.logInfo(error, module);
+                return ServiceUtil.returnError(error);
+            }
+        }
+        Map<String, Object> result = ServiceUtil.returnSuccess();
+        result.put("trackingCodeOrders", trackingCodeOrders);
+        return result;
+    }
 }
Index: applications/marketing/src/main/java/org/apache/ofbiz/marketing/tracking/TrackingCodeEvents.java
===================================================================
--- applications/marketing/src/main/java/org/apache/ofbiz/marketing/tracking/TrackingCodeEvents.java
(revision 1757130)
+++ applications/marketing/src/main/java/org/apache/ofbiz/marketing/tracking/TrackingCodeEvents.java
(working copy)
@@ -18,9 +18,7 @@
  *******************************************************************************/
 package org.apache.ofbiz.marketing.tracking;
 
-import java.sql.Timestamp;
 import java.util.LinkedList;
-import java.util.List;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
@@ -429,83 +427,4 @@
         }
         return "success";
     }
-
-    /** Makes a list of TrackingCodeOrder entities to be attached to the current order; called
by the createOrder event; the values in the returned List will not have the orderId set */
-    public static List<GenericValue> makeTrackingCodeOrders(HttpServletRequest request)
{
-        Delegator delegator = (Delegator) request.getAttribute("delegator");
-        java.sql.Timestamp nowStamp = UtilDateTime.nowTimestamp();
-        List<GenericValue> trackingCodeOrders = new LinkedList<GenericValue>();
-
-        Cookie[] cookies = request.getCookies();
-        Timestamp affiliateReferredTimeStamp = null;
-        String siteId = null;
-        String isBillable = null;
-        String trackingCodeId = null;
-        if (cookies != null && cookies.length > 0) {
-            for (int i = 0; i < cookies.length; i++) {
-                String cookieName = cookies[i].getName();
-
-                //Debug.logInfo(" cookieName is " + cookieName, module);
-                //Debug.logInfo(" cookieValue is " + cookies[i].getValue(), module);
-                // find the siteId cookie if it exists
-                if ("Ofbiz.TKCD.SiteId".equals(cookieName)) {
-                    siteId = cookies[i].getValue();
-                }
-
-                // find the referred timestamp cookie if it exists
-                if ("Ofbiz.TKCD.UpdatedTimeStamp".equals(cookieName)) {
-                    String affiliateReferredTime = cookies[i].getValue();
-                    if (affiliateReferredTime !=null && !affiliateReferredTime.equals(""))
{
-                        try {
-                            affiliateReferredTimeStamp = Timestamp.valueOf(affiliateReferredTime);
-                        } catch (IllegalArgumentException  e) {
-                            Debug.logError(e, "Error parsing affiliateReferredTimeStamp value
from cookie", module);
-                        }
-                    }
-                }
-
-                // find any that start with TKCDB_ for billable tracking code cookies with
isBillable=Y
-                // also and for each TKCDT_ cookie that doesn't have a corresponding billable
code add it to the list with isBillable=N
-                // This cookie value keeps trackingCodeId
-                if (cookieName.startsWith("TKCDB_")) {
-                    isBillable = "Y";
-                    trackingCodeId = cookies[i].getValue();
-                } else if (cookieName.startsWith("TKCDT_")) {
-                    isBillable = "N";
-                    trackingCodeId = cookies[i].getValue();
-                }
-
-            }
-        }
-        GenericValue trackingCode = null;
-        try {
-            trackingCode = EntityQuery.use(delegator).from("TrackingCode").where("trackingCodeId",
trackingCodeId).cache().queryOne();
-        } catch (GenericEntityException e) {
-            Debug.logError(e, "Error looking up TrackingCode with trackingCodeId [" + trackingCodeId
+ "], ignoring this trackingCodeId", module);
-        }
-
-        if (trackingCode != null) {
-            //check effective dates
-            if (trackingCode.get("fromDate") != null && nowStamp.before(trackingCode.getTimestamp("fromDate")))
{
-                if (Debug.infoOn()) Debug.logInfo("The TrackingCode with ID [" + trackingCodeId
+ "] has not yet gone into effect, ignoring this trackingCodeId", module);
-            }
-            if (trackingCode.get("thruDate") != null && nowStamp.after(trackingCode.getTimestamp("thruDate")))
{
-                if (Debug.infoOn()) Debug.logInfo("The TrackingCode with ID [" + trackingCodeId
+ "] has expired, ignoring this trackingCodeId", module);
-            }
-            GenericValue trackingCodeOrder = delegator.makeValue("TrackingCodeOrder",
-                    UtilMisc.toMap("trackingCodeTypeId", trackingCode.get("trackingCodeTypeId"),
-                    "trackingCodeId", trackingCodeId, "isBillable", isBillable, "siteId",
siteId,
-                    "hasExported", "N", "affiliateReferredTimeStamp",affiliateReferredTimeStamp));
-
-            Debug.logInfo(" trackingCodeOrder is " + trackingCodeOrder, module);
-            trackingCodeOrders.add(trackingCodeOrder);
-        } else {
-            // Only log an error if there was a trackingCodeId to begin with
-            if (trackingCodeId != null) {
-                Debug.logError("TrackingCode not found for trackingCodeId [" + trackingCodeId
+ "], ignoring this trackingCodeId.", module);
-            }
-        }
-
-        return trackingCodeOrders;
-    }
 }
{code}


> remove build dependency of Order on Marketing
> ---------------------------------------------
>
>                 Key: OFBIZ-7966
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-7966
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: marketing, order
>    Affects Versions: Trunk
>            Reporter: Pierre Smits
>            Assignee: Jacques Le Roux
>             Fix For: Upcoming Branch
>
>         Attachments: OFBIZ-7966-dependency-v2.patch, OFBIZ-7966-dependency.patch
>
>
> Currently there is a build dependency from order - CheckOutEvents.java on marketing -
TrackingCodeEvents.java
> The createOrder function (in CheckOutEvents.java) calls the makeTrackingCodeOrders function
in TrackingCodeEvents.java



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message