Search in sources :

Example 6 with StudyStatusDTO

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

the class StudyStatusController method update.

@ApiOperation(value = "Edit study status.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-statuses/{studyStatusId}", method = RequestMethod.PUT)
public JsonResult<StudyStatusDTO> update(@PathVariable("studyStatusId") Long id, @RequestBody @Valid StudyStatusDTO studyStatusDTO, BindingResult binding) throws NotExistException, NotUniqueException, ValidationException {
    JsonResult<StudyStatusDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        StudyStatus studyStatus = conversionService.convert(studyStatusDTO, StudyStatus.class);
        studyStatus = studyStatusService.update(studyStatus);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(studyStatus, StudyStatusDTO.class));
    }
    return result;
}
Also used : StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) CreateStudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyStatusDTO) StudyStatus(com.odysseusinc.arachne.portal.model.StudyStatus) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with StudyStatusDTO

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

the class StudyStatusController method get.

@ApiOperation("Get study status.")
@RequestMapping(value = "/api/v1/study-management/study-statuses/{studyStatusId}", method = RequestMethod.GET)
public JsonResult<StudyStatusDTO> get(@PathVariable("studyStatusId") Long id) throws NotExistException {
    StudyStatus studyStatus = studyStatusService.getById(id);
    JsonResult<StudyStatusDTO> result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(conversionService.convert(studyStatus, StudyStatusDTO.class));
    return result;
}
Also used : StudyStatus(com.odysseusinc.arachne.portal.model.StudyStatus) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) CreateStudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyStatusDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with StudyStatusDTO

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

the class StudyStatusController method create.

@ApiOperation(value = "Register new study status.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-statuses", method = RequestMethod.POST)
public JsonResult<StudyStatusDTO> create(@RequestBody @Valid CreateStudyStatusDTO studyStatusDTO, BindingResult binding) throws NotExistException, NotUniqueException, PermissionDeniedException {
    JsonResult<StudyStatusDTO> result;
    if (binding.hasErrors()) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        for (FieldError fieldError : binding.getFieldErrors()) {
            result.getValidatorErrors().put(fieldError.getField(), fieldError.getDefaultMessage());
        }
    } else {
        StudyStatus studyStatus = conversionService.convert(studyStatusDTO, StudyStatus.class);
        studyStatus = studyStatusService.create(studyStatus);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(conversionService.convert(studyStatus, StudyStatusDTO.class));
    }
    return result;
}
Also used : StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) CreateStudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyStatusDTO) StudyStatus(com.odysseusinc.arachne.portal.model.StudyStatus) FieldError(org.springframework.validation.FieldError) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with StudyStatusDTO

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

the class StudyControllerTests method testUpdateStudyType.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-type.xml", assertionMode = NON_STRICT_UNORDERED) })
public void testUpdateStudyType() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setDescription("description");
    StudyTypeDTO type = new StudyTypeDTO(1L);
    type.setName("type1");
    updatedStudyDTO.setType(type);
    StudyStatusDTO status = new StudyStatusDTO(STUDY_STATUS_ID, "Initiate");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_TYPE_JSON_OBJECT, "type1");
}
Also used : CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 10 with StudyStatusDTO

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

the class StudyControllerTests method testUpdateStudyStatus.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-before-updating.xml")
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study/study-after-updating-status.xml", assertionMode = NON_STRICT_UNORDERED) })
public void testUpdateStudyStatus() throws Exception {
    StudyDTO updatedStudyDTO = new StudyDTO();
    updatedStudyDTO.setId(STUDY_ID);
    updatedStudyDTO.setDescription("description");
    StudyTypeDTO type = new StudyTypeDTO(STUDY_TYPE_ID);
    type.setName("type1");
    updatedStudyDTO.setType(type);
    StudyStatusDTO status = new StudyStatusDTO(2L, "Active");
    updatedStudyDTO.setStatus(status);
    testUpdate(updatedStudyDTO, UPDATED_STUDY_STATUS_JSON_OBJECT, "Active");
}
Also used : CreateStudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Aggregations

StudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO)11 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)6 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)6 CreateStudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO)6 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)6 Test (org.junit.Test)6 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)6 StudyStatus (com.odysseusinc.arachne.portal.model.StudyStatus)5 CreateStudyStatusDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyStatusDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)3 FieldError (org.springframework.validation.FieldError)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 BaseConversionServiceAwareConverter (com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter)1 StudyState (com.odysseusinc.arachne.portal.model.statemachine.study.StudyState)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Component (org.springframework.stereotype.Component)1