Search in sources :

Example 61 with OrcidProfile

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

the class OrcidProfileManagerImplTest method testPreventDuplicatedWorks.

@Test
@Transactional
@Rollback(true)
public void testPreventDuplicatedWorks() {
    OrcidWork work1 = createWork1();
    OrcidWork work2 = createWork2();
    OrcidWork work3 = createWork3();
    OrcidProfile profile = createBasicProfile();
    profile = orcidProfileManager.createOrcidProfile(profile, false, false);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(1, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    assertEquals(work1.getWorkTitle().getTitle().getContent(), profile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkTitle().getTitle().getContent());
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(2, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertFalse(found3);
    // Add work # 3 and duplicate other works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // Work 3 was added and work 1 and 2 where not added twice
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    // Duplicate all works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // No new works are added and no duplicated was allowed
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    //Test using work source
    Source source = new Source();
    source.setSourceOrcid(new SourceOrcid(APPLICATION_ORCID));
    work1.setSource(source);
    // Add work1 again, since it have a different source, it should be added
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    //Add work1 again, and it should not be added, since is duplicated
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with OrcidProfile

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

the class OrcidProfileManagerImplTest method testUpdateProfile.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfile() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    String originalPutCode = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    OrcidProfile profile2 = createBasicProfile();
    profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).setPutCode(originalPutCode);
    profile2 = orcidProfileManager.updateOrcidProfile(profile2);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    String resultPutCode = resultProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    assertNotNull(resultProfile);
    assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    assertEquals(1, resultProfile.retrieveOrcidWorks().getOrcidWork().size());
    assertEquals(1, resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://www.wjrs.co.uk", resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals("Put code should not change", originalPutCode, resultPutCode);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with OrcidProfile

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

the class OrcidProfileManagerImplTest method testMemberCreateOrcidProfileWithoutVisibilityOnBioSoDefaultVisibilityIsSetOnBioElements.

@Test
@Transactional
public void testMemberCreateOrcidProfileWithoutVisibilityOnBioSoDefaultVisibilityIsSetOnBioElements() {
    OrcidProfile profile = createBasicProfile();
    String orcidIdentifier = null;
    profile.setOrcidIdentifier(orcidIdentifier);
    setBio(profile, null);
    profile = orcidProfileManager.createOrcidProfile(profile, true, false);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidIdentifier());
    assertNotNull(profile.getOrcidIdentifier().getPath());
    OrcidProfile newProfile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
    assertNotNull(newProfile);
    assertNotNull(newProfile.getOrcidBio());
    OrcidBio bio = newProfile.getOrcidBio();
    assertEquals(Visibility.PRIVATE, bio.getBiography().getVisibility());
    assertEquals(Visibility.PRIVATE, bio.getContactDetails().getAddress().getCountry().getVisibility());
    assertEquals(Visibility.PRIVATE, bio.getExternalIdentifiers().getVisibility());
    assertEquals(Visibility.PRIVATE, bio.getKeywords().getVisibility());
    assertEquals(Visibility.PRIVATE, bio.getPersonalDetails().getOtherNames().getVisibility());
    assertEquals(Visibility.PRIVATE, bio.getResearcherUrls().getVisibility());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with OrcidProfile

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

the class Api12Helper method addFunding.

protected static void addFunding(String userOrcid, String token, String title, T2OAuthAPIService<ClientResponse> oauthT2Client) {
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    FundingList fundings = new FundingList();
    Funding funding = new Funding();
    funding.setVisibility(Visibility.LIMITED);
    FundingTitle fundingTitle = new FundingTitle();
    fundingTitle.setTitle(new Title(title));
    funding.setTitle(fundingTitle);
    funding.setType(FundingType.SALARY_AWARD);
    Amount amount = new Amount();
    amount.setCurrencyCode("CRC");
    amount.setContent("1,250,000");
    funding.setAmount(amount);
    funding.setStartDate(new FuzzyDate(2010, 1, 1));
    funding.setEndDate(new FuzzyDate(2013, 1, 1));
    funding.setDescription("My Grant description");
    funding.setUrl(new Url("http://url.com"));
    Organization org = new Organization();
    org.setName("Orcid Integration Test Org");
    OrganizationAddress add = new OrganizationAddress();
    add.setCity("My City");
    add.setCountry(Iso3166Country.CR);
    org.setAddress(add);
    funding.setOrganization(org);
    FundingExternalIdentifier extIdentifier = new FundingExternalIdentifier();
    extIdentifier.setType(FundingExternalIdentifierType.fromValue("grant_number"));
    extIdentifier.setUrl(new Url("http://url.com"));
    extIdentifier.setValue("My value");
    FundingExternalIdentifiers extIdentifiers = new FundingExternalIdentifiers();
    extIdentifiers.getFundingExternalIdentifier().add(extIdentifier);
    funding.setFundingExternalIdentifiers(extIdentifiers);
    FundingContributors contributors = new FundingContributors();
    FundingContributor contributor = new FundingContributor();
    contributor.setCreditName(new CreditName("My Credit Name"));
    contributor.setContributorEmail(new ContributorEmail("my.email@orcid-integration-test.com"));
    FundingContributorAttributes attributes = new FundingContributorAttributes();
    attributes.setContributorRole(FundingContributorRole.LEAD);
    contributor.setContributorAttributes(attributes);
    contributors.getContributor().add(contributor);
    funding.setFundingContributors(contributors);
    fundings.getFundings().add(funding);
    orcidMessage.getOrcidProfile().getOrcidActivities().setFundings(fundings);
    ClientResponse clientResponse = oauthT2Client.addFundingXml(userOrcid, orcidMessage, token);
    assertEquals(201, clientResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Organization(org.orcid.jaxb.model.message.Organization) Funding(org.orcid.jaxb.model.message.Funding) Amount(org.orcid.jaxb.model.message.Amount) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) FundingContributor(org.orcid.jaxb.model.message.FundingContributor) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) CreditName(org.orcid.jaxb.model.message.CreditName) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) ContributorEmail(org.orcid.jaxb.model.message.ContributorEmail) Url(org.orcid.jaxb.model.message.Url) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) FundingList(org.orcid.jaxb.model.message.FundingList) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) FundingContributors(org.orcid.jaxb.model.message.FundingContributors) FundingContributorAttributes(org.orcid.jaxb.model.message.FundingContributorAttributes) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers)

