Author: nmalin
Date: Fri May 24 15:12:45 2019 New Revision: 1859889 URL: http://svn.apache.org/viewvc?rev=1859889&view=rev Log: Fixed: Backport: 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 Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java?rev=1859889&r1=1859888&r2=1859889&view=diff ============================================================================== --- ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java (original) +++ ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java Fri May 24 15:12:45 2019 @@ -22,6 +22,7 @@ import java.io.IOException; 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; @@ -79,6 +80,8 @@ import org.apache.ofbiz.entity.util.Enti 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; @@ -1097,14 +1100,28 @@ public class GenericDelegator implements ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); - List<GenericValue> removedEntities = null; - if (testMode) { - removedEntities = this.findList(entityName, condition, null, null, null, false); - } - - int rowsAffected = helper.removeByCondition(this, modelEntity, condition); - if (rowsAffected > 0) { - this.clearCacheLine(entityName); + // 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)); + + // 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) { Modified: ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java?rev=1859889&r1=1859888&r2=1859889&view=diff ============================================================================== --- ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java (original) +++ ofbiz/ofbiz-framework/branches/release17.12/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java Fri May 24 15:12:45 2019 @@ -1,4 +1,4 @@ -/******************************************************************************* + /******************************************************************************* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information |
Free forum by Nabble | Edit this page |