Search in sources :

Example 1 with ServiceNotAvailableException

use of com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException 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)

Aggregations

CommonEntityRequestDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO)1 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)1 ServiceNotAvailableException (com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException)1 ImportedFile (com.odysseusinc.arachne.portal.util.ImportedFile)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ObjectMessage (javax.jms.ObjectMessage)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1