Search in sources :

Example 46 with JsonResult

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

the class BaseAnalysisController method sendUnlockRequest.

@ApiOperation("Send analysis unlock request")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/unlock-request", method = POST)
public JsonResult<FileDTO> sendUnlockRequest(Principal principal, @PathVariable("analysisId") Long analysisId, @RequestBody AnalysisUnlockRequestDTO analysisUnlockRequestDTO) throws NotExistException, PermissionDeniedException, AlreadyExistException {
    JsonResult result;
    final IUser user = getUser(principal);
    final AnalysisUnlockRequest unlockRequest = new AnalysisUnlockRequest();
    unlockRequest.setUser(user);
    unlockRequest.setStatus(AnalysisUnlockRequestStatus.PENDING);
    unlockRequest.setCreated(new Date());
    unlockRequest.setToken(UUID.randomUUID().toString().replace("-", ""));
    unlockRequest.setDescription(analysisUnlockRequestDTO.getDescription());
    try {
        final AnalysisUnlockRequest analysisUnlockRequest = analysisService.sendAnalysisUnlockRequest(analysisId, unlockRequest);
        analysisService.findLeads((T) analysisUnlockRequest.getAnalysis()).forEach(lead -> wsTemplate.convertAndSendToUser(lead.getUsername(), "/topic/invitations", new UpdateNotificationDTO()));
        result = new JsonResult<>(NO_ERROR);
    } catch (AlreadyExistException ex) {
        result = new JsonResult<>(VALIDATION_ERROR);
        result.setErrorMessage("Unlock request for the analysis was already created");
    }
    return result;
}
Also used : UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) IUser(com.odysseusinc.arachne.portal.model.IUser) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with JsonResult

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

the class BaseAnalysisController method updateSubmissionInsight.

@ApiOperation("Update submission insight")
@RequestMapping(value = "/api/v1/analysis-management/submissions/{submissionId}/insight", method = PUT)
public JsonResult<SubmissionInsightDTO> updateSubmissionInsight(@PathVariable("submissionId") Long submissionId, @RequestBody SubmissionInsightUpdateDTO insightDTO) throws NotExistException {
    final SubmissionInsight insight = conversionService.convert(insightDTO, SubmissionInsight.class);
    final SubmissionInsight updatedInsight = submissionInsightService.updateSubmissionInsight(submissionId, insight);
    final SubmissionInsightDTO updatedInsightDTO = conversionService.convert(updatedInsight, SubmissionInsightDTO.class);
    final JsonResult<SubmissionInsightDTO> result = new JsonResult<>(NO_ERROR);
    result.setResult(updatedInsightDTO);
    return result;
}
Also used : SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with JsonResult

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

the class BaseAnalysisController method putFileContent.

@ApiOperation("Write content of the code file.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}", method = PUT)
public JsonResult<Boolean> putFileContent(Principal principal, @RequestBody FileDTO fileContentDTO, @PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String uuid) throws PermissionDeniedException, NotExistException, IOException, URISyntaxException {
    final IUser user = getUser(principal);
    AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
    analysisService.writeToFile(analysisFile, fileContentDTO, user);
    JsonResult<Boolean> result = new JsonResult<>(NO_ERROR);
    result.setResult(Boolean.TRUE);
    return result;
}
Also used : AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with JsonResult

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

the class BaseAnalysisController method get.

@ApiOperation("Get analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}", method = GET)
public JsonResult<D> get(@PathVariable("analysisId") Long id) throws NotExistException, PermissionDeniedException {
    JsonResult<D> result;
    T analysis = analysisService.getById(id);
    result = new JsonResult<>(NO_ERROR);
    D analysisDTO = conversionService.convert(analysis, getAnalysisDTOClass());
    result.setResult(analysisDTO);
    return result;
}
Also used : PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) UUID(java.util.UUID) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 50 with JsonResult

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

the class BaseDataSourceController method suggestDataSource.

@RequestMapping(value = "/api/v1/data-sources/search-data-source", method = RequestMethod.GET)
public JsonResult<Page<DS_DTO>> suggestDataSource(Principal principal, @RequestParam("studyId") Long studyId, @RequestParam("query") String query, @ModelAttribute PageDTO pageDTO) throws PermissionDeniedException {
    if (studyId == null || query == null) {
        throw new javax.validation.ValidationException();
    }
    final IUser user = getUser(principal);
    PageRequest pageRequest = getPageRequest(pageDTO);
    Page<DS> dataSources = dataSourceService.suggestDataSource(query, studyId, user.getId(), pageRequest);
    List<DS_DTO> dataSourceDTOs = converterUtils.convertList(dataSources.getContent(), getDataSourceDTOClass());
    CustomPageImpl<DS_DTO> resultPage = new CustomPageImpl<>(dataSourceDTOs, pageRequest, dataSources.getTotalElements());
    return new JsonResult<>(NO_ERROR, resultPage);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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