Search in sources :

Example 61 with RestResponse

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

the class LanguageController method updateLanguage.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{code}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateLanguage(@PathVariable String code, @Valid @RequestBody LanguageRequest languageRequest, BindingResult bindingResult) {
    logger.trace("loading language {}", code);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    LanguageDto result = this.getLanguageService().updateLanguage(code, languageRequest.getStatus());
    return new ResponseEntity<>(new RestResponse(result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with RestResponse

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

the class LanguageController method getLanguages.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getLanguages(RestListRequest requestList) {
    logger.trace("loading languages list");
    this.getLanguageValidator().validateRestListRequest(requestList);
    PagedMetadata<LanguageDto> result = this.getLanguageService().getLanguages(requestList);
    this.getLanguageValidator().validateRestListResult(requestList, result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 with RestResponse

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

the class PageConfigurationController method updatePageWidget.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/pages/{pageCode}/widgets/{frameId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updatePageWidget(@PathVariable String pageCode, @PathVariable int frameId, @Valid @RequestBody WidgetConfigurationRequest widget, BindingResult bindingResult) {
    logger.trace("updating widget configuration in page {} and frame {}", pageCode, frameId);
    WidgetConfigurationDto widgetConfiguration = this.getPageService().updateWidgetConfiguration(pageCode, frameId, widget);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("status", IPageService.STATUS_DRAFT);
    return new ResponseEntity<>(new RestResponse(widgetConfiguration, null, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) 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 64 with RestResponse

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

the class PageConfigurationController method getPageWidgets.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/pages/{pageCode}/widgets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getPageWidgets(@PathVariable String pageCode, @RequestParam(value = "status", required = false, defaultValue = IPageService.STATUS_DRAFT) String status) {
    logger.trace("requested {} widgets detail", pageCode);
    PageConfigurationDto pageConfiguration = this.getPageService().getPageConfiguration(pageCode, status);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("status", status);
    return new ResponseEntity<>(new RestResponse(pageConfiguration.getWidgets(), null, metadata), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with RestResponse

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

the class PageController method movePage.

@RestAccessControl(permission = Permission.MANAGE_PAGES)
@RequestMapping(value = "/pages/{pageCode}/position", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> movePage(@ModelAttribute("user") UserDetails user, @PathVariable String pageCode, @Valid @RequestBody PagePositionRequest pageRequest, BindingResult bindingResult) {
    logger.debug("changing position for page {} with request {}", pageCode, pageRequest);
    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().validateChangePositionRequest(pageCode, pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageValidator().validateGroups(pageCode, pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getPageValidator().validatePagesStatus(pageCode, pageRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    PageDto page = this.getPageService().movePage(pageCode, pageRequest);
    Map<String, String> metadata = new HashMap<>();
    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)

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