Search in sources :

Example 6 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultInterpretationService method sendMentionNotifications.

private void sendMentionNotifications(Interpretation interpretation, InterpretationComment comment, Set<User> users) {
    if (interpretation == null || users.isEmpty()) {
        return;
    }
    String link = getInterpretationLink(interpretation);
    StringBuilder messageContent;
    I18n i18n = i18nManager.getI18n();
    if (comment != null) {
        messageContent = new StringBuilder(i18n.getString("comment_mention_notification")).append(":").append("\n\n").append(Jsoup.parse(comment.getText()).text());
    } else {
        messageContent = new StringBuilder(i18n.getString("interpretation_mention_notification")).append(":").append("\n\n").append(Jsoup.parse(interpretation.getText()).text());
    }
    messageContent.append("\n\n").append(i18n.getString("go_to")).append(" ").append(link);
    User user = currentUserService.getCurrentUser();
    StringBuilder subjectContent = new StringBuilder(user.getDisplayName()).append(" ").append(i18n.getString("mentioned_you_in_dhis2"));
    messageService.sendSystemMessage(users, subjectContent.toString(), messageContent.toString());
}
Also used : User(org.hisp.dhis.user.User) I18n(org.hisp.dhis.i18n.I18n)

Example 7 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultInterpretationService method sendNotificationMessage.

private long sendNotificationMessage(Set<User> users, Interpretation interpretation, InterpretationComment comment, NotificationType notificationType) {
    I18n i18n = i18nManager.getI18n();
    String currentUsername = currentUserService.getCurrentUsername();
    String interpretableName = interpretation.getObject().getName();
    String actionString;
    String details;
    switch(notificationType) {
        case INTERPRETATION_CREATE:
            actionString = i18n.getString("notification_interpretation_create");
            details = interpretation.getText();
            break;
        case INTERPRETATION_UPDATE:
            actionString = i18n.getString("notification_interpretation_update");
            details = interpretation.getText();
            break;
        case INTERPRETATION_LIKE:
            actionString = i18n.getString("notification_interpretation_like");
            details = "";
            break;
        case COMMENT_CREATE:
            actionString = i18n.getString("notification_comment_create");
            details = comment.getText();
            break;
        case COMMENT_UPDATE:
            actionString = i18n.getString("notification_comment_update");
            details = comment.getText();
            break;
        default:
            throw new IllegalArgumentException("Unknown notification type: " + notificationType);
    }
    String subject = String.join(" ", Arrays.asList(i18n.getString("notification_user"), currentUsername, actionString, i18n.getString("notification_object_subscribed")));
    String fullBody = String.join("\n\n", Arrays.asList(String.format("%s: %s", subject, interpretableName), Jsoup.parse(details).text(), String.format("%s %s", i18n.getString("go_to"), getInterpretationLink(interpretation))));
    return messageService.sendSystemMessage(users, subject, fullBody);
}
Also used : I18n(org.hisp.dhis.i18n.I18n)

Example 8 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultSecurityService method sendRestoreOrInviteMessage.

@Override
public boolean sendRestoreOrInviteMessage(User user, String rootPath, RestoreOptions restoreOptions) {
    String encodedTokens = generateAndPersistTokens(user, restoreOptions);
    RestoreType restoreType = restoreOptions.getRestoreType();
    String applicationTitle = systemSettingManager.getStringSetting(SettingKey.APPLICATION_TITLE);
    if (applicationTitle == null || applicationTitle.isEmpty()) {
        applicationTitle = DEFAULT_APPLICATION_TITLE;
    }
    Map<String, Object> vars = new HashMap<>();
    vars.put("applicationTitle", applicationTitle);
    vars.put("restorePath", rootPath + RESTORE_PATH + restoreType.getAction());
    vars.put("token", encodedTokens);
    vars.put("welcomeMessage", user.getWelcomeMessage());
    I18n i18n = i18nManager.getI18n(ObjectUtils.firstNonNull((Locale) userSettingService.getUserSetting(UserSettingKey.UI_LOCALE, user), LocaleManager.DEFAULT_LOCALE));
    vars.put("i18n", i18n);
    rootPath = rootPath.replace("http://", "").replace("https://", "");
    // -------------------------------------------------------------------------
    // Render emails
    // -------------------------------------------------------------------------
    VelocityManager vm = new VelocityManager();
    String messageBody = vm.render(vars, restoreType.getEmailTemplate() + "1");
    String messageSubject = i18n.getString(restoreType.getEmailSubject()) + " " + rootPath;
    // -------------------------------------------------------------------------
    // Send emails
    // -------------------------------------------------------------------------
    emailMessageSender.sendMessage(messageSubject, messageBody, null, null, ImmutableSet.of(user), true);
    return true;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) I18n(org.hisp.dhis.i18n.I18n)

Example 9 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class ProgramSqlGeneratorFunctionsTest method test.

private Object test(String expression, AntlrExprLiteral exprLiteral, ExpressionItemMethod itemMethod) {
    Set<String> dataElementsAndAttributesIdentifiers = new LinkedHashSet<>();
    dataElementsAndAttributesIdentifiers.add(BASE_UID + "a");
    dataElementsAndAttributesIdentifiers.add(BASE_UID + "b");
    dataElementsAndAttributesIdentifiers.add(BASE_UID + "c");
    ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(dataElementsAndAttributesIdentifiers).build();
    CommonExpressionVisitor visitor = CommonExpressionVisitor.builder().idObjectManager(idObjectManager).dimensionService(dimensionService).programIndicatorService(programIndicatorService).programStageService(programStageService).statementBuilder(statementBuilder).i18n(new I18n(null, null)).itemMap(PROGRAM_INDICATOR_ITEMS).itemMethod(itemMethod).progParams(params).build();
    visitor.setExpressionLiteral(exprLiteral);
    return Parser.visit(expression, visitor);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProgramExpressionParams(org.hisp.dhis.parser.expression.ProgramExpressionParams) CommonExpressionVisitor(org.hisp.dhis.parser.expression.CommonExpressionVisitor) AntlrParserUtils.castString(org.hisp.dhis.antlr.AntlrParserUtils.castString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) I18n(org.hisp.dhis.i18n.I18n)

Example 10 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidIndicators.

private List<DataIntegrityIssue> getInvalidIndicators(Function<Indicator, String> getter) {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    I18n i18n = i18nManager.getI18n();
    for (Indicator indicator : indicatorService.getAllIndicators()) {
        ExpressionValidationOutcome result = expressionService.expressionIsValid(getter.apply(indicator), INDICATOR_EXPRESSION);
        if (!result.isValid()) {
            issues.add(toIssue(indicator, i18n.getString(result.getKey())));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) I18n(org.hisp.dhis.i18n.I18n)

Aggregations

I18n (org.hisp.dhis.i18n.I18n)33 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)4 Date (java.util.Date)3 LinkedHashSet (java.util.LinkedHashSet)3 Locale (java.util.Locale)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)3 Period (org.hisp.dhis.period.Period)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Action (com.opensymphony.xwork2.Action)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2