Search in sources :

Example 81 with Funding

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

the class BlackBoxBaseRC3 method unmarshallFromPath.

public Object unmarshallFromPath(String path, Class<?> type) {
    try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
        Object obj = unmarshall(reader, type);
        Object result = null;
        if (Address.class.equals(type)) {
            result = (Address) obj;
        } else if (Education.class.equals(type)) {
            result = (Education) obj;
        } else if (Employment.class.equals(type)) {
            result = (Employment) obj;
        } else if (Funding.class.equals(type)) {
            result = (Funding) obj;
        } else if (Keyword.class.equals(type)) {
            result = (Keyword) obj;
        } else if (Work.class.equals(type)) {
            result = (Work) obj;
        } else if (PeerReview.class.equals(type)) {
            result = (PeerReview) obj;
        } else if (ResearcherUrl.class.equals(type)) {
            result = (ResearcherUrl) obj;
        } else if (PersonalDetails.class.equals(type)) {
            result = (PersonalDetails) obj;
        } else if (OtherName.class.equals(type)) {
            result = (OtherName) obj;
        } else if (PersonExternalIdentifier.class.equals(type)) {
            result = (PersonExternalIdentifier) obj;
        }
        return result;
    } catch (IOException e) {
        throw new RuntimeException("Error reading notification from classpath", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Education(org.orcid.jaxb.model.record_rc3.Education) Funding(org.orcid.jaxb.model.record_rc3.Funding) Work(org.orcid.jaxb.model.record_rc3.Work) OtherName(org.orcid.jaxb.model.record_rc3.OtherName) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ResearcherUrl(org.orcid.jaxb.model.record_rc3.ResearcherUrl) IOException(java.io.IOException)

Example 82 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_rc3/samples/funding-2.0_rc3.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_rc3/" + 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_rc3.Funding) ExternalID(org.orcid.jaxb.model.record_rc3.ExternalID) Test(org.junit.Test)

Example 83 with Funding

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

the class PublicV2Test method createActivities.

private void createActivities() throws JSONException, InterruptedException, URISyntaxException {
    String accessToken = getAccessToken();
    long time = System.currentTimeMillis();
    Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
    for (int i = 0; i < 4; i++) {
        workToCreate.setPutCode(null);
        workToCreate.getWorkTitle().getTitle().setContent("Work # " + i);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
        WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
        wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId(time + " Work Id " + i));
        wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
        wExtId.setRelationship(Relationship.SELF);
        workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
        if (i == 0 || i == 3)
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
    for (int i = 0; i < 4; i++) {
        fundingToCreate.setPutCode(null);
        fundingToCreate.getTitle().getTitle().setContent("Funding # " + i);
        fundingToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
        FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
        fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
        fExtId.setValue(time + " funding Id " + i);
        fExtId.setRelationship(Relationship.SELF);
        fundingToCreate.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
        if (i == 0 || i == 3)
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
    for (int i = 0; i < 4; i++) {
        employmentToCreate.setPutCode(null);
        employmentToCreate.setRoleTitle("Employment # " + i);
        if (i == 0 || i == 3)
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    Education educationToCreate = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
    for (int i = 0; i < 4; i++) {
        educationToCreate.setPutCode(null);
        educationToCreate.setRoleTitle("Education # " + i);
        if (i == 0 || i == 3)
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        else if (i == 1)
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        else
            educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        ClientResponse postResponse = memberV2ApiClient.createEducationXml(getUser1OrcidId(), educationToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
    PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
    for (int i = 0; i < 4; i++) {
        peerReviewToCreate.setPutCode(null);
        peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
        peerReviewToCreate.getSubjectName().getTitle().setContent("PeerReview # " + i);
        peerReviewToCreate.getCompletionDate().setDay(new Day(i + 1));
        peerReviewToCreate.getCompletionDate().setMonth(new Month(i + 1));
        peerReviewToCreate.getCompletionDate().setYear(new Year((i + 1) * 1000));
        peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().get(0).getWorkExternalIdentifierId().setContent("extId-" + (i + 1));
        if (i == 0 || i == 3) {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
        } else if (i == 1) {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
        } else {
            peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
        }
        ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, accessToken);
        assertNotNull(postResponse);
        assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc1.Funding) WorkExternalIdentifierId(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId) FundingExternalIdentifier(org.orcid.jaxb.model.record_rc1.FundingExternalIdentifier) Month(org.orcid.jaxb.model.common_rc1.Month) Year(org.orcid.jaxb.model.common_rc1.Year) Employment(org.orcid.jaxb.model.record_rc1.Employment) Education(org.orcid.jaxb.model.record_rc1.Education) Work(org.orcid.jaxb.model.record_rc1.Work) WorkExternalIdentifier(org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier) Day(org.orcid.jaxb.model.common_rc1.Day) PeerReview(org.orcid.jaxb.model.record_rc1.PeerReview)

Example 84 with Funding

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

the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFundingLeavingVisibilityNullTest.

@Test
public void testUpdateFundingLeavingVisibilityNullTest() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    assertEquals(Visibility.PUBLIC, funding.getVisibility());
    funding.setVisibility(null);
    response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    funding = (Funding) response.getEntity();
    assertEquals(Visibility.PUBLIC, funding.getVisibility());
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 85 with Funding

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

the class MemberV2ApiServiceDelegator_FundingTest method testAddFundingWithInvalidExtIdTypeFail.

@Test
public void testAddFundingWithInvalidExtIdTypeFail() {
    String orcid = "4444-4444-4444-4499";
    SecurityContextTestUtils.setUpSecurityContext(orcid, ScopePathType.ACTIVITIES_READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
    Funding funding = Utils.getFunding();
    try {
        funding.getExternalIdentifiers().getExternalIdentifier().get(0).setType("INVALID");
        serviceDelegator.createFunding(orcid, funding);
        fail();
    } catch (ActivityIdentifierValidationException e) {
    } catch (Exception e) {
        fail();
    }
    funding.getExternalIdentifiers().getExternalIdentifier().get(0).setType("grant_number");
    Response response = serviceDelegator.createFunding(orcid, funding);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    Map<?, ?> map = response.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List<?> resultWithPutCode = (List<?>) map.get("Location");
    Long putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
    // Delete it to roll back the test data
    response = serviceDelegator.deleteFunding(orcid, putCode);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) List(java.util.List) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) 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