use of org.orcid.jaxb.model.notification.permission_v2.Items in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAmendEmail.
@Override
public void sendAmendEmail(OrcidProfile amendedProfile, AmendedSection amendedSection, Collection<Item> items) {
String amenderOrcid = sourceManager.retrieveSourceOrcid();
if (amenderOrcid == null) {
LOGGER.debug("Not sending amend email, because amender is null: {}", amendedProfile);
return;
}
if (amenderOrcid.equals(amendedProfile.getOrcidIdentifier().getPath())) {
LOGGER.debug("Not sending amend email, because self edited: {}", amendedProfile);
return;
}
SendChangeNotifications sendChangeNotifications = amendedProfile.getOrcidInternal().getPreferences().getSendChangeNotifications();
if (sendChangeNotifications == null || !sendChangeNotifications.isValue()) {
LOGGER.debug("Not sending amend email, because option to send change notifications not set to true: {}", amendedProfile);
return;
}
if (OrcidType.ADMIN.equals(profileDao.retrieveOrcidType(amenderOrcid))) {
LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, amendedProfile);
return;
}
String subject = getSubject("email.subject.amend", amendedProfile);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(amendedProfile));
templateParams.put("orcid", amendedProfile.getOrcidIdentifier().getPath());
templateParams.put("amenderName", extractAmenderName(amendedProfile, amenderOrcid));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("subject", subject);
addMessageParams(templateParams, amendedProfile);
// 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 = profileEntityCacheManager.retrieve(amendedProfile.getOrcidIdentifier().getPath()).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(amendedProfile.getOrcidIdentifier().getPath(), notification);
} else {
String email = amendedProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, email, subject, body, html);
}
}
use of org.orcid.jaxb.model.notification.permission_v2.Items in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAmendEmail.
@Override
public void sendAmendEmail(String orcid, AmendedSection amendedSection, Item item) {
OrcidProfile amendedProfile = orcidProfileManager.retrieveOrcidProfile(orcid, LoadOptions.BIO_AND_INTERNAL_ONLY);
Collection<Item> items = new ArrayList<Item>(1);
if (item != null) {
items.add(item);
}
sendAmendEmail(amendedProfile, amendedSection, items);
}
use of org.orcid.jaxb.model.notification.permission_v2.Items in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testEmptyRelationshipOnNotificationItemExternalIds_flagOn.
@Test(expected = ActivityIdentifierValidationException.class)
public void testEmptyRelationshipOnNotificationItemExternalIds_flagOn() {
validator.setRequireRelationshipOnExternalIdentifier(true);
Item i = new Item();
Item i2 = new Item();
Items items = new Items();
ExternalID id1 = new ExternalID();
id1.setRelationship(Relationship.SELF);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
ExternalID id2 = new ExternalID();
id2.setRelationship(null);
id2.setType("source-work-id");
id2.setValue("value2");
id2.setUrl(new Url("http://value1.com"));
i.setExternalIdentifier(id1);
i2.setExternalIdentifier(id2);
items.getItems().add(i);
items.getItems().add(i2);
//both valid
validator.validateNotificationItems(items);
fail("no exception thrown for invalid type");
}
use of org.orcid.jaxb.model.notification.permission_v2.Items in project ORCID-Source by ORCID.
the class ExternalIDValidatorTest method testEmptyRelationshipOnNotificationItemExternalIds_flagOff.
@Test
public void testEmptyRelationshipOnNotificationItemExternalIds_flagOff() {
Item i = new Item();
Item i2 = new Item();
Items items = new Items();
ExternalID id1 = new ExternalID();
id1.setRelationship(Relationship.SELF);
id1.setType("doi");
id1.setValue("value1");
id1.setUrl(new Url("http://value1.com"));
ExternalID id2 = new ExternalID();
id2.setRelationship(null);
id2.setType("source-work-id");
id2.setValue("value2");
id2.setUrl(new Url("http://value1.com"));
i.setExternalIdentifier(id1);
i2.setExternalIdentifier(id2);
items.getItems().add(i);
items.getItems().add(i2);
//both valid
validator.validateNotificationItems(items);
}
Aggregations