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;
}
Aggregations