Example 65 with OrcidProfile

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

the class Api12Helper method addWork.

protected static void addWork(String userOrcid, String token, String title, T2OAuthAPIService<ClientResponse> oauthT2Client) {
    String id = String.valueOf(System.currentTimeMillis());
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    OrcidProfile orcidProfile = new OrcidProfile();
    orcidMessage.setOrcidProfile(orcidProfile);
    OrcidActivities orcidActivities = new OrcidActivities();
    orcidProfile.setOrcidActivities(orcidActivities);
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidActivities.setOrcidWorks(orcidWorks);
    OrcidWork orcidWork = new OrcidWork();
    orcidWorks.getOrcidWork().add(orcidWork);
    orcidWork.setWorkType(WorkType.JOURNAL_ARTICLE);
    orcidWork.setVisibility(Visibility.LIMITED);
    WorkTitle workTitle = new WorkTitle();
    orcidWork.setWorkTitle(workTitle);
    WorkExternalIdentifier wei = new WorkExternalIdentifier();
    wei.setWorkExternalIdentifierId(new WorkExternalIdentifierId(id));
    wei.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
    WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
    extIds.getWorkExternalIdentifier().add(wei);
    orcidWork.setWorkExternalIdentifiers(extIds);
    workTitle.setTitle(new Title(title));
    ClientResponse clientResponse = oauthT2Client.addWorksXml(userOrcid, orcidMessage, token);
    assertEquals(201, clientResponse.getStatus());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientResponse(com.sun.jersey.api.client.ClientResponse) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) 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) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Aggregations

OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)241 Test (org.junit.Test)118 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)77 Transactional (org.springframework.transaction.annotation.Transactional)50 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)45 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)43 DBUnitTest (org.orcid.test.DBUnitTest)43 Rollback (org.springframework.test.annotation.Rollback)40 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)36 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)35 Date (java.util.Date)27 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)27 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)25 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)23 Affiliations (org.orcid.jaxb.model.message.Affiliations)22 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)22 Title (org.orcid.jaxb.model.message.Title)22 Email (org.orcid.jaxb.model.message.Email)21 GivenNames (org.orcid.jaxb.model.message.GivenNames)21 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)21