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