Search in sources :

Example 31 with RecordNameEntity

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

the class RecordNameUtilsTest method testGetPublicNamePublicVisibilityNoCreditName.

@Test
public void testGetPublicNamePublicVisibilityNoCreditName() {
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setVisibility(Visibility.PUBLIC);
    recordName.setGivenNames("given name");
    recordName.setFamilyName("family name");
    String publicName = RecordNameUtils.getPublicName(recordName);
    assertNotNull(recordName);
    assertEquals(recordName.getGivenNames() + " " + recordName.getFamilyName(), publicName);
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Test(org.junit.Test)

Example 32 with RecordNameEntity

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

the class RecordNameUtilsTest method testGetPublicNamePrivateVisibility.

@Test
public void testGetPublicNamePrivateVisibility() {
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setVisibility(Visibility.PRIVATE);
    recordName.setCreditName("credit name");
    recordName.setGivenNames("given name");
    recordName.setFamilyName("family name");
    String publicName = RecordNameUtils.getPublicName(recordName);
    assertNotNull(recordName);
    assertNull(publicName);
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Test(org.junit.Test)

Example 33 with RecordNameEntity

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

the class BibtexManagerImpl method getCreditName.

/**
     * Extract a credit name from the profile
     * @param orcid
     * @return
     */
private String getCreditName(String orcid) {
    ProfileEntity entity = profileEntityManager.findByOrcid(orcid);
    String creditName = null;
    RecordNameEntity recordNameEntity = entity.getRecordNameEntity();
    if (recordNameEntity != null) {
        creditName = recordNameEntity.getCreditName();
        if (StringUtils.isBlank(creditName)) {
            creditName = recordNameEntity.getGivenNames();
            String familyName = recordNameEntity.getFamilyName();
            if (StringUtils.isNotBlank(familyName)) {
                creditName += " " + familyName;
            }
        }
    }
    return creditName;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 34 with RecordNameEntity

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

the class PublicV2ApiServiceDelegatorImpl method viewWorkCitation.

@Override
public Response viewWorkCitation(String orcid, Long putCode) {
    Work w = (Work) this.viewWork(orcid, putCode).getEntity();
    ProfileEntity entity = profileEntityManagerReadOnly.findByOrcid(orcid);
    String creditName = null;
    RecordNameEntity recordNameEntity = entity.getRecordNameEntity();
    if (recordNameEntity != null) {
        if (!recordNameEntity.getVisibility().isMoreRestrictiveThan(Visibility.PUBLIC)) {
            creditName = recordNameEntity.getCreditName();
            if (StringUtils.isBlank(creditName)) {
                creditName = recordNameEntity.getGivenNames();
                String familyName = recordNameEntity.getFamilyName();
                if (StringUtils.isNotBlank(familyName)) {
                    creditName += " " + familyName;
                }
            }
        }
    }
    WorkToCiteprocTranslator tran = new WorkToCiteprocTranslator();
    CSLItemData item = tran.toCiteproc(w, creditName, true);
    return Response.ok(item).build();
}
Also used : CSLItemData(de.undercouch.citeproc.csl.CSLItemData) Work(org.orcid.jaxb.model.record_v2.Work) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) WorkToCiteprocTranslator(org.orcid.api.common.writer.citeproc.WorkToCiteprocTranslator) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 35 with RecordNameEntity

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

the class RecordNameDaoTest method testUpdate.

@Test
public void testUpdate() {
    RecordNameEntity recordName = recordNameDao.getRecordName("4444-4444-4444-4447");
    assertNotNull(recordName);
    assertEquals("Credit Name", recordName.getCreditName());
    assertEquals("Given Names", recordName.getGivenNames());
    assertEquals("Family Name", recordName.getFamilyName());
    assertEquals(Visibility.LIMITED, recordName.getVisibility());
    recordName.setCreditName("Updated Credit Name");
    recordName.setGivenNames("Updated Given Names");
    recordName.setFamilyName("Updated Family Name");
    recordName.setVisibility(Visibility.PUBLIC);
    assertTrue(recordNameDao.updateRecordName(recordName));
    RecordNameEntity updatedRecordName = recordNameDao.getRecordName("4444-4444-4444-4447");
    assertEquals("Updated Credit Name", updatedRecordName.getCreditName());
    assertEquals("Updated Given Names", updatedRecordName.getGivenNames());
    assertEquals("Updated Family Name", updatedRecordName.getFamilyName());
    assertEquals(Visibility.PUBLIC, updatedRecordName.getVisibility());
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

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