Search in sources :

Example 1 with StudyType

use of com.odysseusinc.arachne.portal.model.StudyType in project ArachneCentralAPI by OHDSI.

the class StudyTypeController method get.

@ApiOperation("Get study type.")
@RequestMapping(value = "/api/v1/study-management/study-types/{studyTypeId}", method = RequestMethod.GET)
public JsonResult get(@PathVariable("studyTypeId") Long id) {
    JsonResult result = null;
    try {
        StudyType studyType = studyTypeService.getById(id);
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(studyType);
    } catch (NotExistException ex) {
        log.error(ex.getMessage(), ex);
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("studyTypeId", "Status with id=" + id + " not found");
        result.setErrorMessage(ex.getMessage());
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
        result.setErrorMessage(ex.getMessage());
    }
    return result;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StudyType

use of com.odysseusinc.arachne.portal.model.StudyType in project ArachneCentralAPI by OHDSI.

the class StudyTypeController method list.

@ApiOperation("List study types.")
@RequestMapping(value = "/api/v1/study-management/study-types", method = RequestMethod.GET)
public JsonResult<List<StudyTypeDTO>> list() {
    JsonResult result;
    try {
        Iterable<StudyType> studyTypees = studyTypeService.list();
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        List<StudyTypeDTO> studyTypeDTOs = new LinkedList<>();
        for (StudyType studyType : studyTypees) {
            studyTypeDTOs.add(conversionService.convert(studyType, StudyTypeDTO.class));
        }
        result.setResult(studyTypeDTOs);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
        result.setErrorMessage(ex.getMessage());
    }
    return result;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) CreateStudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyTypeDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) LinkedList(java.util.LinkedList) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with StudyType

use of com.odysseusinc.arachne.portal.model.StudyType in project ArachneCentralAPI by OHDSI.

the class CreateStudyTypeDTOToStudyTypeConverter method convert.

@Override
public StudyType convert(CreateStudyTypeDTO source) {
    StudyType studyType = new StudyType();
    studyType.setId(source.getId());
    studyType.setName(source.getName());
    return studyType;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType)

Example 4 with StudyType

use of com.odysseusinc.arachne.portal.model.StudyType in project ArachneCentralAPI by OHDSI.

the class BaseCreateStudyDTOToStudyConverter method convert.

@Override
public S convert(DTO source) {
    S study = createResultObject();
    study.setTitle(source.getTitle());
    StudyType type = new StudyType();
    type.setId(source.getTypeId());
    study.setType(type);
    return study;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType)

Example 5 with StudyType

use of com.odysseusinc.arachne.portal.model.StudyType in project ArachneCentralAPI by OHDSI.

the class StudyTypeController method create.

@ApiOperation(value = "Register new study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types", method = RequestMethod.POST)
public JsonResult create(@RequestBody @Valid CreateStudyTypeDTO studyTypeDTO, BindingResult binding) {
    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 {
        try {
            StudyType studyType = conversionService.convert(studyTypeDTO, StudyType.class);
            studyType = studyTypeService.create(studyType);
            result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
            result.setResult(studyType);
        } catch (ConverterNotFoundException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        } catch (NotUniqueException ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
            result.getValidatorErrors().put(ex.getField(), ex.getMessage());
            result.setErrorMessage(ex.getMessage());
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
            result.setErrorMessage(ex.getMessage());
        }
    }
    return result;
}
Also used : StudyType(com.odysseusinc.arachne.portal.model.StudyType) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FieldError(org.springframework.validation.FieldError) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StudyType (com.odysseusinc.arachne.portal.model.StudyType)8 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)4 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)4 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ConverterNotFoundException (org.springframework.core.convert.ConverterNotFoundException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 FieldError (org.springframework.validation.FieldError)2 CreateStudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyTypeDTO)1 StudyTypeDTO (com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO)1 Study (com.odysseusinc.arachne.portal.model.Study)1 LinkedList (java.util.LinkedList)1