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.
Related
I have a servicereference with a method I need to use in a test.
The servicereference class is defined as:
public class MyServiceReference : Clientbase<IMyServiceReference>, IMyServiceReference
{
public MyServiceReference()
{
}
..... methods is then defined
}
From my testmethod I have tried both
private MyServiceReference myServiceReferenceFake = A.Fake<MyServiceReference>();
// And
private MyServiceReference myServiceReference = new MyServiceReference();
For both of these is crashes in the constructor with the message:
System.InvalidOperationException: Could not find default endpoint element that references contract.
All I need is to have a callto definition from a method in that class.
How can this be solved?
I've no experience with Clientbase, which I assume to be a System.ServiceModel.ClientBase<TChannel>,but I can make some general comments.
Since you tried first to fake a MyServiceReference, I'll assume that you're not testing that class, and you want to use it as a collaborator for the system under test. In that case, your best bet is to try faking IMyServiceReference. interfaces are very easy to fake, since they don't bring along any behaviour or baggage like faking a class does.
If you feel you really need to fake a MyServiceReference, then we have to contend with the fact that FakeItEasy will eventually call MyServiceReference(), which will call ClientBase<IMyServiceReference>(), whose documentation says
Initializes a new instance of the ClientBase<TChannel> class using the default target endpoint from the application configuration file.
Based on the error you reported, I assume that the application configuration file is not found or does not include the configuration required to create a MyServiceReference. The fact that you get the same error when you just try to instantiate a MyServiceReference directly strengthens my belief.
So I think your paths forward are either to try faking IMyServiceReference or to provide the configuration that ClientBase<IMyServiceReference> needs.
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);
";
I'm trying to make a reshaprer plugin to add one (or more) configurations, besides executable, static method, project, at resharper's build/run window.
Any guidelines where to start? Or how to access build's context and configure?
Currently examining the JetBrains.IDE.RunConfig, SolutionBuilders etc but one help would be appreciated.
Should this plugin be a SolutionComponent or a SolutionInstanceComponent?
Resharper's sdk help lucks documentation on build/run component.
Thank in advance!
You can extend the available run configuration types by implementing IRunConfig and IRunConfigProvider.
The IRunConfigProvider class needs to be marked as [ShellComponent], and can derive from the RunConfigProviderBase abstract base class. You get to specify a name, e.g. "Executable", a type identifier, e.g. "exe" and an icon ID. There's also the CreateNew method, which will create a new instance of your IRunConfig class, which will be mostly unconfigured, at this point.
The IRunConfig interface doesn't need to marked as a component, and should also derive from RunConfigBase - take a look at RunConfigExe in dotPeek to see an example of how to implement. You should override Execute in order to actually run whatever it is you need to run. You can use the RunConfigContext class passed in to actually execute a process from a ProcessStartInfo, or an IProject - this will execute it either by running the process, debugging it, or something else, such as code coverage or profiling.
For an .exe, this is as simple as:
public override void Execute(RunConfigContext context)
{
context.ExecutionProvider.Execute(GetStartInfo(context), context, this);
}
But for a more complicated example, look at RunConfigMethod.Execute, which uses its own standalone launcher executable, and passes in command line parameters to load the correct assembly and execute the given static method.
Settings are implemented with ReadSpecific/SaveSpecific, and you can provide an editor view model with CreateEditor. You'll need a settings class, something like:
[SettingsKey(typeof (ConfigSettings), ".exe config")]
public class ExeSettings
{
[SettingsEntry(null, "Path to .exe")] public string Executable;
[SettingsEntry(null, "Working directory")] public string WorkingDirectory;
[SettingsEntry(null, "Command line arguments")] public string Arguments;
}
The view for the editor is provided by a WPF control that is displayed in a dialog that ReSharper controls. The view needs to be decorated with the [View] attribute and must implement IView<T> where T is the concrete class returned from CreateEditor. This is how ReSharper will locate the view for the view model returned by CreateEditor. Again, take a look at RunConfigMethodView in dotPeek for some more idea of what's going on (and if you look in the resources, you'll be able to see the XAML itself).
I am creating a new module in Prestashop 1.6 which displays some data on the products page in the info box. I have created a new hook in the install method of the module like this: $this->registerHook('combinationDescription') and created the hookDisplayCombinationDescription function for assigning some smarty variables and displaying them with a tpl file.
After installing my module the hook is registered into the database so its usable.
Manually I can insert code into the product.tpl file just like: {hook h="hookDisplayCombinationDescription"} and I think it's working, but I would like to make this step automatically when the module gets installed. How can I do that?
My guess would be that to edit the product.tpl file from the install method of the module but it's a bit dirty method for me. Is there some other nice way to do that?
If you made a custom hook you need to insert its execution somewhere manually: into .tpl or into overrided ProductController.php (if it is an action hook). Prestashop can't execute it automatically for it doesn't know where do you want to execute it.
But you can use the default Prestashop 1.6 hooks to make your part of the code hooked and ready after the module installation. For the product page are these:
displayLeftColumnProduct
displayRightColumnProduct
displayProductTab
displayProductTabContent
displayFooterProduct
displayProductButtons
displayProductPriceBlock
actionProductOutOfStock
You can use one of these hooks and position your content with css (or javascript - to any part of the page).
If you make any custom hook then you have to make it executable first.Prestashop can't execute custom hooks automatically.But for displaying some data on product page you can use predefined prestashop hooks.Some are following
displayProductButtons
displayProductTab
To use these hooks, first you have to register hooks in install function like
public function install()
{
if (!parent::install() || !$this->registerHook('displayProductButtons')){
}
}
and in the same file you have to make a function like
public function hookDisplayProductButtons($params)
{
}
Now in that function you can assign some smarty variables which you want to access or show in your tpl file like
public function hookDisplayProductButtons($params)
{
$this->smarty->assign(array(
'product_name' => 'abc'
));
}
Now in your tpl file you can access that
If you want to add new custom hook and execute them when your particular module is active or installed.
Please follow the following steps:
Add you new custom hook code any where you want to perform your action.
Then, you can insert entry for that new custom hook into database at the time of installing module.
Now, your hook will execute as per your need.
Delete the same entry of hook from database at the time of uninstalling module so that hook could not be executed after uninstalling module.
I am not sure for, Is any other solution available to fulfill your need in prestashop?
So, there's a problem - I need to transplant "Categories Block" module to "displayTopColumn" hook (yep, designer put categories list near (on?) slider). But, by default, there is no possibilities to do this. I don't like that awful Prestashop restrictions, so maybe there is solution for this problem - remove those restrictions?
Thanks.
Removing those restrictions would not resolve anything for a simple reason: if you could hook the module blockcategories to displayTopColumn, this module would not know what to display in this hook because there is no hookDisplayTopColumn() function in it.
However, you can modify the module, and add a function to manage this hook.
To do so, open the file blockcategories.php and add the following:
public function hookDisplayTopColumn($params)
{
// Your code
}
If you want to display here the same content as in the hookLeftColumn hook, you can simply do this:
public function hookDisplayTopColumn($params)
{
return $this->hookLeftColumn($params);
}
You can also create your own function and template by copying, pasting and modifying the code you can find in the function hookLeftColumn() or in the function hookFooter().