public Boolean doInTransaction(TransactionStatus status) { boolean wasDeprecated = profileDao.deprecateProfile(deprecatedOrcid, primaryOrcid, deprecatedMethod, adminUser); // If it was successfully deprecated if (wasDeprecated) { LOGGER.info("Account {} was deprecated to primary account: {}", deprecatedOrcid, primaryOrcid); clearRecord(deprecatedOrcid, false); // Move all email's to the primary record Emails deprecatedAccountEmails = emailManager.getEmails(deprecatedOrcid); if (deprecatedAccountEmails != null) { // For each email in the deprecated profile for (Email email : deprecatedAccountEmails.getEmails()) { // Delete each email from the deprecated // profile LOGGER.info("About to move email {} from profile {} to profile {}", new Object[] { email.getEmail(), deprecatedOrcid, primaryOrcid }); emailManager.moveEmailToOtherAccount(email.getEmail(), deprecatedOrcid, primaryOrcid); } } profileDao.updateLastModifiedDateAndIndexingStatus(deprecatedOrcid, IndexingStatus.REINDEX); return true; } return false; } });
@Override public String getQRCode(String orcid) { if (userUsing2FA(orcid)) { // don't allow generation of new code if user already using throw new UserAlreadyUsing2FAException(); } // generate secret but don't switch on using2FA - user may abort process String secret = Base32.random(); profileEntityManager.update2FASecret(orcid, encryptionManager.encryptForInternalUse(secret)); Email email = emailManagerReadOnly.findPrimaryEmail(orcid); try { return QR_PREFIX + URLEncoder.encode(String.format("otpauth://totp/%s:%s?secret=%s&issuer=%s", APP_NAME, email.getEmail(), secret, APP_NAME), "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error("Error generating QR code", e); return null; } }
@Override public void sendOrcidDeactivateEmail(String userOrcid) { ProfileEntity profile = profileEntityCacheManager.retrieve(userOrcid); Locale userLocale = getUserLocaleFromProfileEntity(profile); org.orcid.jaxb.model.record_v2.Email primaryEmail = emailManager.findPrimaryEmail(userOrcid); Map<String, Object> templateParams = new HashMap<String, Object>(); String subject = getSubject("email.subject.deactivate", userLocale); String email = primaryEmail.getEmail(); String encryptedEmail = encryptionManager.encryptForExternalUse(email); String base64EncodedEmail = Base64.encodeBase64URLSafeString(encryptedEmail.getBytes()); String deactivateUrlEndpointPath = "/account/confirm-deactivate-orcid"; String emailFriendlyName = deriveEmailFriendlyName(profile); templateParams.put("emailName", emailFriendlyName); templateParams.put("orcid", userOrcid); templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp()); templateParams.put("deactivateUrlEndpoint", deactivateUrlEndpointPath + "/" + base64EncodedEmail); templateParams.put("deactivateUrlEndpointUrl", deactivateUrlEndpointPath); templateParams.put("subject", subject); addMessageParams(templateParams, userLocale); // Generate body from template String body = templateManager.processTemplate("deactivate_orcid_email.ftl", templateParams); // Generate html from template String html = templateManager.processTemplate("deactivate_orcid_email_html.ftl", templateParams); mailGunManager.sendEmail(DEACTIVATE_NOTIFY_ORCID_ORG, email, subject, body, html); }
@Override public void sendOrcidLockedEmail(String orcidToLock) { ProfileEntity profile = profileEntityCacheManager.retrieve(orcidToLock); Locale userLocale = getUserLocaleFromProfileEntity(profile); String subject = getSubject("email.subject.locked", userLocale); String email = emailManager.findPrimaryEmail(orcidToLock).getEmail(); String emailFriendlyName = deriveEmailFriendlyName(profile); Map<String, Object> templateParams = new HashMap<String, Object>(); templateParams.put("emailName", emailFriendlyName); templateParams.put("orcid", orcidToLock); templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp()); templateParams.put("subject", subject); addMessageParams(templateParams, userLocale); // Generate body from template String body = templateManager.processTemplate("locked_orcid_email.ftl", templateParams); // Generate html from template String html = templateManager.processTemplate("locked_orcid_email_html.ftl", templateParams); mailGunManager.sendEmail(LOCKED_NOTIFY_ORCID_ORG, email, subject, body, html); }
@Override public void sendPasswordResetEmail(String submittedEmail, String userOrcid) { ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid); String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail(); Locale locale = getUserLocaleFromProfileEntity(record); // Create map of template params Map<String, Object> templateParams = new HashMap<String, Object>(); templateParams.put("emailName", deriveEmailFriendlyName(record)); templateParams.put("submittedEmail", submittedEmail); templateParams.put("orcid", userOrcid); templateParams.put("subject", getSubject("email.subject.reset", getUserLocaleFromProfileEntity(record))); templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp()); // Generate body from template String resetUrl = createResetEmail(primaryEmail, orcidUrlManager.getBaseUrl()); templateParams.put("passwordResetUrl", resetUrl); addMessageParams(templateParams, locale); // Generate body from template String body = templateManager.processTemplate("reset_password_email.ftl", templateParams); String htmlBody = templateManager.processTemplate("reset_password_email_html.ftl", templateParams); mailGunManager.sendEmail(RESET_NOTIFY_ORCID_ORG, submittedEmail, getSubject("email.subject.reset", locale), body, htmlBody); }
private void createOpportunityContact(Contact contact, String opportunityId) { String accountId = contact.getAccountId(); String contactOrcid = contact.getOrcid(); if (StringUtils.isBlank(contact.getEmail())) { Email primaryEmail = emailManager.getEmails(contactOrcid).getEmails().stream().filter(e -> e.isPrimary()).findFirst().get(); contact.setEmail(primaryEmail.getEmail()); } List<Contact> existingContacts = salesForceDao.retrieveAllContactsByAccountId(accountId); Optional<Contact> existingContact = existingContacts.stream().filter(c -> { if ((contact.getOrcid() != null && contact.getOrcid().equals(c.getOrcid())) || (contact.getEmail() != null && contact.getEmail().equals(c.getEmail()))) { return true; } return false; }).findFirst(); String contactId = existingContact.isPresent() ? existingContact.get().getId() : salesForceDao.createContact(contact); OpportunityContactRole contactRole = new OpportunityContactRole(); contactRole.setContactId(contactId); contactRole.setRoleType(ContactRoleType.MAIN_CONTACT); contactRole.setOpportunityId(opportunityId); salesForceDao.createOpportunityContactRole(contactRole); addSalesForceConnection(accountId, contact); }
String creatorName = record.getSource() == null ? null : SourceEntityUtils.getSourceName(record.getSource()); Locale userLocale = getUserLocaleFromProfileEntity(record); String email = emailManager.findPrimaryEmail(orcid).getEmail(); String emailName = deriveEmailFriendlyName(record); String verificationUrl = createClaimVerificationUrl(email, orcidUrlManager.getBaseUrl());
String contactOrcid = contact.getOrcid(); Email primaryEmail = emailManager.getEmails(contactOrcid).getEmails().stream().filter(e -> e.isPrimary()).findFirst().get(); contact.setEmail(primaryEmail.getEmail());
templateParams.put("managedOrcidValue", managedOrcid); String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail(); if (primaryEmail == null) { LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
@Override public void sendClaimReminderEmail(String userOrcid, int daysUntilActivation) { ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid); String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail(); Locale locale = getUserLocaleFromProfileEntity(record);
request.setSuccessMessage(localeManager.resolveMessage("admin.delegate.admin.success", primaryEmail.getEmail()));
if (email.isCurrent()) { Individual mbox = m.createIndividual("mailto:" + email.getEmail(), null); person.addProperty(FOAF.mbox, mbox);