use of com.odysseusinc.arachne.portal.exception.AlreadyExistException 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;
}
use of com.odysseusinc.arachne.portal.exception.AlreadyExistException in project ArachneCentralAPI by OHDSI.
the class BaseStudyServiceImpl method addDataSource.
@Override
// ordering annotations is important to check current participants before method invoke
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).INVITE_DATANODE)")
public StudyDataSourceLink addDataSource(IUser createdBy, Long studyId, Long dataSourceId) throws NotExistException, AlreadyExistException {
T study = studyRepository.getOne(studyId);
if (study == null) {
throw new NotExistException("study not exist", Study.class);
}
DS dataSource = dataSourceService.getNotDeletedById(dataSourceId);
if (dataSource == null) {
throw new NotExistException("dataSource not exist", DataSource.class);
}
StudyDataSourceLink studyDataSourceLink = studyDataSourceLinkRepository.findByDataSourceIdAndStudyId(dataSource.getId(), study.getId());
if (studyDataSourceLink == null) {
studyDataSourceLink = new StudyDataSourceLink();
} else if (studyDataSourceLink.getStatus().isPendingOrApproved()) {
throw new AlreadyExistException();
}
studyDataSourceLink.setStudy(study);
studyDataSourceLink.setDataSource(dataSource);
studyDataSourceLink.setCreated(new Date());
studyDataSourceLink.setToken(UUID.randomUUID().toString());
studyDataSourceLink.setCreatedBy(createdBy);
studyDataSourceLink.setDeletedAt(null);
AddDataSourceStrategy<DS> strategy = addDataSourceStrategyFactory.getStrategy(dataSource);
strategy.addDataSourceToStudy(createdBy, dataSource, studyDataSourceLink);
return studyDataSourceLink;
}
use of com.odysseusinc.arachne.portal.exception.AlreadyExistException in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionInsightServiceImpl method createSubmissionInsight.
@Override
@PreAuthorize("hasPermission(#submissionId, 'Submission', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).EDIT_ANALYSIS)")
public SubmissionInsight createSubmissionInsight(Long submissionId, SubmissionInsight insight) throws AlreadyExistException, NotExistException {
LOGGER.info(CREATING_INSIGHT_LOG, submissionId);
final SubmissionInsight submissionInsight = submissionInsightRepository.findOneBySubmissionId(submissionId);
if (submissionInsight != null) {
final String message = String.format(INSIGHT_ALREADY_EXISTS_EXCEPTION, submissionId);
throw new AlreadyExistException(message);
}
final List<SubmissionStatus> allowedStatuses = Arrays.asList(EXECUTED_PUBLISHED, FAILED_PUBLISHED);
final Submission submission = submissionService.getSubmissionByIdAndStatus(submissionId, allowedStatuses);
throwNotExistExceptionIfNull(submission, submissionId);
insight.setId(null);
insight.setCreated(new Date());
insight.setSubmission(submission);
final SubmissionInsight savedInsight = submissionInsightRepository.save(insight);
final List<SubmissionInsightSubmissionFile> submissionInsightSubmissionFiles = submission.getSubmissionGroup().getFiles().stream().map(sf -> new SubmissionInsightSubmissionFile(savedInsight, sf, new CommentTopic())).collect(Collectors.toList());
submissionInsightSubmissionFileRepository.saveAll(submissionInsightSubmissionFiles);
final List<ResultFile> resultFiles = submission.getResultFiles();
resultFiles.forEach(resultFile -> resultFile.setCommentTopic(new CommentTopic()));
submissionResultFileRepository.saveAll(resultFiles);
return savedInsight;
}
use of com.odysseusinc.arachne.portal.exception.AlreadyExistException in project ArachneCentralAPI by OHDSI.
the class EstimationPreprocessor method attachRunner.
private void attachRunner(Analysis analysis, File file) {
try {
String runnerContent = template.apply(prepareParameters(analysis, file));
final MultipartFile analysisFile = new MockMultipartFile(ANALYSIS_RUNNER_FILENAME, ANALYSIS_RUNNER_FILENAME, "text/x-r-source", runnerContent.getBytes());
AnalysisFile createdFile = analysisService.saveFile(analysisFile, analysis.getAuthor(), analysis, ANALYSIS_RUNNER_FILENAME, true, null);
String fileUuid = createdFile.getUuid();
// Set via service function to unselect all other files
analysisService.setIsExecutable(fileUuid);
} catch (IOException e) {
LOGGER.error("Failed to generate estimation R execution", e);
throw new UncheckedIOException(e);
} catch (AlreadyExistException e) {
LOGGER.error("Failed to save file", e);
}
}
use of com.odysseusinc.arachne.portal.exception.AlreadyExistException in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method sendUnlockRequest.
@ApiOperation("Send analysis unlock request")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/unlock-request", method = POST)
public JsonResult<FileDTO> sendUnlockRequest(Principal principal, @PathVariable("analysisId") Long analysisId, @RequestBody AnalysisUnlockRequestDTO analysisUnlockRequestDTO) throws NotExistException, PermissionDeniedException, AlreadyExistException {
JsonResult result;
final IUser user = getUser(principal);
final AnalysisUnlockRequest unlockRequest = new AnalysisUnlockRequest();
unlockRequest.setUser(user);
unlockRequest.setStatus(AnalysisUnlockRequestStatus.PENDING);
unlockRequest.setCreated(new Date());
unlockRequest.setToken(UUID.randomUUID().toString().replace("-", ""));
unlockRequest.setDescription(analysisUnlockRequestDTO.getDescription());
try {
final AnalysisUnlockRequest analysisUnlockRequest = analysisService.sendAnalysisUnlockRequest(analysisId, unlockRequest);
analysisService.findLeads((T) analysisUnlockRequest.getAnalysis()).forEach(lead -> wsTemplate.convertAndSendToUser(lead.getUsername(), "/topic/invitations", new UpdateNotificationDTO()));
result = new JsonResult<>(NO_ERROR);
} catch (AlreadyExistException ex) {
result = new JsonResult<>(VALIDATION_ERROR);
result.setErrorMessage("Unlock request for the analysis was already created");
}
return result;
}
Aggregations