use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method addCommonEntityToAnalysis.
@ApiOperation("Add common entity to analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities", method = POST)
public JsonResult addCommonEntityToAnalysis(@PathVariable("analysisId") Long analysisId, @RequestBody @Valid DataReferenceDTO entityReference, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws NotExistException, JMSException, IOException, PermissionDeniedException, URISyntaxException {
if (!analysisModificationLock.add(analysisId)) {
throw new ValidationRuntimeException("Analysis import rejected", Collections.singletonMap(entityReference.getEntityGuid(), Collections.singletonList("Another import into this analysis is in progress")));
}
try {
LOGGER.debug("Started import into analysis {}", analysisId);
final IUser user = getUser(principal);
final DataNode dataNode = dataNodeService.getById(entityReference.getDataNodeId());
final T analysis = analysisService.getById(analysisId);
final DataReference dataReference = dataReferenceService.addOrUpdate(entityReference.getEntityGuid(), dataNode);
final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataNode, analysisType);
String description = doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR, description);
} finally {
analysisModificationLock.remove(analysisId);
LOGGER.debug("Completed import into analysis {}", analysisId);
}
}
use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException in project ArachneCentralAPI by OHDSI.
the class AnalysisFilesSavingServiceImpl method saveFiles.
@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public List<AnalysisFile> saveFiles(List<UploadFileDTO> files, IUser user, A analysis) throws IOException {
List<String> errorFileMessages = new ArrayList<>();
List<AnalysisFile> savedFiles = new ArrayList<>();
for (UploadFileDTO f : files) {
try {
if (StringUtils.isNotBlank(f.getLink())) {
savedFiles.add(saveFileByLink(f.getLink(), user, analysis, f.getLabel(), f.getExecutable()));
} else if (f.getFile() != null) {
savedFiles.add(saveFile(f.getFile(), user, analysis, f.getLabel(), f.getExecutable(), null));
} else {
errorFileMessages.add(String.format("Invalid file: \"%s\"", f.getLabel()));
}
} catch (AlreadyExistException e) {
errorFileMessages.add(e.getMessage());
}
}
if (!errorFileMessages.isEmpty()) {
throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of("file", errorFileMessages));
}
return savedFiles;
}
use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException 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