Search in sources :

Example 81 with Funding

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

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

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

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