Search in sources :

Example 1 with RoleDto

use of org.entando.entando.aps.system.services.role.model.RoleDto in project entando-core by entando.

the class RoleService method getRoles.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<RoleDto> getRoles(RestListRequest restRequest) {
    List<Role> roles = this.getRoleManager().getRoles();
    roles = sortRoleList(restRequest, roles);
    if (null != restRequest.getFilters()) {
        for (Filter f : restRequest.getFilters()) {
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_CODE)) {
                roles = roles.stream().filter(i -> i.getName().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
            if (f.getAttributeName().equals(KEY_FILTER_ROLE_DESCR)) {
                roles = roles.stream().filter(i -> i.getDescription().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
            }
        }
    }
    List<Role> subList = restRequest.getSublist(roles);
    List<RoleDto> dtoSlice = this.getDtoBuilder().convert(subList);
    SearcherDaoPaginatedResult<RoleDto> paginatedResult = new SearcherDaoPaginatedResult(roles.size(), dtoSlice);
    PagedMetadata<RoleDto> pagedMetadata = new PagedMetadata<>(restRequest, paginatedResult);
    pagedMetadata.setBody(dtoSlice);
    return pagedMetadata;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)

Example 2 with RoleDto

use of org.entando.entando.aps.system.services.role.model.RoleDto in project entando-core by entando.

the class RoleController method updateRole.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{roleCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<RoleDto>> updateRole(@PathVariable String roleCode, @Valid @RequestBody RoleRequest roleRequest, BindingResult bindingResult) {
    logger.debug("updating role {}", roleCode);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getRoleValidator().validateBodyName(roleCode, roleRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    RoleDto role = this.getRoleService().updateRole(roleRequest);
    return new ResponseEntity<>(new SimpleRestResponse<>(role), HttpStatus.OK);
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResponseEntity(org.springframework.http.ResponseEntity) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RoleDto

use of org.entando.entando.aps.system.services.role.model.RoleDto in project entando-core by entando.

the class RoleController method addRole.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<RoleDto>> addRole(@Valid @RequestBody RoleRequest roleRequest, BindingResult bindingResult) throws ApsSystemException {
    logger.debug("adding role");
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    RoleDto dto = this.getRoleService().addRole(roleRequest);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResponseEntity(org.springframework.http.ResponseEntity) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with RoleDto

use of org.entando.entando.aps.system.services.role.model.RoleDto in project entando-core by entando.

the class RoleController method updateRole.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{roleCode}", method = RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_VALUE, consumes = "application/json-patch+json")
public ResponseEntity<SimpleRestResponse<RoleDto>> updateRole(@PathVariable String roleCode, @RequestBody JsonNode patchRequest, BindingResult bindingResult) {
    logger.debug("update role {} with jsonpatch-request {}", roleCode, patchRequest);
    this.getRoleValidator().validateJsonPatch(patchRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    RoleDto patchedRoleDto = this.getRoleService().getPatchedRole(roleCode, patchRequest);
    RoleRequest patchedRoleRequest = this.roleDtotoRoleRequestConverter.convert(patchedRoleDto);
    return this.updateRole(roleCode, patchedRoleRequest, bindingResult);
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RoleRequest(org.entando.entando.web.role.model.RoleRequest) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RoleDto

use of org.entando.entando.aps.system.services.role.model.RoleDto in project entando-core by entando.

the class RoleService method addRole.

@Override
public RoleDto addRole(RoleRequest roleRequest) {
    try {
        Role role = this.createRole(roleRequest);
        BeanPropertyBindingResult validationResult = this.validateRoleForAdd(role);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        this.getRoleManager().addRole(role);
        RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
        return dto;
    } catch (ApsSystemException e) {
        logger.error("Error adding a role", e);
        throw new RestServerError("error in add role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Aggregations

RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)10 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)5 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Role (com.agiletec.aps.system.services.role.Role)4 ResponseEntity (org.springframework.http.ResponseEntity)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)2 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)2 RestServerError (org.entando.entando.aps.system.exception.RestServerError)2 Filter (org.entando.entando.web.common.model.Filter)2 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)2 RoleRequest (org.entando.entando.web.role.model.RoleRequest)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 IAuthorizationService (com.agiletec.aps.system.services.authorization.IAuthorizationService)1 IRoleManager (com.agiletec.aps.system.services.role.IRoleManager)1 Permission (com.agiletec.aps.system.services.role.Permission)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Comparator (java.util.Comparator)1