cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Impex to remove promotion rules and drools rules

0 Kudos
2,746

Hello, I have a lot of promotion, we have been creating promotions rules (and, consequently, drools rules) for 2 years without a stop. So, the system is overloaded. I am thinking about creating a Impex, to eliminate a lot of promotions that make no sense anymore. So the header I was thinking is: REMOVE PromotionSourceRule; code[unique=true] -> to eliminate Promotion Rules

and the header to eliminate the DroolsRules is not ready, because the code is not unique. I am thinking about using the PK.

Has anyone tried this before?

Accepted Solutions (1)

Accepted Solutions (1)

former_member633554
Active Participant
0 Kudos

I tried it but it didn't work very well from memory. I ended writing a groovy script that archives all rules that have expired. I suppose you could modify this to delete after archiving. This will run on a cron every night.

 import static org.mockito.Mockito.when;
 import static org.mockito.MockitoAnnotations.initMocks;
 import de.hybris.bootstrap.annotations.UnitTest;
 import de.hybris.platform.ruleengine.RuleEngineActionResult;
 import de.hybris.platform.ruleengine.RuleEngineService;
 import de.hybris.platform.ruleengine.model.AbstractRuleEngineRuleModel;
 import de.hybris.platform.ruleengine.model.DroolsKIEModuleModel;
 import de.hybris.platform.ruleengineservices.RuleEngineServiceException;
 import de.hybris.platform.ruleengineservices.compiler.RuleCompilerException;
 import de.hybris.platform.ruleengineservices.compiler.RuleCompilerProblem.Severity;
 import de.hybris.platform.ruleengineservices.compiler.RuleCompilerResult;
 import de.hybris.platform.ruleengineservices.compiler.RuleCompilerService;
 import de.hybris.platform.ruleengineservices.compiler.impl.DefaultRuleCompilerProblem;
 import de.hybris.platform.ruleengineservices.compiler.impl.DefaultRuleCompilerResult;
 import de.hybris.platform.ruleengineservices.enums.RuleStatus;
 import de.hybris.platform.ruleengineservices.maintenance.RuleCompilerPublisherResult;
 import de.hybris.platform.ruleengineservices.maintenance.RuleCompilerPublisherResult.Result;
 import de.hybris.platform.ruleengineservices.model.AbstractRuleModel;
 import de.hybris.platform.servicelayer.model.ModelService;
 import de.hybris.platform.ruleengine.*;
 
 $promotionSourceRulesQuery="select {pk},{code},{enddate} from {promotionsourcerule} where ({enddate} < NOW() - INTERVAL 1 DAY and {status}<>'8796153643099')"
 ruleCompilerService = spring.getBean('ruleCompilerService');
 platformRuleEngineService = spring.getBean('platformRuleEngineService');
 flexibleSearchService = spring.getBean('flexibleSearchService');
 ruleMaintenanceService=spring.getBean("ruleMaintenanceService")
 
 List sourceRules = flexibleSearchService.search($promotionSourceRulesQuery).getResult();
 for (sourceRule in sourceRules) { 
   //ruleCompilerService.compile(sourceRule);
   ruleMaintenanceService.archiveRule(sourceRule);
                                 }
 platformRuleEngineService.initializeAllRulesModules(); 

0 Kudos

The groovy is taking too long to archive the rules, is this normal?

Answers (1)

Answers (1)

former_member626127
Discoverer
0 Kudos

there are out of the box cron jobs in the latest versions to remove the drools rules. its called droolsrulemaintainence job. also there are lot of recommendations given to take care of the promotions under Cx works area of sap.com. please do validate.