Search in sources :

Example 6 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.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(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 7 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.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.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 8 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.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.v3.dev1.notification.custom.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.v3.dev1.notification.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

NotificationCustom (org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)8 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 Test (org.junit.Test)3 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 NotificationCustomEntity (org.orcid.persistence.jpa.entities.NotificationCustomEntity)2 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 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 WorkEntityFactory (org.orcid.core.adapter.impl.WorkEntityFactory)1 ExternalIdentifierTypeConverter (org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter)1 NotificationAmended (org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)1 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)1 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)1 NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)1