Search in sources :

Example 66 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class JpaJaxbFundingAdapterTest method toFundingEntityTest.

@Test
public void toFundingEntityTest() throws JAXBException {
    Funding f = getFunding(true);
    assertNotNull(f);
    ProfileFundingEntity pfe = jpaJaxbFundingAdapter.toProfileFundingEntity(f);
    assertNotNull(pfe);
    // Enums
    assertEquals(Visibility.PRIVATE.value(), pfe.getVisibility().value());
    assertEquals(FundingType.GRANT.value(), pfe.getType().value());
    // General info
    assertEquals(Long.valueOf(0), pfe.getId());
    assertEquals("common:title", pfe.getTitle());
    assertEquals("common:translated-title", pfe.getTranslatedTitle());
    assertEquals("en", pfe.getTranslatedTitleLanguageCode());
    assertEquals("funding:organization-defined-type", pfe.getOrganizationDefinedType());
    assertEquals("funding:short-description", pfe.getDescription());
    assertEquals("1234", pfe.getNumericAmount().toString());
    assertEquals("ADP", pfe.getCurrencyCode());
    assertEquals("http://tempuri.org", pfe.getUrl());
    // Dates
    assertEquals(Integer.valueOf(2), pfe.getStartDate().getDay());
    assertEquals(Integer.valueOf(2), pfe.getStartDate().getMonth());
    assertEquals(Integer.valueOf(1848), pfe.getStartDate().getYear());
    assertEquals(Integer.valueOf(2), pfe.getEndDate().getDay());
    assertEquals(Integer.valueOf(2), pfe.getEndDate().getMonth());
    assertEquals(Integer.valueOf(1848), pfe.getEndDate().getYear());
    // Contributors
    assertEquals("{\"contributor\":[{\"contributorOrcid\":{\"uri\":\"http://orcid.org/8888-8888-8888-8880\",\"path\":\"8888-8888-8888-8880\",\"host\":\"orcid.org\"},\"creditName\":{\"content\":\"funding:credit-name\"},\"contributorEmail\":{\"value\":\"funding@contributor.email\"},\"contributorAttributes\":{\"contributorRole\":\"LEAD\"}}]}", pfe.getContributorsJson());
    // External identifiers
    assertEquals("{\"fundingExternalIdentifier\":[{\"type\":\"GRANT_NUMBER\",\"value\":\"funding:external-identifier-value\",\"url\":{\"value\":\"http://tempuri.org\"},\"relationship\":\"SELF\"},{\"type\":\"GRANT_NUMBER\",\"value\":\"funding:external-identifier-value2\",\"url\":{\"value\":\"http://tempuri.org/2\"},\"relationship\":\"SELF\"}]}", pfe.getExternalIdentifiersJson());
    // Check org is null
    assertNull(pfe.getOrg());
    // Source
    assertNull(pfe.getSourceId());
    assertNull(pfe.getClientSourceId());
    assertNull(pfe.getElementSourceId());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Test(org.junit.Test)

Example 67 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class JpaJaxbFundingAdapterTest method fromFundingEntityTest.

@Test
public void fromFundingEntityTest() throws JAXBException {
    ProfileFundingEntity entity = getProfileFundingEntity();
    assertNotNull(entity);
    assertEquals("123456", entity.getNumericAmount().toString());
    Funding funding = jpaJaxbFundingAdapter.toFunding(entity);
    assertNotNull(funding);
    assertEquals(Long.valueOf(12345), funding.getPutCode());
    assertNotNull(funding.getAmount());
    assertEquals("123456", funding.getAmount().getContent());
    assertEquals("CRC", funding.getAmount().getCurrencyCode());
    assertNotNull(funding.getContributors());
    assertNotNull(funding.getContributors().getContributor());
    assertEquals(1, funding.getContributors().getContributor().size());
    assertEquals("8888-8888-8888-8880", funding.getContributors().getContributor().get(0).getContributorOrcid().getPath());
    assertEquals("orcid.org", funding.getContributors().getContributor().get(0).getContributorOrcid().getHost());
    assertEquals("http://orcid.org/8888-8888-8888-8880", funding.getContributors().getContributor().get(0).getContributorOrcid().getUri());
    assertEquals("funding:creditName", funding.getContributors().getContributor().get(0).getCreditName().getContent());
    assertEquals("funding:description", funding.getDescription());
    assertNotNull(funding.getStartDate());
    assertEquals("01", funding.getStartDate().getDay().getValue());
    assertEquals("01", funding.getStartDate().getMonth().getValue());
    assertEquals("2000", funding.getStartDate().getYear().getValue());
    assertNotNull(funding.getEndDate());
    assertEquals("01", funding.getEndDate().getDay().getValue());
    assertEquals("01", funding.getEndDate().getMonth().getValue());
    assertEquals("2020", funding.getEndDate().getYear().getValue());
    assertEquals("funding:title", funding.getTitle().getTitle().getContent());
    assertEquals("funding:translatedTitle", funding.getTitle().getTranslatedTitle().getContent());
    assertEquals("ES", funding.getTitle().getTranslatedTitle().getLanguageCode());
    assertEquals(FundingType.SALARY_AWARD, funding.getType());
    assertEquals(Visibility.PRIVATE, funding.getVisibility());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Test(org.junit.Test)

Example 68 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class MemberV2Test method testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource.

@Test
public void testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
    fExtId.setValue("Funding Id " + time);
    fExtId.setRelationship(Relationship.SELF);
    funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc1/" + this.getUser1OrcidId() + "/funding/\\d+"));
    ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
    Funding gotFunding = getResponse.getEntity(Funding.class);
    assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
    assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("en", gotFunding.getTitle().getTranslatedTitle().getLanguageCode());
    gotFunding.getTitle().getTitle().setContent("Updated title");
    gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
    gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
    String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotFunding);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
    assertEquals("common:title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
    assertEquals("common:translated-title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("en", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getLanguageCode());
    ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), gotFunding.getPutCode(), accessToken);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc1.Funding) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Test(org.junit.Test)

