public String retrieveOrcidPath() { if (orcidIdentifier == null) { return null; } String path = orcidIdentifier.getPath(); if (path != null) { return path; } if (orcid != null) { return orcid.getValue(); } return null; }
private String getUserOrcidFromOrcidMessage(OrcidMessage message) { OrcidProfile profile = message.getOrcidProfile(); return profile.getOrcidIdentifier().getPath(); }
@Override public void deleteOrcidProfile(OrcidProfile orcidProfile) { deleteOrcidProfile(orcidProfile.getOrcidIdentifier().getPath()); }
public void put(OrcidProfile orcidProfile) { put(orcidProfile.getOrcidIdentifier().getPath(), orcidProfile); }
@Override public OrcidProfile doInTransaction(TransactionStatus status) { return convertToOrcidProfile(profileDao.find(orcidProfile.getOrcidIdentifier().getPath()), LoadOptions.ALL); }
@Override public OrcidProfile updateOrcidPreferences(OrcidProfile updatedOrcidProfile) { OrcidProfile existingProfile = retrieveOrcidProfile(updatedOrcidProfile.getOrcidIdentifier().getPath()); if (existingProfile == null) { return null; } existingProfile.setOrcidPreferences(updatedOrcidProfile.getOrcidPreferences()); OrcidProfile profileToReturn = updateOrcidProfile(existingProfile); notificationManager.sendAmendEmail(updatedOrcidProfile.getOrcidIdentifier().getPath(), AmendedSection.PREFERENCES, null); return profileToReturn; }
@Override @Deprecated //now going via orcid-message-listener public void persistProfileInformationForIndexingIfNecessary(OrcidProfile orcidProfile) { String orcid = orcidProfile.getOrcidIdentifier().getPath(); Date lastModifiedFromSolr = solrDao.retrieveLastModified(orcid); Date lastModifiedFromDb = orcidProfile.getOrcidHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime(); if (lastModifiedFromDb.equals(lastModifiedFromSolr)) { // Check if re-indexing IndexingStatus indexingStatus = profileDao.retrieveIndexingStatus(orcid); if (!IndexingStatus.REINDEX.equals(indexingStatus)) { // If not re-indexing then skip LOG.info("Index is already up to date for orcid: {}", orcid); return; } } persistProfileInformationForIndexing(orcidProfile); }
private void performClientChecks(OAuth2Authentication oAuth2Authentication, ScopePathType requiredScope, OrcidMessage orcidMessage, String orcid) { OAuth2Request authorizationRequest = oAuth2Authentication.getOAuth2Request(); // If we have an ORCID in the request, we assume that this is intended // as an update if (orcidMessage != null && orcidMessage.getOrcidProfile() != null && StringUtils.isNotBlank(orcid)) { OrcidIdentifier orcidOb = orcidMessage.getOrcidProfile().getOrcidIdentifier(); String messageOrcid = orcidOb != null ? orcidOb.getPath() : orcid; if (StringUtils.isNotBlank(messageOrcid) && !orcid.equals(messageOrcid)) { throw new IllegalArgumentException("The ORCID in the body and the URI do NOT match. Body ORCID: " + messageOrcid + " URI ORCID: " + orcid + " do NOT match."); } profileEntityCacheManager.retrieve(messageOrcid); if (!profileEntityManager.existsAndNotClaimedAndBelongsTo(messageOrcid, authorizationRequest.getClientId())) { throw new AccessControlException("You cannot update this profile as it has been claimed, or you are not the owner."); } } }
public static String createCacheKey(OrcidProfile profile) { OrcidHistory orcidHistory = profile.getOrcidHistory(); OrcidIdentifier orcidIdentifier = profile.getOrcidIdentifier(); String xmlFormatLastModifiedDate = (orcidHistory != null && orcidHistory.getLastModifiedDate() != null) ? orcidHistory.getLastModifiedDate().getValue() .toXMLFormat() : "no-last-modified"; String path = orcidIdentifier != null ? orcidIdentifier.getPath() : "no-orcid-identifier"; return StringUtils.join(new String[] {path, xmlFormatLastModifiedDate, profile.getReleaseName() }, "_"); }
/** * Updates the ORCID bio data * * @param updatedOrcidProfile * @return */ @Deprecated @Override public OrcidProfile updateOrcidBio(OrcidProfile updatedOrcidProfile) { addSourceToBioElements(updatedOrcidProfile); OrcidProfile existingProfile = retrieveOrcidProfile(updatedOrcidProfile.getOrcidIdentifier().getPath(), LoadOptions.ALL_WITH_NEW_AFFILIATION_TYPES); if (existingProfile == null) { return null; } // preserve the visibility settings orcidJaxbCopyManager.copyUpdatedBioToExistingWithVisibility(existingProfile.getOrcidBio(), updatedOrcidProfile.getOrcidBio()); OrcidProfile profileToReturn = updateOrcidProfile(existingProfile, UpdateOptions.NO_ACTIVITIES); notificationManager.sendAmendEmail(updatedOrcidProfile.getOrcidIdentifier().getPath(), AmendedSection.BIO, null); return profileToReturn; }
public boolean sendVerifiedRequiredAnnouncement2017(OrcidProfile orcidProfile) { String orcid = orcidProfile.getOrcidIdentifier().getPath(); String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(); String emailFriendlyName = notificationManager.deriveEmailFriendlyName(profileDaoReadOnly.find(orcid)); String verificationUrl = notificationManager.createVerificationUrl(email, orcidUrlManager.getBaseUrl()); String emailFrequencyUrl = notificationManager.createUpdateEmailFrequencyUrl(orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue()); Map<String, Boolean> features = new HashMap<String, Boolean>(); for(Features f : Features.values()) { features.put(f.name(), f.isActive()); } Locale locale = localeManager.getLocaleFromOrcidProfile(orcidProfile); Map<String, Object> templateParams = new HashMap<String, Object>(); templateParams.put("emailName", emailFriendlyName); templateParams.put("verificationUrl", verificationUrl); templateParams.put("emailFrequencyUrl", emailFrequencyUrl); templateParams.put("orcid", orcid); templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); templateParams.put("messages", this.messages); templateParams.put("messageArgs", new Object[0]); templateParams.put("locale", locale); templateParams.put("features", features); String subject = messages.getMessage("email.service_announcement.subject.imporant_information", null, locale); String text = templateManager.processTemplate("verified_required_announcement_2017.ftl", templateParams); String html = templateManager.processTemplate("verified_required_announcement_2017_html.ftl", templateParams); return mailGunManager.sendEmail("support@notify.orcid.org", email, subject, text, html); }
private String getMessageIdForLog(OrcidMessage messageToBeFiltered) { String messageIdForLog = "unknown"; OrcidSearchResults orcidSearchResults = messageToBeFiltered.getOrcidSearchResults(); OrcidProfile orcidProfile = messageToBeFiltered.getOrcidProfile(); if (orcidSearchResults != null) { messageIdForLog = "orcid-search-results"; } else if (orcidProfile != null) { OrcidIdentifier orcidIdentifier = orcidProfile.getOrcidIdentifier(); if (orcidIdentifier != null) { messageIdForLog = orcidIdentifier.getPath(); } Orcid orcid = orcidProfile.getOrcid(); if (orcid != null) { messageIdForLog = orcid.getValue(); } } return messageIdForLog; }
/** * Check the permissions for the given * {@link org.springframework.security.core.Authentication} object and the * scopes defined in the required scopes * * @param authentication * The authentication object associated with this session * @param requiredScope * the scopes required to perform the requested operation * @param orcid * the orcid passed into the request. This is for requests, such * as a GET /1234-1234-1234-1234/orcid-bio * @param orcidMessage * the {@link org.orcid.jaxb.model.message.OrcidMessage} that has * been sent as part of this request. This will only apply to * PUTs and POSTs */ @Override public void checkPermissions(Authentication authentication, ScopePathType requiredScope, String orcid, OrcidMessage orcidMessage) { if (StringUtils.isNotBlank(orcid) && orcidMessage != null && orcidMessage.getOrcidProfile() != null && (orcidMessage.getOrcidProfile().getOrcidIdentifier() == null || StringUtils.isBlank(orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath()))) { orcidMessage.getOrcidProfile().setOrcidIdentifier(orcid); } performPermissionChecks(authentication, requiredScope, orcid, orcidMessage); }
public boolean sendServiceAnnouncement_1_For_2015(OrcidProfile orcidProfile) { String orcid = orcidProfile.getOrcidIdentifier().getPath(); String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(); String emailFriendlyName = notificationManager.deriveEmailFriendlyName(profileDaoReadOnly.find(orcid));
@Override public OrcidProfile createOrcidProfileAndNotify(OrcidProfile orcidProfile) { OrcidProfile createdOrcidProfile = createOrcidProfile(orcidProfile, true, false); notificationManager.sendApiRecordCreationEmail(orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue(), orcidProfile.getOrcidIdentifier().getPath()); return createdOrcidProfile; }
@Override @Deprecated public OrcidProfile updateAffiliations(OrcidProfile updatedOrcidProfile) { OrcidProfile existingProfile = retrieveOrcidProfile(updatedOrcidProfile.getOrcidIdentifier().getPath(), LoadOptions.ALL_WITH_NEW_AFFILIATION_TYPES); if (existingProfile == null) { return null; } OrcidActivities updatedActivities = updatedOrcidProfile.getOrcidActivities(); if (updatedActivities == null) { return null; } Affiliations updatedAffiliations = updatedActivities.getAffiliations(); if (updatedAffiliations == null) { return null; } OrcidActivities existingActivities = existingProfile.getOrcidActivities(); if (existingActivities == null) { existingActivities = new OrcidActivities(); existingProfile.setOrcidActivities(existingActivities); } Affiliations existingAffiliations = existingActivities.getAffiliations(); if (existingAffiliations == null) { existingAffiliations = new Affiliations(); existingActivities.setAffiliations(existingAffiliations); } orcidJaxbCopyManager.copyAffiliationsToExistingPreservingVisibility(existingAffiliations, updatedAffiliations); OrcidProfile profileToReturn = updateOrcidProfile(existingProfile, UpdateOptions.AFFILIATIONS_ONLY); notificationManager.sendAmendEmail(updatedOrcidProfile.getOrcidIdentifier().getPath(), AmendedSection.AFFILIATION, null); return profileToReturn; }
@Override @Transactional public void updatePasswordInformation(OrcidProfile updatedOrcidProfile) { String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath(); String hashedPassword = hash(updatedOrcidProfile.getPassword()); profileDao.updateEncryptedPassword(orcid, hashedPassword); OrcidProfile cachedProfile = orcidProfileCacheManager.retrieve(orcid); if (cachedProfile != null) { profileDao.flush(); SecurityDetails securityDetails = initSecurityDetails(cachedProfile); securityDetails.setEncryptedPassword(new EncryptedPassword(hashedPassword)); cachedProfile.setPassword(hashedPassword); orcidProfileCacheManager.put(cachedProfile); } updateSecurityQuestionInformation(updatedOrcidProfile); }
@Override public void updateSecurityQuestionInformation(OrcidProfile updatedOrcidProfile) { String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath(); SecurityQuestionId securityQuestionId = updatedOrcidProfile.getOrcidInternal().getSecurityDetails().getSecurityQuestionId(); Integer questionId = null; if (securityQuestionId != null) { questionId = new Long(securityQuestionId.getValue()).intValue(); } String unencryptedAnswer = updatedOrcidProfile.getSecurityQuestionAnswer(); String encryptedAnswer = encrypt(unencryptedAnswer); profileDao.updateSecurityQuestion(orcid, questionId, questionId != null ? encryptedAnswer : null); OrcidProfile cachedProfile = orcidProfileCacheManager.retrieve(orcid); if (cachedProfile != null) { profileDao.flush(); SecurityDetails securityDetails = initSecurityDetails(cachedProfile); securityDetails.setSecurityQuestionId(questionId != null ? new SecurityQuestionId(questionId) : null); securityDetails.setEncryptedSecurityAnswer(encryptedAnswer != null ? new EncryptedSecurityAnswer(encryptedAnswer) : null); cachedProfile.setSecurityQuestionAnswer(encryptedAnswer != null ? unencryptedAnswer : null); orcidProfileCacheManager.put(cachedProfile); } }
@Override public ProfileEntity toProfileEntity(OrcidProfile profile, ProfileEntity existingProfileEntity, UpdateOptions updateOptions) { Assert.notNull(profile, "Cannot convert a null OrcidProfile"); ProfileEntity profileEntity = existingProfileEntity == null ? new ProfileEntity() : existingProfileEntity; // if orcid-id exist us it String orcidString = profile.getOrcidIdentifier().getPath(); if (profile.retrieveOrcidUriAsString() != null && !profile.retrieveOrcidUriAsString().isEmpty()) { orcidString = OrcidStringUtils.getOrcidNumber(profile.retrieveOrcidUriAsString()); } profileEntity.setId(orcidString); profileEntity.setOrcidType(profile.getType().name()); profileEntity.setGroupType(profile.getGroupType() != null ? profile.getGroupType().name() : null); setBioDetails(profileEntity, profile.getOrcidBio()); setHistoryDetails(profileEntity, profile.getOrcidHistory()); setActivityDetails(profileEntity, profile.getOrcidActivities(), updateOptions); setInternalDetails(profileEntity, profile.getOrcidInternal()); setPreferencesDetails(profileEntity, profile.getOrcidPreferences()); profileEntity.setUserLastIp(profile.getUserLastIp()); profileEntity.setReviewed(profile.isReviewed()); if(profileEntity.getUsedRecaptchaOnRegistration() == null) { profileEntity.setUsedRecaptchaOnRegistration(false); } return profileEntity; }
@Override public ProfileEventResult call() throws Exception { String orcidId = getOrcidProfile().getOrcidIdentifier().getPath(); if (orcidProfile.getOrcidBio() == null || orcidProfile.getOrcidBio().getContactDetails() == null || orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() == null || orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue() == null) { return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_SKIPPED_2017); } if (orcidProfile.isLocked() || orcidProfile.isDeactivated() || orcidProfile.getOrcidDeprecated() != null || !orcidProfile.getOrcidHistory().getClaimed().isValue()) { return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_SKIPPED_2017); } Email primaryEmail = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail(); if (primaryEmail.isVerified()) { return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_HAS_VALIDATED_2017); } else { try { boolean sent = sendVerifiedRequiredAnnouncement2017(orcidProfile); if (sent) { return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_SENT_2017); } else { return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_FAIL_2017); } } catch (Exception e) { LOG.error("ProfileEventType exception trying to send email to: " + orcidProfile.retrieveOrcidUriAsString(), e); return new ProfileEventResult(orcidId, ProfileEventType.VERIFIED_REQUIRED_FAIL_2017); } } }