use of com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT in project ArachneCentralAPI by OHDSI.
the class AnalysisFilesSavingServiceImpl method saveCohortAnalysisArchive.
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public void saveCohortAnalysisArchive(A analysis, DataReference dataReference, IUser user, List<MultipartFile> files) {
MultipartFile genericSqlFile = files.stream().filter(file -> file.getName().endsWith(OHDSI_SQL_EXT)).findAny().orElseThrow(() -> new ArachneSystemRuntimeException(String.format("There is no sql file for %s analysis.", analysis.getId())));
Collection<MultipartFile> filesForArchive = files.stream().filter(file -> ObjectUtils.notEqual(file, genericSqlFile)).filter(file -> !StringUtils.equals(ANALYSIS_INFO_FILE_DESCRIPTION, file.getName())).collect(Collectors.toList());
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (ZipOutputStream zos = new ZipOutputStream(out)) {
generateFilesForEachDialectAndAddToZip(zos, genericSqlFile);
ZipUtil.addZipEntries(zos, filesForArchive);
} catch (IOException e) {
log.error("Failed to create zip file for {} analysis", analysis.getId(), e);
throw new ArachneSystemRuntimeException(e);
}
String fileName = AnalysisArchiveUtils.getArchiveFileName(CommonAnalysisType.COHORT, getAnalysisName(genericSqlFile));
MultipartFile sqlArchive = new MockMultipartFile(fileName, fileName, "application/zip", out.toByteArray());
try {
saveFile(sqlArchive, user, analysis, fileName, false, dataReference);
} catch (Exception e) {
log.error("Failed to save zip file for {} analysis", analysis.getId(), e);
throw new ArachneSystemRuntimeException(e);
}
}
Aggregations