use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class JpaJaxbEmailAdapterTest method fromEmailToEmailEntity.
@Test
public void fromEmailToEmailEntity() {
EmailEntity entity = getEmailEntity();
Email email = jpaJaxbEmailAdapter.toEmail(entity);
assertNotNull(email);
assertNotNull(email.getLastModifiedDate().getValue());
assertNotNull(email.getCreatedDate().getValue());
assertEquals("email@test.orcid.org", email.getEmail());
assertEquals(Visibility.PRIVATE, email.getVisibility());
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class JpaJaxbEmailAdapterTest method testEmailEntityToEmail.
@Test
public void testEmailEntityToEmail() throws JAXBException {
Email email = getEmail();
assertNotNull(email);
EmailEntity entity = jpaJaxbEmailAdapter.toEmailEntity(email);
assertNotNull(entity);
assertNotNull(entity.getDateCreated());
assertNotNull(entity.getLastModified());
assertEquals("user1@email.com", entity.getId());
assertEquals(Visibility.PUBLIC, entity.getVisibility());
// Source
assertNull(entity.getSourceId());
assertNull(entity.getClientSourceId());
assertNull(entity.getElementSourceId());
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class RegistrationManagerImpl method createMinimalProfile.
/**
* Creates a minimal record
*
* @param orcidProfile
* The record to create
* @return the new record
*/
private String createMinimalProfile(Registration registration, boolean usedCaptcha, Locale locale, String ip) {
Date now = new Date();
String orcid = orcidGenerationManager.createNewOrcid();
ProfileEntity newRecord = new ProfileEntity();
newRecord.setId(orcid);
try {
newRecord.setHashedOrcid(encryptionManager.sha256Hash(orcid));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
newRecord.setOrcidType(OrcidType.USER);
newRecord.setDateCreated(now);
newRecord.setLastModified(now);
newRecord.setSubmissionDate(now);
newRecord.setClaimed(true);
newRecord.setEnableDeveloperTools(false);
newRecord.setRecordLocked(false);
newRecord.setReviewed(false);
newRecord.setEnableNotifications(DefaultPreferences.NOTIFICATIONS_ENABLED);
newRecord.setUsedRecaptchaOnRegistration(usedCaptcha);
newRecord.setUserLastIp(ip);
newRecord.setLastLogin(now);
if (PojoUtil.isEmpty(registration.getSendEmailFrequencyDays())) {
newRecord.setSendEmailFrequencyDays(Float.valueOf(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS));
} else {
newRecord.setSendEmailFrequencyDays(Float.valueOf(registration.getSendEmailFrequencyDays().getValue()));
}
if (registration.getSendMemberUpdateRequests() == null) {
newRecord.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
} else {
newRecord.setSendMemberUpdateRequests(registration.getSendMemberUpdateRequests().getValue());
}
newRecord.setCreationMethod(PojoUtil.isEmpty(registration.getCreationType()) ? CreationMethod.DIRECT.value() : registration.getCreationType().getValue());
newRecord.setSendChangeNotifications(registration.getSendChangeNotifications().getValue());
newRecord.setSendAdministrativeChangeNotifications(true);
newRecord.setSendOrcidNews(registration.getSendOrcidNews().getValue());
newRecord.setLocale(locale == null ? org.orcid.jaxb.model.common_v2.Locale.EN : org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.toString()));
// Visibility defaults
newRecord.setActivitiesVisibilityDefault(Visibility.fromValue(registration.getActivitiesVisibilityDefault().getVisibility().value()));
// Encrypt the password
newRecord.setEncryptedPassword(encryptionManager.hashForInternalUse(registration.getPassword().getValue()));
// Set primary email
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId(registration.getEmail().getValue().trim());
emailEntity.setProfile(newRecord);
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
emailEntity.setVerified(false);
// Email is private by default
emailEntity.setVisibility(Visibility.PRIVATE);
emailEntity.setSourceId(orcid);
Set<EmailEntity> emails = new HashSet<>();
emails.add(emailEntity);
// Set additional emails
for (Text emailAdditional : registration.getEmailsAdditional()) {
if (!PojoUtil.isEmpty(emailAdditional)) {
EmailEntity emailAdditionalEntity = new EmailEntity();
emailAdditionalEntity.setId(emailAdditional.getValue().trim());
emailAdditionalEntity.setProfile(newRecord);
emailAdditionalEntity.setPrimary(false);
emailAdditionalEntity.setCurrent(true);
emailAdditionalEntity.setVerified(false);
// Email is private by default
emailAdditionalEntity.setVisibility(Visibility.PRIVATE);
emailAdditionalEntity.setSourceId(orcid);
emails.add(emailAdditionalEntity);
}
}
// Add all emails to record
newRecord.setEmails(emails);
// Set the name
RecordNameEntity recordNameEntity = new RecordNameEntity();
recordNameEntity.setDateCreated(now);
recordNameEntity.setLastModified(now);
recordNameEntity.setProfile(newRecord);
// Name is public by default
recordNameEntity.setVisibility(Visibility.PUBLIC);
if (!PojoUtil.isEmpty(registration.getFamilyNames())) {
recordNameEntity.setFamilyName(registration.getFamilyNames().getValue().trim());
}
if (!PojoUtil.isEmpty(registration.getGivenNames())) {
recordNameEntity.setGivenNames(registration.getGivenNames().getValue().trim());
}
newRecord.setRecordNameEntity(recordNameEntity);
// Set authority
OrcidGrantedAuthority authority = new OrcidGrantedAuthority();
authority.setProfileEntity(newRecord);
authority.setAuthority(OrcidWebRole.ROLE_USER.getAuthority());
Set<OrcidGrantedAuthority> authorities = new HashSet<OrcidGrantedAuthority>(1);
authorities.add(authority);
newRecord.setAuthorities(authorities);
profileDao.persist(newRecord);
profileDao.flush();
return newRecord.getId();
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class EmailMessageSenderImpl method sendEmailMessages.
@Override
public void sendEmailMessages() {
LOGGER.info("About to send email messages");
List<Object[]> orcidsWithUnsentNotifications = notificationDaoReadOnly.findRecordsWithUnsentNotifications();
for (final Object[] element : orcidsWithUnsentNotifications) {
String orcid = (String) element[0];
try {
Float emailFrequencyDays = Float.valueOf((float) element[1]);
Date recordActiveDate = (Date) element[2];
LOGGER.info("Sending messages for orcid: {}", orcid);
List<Notification> notifications = notificationManager.findNotificationsToSend(orcid, emailFrequencyDays, recordActiveDate);
if (!notifications.isEmpty()) {
LOGGER.info("Found {} messages to send for orcid: {}", notifications.size(), orcid);
EmailMessage digestMessage = createDigest(orcid, notifications);
digestMessage.setFrom(DIGEST_FROM_ADDRESS);
EmailEntity primaryEmail = emailDao.findPrimaryEmail(orcid);
if (primaryEmail == null) {
LOGGER.info("No primary email for orcid: " + orcid);
return;
}
digestMessage.setTo(primaryEmail.getId());
boolean successfullySent = mailGunManager.sendEmail(digestMessage.getFrom(), digestMessage.getTo(), digestMessage.getSubject(), digestMessage.getBodyText(), digestMessage.getBodyHtml());
if (successfullySent) {
flagAsSent(notifications);
}
} else {
LOGGER.info("There are no notifications to send for orcid: {}", orcid);
}
} catch (RuntimeException e) {
LOGGER.warn("Problem sending email message to user: " + orcid, e);
}
}
LOGGER.info("Finished sending email messages");
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class SetUpClientsAndUsers method clearRegistry.
private boolean clearRegistry(OrcidProfile existingProfile, Map<String, String> params) {
if (existingProfile != null) {
String orcid = params.get(ORCID);
String email = params.get(EMAIL);
// exception
if (existingProfile.getOrcidBio() == null || existingProfile.getOrcidBio().getContactDetails() == null || existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() == null || !email.equals(existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue())) {
throw new ApplicationException("User with email " + params.get(EMAIL) + " must have orcid id '" + orcid + "' but it is '" + existingProfile.getOrcidId() + "'");
}
// Check if the profile have the same password, if not, update the
// password
String encryptedPassword = encryptionManager.hashForInternalUse(params.get(PASSWORD));
if (!encryptedPassword.equals(existingProfile.getPassword())) {
existingProfile.setPassword(params.get(PASSWORD));
orcidProfileManager.updatePasswordInformation(existingProfile);
}
// Set default names
Name name = new Name();
name.setCreditName(new CreditName(params.get(CREDIT_NAME)));
name.setGivenNames(new GivenNames(params.get(GIVEN_NAMES)));
name.setFamilyName(new FamilyName(params.get(FAMILY_NAMES)));
name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
if (recordNameManager.exists(orcid)) {
recordNameManager.updateRecordName(orcid, name);
} else {
recordNameManager.createRecordName(orcid, name);
}
profileDao.updatePreferences(orcid, true, true, true, true, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, true, 1f);
// Set default bio
org.orcid.jaxb.model.record_v2.Biography bio = biographyManager.getBiography(orcid);
if (bio == null || bio.getContent() == null) {
bio = new org.orcid.jaxb.model.record_v2.Biography(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.createBiography(orcid, bio);
} else {
bio.setContent(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.updateBiography(orcid, bio);
}
// Remove other names
List<OtherNameEntity> otherNames = otherNameDao.getOtherNames(orcid, 0L);
if (otherNames != null && !otherNames.isEmpty()) {
for (OtherNameEntity otherName : otherNames) {
otherNameDao.deleteOtherName(otherName);
}
}
// Remove keywords
List<ProfileKeywordEntity> keywords = profileKeywordDao.getProfileKeywords(orcid, 0L);
if (keywords != null && !keywords.isEmpty()) {
for (ProfileKeywordEntity keyword : keywords) {
profileKeywordDao.deleteProfileKeyword(keyword);
}
}
// Remove researcher urls
List<ResearcherUrlEntity> rUrls = researcherUrlDao.getResearcherUrls(orcid, 0L);
if (rUrls != null && !rUrls.isEmpty()) {
for (ResearcherUrlEntity rUrl : rUrls) {
researcherUrlDao.deleteResearcherUrl(orcid, rUrl.getId());
}
}
// Remove external ids
List<ExternalIdentifierEntity> extIds = externalIdentifierDao.getExternalIdentifiers(orcid, System.currentTimeMillis());
if (extIds != null && !extIds.isEmpty()) {
for (ExternalIdentifierEntity extId : extIds) {
externalIdentifierDao.removeExternalIdentifier(orcid, extId.getId());
}
}
// Remove addresses
List<AddressEntity> addresses = addressDao.getAddresses(orcid, 0L);
if (addresses != null && !addresses.isEmpty()) {
for (AddressEntity address : addresses) {
addressDao.deleteAddress(orcid, address.getId());
}
}
// Remove emails
List<EmailEntity> emails = emailDao.findByOrcid(orcid, profileEntityManager.getLastModified(orcid));
if (emails != null && !emails.isEmpty()) {
for (EmailEntity rc2Email : emails) {
if (!params.get(EMAIL).equals(rc2Email.getId())) {
emailDao.removeEmail(orcid, rc2Email.getId());
}
}
}
// Remove notifications
List<NotificationEntity> notifications = notificationDao.findByOrcid(orcid, true, 0, 10000);
if (notifications != null && !notifications.isEmpty()) {
for (NotificationEntity notification : notifications) {
notificationDao.deleteNotificationItemByNotificationId(notification.getId());
notificationDao.deleteNotificationWorkByNotificationId(notification.getId());
notificationDao.deleteNotificationById(notification.getId());
}
}
// Remove works
List<WorkLastModifiedEntity> works = workDao.getWorkLastModifiedList(orcid);
if (works != null && !works.isEmpty()) {
for (WorkLastModifiedEntity work : works) {
workDao.removeWork(orcid, work.getId());
}
}
// Remove affiliations
List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
if (affiliations != null && !affiliations.isEmpty()) {
for (OrgAffiliationRelationEntity affiliation : affiliations) {
orgAffiliationRelationDao.remove(affiliation.getId());
}
}
// Remove fundings
List<ProfileFundingEntity> fundings = profileFundingDao.getByUser(orcid, profileEntityManager.getLastModified(orcid));
if (fundings != null && !fundings.isEmpty()) {
for (ProfileFundingEntity funding : fundings) {
profileFundingDao.removeProfileFunding(orcid, funding.getId());
}
}
// Remove peer reviews
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid, profileEntityManager.getLastModified(orcid));
if (peerReviews != null && !peerReviews.isEmpty()) {
for (PeerReviewEntity peerReview : peerReviews) {
peerReviewDao.removePeerReview(orcid, peerReview.getId());
}
}
// Remove 3d party links
List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenDetailDao.findByUserName(orcid);
if (tokenDetails != null && !tokenDetails.isEmpty()) {
for (OrcidOauth2TokenDetail token : tokenDetails) {
orcidOauth2TokenDetailDao.remove(token.getId());
}
}
// Unlock just in case it is locked
profileDao.unlockProfile(orcid);
return true;
}
return false;
}
Aggregations