use of com.odysseusinc.arachne.portal.model.AnalysisFile 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;
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisServiceImpl method saveFile.
@Override
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws IOException {
String originalFilename = multipartFile.getOriginalFilename();
String fileNameLowerCase = UUID.randomUUID().toString();
try {
Path analysisPath = getAnalysisPath(analysis);
Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
AnalysisFile analysisFile = new AnalysisFile();
analysisFile.setDataReference(dataReference);
analysisFile.setUuid(fileNameLowerCase);
analysisFile.setAnalysis(analysis);
analysisFile.setContentType(CommonFileUtils.getContentType(originalFilename, targetPath.toString()));
analysisFile.setLabel(label);
analysisFile.setAuthor(user);
analysisFile.setUpdatedBy(user);
analysisFile.setExecutable(false);
analysisFile.setRealName(originalFilename);
Date created = new Date();
analysisFile.setCreated(created);
analysisFile.setUpdated(created);
analysisFile.setVersion(1);
beforeSaveAnalysisFile(analysisFile);
AnalysisFile saved = analysisFileRepository.save(analysisFile);
analysis.getFiles().add(saved);
afterSaveAnalysisFile(saved);
if (Boolean.TRUE.equals(isExecutable)) {
setIsExecutable(saved.getUuid());
}
preprocessorService.preprocessFile(analysis, analysisFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getRealName(), new FileInputStream(targetPath.toString()), AntivirusJobFileType.ANALYSIS_FILE)));
return saved;
} catch (IOException | RuntimeException ex) {
String message = "error save file to disk, filename=" + fileNameLowerCase + " ex=" + ex.toString();
LOGGER.error(message, ex);
throw new IOException(message);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method getFileContent.
@ApiOperation("Get analysis code file.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}", method = GET)
public JsonResult<AnalysisFileDTO> getFileContent(@PathVariable("analysisId") Long analysisId, @RequestParam(defaultValue = "true") Boolean withContent, @PathVariable("fileUuid") String uuid) throws PermissionDeniedException, NotExistException, IOException {
AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
AnalysisFileDTO analysisFileDTO = conversionService.convert(analysisFile, AnalysisFileDTO.class);
if (withContent) {
analysisFileDTO = (AnalysisFileDTO) FileDtoContentHandler.getInstance(analysisFileDTO, analysisService.getPath(analysisFile).toFile()).withPdfConverter(toPdfConverter::convert).handle();
}
return new JsonResult<>(NO_ERROR, analysisFileDTO);
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class ArachnePermissionEvaluator method addPermissions.
public boolean addPermissions(ArachneUser user, HasArachnePermissions hasPermissionsObj) {
Set<ArachnePermission> allPermissions = getAllPermissions(hasPermissionsObj, user);
hasPermissionsObj.setPermissions(allPermissions);
if (hasPermissionsObj instanceof Analysis) {
final Analysis analysis = (Analysis) hasPermissionsObj;
final List<SubmissionGroup> submissionGroups = analysis.getSubmissionGroups();
if (!CollectionUtils.isEmpty(submissionGroups)) {
submissionGroups.forEach(submissionGroup -> submissionGroup.getSubmissions().forEach(submission -> {
final Set<ArachnePermission> submissionPermissions = getAllPermissions(submission, user);
submission.setPermissions(submissionPermissions);
}));
}
final List<AnalysisFile> files = analysis.getFiles();
if (!CollectionUtils.isEmpty(files)) {
files.forEach(file -> {
final Set<ArachnePermission> filePermissions = getAllPermissions(file, user);
file.setPermissions(filePermissions);
});
}
} else if (hasPermissionsObj instanceof Study) {
final Study study = (Study) hasPermissionsObj;
for (final Analysis analysis : study.getAnalyses()) {
analysis.setPermissions(getAllPermissions(analysis, user));
}
}
return true;
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class ArachneFileToFileContentDTOConverter method convert.
@Override
public AnalysisFileDTO convert(ArachneFile source) {
AnalysisFileDTO fileContentDTO = new AnalysisFileDTO();
fileContentDTO.setUuid(source.getUuid());
fileContentDTO.setName(source.getRealName());
fileContentDTO.setCreated(source.getCreated());
fileContentDTO.setLabel(source.getLabel());
if (source instanceof AnalysisFile && ((AnalysisFile) source).getAnalysis() != null) {
fileContentDTO.setAnalysisId(((AnalysisFile) source).getAnalysis().getId());
}
if (source instanceof SubmissionFile) {
fileContentDTO.setDocType(source.getContentType());
}
return fileContentDTO;
}
Aggregations