Search in sources :

Example 11 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method deriveEmailFriendlyNameTest.

@Test
public void deriveEmailFriendlyNameTest() {
    ProfileEntity testProfile = new ProfileEntity("0000-0000-0000-0003");
    assertEquals("ORCID Registry User", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.setRecordNameEntity(new RecordNameEntity());
    assertEquals("ORCID Registry User", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setGivenNames("Given Name");
    assertEquals("Given Name", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setFamilyName("Family Name");
    assertEquals("Given Name Family Name", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setCreditName("Credit Name");
    assertEquals("Credit Name", notificationManager.deriveEmailFriendlyName(testProfile));
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testSendDeactivateEmail.

@Test
public void testSendDeactivateEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    final String orcid = "0000-0000-0000-0003";
    ProfileEntity profile = new ProfileEntity(orcid);
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(orcid)).thenReturn(profile);
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendOrcidDeactivateEmail(orcid);
    }
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testChangeEmailAddress.

@Test
public void testChangeEmailAddress() throws Exception {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    final String orcid = "0000-0000-0000-0003";
    ProfileEntity profile = new ProfileEntity(orcid);
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(orcid)).thenReturn(profile);
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendEmailAddressChangedNotification(orcid, "new@email.com", "original@email.com");
    }
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 14 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class RecordNameDaoImpl method getRecordName.

@Override
public RecordNameEntity getRecordName(String orcid) {
    Query query = entityManager.createQuery("FROM RecordNameEntity WHERE profile.id = :orcid");
    query.setParameter("orcid", orcid);
    return (RecordNameEntity) query.getSingleResult();
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity)

Example 15 with RecordNameEntity

use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.

the class RecordNameDaoImpl method findByCreditName.

@Override
public RecordNameEntity findByCreditName(String creditName) {
    Query query = entityManager.createQuery("FROM RecordNameEntity WHERE creditName = :creditName");
    query.setParameter("creditName", creditName);
    @SuppressWarnings("unchecked") List<RecordNameEntity> names = (List<RecordNameEntity>) query.getResultList();
    if (names == null || names.isEmpty()) {
        return null;
    }
    //Return the first result
    return names.get(0);
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) List(java.util.List)

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)42 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)20 Test (org.junit.Test)15 DBUnitTest (org.orcid.test.DBUnitTest)8 Date (java.util.Date)7 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Email (org.orcid.jaxb.model.record_v2.Email)4 Before (org.junit.Before)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Name (org.orcid.jaxb.model.record_v2.Name)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 List (java.util.List)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 CreditName (org.orcid.jaxb.model.common_v2.CreditName)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 Transactional (org.springframework.transaction.annotation.Transactional)2