Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get i18n keys for NotificationTypes

Debeka Jira
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 7, 2020

We are working on a plugin to document our projects. We want to document who gets notified in case of an event. Since we are a non english company we'd like to have the translated names (for example for current assignee). In case of a RoleNotification we couldn't find a way to retrieve the translated name. The NotificationType Enum doesn't provide a method to retrieve the translated name.

We are looking for a Class/Enum/Interface that stores the i18n keys for the NotificationTypes or a different way to handle the notfications.

 

Current Code:

ServiceOutcome<NotificationScheme> schemes =
notificationSchemeService.getNotificationSchemeForProject(getGenericAdminUser(), project.getKey());
NotificationScheme notificationScheme = schemes.getReturnedValue();

Map<String, Set<String>> notificationMapping = new HashMap<>();

for (EventNotifications eventNotifications : notificationScheme.getEventNotifications()) {

String notificationName = eventNotifications.getEventType().getTranslatedName(getGenericAdminUser());

if (!notificationMapping.containsKey(notificationName)) {
notificationMapping.put(notificationName, new HashSet<String>());
}

Set<String> value = notificationMapping.get(notificationName);

for (Notification notification : eventNotifications.getNotifications()) {
if (notification instanceof CustomFieldValueNotification) {
CustomFieldValueNotification customFieldValueNotification = (CustomFieldValueNotification) notification;
value.add(customFieldValueNotification.getCustomField().getName());
} else if (notification instanceof EmailNotification) {
EmailNotification emailNotification = (EmailNotification) notification;
value.add(emailNotification.getEmail());
} else if (notification instanceof GroupNotification) {
GroupNotification groupNotification = (GroupNotification) notification;
value.add(groupNotification.getGroup().getName());
} else if (notification instanceof ProjectRoleNotification) {
ProjectRoleNotification projectRoleNotification = (ProjectRoleNotification) notification;
value.add(projectRoleNotification.getProjectRole().getName());
} else if (notification instanceof UserNotification) {
UserNotification userNotification = (UserNotification) notification;
value.add(userNotification.getApplicationUser().getDisplayName());
} else if (notification instanceof RoleNotification) {
RoleNotification roleNotification = (RoleNotification) notification;
value.add(getNotificationTypeNameTranslation(roleNotification.getNotificationType()));
}
}
}

private String getNotificationTypeNameTranslation(NotificationType notificationType) {
I18nHelper helper = ComponentAccessor.getI18nHelperFactory().getInstance(Locale.GERMANY);
switch (notificationType) {
case ALL_WATCHERS:
return helper.getText("admin.notification.types.all.watchers");
case COMPONENT_LEAD:
return helper.getText(AssigneeTypes.PRETTY_COMPONENT_LEAD);
case CURRENT_ASSIGNEE:
return helper.getText("admin.notification.types.current.assignee");
case CURRENT_USER:
return helper.getText("admin.notification.types.current.user");
case GROUP:
return helper.getText("admin.notification.types.group");
case GROUP_CUSTOM_FIELD_VALUE:
return helper.getText("admin.notification.types.group.custom.field.value");
case PROJECT_LEAD:
return helper.getText(AssigneeTypes.PRETTY_PROJECT_LEAD);
case PROJECT_ROLE:
return helper.getText("admin.notification.types.projectrole");
case REPORTER:
return helper.getText("admin.notification.types.reporter");
case SINGLE_EMAIL_ADDRESS:
return helper.getText("admin.notification.types.single.email.address");
case SINGLE_USER:
return helper.getText("admin.notification.types.single.user");
case USER_CUSTOM_FIELD_VALUE:
return helper.getText("admin.notification.types.user.custom.field.value");
default:
return "";
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer