Search in sources :

Example 1 with CommonEntityRequestDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method getEntityRequests.

@RequestMapping(value = "/api/v1/data-nodes/entities", method = GET)
public List<CommonEntityRequestDTO> getEntityRequests(Principal principal) throws PermissionDeniedException, JMSException {
    DataNode dataNode = getDatanode(principal);
    final String requestQueue = getRequestQueueName(MessagingUtils.Entities.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    List<CommonEntityRequestDTO> cohortRequests = new ArrayList<>();
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        final CommonEntityRequestDTO cohortRequest = (CommonEntityRequestDTO) requestMessage.getObject();
        cohortRequest.setId(requestMessage.getJMSCorrelationID());
        cohortRequests.add(cohortRequest);
    }
    return cohortRequests;
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommonEntityRequestDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO 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)2 ArrayList (java.util.ArrayList)2 ObjectMessage (javax.jms.ObjectMessage)2 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)1 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)1 ServiceNotAvailableException (com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1 ImportedFile (com.odysseusinc.arachne.portal.util.ImportedFile)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1