use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.
the class AnalysisFilesSavingServiceImpl method saveFile.
@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public AnalysisFile saveFile(MultipartFile multipartFile, IUser user, A analysis, String label, Boolean isExecutable, DataReference dataReference) throws AlreadyExistException {
ensureLabelIsUnique(analysis.getId(), label);
String originalFilename = multipartFile.getOriginalFilename();
String fileNameLowerCase = UUID.randomUUID().toString();
try {
Path analysisPath = analysisHelper.getAnalysisPath(analysis);
Path targetPath = Paths.get(analysisPath.toString(), fileNameLowerCase);
Files.copy(multipartFile.getInputStream(), targetPath, REPLACE_EXISTING);
final String contentType = CommonFileUtils.getContentType(originalFilename, targetPath.toString());
AnalysisFile analysisFile = buildNewAnalysisFileEntry(user, analysis, label, isExecutable, originalFilename, fileNameLowerCase, contentType);
analysisFile.setDataReference(dataReference);
AnalysisFile saved = analysisFileRepository.save(analysisFile);
analysis.getFiles().add(saved);
preprocessorService.preprocessFile(analysis, analysisFile);
eventPublisher.publishEvent(new AntivirusJobEvent(this, new AntivirusJob(saved.getId(), saved.getName(), 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();
log.error(message, ex);
throw new ArachneSystemRuntimeException(message);
}
}
use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.
the class ToPdfConverter method recreateJodConverterWorkingFolderIfNoLongerExists.
private void recreateJodConverterWorkingFolderIfNoLongerExists() {
if (officeManager != null) {
final File tempFile = officeManager.makeTemporaryFile();
final Path currentTempDir = tempFile.toPath().getParent();
if (!currentTempDir.toFile().exists()) {
log.info("Recreating JodConverter temp folder: {}", currentTempDir);
try {
Files.createDirectories(currentTempDir);
} catch (IOException ex) {
throw new ArachneSystemRuntimeException("Cannot restore officeManager temp folder: " + currentTempDir, ex);
}
}
}
}
use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException in project ArachneCentralAPI by OHDSI.
the class SearchIndexesRefresher method rebuildAllIndexes.
private void rebuildAllIndexes() {
try {
dataSourceService.indexAllBySolr();
userService.indexAllBySolr();
studyService.indexAllBySolr();
analysisService.indexAllBySolr();
paperService.indexAllBySolr();
} catch (Exception ex) {
throw new ArachneSystemRuntimeException(ex);
}
}
use of com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException 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