How to publish a PromotionSourceRule through Impex? - sap-commerce-cloud

I have used the below impEx to create a coupon based promotion rule. The rule gets created successfully but the promotion modules doesn't get deployed to it.
INSERT_UPDATE PromotionSourceRule;code[unique=true];priority;maxAllowedRuns;stackable[default=false];ruleGroup(code);conditions;actions;website(Identifier)[default=$defaultPromoGrp];status(code)[default=$defaultRuleStatus];excludeFromStorefrontDisplay[default=false]
"#% beforeEach:
if(de.hybris.platform.personalizationsampledataaddon.util.CxAddOnSampleDataUtils.isPromotionSourceRuleUnmodifiable(line.get(new Integer(1)))){
line.clear();
}";
"#% afterEach: de.hybris.platform.core.Registry.getApplicationContext().getBean(""ruleEngineSystemSetup"").registerSourceRuleForDeployment(impex.getLastImportedItem(), new String[]{$promotionModule, $promotionPreviewModule});"
;coupon_code_20_percentage_cart_discount;25;1;true;couponPromotionRuleGroup;"[{""definitionId"":""y_qualifying_coupons"",""parameters"":{""coupons"":{""uuid"":""COUPON20"",""type"":""List(ItemType(AbstractCoupon))"",""value"":[""COUPON20""]}},""children"":[]}]";"[{""definitionId"":""y_order_percentage_discount"",""parameters"":{""value"":{""uuid"":""20"",""type"":""java.math.BigDecimal"",""value"":20}}}]";;;

did you do the import through the hac or as part of a system init/update?
The logic in the RuleEngineSystemSetup only works in the context of a system initialization or system update.
If you look at the default implementation you will see:
public class DefaultRuleEngineSystemSetup extends AbstractEventListener<AfterInitializationEndEvent>
so during the impex and the call to registerSourceRuleForDeployment the rules are only registered for publication and once the AfterInitializationEndEvent is fired (by the platform after an init/update) the collected rules are published.
If you run this script in the context of the hac you could use beanshell code to either invoke one of the regular RuleEngineService methods to initialize your module(s) or you could try to invoke the DefaultRuleEngineSystemSetup.onEvent(final AfterInitializationEndEvent event) method passing in a "fake" non-null event to trigger the logic inside the system setup class (it requires a non-null event for logging which event came in I believe, but other than that the event is not used)
The last thing I haven't tried, both requires some more scripting in your impex script.
Hope this helps,
Sebastian

The below impex will be used to compile and publish the promotion rules
$defaultPromoGrp = <promo-group>
$promotionSourceRulesQuery="select {psr.pk} from {PromotionSourceRule as psr},{PromotionGroup as pg} where {psr.code} in ('<Promotion Code with comma separated>') and {pg.Identifier}='$defaultPromoGrp' and {psr.website}={pg.pk}"
"#%groovy% ruleCompilerService = spring.getBean('ruleCompilerService');
platformRuleEngineService = spring.getBean('platformRuleEngineService');
flexibleSearchService = spring.getBean('flexibleSearchService');
List sourceRules = flexibleSearchService.search($promotionSourceRulesQuery).getResult();
spring.getBean('ruleMaintenanceService').compileAndPublishRules(sourceRules, ""promotions-module"", false);
";

Related

How can I invoke a task module on handleTeamsMessagingExtensionSelectItem(...)?

I am building a messaging extension app for MS Teams using the Teams-Toolkit in Visual Studio Code. I have been able to launch task modules from the message context without a problem but is there a way to launch a task module from handleTeamsMessagingExtensionSelectItem(context, obj)? The goal is for the user to select an item from the query list which triggers a new task module where they can fill out and submit a form (adaptive card).
For more visibility, adding the answer from the comment section:
Task module can be opened using TaskModuleResponse return type.
Only TeamsTaskModuleFetchAsync() method supports TaskModuleResponse return type.
TeamsMessagingExtensionSelectItemAsync() method return type can be MessagingExtensionResponse only. As this response type can't be changed.
So, overall not feasible.

Cucumber JVM : avoid dependency injection by Picocontainer for features not tagged for execution

