Search in sources :

Example 1 with RoleDTO

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

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

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;
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO)

Example 4 with RoleDTO

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);
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 5 with RoleDTO

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

Aggregations

RoleDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO)7 Role (com.odysseusinc.arachne.portal.model.Role)4 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)2 Test (org.junit.Test)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 FieldError (org.springframework.validation.FieldError)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1