Search in sources :

Example 1 with Importance

use of org.hisp.dhis.validation.Importance in project dhis2-core by dhis2.

the class DefaultValidationNotificationService method createSummarizedMessage.

/**
 * Creates a summarized message from the given MessagePairs and pre-rendered
 * map of NotificationMessages. The messages generated by each distinct
 * MessagePair are concatenated in their given order.
 */
private static NotificationMessage createSummarizedMessage(SortedSet<MessagePair> pairs, final Map<MessagePair, NotificationMessage> renderedNotificationsMap, final Date validationDate) {
    Map<Importance, Long> counts = pairs.stream().map(m -> m.result.getValidationRule().getImportance()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
    String subject = String.format("Validation violations as of %s", DateUtils.getLongDateString(validationDate));
    String message = String.format("Violations: High %d, medium %d, low %d", counts.getOrDefault(HIGH, 0L), counts.getOrDefault(Importance.MEDIUM, 0L), counts.getOrDefault(LOW, 0L));
    // Concatenate the notifications in sorted order, divide by double
    // linebreak
    message = message + pairs.stream().sorted().map(renderedNotificationsMap::get).map(n -> String.format("%s%s%s", n.getSubject(), LN, n.getMessage())).reduce("", (initStr, newStr) -> String.format("%s%s%s", initStr, LN + LN, newStr));
    NotificationMessage notificationMessage = new NotificationMessage(subject, message);
    notificationMessage.setPriority(getPriority(counts.getOrDefault(HIGH, 0L) > 0 ? HIGH : counts.getOrDefault(MEDIUM, 0L) > 0 ? MEDIUM : LOW));
    return notificationMessage;
}
Also used : Importance(org.hisp.dhis.validation.Importance) NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) SortedSet(java.util.SortedSet) Importance(org.hisp.dhis.validation.Importance) Date(java.util.Date) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) SendStrategy(org.hisp.dhis.notification.SendStrategy) MessageService(org.hisp.dhis.message.MessageService) Function(java.util.function.Function) ValidationResult(org.hisp.dhis.validation.ValidationResult) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HIGH(org.hisp.dhis.validation.Importance.HIGH) Service(org.springframework.stereotype.Service) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) User(org.hisp.dhis.user.User) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) LOW(org.hisp.dhis.validation.Importance.LOW) BiMap(com.google.common.collect.BiMap) LN(org.hisp.dhis.commons.util.TextUtils.LN) MessageConversationPriority(org.hisp.dhis.message.MessageConversationPriority) Predicate(java.util.function.Predicate) ValidationResultService(org.hisp.dhis.validation.ValidationResultService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) CompareToBuilder(org.apache.commons.lang3.builder.CompareToBuilder) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Slf4j(lombok.extern.slf4j.Slf4j) Clock(org.hisp.dhis.system.util.Clock) HashBiMap(com.google.common.collect.HashBiMap) MEDIUM(org.hisp.dhis.validation.Importance.MEDIUM) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) DateUtils(org.hisp.dhis.util.DateUtils) Transactional(org.springframework.transaction.annotation.Transactional) NotificationMessage(org.hisp.dhis.notification.NotificationMessage)

Example 2 with Importance

use of org.hisp.dhis.validation.Importance in project dhis2-core by dhis2.

the class DataAnalysisController method generateValidationRulesReportGridFromResults.

private Grid generateValidationRulesReportGridFromResults(List<ValidationResult> results, OrganisationUnit orgUnit) {
    Grid grid = new ListGrid();
    if (results != null) {
        I18nFormat format = i18nManager.getI18nFormat();
        I18n i18n = i18nManager.getI18n();
        grid.setTitle(i18n.getString("data_quality_report"));
        if (orgUnit != null) {
            grid.setSubtitle(orgUnit.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();
            Importance importance = validationResult.getValidationRule().getImportance();
            Operator operator = validationResult.getValidationRule().getOperator();
            grid.addRow();
            grid.addValue(unit.getName());
            grid.addValue(format.formatPeriod(period));
            grid.addValue(validationResult.getValidationRule().getName());
            grid.addValue(i18n.getString(importance.toString().toLowerCase()));
            grid.addValue(validationResult.getValidationRule().getLeftSide().getDescription());
            grid.addValue(String.valueOf(validationResult.getLeftsideValue()));
            grid.addValue(i18n.getString(operator.toString()));
            grid.addValue(String.valueOf(validationResult.getRightsideValue()));
            grid.addValue(validationResult.getValidationRule().getRightSide().getDescription());
        }
    }
    return grid;
}
Also used : Importance(org.hisp.dhis.validation.Importance) Operator(org.hisp.dhis.expression.Operator) 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) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ValidationResult(org.hisp.dhis.validation.ValidationResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) I18n(org.hisp.dhis.i18n.I18n) GridHeader(org.hisp.dhis.common.GridHeader)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Importance (org.hisp.dhis.validation.Importance)2 ValidationResult (org.hisp.dhis.validation.ValidationResult)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 Sets (com.google.common.collect.Sets)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)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 Slf4j (lombok.extern.slf4j.Slf4j)1