Skip to content

Commit

Permalink
chore: general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee committed Nov 28, 2023
1 parent 3391cff commit 8ac8b96
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 81 deletions.
18 changes: 5 additions & 13 deletions src/main/java/org/hisp/dhis/rules/RuleEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@
import java.util.concurrent.Callable;

public record RuleEngine(
@Nonnull
RuleEngineContext executionContext,

@Nonnull
List<RuleEvent> events,

@CheckForNull
RuleEnrollment enrollment,

@CheckForNull
TriggerEnvironment triggerEnvironment
)
{
@Nonnull RuleEngineContext executionContext,
@Nonnull List<RuleEvent> events,
@CheckForNull RuleEnrollment enrollment,
@CheckForNull TriggerEnvironment triggerEnvironment
) {
@Nonnull
public Callable<List<RuleEffect>> evaluate( @Nonnull RuleEvent ruleEvent )
{
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/org/hisp/dhis/rules/RuleEngineContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
import java.util.Map;

public record RuleEngineContext(
@Nonnull
List<Rule> rules,
@Nonnull
List<RuleVariable> ruleVariables,
@Nonnull
Map<String, List<String>> supplementaryData,
@Nonnull
Map<String, String> constantsValues,
@Nonnull
RuleEngineIntent ruleEngineIntent,
@CheckForNull
Map<String, DataItem> dataItemStore) {
@Nonnull List<Rule> rules,
@Nonnull List<RuleVariable> ruleVariables,
@Nonnull Map<String, List<String>> supplementaryData,
@Nonnull Map<String, String> constantsValues,
@Nonnull RuleEngineIntent ruleEngineIntent,
@CheckForNull Map<String, DataItem> dataItemStore
) {

RuleEngineContext(@Nonnull List<Rule> rules, @Nonnull List<RuleVariable> ruleVariables,
@Nonnull Map<String, List<String>> supplementaryData, @Nonnull Map<String, String> constantsValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
import java.util.concurrent.Callable;

record RuleEngineMultipleExecution(
@Nonnull
List<Rule> rules,
@Nonnull
RuleVariableValueMap ruleVariableValueMap,
@Nonnull
Map<String, List<String>> supplementaryData,
@Nonnull
RuleConditionEvaluator ruleConditionEvaluator) implements Callable<List<RuleEffects>> {
@Nonnull List<Rule> rules,
@Nonnull RuleVariableValueMap ruleVariableValueMap,
@Nonnull Map<String, List<String>> supplementaryData,
@Nonnull RuleConditionEvaluator ruleConditionEvaluator
) implements Callable<List<RuleEffects>> {

RuleEngineMultipleExecution(@Nonnull List<Rule> rules,
@Nonnull RuleVariableValueMap ruleVariableValueMap, @Nonnull Map<String, List<String>> supplementaryData )
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/hisp/dhis/rules/RuleVariableValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import java.util.List;

public record RuleVariableValue(
@CheckForNull
String value,
@Nonnull
RuleValueType type,
@Nonnull
List<String> candidates,
@CheckForNull
String eventDate
@CheckForNull String value,
@Nonnull RuleValueType type,
@Nonnull List<String> candidates,
@CheckForNull String eventDate
) implements VariableValue {
private static final String DATE_PATTERN = "yyyy-MM-dd";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import javax.annotation.Nonnull;

public record RuleActionHideProgramStage(
@Nonnull
String data,
@Nonnull
String programStage
@Nonnull String data,
@Nonnull String programStage
) implements RuleAction {

@Nonnull
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/hisp/dhis/rules/models/RuleActionText.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
* or 'program indicator' widget.
*/
public record RuleActionText(
@Nonnull
String data,
@Nonnull
String content,
@Nonnull
String location

@Nonnull String data,
@Nonnull String content,
@Nonnull String location
) implements RuleAction {

public static final String LOCATION_FEEDBACK_WIDGET = "feedback";
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/hisp/dhis/rules/models/RuleEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

;

public record RuleEffect( @Nonnull String ruleId, @Nonnull RuleAction ruleAction, @CheckForNull String data )
{
public RuleEffect( @Nonnull String ruleId, @Nonnull RuleAction ruleAction )
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/hisp/dhis/rules/models/RuleEffects.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.hisp.dhis.rules.models;

import javax.annotation.Nonnull;
import java.util.List;

public record RuleEffects(
TrackerObjectType trackerObjectType,
String trackerObjectUid,
List<RuleEffect> ruleEffects)
@Nonnull TrackerObjectType trackerObjectType,
@Nonnull String trackerObjectUid,
@Nonnull List<RuleEffect> ruleEffects)
{
public boolean isEnrollment(){
return this.trackerObjectType == TrackerObjectType.ENROLLMENT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package org.hisp.dhis.rules.models;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public record RuleEvaluationResult(
Rule rule,
List<RuleEffect> ruleEffects,
@Nonnull Rule rule,
@Nonnull List<RuleEffect> ruleEffects,
boolean evaluatedAs,
boolean error)
{

public static RuleEvaluationResult evaluatedResult(Rule rule, List<RuleEffect> ruleEffects) {
public static RuleEvaluationResult evaluatedResult(@Nonnull Rule rule, @Nonnull List<RuleEffect> ruleEffects) {
return new RuleEvaluationResult( rule, ruleEffects, true, false );
}

public static RuleEvaluationResult notEvaluatedResult(Rule rule) {
public static RuleEvaluationResult notEvaluatedResult(@Nonnull Rule rule) {
return new RuleEvaluationResult( rule, new ArrayList<>(), false, false );
}

public static RuleEvaluationResult errorRule( Rule rule, String errorMessage ) {
public static RuleEvaluationResult errorRule( @Nonnull Rule rule, @Nonnull String errorMessage ) {
ArrayList<RuleEffect> effects = new ArrayList<>();

effects.add(new RuleEffect(rule.uid(), RuleActionError.create(errorMessage), errorMessage));
Expand Down
34 changes: 15 additions & 19 deletions src/main/java/org/hisp/dhis/rules/models/RuleValidationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,50 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import javax.annotation.CheckForNull;

/**
* @author Zubair Asghar
*/
public record RuleValidationResult(
String description,
boolean valid,
String errorMessage,
Throwable exception) {
@CheckForNull String description,
boolean valid,
@CheckForNull String errorMessage,
@CheckForNull Throwable exception
) {

public static Builder builder()
{
public static Builder builder() {
return new Builder();
}

public static class Builder
{
public static class Builder {
private String description;
private boolean isValid;
private String errorMessage;
private Throwable exception;

public Builder description( String description )
{
public Builder description(String description) {
this.description = description;
return this;
}

public Builder isValid( boolean isValid )
{
public Builder isValid(boolean isValid) {
this.isValid = isValid;
return this;
}

public Builder errorMessage( String errorMessage )
{
public Builder errorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}

public Builder exception( Throwable exception )
{
public Builder exception(Throwable exception) {
this.exception = exception;
return this;
}

public RuleValidationResult build()
{
return new RuleValidationResult( this.description, this.isValid, this.errorMessage, exception );
public RuleValidationResult build() {
return new RuleValidationResult(this.description, this.isValid, this.errorMessage, exception);
}
}
}

0 comments on commit 8ac8b96

Please sign in to comment.