use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO 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.api.v1.dto.dictionary.RoleDTO 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.api.v1.dto.dictionary.RoleDTO in project ArachneCentralAPI by OHDSI.
the class RoleToRoleDTOConverter method convert.
@Override
public RoleDTO convert(Role source) {
RoleDTO dto = new RoleDTO();
dto.setId(source.getId());
dto.setName(source.getName());
dto.setDescription(source.getDescription());
return dto;
}
use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO in project ArachneCentralAPI by OHDSI.
the class RoleControllerTests method testUpdateRole.
@Test
@DatabaseSetup(value = "/data/role/role-before-updating.xml")
@ExpectedDatabase(table = "roles", value = "/data/role/roles.xml", assertionMode = NON_STRICT_UNORDERED)
public void testUpdateRole() throws Exception {
RoleDTO roleDTO = new RoleDTO();
roleDTO.setId(ROLE_ID);
roleDTO.setName(UPDATED_ROLE_NAME);
roleDTO.setDescription(ROLE_DESCRIPTION);
MvcResult mvcResult = mvc.perform(put("/api/v1/admin/roles/" + ROLE_ID).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(roleDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
JSONAssert.assertEquals(UPDATED_ROLE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO 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;
}
Aggregations