use of org.hisp.dhis.rules.models.RuleDataValue in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilderShould method thrown_illegal_state_exception_on_duplicate_events.
@Test
public void thrown_illegal_state_exception_on_duplicate_events() {
RuleEvent ruleEvent = RuleEvent.create("test_event_two", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
try {
RuleVariableValueMapBuilder.target(ruleEvent).ruleVariables(new ArrayList<RuleVariable>()).ruleEvents(Arrays.asList(ruleEvent)).build();
fail("IllegalStateException was expected, but nothing was thrown.");
} catch (IllegalStateException illegalStateException) {
// noop
}
}
use of org.hisp.dhis.rules.models.RuleDataValue in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilder method buildAllEventValues.
private void buildAllEventValues() {
List<RuleEvent> events = new ArrayList<>(ruleEvents);
if (ruleEvent != null) {
// target event should be among the list of all
// events in order to achieve correct behavior
events.add(ruleEvent);
}
// sort list of events by eventDate:
Collections.sort(events, RuleEvent.EVENT_DATE_COMPARATOR);
// aggregating values by data element uid
for (int i = 0; i < events.size(); i++) {
RuleEvent ruleEvent = events.get(i);
for (int j = 0; j < ruleEvent.dataValues().size(); j++) {
RuleDataValue ruleDataValue = ruleEvent.dataValues().get(j);
// push new list if it is not there for the given data element
if (!allEventsValues.containsKey(ruleDataValue.dataElement())) {
allEventsValues.put(ruleDataValue.dataElement(), // NOPMD
new ArrayList<RuleDataValue>(events.size()));
}
// append data value to the list
allEventsValues.get(ruleDataValue.dataElement()).add(ruleDataValue);
}
}
}
use of org.hisp.dhis.rules.models.RuleDataValue in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilder method buildCurrentEventValues.
private void buildCurrentEventValues() {
if (ruleEvent != null) {
for (int index = 0; index < ruleEvent.dataValues().size(); index++) {
RuleDataValue ruleDataValue = ruleEvent.dataValues().get(index);
currentEventValues.put(ruleDataValue.dataElement(), ruleDataValue);
}
}
}
use of org.hisp.dhis.rules.models.RuleDataValue in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilder method createNewestStageEventVariableValue.
private void createNewestStageEventVariableValue(@Nonnull Map<String, RuleVariableValue> valueMap, @Nonnull RuleVariableNewestStageEvent variable) {
List<RuleDataValue> stageRuleDataValues = new ArrayList<>();
List<RuleDataValue> sourceRuleDataValues = allEventsValues.get(variable.dataElement());
if (sourceRuleDataValues != null && !sourceRuleDataValues.isEmpty()) {
// filter data values based on program stage
for (int i = 0; i < sourceRuleDataValues.size(); i++) {
RuleDataValue ruleDataValue = sourceRuleDataValues.get(i);
if (variable.programStage().equals(ruleDataValue.programStage())) {
stageRuleDataValues.add(ruleDataValue);
}
}
}
if (stageRuleDataValues.isEmpty()) {
valueMap.put(variable.name(), create(variable.dataElementType()));
} else {
valueMap.put(variable.name(), create(stageRuleDataValues.get(0).value(), variable.dataElementType(), Utils.values(stageRuleDataValues)));
}
}
use of org.hisp.dhis.rules.models.RuleDataValue in project dhis2-android-sdk by dhis2.
the class RuleVariableValueMapBuilder method createCurrentEventVariableValue.
private void createCurrentEventVariableValue(@Nonnull Map<String, RuleVariableValue> valueMap, @Nonnull RuleVariableCurrentEvent variable) {
if (ruleEvent == null) {
return;
}
RuleVariableValue variableValue;
if (currentEventValues.containsKey(variable.dataElement())) {
RuleDataValue value = currentEventValues.get(variable.dataElement());
variableValue = create(value.value(), variable.dataElementType(), Arrays.asList(value.value()));
} else {
variableValue = create(variable.dataElementType());
}
valueMap.put(variable.name(), variableValue);
}
Aggregations