Search in sources :

Example 1 with GetOrCreateDeviceFromGatewayResponse

use of org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg requestMsg, TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse> callback) {
    TbProtoQueueMsg<TransportApiRequestMsg> protoMsg = new TbProtoQueueMsg<>(UUID.randomUUID(), TransportApiRequestMsg.newBuilder().setGetOrCreateDeviceRequestMsg(requestMsg).build());
    log.trace("Processing msg: {}", requestMsg);
    ListenableFuture<GetOrCreateDeviceFromGatewayResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.GetOrCreateDeviceFromGatewayResponseMsg msg = tmp.getValue().getGetOrCreateDeviceResponseMsg();
        GetOrCreateDeviceFromGatewayResponse.GetOrCreateDeviceFromGatewayResponseBuilder result = GetOrCreateDeviceFromGatewayResponse.builder();
        if (msg.hasDeviceInfo()) {
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (profileBody != null && !profileBody.isEmpty()) {
                result.deviceProfile(deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody));
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : GetOrCreateDeviceFromGatewayResponse(org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse) TransportApiRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) ByteString(com.google.protobuf.ByteString) TbProtoQueueMsg(org.thingsboard.server.queue.common.TbProtoQueueMsg) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Aggregations

ByteString (com.google.protobuf.ByteString)1 GetOrCreateDeviceFromGatewayResponse (org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse)1 TransportDeviceInfo (org.thingsboard.server.common.transport.auth.TransportDeviceInfo)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 TransportApiRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg)1 TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)1