Search in sources :

Example 1 with FundingExternalIdentifierForm

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

the class FundingsController method removeEmptyExternalIds.

private void removeEmptyExternalIds(FundingForm funding) {
    List<FundingExternalIdentifierForm> extIds = funding.getExternalIdentifiers();
    List<FundingExternalIdentifierForm> updatedExtIds = new ArrayList<FundingExternalIdentifierForm>();
    if (extIds != null) {
        // For all external identifiers
        for (FundingExternalIdentifierForm extId : extIds) {
            // Keep only the ones that contains a value or url
            if (!PojoUtil.isEmpty(extId.getValue()) || !PojoUtil.isEmpty(extId.getUrl())) {
                updatedExtIds.add(extId);
            }
        }
    }
    funding.setExternalIdentifiers(updatedExtIds);
}
Also used : ArrayList(java.util.ArrayList) FundingExternalIdentifierForm(org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm)

Example 2 with FundingExternalIdentifierForm

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

the class FundingsController method postFunding.

/**
     * Persist a funding object on database
     * */
@RequestMapping(value = "/funding.json", method = RequestMethod.POST)
@ResponseBody
public FundingForm postFunding(@RequestBody FundingForm funding) throws Exception {
    // Reset errors
    funding.setErrors(new ArrayList<String>());
    // Remove empty external identifiers
    removeEmptyExternalIds(funding);
    validateName(funding);
    validateAmount(funding);
    validateCurrency(funding);
    validateTitle(funding);
    validateTranslatedTitle(funding);
    validateDescription(funding);
    validateUrl(funding);
    validateDates(funding);
    validateExternalIdentifiers(funding);
    validateType(funding);
    validateOrganizationDefinedType(funding);
    validateCity(funding);
    validateRegion(funding);
    validateCountry(funding);
    copyErrors(funding.getCity(), funding);
    copyErrors(funding.getRegion(), funding);
    copyErrors(funding.getCountry(), funding);
    copyErrors(funding.getFundingName(), funding);
    copyErrors(funding.getAmount(), funding);
    copyErrors(funding.getCurrencyCode(), funding);
    copyErrors(funding.getFundingTitle().getTitle(), funding);
    copyErrors(funding.getDescription(), funding);
    copyErrors(funding.getUrl(), funding);
    copyErrors(funding.getFundingType(), funding);
    if (funding.getStartDate() != null)
        copyErrors(funding.getStartDate(), funding);
    if (funding.getEndDate() != null)
        copyErrors(funding.getEndDate(), funding);
    if (funding.getFundingTitle().getTranslatedTitle() != null)
        copyErrors(funding.getFundingTitle().getTranslatedTitle(), funding);
    if (funding.getOrganizationDefinedFundingSubType() != null)
        copyErrors(funding.getOrganizationDefinedFundingSubType().getSubtype(), funding);
    for (FundingExternalIdentifierForm extId : funding.getExternalIdentifiers()) {
        if (extId.getType() != null)
            copyErrors(extId.getType(), funding);
        if (extId.getUrl() != null)
            copyErrors(extId.getUrl(), funding);
        if (extId.getValue() != null)
            copyErrors(extId.getValue(), funding);
    }
    // If there are no errors, persist to DB
    if (funding.getErrors().isEmpty()) {
        if (PojoUtil.isEmpty(funding.getPutCode())) {
            addFunding(funding);
        } else {
            editFunding(funding);
        }
    }
    return funding;
}
Also used : FundingExternalIdentifierForm(org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with FundingExternalIdentifierForm

use of org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm 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)

Aggregations

FundingExternalIdentifierForm (org.orcid.pojo.ajaxForm.FundingExternalIdentifierForm)3 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 Contributor (org.orcid.pojo.ajaxForm.Contributor)1 Date (org.orcid.pojo.ajaxForm.Date)1 FundingForm (org.orcid.pojo.ajaxForm.FundingForm)1 FundingTitleForm (org.orcid.pojo.ajaxForm.FundingTitleForm)1 OrgDefinedFundingSubType (org.orcid.pojo.ajaxForm.OrgDefinedFundingSubType)1 Text (org.orcid.pojo.ajaxForm.Text)1 TranslatedTitleForm (org.orcid.pojo.ajaxForm.TranslatedTitleForm)1 Visibility (org.orcid.pojo.ajaxForm.Visibility)1