use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method updateCommonEntityInAnalysis.
@ApiOperation("update common entity in analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities/{fileUuid}", method = PUT)
public JsonResult updateCommonEntityInAnalysis(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String fileUuid, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws IOException, JMSException, PermissionDeniedException, URISyntaxException {
final IUser user = getUser(principal);
final AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, fileUuid);
T analysis = (T) analysisFile.getAnalysis();
final DataReference dataReference = analysisFile.getDataReference();
final DataReferenceDTO entityReference = new DataReferenceDTO(dataReference.getDataNode().getId(), dataReference.getGuid());
final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataReference.getDataNode(), analysisType);
analysisService.findAnalysisFilesByDataReference(analysis, dataReference).forEach(af -> {
analysisService.deleteAnalysisFile(analysis, af);
analysis.getFiles().remove(af);
});
doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR);
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method getFile.
@ApiOperation("Get code file of the submission.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}/download", method = GET)
public void getFile(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String uuid, HttpServletResponse response) throws PermissionDeniedException, NotExistException, IOException {
try {
AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
putFileContentToResponse(response, analysisFile.getContentType(), StringUtils.getFilename(analysisFile.getRealName()), analysisService.getAnalysisFile(analysisFile));
} catch (IOException ex) {
LOGGER.info("Error writing file to output stream. Filename was '{}'", uuid, ex);
throw new IOException("Error writing file to output stream. Filename was " + uuid, ex);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method putFileContent.
@ApiOperation("Write content of the code file.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/code-files/{fileUuid}", method = PUT)
public JsonResult<Boolean> putFileContent(Principal principal, @RequestBody FileDTO fileContentDTO, @PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String uuid) throws PermissionDeniedException, NotExistException, IOException, URISyntaxException {
final IUser user = getUser(principal);
AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, uuid);
analysisService.writeToFile(analysisFile, fileContentDTO, user);
JsonResult<Boolean> result = new JsonResult<>(NO_ERROR);
result.setResult(Boolean.TRUE);
return result;
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile 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);
}
}
use of com.odysseusinc.arachne.portal.model.AnalysisFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method createSubmissionGroup.
@Override
public SubmissionGroup createSubmissionGroup(IUser user, Analysis analysis) throws IOException, NoExecutableFileException {
checkBeforeCreateSubmissionGroup(analysis);
List<SubmissionFile> files = new LinkedList<>();
SubmissionGroup submissionGroup = new SubmissionGroup();
submissionGroup.setAnalysis(analysis);
submissionGroup.setAnalysisType(analysis.getType());
submissionGroup.setAuthor(user);
Date now = new Date();
submissionGroup.setCreated(now);
submissionGroup.setUpdated(now);
submissionGroup.setFiles(files);
submissionGroup = submissionGroupRepository.save(submissionGroup);
Path submissionGroupFolder = analysisHelper.getSubmissionGroupFolder(submissionGroup);
if (Files.notExists(submissionGroupFolder)) {
Files.createDirectories(submissionGroupFolder);
}
for (AnalysisFile analysisFile : analysis.getFiles()) {
SubmissionFile submissionFile = new SubmissionFile();
String storeFilesPath = fileStorePath + File.separator + "content";
String uuid = UUID.randomUUID().toString();
submissionFile.setSubmissionGroup(submissionGroup);
submissionFile.setContentType(analysisFile.getContentType());
submissionFile.setCreated(analysisFile.getCreated());
submissionFile.setUpdated(analysisFile.getUpdated());
submissionFile.setLabel(analysisFile.getLabel());
submissionFile.setRealName(analysisFile.getRealName());
submissionFile.setEntryPoint(analysisFile.getEntryPoint());
submissionFile.setUuid(uuid);
submissionFile.setAuthor(analysisFile.getAuthor());
submissionFile.setVersion(analysisFile.getVersion());
submissionFile.setAntivirusStatus(analysisFile.getAntivirusStatus());
submissionFile.setAntivirusDescription(analysisFile.getAntivirusDescription());
Boolean isExecutable = analysisFile.getExecutable();
submissionFile.setExecutable(isExecutable != null && isExecutable);
Path analysisFileContent = Paths.get(storeFilesPath, analysis.getStudy().getId().toString(), analysis.getId().toString(), analysisFile.getUuid());
Path submissionFileContent = submissionGroupFolder.resolve(uuid);
Path target = Files.copy(analysisFileContent, submissionFileContent, StandardCopyOption.REPLACE_EXISTING);
try (InputStream in = Files.newInputStream(target)) {
String checksum = DigestUtils.md5DigestAsHex(in);
submissionFile.setChecksum(checksum);
}
files.add(submissionFile);
}
submissionFileRepository.save(files);
submissionGroup.setChecksum(calculateMD5Hash(submissionGroupFolder, files));
submissionGroupRepository.save(submissionGroup);
return submissionGroup;
}
Aggregations