Search in sources :

Example 21 with Notification

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

Example 22 with Notification

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());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) 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) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended) Test(org.junit.Test)

Example 23 with Notification

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());
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Notification

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

Example 25 with Notification

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());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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