Search in sources :

Example 31 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method persistAddedWorks.

private void persistAddedWorks(String orcid, List<OrcidWork> updatedOrcidWorksList) {
    for (OrcidWork updatedOrcidWork : updatedOrcidWorksList) {
        populateContributorInfo(updatedOrcidWork);
        // Create the work entity
        WorkEntity workEntity = jaxb2JpaAdapter.getWorkEntity(orcid, updatedOrcidWork, null);
        workDao.persist(workEntity);
        updatedOrcidWork.setPutCode(String.valueOf(workEntity.getId()));
    }
    orcidProfileCacheManager.remove(orcid);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork)

Example 32 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method checkForAlreadyExistingWorks.

private void checkForAlreadyExistingWorks(String orcid, OrcidWorks existingOrcidWorks, List<OrcidWork> updatedOrcidWorksList) {
    if (existingOrcidWorks != null) {
        Set<OrcidWork> existingOrcidWorksSet = new HashSet<>();
        for (OrcidWork existingWork : existingOrcidWorks.getOrcidWork()) {
            existingOrcidWorksSet.add(existingWork);
        }
        for (Iterator<OrcidWork> updatedWorkIterator = updatedOrcidWorksList.iterator(); updatedWorkIterator.hasNext(); ) {
            OrcidWork updatedWork = updatedWorkIterator.next();
            for (OrcidWork orcidWork : existingOrcidWorksSet) {
                if (orcidWork.isDuplicated(updatedWork)) {
                    // Update the existing work
                    WorkEntity workEntity = workDao.find(Long.valueOf(orcidWork.getPutCode()));
                    workEntity.clean();
                    workEntity = jaxb2JpaAdapter.getWorkEntity(orcid, updatedWork, workEntity);
                    workDao.persist(workEntity);
                    // Since it was already updated, remove it from the list
                    // of updated works
                    updatedWorkIterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 33 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method getOrcidWork.

private OrcidWork getOrcidWork(String workName, boolean isExistingWork) {
    OrcidWork orcidWork = new OrcidWork();
    if (isExistingWork) {
        orcidWork.setPutCode(String.valueOf(currentWorkId));
        currentWorkId += 1;
    }
    // Set title
    WorkTitle title = new WorkTitle();
    if (isExistingWork)
        title.setTitle(new Title("Title for " + workName));
    else
        title.setTitle(new Title("Title for " + workName + "->updated"));
    orcidWork.setWorkTitle(title);
    // Set source
    Source workSource = new Source(TEST_ORCID);
    orcidWork.setSource(workSource);
    // Set external identifiers
    WorkExternalIdentifier extId1 = new WorkExternalIdentifier();
    extId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("doi-" + workName));
    extId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
    WorkExternalIdentifier extId2 = new WorkExternalIdentifier();
    if (isExistingWork)
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + workName));
    else
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + workName + "->updated"));
    extId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.ISSN);
    WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
    extIds.getWorkExternalIdentifier().add(extId1);
    extIds.getWorkExternalIdentifier().add(extId2);
    orcidWork.setWorkExternalIdentifiers(extIds);
    return orcidWork;
}
Also used : WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) WorkExternalIdentifierId(org.orcid.jaxb.model.message.WorkExternalIdentifierId) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) Source(org.orcid.jaxb.model.message.Source)

Example 34 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testCheckWorkExternalIdentifiersAreNotDuplicated1.

@Test
@Transactional
public void testCheckWorkExternalIdentifiersAreNotDuplicated1() {
    List<OrcidWork> newOrcidWorksList = new ArrayList<OrcidWork>();
    List<OrcidWork> existingWorkList = new ArrayList<OrcidWork>();
    OrcidWork newWork1 = getOrcidWork("work1", false);
    OrcidWork newWork2 = getOrcidWork("work2", false);
    OrcidWork existingWork4 = getOrcidWork("work4", true);
    OrcidWork existingWork5 = getOrcidWork("work5", true);
    // Check no duplicates at all
    newOrcidWorksList.add(newWork1);
    newOrcidWorksList.add(newWork2);
    existingWorkList.add(existingWork4);
    existingWorkList.add(existingWork5);
    try {
        orcidProfileManager.checkWorkExternalIdentifiersAreNotDuplicated(newOrcidWorksList, existingWorkList);
    } catch (Exception e) {
        fail();
    }
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testCheckWorkExternalIdentifiersAreNotDuplicated3.

@Test
@Transactional
public void testCheckWorkExternalIdentifiersAreNotDuplicated3() {
    List<OrcidWork> newOrcidWorksList = new ArrayList<OrcidWork>();
    List<OrcidWork> existingWorkList = new ArrayList<OrcidWork>();
    OrcidWork newWork1 = getOrcidWork("work1", false);
    OrcidWork newWork2 = getOrcidWork("work2", false);
    OrcidWork newWork3 = getOrcidWork("work3", false);
    OrcidWork newWork3_fixed = getOrcidWork("work3", false);
    WorkTitle updatedTitle = new WorkTitle();
    updatedTitle.setTitle(new Title("updated title"));
    newWork3_fixed.setWorkTitle(updatedTitle);
    // Check #3: Check duplicates in new works
    newOrcidWorksList.add(newWork1);
    newOrcidWorksList.add(newWork2);
    newOrcidWorksList.add(newWork3);
    newOrcidWorksList.add(newWork3_fixed);
    try {
        orcidProfileManager.checkWorkExternalIdentifiersAreNotDuplicated(newOrcidWorksList, existingWorkList);
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("Works \"Title for work3->updated\" and \"updated title\" have the same external id \"doi-work3\"", iae.getMessage());
    }
}
Also used : WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OrcidWork (org.orcid.jaxb.model.message.OrcidWork)81 Test (org.junit.Test)44 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)42 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)32 Transactional (org.springframework.transaction.annotation.Transactional)26 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)24 Title (org.orcid.jaxb.model.message.Title)23 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)20 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)18 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)16 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)16 Source (org.orcid.jaxb.model.message.Source)14 Rollback (org.springframework.test.annotation.Rollback)13 ArrayList (java.util.ArrayList)12 Funding (org.orcid.jaxb.model.message.Funding)12 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)12 BaseTest (org.orcid.core.BaseTest)11 Contributor (org.orcid.jaxb.model.message.Contributor)11 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)11 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)10