Search in sources :

Example 81 with Funding

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

Example 82 with Funding

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

the class FundingsController method createFundingIdList.

/**
     * Create a funding id list and sorts a map associated with the list in in
     * the session
     * 
     */
private List<String> createFundingIdList(HttpServletRequest request) {
    Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
    String orcid = getEffectiveUserOrcid();
    List<Funding> fundings = profileFundingManager.getFundingList(orcid, profileEntityManager.getLastModified(orcid));
    HashMap<String, FundingForm> fundingsMap = new HashMap<String, FundingForm>();
    List<String> fundingIds = new ArrayList<String>();
    if (fundings != null) {
        for (Funding funding : fundings) {
            try {
                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));
                }
                if (form.getContributors() != null) {
                    for (Contributor contributor : form.getContributors()) {
                        if (!PojoUtil.isEmpty(contributor.getOrcid())) {
                            String contributorOrcid = contributor.getOrcid().getValue();
                            if (profileEntityManager.orcidExists(contributorOrcid)) {
                                // contributor is an ORCID user - visibility of user's name in record must be taken into account 
                                ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                                String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                                contributor.setCreditName(Text.valueOf(publicContributorCreditName));
                            }
                        }
                    }
                }
                form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
                String putCode = String.valueOf(funding.getPutCode());
                fundingsMap.put(putCode, form);
                fundingIds.add(putCode);
            } catch (Exception e) {
                LOGGER.error("Failed to parse as Funding. Put code" + funding.getPutCode(), e);
            }
        }
        request.getSession().setAttribute(GRANT_MAP, fundingsMap);
    }
    return fundingIds;
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) HashMap(java.util.HashMap) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) BigDecimal(java.math.BigDecimal) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 83 with Funding

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

the class MemberV2ApiServiceDelegatorImpl method viewFunding.

@Override
public Response viewFunding(String orcid, Long putCode) {
    Funding f = profileFundingManagerReadOnly.getFunding(orcid, putCode);
    orcidSecurityManager.checkAndFilter(orcid, f, ScopePathType.FUNDING_READ_LIMITED);
    ActivityUtils.setPathToActivity(f, orcid);
    sourceUtils.setSourceName(f);
    contributorUtils.filterContributorPrivateData(f);
    return Response.ok(f).build();
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding)

Example 84 with Funding

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

the class MemberV2ApiServiceDelegatorImpl method createFunding.

@Override
public Response createFunding(String orcid, Funding funding) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.FUNDING_CREATE);
    clearSource(funding);
    Funding f = profileFundingManager.createFunding(orcid, funding, true);
    sourceUtils.setSourceName(f);
    try {
        return Response.created(new URI(String.valueOf(f.getPutCode()))).build();
    } catch (URISyntaxException e) {
        throw new RuntimeException(localeManager.resolveMessage("apiError.createfunding_response.exception"), e);
    }
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 85 with Funding

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

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 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 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6