use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAcknowledgeMessage.
@Override
public void sendAcknowledgeMessage(String userOrcid, String clientId) throws UnsupportedEncodingException {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
Locale userLocale = (profileEntity.getLocale() == null || profileEntity.getLocale().value() == null) ? Locale.ENGLISH : LocaleUtils.toLocale(profileEntity.getLocale().value());
String subject = getSubject("email.subject.institutional_sign_in", userLocale);
String authorizationUrl = buildAuthorizationUrlForInstitutionalSignIn(clientDetails);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(profileEntity));
templateParams.put("orcid", userOrcid);
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("subject", subject);
templateParams.put("clientName", clientDetails.getClientName());
templateParams.put("authorization_url", authorizationUrl);
addMessageParams(templateParams, userLocale);
// Generate body from template
String body = templateManager.processTemplate("authenticate_request_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("authenticate_request_email_html.ftl", templateParams);
boolean notificationsEnabled = profileEntity.getEnableNotifications();
if (notificationsEnabled) {
NotificationInstitutionalConnection notification = new NotificationInstitutionalConnection();
notification.setNotificationType(NotificationType.INSTITUTIONAL_CONNECTION);
notification.setAuthorizationUrl(new AuthorizationUrl(authorizationUrl));
NotificationInstitutionalConnectionEntity notificationEntity = (NotificationInstitutionalConnectionEntity) notificationAdapter.toNotificationEntity(notification);
notificationEntity.setProfile(new ProfileEntity(userOrcid));
notificationEntity.setClientSourceId(clientId);
notificationEntity.setAuthenticationProviderId(clientDetails.getAuthenticationProviderId());
notificationDao.persist(notificationEntity);
} else {
Emails emails = emailManager.getEmails(userOrcid);
String primaryEmail = null;
if (emails == null || emails.getEmails() == null) {
throw new IllegalArgumentException("Unable to find primary email for: " + userOrcid);
}
for (org.orcid.jaxb.model.v3.dev1.record.Email email : emails.getEmails()) {
if (email.isPrimary()) {
primaryEmail = email.getEmail();
}
}
mailGunManager.sendEmail(UPDATE_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
}
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class NotificationManagerImpl method findPermissionsByOrcidAndClient.
@Override
@Transactional(readOnly = true)
public NotificationPermissions findPermissionsByOrcidAndClient(String orcid, String client, int firstResult, int maxResults) {
NotificationPermissions notifications = new NotificationPermissions();
List<Notification> notificationsForOrcidAndClient = notificationAdapter.toNotification(notificationDao.findPermissionsByOrcidAndClient(orcid, client, firstResult, maxResults));
List<NotificationPermission> notificationPermissions = new ArrayList<>();
notificationsForOrcidAndClient.forEach(n -> notificationPermissions.add((NotificationPermission) n));
notifications.setNotifications(notificationPermissions);
return notifications;
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification 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.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.
@Test
public void testToNotificationPermissionEntity() {
NotificationPermission notification = new NotificationPermission();
notification.setNotificationType(NotificationType.PERMISSION);
String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&response_type=code&scope=/orcid-works/create&redirect_uri=http://somethirdparty.com";
AuthorizationUrl url = new AuthorizationUrl();
notification.setAuthorizationUrl(url);
notification.setNotificationIntro("This is the intro");
notification.setNotificationSubject("This is the subject");
Source source = new Source();
notification.setSource(source);
SourceClientId clientId = new SourceClientId();
source.setSourceClientId(clientId);
clientId.setPath("APP-5555-5555-5555-5555");
url.setUri(authorizationUrlString);
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 NotificationAddItemsEntity);
NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
assertNotNull(notificationEntity);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.PERMISSION, notificationEntity.getNotificationType());
assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
// Source
assertNull(notificationEntity.getSourceId());
assertNull(notificationEntity.getClientSourceId());
assertNull(notificationEntity.getElementSourceId());
Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
assertNotNull(activityEntities);
assertEquals(1, activityEntities.size());
NotificationItemEntity activityEntity = activityEntities.iterator().next();
assertEquals(org.orcid.jaxb.model.notification.permission_v2.ItemType.WORK, activityEntity.getItemType());
assertEquals("Latest Research Article", activityEntity.getItemName());
assertEquals("DOI", activityEntity.getExternalIdType());
assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
use of org.orcid.jaxb.model.v3.dev1.notification.Notification in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testCustomEntityToNotification.
@Test
public void testCustomEntityToNotification() {
NotificationCustomEntity notificationEntity = new NotificationCustomEntity();
notificationEntity.setId(123L);
notificationEntity.setNotificationType(org.orcid.jaxb.model.notification_v2.NotificationType.CUSTOM);
notificationEntity.setSubject("Test subject");
notificationEntity.setDateCreated(DateUtils.convertToDate("2014-01-01T09:17:56"));
notificationEntity.setReadDate(DateUtils.convertToDate("2014-03-04T17:43:06"));
Notification notification = jpaJaxbNotificationAdapter.toNotification(notificationEntity);
assertNotNull(notification);
assertTrue(notification instanceof NotificationCustom);
NotificationCustom notificationCustom = (NotificationCustom) notification;
assertEquals(NotificationType.CUSTOM, notification.getNotificationType());
assertEquals("Test subject", notificationCustom.getSubject());
assertEquals("2014-01-01T09:17:56.000Z", notification.getCreatedDate().toXMLFormat());
assertEquals("2014-03-04T17:43:06.000Z", notification.getReadDate().toXMLFormat());
}
Aggregations