Search in sources :

Example 81 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility 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);
    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.v3.dev1.record.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 Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class WorkspaceController method setKeywordsFormJson.

@RequestMapping(value = "/my-orcid/keywordsForms.json", method = RequestMethod.POST)
@ResponseBody
public KeywordsForm setKeywordsFormJson(HttpServletRequest request, @RequestBody KeywordsForm kf) throws NoSuchRequestHandlingMethodException {
    kf.setErrors(new ArrayList<String>());
    if (kf != null) {
        Iterator<KeywordForm> it = kf.getKeywords().iterator();
        while (it.hasNext()) {
            KeywordForm k = it.next();
            if (!PojoUtil.isEmpty(k.getContent())) {
                if (k.getContent().length() > SiteConstants.KEYWORD_MAX_LENGTH) {
                    k.setContent(k.getContent().substring(0, SiteConstants.KEYWORD_MAX_LENGTH));
                }
            } else {
                it.remove();
            }
            // Validate visibility is not null
            validateVisibility(k);
            copyErrors(k, kf);
            copyErrors(k.getVisibility(), kf);
        }
        if (kf.getErrors().size() > 0) {
            return kf;
        }
        Keywords updatedKeywords = kf.toKeywords();
        profileKeywordManager.updateKeywords(getCurrentUserOrcid(), updatedKeywords);
    }
    return kf;
}
Also used : KeywordForm(org.orcid.pojo.ajaxForm.KeywordForm) Keywords(org.orcid.jaxb.model.v3.dev1.record.Keywords) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 83 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class WorkspaceController method setWebsitesFormJson.

/**
 * Retrieve all external identifiers as a json string
 */
@RequestMapping(value = "/my-orcid/websitesForms.json", method = RequestMethod.POST)
@ResponseBody
public WebsitesForm setWebsitesFormJson(HttpServletRequest request, @RequestBody WebsitesForm ws) throws NoSuchRequestHandlingMethodException {
    ws.setErrors(new ArrayList<String>());
    if (ws != null) {
        Set<String> existingUrls = new HashSet<String>();
        for (WebsiteForm w : ws.getWebsites()) {
            // Clean old errors
            w.setErrors(new ArrayList<String>());
            // Validate url
            validateUrl(w.getUrl());
            copyErrors(w.getUrl(), w);
            // Validate url name
            if (isLongerThan(w.getUrlName(), SiteConstants.URL_NAME_MAX_LENGTH)) {
                w.getErrors().add(getMessage("manualWork.length_less_X", SiteConstants.URL_NAME_MAX_LENGTH));
            }
            // Check there are no duplicates
            if (existingUrls.contains(w.getUrl().getValue())) {
                w.getErrors().add(getMessage("researcher_url.error.duplicated", w.getUrl()));
            } else {
                existingUrls.add(w.getUrl().getValue());
            }
            // Validate visibility is not null
            validateVisibility(w);
            copyErrors(w, ws);
            copyErrors(w.getUrl(), ws);
            copyErrors(w.getVisibility(), ws);
        }
        if (ws.getErrors().size() > 0) {
            return ws;
        }
        ResearcherUrls rUrls = ws.toResearcherUrls();
        researcherUrlManager.updateResearcherUrls(getCurrentUserOrcid(), rUrls);
    }
    return ws;
}
Also used : WebsiteForm(org.orcid.pojo.ajaxForm.WebsiteForm) ResearcherUrls(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 84 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class WorkspaceController method updateExternalIdentifierJson.

/**
 * Update the visibility of the given external identifeirs
 */
@RequestMapping(value = "/my-orcid/externalIdentifiers.json", method = RequestMethod.POST)
@ResponseBody
public ExternalIdentifiersForm updateExternalIdentifierJson(HttpServletRequest request, @RequestBody ExternalIdentifiersForm externalIdentifiersForm) {
    externalIdentifiersForm.setErrors(new ArrayList<String>());
    // Validate visibility is not null
    if (externalIdentifiersForm != null && externalIdentifiersForm.getExternalIdentifiers() != null) {
        for (ExternalIdentifierForm extId : externalIdentifiersForm.getExternalIdentifiers()) {
            // Validate visibility is not null
            validateVisibility(extId);
            copyErrors(extId, externalIdentifiersForm);
        }
    }
    if (!externalIdentifiersForm.getErrors().isEmpty()) {
        return externalIdentifiersForm;
    }
    PersonExternalIdentifiers externalIdentifiers = externalIdentifiersForm.toPersonExternalIdentifiers();
    externalIdentifiers = externalIdentifierManager.updateExternalIdentifiers(getCurrentUserOrcid(), externalIdentifiers);
    return externalIdentifiersForm;
}
Also used : PersonExternalIdentifiers(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers) ExternalIdentifierForm(org.orcid.pojo.ajaxForm.ExternalIdentifierForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 85 with Visibility

use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.

the class WorkspaceController method getWebsitesFormJson.

/**
 * Retrieve all external identifiers as a json string
 */
@RequestMapping(value = "/my-orcid/websitesForms.json", method = RequestMethod.GET)
@ResponseBody
public WebsitesForm getWebsitesFormJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
    ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(getCurrentUserOrcid());
    WebsitesForm form = WebsitesForm.valueOf(rUrls);
    // Set the default visibility
    ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
    if (profile != null && profile.getActivitiesVisibilityDefault() != null) {
        form.setVisibility(Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
    }
    return form;
}
Also used : ResearcherUrls(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls) WebsitesForm(org.orcid.pojo.ajaxForm.WebsitesForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)44 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 Test (org.junit.Test)17 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Url (org.orcid.jaxb.model.v3.dev1.common.Url)11 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)11 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 HashMap (java.util.HashMap)10 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Name (org.orcid.jaxb.model.v3.dev1.record.Name)7 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)6 Date (java.util.Date)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5