Search in sources :

Example 6 with RoleDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO 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 7 with RoleDTO

use of com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO in project ArachneCentralAPI by OHDSI.

the class RoleControllerTests method testRole.

@Test
@DatabaseSetup(value = "/data/role/empty-role.xml")
@ExpectedDatabase(table = "roles", value = "/data/role/added-role.xml", assertionMode = NON_STRICT)
public void testRole() throws Exception {
    RoleDTO roleDTO = new RoleDTO();
    roleDTO.setName(ROLE_NAME);
    roleDTO.setDescription(ROLE_DESCRIPTION);
    MvcResult mvcResult = mvc.perform(post("/api/v1/admin/roles/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(roleDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(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)

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