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());
}
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);
}
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;
}
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);
}
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;
}
Aggregations