use of org.springframework.web.multipart.MultipartFile 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 {
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);
doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR);
}
use of org.springframework.web.multipart.MultipartFile in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method getEntityFiles.
protected List<MultipartFile> getEntityFiles(DataReferenceDTO entityReference, DataNode dataNode, CommonAnalysisType entityType) throws JMSException, IOException, URISyntaxException {
Long waitForResponse = datanodeImportTimeout;
Long messageLifeTime = datanodeImportTimeout;
String baseQueue = MessagingUtils.Entities.getBaseQueue(dataNode);
CommonEntityRequestDTO request = new CommonEntityRequestDTO(entityReference.getEntityGuid(), entityType);
ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, request, baseQueue, waitForResponse, messageLifeTime);
final ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
if (responseMessage == null) {
String message = String.format(ENTITY_IS_NOT_AVAILABLE, entityType.getTitle(), entityReference.getEntityGuid(), entityReference.getDataNodeId());
throw new ServiceNotAvailableException(message);
}
List<MultipartFile> files = new LinkedList<>();
final List<ImportedFile> importedFiles = (List<ImportedFile>) responseMessage.getObject();
if (entityType.equals(CommonAnalysisType.ESTIMATION)) {
files.addAll(importService.processEstimation(importedFiles));
} else {
files = importedFiles.stream().map(file -> conversionService.convert(file, MockMultipartFile.class)).collect(Collectors.toList());
}
if (entityType.equals(CommonAnalysisType.PREDICTION)) {
attachPredictionFiles(files);
}
if (entityType.equals(CommonAnalysisType.COHORT_CHARACTERIZATION)) {
attachCohortCharacterizationFiles(files);
}
if (entityType.equals(CommonAnalysisType.INCIDENCE)) {
attachIncidenceRatesFiles(files);
}
return files;
}
use of org.springframework.web.multipart.MultipartFile in project ArachneCentralAPI by OHDSI.
the class EstimationPreprocessor method attachEstimationAnalysisCode.
private void attachEstimationAnalysisCode(Analysis analysis) {
Resource resource = new ClassPathResource(ESTIMATION_ANALYSIS_SOURCE);
try (final InputStream in = resource.getInputStream()) {
final MultipartFile analysisFile = new MockMultipartFile(ANALYSIS_BUNDLE_FILENAME, ANALYSIS_BUNDLE_FILENAME, null, in);
analysisService.saveFile(analysisFile, analysis.getAuthor(), analysis, analysisFile.getName(), false, null);
} catch (IOException e) {
LOGGER.error("Failed to add file", e);
throw new UncheckedIOException(e);
}
}
use of org.springframework.web.multipart.MultipartFile in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionServiceImpl method uploadResultsByDataOwner.
@Override
public ResultFile uploadResultsByDataOwner(Long submissionId, String name, MultipartFile file) throws NotExistException, IOException {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
IUser user = userService.getByUsername(userDetails.getUsername());
T submission = submissionRepository.findByIdAndStatusIn(submissionId, Collections.singletonList(IN_PROGRESS.name()));
throwNotExistExceptionIfNull(submission, submissionId);
File tempFile = File.createTempFile("manual-upload", name);
file.transferTo(tempFile);
ResultFile resultFile = createResultFile(tempFile.toPath(), ObjectUtils.firstNonNull(name, file.getOriginalFilename()), submission, user.getId());
Date updated = new Date();
List<ResultFile> resultFiles = submission.getResultFiles();
resultFiles.add(resultFile);
submission.setUpdated(updated);
submissionResultFileRepository.save(resultFiles);
saveSubmission(submission);
return resultFile;
}
use of org.springframework.web.multipart.MultipartFile in project bigbluebutton by bigbluebutton.
the class HttpTunnelStreamController method handleCaptureUpdateRequest.
private void handleCaptureUpdateRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
String room = request.getParameterValues("room")[0];
// This data is never a keyframe
String keyframe = "false";
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Get the list of multipart files that are in this POST request.
// Get the block info from each embedded file and send it to the
// session manager to update the viewers.
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Iterator uploadedFilenames = multipartRequest.getFileNames();
while (uploadedFilenames.hasNext()) {
// process each embedded upload-file (block)
String uploadedFilename = (String) uploadedFilenames.next();
MultipartFile multipartFile = multipartRequest.getFile(uploadedFilename);
// Parse the block info out of the upload file name
// The file name is of format "blockgroup_<seqnum>_<position>".
String[] uploadedFileInfo = uploadedFilename.split("[_]");
String seqNum = uploadedFileInfo[1];
String position = uploadedFileInfo[2];
// Update the viewers with the uploaded block data.
sessionManager.updateBlock(room, Integer.valueOf(position), multipartFile.getBytes(), // This data is never a keyframe
false, Integer.parseInt(seqNum));
}
// process each embedded upload-file (block)
/*
// MultipartFile is a copy of file in memory, not in file system
MultipartFile multipartFile = multipartRequest.getFile("blockdata");
long startRx = System.currentTimeMillis();
byte[] blockData = multipartFile.getBytes();
String room = request.getParameterValues("room")[0];
String seqNum = request.getParameterValues("sequenceNumber")[0];
String keyframe = request.getParameterValues("keyframe")[0];
String position = request.getParameterValues("position")[0];
if (! hasSessionManager) {
sessionManager = getSessionManager();
hasSessionManager = true;
}
sessionManager.updateBlock(room, Integer.valueOf(position), blockData, Boolean.parseBoolean(keyframe), Integer.parseInt(seqNum));
*/
}
Aggregations