Search in sources :

Example 1 with Role

use of com.odysseusinc.arachne.portal.model.Role in project ArachneCentralAPI by OHDSI.

the class RoleController method update.

@ApiOperation(value = "Edit role.", hidden = true)
@RequestMapping(value = "/api/v1/admin/roles/{roleId}", method = RequestMethod.PUT)
public JsonResult<RoleDTO> update(@PathVariable("roleId") Long id, @RequestBody @Valid RoleDTO roleDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    JsonResult<RoleDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        Role role = conversionService.convert(roleDTO, Role.class);
        role.setId(id);
        role = roleService.update(role);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(role, RoleDTO.class));
    }
    return result;
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) Role(com.odysseusinc.arachne.portal.model.Role) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Role

use of com.odysseusinc.arachne.portal.model.Role in project ArachneCentralAPI by OHDSI.

the class RoleController method create.

@ApiOperation(value = "Register new role.", hidden = true)
@RequestMapping(value = "/api/v1/admin/roles", method = RequestMethod.POST)
public JsonResult<RoleDTO> create(@RequestBody @Valid RoleDTO roleDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
    JsonResult<RoleDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        Role role = conversionService.convert(roleDTO, Role.class);
        role = roleService.create(role);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(role, RoleDTO.class));
    }
    return result;
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) Role(com.odysseusinc.arachne.portal.model.Role) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Role

use of com.odysseusinc.arachne.portal.model.Role in project ArachneCentralAPI by OHDSI.

the class RoleController method list.

@ApiOperation(value = "List roles.", hidden = true)
@RequestMapping(value = "/api/v1/admin/roles", method = RequestMethod.GET)
public JsonResult<List<RoleDTO>> list() {
    JsonResult<List<RoleDTO>> result;
    Iterable<Role> roles = roleService.list();
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    List<RoleDTO> roleDTOs = new LinkedList<>();
    for (Role role : roles) {
        roleDTOs.add(conversionService.convert(role, RoleDTO.class));
    }
    result.setResult(roleDTOs);
    return result;
}
Also used : Role(com.odysseusinc.arachne.portal.model.Role) RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Role

use of com.odysseusinc.arachne.portal.model.Role in project ArachneCentralAPI by OHDSI.

the class RoleController method get.

@ApiOperation(value = "Get role description.", hidden = true)
@RequestMapping(value = "/api/v1/admin/roles/{roleId}", method = RequestMethod.GET)
public JsonResult<RoleDTO> get(@PathVariable("roleId") Long id) throws NotExistException {
    JsonResult<RoleDTO> result;
    if (id == null) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("roleId", "cannot be null");
    } else {
        Role role = roleService.getById(id);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(role, RoleDTO.class));
    }
    return result;
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) Role(com.odysseusinc.arachne.portal.model.Role) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Role

use of com.odysseusinc.arachne.portal.model.Role in project ArachneCentralAPI by OHDSI.

the class RoleDTOToRoleConverter method convert.

@Override
public Role convert(RoleDTO source) {
    Role role = new Role();
    role.setId(source.getId());
    role.setName(source.getName());
    role.setDescription(source.getDescription());
    return role;
}
Also used : Role(com.odysseusinc.arachne.portal.model.Role)

Aggregations

Role (com.odysseusinc.arachne.portal.model.Role)5 RoleDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 FieldError (org.springframework.validation.FieldError)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1