use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationCustomEntity.
@Test
public void testToNotificationCustomEntity() {
NotificationCustom notification = new NotificationCustom();
notification.setNotificationType(NotificationType.CUSTOM);
notification.setSubject("Test subject");
NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
assertNotNull(notificationEntity);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.CUSTOM, notificationEntity.getNotificationType());
assertEquals("Test subject", notification.getSubject());
}
use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendNotificationToAddedDelegate.
@Override
@Transactional
public void sendNotificationToAddedDelegate(String userGrantingPermission, String userReceivingPermission) {
ProfileEntity delegateProfileEntity = profileEntityCacheManager.retrieve(userReceivingPermission);
Boolean sendAdministrativeChangeNotifications = delegateProfileEntity.getSendAdministrativeChangeNotifications();
if (sendAdministrativeChangeNotifications == null || !sendAdministrativeChangeNotifications) {
LOGGER.debug("Not sending added delegate email, because option to send administrative change notifications not set to true for delegate: {}", delegateProfileEntity.getId());
return;
}
ProfileEntity profile = profileEntityCacheManager.retrieve(userGrantingPermission);
Locale userLocale = getUserLocaleFromProfileEntity(delegateProfileEntity);
String subject = getSubject("email.subject.added_as_delegate", userLocale);
org.orcid.jaxb.model.v3.dev1.record.Email primaryEmail = emailManager.findPrimaryEmail(userGrantingPermission);
String grantingOrcidEmail = primaryEmail.getEmail();
String emailNameForDelegate = deriveEmailFriendlyName(delegateProfileEntity);
String email = emailManager.findPrimaryEmail(userReceivingPermission).getEmail();
String assetsUrl = getAssetsUrl();
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailNameForDelegate", emailNameForDelegate);
templateParams.put("grantingOrcidValue", userGrantingPermission);
templateParams.put("grantingOrcidName", deriveEmailFriendlyName(profile));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("grantingOrcidEmail", grantingOrcidEmail);
templateParams.put("subject", subject);
templateParams.put("assetsUrl", assetsUrl);
addMessageParams(templateParams, userLocale);
// Generate body from template
String body = templateManager.processTemplate("added_as_delegate_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("added_as_delegate_email_html.ftl", templateParams);
boolean notificationsEnabled = delegateProfileEntity.getEnableNotifications();
if (notificationsEnabled) {
NotificationCustom notification = new NotificationCustom();
notification.setNotificationType(NotificationType.CUSTOM);
notification.setSubject(subject);
notification.setBodyHtml(html);
createNotification(userReceivingPermission, notification);
} else {
mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, email, subject, body, html);
}
}
use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.
the class NotificationManagerTest method testCreateCustomNotification.
@Test
public void testCreateCustomNotification() {
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
String testOrcid = "0000-0000-0000-0003";
NotificationCustom notification = new NotificationCustom();
notification.setSubject("Test subject");
notification.setLang("en-gb");
Notification result = notificationManager.createNotification(testOrcid, notification);
assertNotNull(result);
assertTrue(result instanceof NotificationCustom);
NotificationCustom customResult = (NotificationCustom) result;
assertEquals("Test subject", customResult.getSubject());
assertEquals("en-gb", customResult.getLang());
}
Aggregations