Search in sources :

Example 1 with CommonEntityRequestObject

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

the class BaseDataNodeMessageServiceImpl method getListRequest.

@Override
public CommonListEntityRequest getListRequest(DN dataNode) throws JMSException {
    Map<String, CommonEntityRequestObject> requestMap = new LinkedHashMap<>();
    String requestQueue = getRequestQueueName(MessagingUtils.EntitiesList.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        requestMap.put(requestMessage.getJMSCorrelationID(), (CommonEntityRequestObject) requestMessage.getObject());
    }
    return new CommonListEntityRequest(requestMap);
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with CommonEntityRequestObject

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

the class BaseDataNodeMessageServiceImpl method getDataList.

@Override
@PreAuthorize("hasPermission(#dataNode, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).IMPORT_FROM_DATANODE)")
public <T extends CommonEntityDTO> List<T> getDataList(DN dataNode, CommonAnalysisType analysisType) throws JMSException {
    Long waitForResponse = messagingTimeout;
    Long messageLifeTime = messagingTimeout;
    // Get all Atlases available in user's tenant
    List<IAtlas> atlasList = atlasService.findAll().stream().filter(a -> a.getVersion() != null).collect(Collectors.toList());
    String baseQueue = MessagingUtils.EntitiesList.getBaseQueue(dataNode);
    ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, new CommonEntityRequestObject(atlasList.stream().map(IAtlas::getId).collect(Collectors.toList()), analysisType), baseQueue, waitForResponse, messageLifeTime);
    ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
    List<T> entityList = (List<T>) responseMessage.getObject();
    Map<Long, IAtlas> atlasMap = atlasList.stream().collect(Collectors.toMap(IAtlas::getId, a -> a));
    entityList.forEach(e -> e.setName(atlasMap.get(e.getOriginId()).getName() + ": " + e.getName()));
    return entityList;
}
Also used : CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) AtlasService(com.odysseusinc.arachne.portal.service.AtlasService) ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ObjectMessage(javax.jms.ObjectMessage) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) Collectors(java.util.stream.Collectors) JMSException(javax.jms.JMSException) CommonEntityDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) List(java.util.List) DataNode(com.odysseusinc.arachne.portal.model.DataNode) Map(java.util.Map) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) MessagingUtils.getRequestQueueName(com.odysseusinc.arachne.commons.service.messaging.MessagingUtils.getRequestQueueName) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) List(java.util.List) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

CommonEntityRequestObject (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject)2 CommonListEntityRequest (com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest)2 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)2 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)2 LinkedHashMap (java.util.LinkedHashMap)2 ObjectMessage (javax.jms.ObjectMessage)2 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 CommonEntityDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO)1 MessagingUtils.getRequestQueueName (com.odysseusinc.arachne.commons.service.messaging.MessagingUtils.getRequestQueueName)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1 IAtlas (com.odysseusinc.arachne.portal.model.IAtlas)1 AtlasService (com.odysseusinc.arachne.portal.service.AtlasService)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 JMSException (javax.jms.JMSException)1 Value (org.springframework.beans.factory.annotation.Value)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1