Search in sources :

Example 1 with ValidationResult

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());
}
Also used : NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) java.util(java.util) LN(org.hisp.dhis.commons.util.TextUtils.LN) Importance(org.hisp.dhis.validation.Importance) ValidationResultService(org.hisp.dhis.validation.ValidationResultService) Predicate(java.util.function.Predicate) SendStrategy(org.hisp.dhis.notification.SendStrategy) DateUtils(org.hisp.dhis.system.util.DateUtils) MessageService(org.hisp.dhis.message.MessageService) NotNull(javax.validation.constraints.NotNull) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) ValidationResult(org.hisp.dhis.validation.ValidationResult) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Clock(org.hisp.dhis.system.util.Clock) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) User(org.hisp.dhis.user.User) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) com.google.common.collect(com.google.common.collect) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValidationResult(org.hisp.dhis.validation.ValidationResult)

Example 2 with ValidationResult

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) Period(org.hisp.dhis.period.Period) List(java.util.List) ValidationResult(org.hisp.dhis.validation.ValidationResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 3 with ValidationResult

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) ValidationResult(org.hisp.dhis.validation.ValidationResult) Date(java.util.Date) DateTime(org.joda.time.DateTime) DeflatedDataValue(org.hisp.dhis.datavalue.DeflatedDataValue) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 4 with ValidationResult

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;
}
Also used : User(org.hisp.dhis.user.User) Clock(org.hisp.dhis.system.util.Clock) ValidationResult(org.hisp.dhis.validation.ValidationResult) SendStrategy(org.hisp.dhis.notification.SendStrategy)

Example 5 with ValidationResult

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;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) ValidationResult(org.hisp.dhis.validation.ValidationResult)

Aggregations

ValidationResult (org.hisp.dhis.validation.ValidationResult)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 SendStrategy (org.hisp.dhis.notification.SendStrategy)2 Period (org.hisp.dhis.period.Period)2 Clock (org.hisp.dhis.system.util.Clock)2 User (org.hisp.dhis.user.User)2 com.google.common.collect (com.google.common.collect)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 NotNull (javax.validation.constraints.NotNull)1 CompareToBuilder (org.apache.commons.lang3.builder.CompareToBuilder)1 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)1 HashCodeBuilder (org.apache.commons.lang3.builder.HashCodeBuilder)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1