use of com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT in project ArachneCentralAPI by OHDSI.
the class AnalysisFilesSavingServiceImpl method saveFiles.
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
protected List<AnalysisFile> saveFiles(List<MultipartFile> multipartFiles, IUser user, A analysis, DataReference dataReference, BiPredicate<String, CommonAnalysisType> checkFileExecutabilityPredicate) {
List<MultipartFile> filteredFiles = multipartFiles.stream().filter(file -> !(CommonAnalysisType.COHORT.equals(analysis.getType()) && file.getName().endsWith(OHDSI_JSON_EXT))).filter(file -> !file.getName().startsWith(ANALYSIS_INFO_FILE_DESCRIPTION)).collect(Collectors.toList());
List<AnalysisFile> savedFiles = new ArrayList<>();
List<String> errorFileMessages = new ArrayList<>();
for (MultipartFile file : filteredFiles) {
try {
final boolean isExecutable = checkFileExecutabilityPredicate.test(file.getOriginalFilename(), analysis.getType());
savedFiles.add(saveFile(file, user, analysis, file.getName(), isExecutable, dataReference));
} catch (AlreadyExistException e) {
errorFileMessages.add(e.getMessage());
}
}
if (!errorFileMessages.isEmpty()) {
throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of(dataReference.getGuid(), errorFileMessages));
}
return savedFiles;
}
Aggregations