Search in sources :

Example 6 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class RestExceptionHandler method processValidationError.

@ExceptionHandler(value = ValidationGenericException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public RestResponse processValidationError(ValidationGenericException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    BindingResult result = ex.getBindingResult();
    RestResponse response = processAllErrors(result);
    return response;
}
Also used : BindingResult(org.springframework.validation.BindingResult) RestResponse(org.entando.entando.web.common.model.RestResponse) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class RestExceptionHandler method processEntandoTokenException.

@ExceptionHandler(value = EntandoTokenException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public RestResponse processEntandoTokenException(EntandoAuthorizationException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    RestResponse response = new RestResponse();
    RestError error = new RestError(RestErrorCodes.UNAUTHORIZED, this.resolveLocalizedErrorMessage("UNAUTHORIZED", new Object[] { ex.getUsername(), ex.getRequestURI(), ex.getMethod() }));
    List<RestError> errors = new ArrayList<>();
    errors.add(error);
    response.setErrors(errors);
    return response;
}
Also used : RestResponse(org.entando.entando.web.common.model.RestResponse) RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class DatabaseController method deleteDumpReport.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/report/{reportCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteDumpReport(@PathVariable String reportCode) {
    logger.debug("Deleting dump report -> code {}", reportCode);
    this.getDatabaseService().deleteDumpReport(reportCode);
    logger.debug("Deleted dump report -> {}", reportCode);
    Map<String, String> response = new HashMap<>();
    response.put("code", reportCode);
    return new ResponseEntity<>(new RestResponse(response), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class DatabaseController method getStatus.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getStatus() {
    Integer status = this.getDatabaseService().getStatus();
    Map<String, String> response = new HashMap<>();
    response.put("status", String.valueOf(status));
    logger.debug("Required database status -> {}", status);
    return new ResponseEntity<>(new RestResponse(response), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with RestResponse

use of org.entando.entando.web.common.model.RestResponse in project entando-core by entando.

the class DatabaseController method getDumpReports.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getDumpReports(@Valid RestListRequest requestList) {
    this.getDatabaseValidator().validateRestListRequest(requestList);
    PagedMetadata<ShortDumpReportDto> result = this.getDatabaseService().getShortDumpReportDtos(requestList);
    this.getDatabaseValidator().validateRestListResult(requestList, result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), new ArrayList<>(), result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) ShortDumpReportDto(org.entando.entando.aps.system.services.database.model.ShortDumpReportDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RestResponse (org.entando.entando.web.common.model.RestResponse)95 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)86 ResponseEntity (org.springframework.http.ResponseEntity)86 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)86 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)34 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)18 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)8 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)7 BindingResult (org.springframework.validation.BindingResult)7 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)6 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)4 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)4 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)4 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4