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;
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations