Search in sources :

Example 1 with JsonTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration in project thingsboard by thingsboard.

the class AbstractMqttIntegrationTest method createMqttDeviceProfile.

protected DeviceProfile createMqttDeviceProfile(TransportPayloadType transportPayloadType, String telemetryTopic, String attributesTopic, String telemetryProtoSchema, String attributesProtoSchema, String rpcResponseProtoSchema, String rpcRequestProtoSchema, String provisionKey, String provisionSecret, DeviceProfileProvisionType provisionType, boolean enableCompatibilityWithJsonPayloadFormat, boolean useJsonPayloadFormatForDefaultDownlinkTopics) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setName(transportPayloadType.name());
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setTransportType(DeviceTransportType.MQTT);
    deviceProfile.setProvisionType(provisionType);
    deviceProfile.setProvisionDeviceKey(provisionKey);
    deviceProfile.setDescription(transportPayloadType.name() + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = new MqttDeviceProfileTransportConfiguration();
    if (!StringUtils.isEmpty(telemetryTopic)) {
        mqttDeviceProfileTransportConfiguration.setDeviceTelemetryTopic(telemetryTopic);
    }
    if (!StringUtils.isEmpty(attributesTopic)) {
        mqttDeviceProfileTransportConfiguration.setDeviceAttributesTopic(attributesTopic);
    }
    TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
    if (TransportPayloadType.JSON.equals(transportPayloadType)) {
        transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
    } else {
        ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
        if (StringUtils.isEmpty(telemetryProtoSchema)) {
            telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(attributesProtoSchema)) {
            attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(rpcResponseProtoSchema)) {
            rpcResponseProtoSchema = DEVICE_RPC_RESPONSE_PROTO_SCHEMA;
        }
        if (StringUtils.isEmpty(rpcRequestProtoSchema)) {
            rpcRequestProtoSchema = DEVICE_RPC_REQUEST_PROTO_SCHEMA;
        }
        protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
        protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
        protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
        protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
        protoTransportPayloadConfiguration.setEnableCompatibilityWithJsonPayloadFormat(enableCompatibilityWithJsonPayloadFormat);
        protoTransportPayloadConfiguration.setUseJsonPayloadFormatForDefaultDownlinkTopics(enableCompatibilityWithJsonPayloadFormat && useJsonPayloadFormatForDefaultDownlinkTopics);
        transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
    }
    mqttDeviceProfileTransportConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
    deviceProfileData.setTransportConfiguration(mqttDeviceProfileTransportConfiguration);
    DeviceProfileProvisionConfiguration provisionConfiguration;
    switch(provisionType) {
        case ALLOW_CREATE_NEW_DEVICES:
            provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case CHECK_PRE_PROVISIONED_DEVICES:
            provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case DISABLED:
        default:
            provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret);
            break;
    }
    deviceProfileData.setProvisionConfiguration(provisionConfiguration);
    deviceProfileData.setConfiguration(configuration);
    deviceProfile.setProfileData(deviceProfileData);
    deviceProfile.setDefault(false);
    deviceProfile.setDefaultRuleChainId(null);
    return deviceProfile;
}
Also used : DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration) DeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) JsonTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration)

Example 2 with JsonTransportPayloadConfiguration

use of org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration in project thingsboard by thingsboard.

the class AbstractCoapIntegrationTest method createCoapDeviceProfile.

