Search in sources :

Example 31 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class PageController method addPage.

@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addPage(@ModelAttribute("user") UserDetails user, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("creating page with request {}", pageRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getPageValidator().validate(pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    PageDto dto = this.getPageService().addPage(pageRequest);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse(dto, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class PageController method deletePage.

@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deletePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode) throws ApsSystemException {
    logger.info("deleting {}", pageCode);
    if (!this.getAuthorizationService().isAuth(user, pageCode)) {
        return new ResponseEntity<>(new RestResponse(new PageDto()), HttpStatus.UNAUTHORIZED);
    }
    DataBinder binder = new DataBinder(pageCode);
    BindingResult bindingResult = binder.getBindingResult();
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getPageValidator().validateOnlinePage(pageCode, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getPageValidator().validateChildren(pageCode, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageService().removePage(pageCode);
    Map<String, String> payload = new HashMap<>();
    payload.put("code", pageCode);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse(payload, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) BindingResult(org.springframework.validation.BindingResult) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) DataBinder(org.springframework.validation.DataBinder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class PageController method updatePageStatus.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/pages/{pageCode}/status", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updatePageStatus(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PageStatusRequest pageStatusRequest, BindingResult bindingResult) {
    logger.debug("changing status for page {} with request {}", pageCode, pageStatusRequest);
    if (!this.getAuthorizationService().isAuth(user, pageCode)) {
        return new ResponseEntity<>(new RestResponse(new PageDto()), HttpStatus.UNAUTHORIZED);
    }
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageValidator().validateReferences(pageCode, pageStatusRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    PageDto page = this.getPageService().updatePageStatus(pageCode, pageStatusRequest.getStatus());
    Map<String, String> metadata = new HashMap<>();
    metadata.put("status", pageStatusRequest.getStatus());
    return new ResponseEntity<>(new RestResponse(page, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class PageModelController method addPageModel.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addPageModel(@Valid @RequestBody PageModelRequest pagemodelRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPagemModelValidator().validate(pagemodelRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    PageModelDto dto = this.getPageModelService().addPageModel(pagemodelRequest);
    return new ResponseEntity<>(new RestResponse(dto), 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) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with ValidationGenericException

use of org.entando.entando.web.common.exceptions.ValidationGenericException in project entando-core by entando.

the class PageModelController method updatePageModel.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{code}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, name = "roleGroup")
public ResponseEntity<RestResponse> updatePageModel(@PathVariable String code, @Valid @RequestBody PageModelRequest pageModelRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPagemModelValidator().validateBodyName(code, pageModelRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    PageModelDto pageModel = this.getPageModelService().updatePageModel(pageModelRequest);
    return new ResponseEntity<>(new RestResponse(pageModel), 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) PageModelDto(org.entando.entando.aps.system.services.pagemodel.model.PageModelDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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