Search in sources :

Example 1 with AllowCreateNewDevicesDeviceProfileProvisionConfiguration

use of org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration 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 AllowCreateNewDevicesDeviceProfileProvisionConfiguration

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

the class BaseEdgeTest method extendDeviceProfileData.

private void extendDeviceProfileData(DeviceProfile deviceProfile) {
    DeviceProfileData profileData = deviceProfile.getProfileData();
    List<DeviceProfileAlarm> alarms = new ArrayList<>();
    DeviceProfileAlarm deviceProfileAlarm = new DeviceProfileAlarm();
    deviceProfileAlarm.setAlarmType("High Temperature");
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setAlarmDetails("Alarm Details");
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setSpec(new SimpleAlarmConditionSpec());
    List<AlarmConditionFilter> condition = new ArrayList<>();
    AlarmConditionFilter alarmConditionFilter = new AlarmConditionFilter();
    alarmConditionFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.ATTRIBUTE, "temperature"));
    NumericFilterPredicate predicate = new NumericFilterPredicate();
    predicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    predicate.setValue(new FilterPredicateValue<>(55.0));
    alarmConditionFilter.setPredicate(predicate);
    alarmConditionFilter.setValueType(EntityKeyValueType.NUMERIC);
    condition.add(alarmConditionFilter);
    alarmCondition.setCondition(condition);
    alarmRule.setCondition(alarmCondition);
    deviceProfileAlarm.setClearRule(alarmRule);
    TreeMap<AlarmSeverity, AlarmRule> createRules = new TreeMap<>();
    createRules.put(AlarmSeverity.CRITICAL, alarmRule);
    deviceProfileAlarm.setCreateRules(createRules);
    alarms.add(deviceProfileAlarm);
    profileData.setAlarms(alarms);
    profileData.setProvisionConfiguration(new AllowCreateNewDevicesDeviceProfileProvisionConfiguration("123"));
}
Also used : AlarmSeverity(org.thingsboard.server.common.data.alarm.AlarmSeverity) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) ArrayList(java.util.ArrayList) SimpleAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.SimpleAlarmConditionSpec) TreeMap(java.util.TreeMap) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) AllowCreateNewDevicesDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)

Example 3 with AllowCreateNewDevicesDeviceProfileProvisionConfiguration

use of org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration 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

AllowCreateNewDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.AllowCreateNewDevicesDeviceProfileProvisionConfiguration)3 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)3 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)2 CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration (org.thingsboard.server.common.data.device.profile.CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration)2 DefaultDeviceProfileConfiguration (org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration)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 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 AlarmSeverity (org.thingsboard.server.common.data.alarm.AlarmSeverity)1 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)1 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)1 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)1 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)1 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