use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.
@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
final String orcid = "0000-0000-0000-0003";
String delegateOrcid = "1234-5678-1234-5678";
ProfileEntity profile = new ProfileEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setCreditName("My credit name");
recordName.setVisibility(Visibility.PUBLIC);
profile.setRecordNameEntity(recordName);
profile.setSendAdministrativeChangeNotifications(true);
profile.setSendChangeNotifications(true);
profile.setSendMemberUpdateRequests(true);
profile.setSendOrcidNews(true);
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId("test@email.com");
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(emailEntity);
profile.setEmails(emails);
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
Email email = new Email();
email.setEmail("test@email.com");
Email delegateEmail = new Email();
delegateEmail.setEmail("delegate@email.com");
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
when(mockEmailManager.findPrimaryEmail(delegateOrcid)).thenReturn(delegateEmail);
for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
profile.setLocale(locale);
notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", delegateOrcid);
}
}
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(org.orcid.jaxb.model.common_v2.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 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 JpaJaxbEntityAdapterToProfileEntityTest method testToProfileEntity.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testToProfileEntity() throws JAXBException {
OrcidMessage orcidMessage = getOrcidMessage(ORCID_PROTECTED_FULL_XML);
ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
assertNotNull(profileEntity);
profileDao.persist(profileEntity);
ProfileEntity retrievedProfileEntity = profileDao.find(orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath());
assertNotNull(retrievedProfileEntity);
assertEquals("Josiah", retrievedProfileEntity.getRecordNameEntity().getGivenNames());
// Check all email visibility and values
Set<EmailEntity> emails = profileEntity.getEmails();
assertNotNull(emails);
assertEquals(2, emails.size());
Map<String, EmailEntity> emailMap = EmailEntity.mapById(emails);
EmailEntity primaryEmail = emailMap.get("josiah_carberry@brown.edu");
assertNotNull(primaryEmail);
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, primaryEmail.getVisibility());
assertTrue(primaryEmail.getPrimary());
assertTrue(primaryEmail.getCurrent());
assertTrue(primaryEmail.getVerified());
assertEquals("4444-4444-4444-4446", primaryEmail.getElementSourceId());
EmailEntity nonPrimaryEmail1 = emailMap.get("josiah_carberry_1@brown.edu");
assertNotNull(nonPrimaryEmail1);
assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, nonPrimaryEmail1.getVisibility());
assertFalse(nonPrimaryEmail1.getPrimary());
assertTrue(nonPrimaryEmail1.getCurrent());
assertFalse(nonPrimaryEmail1.getVerified());
assertEquals("4444-4444-4444-4446", nonPrimaryEmail1.getElementSourceId());
assertEquals(2, profileEntity.getProfileFunding().size());
for (ProfileFundingEntity profileGrantEntity : profileEntity.getProfileFunding()) {
assertNotNull(profileGrantEntity.getContributorsJson());
}
assertNull(profileEntity.getGivenPermissionBy());
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class EmailManagerImpl method setPrimary.
@Override
public void setPrimary(String orcid, String email, HttpServletRequest request) {
Email currentPrimaryEmail = this.findPrimaryEmail(orcid);
EmailEntity newPrimary = emailDao.find(email);
if (newPrimary != null && !currentPrimaryEmail.getEmail().equals(email)) {
emailDao.updatePrimary(orcid, email);
notificationManager.sendEmailAddressChangedNotification(orcid, email, currentPrimaryEmail.getEmail());
if (!newPrimary.getVerified()) {
notificationManager.sendVerificationEmail(orcid, email);
request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
}
}
}
Aggregations