use of org.orcid.jaxb.model.v3.dev1.notification.Notification 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.Notification in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.
@Test
public void testToNotificationAmendedEntity() {
NotificationAmended notification = new NotificationAmended();
notification.setNotificationType(NotificationType.AMENDED);
Source source = new Source();
notification.setSource(source);
SourceClientId clientId = new SourceClientId();
source.setSourceClientId(clientId);
clientId.setPath("APP-5555-5555-5555-5555");
Items activities = new Items();
notification.setItems(activities);
Item activity = new Item();
activities.getItems().add(activity);
activity.setItemType(ItemType.WORK);
activity.setItemName("Latest Research Article");
ExternalID extId = new ExternalID();
activity.setExternalIdentifier(extId);
extId.setType("doi");
extId.setValue("1234/abc123");
NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
assertTrue(notificationEntity instanceof NotificationAmendedEntity);
NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
assertNotNull(notificationEntity);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.AMENDED, notificationEntity.getNotificationType());
// Source
assertNull(notificationAmendedEntity.getSourceId());
assertNull(notificationAmendedEntity.getClientSourceId());
assertNull(notificationAmendedEntity.getElementSourceId());
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class EmailManagerImpl method addEmail.
@Override
@Transactional
public void addEmail(HttpServletRequest request, String orcid, Email email) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
String sourceId = sourceEntity.getSourceProfile() == null ? null : sourceEntity.getSourceProfile().getId();
String clientSourceId = sourceEntity.getSourceClient() == null ? null : sourceEntity.getSourceClient().getId();
Email currentPrimaryEmail = findPrimaryEmail(orcid);
// Create the new email
emailDao.addEmail(orcid, email.getEmail(), org.orcid.jaxb.model.common_v2.Visibility.fromValue(email.getVisibility().value()), sourceId, clientSourceId);
// if primary email changed send notification.
if (email.isPrimary() && !StringUtils.equals(currentPrimaryEmail.getEmail(), email.getEmail())) {
request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
notificationManager.sendEmailAddressChangedNotification(orcid, email.getEmail(), currentPrimaryEmail.getEmail());
}
// send verifcation email for new address
notificationManager.sendVerificationEmail(orcid, email.getEmail());
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification 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.Notification in project ORCID-Source by ORCID.
the class NotificationValidationManagerImpl method validateNotificationPermission.
@Override
public void validateNotificationPermission(NotificationPermission notification) {
AuthorizationUrl authorizationUrl = notification.getAuthorizationUrl();
String uriString = authorizationUrl.getUri();
if (StringUtils.isNotBlank(uriString)) {
try {
new URI(uriString);
} catch (URISyntaxException e) {
throw new OrcidValidationException("Bad authorization uri", e);
}
}
externalIDValidator.validateNotificationItems(notification.getItems());
}
Aggregations