use of net.nemerosa.ontrack.model.settings.SettingsManager 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;
}
Aggregations