Search in sources :

Example 31 with MultipartFile

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);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataNode(com.odysseusinc.arachne.portal.model.DataNode) IUser(com.odysseusinc.arachne.portal.model.IUser) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with MultipartFile

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;
}
Also used : ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) LinkedList(java.util.LinkedList) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ObjectMessage(javax.jms.ObjectMessage) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 33 with MultipartFile

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);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 34 with MultipartFile

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;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) IUser(com.odysseusinc.arachne.portal.model.IUser) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) ResultFile(com.odysseusinc.arachne.portal.model.ResultFile) File(java.io.File) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) SubmissionFile(com.odysseusinc.arachne.portal.model.SubmissionFile) MultipartFile(org.springframework.web.multipart.MultipartFile) Date(java.util.Date)

Example 35 with MultipartFile

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));
*/
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Aggregations

MultipartFile (org.springframework.web.multipart.MultipartFile)76 File (java.io.File)26 IOException (java.io.IOException)23 Test (org.junit.Test)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 MockMultipartFile (org.springframework.mock.web.test.MockMultipartFile)14 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)12 MockMultipartHttpServletRequest (org.springframework.mock.web.test.MockMultipartHttpServletRequest)11 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 MethodParameter (org.springframework.core.MethodParameter)8 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)6 RequestParam (org.springframework.web.bind.annotation.RequestParam)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FileOutputStream (java.io.FileOutputStream)5 LinkedList (java.util.LinkedList)5 ActivitiException (org.activiti.engine.ActivitiException)5