Search in sources :

Example 16 with Notification

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);
    }
}
Also used : Locale(java.util.Locale) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NotificationInstitutionalConnection(org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection) HashMap(java.util.HashMap) NotificationInstitutionalConnectionEntity(org.orcid.persistence.jpa.entities.NotificationInstitutionalConnectionEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails)

Example 17 with Notification

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;
}
Also used : NotificationPermissions(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermissions) ArrayList(java.util.ArrayList) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Notification

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);
}
Also used : Locale(java.util.Locale) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 19 with 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&amp;response_type=code&amp;scope=/orcid-works/create&amp;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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) SourceClientId(org.orcid.jaxb.model.v3.dev1.common.SourceClientId) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationItemEntity(org.orcid.persistence.jpa.entities.NotificationItemEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) Test(org.junit.Test)

Example 20 with Notification

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());
}
Also used : NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)13 NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)13 NotificationCustom (org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)9 HashMap (java.util.HashMap)8 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 Locale (java.util.Locale)5 NotificationInstitutionalConnection (org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection)5 Source (org.orcid.jaxb.model.v3.dev1.common.Source)4 NotificationAmended (org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)4 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Email (org.orcid.jaxb.model.v3.dev1.record.Email)3