use of com.odysseusinc.arachne.portal.model.SubmissionFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method createSubmissionGroup.
@Override
public SubmissionGroup createSubmissionGroup(IUser user, Analysis analysis) throws IOException, NoExecutableFileException {
checkBeforeCreateSubmissionGroup(analysis);
List<SubmissionFile> files = new LinkedList<>();
SubmissionGroup submissionGroup = new SubmissionGroup();
submissionGroup.setAnalysis(analysis);
submissionGroup.setAnalysisType(analysis.getType());
submissionGroup.setAuthor(user);
Date now = new Date();
submissionGroup.setCreated(now);
submissionGroup.setUpdated(now);
submissionGroup.setFiles(files);
submissionGroup = submissionGroupRepository.save(submissionGroup);
Path submissionGroupFolder = analysisHelper.getSubmissionGroupFolder(submissionGroup);
if (Files.notExists(submissionGroupFolder)) {
Files.createDirectories(submissionGroupFolder);
}
for (AnalysisFile analysisFile : analysis.getFiles()) {
SubmissionFile submissionFile = new SubmissionFile();
String storeFilesPath = fileStorePath + File.separator + "content";
String uuid = UUID.randomUUID().toString();
submissionFile.setSubmissionGroup(submissionGroup);
submissionFile.setContentType(analysisFile.getContentType());
submissionFile.setCreated(analysisFile.getCreated());
submissionFile.setUpdated(analysisFile.getUpdated());
submissionFile.setLabel(analysisFile.getLabel());
submissionFile.setRealName(analysisFile.getRealName());
submissionFile.setEntryPoint(analysisFile.getEntryPoint());
submissionFile.setUuid(uuid);
submissionFile.setAuthor(analysisFile.getAuthor());
submissionFile.setVersion(analysisFile.getVersion());
submissionFile.setAntivirusStatus(analysisFile.getAntivirusStatus());
submissionFile.setAntivirusDescription(analysisFile.getAntivirusDescription());
Boolean isExecutable = analysisFile.getExecutable();
submissionFile.setExecutable(isExecutable != null && isExecutable);
Path analysisFileContent = Paths.get(storeFilesPath, analysis.getStudy().getId().toString(), analysis.getId().toString(), analysisFile.getUuid());
Path submissionFileContent = submissionGroupFolder.resolve(uuid);
Path target = Files.copy(analysisFileContent, submissionFileContent, StandardCopyOption.REPLACE_EXISTING);
try (InputStream in = Files.newInputStream(target)) {
String checksum = DigestUtils.md5DigestAsHex(in);
submissionFile.setChecksum(checksum);
}
files.add(submissionFile);
}
submissionFileRepository.save(files);
submissionGroup.setChecksum(calculateMD5Hash(submissionGroupFolder, files));
submissionGroupRepository.save(submissionGroup);
return submissionGroup;
}
use of com.odysseusinc.arachne.portal.model.SubmissionFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method getSubmissionAllFiles.
@Override
public void getSubmissionAllFiles(Long submissionGroupId, String archiveName, OutputStream os) throws IOException {
SubmissionGroup submissionGroup = submissionGroupRepository.findOne(submissionGroupId);
Path storeFilesPath = analysisHelper.getSubmissionGroupFolder(submissionGroup);
try (ZipOutputStream zos = new ZipOutputStream(os)) {
for (SubmissionFile submissionFile : submissionGroup.getFiles()) {
String realName = submissionFile.getRealName();
Path file = storeFilesPath.resolve(submissionFile.getUuid());
if (Files.notExists(file)) {
file = legacyAnalysisHelper.getOldSubmissionFile(submissionFile).orElseThrow(FileNotFoundException::new);
}
if (Files.exists(file)) {
ZipUtil.addZipEntry(zos, realName, file);
}
}
}
}
Aggregations