Search in sources :

Example 6 with Items

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Items(org.orcid.jaxb.model.notification.permission_v2.Items) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 7 with Items

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);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Item(org.orcid.jaxb.model.notification.permission_v2.Item) ArrayList(java.util.ArrayList)

Example 8 with 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");
}
Also used : Item(org.orcid.jaxb.model.notification.permission_v2.Item) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Example 9 with Items

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);
}
Also used : Item(org.orcid.jaxb.model.notification.permission_v2.Item) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Items(org.orcid.jaxb.model.notification.permission_v2.Items) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)7 Items (org.orcid.jaxb.model.notification.permission_v2.Items)7 Test (org.junit.Test)6 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ArrayList (java.util.ArrayList)3 Source (org.orcid.jaxb.model.common_v2.Source)3 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)3 Url (org.orcid.jaxb.model.common_v2.Url)3 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)2 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)2 NotificationEntity (org.orcid.persistence.jpa.entities.NotificationEntity)2 HashMap (java.util.HashMap)1 BaseTest (org.orcid.core.BaseTest)1 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)1 SourceName (org.orcid.jaxb.model.common_v2.SourceName)1 FamilyName (org.orcid.jaxb.model.message.FamilyName)1 GivenNames (org.orcid.jaxb.model.message.GivenNames)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1