Search in sources :

Example 16 with ValidationGenericException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ValidationGenericException

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with ValidationGenericException

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);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 19 with ValidationGenericException

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);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 20 with ValidationGenericException

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);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Aggregations

ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)44 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)34 RestResponse (org.entando.entando.web.common.model.RestResponse)34 ResponseEntity (org.springframework.http.ResponseEntity)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)34 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)12 ArrayList (java.util.ArrayList)9 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)9 HashMap (java.util.HashMap)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4 Category (com.agiletec.aps.system.services.category.Category)3 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)3 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)3 GuiFragmentDto (org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto)3 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2