svn commit: r569693 - in /ofbiz/trunk/framework/service: servicedef/services.xml src/org/ofbiz/service/ServiceUtil.java

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

svn commit: r569693 - in /ofbiz/trunk/framework/service: servicedef/services.xml src/org/ofbiz/service/ServiceUtil.java

jaz-3
Author: jaz
Date: Sat Aug 25 09:02:35 2007
New Revision: 569693

URL: http://svn.apache.org/viewvc?rev=569693&view=rev
Log:
implemented a simple date based ECA condition

Modified:
    ofbiz/trunk/framework/service/servicedef/services.xml
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java

Modified: ofbiz/trunk/framework/service/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services.xml?rev=569693&r1=569692&r2=569693&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services.xml (original)
+++ ofbiz/trunk/framework/service/servicedef/services.xml Sat Aug 25 09:02:35 2007
@@ -97,4 +97,12 @@
         <description>Interface to describe services used to process incoming email</description>
         <attribute name="messageWrapper" type="org.ofbiz.service.mail.MimeMessageWrapper" mode="IN"/>
     </service>
+
+    <!-- simple condition implementation -->
+    <service name="effectiveDateEcaCondition" engine="java" auth="false" use-transaction="false"
+            location="org.ofbiz.service.ServiceUtil" invoke="genericDateCondition">
+        <implements service="serviceEcaConditionInterface"/>
+        <attribute name="fromDate" mode="IN" type="java.sql.Timestamp" optional="true"/>
+        <attribute name="thruDate" mode="IN" type="java.sql.Timestamp" optional="true"/>
+    </service>
 </services>

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=569693&r1=569692&r2=569693&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Sat Aug 25 09:02:35 2007
@@ -18,38 +18,29 @@
  *******************************************************************************/
 package org.ofbiz.service;
 
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.transaction.Transaction;
-
-import javolution.util.FastMap;
 import javolution.util.FastList;
-
-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 javolution.util.FastMap;
+import org.ofbiz.base.util.*;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.transaction.TransactionUtil;
-import org.ofbiz.entity.transaction.GenericTransactionException;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.transaction.GenericTransactionException;
+import org.ofbiz.entity.transaction.TransactionUtil;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.security.Security;
 import org.ofbiz.service.config.ServiceConfigUtil;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.transaction.Transaction;
+import java.sql.Timestamp;
+import java.util.*;
+
 /**
  * Generic Service Utility Class
  */
@@ -574,6 +565,20 @@
             String errMsg = UtilProperties.getMessage(ServiceUtil.resource, "serviceUtil.unable_to_cancel_job_retries", locale) + " : " + job;
             return ServiceUtil.returnError(errMsg);
         }
+    }
+
+    public static Map genericDateCondition(DispatchContext dctx, Map context) {
+        Timestamp fromDate = (Timestamp) context.get("fromDate");
+        Timestamp thruDate = (Timestamp) context.get("thruDate");
+        Timestamp now = UtilDateTime.nowTimestamp();
+        Boolean reply = Boolean.TRUE;
+                          
+        if (fromDate != null && fromDate.after(now)) reply = Boolean.FALSE;
+        if (thruDate != null && thruDate.before(now)) reply = Boolean.FALSE;
+
+        Map result = ServiceUtil.returnSuccess();
+        result.put("conditionReply", reply);
+        return result;
     }
 
     public static GenericValue getUserLogin(DispatchContext dctx, Map context, String runAsUser) {