Search in sources :

Example 1 with ActivityStreamAuditable

use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.

the class PageController method updatePage.

@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse<PageDto, Map<String, String>>> updatePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PageRequest pageRequest, BindingResult bindingResult) {
    logger.debug("updating page {} with request {}", pageCode, pageRequest);
    if (!this.getAuthorizationService().isAuth(user, pageCode)) {
        throw new ResourcePermissionsException(bindingResult, user.getUsername(), pageCode);
    }
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageValidator().validateBodyCode(pageCode, pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    PagePositionRequest pagePositionRequest = new PagePositionRequest();
    pagePositionRequest.setParentCode(pageRequest.getParentCode());
    pagePositionRequest.setCode(pageCode);
    int position = pageService.getPages(pageCode).size() + 1;
    pagePositionRequest.setPosition(position);
    this.getPageValidator().validateMovePage(pageCode, bindingResult, pagePositionRequest);
    PageDto page = this.getPageService().updatePage(pageCode, pageRequest);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse<>(page, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) HashMap(java.util.HashMap) ResourcePermissionsException(org.entando.entando.web.common.exceptions.ResourcePermissionsException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) ActivityStreamAuditable(org.entando.entando.web.common.annotation.ActivityStreamAuditable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ActivityStreamAuditable

use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.

the class PageController method deletePage.

@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<?>> deletePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode) throws ApsSystemException {
    logger.debug("deleting {}", pageCode);
    if (!this.getAuthorizationService().isAuth(user, pageCode)) {
        return new ResponseEntity<>(new SimpleRestResponse<>(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);
    return new ResponseEntity<>(new SimpleRestResponse<>(payload), 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) DataBinder(org.springframework.validation.DataBinder) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) ActivityStreamAuditable(org.entando.entando.web.common.annotation.ActivityStreamAuditable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ActivityStreamAuditable

use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.

the class PageController method addPage.

@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<PageDto>> 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);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) ActivityStreamAuditable(org.entando.entando.web.common.annotation.ActivityStreamAuditable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ActivityStreamAuditable

use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.

the class PageController method updatePageStatus.

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

Example 5 with ActivityStreamAuditable

use of org.entando.entando.web.common.annotation.ActivityStreamAuditable in project entando-core by entando.

the class PageController method movePage.

@ActivityStreamAuditable
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}/position", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<PageDto>> movePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PagePositionRequest pageRequest, BindingResult bindingResult) {
    logger.debug("changing position for page {} with request {}", pageCode, pageRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageValidator().validateMovePage(pageCode, bindingResult, pageRequest);
    if (!this.getAuthorizationService().isAuth(user, pageCode)) {
        return new ResponseEntity<>(new SimpleRestResponse<>(new PageDto()), HttpStatus.UNAUTHORIZED);
    }
    PageDto page = this.getPageService().movePage(pageCode, pageRequest);
    return new ResponseEntity<>(new SimpleRestResponse<>(page), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) ActivityStreamAuditable(org.entando.entando.web.common.annotation.ActivityStreamAuditable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ActivityStreamAuditable (org.entando.entando.web.common.annotation.ActivityStreamAuditable)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 ResponseEntity (org.springframework.http.ResponseEntity)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)7 HashMap (java.util.HashMap)6 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)5 PageConfigurationDto (org.entando.entando.aps.system.services.page.model.PageConfigurationDto)2 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)1 ResourcePermissionsException (org.entando.entando.web.common.exceptions.ResourcePermissionsException)1 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1 PagePositionRequest (org.entando.entando.web.page.model.PagePositionRequest)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1 BindingResult (org.springframework.validation.BindingResult)1 DataBinder (org.springframework.validation.DataBinder)1