Search in sources :

Example 76 with Funding

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

the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.

@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
    long time = System.currentTimeMillis();
    List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
    String accessToken = getAccessToken(scopes);
    Work work1 = (Work) unmarshallFromPath("/record_2.0_rc2/samples/work-2.0_rc2.xml", Work.class);
    work1.setPutCode(null);
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    org.orcid.jaxb.model.record_rc2.WorkTitle title1 = new org.orcid.jaxb.model.record_rc2.WorkTitle();
    title1.setTitle(new Title("Work # 1"));
    work1.setWorkTitle(title1);
    ExternalID wExtId1 = new ExternalID();
    wExtId1.setValue("Work Id " + time);
    wExtId1.setType(WorkExternalIdentifierType.AGR.value());
    wExtId1.setRelationship(Relationship.SELF);
    wExtId1.setUrl(new Url("http://orcid.org/work#1"));
    work1.getExternalIdentifiers().getExternalIdentifier().clear();
    work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
    //Add the work
    ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
    Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc2/samples/funding-2.0_rc2.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);
    //Add the funding
    postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    // Delete funding        
    Map map = postResponse.getMetadata();
    assertNotNull(map);
    assertTrue(map.containsKey("Location"));
    List resultWithPutCode = (List) map.get("Location");
    String location = resultWithPutCode.get(0).toString();
    Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
    ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
    assertNotNull(deleteResponse);
    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Funding(org.orcid.jaxb.model.record_rc2.Funding) ExternalID(org.orcid.jaxb.model.record_rc2.ExternalID) Title(org.orcid.jaxb.model.common_rc2.Title) Url(org.orcid.jaxb.model.common_rc2.Url) Work(org.orcid.jaxb.model.record_rc2.Work) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 77 with Funding

use of org.orcid.jaxb.model.record_rc3.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 78 with Funding

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

the class FundingsController method getFundingJson.

/**
     * List fundings associated with a profile
     * */
@RequestMapping(value = "/getFunding.json", method = RequestMethod.GET)
@ResponseBody
public FundingForm getFundingJson(@RequestParam(value = "fundingId") Long fundingId) {
    if (fundingId == null)
        return null;
    Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
    Funding funding = profileFundingManager.getFunding(getEffectiveUserOrcid(), fundingId);
    FundingForm form = FundingForm.valueOf(funding);
    if (funding.getType() != null) {
        form.setFundingTypeForDisplay(getMessage(buildInternationalizationKey(org.orcid.jaxb.model.message.FundingType.class, funding.getType().value())));
    }
    // Set translated title language name
    if (!(funding.getTitle().getTranslatedTitle() == null) && !StringUtils.isEmpty(funding.getTitle().getTranslatedTitle().getLanguageCode())) {
        String languageName = languages.get(funding.getTitle().getTranslatedTitle().getLanguageCode());
        form.getFundingTitle().getTranslatedTitle().setLanguageName(languageName);
    }
    // Set the formatted amount
    if (funding.getAmount() != null && StringUtils.isNotBlank(funding.getAmount().getContent())) {
        BigDecimal bigDecimal = new BigDecimal(funding.getAmount().getContent());
        String formattedAmount = formatAmountString(bigDecimal);
        form.setAmount(Text.valueOf(formattedAmount));
    }
    form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
    return form;
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) BigDecimal(java.math.BigDecimal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 79 with Funding

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

the class FundingsController method editFunding.

private void editFunding(FundingForm fundingForm) throws Exception {
    // Set the right value for the amount
    setAmountWithTheCorrectFormat(fundingForm);
    // Set the credit name
    setTypeToExternalIdentifiers(fundingForm);
    // Add to database
    Funding funding = fundingForm.toFunding();
    funding = profileFundingManager.updateFunding(getEffectiveUserOrcid(), funding, false);
    // Send the new funding sub type for indexing
    if (fundingForm.getOrganizationDefinedFundingSubType() != null && !PojoUtil.isEmpty(fundingForm.getOrganizationDefinedFundingSubType().getSubtype()) && !fundingForm.getOrganizationDefinedFundingSubType().isAlreadyIndexed())
        profileFundingManager.addFundingSubType(fundingForm.getOrganizationDefinedFundingSubType().getSubtype().getValue(), getEffectiveUserOrcid());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding)

Example 80 with Funding

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

the class FundingsController method addFunding.

private void addFunding(FundingForm fundingForm) throws Exception {
    // Set the right value for the amount
    setAmountWithTheCorrectFormat(fundingForm);
    // Set default type for external identifiers
    setTypeToExternalIdentifiers(fundingForm);
    // Add to database
    Funding funding = fundingForm.toFunding();
    funding = profileFundingManager.createFunding(getEffectiveUserOrcid(), funding, false);
    // Send the new funding sub type for indexing
    if (fundingForm.getOrganizationDefinedFundingSubType() != null && !PojoUtil.isEmpty(fundingForm.getOrganizationDefinedFundingSubType().getSubtype()) && !fundingForm.getOrganizationDefinedFundingSubType().isAlreadyIndexed())
        profileFundingManager.addFundingSubType(fundingForm.getOrganizationDefinedFundingSubType().getSubtype().getValue(), getEffectiveUserOrcid());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)71 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 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)8 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)8 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 BaseTest (org.orcid.core.BaseTest)6