Search in sources :

Example 6 with RoleDto

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

the class RoleMockHelper method mockRoleDto.

/**
 * @return a mocked RoleDto instance
 */
public static RoleDto mockRoleDto(String suffix) {
    RoleDto role = new RoleDto();
    role.setName(ROLE_NAME + suffix);
    // role.setPermissions(PERMISSION + suffix);
    return role;
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto)

Example 7 with RoleDto

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

the class RoleController method getRoles.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getRoles(RestListRequest requestList) throws JsonProcessingException {
    this.getRoleValidator().validateRestListRequest(requestList);
    PagedMetadata<RoleDto> result = this.getRoleService().getRoles(requestList);
    this.getRoleValidator().validateRestListResult(requestList, result);
    logger.debug("loading role list -> {}", result);
    return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
Also used : RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RoleDto

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

the class RoleService method updateRole.

@Override
public RoleDto updateRole(RoleRequest roleRequest) {
    try {
        Role role = this.getRoleManager().getRole(roleRequest.getCode());
        if (null == role) {
            logger.warn("no role found with code {}", roleRequest.getCode());
            throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleRequest.getCode());
        }
        role.setDescription(roleRequest.getName());
        role.getPermissions().clear();
        if (null != roleRequest.getPermissions()) {
            roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
        }
        BeanPropertyBindingResult validationResult = this.validateRoleForUpdate(role);
        if (validationResult.hasErrors()) {
            throw new ValidationGenericException(validationResult);
        }
        this.getRoleManager().updateRole(role);
        RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
        return dto;
    } catch (ApsSystemException e) {
        logger.error("Error updating a role", e);
        throw new RestServerError("error in update role", e);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Role(com.agiletec.aps.system.services.role.Role) RoleValidator(org.entando.entando.web.role.validator.RoleValidator) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IRoleManager(com.agiletec.aps.system.services.role.IRoleManager) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IAuthorizationService(com.agiletec.aps.system.services.authorization.IAuthorizationService) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RoleRequest(org.entando.entando.web.role.model.RoleRequest) Permission(com.agiletec.aps.system.services.role.Permission) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) PostConstruct(javax.annotation.PostConstruct) Comparator(java.util.Comparator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) 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) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 9 with RoleDto

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

the class RoleService method getRole.

@Override
public RoleDto getRole(String roleCode) {
    Role role = this.getRoleManager().getRole(roleCode);
    if (null == role) {
        logger.warn("no role found with code {}", roleCode);
        throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleCode);
    }
    RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
    return dto;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 10 with RoleDto

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

the class RoleController method getRole.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{roleCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<RoleDto>> getRole(@PathVariable String roleCode) {
    logger.debug("loading role {}", roleCode);
    RoleDto role = this.getRoleService().getRole(roleCode);
    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) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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