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;
}
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;
}
Aggregations