Search in sources :

Example 36 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorks_duplicatedShouldFail.

@Test(expected = IllegalArgumentException.class)
public void testAddWorks_duplicatedShouldFail() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    profile2.setOrcidActivities(new OrcidActivities());
    profile2.getOrcidActivities().setOrcidWorks(new OrcidWorks());
    profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
    OrcidWorks orcidWorks = profile2.getOrcidActivities().getOrcidWorks();
    OrcidWork work1 = createWork1();
    work1.getWorkTitle().getTitle().setContent("Updated title");
    orcidWorks.getOrcidWork().add(work1);
    OrcidWork work2 = createWork2();
    orcidWorks.getOrcidWork().add(work2);
    OrcidWork work3 = createWork3();
    orcidWorks.getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile2);
    fail("Must not allow different works with same ext ids from the same source");
}
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) Test(org.junit.Test)

Example 37 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testCreateRecordWithClient1AddTryToAddExactDuplicate.

@Test
public void testCreateRecordWithClient1AddTryToAddExactDuplicate() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    OrcidWork work1 = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0);
    OrcidWork dupWork = createWork1();
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(dupWork);
    orcidProfileManager.addOrcidWorks(profile1);
    OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    OrcidWork existingWork = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0);
    assertEquals(work1.getPutCode(), existingWork.getPutCode());
    assertEquals(work1, existingWork);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test)

Example 38 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorks.

@Test
public void testAddWorks() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    String putCode1 = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    profile2.setOrcidActivities(new OrcidActivities());
    profile2.getOrcidActivities().setOrcidWorks(new OrcidWorks());
    profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
    OrcidWorks orcidWorks = profile2.getOrcidActivities().getOrcidWorks();
    OrcidWork work1 = createWork1();
    orcidWorks.getOrcidWork().add(work1);
    OrcidWork work2 = createWork2();
    orcidWorks.getOrcidWork().add(work2);
    OrcidWork work3 = createWork3();
    orcidWorks.getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile2);
    // Retry them again and verify that only work2 and work3 where created
    // Since work1 is an exact duplicated, it will just be ignored, so, we
    // must verify it keep having the same put code
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    List<OrcidWork> works = resultProfile.retrieveOrcidWorks().getOrcidWork();
    assertEquals(3, works.size());
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    for (OrcidWork work : works) {
        // TODO: limited?????
        assertEquals(Visibility.PRIVATE, work.getVisibility());
        if (work.getWorkTitle().getTitle().getContent().equals("Test Title")) {
            assertEquals(putCode1, work.getPutCode());
            found1 = true;
        } else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
            found2 = true;
        } else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
            found3 = true;
        } else {
            fail("Invalid work found " + work.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
}
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) Test(org.junit.Test)

Example 39 with OrcidWork

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

the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorkRespectDefaultVisibility.

@Test
public void testAddWorkRespectDefaultVisibility() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
    OrcidWork work2 = createWork2();
    work2.setVisibility(Visibility.PUBLIC);
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    orcidProfileManager.updateOrcidWorks(profile1);
    OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(2, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    assertEquals(Visibility.PRIVATE, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getVisibility());
    assertEquals(Visibility.LIMITED, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(1).getVisibility());
    profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
    orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
    OrcidWork work3 = createWork3();
    work3.setVisibility(Visibility.PRIVATE);
    profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.updateOrcidWorks(profile1);
    updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(3, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().forEach(work -> {
        if (work.getWorkTitle().getTitle().getContent().equals("Test Title")) {
            assertEquals(Visibility.PRIVATE, work.getVisibility());
        } else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
            assertEquals(Visibility.LIMITED, work.getVisibility());
        } else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
            assertEquals(Visibility.PUBLIC, work.getVisibility());
        } else {
            fail("Unknown work " + work.getWorkTitle().getTitle().getContent());
        }
    });
    // Clear all works
    workManager.removeAllWorks(TEST_ORCID);
    // Start over with addOrcidWorks
    profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    profile1.setOrcidActivities(new OrcidActivities());
    profile1.getOrcidActivities().setOrcidWorks(new OrcidWorks());
    profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
    work2 = createWork2();
    work2.setVisibility(Visibility.PUBLIC);
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    orcidProfileManager.addOrcidWorks(profile1);
    updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(1, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    // TODO: public?????
    assertEquals(Visibility.LIMITED, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getVisibility());
    profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
    orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
    work3 = createWork3();
    work3.setVisibility(Visibility.PRIVATE);
    profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile1);
    updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(2, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().forEach(work -> {
        if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
            assertEquals(Visibility.LIMITED, work.getVisibility());
        } else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
            assertEquals(Visibility.PUBLIC, work.getVisibility());
        } else {
            fail("Unknown work " + work.getWorkTitle().getTitle().getContent());
        }
    });
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test)

Example 40 with OrcidWork

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

the class PublicationTest method testGetOrcidWork.

@Test
public void testGetOrcidWork() {
    String doi = "10.1029\\/2002JD002436";
    String title = "5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions";
    String fullCitation = "Riemer, N, 2003, '5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions', <i>Journal of Geophysical Research<\\/i>, vol. 30, no. D4, p. 1255.";
    String coins = "ctx_ver=Z39.88-2004&rft_val_fmt=info:ofi\\/fmt:kev:mtx:journal&rft_id=info:doi\\/10.1029\\/2002JD002436&rtf.genre=journal-article&rtf.spage=1255&rtf.date=2003&rtf.aulast=Riemer&rtf.aufirst=N.&rtf.auinit=N&rtf.atitle=5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions&rtf.jtitle=Journal of Geophysical Research&rtf.volume=30&rtf.issue=D4";
    Publication publication = new Publication();
    publication.setDoi(doi);
    publication.setTitle(title);
    publication.setFullCitation(fullCitation);
    publication.setCoins(coins);
    OrcidWork orcidWork = publication.getOrcidWork();
    assertNotNull(orcidWork);
    assertEquals(doi, orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
    assertEquals(WorkExternalIdentifierType.DOI, orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierType());
    assertEquals(title, orcidWork.getWorkTitle().getTitle().getContent());
    assertEquals(fullCitation, orcidWork.getWorkCitation().getCitation());
    PublicationDate publicationDate = orcidWork.getPublicationDate();
    assertNotNull(publicationDate);
    assertEquals(null, publicationDate.getDay());
    assertEquals(null, publicationDate.getMonth());
    assertEquals("2003", publicationDate.getYear().getValue());
    assertEquals(1, orcidWork.getWorkContributors().getContributor().size());
    Contributor contributor = orcidWork.getWorkContributors().getContributor().get(0);
    assertEquals("Riemer N.", contributor.getCreditName().getContent());
    assertEquals(ContributorRole.AUTHOR, contributor.getContributorAttributes().getContributorRole());
    assertEquals(SequenceType.FIRST, contributor.getContributorAttributes().getContributorSequence());
}
Also used : PublicationDate(org.orcid.jaxb.model.message.PublicationDate) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test)

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