Search in sources :

Example 1 with SettingsValidationException

use of net.nemerosa.ontrack.model.settings.SettingsValidationException in project ontrack by nemerosa.

the class SettingsController method updateSettings.

/**
 * Security
 */
@RequestMapping(value = "/{type:.*}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.ACCEPTED)
public <T> Ack updateSettings(@PathVariable String type, @RequestBody JsonNode settingsNode) {
    securityService.checkGlobalFunction(GlobalSettings.class);
    // Gets the settings manager by type
    @SuppressWarnings("unchecked") SettingsManager<T> settingsManager = (SettingsManager<T>) settingsManagers.stream().filter(candidate -> StringUtils.equals(type, getSettingsManagerName(candidate))).findFirst().orElseThrow(() -> new SettingsManagerNotFoundException(type));
    // Parsing
    T settings;
    try {
        settings = objectMapper.treeToValue(settingsNode, settingsManager.getSettingsClass());
    } catch (JsonProcessingException e) {
        throw new SettingsValidationException(e);
    }
    // Saves the settings
    settingsManager.saveSettings(settings);
    // OK
    return Ack.OK;
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) ObjectMapperFactory(net.nemerosa.ontrack.json.ObjectMapperFactory) AbstractResourceController(net.nemerosa.ontrack.ui.controller.AbstractResourceController) DescribedForm(net.nemerosa.ontrack.model.form.DescribedForm) MvcUriComponentsBuilder.on(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.on) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SettingsManagerNotFoundException(net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException) Resource(net.nemerosa.ontrack.ui.resource.Resource) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) List(java.util.List) Resources(net.nemerosa.ontrack.ui.resource.Resources) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) SettingsValidationException(net.nemerosa.ontrack.model.settings.SettingsValidationException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SettingsManager(net.nemerosa.ontrack.model.settings.SettingsManager) SettingsManagerNotFoundException(net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException) SettingsManager(net.nemerosa.ontrack.model.settings.SettingsManager) SettingsValidationException(net.nemerosa.ontrack.model.settings.SettingsValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ObjectMapperFactory (net.nemerosa.ontrack.json.ObjectMapperFactory)1 Ack (net.nemerosa.ontrack.model.Ack)1 DescribedForm (net.nemerosa.ontrack.model.form.DescribedForm)1 GlobalSettings (net.nemerosa.ontrack.model.security.GlobalSettings)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 SettingsManager (net.nemerosa.ontrack.model.settings.SettingsManager)1 SettingsManagerNotFoundException (net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException)1 SettingsValidationException (net.nemerosa.ontrack.model.settings.SettingsValidationException)1 AbstractResourceController (net.nemerosa.ontrack.ui.controller.AbstractResourceController)1 Resource (net.nemerosa.ontrack.ui.resource.Resource)1 Resources (net.nemerosa.ontrack.ui.resource.Resources)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 HttpStatus (org.springframework.http.HttpStatus)1