use of org.orcid.jaxb.model.v3.dev1.notification.permission.Item in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAmendEmail.
@Override
public void sendAmendEmail(String userOrcid, AmendedSection amendedSection, Collection<Item> items) {
String amenderOrcid = sourceManager.retrieveSourceOrcid();
ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid);
Locale locale = getUserLocaleFromProfileEntity(record);
if (amenderOrcid == null) {
LOGGER.info("Not sending amend email to {} because amender is null", userOrcid);
return;
}
if (amenderOrcid.equals(userOrcid)) {
LOGGER.debug("Not sending amend email, because self edited: {}", userOrcid);
return;
}
Boolean sendChangeNotifications = record.getSendChangeNotifications();
if (sendChangeNotifications == null || !sendChangeNotifications) {
LOGGER.debug("Not sending amend email, because option to send change notifications is disabled: {}", userOrcid);
return;
}
org.orcid.jaxb.model.common_v2.OrcidType amenderType = profileDao.retrieveOrcidType(amenderOrcid);
if (amenderType != null && OrcidType.ADMIN.equals(OrcidType.fromValue(amenderType.value()))) {
LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, userOrcid);
return;
}
String subject = getSubject("email.subject.amend", locale);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(record));
templateParams.put("orcid", userOrcid);
templateParams.put("amenderName", extractAmenderName(userOrcid, amenderOrcid));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("subject", subject);
addMessageParams(templateParams, locale);
// Generate body from template
String body = templateManager.processTemplate("amend_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);
boolean notificationsEnabled = record.getEnableNotifications();
if (notificationsEnabled) {
NotificationAmended notification = new NotificationAmended();
notification.setNotificationType(NotificationType.AMENDED);
notification.setAmendedSection(amendedSection);
if (items != null) {
notification.setItems(new Items(new ArrayList<>(items)));
}
createNotification(userOrcid, notification);
} else {
String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
}
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.Item in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method createItemList.
private List<Item> createItemList(OrgAffiliationRelationEntity orgAffiliationEntity) {
Item item = new Item();
item.setItemName(orgAffiliationEntity.getOrg().getName());
ItemType itemType = null;
switch(orgAffiliationEntity.getAffiliationType()) {
case DISTINCTION:
itemType = ItemType.DISTINCTION;
break;
case EDUCATION:
itemType = ItemType.EDUCATION;
break;
case EMPLOYMENT:
itemType = ItemType.EMPLOYMENT;
break;
case INVITED_POSITION:
itemType = ItemType.INVITED_POSITION;
break;
case MEMBERSHIP:
itemType = ItemType.MEMBERSHIP;
break;
case QUALIFICATION:
itemType = ItemType.QUALIFICATION;
break;
case SERVICE:
itemType = ItemType.SERVICE;
break;
}
item.setItemType(itemType);
item.setPutCode(String.valueOf(orgAffiliationEntity.getId()));
return Arrays.asList(item);
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.Item in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method createItemList.
private List<Item> createItemList(ProfileFundingEntity profileFundingEntity) {
Item item = new Item();
item.setItemName(profileFundingEntity.getTitle());
item.setItemType(ItemType.FUNDING);
item.setPutCode(String.valueOf(profileFundingEntity.getId()));
return Arrays.asList(item);
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.Item in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.
@Test
public void testToNotificationPermissionEntity() {
NotificationPermission notification = new NotificationPermission();
notification.setNotificationType(NotificationType.PERMISSION);
String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&response_type=code&scope=/orcid-works/create&redirect_uri=http://somethirdparty.com";
AuthorizationUrl url = new AuthorizationUrl();
notification.setAuthorizationUrl(url);
notification.setNotificationIntro("This is the intro");
notification.setNotificationSubject("This is the subject");
Source source = new Source();
notification.setSource(source);
SourceClientId clientId = new SourceClientId();
source.setSourceClientId(clientId);
clientId.setPath("APP-5555-5555-5555-5555");
url.setUri(authorizationUrlString);
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 NotificationAddItemsEntity);
NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
assertNotNull(notificationEntity);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.PERMISSION, notificationEntity.getNotificationType());
assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
// Source
assertNull(notificationEntity.getSourceId());
assertNull(notificationEntity.getClientSourceId());
assertNull(notificationEntity.getElementSourceId());
Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
assertNotNull(activityEntities);
assertEquals(1, activityEntities.size());
NotificationItemEntity activityEntity = activityEntities.iterator().next();
assertEquals(org.orcid.jaxb.model.notification.permission_v2.ItemType.WORK, activityEntity.getItemType());
assertEquals("Latest Research Article", activityEntity.getItemName());
assertEquals("DOI", activityEntity.getExternalIdType());
assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.Item 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());
}
Aggregations