Search in sources :

Example 1 with Source

use of org.orcid.jaxb.model.message.Source in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorImpl method setSponsorFromAuthentication.

public void setSponsorFromAuthentication(OrcidProfile profile) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (profile.getOrcidHistory() == null) {
        OrcidHistory orcidHistory = new OrcidHistory();
        orcidHistory.setCreationMethod(CreationMethod.API);
        profile.setOrcidHistory(orcidHistory);
    }
    profile.getOrcidHistory().setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        Source sponsor = new Source();
        String sponsorId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(sponsorId);
        if (clientDetails != null) {
            sponsor.setSourceName(new SourceName(clientDetails.getClientName()));
            if (OrcidStringUtils.isClientId(sponsorId)) {
                sponsor.setSourceClientId(new SourceClientId(sponsorId));
            } else {
                sponsor.setSourceOrcid(new SourceOrcid(sponsorId));
            }
        }
        profile.getOrcidHistory().setSource(sponsor);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceName(org.orcid.jaxb.model.message.SourceName) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source)

Example 2 with Source

use of org.orcid.jaxb.model.message.Source in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendClaimReminderEmail.

@Override
public void sendClaimReminderEmail(OrcidProfile orcidProfile, int daysUntilActivation) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(orcidProfile));
    String orcid = orcidProfile.getOrcidIdentifier().getPath();
    templateParams.put("orcid", orcid);
    templateParams.put("subject", getSubject("email.subject.claim_reminder", orcidProfile));
    Source source = orcidProfile.getOrcidHistory().getSource();
    String creatorName = "";
    if (source != null) {
        if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
            creatorName = source.getSourceName().getContent();
        } else {
            creatorName = source.retrieveSourcePath();
        }
    }
    templateParams.put("creatorName", creatorName);
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("daysUntilActivation", daysUntilActivation);
    Email primaryEmail = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail();
    if (primaryEmail == null) {
        LOGGER.info("Cant send claim reminder email if primary email is null: {}", orcid);
        return;
    }
    String verificationUrl = createClaimVerificationUrl(primaryEmail.getValue(), orcidUrlManager.getBaseUrl());
    templateParams.put("verificationUrl", verificationUrl);
    addMessageParams(templateParams, orcidProfile);
    String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
    // Generate body from template
    String body = templateManager.processTemplate("claim_reminder_email.ftl", templateParams);
    String htmlBody = templateManager.processTemplate("claim_reminder_email_html.ftl", templateParams);
    // Send message
    if (apiRecordCreationEmailEnabled) {
        mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, getSubject("email.subject.claim_reminder", orcidProfile), body, htmlBody);
        profileEventDao.persist(new ProfileEventEntity(orcid, ProfileEventType.CLAIM_REMINDER_SENT));
    } else {
        LOGGER.debug("Not sending claim reminder email, because API record creation email option is disabled. Message would have been: {}", body);
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) Source(org.orcid.jaxb.model.message.Source) MessageSource(org.springframework.context.MessageSource)

Example 3 with Source

use of org.orcid.jaxb.model.message.Source in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendApiRecordCreationEmail.

@Override
@Transactional
public void sendApiRecordCreationEmail(String toEmail, OrcidProfile createdProfile) {
    Source source = null;
    CustomEmailEntity customEmail = null;
    if (createdProfile.getOrcidHistory() != null && createdProfile.getOrcidHistory().getSource() != null) {
        if (!PojoUtil.isEmpty(createdProfile.getOrcidHistory().getSource().retrieveSourcePath())) {
            source = createdProfile.getOrcidHistory().getSource();
            customEmail = getCustomizedEmail(createdProfile.getOrcidHistory().getSource().retrieveSourcePath(), EmailType.CLAIM);
        }
    }
    String email = createdProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue().trim();
    String emailName = deriveEmailFriendlyName(createdProfile);
    String orcid = createdProfile.getOrcidIdentifier().getPath();
    String verificationUrl = createClaimVerificationUrl(email, orcidUrlManager.getBaseUrl());
    String creatorName = "";
    if (source != null) {
        if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
            creatorName = source.getSourceName().getContent();
        } else if (!PojoUtil.isEmpty(source.retrieveSourcePath())) {
            creatorName = source.retrieveSourcePath();
        }
    }
    String subject = null;
    String body = null;
    String htmlBody = null;
    String sender = null;
    if (customEmail != null) {
        // Get the customized sender if available
        sender = PojoUtil.isEmpty(customEmail.getSender()) ? CLAIM_NOTIFY_ORCID_ORG : customEmail.getSender();
        // Get the customized subject is available
        subject = PojoUtil.isEmpty(customEmail.getSubject()) ? getSubject("email.subject.api_record_creation", createdProfile) : customEmail.getSubject();
        // Replace the wildcards
        subject = subject.replace(WILDCARD_USER_NAME, emailName);
        subject = subject.replace(WILDCARD_MEMBER_NAME, creatorName);
        if (customEmail.isHtml()) {
            htmlBody = customEmail.getContent();
            htmlBody = htmlBody.replace(WILDCARD_USER_NAME, emailName);
            htmlBody = htmlBody.replace(WILDCARD_MEMBER_NAME, creatorName);
            htmlBody = htmlBody.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
            if (htmlBody.contains(WILDCARD_WEBSITE) || htmlBody.contains(WILDCARD_DESCRIPTION)) {
                ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
                htmlBody = htmlBody.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
                htmlBody = htmlBody.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
            }
        } else {
            body = customEmail.getContent();
            body = body.replace(WILDCARD_USER_NAME, emailName);
            body = body.replace(WILDCARD_MEMBER_NAME, creatorName);
            body = body.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
            if (body.contains(WILDCARD_WEBSITE) || body.contains(WILDCARD_DESCRIPTION)) {
                ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
                body = body.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
                body = body.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
            }
        }
    } else {
        subject = getSubject("email.subject.api_record_creation", createdProfile);
        // Create map of template params
        Map<String, Object> templateParams = new HashMap<String, Object>();
        templateParams.put("emailName", emailName);
        templateParams.put("orcid", orcid);
        templateParams.put("subject", subject);
        templateParams.put("creatorName", creatorName);
        templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
        templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
        templateParams.put("verificationUrl", verificationUrl);
        addMessageParams(templateParams, createdProfile);
        // Generate body from template
        body = templateManager.processTemplate("api_record_creation_email.ftl", templateParams);
        htmlBody = templateManager.processTemplate("api_record_creation_email_html.ftl", templateParams);
    }
    // Send message
    if (apiRecordCreationEmailEnabled) {
        boolean isCustomEmail = customEmail != null ? true : false;
        // mailgun
        if (isCustomEmail) {
            mailGunManager.sendEmail(sender, email, subject, body, htmlBody, isCustomEmail);
        } else {
            mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, subject, body, htmlBody);
        }
    } else {
        LOGGER.debug("Not sending API record creation email, because option is disabled. Message would have been: {}", body);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) HashMap(java.util.HashMap) CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) Source(org.orcid.jaxb.model.message.Source) MessageSource(org.springframework.context.MessageSource) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Source

use of org.orcid.jaxb.model.message.Source in project ORCID-Source by ORCID.

the class OrcidJaxbCopyManagerImpl method createSource.

private Source createSource(String amenderOrcid) {
    Source source = new Source();
    if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
        source.setSourceOrcid(new SourceOrcid(amenderOrcid));
        source.setSourceClientId(null);
    } else {
        source.setSourceClientId(new SourceClientId(amenderOrcid));
        source.setSourceOrcid(null);
    }
    return source;
}
Also used : SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Example 5 with Source

use of org.orcid.jaxb.model.message.Source in project ORCID-Source by ORCID.

the class OrcidMessageVersionConverterImplV1_2_rc5ToV1_2_rc6 method downgradeProfile.

private void downgradeProfile(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidBio() != null)
            if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null)
                for (ExternalIdentifier externalIdentifier : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
                    Source source = externalIdentifier.getSource();
                    if (source != null) {
                        SourceOrcid sourceOrcid = source.getSourceOrcid();
                        if (sourceOrcid != null) {
                            externalIdentifier.setSource(null);
                            externalIdentifier.setExternalIdSource(new ExternalIdSource(sourceOrcid));
                        }
                    }
                }
        if (orcidProfile.getOrcidActivities() != null) {
            if (orcidProfile.getOrcidActivities().getOrcidWorks() != null) {
                for (OrcidWork act : orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork()) downGradeActivity(act);
            }
        }
        OrcidInternal orcidInternal = orcidProfile.getOrcidInternal();
        if (orcidInternal != null) {
            Preferences prefs = orcidInternal.getPreferences();
            if (prefs != null) {
                prefs.setSendEmailFrequencyDays(null);
                prefs.setSendMemberUpdateRequests(null);
            }
            ReferredBy referredBy = orcidInternal.getReferredBy();
            if (referredBy != null && !OrcidStringUtils.isValidOrcid(referredBy.getPath())) {
                orcidInternal.setReferredBy(null);
            }
        }
    }
}
Also used : WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) ReferredBy(org.orcid.jaxb.model.message.ReferredBy) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Preferences(org.orcid.jaxb.model.message.Preferences) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) Source(org.orcid.jaxb.model.message.Source) WorkSource(org.orcid.jaxb.model.message.WorkSource)

Aggregations

Source (org.orcid.jaxb.model.message.Source)30 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)14 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)11 SourceOrcid (org.orcid.jaxb.model.message.SourceOrcid)10 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)9 Title (org.orcid.jaxb.model.message.Title)9 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)8 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)8 Test (org.junit.Test)7 Subtitle (org.orcid.jaxb.model.message.Subtitle)7 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Date (java.util.Date)6 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)6 HashMap (java.util.HashMap)5 Claimed (org.orcid.jaxb.model.message.Claimed)5 Email (org.orcid.jaxb.model.message.Email)5 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)5 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)5 SourceClientId (org.orcid.jaxb.model.message.SourceClientId)5