Search in sources :

Example 1 with AddressForm

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

the class ManageProfileController method setProfileCountryJson.

@RequestMapping(value = "/countryForm.json", method = RequestMethod.POST)
@ResponseBody
public AddressesForm setProfileCountryJson(HttpServletRequest request, @RequestBody AddressesForm addressesForm) throws NoSuchRequestHandlingMethodException {
    addressesForm.setErrors(new ArrayList<String>());
    Map<String, String> countries = retrieveIsoCountries();
    if (addressesForm != null) {
        if (addressesForm.getAddresses() != null) {
            for (AddressForm form : addressesForm.getAddresses()) {
                if (form.getIso2Country() == null || form.getIso2Country().getValue() == null) {
                    form.getErrors().add(getMessage("common.invalid_country"));
                } else {
                    form.setCountryName(countries.get(form.getIso2Country().getValue().name()));
                }
                // Validate visibility is not null
                validateVisibility(form);
                copyErrors(form, addressesForm);
                copyErrors(form.getVisibility(), addressesForm);
            }
        }
        if (!addressesForm.getErrors().isEmpty()) {
            return addressesForm;
        }
        Addresses addresses = addressesForm.toAddresses();
        addressManager.updateAddresses(getCurrentUserOrcid(), addresses);
    }
    return addressesForm;
}
Also used : Addresses(org.orcid.jaxb.model.v3.dev1.record.Addresses) AddressForm(org.orcid.pojo.ajaxForm.AddressForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with AddressForm

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

the class ManageProfileController method getProfileCountryJson.

@RequestMapping(value = "/countryForm.json", method = RequestMethod.GET)
@ResponseBody
public AddressesForm getProfileCountryJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
    Addresses addresses = addressManager.getAddresses(getCurrentUserOrcid());
    AddressesForm form = AddressesForm.valueOf(addresses);
    // Set country name
    if (form != null && form.getAddresses() != null) {
        Map<String, String> countries = retrieveIsoCountries();
        for (AddressForm addressForm : form.getAddresses()) {
            addressForm.setCountryName(countries.get(addressForm.getIso2Country().getValue().name()));
        }
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
    // Set the default visibility
    if (profile.getActivitiesVisibilityDefault() != null) {
        form.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
    }
    // Return an empty country in case we dont have any
    if (form.getAddresses() == null) {
        form.setAddresses(new ArrayList<AddressForm>());
    }
    if (form.getAddresses().isEmpty()) {
        AddressForm address = new AddressForm();
        address.setDisplayIndex(1L);
        address.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
        form.getAddresses().add(address);
    }
    return form;
}
Also used : Addresses(org.orcid.jaxb.model.v3.dev1.record.Addresses) AddressesForm(org.orcid.pojo.ajaxForm.AddressesForm) AddressForm(org.orcid.pojo.ajaxForm.AddressForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)2 AddressForm (org.orcid.pojo.ajaxForm.AddressForm)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 AddressesForm (org.orcid.pojo.ajaxForm.AddressesForm)1