protected DeviceProfile createCoapDeviceProfile(TransportPayloadType transportPayloadType, CoapDeviceType coapDeviceType, String provisionSecret, DeviceProfileProvisionType provisionType, String provisionKey, String attributesProtoSchema, String telemetryProtoSchema, String rpcResponseProtoSchema, String rpcRequestProtoSchema) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setName(transportPayloadType.name());
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setProvisionType(provisionType);
    deviceProfile.setProvisionDeviceKey(provisionKey);
    deviceProfile.setDescription(transportPayloadType.name() + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    deviceProfile.setTransportType(DeviceTransportType.COAP);
    CoapDeviceProfileTransportConfiguration coapDeviceProfileTransportConfiguration = new CoapDeviceProfileTransportConfiguration();
    CoapDeviceTypeConfiguration coapDeviceTypeConfiguration;
    if (CoapDeviceType.DEFAULT.equals(coapDeviceType)) {
        DefaultCoapDeviceTypeConfiguration defaultCoapDeviceTypeConfiguration = new DefaultCoapDeviceTypeConfiguration();
        TransportPayloadTypeConfiguration transportPayloadTypeConfiguration;
        if (TransportPayloadType.PROTOBUF.equals(transportPayloadType)) {
            ProtoTransportPayloadConfiguration protoTransportPayloadConfiguration = new ProtoTransportPayloadConfiguration();
            if (StringUtils.isEmpty(telemetryProtoSchema)) {
                telemetryProtoSchema = DEVICE_TELEMETRY_PROTO_SCHEMA;
            }
            if (StringUtils.isEmpty(attributesProtoSchema)) {
                attributesProtoSchema = DEVICE_ATTRIBUTES_PROTO_SCHEMA;
            }
            if (StringUtils.isEmpty(rpcResponseProtoSchema)) {
                rpcResponseProtoSchema = DEVICE_RPC_RESPONSE_PROTO_SCHEMA;
            }
            if (StringUtils.isEmpty(rpcRequestProtoSchema)) {
                rpcRequestProtoSchema = DEVICE_RPC_REQUEST_PROTO_SCHEMA;
            }
            protoTransportPayloadConfiguration.setDeviceTelemetryProtoSchema(telemetryProtoSchema);
            protoTransportPayloadConfiguration.setDeviceAttributesProtoSchema(attributesProtoSchema);
            protoTransportPayloadConfiguration.setDeviceRpcResponseProtoSchema(rpcResponseProtoSchema);
            protoTransportPayloadConfiguration.setDeviceRpcRequestProtoSchema(rpcRequestProtoSchema);
            transportPayloadTypeConfiguration = protoTransportPayloadConfiguration;
        } else {
            transportPayloadTypeConfiguration = new JsonTransportPayloadConfiguration();
        }
        defaultCoapDeviceTypeConfiguration.setTransportPayloadTypeConfiguration(transportPayloadTypeConfiguration);
        coapDeviceTypeConfiguration = defaultCoapDeviceTypeConfiguration;
    } else {
        coapDeviceTypeConfiguration = new EfentoCoapDeviceTypeConfiguration();
    }
    coapDeviceProfileTransportConfiguration.setCoapDeviceTypeConfiguration(coapDeviceTypeConfiguration);
    deviceProfileData.setTransportConfiguration(coapDeviceProfileTransportConfiguration);
    DeviceProfileProvisionConfiguration provisionConfiguration;
    switch(provisionType) {
        case ALLOW_CREATE_NEW_DEVICES:
            provisionConfiguration = new AllowCreateNewDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case CHECK_PRE_PROVISIONED_DEVICES:
            provisionConfiguration = new CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(provisionSecret);
            break;
        case DISABLED:
        default:
            provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(provisionSecret);
            break;
    }
    deviceProfileData.setProvisionConfiguration(provisionConfiguration);
    deviceProfileData.setConfiguration(configuration);
    deviceProfile.setProfileData(deviceProfileData);
    deviceProfile.setDefault(false);
    deviceProfile.setDefaultRuleChainId(null);
    return deviceProfile;
}
Also used : DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) EfentoCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeConfiguration) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) JsonTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration) CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration) DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration) DeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) EfentoCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeConfiguration) CoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration) DefaultCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData)

Aggregations

DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)2 AllowCreateNewDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration)2 CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration)2 DefaultDeviceProfileConfiguration (org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration)2 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)2 DeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.DeviceProfileProvisionConfiguration)2 DisabledDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration)2 JsonTransportPayloadConfiguration (org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration)2 ProtoTransportPayloadConfiguration (org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration)2 TransportPayloadTypeConfiguration (org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration)2 CoapDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration)1 CoapDeviceTypeConfiguration (org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration)1 DefaultCoapDeviceTypeConfiguration (org.thingsboard.server.common.data.device.profile.DefaultCoapDeviceTypeConfiguration)1 EfentoCoapDeviceTypeConfiguration (org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeConfiguration)1 MqttDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration)1