Search in sources :

Example 26 with OrcidWorks

use of org.orcid.jaxb.model.message.OrcidWorks 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 27 with OrcidWorks

use of org.orcid.jaxb.model.message.OrcidWorks 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 28 with OrcidWorks

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

the class T2OrcidApiServiceDelegatorTest method testAddWorks.

@Test
public void testAddWorks() {
    SecurityContextTestUtils.setUpSecurityContext();
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4441"));
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidActivities.setOrcidWorks(orcidWorks);
    Response response = t2OrcidApiServiceDelegator.addWorks(mockedUriInfo, "4444-4444-4444-4441", orcidMessage);
    assertNotNull(response);
    assertEquals(201, response.getStatus());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 29 with OrcidWorks

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

the class OrcidProfileManagerImpl method dedupeWorks.

private void dedupeWorks(OrcidProfile orcidProfile) {
    OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
    if (orcidActivities != null) {
        OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
        if (orcidWorks != null) {
            OrcidWorks dedupedOrcidWorks = dedupeWorks(orcidWorks);
            orcidActivities.setOrcidWorks(dedupedOrcidWorks);
        }
    }
}
Also used : OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 30 with OrcidWorks

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

the class OrcidMessageUtil method setSourceName.

public void setSourceName(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidActivities() != null) {
            OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
            if (orcidActivities.getAffiliations() != null) {
                Affiliations affs = orcidActivities.getAffiliations();
                List<Affiliation> affList = affs.getAffiliation();
                if (affList != null) {
                    for (Affiliation aff : affList) {
                        setSourceName(aff);
                    }
                }
            }
            if (orcidActivities.getFundings() != null) {
                FundingList fundingList = orcidActivities.getFundings();
                List<Funding> fundings = fundingList.getFundings();
                if (fundings != null) {
                    for (Funding funding : fundings) {
                        setSourceName(funding);
                    }
                }
            }
            if (orcidActivities.getOrcidWorks() != null) {
                OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
                List<OrcidWork> works = orcidWorks.getOrcidWork();
                if (works != null) {
                    for (OrcidWork work : works) {
                        setSourceName(work);
                    }
                }
            }
        }
        if (orcidProfile.getOrcidBio() != null) {
            OrcidBio orcidBio = orcidProfile.getOrcidBio();
            if (orcidBio.getContactDetails() != null) {
                Address address = orcidBio.getContactDetails().getAddress();
                if (address != null) {
                    setSourceName(address);
                }
            }
            if (orcidBio.getExternalIdentifiers() != null) {
                ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
                List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
                if (extIdsList != null) {
                    for (ExternalIdentifier extId : extIdsList) {
                        setSourceName(extId);
                    }
                }
            }
            if (orcidBio.getKeywords() != null) {
                Keywords keywords = orcidBio.getKeywords();
                List<Keyword> keywordList = keywords.getKeyword();
                if (keywordList != null) {
                    for (Keyword keyword : keywordList) {
                        setSourceName(keyword);
                    }
                }
            }
            if (orcidBio.getPersonalDetails() != null) {
                OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
                if (otherNames != null) {
                    List<OtherName> otherNameList = otherNames.getOtherName();
                    if (otherNameList != null) {
                        for (OtherName otherName : otherNameList) {
                            setSourceName(otherName);
                        }
                    }
                }
            }
            if (orcidBio.getResearcherUrls() != null) {
                ResearcherUrls rUrls = orcidBio.getResearcherUrls();
                List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
                if (rUrlList != null) {
                    for (ResearcherUrl rUrl : rUrlList) {
                        setSourceName(rUrl);
                    }
                }
            }
        }
    }
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) Keyword(org.orcid.jaxb.model.message.Keyword) Funding(org.orcid.jaxb.model.message.Funding) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OtherName(org.orcid.jaxb.model.message.OtherName) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) FundingList(org.orcid.jaxb.model.message.FundingList) Affiliations(org.orcid.jaxb.model.message.Affiliations) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Aggregations

OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)46 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)35 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)32 Test (org.junit.Test)24 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)19 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)15 Title (org.orcid.jaxb.model.message.Title)15 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)13 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)13 Transactional (org.springframework.transaction.annotation.Transactional)12 FundingList (org.orcid.jaxb.model.message.FundingList)9 Funding (org.orcid.jaxb.model.message.Funding)8 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)8 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)8 DBUnitTest (org.orcid.test.DBUnitTest)8 Rollback (org.springframework.test.annotation.Rollback)8 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)7 Date (java.util.Date)6 Affiliations (org.orcid.jaxb.model.message.Affiliations)6 Subtitle (org.orcid.jaxb.model.message.Subtitle)6