Search in sources :

Example 56 with RestResponse

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

the class GroupController method addGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addGroup(@Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getGroupValidator().validate(groupRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    GroupDto dto = this.getGroupService().addGroup(groupRequest);
    return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) 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 57 with RestResponse

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

the class GroupController method deleteGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{groupName}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteGroup(@PathVariable String groupName) throws ApsSystemException {
    logger.info("deleting {}", groupName);
    this.getGroupService().removeGroup(groupName);
    Map<String, String> result = new HashMap<>();
    result.put("code", groupName);
    return new ResponseEntity<>(new RestResponse(result), 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 58 with RestResponse

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

the class GuiFragmentController method updateGuiFragment.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{fragmentCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGuiFragment(@PathVariable String fragmentCode, @Valid @RequestBody GuiFragmentRequestBody guiFragmentRequest, BindingResult bindingResult) {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    int result = this.getGuiFragmentValidator().validateBody(fragmentCode, guiFragmentRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        if (404 == result) {
            throw new RestRourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", fragmentCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    GuiFragmentDto fragment = this.getGuiFragmentService().updateGuiFragment(guiFragmentRequest);
    return new ResponseEntity<>(new RestResponse(fragment), HttpStatus.OK);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) GuiFragmentDto(org.entando.entando.aps.system.services.guifragment.model.GuiFragmentDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 59 with RestResponse

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

the class LabelController method deleteLabelGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{labelCode}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteLabelGroup(@PathVariable String labelCode) throws ApsSystemException {
    logger.debug("deleting label {}", labelCode);
    this.getLabelService().removeLabelGroup(labelCode);
    Map<String, String> result = new HashMap<>();
    result.put("key", labelCode);
    return new ResponseEntity<>(new RestResponse(result), 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 60 with RestResponse

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

the class LabelController method getLables.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getLables(RestListRequest requestList) {
    logger.debug("loading labels");
    this.getLabelValidator().validateRestListRequest(requestList);
    PagedMetadata<LabelDto> result = this.getLabelService().getLabelGroups(requestList);
    this.getLabelValidator().validateRestListResult(requestList, result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) 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