Search in sources :

Example 1 with ImportedFile

use of com.odysseusinc.arachne.portal.util.ImportedFile in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method getEntityFiles.

public 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);
    }
    final List<ImportedFile> importedFiles = (List<ImportedFile>) responseMessage.getObject();
    boolean hasAnalysisRunner = hasAnalysisRunner(importedFiles);
    if (entityType.equals(CommonAnalysisType.ESTIMATION) && !hasAnalysisRunner) {
        return importService.processEstimation(importedFiles);
    }
    List<MultipartFile> files = importedFiles.stream().map(file -> conversionService.convert(file, MockMultipartFile.class)).collect(Collectors.toList());
    if (!hasAnalysisRunner) {
        files.addAll(generateAnalysisFiles(entityType));
    }
    return files;
}
Also used : ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) UploadFilesDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFilesDTO) Valid(javax.validation.Valid) CommentUtils.getRecentCommentables(com.odysseusinc.arachne.portal.util.CommentUtils.getRecentCommentables) AnalysisLockDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) Sort(org.springframework.data.domain.Sort) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) Resource(org.springframework.core.io.Resource) MessagingUtils(com.odysseusinc.arachne.portal.service.messaging.MessagingUtils) FieldError(org.springframework.validation.FieldError) Set(java.util.Set) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) Page(org.springframework.data.domain.Page) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Stream(java.util.stream.Stream) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) VALIDATION_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR) DataReference(com.odysseusinc.arachne.portal.model.DataReference) BindingResult(org.springframework.validation.BindingResult) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) StreamSupport(java.util.stream.StreamSupport) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) IOException(java.io.IOException) HttpUtils.putFileContentToResponse(com.odysseusinc.arachne.portal.util.HttpUtils.putFileContentToResponse) SubmissionInsightUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightUpdateDTO) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) AnalysisUnlockRequestDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) AnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) ShortBaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortBaseAnalysisDTO) JMSException(javax.jms.JMSException) Collectors(java.util.stream.Collectors) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) List(java.util.List) Principal(java.security.Principal) DataReferenceService(com.odysseusinc.arachne.portal.service.DataReferenceService) AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) AnalysisUnlockRequestStatus(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequestStatus) SubmissionGroupDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ObjectMessage(javax.jms.ObjectMessage) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) HeraclesAnalysisService(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisService) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) POST(org.springframework.web.bind.annotation.RequestMethod.POST) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) CommonFilenameUtils(com.odysseusinc.arachne.commons.utils.CommonFilenameUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) HeraclesAnalysisKind(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisKind) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DataNode(com.odysseusinc.arachne.portal.model.DataNode) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportService(com.odysseusinc.arachne.portal.service.ImportService) NotEmptyException(com.odysseusinc.arachne.portal.exception.NotEmptyException) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) InputStream(java.io.InputStream) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ObjectMessage(javax.jms.ObjectMessage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ImportedFile

use of com.odysseusinc.arachne.portal.util.ImportedFile in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method saveEntity.

@ApiOperation("Save entity")
@RequestMapping(value = "/api/v1/data-nodes/common-entity/{id}", method = POST)
public void saveEntity(Principal principal, @PathVariable("id") String id, @RequestParam(required = false) MultipartFile[] files) throws PermissionDeniedException, IOException {
    LinkedList<ImportedFile> importedFiles = new LinkedList<>();
    for (MultipartFile mpf : files) {
        importedFiles.add(new ImportedFile(mpf.getOriginalFilename(), mpf.getBytes()));
    }
    saveCommonEntity(principal, id, importedFiles);
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ImportedFile (com.odysseusinc.arachne.portal.util.ImportedFile)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 CommonEntityRequestDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO)1 OptionDTO (com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO)1 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 NO_ERROR (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR)1 PERMISSION_DENIED (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED)1 VALIDATION_ERROR (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR)1 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)1 CommonFilenameUtils (com.odysseusinc.arachne.commons.utils.CommonFilenameUtils)1 AnalysisCreateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO)1 AnalysisDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO)1 AnalysisFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO)1 AnalysisLockDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO)1 AnalysisUnlockRequestDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO)1 AnalysisUpdateDTO (com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO)1 Commentable (com.odysseusinc.arachne.portal.api.v1.dto.Commentable)1