use of org.orcid.jaxb.model.notification.custom_v2.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());
}
use of org.orcid.jaxb.model.notification.custom_v2.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(NotificationType.CUSTOM, notificationEntity.getNotificationType());
assertEquals("Test subject", notification.getSubject());
}
use of org.orcid.jaxb.model.notification.custom_v2.NotificationCustom in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAutoDeprecateNotification.
@Override
public void sendAutoDeprecateNotification(String primaryOrcid, String deprecatedOrcid) {
ProfileEntity primaryProfileEntity = profileEntityCacheManager.retrieve(primaryOrcid);
ProfileEntity deprecatedProfileEntity = profileEntityCacheManager.retrieve(deprecatedOrcid);
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(deprecatedProfileEntity.getSource().getSourceId());
Locale userLocale = LocaleUtils.toLocale(primaryProfileEntity.getLocale() == null ? org.orcid.jaxb.model.message.Locale.EN.value() : primaryProfileEntity.getLocale().value());
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
String subject = getSubject("email.subject.auto_deprecate", userLocale);
String assetsUrl = getAssetsUrl();
Date deprecatedAccountCreationDate = deprecatedProfileEntity.getDateCreated();
// Create map of template params
templateParams.put("primaryId", primaryOrcid);
templateParams.put("name", deriveEmailFriendlyName(primaryProfileEntity));
templateParams.put("assetsUrl", assetsUrl);
templateParams.put("subject", subject);
templateParams.put("clientName", clientDetails.getClientName());
templateParams.put("deprecatedAccountCreationDate", deprecatedAccountCreationDate);
templateParams.put("deprecatedId", deprecatedOrcid);
addMessageParams(templateParams, userLocale);
// Generate html from template
String html = templateManager.processTemplate("auto_deprecated_account_html.ftl", templateParams);
NotificationCustom notification = new NotificationCustom();
notification.setNotificationType(NotificationType.CUSTOM);
notification.setSubject(subject);
notification.setBodyHtml(html);
createNotification(primaryOrcid, notification);
}
use of org.orcid.jaxb.model.notification.custom_v2.NotificationCustom in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendDelegationRequestEmail.
@Override
public void sendDelegationRequestEmail(String managedOrcid, String trustedOrcid, String link) {
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("link", link);
ProfileEntity managedEntity = profileEntityCacheManager.retrieve(managedOrcid);
ProfileEntity trustedEntity = profileEntityCacheManager.retrieve(trustedOrcid);
String emailNameForDelegate = deriveEmailFriendlyName(managedEntity);
String trustedOrcidName = deriveEmailFriendlyName(trustedEntity);
templateParams.put("emailNameForDelegate", emailNameForDelegate);
templateParams.put("trustedOrcidName", trustedOrcidName);
templateParams.put("trustedOrcidValue", trustedOrcid);
templateParams.put("managedOrcidValue", managedOrcid);
String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail();
if (primaryEmail == null) {
LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
return;
}
Locale userLocale = LocaleUtils.toLocale("en");
if (managedEntity.getLocale() != null) {
userLocale = LocaleUtils.toLocale(managedEntity.getLocale().value());
}
addMessageParams(templateParams, userLocale);
String htmlBody = templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);
// Send message
if (apiRecordCreationEmailEnabled) {
String subject = messages.getMessage("email.subject.admin_as_delegate", new Object[] { trustedOrcidName }, userLocale);
boolean notificationsEnabled = trustedEntity != null ? trustedEntity.getEnableNotifications() : false;
if (notificationsEnabled) {
NotificationCustom notification = new NotificationCustom();
notification.setNotificationType(NotificationType.CUSTOM);
notification.setSubject(subject);
notification.setBodyHtml(htmlBody);
createNotification(managedOrcid, notification);
} else {
mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, primaryEmail, subject, null, htmlBody);
}
profileEventDao.persist(new ProfileEventEntity(managedOrcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
} else {
LOGGER.debug("Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}", htmlBody);
}
}
use of org.orcid.jaxb.model.notification.custom_v2.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.record_v2.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);
}
}
Aggregations