Search in sources :

Example 1 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method saveCommonEntity.

private void saveCommonEntity(Principal principal, String id, Serializable object) throws PermissionDeniedException {
    DataNode dataNode = getDatanode(principal);
    String queueBase = MessagingUtils.Entities.getBaseQueue(dataNode);
    String responseQueue = getResponseQueueName(queueBase);
    jmsTemplate.send(responseQueue, session -> {
        ObjectMessage message = session.createObjectMessage(object);
        message.setJMSCorrelationID(id);
        return message;
    });
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage)

Example 2 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode 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 3 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode 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 4 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method addCommonEntityToAnalysis.

@ApiOperation("Add common entity to analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities", method = POST)
public JsonResult addCommonEntityToAnalysis(@PathVariable("analysisId") Long analysisId, @RequestBody @Valid DataReferenceDTO entityReference, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws NotExistException, JMSException, IOException, PermissionDeniedException, URISyntaxException {
    final IUser user = getUser(principal);
    final DataNode dataNode = dataNodeService.getById(entityReference.getDataNodeId());
    final T analysis = analysisService.getById(analysisId);
    final DataReference dataReference = dataReferenceService.addOrUpdate(entityReference.getEntityGuid(), dataNode);
    final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataNode, analysisType);
    doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
    return new JsonResult(NO_ERROR);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataNode(com.odysseusinc.arachne.portal.model.DataNode) IUser(com.odysseusinc.arachne.portal.model.IUser) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DataNode

use of com.odysseusinc.arachne.portal.model.DataNode in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeController method createDataSource.

@ApiOperation("Create new data source of datanode.")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}/data-sources", method = RequestMethod.POST)
public JsonResult createDataSource(@PathVariable("dataNodeId") Long id, @RequestBody C_DS_DTO commonDataSourceDTO) throws FieldException, NotExistException, ValidationException, IOException, SolrServerException, NoSuchFieldException, IllegalAccessException, BindException {
    // we validate only two fields, because we don't want to validate another fields, because they always are null
    validate(commonDataSourceDTO);
    JsonResult<CommonDataSourceDTO> result;
    DataNode dataNode = baseDataNodeService.getById(id);
    if (dataNode == null) {
        throw new IllegalArgumentException("Unable to find datanode by ID " + id);
    }
    DS dataSource = convertCommonDataSourceDtoToDataSource(commonDataSourceDTO);
    dataSource.setDataNode(dataNode);
    dataSource = dataSourceService.createOrRestoreDataSource(dataSource);
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(genericConversionService.convert(dataSource, CommonDataSourceDTO.class));
    return result;
}
Also used : CommonDataSourceDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataNode (com.odysseusinc.arachne.portal.model.DataNode)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ApiOperation (io.swagger.annotations.ApiOperation)5 ObjectMessage (javax.jms.ObjectMessage)4 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)3 IUser (com.odysseusinc.arachne.portal.model.IUser)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 CommonEntityDTO (com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO)2 ConsumerTemplate (com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate)2 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)2 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)2 Study (com.odysseusinc.arachne.portal.model.Study)2 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)2 List (java.util.List)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1