You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by de...@apache.org on 2017/10/17 11:52:14 UTC

svn commit: r1812394 - in /ofbiz/ofbiz-framework/trunk/framework/service: dtd/service-eca.xsd src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java

Author: deepak
Date: Tue Oct 17 11:52:14 2017
New Revision: 1812394

URL: http://svn.apache.org/viewvc?rev=1812394&view=rev
Log:
Improved: Added ability to disable seca rule (OFBIZ-9826)
We have enabled flag in ServiceEcaRule class, if its set false then seca rule will not be executed.
But there is not way to disable seca.

We can add enabled flag in SECA definition to disable the existing seca rule.
Here is the proposal:
- Add new attribute on seca tag named enabled
- Default value will be true for this.
- If user want to disable existing OOTB seca rule, then user can define same rule in custom component and set the enabled=false
Need to do some changes in code to honor the enabled attribute while loading seca rule.

Also as per current flow if same seca rule is define more then once, system will execute all the rule, ideally it should not execute same rule (same rule, condition and action) if its defined more than one.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/service/dtd/service-eca.xsd
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
    ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/service/dtd/service-eca.xsd
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/dtd/service-eca.xsd?rev=1812394&r1=1812393&r2=1812394&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/dtd/service-eca.xsd (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/dtd/service-eca.xsd Tue Oct 17 11:52:14 2017
@@ -262,5 +262,13 @@ under the License.
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="enabled" default="true">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
 </xs:schema>

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java?rev=1812394&r1=1812393&r2=1812394&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java Tue Oct 17 11:52:14 2017
@@ -55,6 +55,7 @@ public final class ServiceEcaRule implem
         this.eventName = eca.getAttribute("event");
         this.runOnFailure = "true".equals(eca.getAttribute("run-on-failure"));
         this.runOnError = "true".equals(eca.getAttribute("run-on-error"));
+        this.enabled = !"false".equals(eca.getAttribute("enabled"));
 
         for (Element element: UtilXml.childElementList(eca, "condition")) {
             conditions.add(new ServiceEcaCondition(element, true, false));
@@ -199,9 +200,6 @@ public final class ServiceEcaRule implem
             if (this.runOnError != other.runOnError) {
                 return false;
             }
-            if (this.enabled != other.enabled) {
-                return false;
-            }
 
             return true;
         } else {

Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java?rev=1812394&r1=1812393&r2=1812394&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaUtil.java Tue Oct 17 11:52:14 2017
@@ -147,6 +147,11 @@ public final class ServiceEcaUtil {
                     eventMap.put(eventName, rules);
                 }
             }
+            //remove the old rule if found and keep the recent one
+            //This will prevent duplicate rule execution along with enabled/disabled seca workflow
+            if (rules.remove(rule)) {
+                Debug.logWarning("Duplicate Service ECA [" + serviceName + "] on [" + eventName + "] ", module);
+            }
             rules.add(rule);
         }
     }