Search in sources :

Example 6 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class FundingsController method getFunding.

/**
     * Returns a blank funding form
     * */
@RequestMapping(value = "/funding.json", method = RequestMethod.GET)
@ResponseBody
public FundingForm getFunding() {
    FundingForm result = new FundingForm();
    result.setAmount(new Text());
    result.setCurrencyCode(Text.valueOf(""));
    result.setDescription(new Text());
    result.setFundingName(new Text());
    result.setFundingType(Text.valueOf(""));
    result.setSourceName(new String());
    OrgDefinedFundingSubType subtype = new OrgDefinedFundingSubType();
    subtype.setAlreadyIndexed(false);
    subtype.setSubtype(Text.valueOf(""));
    result.setOrganizationDefinedFundingSubType(subtype);
    FundingTitleForm title = new FundingTitleForm();
    title.setTitle(new Text());
    TranslatedTitleForm tt = new TranslatedTitleForm();
    tt.setContent(new String());
    tt.setLanguageCode(new String());
    tt.setLanguageName(new String());
    title.setTranslatedTitle(tt);
    result.setFundingTitle(title);
    result.setUrl(new Text());
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    Visibility v = Visibility.valueOf(profile.getActivitiesVisibilityDefault() == null ? org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.FUNDING_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault());
    result.setVisibility(v);
    Date startDate = new Date();
    result.setStartDate(startDate);
    startDate.setDay("");
    startDate.setMonth("");
    startDate.setYear("");
    Date endDate = new Date();
    result.setEndDate(endDate);
    endDate.setDay("");
    endDate.setMonth("");
    endDate.setYear("");
    // Set empty contributor
    Contributor contr = new Contributor();
    List<Contributor> contrList = new ArrayList<Contributor>();
    Text rText = new Text();
    rText.setValue("");
    contr.setContributorRole(rText);
    Text sText = new Text();
    sText.setValue("");
    contr.setContributorSequence(sText);
    contrList.add(contr);
    result.setContributors(contrList);
    // Set empty external identifier
    List<FundingExternalIdentifierForm> emptyExternalIdentifiers = new ArrayList<FundingExternalIdentifierForm>();
    FundingExternalIdentifierForm f = new FundingExternalIdentifierForm();
    f.setType(Text.valueOf(DEFAULT_FUNDING_EXTERNAL_IDENTIFIER_TYPE));
    f.setUrl(new Text());
    f.setValue(new Text());
    f.setRelationship(Text.valueOf(Relationship.SELF.value()));
    emptyExternalIdentifiers.add(f);
    result.setExternalIdentifiers(emptyExternalIdentifiers);
    result.setCity(new Text());
    result.setCountry(Text.valueOf(""));
    result.setRegion(new Text());
    return result;
}
Also used : FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) FundingTitleForm(org.orcid.pojo.ajaxForm.FundingTitleForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(org.orcid.pojo.ajaxForm.Date) Visibility(org.orcid.pojo.ajaxForm.Visibility) FundingExternalIdentifierForm(org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm) TranslatedTitleForm(org.orcid.pojo.ajaxForm.TranslatedTitleForm) OrgDefinedFundingSubType(org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm 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 8 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm 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 9 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class OrcidInfo method getFundingsJson.

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/fundings.json")
@ResponseBody
public List<FundingForm> getFundingsJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "fundingIds") String fundingIdsStr) {
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    List<FundingForm> fundings = new ArrayList<FundingForm>();
    Map<Long, Funding> fundingMap = fundingMap(orcid, getLastModifiedTime(orcid));
    String[] fundingIds = fundingIdsStr.split(",");
    for (String id : fundingIds) {
        Funding funding = fundingMap.get(Long.valueOf(id));
        validateVisibility(funding.getVisibility());
        sourceUtils.setSourceName(funding);
        FundingForm form = FundingForm.valueOf(funding);
        // Set type name
        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 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));
        }
        // Set country name
        form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
        fundings.add(form);
    }
    return fundings;
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with FundingForm

use of org.orcid.pojo.ajaxForm.FundingForm in project ORCID-Source by ORCID.

the class FundingsControllerTest method testAddFundingWithInvalidDates.

@Test
public void testAddFundingWithInvalidDates() throws Exception {
    FundingForm funding = getFundingForm();
    //Check valid start date
    Date startDate = new Date();
    startDate.setMonth("01");
    funding.setStartDate(startDate);
    funding = fundingController.postFunding(funding);
    assertNotNull(funding);
    assertNotNull(funding.getErrors());
    assertEquals(1, funding.getErrors().size());
    assertEquals(fundingController.getMessage("common.dates.invalid"), funding.getErrors().get(0));
    //Check valid end date
    funding = getFundingForm();
    Date endDate = new Date();
    endDate.setMonth("01");
    funding.setEndDate(endDate);
    funding = fundingController.postFunding(funding);
    assertNotNull(funding);
    assertNotNull(funding.getErrors());
    assertEquals(1, funding.getErrors().size());
    assertEquals(fundingController.getMessage("common.dates.invalid"), funding.getErrors().get(0));
    //Check end date is after start date
    funding = getFundingForm();
    startDate = new Date();
    startDate.setMonth("01");
    startDate.setYear("2015");
    endDate = new Date();
    endDate.setMonth("01");
    endDate.setYear("2014");
    funding.setStartDate(startDate);
    funding.setEndDate(endDate);
    funding = fundingController.postFunding(funding);
    assertNotNull(funding);
    assertNotNull(funding.getErrors());
    assertEquals(1, funding.getErrors().size());
    assertEquals(fundingController.getMessage("fundings.endDate.after"), funding.getErrors().get(0));
}
Also used : FundingForm(org.orcid.pojo.ajaxForm.FundingForm) Date(org.orcid.pojo.ajaxForm.Date) Test(org.junit.Test) BaseControllerTest(org.orcid.frontend.web.util.BaseControllerTest)

Aggregations

FundingForm (org.orcid.pojo.ajaxForm.FundingForm)18 Test (org.junit.Test)12 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)12 Locale (java.util.Locale)11 MockHttpSession (org.springframework.mock.web.MockHttpSession)8 HttpSession (javax.servlet.http.HttpSession)7 FundingTitleForm (org.orcid.pojo.ajaxForm.FundingTitleForm)5 Rollback (org.springframework.test.annotation.Rollback)5 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Funding (org.orcid.jaxb.model.record_v2.Funding)3 Contributor (org.orcid.pojo.ajaxForm.Contributor)3 HashMap (java.util.HashMap)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 Date (org.orcid.pojo.ajaxForm.Date)2 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)2 FundingExternalIdentifierForm (org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm)1 OrgDefinedFundingSubType (org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType)1