use of org.hisp.dhis.validation.ValidationResult in project dhis2-core by dhis2.
the class DefaultValidationNotificationService method resolveRecipients.
/**
* Resolve all distinct recipients for the given MessagePair.
*/
private static Set<User> resolveRecipients(MessagePair pair) {
ValidationResult validationResult = pair.result;
ValidationNotificationTemplate template = pair.template;
// Limit recipients to be withing org unit hierarchy only, effectively
// producing a cross-cut of all users in the configured user groups.
final boolean limitToHierarchy = template.getNotifyUsersInHierarchyOnly();
Set<OrganisationUnit> orgUnitsToInclude = Sets.newHashSet();
if (limitToHierarchy) {
// Include self
orgUnitsToInclude.add(validationResult.getOrganisationUnit());
orgUnitsToInclude.addAll(validationResult.getOrganisationUnit().getAncestors());
}
return template.getRecipientUserGroups().stream().flatMap(ug -> ug.getMembers().stream()).distinct().filter(user -> !limitToHierarchy || orgUnitsToInclude.contains(user.getOrganisationUnit())).collect(Collectors.toSet());
}
use of org.hisp.dhis.validation.ValidationResult in project dhis2-core by dhis2.
the class ExportValidationResultAction method generateGrid.
@SuppressWarnings("unchecked")
private Grid generateGrid() {
List<ValidationResult> results = (List<ValidationResult>) SessionUtils.getSessionVar(KEY_VALIDATIONRESULT);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
Grid grid = new ListGrid();
grid.setTitle(i18n.getString("data_quality_report"));
if (organisationUnit != null) {
grid.setSubtitle(organisationUnit.getName());
}
grid.addHeader(new GridHeader(i18n.getString("source"), false, true));
grid.addHeader(new GridHeader(i18n.getString("period"), false, true));
grid.addHeader(new GridHeader(i18n.getString("validation_rule"), false, true));
grid.addHeader(new GridHeader(i18n.getString("importance"), false, true));
grid.addHeader(new GridHeader(i18n.getString("left_side_description"), false, true));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("operator"), false, false));
grid.addHeader(new GridHeader(i18n.getString("value"), false, false));
grid.addHeader(new GridHeader(i18n.getString("right_side_description"), false, true));
for (ValidationResult validationResult : results) {
OrganisationUnit unit = validationResult.getOrganisationUnit();
Period period = validationResult.getPeriod();
grid.addRow();
grid.addValue(unit.getName());
grid.addValue(format.formatPeriod(period));
grid.addValue(validationResult.getValidationRule().getName());
grid.addValue(i18n.getString(validationResult.getValidationRule().getImportance().toString().toLowerCase()));
//TODO lazy prone
grid.addValue(validationResult.getValidationRule().getLeftSide().getDescription());
grid.addValue(String.valueOf(validationResult.getLeftsideValue()));
grid.addValue(i18n.getString(validationResult.getValidationRule().getOperator().toString()));
grid.addValue(String.valueOf(validationResult.getRightsideValue()));
grid.addValue(validationResult.getValidationRule().getRightSide().getDescription());
}
return grid;
}
use of org.hisp.dhis.validation.ValidationResult in project dhis2-core by dhis2.
the class ValidationAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
DataSet dataSet = dataSetService.getDataSet(ds);
Period selectedPeriod = PeriodType.getPeriodFromIsoString(pe);
DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
if (attributeOptionCombo == null) {
attributeOptionCombo = dataElementCategoryService.getDefaultDataElementCategoryOptionCombo();
}
if (selectedPeriod == null || orgUnit == null || (multiOu && !orgUnit.hasChild())) {
return SUCCESS;
}
Period period = periodService.getPeriod(selectedPeriod.getStartDate(), selectedPeriod.getEndDate(), selectedPeriod.getPeriodType());
List<OrganisationUnit> organisationUnits = new ArrayList<>();
if (!multiOu) {
organisationUnits.add(orgUnit);
} else {
organisationUnits.addAll(orgUnit.getChildren());
}
Collections.sort(organisationUnits);
Date from = new DateTime(period.getStartDate()).minusYears(2).toDate();
for (OrganisationUnit organisationUnit : organisationUnits) {
List<DeflatedDataValue> values = new ArrayList<>(minMaxOutlierAnalysisService.analyse(Sets.newHashSet(organisationUnit), dataSet.getDataElements(), Sets.newHashSet(period), null, from));
if (!values.isEmpty()) {
dataValues.put(organisationUnit.getUid(), values);
}
List<ValidationResult> results = new ArrayList<>(validationService.startInteractiveValidationAnalysis(dataSet, period, organisationUnit, attributeOptionCombo));
if (!results.isEmpty()) {
validationResults.put(organisationUnit.getUid(), results);
}
List<DataElementOperand> violations = validationService.validateRequiredComments(dataSet, period, organisationUnit, attributeOptionCombo);
if (!violations.isEmpty()) {
commentViolations.put(organisationUnit.getUid(), violations);
}
}
return dataValues.isEmpty() && validationResults.isEmpty() && commentViolations.isEmpty() ? SUCCESS : INPUT;
}
use of org.hisp.dhis.validation.ValidationResult in project dhis2-core by dhis2.
the class DefaultValidationNotificationService method sendNotifications.
// -------------------------------------------------------------------------
// ValidationNotificationService implementation
// -------------------------------------------------------------------------
@Override
public Set<ValidationResult> sendNotifications(Set<ValidationResult> validationResults) {
if (validationResults.isEmpty()) {
return Sets.newHashSet();
}
Clock clock = new Clock(log).startClock().logTime(String.format("Creating notifications for %d validation results", validationResults.size()));
// Filter out un-applicable validation results and put in (natural) order
SortedSet<ValidationResult> applicableResults = validationResults.stream().filter(IS_APPLICABLE_RESULT).collect(Collectors.toCollection(TreeSet::new));
// Transform into distinct pairs of ValidationRule and ValidationNotificationTemplate
SortedSet<MessagePair> messagePairs = createMessagePairs(applicableResults);
// Segregate MessagePairs based on SendStrategy
Map<SendStrategy, SortedSet<MessagePair>> segregatedMap = segregateMessagePairBasedOnStrategy(messagePairs);
Map<SendStrategy, Map<Set<User>, NotificationMessage>> notficationCollections = new HashMap<>();
notficationCollections.put(SendStrategy.SINGLE_NOTIFICATION, createSingleNotifications(segregatedMap.getOrDefault(SendStrategy.SINGLE_NOTIFICATION, new TreeSet<>())));
notficationCollections.put(SendStrategy.COLLECTIVE_SUMMARY, createSummaryNotifications(segregatedMap.getOrDefault(SendStrategy.COLLECTIVE_SUMMARY, new TreeSet<>())));
for (Map.Entry<SendStrategy, Map<Set<User>, NotificationMessage>> entry : notficationCollections.entrySet()) {
clock.logTime(String.format("Sending %d %s notification(s)", entry.getValue().size(), entry.getKey().getDescription()));
entry.getValue().forEach(this::sendNotification);
}
clock.logTime("Done sending validation notifications");
return applicableResults;
}
use of org.hisp.dhis.validation.ValidationResult in project dhis2-core by dhis2.
the class ValidationResultController method getObjectList.
@GetMapping
@ResponseBody
public RootNode getObjectList(ValidationResultQuery query) {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
List<ValidationResult> validationResults = validationResultService.getValidationResults(query);
RootNode rootNode = NodeUtils.createMetadata();
if (!query.isSkipPaging()) {
query.setTotal(validationResultService.countValidationResults(query));
rootNode.addChild(NodeUtils.createPager(query.getPager()));
}
rootNode.addChild(fieldFilterService.filter(ValidationResult.class, validationResults, fields));
return rootNode;
}
Aggregations