Search in sources :

Example 1 with AffiliationForm

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

the class OrcidInfo method getAffiliationsJson.

@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/affiliations.json")
@ResponseBody
public List<AffiliationForm> getAffiliationsJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "affiliationIds") String workIdsStr) {
    List<AffiliationForm> affs = new ArrayList<AffiliationForm>();
    Map<Long, Affiliation> affMap = affiliationMap(orcid, profileEntManager.getLastModified(orcid));
    String[] affIds = workIdsStr.split(",");
    for (String id : affIds) {
        Affiliation aff = affMap.get(Long.valueOf(id));
        validateVisibility(aff.getVisibility());
        AffiliationForm form = AffiliationForm.valueOf(aff);
        form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, aff.getOrganization().getAddress().getCountry().name())));
        affs.add(form);
    }
    return affs;
}
Also used : ArrayList(java.util.ArrayList) AffiliationForm(org.orcid.pojo.ajaxForm.AffiliationForm) Affiliation(org.orcid.jaxb.model.record_v2.Affiliation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with AffiliationForm

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

the class AffiliationsController method getAffiliationJson.

/**
     * List affiliations associated with a profile
     * */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/affiliations.json", method = RequestMethod.GET)
@ResponseBody
public List<AffiliationForm> getAffiliationJson(HttpServletRequest request, @RequestParam(value = "affiliationIds") String affiliationIdsStr) {
    List<AffiliationForm> affiliationList = new ArrayList<>();
    AffiliationForm affiliation = null;
    String[] affiliationIds = affiliationIdsStr.split(",");
    if (affiliationIds != null) {
        HashMap<String, AffiliationForm> affiliationsMap = (HashMap<String, AffiliationForm>) request.getSession().getAttribute(AFFILIATIONS_MAP);
        // this should never happen, but just in case.
        if (affiliationsMap == null) {
            createAffiliationsIdList(request);
            affiliationsMap = (HashMap<String, AffiliationForm>) request.getSession().getAttribute(AFFILIATIONS_MAP);
        }
        for (String affiliationId : affiliationIds) {
            affiliation = affiliationsMap.get(affiliationId);
            if (affiliation.getStartDate() == null) {
                initializeStartDate(affiliation);
            } else {
                if (affiliation.getStartDate().getDay() == null) {
                    affiliation.getStartDate().setDay(new String());
                }
                if (affiliation.getStartDate().getMonth() == null) {
                    affiliation.getStartDate().setMonth(new String());
                }
                if (affiliation.getStartDate().getYear() == null) {
                    affiliation.getStartDate().setYear(new String());
                }
            }
            if (affiliation.getEndDate() == null) {
                initializeEndDate(affiliation);
            } else {
                if (affiliation.getEndDate().getDay() == null) {
                    affiliation.getEndDate().setDay(new String());
                }
                if (affiliation.getEndDate().getMonth() == null) {
                    affiliation.getEndDate().setMonth(new String());
                }
                if (affiliation.getEndDate().getYear() == null) {
                    affiliation.getEndDate().setYear(new String());
                }
            }
            affiliationList.add(affiliation);
        }
    }
    return affiliationList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AffiliationForm(org.orcid.pojo.ajaxForm.AffiliationForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with AffiliationForm

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

the class AffiliationsController method getAffiliation.

/**
     * Returns a blank affiliation form
     * */
@RequestMapping(value = "/affiliation.json", method = RequestMethod.GET)
@ResponseBody
public AffiliationForm getAffiliation(HttpServletRequest request) {
    AffiliationForm affiliationForm = new AffiliationForm();
    ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
    Visibility v = Visibility.valueOf(profile.getActivitiesVisibilityDefault() == null ? org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.FUNDING_DEFAULT.getVisibility().value()) : profile.getActivitiesVisibilityDefault());
    affiliationForm.setVisibility(v);
    Text affiliationName = new Text();
    affiliationForm.setAffiliationName(affiliationName);
    affiliationName.setRequired(true);
    Text city = new Text();
    affiliationForm.setCity(city);
    Text region = new Text();
    affiliationForm.setRegion(region);
    Text country = new Text();
    affiliationForm.setCountry(country);
    country.setValue("");
    country.setRequired(true);
    Text department = new Text();
    affiliationForm.setDepartmentName(department);
    Text roleTitle = new Text();
    affiliationForm.setRoleTitle(roleTitle);
    Text affiliationType = new Text();
    affiliationForm.setAffiliationType(affiliationType);
    affiliationType.setValue("");
    Date startDate = new Date();
    affiliationForm.setStartDate(startDate);
    startDate.setDay("");
    startDate.setMonth("");
    startDate.setYear("");
    Date endDate = new Date();
    affiliationForm.setEndDate(endDate);
    endDate.setDay("");
    endDate.setMonth("");
    endDate.setYear("");
    affiliationForm.setOrgDisambiguatedId(new Text());
    return affiliationForm;
}
Also used : AffiliationForm(org.orcid.pojo.ajaxForm.AffiliationForm) Visibility(org.orcid.pojo.ajaxForm.Visibility) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(org.orcid.pojo.ajaxForm.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with AffiliationForm

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

the class AffiliationsController method createAffiliationsIdList.

/**
     * Create an affiliation id list and sorts a map associated with the list in
     * in the session
     * 
     */
private List<String> createAffiliationsIdList(HttpServletRequest request) {
    List<Affiliation> affiliationsList = affiliationsManager.getAffiliations(getCurrentUserOrcid());
    HashMap<String, AffiliationForm> affiliationsMap = new HashMap<>();
    List<String> affiliationIds = new ArrayList<String>();
    if (affiliationsList != null) {
        for (Affiliation affiliation : affiliationsList) {
            AffiliationForm form = AffiliationForm.valueOf(affiliation);
            form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, form.getCountry().getValue())));
            affiliationsMap.put(form.getPutCode().getValue(), form);
            affiliationIds.add(form.getPutCode().getValue());
        }
        request.getSession().setAttribute(AFFILIATIONS_MAP, affiliationsMap);
    }
    return affiliationIds;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AffiliationForm(org.orcid.pojo.ajaxForm.AffiliationForm) Affiliation(org.orcid.jaxb.model.record_v2.Affiliation)

Aggregations

AffiliationForm (org.orcid.pojo.ajaxForm.AffiliationForm)4 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 HashMap (java.util.HashMap)2 Affiliation (org.orcid.jaxb.model.record_v2.Affiliation)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 Date (org.orcid.pojo.ajaxForm.Date)1 Text (org.orcid.pojo.ajaxForm.Text)1 Visibility (org.orcid.pojo.ajaxForm.Visibility)1