Search in sources :

Example 56 with RecordNameEntity

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

the class RecordNameManagerImpl method createRecordName.

@Override
public void createRecordName(String orcid, Name name) {
    if (name == null) {
        return;
    }
    if (recordNameDao.exists(orcid)) {
        throw new IllegalArgumentException("The name for " + orcid + " already exists");
    }
    RecordNameEntity entity = jpaJaxbNameAdapter.toRecordNameEntity(name);
    if (entity.getProfile() == null || PojoUtil.isEmpty(entity.getProfile().getId())) {
        entity.setProfile(new ProfileEntity(orcid));
    }
    Date now = new Date();
    entity.setDateCreated(now);
    entity.setLastModified(now);
    recordNameDao.createRecordName(entity);
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 57 with RecordNameEntity

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

the class Jaxb2JpaAdapterImpl method setCreditNameDetails.

private void setCreditNameDetails(ProfileEntity profileEntity, CreditName creditName) {
    if (creditName != null) {
        if (profileEntity.getRecordNameEntity() == null) {
            profileEntity.setRecordNameEntity(new RecordNameEntity());
            profileEntity.getRecordNameEntity().setProfile(profileEntity);
        }
        RecordNameEntity recordName = profileEntity.getRecordNameEntity();
        // Save the record name entity
        if (creditName.getVisibility() != null) {
            recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(creditName.getVisibility().value()));
        } else {
            recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
        }
        recordName.setCreditName(creditName.getContent());
    }
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity)

Example 58 with RecordNameEntity

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

the class PublicV3ApiServiceDelegatorImpl 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(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
            creditName = recordNameEntity.getCreditName();
            if (StringUtils.isBlank(creditName)) {
                creditName = recordNameEntity.getGivenNames();
                String familyName = recordNameEntity.getFamilyName();
                if (StringUtils.isNotBlank(familyName)) {
                    creditName += " " + familyName;
                }
            }
        }
    }
    V3WorkToCiteprocTranslator tran = new V3WorkToCiteprocTranslator();
    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.v3.dev1.record.Work) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) V3WorkToCiteprocTranslator(org.orcid.api.common.writer.citeproc.V3WorkToCiteprocTranslator) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 59 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 60 with RecordNameEntity

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

the class SelfServiceController method addContactByEmail.

@RequestMapping(value = "/add-contact-by-email.json")
@ResponseBody
public Contact addContactByEmail(@RequestBody Contact contact) {
    checkFullAccess(contact.getAccountId());
    EmailEntity emailEntity = emailManager.findCaseInsensitive(contact.getEmail());
    contact.setOrcid(emailEntity.getProfile().getId());
    RecordNameEntity recordNameEntity = emailEntity.getProfile().getRecordNameEntity();
    if (Visibility.PUBLIC.equals(recordNameEntity.getVisibility())) {
        contact.setFirstName(recordNameEntity.getGivenNames());
        contact.setLastName(recordNameEntity.getFamilyName());
    } else {
        contact.setFirstName(NOT_PUBLIC);
        contact.setLastName(NOT_PUBLIC);
    }
    salesForceManager.createContact(contact);
    return contact;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)66 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)35 Test (org.junit.Test)26 DBUnitTest (org.orcid.test.DBUnitTest)13 Date (java.util.Date)11 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)10 HashSet (java.util.HashSet)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Before (org.junit.Before)4 Name (org.orcid.jaxb.model.v3.dev1.record.Name)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 Locale (org.orcid.jaxb.model.common_v2.Locale)3 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 Email (org.orcid.jaxb.model.record_v2.Email)3 Name (org.orcid.jaxb.model.record_v2.Name)3 Email (org.orcid.jaxb.model.v3.dev1.record.Email)3