Search in sources :

Example 1 with CommonEntityDTO

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

the class BaseDataNodeMessagingController method saveListResponse.

/**
 * Posts responses for for CommonEntity list requests
 * (for pushing by Node's back)
 */
@RequestMapping(value = "/api/v1/data-nodes/entity-lists/responses", method = POST)
public void saveListResponse(@RequestBody @Valid CommonListEntityResponseDTO commonListEntityResponseDTO, Principal principal) throws PermissionDeniedException {
    DataNode dataNode = getDatanode(principal);
    String responseQueue = getResponseQueueName(MessagingUtils.EntitiesList.getBaseQueue(dataNode));
    List<CommonEntityDTO> response = (List<CommonEntityDTO>) commonListEntityResponseDTO.getEntities();
    for (String correlationId : commonListEntityResponseDTO.getRequestIds()) {
        jmsTemplate.send(responseQueue, session -> {
            ObjectMessage message = session.createObjectMessage((Serializable) response);
            message.setJMSCorrelationID(correlationId);
            return message;
        });
    }
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CommonEntityDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CommonEntityDTO

use of com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO 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

CommonEntityDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO)2 DataNode (com.odysseusinc.arachne.portal.model.DataNode)2 List (java.util.List)2 ObjectMessage (javax.jms.ObjectMessage)2 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 CommonEntityRequestObject (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject)1 CommonListEntityRequest (com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest)1 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)1 MessagingUtils.getRequestQueueName (com.odysseusinc.arachne.commons.service.messaging.MessagingUtils.getRequestQueueName)1 ProducerConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate)1 IAtlas (com.odysseusinc.arachne.portal.model.IAtlas)1 AtlasService (com.odysseusinc.arachne.portal.service.AtlasService)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)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