Search in sources :

Example 31 with EmailEntity

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);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) Locale(org.orcid.jaxb.model.common_v2.Locale) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 32 with EmailEntity

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());
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Test(org.junit.Test)

Example 33 with EmailEntity

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());
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Test(org.junit.Test)

Example 34 with EmailEntity

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());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with EmailEntity

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);
        }
    }
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Aggregations

EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)45 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)21 Date (java.util.Date)14 Test (org.junit.Test)14 HashSet (java.util.HashSet)11 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)10 DBUnitTest (org.orcid.test.DBUnitTest)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Email (org.orcid.jaxb.model.v3.dev1.record.Email)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Set (java.util.Set)4 Email (org.orcid.jaxb.model.record_v2.Email)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2