Search in sources :

Example 1 with TransportApiRequestMsg

use of org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg in project thingsboard by thingsboard.

the class DefaultTransportApiService method handle.

@Override
public ListenableFuture<TbProtoQueueMsg<TransportApiResponseMsg>> handle(TbProtoQueueMsg<TransportApiRequestMsg> tbProtoQueueMsg) {
    TransportApiRequestMsg transportApiRequestMsg = tbProtoQueueMsg.getValue();
    ListenableFuture<TransportApiResponseMsg> result = null;
    if (transportApiRequestMsg.hasValidateTokenRequestMsg()) {
        ValidateDeviceTokenRequestMsg msg = transportApiRequestMsg.getValidateTokenRequestMsg();
        result = validateCredentials(msg.getToken(), DeviceCredentialsType.ACCESS_TOKEN);
    } else if (transportApiRequestMsg.hasValidateBasicMqttCredRequestMsg()) {
        TransportProtos.ValidateBasicMqttCredRequestMsg msg = transportApiRequestMsg.getValidateBasicMqttCredRequestMsg();
        result = validateCredentials(msg);
    } else if (transportApiRequestMsg.hasValidateX509CertRequestMsg()) {
        ValidateDeviceX509CertRequestMsg msg = transportApiRequestMsg.getValidateX509CertRequestMsg();
        result = validateCredentials(msg.getHash(), DeviceCredentialsType.X509_CERTIFICATE);
    } else if (transportApiRequestMsg.hasGetOrCreateDeviceRequestMsg()) {
        result = handle(transportApiRequestMsg.getGetOrCreateDeviceRequestMsg());
    } else if (transportApiRequestMsg.hasEntityProfileRequestMsg()) {
        result = handle(transportApiRequestMsg.getEntityProfileRequestMsg());
    } else if (transportApiRequestMsg.hasLwM2MRequestMsg()) {
        result = handle(transportApiRequestMsg.getLwM2MRequestMsg());
    } else if (transportApiRequestMsg.hasValidateDeviceLwM2MCredentialsRequestMsg()) {
        ValidateDeviceLwM2MCredentialsRequestMsg msg = transportApiRequestMsg.getValidateDeviceLwM2MCredentialsRequestMsg();
        result = validateCredentials(msg.getCredentialsId(), DeviceCredentialsType.LWM2M_CREDENTIALS);
    } else if (transportApiRequestMsg.hasProvisionDeviceRequestMsg()) {
        result = handle(transportApiRequestMsg.getProvisionDeviceRequestMsg());
    } else if (transportApiRequestMsg.hasResourceRequestMsg()) {
        result = handle(transportApiRequestMsg.getResourceRequestMsg());
    } else if (transportApiRequestMsg.hasSnmpDevicesRequestMsg()) {
        result = handle(transportApiRequestMsg.getSnmpDevicesRequestMsg());
    } else if (transportApiRequestMsg.hasDeviceRequestMsg()) {
        result = handle(transportApiRequestMsg.getDeviceRequestMsg());
    } else if (transportApiRequestMsg.hasDeviceCredentialsRequestMsg()) {
        result = handle(transportApiRequestMsg.getDeviceCredentialsRequestMsg());
    } else if (transportApiRequestMsg.hasOtaPackageRequestMsg()) {
        result = handle(transportApiRequestMsg.getOtaPackageRequestMsg());
    }
    return Futures.transform(Optional.ofNullable(result).orElseGet(this::getEmptyTransportApiResponseFuture), value -> new TbProtoQueueMsg<>(tbProtoQueueMsg.getKey(), value, tbProtoQueueMsg.getHeaders()), MoreExecutors.directExecutor());
}
Also used : ValidateDeviceLwM2MCredentialsRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg) TransportApiRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg) ValidateDeviceX509CertRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg) ValidateDeviceTokenRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg) TransportApiResponseMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg)

Example 2 with TransportApiRequestMsg

use of org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg 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)

Example 3 with TransportApiRequestMsg

use of org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg requestMsg, TransportServiceCallback<ValidateDeviceCredentialsResponse> callback) {
    log.trace("Processing msg: {}", requestMsg);
    TbProtoQueueMsg<TransportApiRequestMsg> protoMsg = new TbProtoQueueMsg<>(UUID.randomUUID(), TransportApiRequestMsg.newBuilder().setValidateDeviceLwM2MCredentialsRequestMsg(requestMsg).build());
    ListenableFuture<ValidateDeviceCredentialsResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.ValidateDeviceCredentialsResponseMsg msg = tmp.getValue().getValidateCredResponseMsg();
        ValidateDeviceCredentialsResponse.ValidateDeviceCredentialsResponseBuilder result = ValidateDeviceCredentialsResponse.builder();
        if (msg.hasDeviceInfo()) {
            result.credentials(msg.getCredentialsBody());
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (!profileBody.isEmpty()) {
                DeviceProfile profile = deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody);
                result.deviceProfile(profile);
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) 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) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)

Aggregations

TransportApiRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg)3 ByteString (com.google.protobuf.ByteString)2 TransportDeviceInfo (org.thingsboard.server.common.transport.auth.TransportDeviceInfo)2 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)2 TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)2 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)1 GetOrCreateDeviceFromGatewayResponse (org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse)1 ValidateDeviceCredentialsResponse (org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)1 TransportApiResponseMsg (org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg)1 ValidateDeviceLwM2MCredentialsRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg)1 ValidateDeviceTokenRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg)1 ValidateDeviceX509CertRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg)1