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);
}
}
}
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 "";
}
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"));
}
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);
}
}
Aggregations