Search in sources :

Example 1 with WebsiteForm

use of org.orcid.pojo.ajaxForm.WebsiteForm 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>());
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    Visibility defaultVisibility = Visibility.valueOf(profile.getActivitiesVisibilityDefault());
    if (ws != null) {
        Set<String> existingUrls = new HashSet<String>();
        for (WebsiteForm w : ws.getWebsites()) {
            //Clean old errors
            w.setErrors(new ArrayList<String>());
            //Validate
            if (!validateUrl(w.getUrl())) {
                w.getErrors().add(getMessage("common.invalid_url"));
            }
            if (isLongerThan(w.getUrlName(), SiteConstants.URL_MAX_LENGTH)) {
                w.getErrors().add(getMessage("manualWork.length_less_X"));
            }
            //Check there are no duplicates
            if (existingUrls.contains(w.getUrl())) {
                w.getErrors().add(getMessage("researcher_url.error.duplicated", w.getUrl()));
            } else {
                existingUrls.add(w.getUrl());
            }
            //Set default visibility in case it is null
            if (w.getVisibility() == null || w.getVisibility().getVisibility() == null) {
                w.setVisibility(defaultVisibility);
            }
            copyErrors(w, 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.record_v2.ResearcherUrls) Visibility(org.orcid.pojo.ajaxForm.Visibility) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

HashSet (java.util.HashSet)1 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)1 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 Visibility (org.orcid.pojo.ajaxForm.Visibility)1 WebsiteForm (org.orcid.pojo.ajaxForm.WebsiteForm)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1