Search in sources :

Example 6 with DelegationDetails

use of org.orcid.jaxb.model.message.DelegationDetails in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendNotificationToAddedDelegate.

@Override
@Transactional
public void sendNotificationToAddedDelegate(String userGrantingPermission, DelegationDetails... delegatesGrantedByUser) {
    ProfileEntity profile = profileEntityCacheManager.retrieve(userGrantingPermission);
    Locale userLocale = getUserLocaleFromProfileEntity(profile);
    String subject = getSubject("email.subject.added_as_delegate", userLocale);
    for (DelegationDetails newDelegation : delegatesGrantedByUser) {
        ProfileEntity delegateProfileEntity = profileDao.find(newDelegation.getDelegateSummary().getOrcidIdentifier().getPath());
        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;
        }
        org.orcid.jaxb.model.record_v2.Email primaryEmail = emailManager.findPrimaryEmail(userGrantingPermission);
        String grantingOrcidEmail = primaryEmail.getEmail();
        String emailNameForDelegate = deriveEmailFriendlyName(delegateProfileEntity);
        String email = delegateProfileEntity.getPrimaryEmail().getId();
        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);
        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(newDelegation.getDelegateSummary().getOrcidIdentifier().getPath(), 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) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with DelegationDetails

use of org.orcid.jaxb.model.message.DelegationDetails in project ORCID-Source by ORCID.

the class NotificationManagerImpl method extractAmenderName.

private String extractAmenderName(OrcidProfile orcidProfile, String amenderId) {
    Delegation delegation = orcidProfile.getOrcidBio().getDelegation();
    if (delegation != null && delegation.getGivenPermissionTo() != null && !delegation.getGivenPermissionTo().getDelegationDetails().isEmpty()) {
        for (DelegationDetails delegationDetails : delegation.getGivenPermissionTo().getDelegationDetails()) {
            if (amenderId.equals(delegationDetails.getDelegateSummary().getOrcidIdentifier().getPath())) {
                return delegationDetails.getDelegateSummary().getCreditName().getContent();
            }
        }
    }
    ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(amenderId);
    if (clientDetailsEntity != null) {
        return clientDetailsEntity.getClientName();
    }
    return "";
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Delegation(org.orcid.jaxb.model.message.Delegation)

Example 8 with DelegationDetails

use of org.orcid.jaxb.model.message.DelegationDetails in project ORCID-Source by ORCID.

the class JpaJaxbEntityAdapterToOrcidProfileTest method checkDelegation.

private void checkDelegation(Delegation delegation) {
    assertNotNull(delegation);
    assertEquals(1, delegation.getGivenPermissionTo().getDelegationDetails().size());
    DelegationDetails givenPermssionToDetails = delegation.getGivenPermissionTo().getDelegationDetails().iterator().next();
    assertEquals("4444-4444-4444-4446", givenPermssionToDetails.getDelegateSummary().getOrcidIdentifier().getPath());
    assertTrue(givenPermssionToDetails.getApprovalDate().getValue().toXMLFormat().startsWith("2011-10-17T16:59:32.000"));
    assertEquals(1, delegation.getGivenPermissionBy().getDelegationDetails().size());
    DelegationDetails givenPermissionByDetails = delegation.getGivenPermissionBy().getDelegationDetails().iterator().next();
    assertEquals("4444-4444-4444-4441", givenPermissionByDetails.getDelegateSummary().getOrcidIdentifier().getPath());
    assertTrue(givenPermissionByDetails.getApprovalDate().getValue().toXMLFormat().startsWith("2011-08-24T11:28:16.000"));
}
Also used : DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails)

Example 9 with DelegationDetails

use of org.orcid.jaxb.model.message.DelegationDetails in project ORCID-Source by ORCID.

the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.

@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
    final String orcid = "0000-0000-0000-0003";
    String delegateOrcid = "1234-5678-1234-5678";
    ProfileEntity profile = new ProfileEntity();
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    profile.setSendAdministrativeChangeNotifications(true);
    profile.setSendChangeNotifications(true);
    profile.setSendMemberUpdateRequests(true);
    profile.setSendOrcidNews(true);
    EmailEntity emailEntity = new EmailEntity();
    emailEntity.setId("test@email.com");
    emailEntity.setPrimary(true);
    emailEntity.setCurrent(true);
    Set<EmailEntity> emails = new HashSet<EmailEntity>();
    emails.add(emailEntity);
    profile.setEmails(emails);
    SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
    when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
    when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            profile.setId(invocation.getArgument(0));
            return profile;
        }
    });
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    DelegationDetails firstNewDelegate = new DelegationDetails();
    DelegateSummary firstNewDelegateSummary = new DelegateSummary();
    firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
    firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
    firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", firstNewDelegate);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) CreditName(org.orcid.jaxb.model.message.CreditName) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

DelegationDetails (org.orcid.jaxb.model.message.DelegationDetails)9 DelegateSummary (org.orcid.jaxb.model.message.DelegateSummary)6 Delegation (org.orcid.jaxb.model.message.Delegation)4 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Test (org.junit.Test)2 CreditName (org.orcid.jaxb.model.message.CreditName)2 GivenPermissionBy (org.orcid.jaxb.model.message.GivenPermissionBy)2 GivenPermissionTo (org.orcid.jaxb.model.message.GivenPermissionTo)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1