Example 69 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class PublicV2Test method checkFunding.

private void checkFunding(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
    Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    fundingToCreate.setPutCode(null);
    fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
    String accessToken = getAccessToken();
    ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String path = postResponse.getLocation().getPath();
    String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
    ClientResponse getFundingResponse = null;
    if (readPublicToken != null) {
        getFundingResponse = publicV2ApiClient.viewFundingXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        getFundingResponse = publicV2ApiClient.viewFundingXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(getFundingResponse);
    checkResponse(getFundingResponse);
    Funding funding = getFundingResponse.getEntity(Funding.class);
    assertNotNull(funding);
    assertEquals("common:title", funding.getTitle().getTitle().getContent());
    ClientResponse getFundingSummaryResponse = null;
    if (readPublicToken != null) {
        getFundingSummaryResponse = publicV2ApiClient.viewFundingSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
    } else {
        getFundingSummaryResponse = publicV2ApiClient.viewFundingSummaryXml(getUser1OrcidId(), putCode);
    }
    assertNotNull(getFundingSummaryResponse);
    checkResponse(getFundingSummaryResponse);
    FundingSummary summary = getFundingSummaryResponse.getEntity(FundingSummary.class);
    assertNotNull(summary);
    assertEquals("common:title", summary.getTitle().getTitle().getContent());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc1.Funding) FundingSummary(org.orcid.jaxb.model.record.summary_rc1.FundingSummary)

Example 70 with Funding

use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.

the class OrcidRecordToSolrDocumentTest method test12SameAs20.

@Test
public void test12SameAs20() throws IOException, SolrServerException, JAXBException {
    OrcidProfileToSolrDocument v12 = new OrcidProfileToSolrDocument();
    OrcidRecordToSolrDocument v20 = new OrcidRecordToSolrDocument(false);
    Record record = getRecord("/v20record.xml");
    OrcidMessage message = getOrcidMessage();
    OrcidSolrDocument v12Doc = v12.convert(message.getOrcidProfile());
    OrcidSolrDocument v20Doc = v20.convert(record, new ArrayList<Funding>());
    Assert.assertEquals(v12Doc.getOrcid(), v20Doc.getOrcid());
    Assert.assertEquals(v12Doc.getFamilyName(), v20Doc.getFamilyName());
    Assert.assertEquals(v12Doc.getGivenNames(), v20Doc.getGivenNames());
    Assert.assertEquals(v12Doc.getGivenAndFamilyNames(), v20Doc.getGivenAndFamilyNames());
    Assert.assertTrue(v12Doc.getDigitalObjectIds().containsAll(v20Doc.getDigitalObjectIds()));
    Assert.assertTrue(v20Doc.getDigitalObjectIds().containsAll(v12Doc.getDigitalObjectIds()));
    Assert.assertTrue(v12Doc.getWorkTitles().containsAll(v20Doc.getWorkTitles()));
    Assert.assertTrue(v20Doc.getWorkTitles().containsAll(v12Doc.getWorkTitles()));
    Assert.assertTrue(v12Doc.getCit().containsAll(v20Doc.getCit()));
    Assert.assertTrue(v20Doc.getCit().containsAll(v12Doc.getCit()));
    Assert.assertTrue(v12Doc.getAgr().containsAll(v20Doc.getAgr()));
    Assert.assertTrue(v20Doc.getAgr().containsAll(v12Doc.getAgr()));
    Assert.assertEquals(v12Doc.getProfileLastModifiedDate(), v20Doc.getProfileLastModifiedDate());
    Assert.assertEquals(v12Doc.getProfileSubmissionDate(), v20Doc.getProfileSubmissionDate());
}
Also used : OrcidRecordToSolrDocument(org.orcid.listener.solr.OrcidRecordToSolrDocument) Funding(org.orcid.jaxb.model.record_v2.Funding) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Record(org.orcid.jaxb.model.record_v2.Record) OrcidProfileToSolrDocument(org.orcid.listener.solr.OrcidProfileToSolrDocument) Test(org.junit.Test)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)73 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ArrayList (java.util.ArrayList)16 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Response (javax.ws.rs.core.Response)15 DBUnitTest (org.orcid.test.DBUnitTest)15 Url (org.orcid.jaxb.model.common_v2.Url)14 Title (org.orcid.jaxb.model.common_v2.Title)11 Work (org.orcid.jaxb.model.record_v2.Work)10 List (java.util.List)9 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)9 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)9 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 BaseTest (org.orcid.core.BaseTest)6 Funding (org.orcid.jaxb.model.record_rc4.Funding)6 Education (org.orcid.jaxb.model.record_v2.Education)6