Search in sources :

Example 71 with OrcidWork

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

the class OrcidProfileManagerImplTest method getWorkInsideOrcidProfile.

private OrcidProfile getWorkInsideOrcidProfile(String defaultTitle, String orcid) {
    OrcidWork orcidWork = new OrcidWork();
    // Set title
    WorkTitle title = new WorkTitle();
    if (defaultTitle != null)
        title.setTitle(new Title(defaultTitle));
    else
        title.setTitle(new Title("Title"));
    orcidWork.setWorkTitle(title);
    // Set external identifiers
    WorkExternalIdentifier extId1 = new WorkExternalIdentifier();
    extId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("doi-" + defaultTitle));
    extId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
    WorkExternalIdentifier extId2 = new WorkExternalIdentifier();
    if (defaultTitle != null)
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + defaultTitle));
    else
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + System.currentTimeMillis()));
    extId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.ISSN);
    WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
    extIds.getWorkExternalIdentifier().add(extId1);
    extIds.getWorkExternalIdentifier().add(extId2);
    orcidWork.setWorkExternalIdentifiers(extIds);
    orcidWork.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
    OrcidProfile profile = new OrcidProfile();
    profile.setOrcidIdentifier(orcid);
    List<OrcidWork> workList = new ArrayList<OrcidWork>();
    workList.add(orcidWork);
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidWorks.setOrcidWork(workList);
    profile.setOrcidWorks(orcidWorks);
    return profile;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) 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) 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) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 72 with OrcidWork

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

the class OrcidProfileManagerImplTest method testCheckWorkExternalIdentifiersAreNotDuplicated2.

@Test
@Transactional
public void testCheckWorkExternalIdentifiersAreNotDuplicated2() {
    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 existingWork3 = getOrcidWork("work3", true);
    OrcidWork existingWork4 = getOrcidWork("work4", true);
    OrcidWork existingWork5 = getOrcidWork("work5", true);
    // Check duplicates in new works and existing works
    newOrcidWorksList.add(newWork1);
    newOrcidWorksList.add(newWork2);
    existingWorkList.add(existingWork4);
    existingWorkList.add(existingWork5);
    newOrcidWorksList.add(newWork3);
    existingWorkList.add(existingWork3);
    try {
        orcidProfileManager.checkWorkExternalIdentifiersAreNotDuplicated(newOrcidWorksList, existingWorkList);
        fail();
    } catch (IllegalArgumentException iae) {
        assertEquals("Works \"Title for work3->updated\" and \"Title for work3\"(put-code '" + existingWork3.getPutCode() + "') have the same external id \"doi-work3\"", iae.getMessage());
    }
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 73 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testCreateRecordWithClient1AddTryToAddADuplicate.

@Test(expected = IllegalArgumentException.class)
public void testCreateRecordWithClient1AddTryToAddADuplicate() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    OrcidWork dupWork = createWork1();
    dupWork.getWorkTitle().getTitle().setContent("Updated title");
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(dupWork);
    orcidProfileManager.addOrcidWorks(profile1);
    fail();
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test)

Example 74 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testCreateRecordWithClient1AddDuplicateWithClient2.

@Test
public void testCreateRecordWithClient1AddDuplicateWithClient2() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    assertEquals(CLIENT_1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getSource().retrieveSourcePath());
    String work1PutCode = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    // Change the source entity
    TargetProxyHelper.injectIntoProxy(jaxb2JpaAdapter, "sourceManager", anotherMockSourceManager);
    TargetProxyHelper.injectIntoProxy(orcidProfileManager, "sourceManager", anotherMockSourceManager);
    OrcidWork dupWork = createWork1();
    profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(dupWork);
    orcidProfileManager.addOrcidWorks(profile1);
    OrcidProfile profileWithWork1FromTwoDifferentSources = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(2, profileWithWork1FromTwoDifferentSources.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    profileWithWork1FromTwoDifferentSources.getOrcidActivities().getOrcidWorks().getOrcidWork().forEach(work -> {
        if (work.getPutCode().equals(work1PutCode)) {
            assertEquals(CLIENT_1, work.retrieveSourcePath());
        } else {
            assertEquals(CLIENT_2, work.retrieveSourcePath());
        }
    });
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test)

Example 75 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method addDataToTestRecord.

private void addDataToTestRecord() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    OrcidWork work1 = createWork1();
    profile1.setOrcidActivities(new OrcidActivities());
    profile1.getOrcidActivities().setOrcidWorks(new OrcidWorks());
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.updateOrcidProfile(profile1);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

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