Search in sources :

Example 26 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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 27 with JsonResult

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

the class StudyTypeController method delete.

@ApiOperation(value = "Delete study type.", hidden = true)
@RequestMapping(value = "/api/v1/admin/study-types/{studyTypeId}", method = RequestMethod.DELETE)
public JsonResult delete(@PathVariable("studyTypeId") Long id) {
    JsonResult result = null;
    if (id == null) {
        result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
        result.getValidatorErrors().put("studyTypeId", "cannot be null");
    } else {
        try {
            studyTypeService.delete(id);
            result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
            result.setResult(Boolean.TRUE);
        } 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 : 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 28 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult 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 29 with JsonResult

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

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<JsonResult> exceptionHandler(UserNotFoundException ex, HttpServletResponse response) throws IOException {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getField(), ex.getMessage());
    response.sendRedirect("/auth/login?message=email-not-confirmed");
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 30 with JsonResult

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

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(NotExistException.class)
public ResponseEntity<JsonResult> exceptionHandler(NotExistException ex) {
    LOGGER.error(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getEntity().getSimpleName(), ex.getMessage());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)71 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)58 ApiOperation (io.swagger.annotations.ApiOperation)55 IUser (com.odysseusinc.arachne.portal.model.IUser)22 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)17 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)17 ResponseEntity (org.springframework.http.ResponseEntity)16 GET (org.springframework.web.bind.annotation.RequestMethod.GET)10 POST (org.springframework.web.bind.annotation.RequestMethod.POST)10 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)10 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 FieldError (org.springframework.validation.FieldError)6 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)5 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)5 DataNode (com.odysseusinc.arachne.portal.model.DataNode)5 IOException (java.io.IOException)5 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)4 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)4