Search in sources :

Example 1 with AmendedSection

use of org.orcid.jaxb.model.notification.amended_v2.AmendedSection 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SendChangeNotifications (org.orcid.jaxb.model.message.SendChangeNotifications)1 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)1 Items (org.orcid.jaxb.model.notification.permission_v2.Items)1