Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve documentation (#12) #5619

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,13 @@ Finally, you instantiate a `RuleUnitInstance` using `RuleUnitProvider` to execut
public void test() {
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
...

List<Measurement> queryResult = instance.executeQuery("FindColor").stream().map(tuple -> (Measurement) tuple.get("$m")).collect(toList());
...

} finally {
instance.dispose();
}
} // instance.close() is called automatically
}
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@ Using Rule Unit APIs, the resulting Java snippet would be like this:
[source,java]
----
MeasurementUnit measurementUnit = new MeasurementUnit();
RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));

instance.fire();
} finally {
instance.dispose();
}
} // instance.close() is called automatically
----

In Rule Unit, instantiate `RuleUnitInstance` instead of `KieSession`. Add facts to `DataSource` property instead of `insert`. Generic KIE API calls (e.g. `KieServices`, `KieContainer`, `KieBase` ... ) are no longer needed. Instead, one more class `Unit` has to be defined.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public void test() {
LOG.info("Creating RuleUnit");
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
LOG.info("Insert data");
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));
Expand All @@ -74,8 +73,6 @@ public void test() {
assertTrue("contains red", measurementUnit.getControlSet().contains("red"));
assertTrue("contains green", measurementUnit.getControlSet().contains("green"));
assertTrue("contains blue", measurementUnit.getControlSet().contains("blue"));
} finally {
instance.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void test() {
LOG.info("Creating RuleUnit");
MeasurementUnit measurementUnit = new MeasurementUnit();

RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit);
try {
try (RuleUnitInstance<MeasurementUnit> instance = RuleUnitProvider.get().createRuleUnitInstance(measurementUnit)) {
LOG.info("Insert data");
measurementUnit.getMeasurements().add(new Measurement("color", "red"));
measurementUnit.getMeasurements().add(new Measurement("color", "green"));
Expand All @@ -54,8 +53,6 @@ public void test() {
assertTrue("contains red", measurementUnit.getControlSet().contains("red"));
assertTrue("contains green", measurementUnit.getControlSet().contains("green"));
assertTrue("contains blue", measurementUnit.getControlSet().contains("blue"));
} finally {
instance.close();
}
}
}
Loading