Search in sources :

Example 1 with UploadFileDTO

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

the class BaseAnalysisController method uploadFile.

@ApiOperation("Upload file to attach to analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/upload", method = POST)
public JsonResult<List<AnalysisFileDTO>> uploadFile(Principal principal, @Valid UploadFileDTO uploadFileDTO, @PathVariable("analysisId") Long id) throws PermissionDeniedException, NotExistException, IOException {
    IUser user = getUser(principal);
    T analysis = analysisService.getById(id);
    JsonResult<List<AnalysisFileDTO>> result = new JsonResult<>(NO_ERROR);
    List<AnalysisFileDTO> createdFiles = new ArrayList<>();
    if (uploadFileDTO.getFile() != null) {
        AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getFile(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable(), null);
        createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
    } else {
        if (StringUtils.hasText(uploadFileDTO.getLink())) {
            AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getLink(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable());
            createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
        } else {
            result.setErrorCode(VALIDATION_ERROR.getCode());
        }
    }
    result.setResult(createdFiles);
    return result;
}
Also used : PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) ArrayList(java.util.ArrayList) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)1 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)1 IUser (com.odysseusinc.arachne.portal.model.IUser)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 GET (org.springframework.web.bind.annotation.RequestMethod.GET)1 POST (org.springframework.web.bind.annotation.RequestMethod.POST)1 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)1