Search in sources :

Example 1 with NotificationCustom

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());
}
Also used : NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Notification(org.orcid.jaxb.model.notification_v2.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with NotificationCustom

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

Example 3 with NotificationCustom

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

Example 4 with NotificationCustom

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

Example 5 with NotificationCustom

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

Aggregations

NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)9 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 Test (org.junit.Test)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 Notification (org.orcid.jaxb.model.notification_v2.Notification)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)2 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 NotificationCustomEntity (org.orcid.persistence.jpa.entities.NotificationCustomEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 MappingContext (ma.glasnost.orika.MappingContext)1 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 BaseTest (org.orcid.core.BaseTest)1