Search in sources :

Example 1 with CommonProfessionalTypeDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO in project ArachneCentralAPI by OHDSI.

the class ProfessionalTypeController method update.

@ApiOperation(value = "Update professional type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/professional-types/{professionalTypeId}", method = RequestMethod.PUT)
public JsonResult<CommonProfessionalTypeDTO> update(@PathVariable("professionalTypeId") Long id, @RequestBody @Valid CommonProfessionalTypeDTO professionalTypeDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    JsonResult result = null;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        ProfessionalType professionalType = conversionService.convert(professionalTypeDTO, ProfessionalType.class);
        professionalType.setId(id);
        professionalType = professionalTypeService.update(professionalType);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(professionalType);
    }
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommonProfessionalTypeDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO in project ArachneCentralAPI by OHDSI.

the class ProfessionalTypeController method get.

@ApiOperation("Get professional type.")
@RequestMapping(value = "/api/v1/user-management/professional-types/{professionalTypeId}", method = RequestMethod.GET)
public JsonResult<CommonProfessionalTypeDTO> get(@PathVariable("professionalTypeId") Long id) throws NotExistException {
    JsonResult result;
    if (id == null) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("professionalTypeId", "cannot be null");
    } else {
        ProfessionalType skill = professionalTypeService.getById(id);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(skill);
    }
    return result;
}
Also used : ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CommonProfessionalTypeDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO in project ArachneCentralAPI by OHDSI.

the class ProfessionalTypeController method create.

@ApiOperation(value = "Register new professional type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/professional-types", method = RequestMethod.POST)
public JsonResult<CommonProfessionalTypeDTO> create(@RequestBody @Valid CommonProfessionalTypeDTO professionalTypeDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
    JsonResult result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        ProfessionalType professionalType = conversionService.convert(professionalTypeDTO, ProfessionalType.class);
        professionalType = professionalTypeService.create(professionalType);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(professionalType, professionalTypeDTO.getClass()));
    }
    return result;
}
Also used : FieldError(org.springframework.validation.FieldError) ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CommonProfessionalTypeDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO in project ArachneCentralAPI by OHDSI.

the class ProfessionalTypeControllerTests method testCreateProfessionalType.

@Test
@DatabaseSetup(value = "/data/professionaltype/empty-professional-type.xml")
@ExpectedDatabase(table = "users_data", value = "/data/users-without-external-dependency.xml", assertionMode = NON_STRICT)
public void testCreateProfessionalType() throws Exception {
    CommonProfessionalTypeDTO professionalTypeDTO = new CommonProfessionalTypeDTO();
    professionalTypeDTO.setName(PROFESSIONAL_TYPE_NAME);
    MvcResult mvcResult = mvc.perform(post("/api/v1/admin/professional-types/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(professionalTypeDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(PROFESSIONAL_TYPE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : CommonProfessionalTypeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO) 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 CommonProfessionalTypeDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO in project ArachneCentralAPI by OHDSI.

the class ProfessionalTypeController method list.

@ApiOperation("List professional types.")
@RequestMapping(value = "/api/v1/user-management/professional-types", method = RequestMethod.GET)
public JsonResult<List<CommonProfessionalTypeDTO>> list() {
    JsonResult result = null;
    Iterable<ProfessionalType> professionalTypes = professionalTypeService.list();
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(professionalTypes);
    return result;
}
Also used : ProfessionalType(com.odysseusinc.arachne.portal.model.ProfessionalType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CommonProfessionalTypeDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO)4 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 ProfessionalType (com.odysseusinc.arachne.portal.model.ProfessionalType)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 UserProfileGeneralDTO (com.odysseusinc.arachne.portal.api.v1.dto.UserProfileGeneralDTO)1