Search in sources :

Example 56 with Funding

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

the class ValidateV2RC3Identifiers method testFunding.

@Test
public void testFunding() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Funding funding = unmarshallFromPath("/record_2.0_rc3/samples/funding-2.0_rc3.xml", Funding.class);
    assertEquals("funding:organization-defined-type", funding.getOrganizationDefinedType().getContent());
    assertNotNull(funding.getExternalIdentifiers());
    assertNotNull(funding.getExternalIdentifiers().getExternalIdentifier());
    Assert.notEmpty(funding.getExternalIdentifiers().getExternalIdentifier());
    assertEquals("grant_number", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
    assertEquals("funding:external-identifier-value", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://tempuri.org"), funding.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, funding.getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    Validator validator = getValidator("funding");
    validator.validate(marshall(Funding.class, funding));
    validator.validate(marshallToDOM(Funding.class, funding));
}
Also used : Funding(org.orcid.jaxb.model.record_rc3.Funding) Url(org.orcid.jaxb.model.common_rc3.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 57 with Funding

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

the class ValidateV2IdentifiersTest method testFunding.

@Test
public void testFunding() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Funding funding = unmarshallFromPath("/record_2.0/samples/read_samples/funding-2.0.xml", Funding.class);
    assertEquals("funding:organization-defined-type", funding.getOrganizationDefinedType().getContent());
    assertNotNull(funding.getExternalIdentifiers());
    assertNotNull(funding.getExternalIdentifiers().getExternalIdentifier());
    Assert.notEmpty(funding.getExternalIdentifiers().getExternalIdentifier());
    assertEquals("grant_number", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getType());
    assertEquals("funding:external-identifier-value", funding.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
    assertEquals(new Url("http://tempuri.org"), funding.getExternalIdentifiers().getExternalIdentifier().get(0).getUrl());
    assertEquals(Relationship.SELF, funding.getExternalIdentifiers().getExternalIdentifier().get(0).getRelationship());
    Validator validator = getValidator("funding");
    validator.validate(marshall(Funding.class, funding));
    validator.validate(marshallToDOM(Funding.class, funding));
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) Url(org.orcid.jaxb.model.common_v2.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 58 with Funding

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

the class MemberV2Test method createViewUpdateAndDeleteFunding.

@Test
public void createViewUpdateAndDeleteFunding() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    Funding funding = (Funding) unmarshallFromPath("/record_2.0/samples/read_samples/funding-2.0.xml", Funding.class);
    funding.setPutCode(null);
    funding.setVisibility(Visibility.PUBLIC);
    funding.getExternalIdentifiers().getExternalIdentifier().clear();
    ExternalID fExtId = new ExternalID();
    fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
    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/" + 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());
    //Save the original visibility
    Visibility originalVisibility = gotFunding.getVisibility();
    Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
    //Verify you cant update the visibility
    gotFunding.setVisibility(updatedVisibility);
    ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
    OrcidError error = putResponse.getEntity(OrcidError.class);
    assertNotNull(error);
    assertEquals(Integer.valueOf(9035), error.getErrorCode());
    //Set the visibility again to the initial one
    gotFunding.setVisibility(originalVisibility);
    gotFunding.getTitle().getTitle().setContent("Updated title");
    gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
    gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
    putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
    assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
    ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
    Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
    assertEquals("Updated title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
    assertEquals("Updated translated title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
    assertEquals("es", 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) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) Funding(org.orcid.jaxb.model.record_v2.Funding) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Test(org.junit.Test)

Example 59 with Funding

use of org.orcid.jaxb.model.record_rc1.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)

Example 60 with Funding

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

the class OrcidRecordToSolrDocumentTest method testOrgIDAndGrantNumber.

@Test
public void testOrgIDAndGrantNumber() throws JAXBException {
    Record record = getRecord("/v20record.xml");
    OrcidRecordToSolrDocument v20 = new OrcidRecordToSolrDocument(false);
    OrcidSolrDocument v20Doc = v20.convert(record, new ArrayList<Funding>());
    Assert.assertTrue(v20Doc.getOrganisationIds().containsKey("ringgold-org-id"));
    Assert.assertTrue(v20Doc.getOrganisationIds().get("ringgold-org-id").contains("5488"));
    Assert.assertTrue(v20Doc.getOrganisationIds().get("ringgold-org-id").contains("4925"));
    Assert.assertTrue(v20Doc.getOrganisationNames().get("affiliation-org-name").contains("Open University"));
    Assert.assertTrue(v20Doc.getOrganisationNames().get("affiliation-org-name").contains("British Library"));
/*
        Assert.assertTrue(v20Doc.getOrganisationNames().get("funding-org-name").contains("THOR - Technical and Human Infrastructure for Open Research"));
        Assert.assertTrue(v20Doc.getGrantNumbers().contains("H2020-EU.1.4.1.3."));
        */
}
Also used : OrcidRecordToSolrDocument(org.orcid.listener.solr.OrcidRecordToSolrDocument) Funding(org.orcid.jaxb.model.record_v2.Funding) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Record(org.orcid.jaxb.model.record_v2.Record) Test(org.junit.Test)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)70 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ArrayList (java.util.ArrayList)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Response (javax.ws.rs.core.Response)15 Url (org.orcid.jaxb.model.common_v2.Url)15 DBUnitTest (org.orcid.test.DBUnitTest)15 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 IOException (java.io.IOException)8 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 Education (org.orcid.jaxb.model.record_v2.Education)8 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)8 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)8 InputStreamReader (java.io.InputStreamReader)7 Reader (java.io.Reader)7