INSERT_UPDATE DroolsKIEModule ; name[unique=true] ; mvnGroupId ; mvnArtifactId ; mvnVersion ; ruleType(code) ; active ; version ;
; promotions-ca-module ; hybris-rules ; promotions-ca ; 1.0.0 ; PROMOTION ; true ; -1 ;
INSERT_UPDATE DroolsKIEBase ; name[unique=true] ; kieModule(name)[unique=true] ; equalityBehavior(code) ; eventProcessingMode(code)
; promotions-ca-base ; promotions-ca-module ; EQUALITY ; STREAM
INSERT_UPDATE DroolsKIESession ; name[unique=true] ; kieBase(name)[unique=true] ; sessionType(code)
; promotions-ca-session ; promotions-ca-base ; STATELESS
INSERT_UPDATE DroolsRuleEngineContext ; name[unique=true] ; kieSession(name) ; ruleFiringLimit
; promotions-ca-context ; promotions-ca-session ; 200 ;
UPDATE DroolsKIEBase ; name[unique=true] ; defaultKIESession(name)
; promotions-ca-base ; promotions-ca-session
UPDATE DroolsKIEModule ; name[unique=true] ; defaultKIEBase(name)
"#% afterEach: de.hybris.platform.core.Registry.getApplicationContext().getBean(""ruleEngineSystemSetup"").initializeModule(impex.getLastImportedItem());"
; promotions-ca-module ; promotions-ca-base
INSERT_UPDATE CatalogVersionToRuleEngineContextMapping ; context(name)[unique=true] ; catalogVersion(catalog(id),version)[unique=true]
; promotions-ca-context ; testCAProductCatalog:Online
package com.test.core.impex.translators;
import de.hybris.platform.core.Registry;
import de.hybris.platform.impex.jalo.translators.AbstractValueTranslator;
import de.hybris.platform.jalo.Item;
import de.hybris.platform.jalo.JaloInvalidParameterException;
import de.hybris.platform.jalo.enumeration.EnumerationValue;
import de.hybris.platform.promotionengineservices.jalo.PromotionSourceRule;
import de.hybris.platform.promotionengineservices.model.PromotionSourceRuleModel;
import de.hybris.platform.ruleengineservices.enums.RuleStatus;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
@SuppressWarnings("deprecation")
public class PromotionVersionTranslator extends AbstractValueTranslator {
private static final String PROMOTION_QUERY_PART1 = "select {pk} from {PromotionSourceRule} where {code} = '";
private static final String PROMOTION_QUERY_PART2 = "' AND {status} IN ({{select {pk} from {EnumerationValue} where {code} IN ('PUBLISHED','UNPUBLISHED','INACTIVE') }}) order by {version} desc";
@Override
public String exportValue(Object var1) throws JaloInvalidParameterException {
if(var1 instanceof PromotionSourceRule ) {
return ((PromotionSourceRule)var1).getCode();
}
return var1.toString();
}
@Override
public final Object importValue(String valueExpr, Item toItem) throws JaloInvalidParameterException {
this.clearStatus();
Object ret=findVersionValue( valueExpr);
return ret;
}
private Long findVersionValue(String code) {
final FlexibleSearchQuery query = new FlexibleSearchQuery(PROMOTION_QUERY_PART1+code+PROMOTION_QUERY_PART2 );
List<PromotionSourceRuleModel> results = getFlexibleSearchService().<PromotionSourceRuleModel> search(query).getResult();
Long finalVersion = Long.valueOf(0);
if(CollectionUtils.isNotEmpty(results)) {
PromotionSourceRuleModel promotionSourceRuleModel = results.get(0);
PromotionSourceRule promotionSourceRule = getModelService().getSource(promotionSourceRuleModel);
EnumerationValue status = promotionSourceRule.getStatus();
Long version = promotionSourceRule.getVersion();
if(status.getCode().equals(RuleStatus.UNPUBLISHED.getCode())) {
finalVersion= version;
}
else {
finalVersion= version+1;
}
}
return finalVersion;
}
private FlexibleSearchService getFlexibleSearchService() {
return (FlexibleSearchService) Registry.getApplicationContext().getBean("flexibleSearchService",
FlexibleSearchService.class);
}
private ModelService getModelService() {
return (ModelService) Registry.getApplicationContext().getBean("modelService",
ModelService.class);
}
}
$defaultPromoGrp=CAPromoGrp
$defaultStatus=PUBLISHED
INSERT_UPDATE PromotionSourceRule ; code[unique=true] ; version[unique=true][translator=com.test.core.impex.translators.PromotionVersionTranslator]; name[lang=en] ; status(code) ; priority ; maxAllowedRuns ; stackable[default=false] ; ; actions ; description[lang=en]
"#% afterEach: de.hybris.platform.core.Registry.getApplicationContext().getBean(""ruleCompilerService"").compile( de.hybris.platform.core.Registry.getApplicationContext().getBean(""modelService"").get(impex.getLastImportedItem()),""promotions-ca-module""); de.hybris.platform.core.Registry.getApplicationContext().getBean(""platformRuleEngineService"").initializeAllRulesModules();"
#Test promotion
; test; test; test promotion;PUBLISHED; 40; 1; true ; orderPromotionRuleGroup; <replace with condition>; "[{""definitionId"":""y_trigger_message"",""parameters"":{}}]" ;; This is test promo. ; This is test promo.
$defaultPromoGrp=USPromoGrp
$defaultStatus=PUBLISHED
INSERT_UPDATE PromotionSourceRule ; code[unique=true] ; version[unique=true][translator=com.test.core.impex.translators.PromotionVersionTranslator]; name[lang=en] ; status(code) ; priority ; maxAllowedRuns ; stackable[default=false] ; ; actions ; description[lang=en]
"#% afterEach: de.hybris.platform.core.Registry.getApplicationContext().getBean(""ruleCompilerService"").compile( de.hybris.platform.core.Registry.getApplicationContext().getBean(""modelService"").get(impex.getLastImportedItem()),""promotions-module""); de.hybris.platform.core.Registry.getApplicationContext().getBean(""platformRuleEngineService"").initializeAllRulesModules();"
#Test promotion
; test; test; test promotion;PUBLISHED; 40; 1; true ; orderPromotionRuleGroup; <replace with condition>; "[{""definitionId"":""y_trigger_message"",""parameters"":{}}]" ;; This is test promo. ; This is test promo.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |