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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
}
}
Aggregations