use of com.serotonin.m2m2.vo.exception.ValidationException in project ma-core-public by infiniteautomation.
the class Validatable method ensureValid.
/**
* Validates the object and throws a ValidationException if it is not valid
*
* @throws ValidationException
*/
public default void ensureValid() throws ValidationException {
ProcessResult response = new ProcessResult();
this.validate(response);
if (response.getHasMessages()) {
throw new ValidationException(response);
}
}
use of com.serotonin.m2m2.vo.exception.ValidationException in project ma-modules-public by infiniteautomation.
the class SystemSettingsRestController method update.
@ApiOperation(value = "Update an existing System Setting", notes = "If no type is provided, String is assumed")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json" }, produces = { "application/json" }, value = "/{key}")
public ResponseEntity<Object> update(@PathVariable String key, @ApiParam(value = "Updated model", required = true) @RequestBody(required = true) Object model, @ApiParam(value = "Setting Type", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "STRING") SystemSettingTypeEnum type, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<Object> result = new RestProcessResult<Object>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
Map<String, Object> settings = new HashMap<String, Object>();
settings.put(key, model);
ProcessResult response = new ProcessResult();
this.dao.validate(settings, response);
if (response.getHasMessages()) {
throw new ValidationException(response);
}
switch(type) {
case BOOLEAN:
dao.setBooleanValue(key, (Boolean) model);
break;
case INTEGER:
dao.setIntValue(key, (Integer) model);
break;
case JSON:
try {
dao.setJsonObjectValue(key, model);
} catch (Exception e) {
result.addRestMessage(this.getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
break;
case STRING:
default:
// Potentially convert value from its code
Integer code = this.dao.convertToValueFromCode(key, (String) model);
if (code != null)
dao.setIntValue(key, code);
else
dao.setValue(key, (String) model);
break;
}
// J.W. WTF is this for?
// Put a link to the updated data in the header
URI location = builder.path("/v1/system-settings/{key}").buildAndExpand(key).toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
return result.createResponseEntity(model);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.exception.ValidationException in project ma-modules-public by infiniteautomation.
the class SystemSettingsRestController method updateMany.
@ApiOperation(value = "Update Many System Settings", notes = "Admin Privs Required")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" })
public ResponseEntity<Map<String, Object>> updateMany(@ApiParam(value = "Updated settings", required = true) @RequestBody(required = true) Map<String, Object> settings, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<Map<String, Object>> result = new RestProcessResult<Map<String, Object>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
ProcessResult response = new ProcessResult();
// Convert incoming ExportCodes to int values
settings = this.dao.convertCodesToValues(settings);
this.dao.validate(settings, response);
if (response.getHasMessages()) {
throw new ValidationException(response);
}
this.dao.updateSettings(settings);
// J.W. WTF is this for?
// Put a link to the updated data in the header
URI location = builder.path("/v1/system-settings").buildAndExpand().toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
return result.createResponseEntity(settings);
}
return result.createResponseEntity();
}
Aggregations