Search in sources :

Example 76 with OtherName

use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.

the class OtherNameManagerImpl method updateOtherNames.

@Override
@Transactional
public OtherNames updateOtherNames(String orcid, OtherNames otherNames) {
    List<OtherNameEntity> existingOtherNamesEntityList = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    //Delete the deleted ones
    for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
        boolean deleteMe = true;
        if (otherNames.getOtherNames() != null) {
            for (OtherName updatedOrNew : otherNames.getOtherNames()) {
                if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                    deleteMe = false;
                    break;
                }
            }
        }
        if (deleteMe) {
            try {
                otherNameDao.deleteOtherName(existingOtherName);
            } catch (Exception e) {
                throw new ApplicationException("Unable to delete other name " + existingOtherName.getId(), e);
            }
        }
    }
    if (otherNames != null && otherNames.getOtherNames() != null) {
        for (OtherName updatedOrNew : otherNames.getOtherNames()) {
            if (updatedOrNew.getPutCode() != null) {
                //Update the existing ones
                for (OtherNameEntity existingOtherName : existingOtherNamesEntityList) {
                    if (existingOtherName.getId().equals(updatedOrNew.getPutCode())) {
                        existingOtherName.setLastModified(new Date());
                        existingOtherName.setVisibility(updatedOrNew.getVisibility());
                        existingOtherName.setDisplayName(updatedOrNew.getContent());
                        existingOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                        otherNameDao.merge(existingOtherName);
                    }
                }
            } else {
                //Add the new ones
                OtherNameEntity newOtherName = jpaJaxbOtherNameAdapter.toOtherNameEntity(updatedOrNew);
                SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
                ProfileEntity profile = new ProfileEntity(orcid);
                newOtherName.setProfile(profile);
                newOtherName.setDateCreated(new Date());
                //Set the source
                if (sourceEntity.getSourceProfile() != null) {
                    newOtherName.setSourceId(sourceEntity.getSourceProfile().getId());
                }
                if (sourceEntity.getSourceClient() != null) {
                    newOtherName.setClientSourceId(sourceEntity.getSourceClient().getId());
                }
                newOtherName.setVisibility(updatedOrNew.getVisibility());
                newOtherName.setDisplayIndex(updatedOrNew.getDisplayIndex());
                otherNameDao.persist(newOtherName);
            }
        }
    }
    return otherNames;
}
Also used : ApplicationException(org.orcid.core.exception.ApplicationException) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.record_v2.OtherName) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) ApplicationException(org.orcid.core.exception.ApplicationException) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with OtherName

use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.

the class OtherNameForm method toOtherName.

public OtherName toOtherName() {
    OtherName otherName = new OtherName();
    if (!PojoUtil.isEmpty(this.getContent())) {
        otherName.setContent(this.getContent());
    }
    if (this.visibility != null && this.visibility.getVisibility() != null) {
        otherName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(this.getVisibility().getVisibility().value()));
    }
    if (!PojoUtil.isEmpty(this.getPutCode())) {
        otherName.setPutCode(Long.valueOf(this.getPutCode()));
    }
    if (displayIndex != null) {
        otherName.setDisplayIndex(displayIndex);
    } else {
        otherName.setDisplayIndex(0L);
    }
    otherName.setSource(new Source(source));
    return otherName;
}
Also used : OtherName(org.orcid.jaxb.model.record_v2.OtherName) Source(org.orcid.jaxb.model.common_v2.Source)

Example 78 with OtherName

use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.

the class OtherNameManagerTest method testAddOtherNameToUnclaimedRecordPreserveOtherNameVisibility.

@Test
public void testAddOtherNameToUnclaimedRecordPreserveOtherNameVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    OtherName otherName = getOtherName();
    otherName = otherNameManager.createOtherName(unclaimedOrcid, otherName, true);
    otherName = otherNameManager.getOtherName(unclaimedOrcid, otherName.getPutCode());
    assertNotNull(otherName);
    assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 79 with OtherName

use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.

the class OtherNameManagerTest method displayIndexIsSetTo_1_FromUI.

@Test
public void displayIndexIsSetTo_1_FromUI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    OtherName otherName = getOtherName();
    otherName.setContent(otherName.getContent() + " fromUI");
    otherName = otherNameManager.createOtherName(claimedOrcid, otherName, false);
    otherName = otherNameManager.getOtherName(claimedOrcid, otherName.getPutCode());
    assertNotNull(otherName);
    assertEquals(Long.valueOf(1), otherName.getDisplayIndex());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 80 with OtherName

use of org.orcid.jaxb.model.record_rc3.OtherName in project ORCID-Source by ORCID.

the class OtherNameManagerTest method getOtherName.

private OtherName getOtherName() {
    OtherName otherName = new OtherName();
    otherName.setContent("other-name");
    otherName.setVisibility(Visibility.PUBLIC);
    return otherName;
}
Also used : OtherName(org.orcid.jaxb.model.record_v2.OtherName)

Aggregations

OtherName (org.orcid.jaxb.model.record_v2.OtherName)114 Test (org.junit.Test)99 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)55 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)45 Biography (org.orcid.jaxb.model.record_v2.Biography)44 Address (org.orcid.jaxb.model.record_v2.Address)43 Keyword (org.orcid.jaxb.model.record_v2.Keyword)42 Name (org.orcid.jaxb.model.record_v2.Name)42 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)42 Email (org.orcid.jaxb.model.record_v2.Email)39 Addresses (org.orcid.jaxb.model.record_v2.Addresses)32 Emails (org.orcid.jaxb.model.record_v2.Emails)32 Keywords (org.orcid.jaxb.model.record_v2.Keywords)32 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)32 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)32 Person (org.orcid.jaxb.model.record_v2.Person)30 ArrayList (java.util.ArrayList)23 DBUnitTest (org.orcid.test.DBUnitTest)22 Response (javax.ws.rs.core.Response)20 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18