Skip to content
Permalink
Browse files

Fixed: Manage EECAs on delegator.removeBy

(OFBIZ-11040)
When you delete some entities through removeByAnd or removeByCondition, eeca aren't enable and the remove is quite as regard implemented rules.
With
        <eca entity="GoodIndentification" operation="create-store-remove" event="return">
             <action service="indexProductKeywords" mode="sync"/>
        </eca>
And
        delegator.removeByAnd('GoodIdentification', [productId: 'WG-1111'])

The service indexProductKeywords wasn't call for the productId WG-1111

To solve this situation, the idea would be delegator.removeValue for each element to delete when an eeca is present otherwise call the standard helper.removeByCondition.

Thanks to Leila Mekika for raise and fix this issue, Jacques Leroux and Mathieu Lirzin for the review

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1859887 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
nmalin committed May 24, 2019
1 parent 5a9b057 commit a6c3c08cc0fb80e13d20bb815ef994c0115a6efd
Showing with 24 additions and 7 deletions.
  1. +24 −7 framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java
@@ -22,6 +22,7 @@
import java.net.URL;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -80,6 +81,8 @@
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.entity.util.EntityStoreOptions;
import org.apache.ofbiz.entity.util.SequenceUtil;
import org.apache.ofbiz.entityext.eca.EntityEcaRule;
import org.apache.ofbiz.entityext.eca.EntityEcaUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -1073,14 +1076,28 @@ public int removeByCondition(String entityName, EntityCondition condition) throw
ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
GenericHelper helper = getEntityHelper(entityName);

List<GenericValue> removedEntities = null;
if (testMode) {
removedEntities = this.findList(entityName, condition, null, null, null, false);
}
// We check if there are eca rules for this entity
String entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(this.delegatorBaseName);
boolean hasEntityEcaRules = UtilValidate.isNotEmpty(
EntityEcaUtil.getEntityEcaCache(entityEcaReaderName).get(entityName));

int rowsAffected = helper.removeByCondition(this, modelEntity, condition);
if (rowsAffected > 0) {
this.clearCacheLine(entityName);
// When we delete in mass, if we are in test mode or the entity have an eeca linked we will remove one by one
// for test mode to help the rollback
// for eeca to analyse each value to check if a condition match
List<GenericValue> removedEntities = (testMode || hasEntityEcaRules)
? findList(entityName, condition, null, null, null, false)
: Collections.emptyList();

int rowsAffected = 0;
if (! removedEntities.isEmpty()) {
for (GenericValue entity : removedEntities) {
rowsAffected += removeValue(entity);
}
} else {
rowsAffected = helper.removeByCondition(this, modelEntity, condition);
if (rowsAffected > 0) {
this.clearCacheLine(entityName);
}
}

if (testMode) {

0 comments on commit a6c3c08

Please sign in to comment.
You can’t perform that action at this time.