use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class WidgetController method updateWidget.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets/{widgetCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, name = "widget")
public ResponseEntity<RestResponse> updateWidget(@PathVariable String widgetCode, @Valid @RequestBody WidgetRequest widgetRequest, BindingResult bindingResult) {
logger.trace("update widget. Code: {} and body {}: ", widgetCode, widgetRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.widgetValidator.validateWidgetCode(widgetCode, widgetRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
WidgetDto widgetDto = this.widgetService.updateWidget(widgetCode, widgetRequest);
return new ResponseEntity<>(new RestResponse(widgetDto), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class WidgetController method addWidget.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/widgets", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, name = "widget")
public ResponseEntity<RestResponse> addWidget(@Valid @RequestBody WidgetRequest widgetRequest, BindingResult bindingResult) throws ApsSystemException {
logger.trace("add widget. body {}: ", widgetRequest);
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
this.widgetValidator.validate(widgetRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
WidgetDto widgetDto = this.widgetService.addWidget(widgetRequest);
return new ResponseEntity<>(new RestResponse(widgetDto), HttpStatus.OK);
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class LabelService method addLabelGroup.
@Override
public LabelDto addLabelGroup(LabelDto labelRequest) {
try {
BeanPropertyBindingResult validationResult = this.validateAddLabelGroup(labelRequest);
if (validationResult.hasErrors()) {
throw new ValidationGenericException(validationResult);
}
String code = labelRequest.getKey();
ApsProperties languages = new ApsProperties();
languages.putAll(labelRequest.getTitles());
this.getI18nManager().addLabelGroup(code, languages);
return labelRequest;
} catch (ApsSystemException t) {
logger.error("error in add label group with code {}", labelRequest.getKey(), t);
throw new RestServerError("error in add label group", t);
}
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class LabelService method updateLabelGroup.
@Override
public LabelDto updateLabelGroup(LabelDto labelRequest) {
try {
String code = labelRequest.getKey();
ApsProperties labelGroup = this.getI18nManager().getLabelGroup(code);
if (null == labelGroup) {
logger.warn("no label found with key {}", code);
throw new RestRourceNotFoundException(LabelValidator.ERRCODE_LABELGROUP_NOT_FOUND, "label", code);
}
BeanPropertyBindingResult validationResult = this.validateUpdateLabelGroup(labelRequest);
if (validationResult.hasErrors()) {
throw new ValidationGenericException(validationResult);
}
ApsProperties languages = new ApsProperties();
languages.putAll(labelRequest.getTitles());
this.getI18nManager().updateLabelGroup(code, languages);
return labelRequest;
} catch (ApsSystemException t) {
logger.error("error in update label group with code {}", labelRequest.getKey(), t);
throw new RestServerError("error in update label group", t);
}
}
use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.
the class WidgetService method removeWidget.
@Override
public void removeWidget(String widgetCode) {
try {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
BeanPropertyBindingResult validationResult = checkWidgetForDelete(type);
if (validationResult.hasErrors()) {
throw new ValidationGenericException(validationResult);
}
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetCode);
for (String fragmentCode : fragmentCodes) {
this.getGuiFragmentManager().deleteGuiFragment(fragmentCode);
}
this.getWidgetManager().deleteWidgetType(widgetCode);
} catch (ApsSystemException e) {
logger.error("Failed to remove widget type for request {} ", widgetCode);
throw new RestServerError("failed to update widget type by code ", e);
}
}
Aggregations