Assuming that I have a Cucumber feature tagged #api
#api
Feature: BankID authentication
Scenario Outline: Successful authentication of user using BankID
Given the initial flow start URLĀ 
When I enter that "<url>" into my browser
...
and steps for execution as below:
public class ApiSteps implements En {
public ApiSteps (ABCinjected abcInjected) {
Given("^the initial flow start URLĀ $", () -> {});
When("^I enter that \"([^\"]*)\" into my browser$", abcInjected::navigateToAuthenticationPage);
...
}
Even if I define this feature not to be executed by specifying different Cucumber tags or explicitly specifying tags = {"not #api"} , although steps themselves are not executed per se, Picocontainer still creates and injects instance of ABCinjected class, which is undesirable. Is it possible to control this behavior? I assume if feature is tagged as not to be executed and related scenario/steps are ignored, consecutively DI should not happen.
I got response from Cucumber contributor on Github:
When using lamda steddefs the class has to be instantiated to register
the steps. And we would need to know the steps defined by the class to
determine if we should instantiate it. This is a dead lock of
requirements.
Another recommendation is to set different packages for steps (api, units etc) and set different glue on runtime.
https://github.com/cucumber/cucumber-jvm/issues/1672

How to perform teardown for releasing resources after each Scenario In serenity BDD with Cucumber

I am using Serenity with BDD and need to perform a teardown step that must get executed after completion of each Scenario. Also, this teardown step should not be visible to report as it is technical thing and nothing to do with behavior to be exposed as part of cucumber such as releasing few expensive resource that got
I used cucumber's #After annotation which is working as expected, but the problem is now this step is also shown in my Report which I don't want to be visible.
Could someone please suggest me a solution that allows me to perform teardown step that gets executed per scenario but should not be added as step in my Serenity Report.
Current Solution I have is which does not satisfy my need:
Step Definition Class has following method:
#After
public void tearDown() {
systemAction.deleteCostlyResource(id);
}
but #After annotation makes it a candidate for Reporting Step.
If you are using Dependency Injection, you could have your DI framework teardown the resources at the end of the scenarios?
For instance, if you are using Spring:
If the "costly resource" is a class that you yourself have created, mark it with:
#Component
#Scope("cucumber-glue")
If the "costly resource" is not a class you created, but provided by a framework or whatever, you can register it as a bean in your spring (test)configuration and mark it with a "destroy method".
For example, to register Selenium WebDriver using annotation based configuration and making sure to quit after each Scenario, mark it with:
#Bean(destroyMethod = "quit")
In this example, quit() is WebDriver's method to quit(). In your situation, call "costly resource's" quit method, or equivalent thereof.

Groovy Script for JIRA-actions

I want to achieve the following using Adaptavist Scriptrunner in JIRA: A user comments on an issue and triggers a Scriptrunner custom script. If the issue is in the state "waiting for customer reply" and the user is a customer, trigger the workflow-transition "respond to question" and transfer the issue into the state "customer responded".
The Adaptavist Scriptrunner-Plugin uses Groovy as its language of choice for custom scripts. Unfortunately I have never worked with Groovy before and thus have no idea what I have to do to make this work. Out of the examples in the Scriptrunner docs I made the following:
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue)
def wfd = workflow.getDescriptor()
def actionName = wfd.getAction(transientVars["actionId"] as int).getName()
This is supposed to get me the current workflow step but doesn't work. Would anyone be so kind, to help me write this script?
Cheers!
There's already available Script Listener called Fast-track transition an issue. You need just to create a new instance of it, bind it to your project and Issue Commented event, and add extra condition like issue.status.name == 'Waiting For Customer Reply' && currentUser == issue.reporter, and specify the transition. If you change workflow, you might need to update a listener too.
Also, these listeners, post-functions etc. are implemented as 'canned' scripts (classes implementing certain interface) which are available as plain groovy files in the plugin itself in the JAR file, they can teach a lot.

How to run technical rule in IBM ODM

I would like to know, how should we execute the rules written in technical rule of IBM ODM.
I am using ODM V8.0.1. I have tried as below.
I created a XOM having class named Courier.java
public class Courier {
private String courierType;
private int distance;
with getters & setters
}
I created a rule project adding this XOM and created respective BOM.
I have added Courier Object as IN_OUT ruleset parameter with Name as "courier"
Then created a Technical Rule with below code
when {
cour : Courier();
}
then {
note("Courier Object Check is Satisfied");
}
Created a ruleflow having only one rule task pointing the above technical rule.
Then I run this ruleflow as
Run as --> Run Configuration
In Run Configuration dailog box, written below function to create courier object and
ran the configuration.
com.seldart.Courier cour= new com.seldart.Courier();
return cour;
Ruleflow execution went for 2 seconds but the statement in note() method has not
printed in the console.
I am not sure, whether rule flow has not picked the technical rule itself to run or courier object is not recognized ? Kindly guide me on executing this technical rule in right way. Thanks.
I think you have to explicitly add your courier ruleset parameter to the working memory, for instance in the Initial Action of the Start Node of your ruleflow.
For example, in IRL:
insert courier;
Simply, first of all create an action verbalization for your function in B2X. This way, it becames "visible" to all rule objects in your project and references.
Second, try to create an action rule and reference this new verbalization with it.
Third, create a rule flow to orchestrate this action rule.
To execute all this stuff try to simulate the ruleset or export and run the jar package with the ILOG/IBM JRules API.

Resources