Search in sources :

Example 61 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DefaultSystemDataLoaderService method loadDemoData.

@Override
public void loadDemoData() throws Exception {
    Tenant demoTenant = new Tenant();
    demoTenant.setRegion("Global");
    demoTenant.setTitle("Tenant");
    demoTenant = tenantService.saveTenant(demoTenant);
    installScripts.loadDemoRuleChains(demoTenant.getId());
    createUser(Authority.TENANT_ADMIN, demoTenant.getId(), null, "tenant@thingsboard.org", "tenant");
    Customer customerA = new Customer();
    customerA.setTenantId(demoTenant.getId());
    customerA.setTitle("Customer A");
    customerA = customerService.saveCustomer(customerA);
    Customer customerB = new Customer();
    customerB.setTenantId(demoTenant.getId());
    customerB.setTitle("Customer B");
    customerB = customerService.saveCustomer(customerB);
    Customer customerC = new Customer();
    customerC.setTenantId(demoTenant.getId());
    customerC.setTitle("Customer C");
    customerC = customerService.saveCustomer(customerC);
    createUser(Authority.CUSTOMER_USER, demoTenant.getId(), customerA.getId(), "customer@thingsboard.org", CUSTOMER_CRED);
    createUser(Authority.CUSTOMER_USER, demoTenant.getId(), customerA.getId(), "customerA@thingsboard.org", CUSTOMER_CRED);
    createUser(Authority.CUSTOMER_USER, demoTenant.getId(), customerB.getId(), "customerB@thingsboard.org", CUSTOMER_CRED);
    createUser(Authority.CUSTOMER_USER, demoTenant.getId(), customerC.getId(), "customerC@thingsboard.org", CUSTOMER_CRED);
    DeviceProfile defaultDeviceProfile = this.deviceProfileService.findOrCreateDeviceProfile(demoTenant.getId(), DEFAULT_DEVICE_TYPE);
    createDevice(demoTenant.getId(), customerA.getId(), defaultDeviceProfile.getId(), "Test Device A1", "A1_TEST_TOKEN", null);
    createDevice(demoTenant.getId(), customerA.getId(), defaultDeviceProfile.getId(), "Test Device A2", "A2_TEST_TOKEN", null);
    createDevice(demoTenant.getId(), customerA.getId(), defaultDeviceProfile.getId(), "Test Device A3", "A3_TEST_TOKEN", null);
    createDevice(demoTenant.getId(), customerB.getId(), defaultDeviceProfile.getId(), "Test Device B1", "B1_TEST_TOKEN", null);
    createDevice(demoTenant.getId(), customerC.getId(), defaultDeviceProfile.getId(), "Test Device C1", "C1_TEST_TOKEN", null);
    createDevice(demoTenant.getId(), null, defaultDeviceProfile.getId(), "DHT11 Demo Device", "DHT11_DEMO_TOKEN", "Demo device that is used in sample " + "applications that upload data from DHT11 temperature and humidity sensor");
    createDevice(demoTenant.getId(), null, defaultDeviceProfile.getId(), "Raspberry Pi Demo Device", "RASPBERRY_PI_DEMO_TOKEN", "Demo device that is used in " + "Raspberry Pi GPIO control sample application");
    DeviceProfile thermostatDeviceProfile = new DeviceProfile();
    thermostatDeviceProfile.setTenantId(demoTenant.getId());
    thermostatDeviceProfile.setDefault(false);
    thermostatDeviceProfile.setName("thermostat");
    thermostatDeviceProfile.setType(DeviceProfileType.DEFAULT);
    thermostatDeviceProfile.setTransportType(DeviceTransportType.DEFAULT);
    thermostatDeviceProfile.setProvisionType(DeviceProfileProvisionType.DISABLED);
    thermostatDeviceProfile.setDescription("Thermostat device profile");
    thermostatDeviceProfile.setDefaultRuleChainId(ruleChainService.findTenantRuleChainsByType(demoTenant.getId(), RuleChainType.CORE, new PageLink(1, 0, "Thermostat")).getData().get(0).getId());
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    DefaultDeviceProfileTransportConfiguration transportConfiguration = new DefaultDeviceProfileTransportConfiguration();
    DisabledDeviceProfileProvisionConfiguration provisionConfiguration = new DisabledDeviceProfileProvisionConfiguration(null);
    deviceProfileData.setConfiguration(configuration);
    deviceProfileData.setTransportConfiguration(transportConfiguration);
    deviceProfileData.setProvisionConfiguration(provisionConfiguration);
    thermostatDeviceProfile.setProfileData(deviceProfileData);
    DeviceProfileAlarm highTemperature = new DeviceProfileAlarm();
    highTemperature.setId("highTemperatureAlarmID");
    highTemperature.setAlarmType("High Temperature");
    AlarmRule temperatureRule = new AlarmRule();
    AlarmCondition temperatureCondition = new AlarmCondition();
    temperatureCondition.setSpec(new SimpleAlarmConditionSpec());
    AlarmConditionFilter temperatureAlarmFlagAttributeFilter = new AlarmConditionFilter();
    temperatureAlarmFlagAttributeFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.ATTRIBUTE, "temperatureAlarmFlag"));
    temperatureAlarmFlagAttributeFilter.setValueType(EntityKeyValueType.BOOLEAN);
    BooleanFilterPredicate temperatureAlarmFlagAttributePredicate = new BooleanFilterPredicate();
    temperatureAlarmFlagAttributePredicate.setOperation(BooleanFilterPredicate.BooleanOperation.EQUAL);
    temperatureAlarmFlagAttributePredicate.setValue(new FilterPredicateValue<>(Boolean.TRUE));
    temperatureAlarmFlagAttributeFilter.setPredicate(temperatureAlarmFlagAttributePredicate);
    AlarmConditionFilter temperatureTimeseriesFilter = new AlarmConditionFilter();
    temperatureTimeseriesFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    temperatureTimeseriesFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate temperatureTimeseriesFilterPredicate = new NumericFilterPredicate();
    temperatureTimeseriesFilterPredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    FilterPredicateValue<Double> temperatureTimeseriesPredicateValue = new FilterPredicateValue<>(25.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "temperatureAlarmThreshold"));
    temperatureTimeseriesFilterPredicate.setValue(temperatureTimeseriesPredicateValue);
    temperatureTimeseriesFilter.setPredicate(temperatureTimeseriesFilterPredicate);
    temperatureCondition.setCondition(Arrays.asList(temperatureAlarmFlagAttributeFilter, temperatureTimeseriesFilter));
    temperatureRule.setAlarmDetails("Current temperature = ${temperature}");
    temperatureRule.setCondition(temperatureCondition);
    highTemperature.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.MAJOR, temperatureRule)));
    AlarmRule clearTemperatureRule = new AlarmRule();
    AlarmCondition clearTemperatureCondition = new AlarmCondition();
    clearTemperatureCondition.setSpec(new SimpleAlarmConditionSpec());
    AlarmConditionFilter clearTemperatureTimeseriesFilter = new AlarmConditionFilter();
    clearTemperatureTimeseriesFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    clearTemperatureTimeseriesFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate clearTemperatureTimeseriesFilterPredicate = new NumericFilterPredicate();
    clearTemperatureTimeseriesFilterPredicate.setOperation(NumericFilterPredicate.NumericOperation.LESS_OR_EQUAL);
    FilterPredicateValue<Double> clearTemperatureTimeseriesPredicateValue = new FilterPredicateValue<>(25.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "temperatureAlarmThreshold"));
    clearTemperatureTimeseriesFilterPredicate.setValue(clearTemperatureTimeseriesPredicateValue);
    clearTemperatureTimeseriesFilter.setPredicate(clearTemperatureTimeseriesFilterPredicate);
    clearTemperatureCondition.setCondition(Collections.singletonList(clearTemperatureTimeseriesFilter));
    clearTemperatureRule.setCondition(clearTemperatureCondition);
    clearTemperatureRule.setAlarmDetails("Current temperature = ${temperature}");
    highTemperature.setClearRule(clearTemperatureRule);
    DeviceProfileAlarm lowHumidity = new DeviceProfileAlarm();
    lowHumidity.setId("lowHumidityAlarmID");
    lowHumidity.setAlarmType("Low Humidity");
    AlarmRule humidityRule = new AlarmRule();
    AlarmCondition humidityCondition = new AlarmCondition();
    humidityCondition.setSpec(new SimpleAlarmConditionSpec());
    AlarmConditionFilter humidityAlarmFlagAttributeFilter = new AlarmConditionFilter();
    humidityAlarmFlagAttributeFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.ATTRIBUTE, "humidityAlarmFlag"));
    humidityAlarmFlagAttributeFilter.setValueType(EntityKeyValueType.BOOLEAN);
    BooleanFilterPredicate humidityAlarmFlagAttributePredicate = new BooleanFilterPredicate();
    humidityAlarmFlagAttributePredicate.setOperation(BooleanFilterPredicate.BooleanOperation.EQUAL);
    humidityAlarmFlagAttributePredicate.setValue(new FilterPredicateValue<>(Boolean.TRUE));
    humidityAlarmFlagAttributeFilter.setPredicate(humidityAlarmFlagAttributePredicate);
    AlarmConditionFilter humidityTimeseriesFilter = new AlarmConditionFilter();
    humidityTimeseriesFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "humidity"));
    humidityTimeseriesFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate humidityTimeseriesFilterPredicate = new NumericFilterPredicate();
    humidityTimeseriesFilterPredicate.setOperation(NumericFilterPredicate.NumericOperation.LESS);
    FilterPredicateValue<Double> humidityTimeseriesPredicateValue = new FilterPredicateValue<>(60.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "humidityAlarmThreshold"));
    humidityTimeseriesFilterPredicate.setValue(humidityTimeseriesPredicateValue);
    humidityTimeseriesFilter.setPredicate(humidityTimeseriesFilterPredicate);
    humidityCondition.setCondition(Arrays.asList(humidityAlarmFlagAttributeFilter, humidityTimeseriesFilter));
    humidityRule.setCondition(humidityCondition);
    humidityRule.setAlarmDetails("Current humidity = ${humidity}");
    lowHumidity.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.MINOR, humidityRule)));
    AlarmRule clearHumidityRule = new AlarmRule();
    AlarmCondition clearHumidityCondition = new AlarmCondition();
    clearHumidityCondition.setSpec(new SimpleAlarmConditionSpec());
    AlarmConditionFilter clearHumidityTimeseriesFilter = new AlarmConditionFilter();
    clearHumidityTimeseriesFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "humidity"));
    clearHumidityTimeseriesFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate clearHumidityTimeseriesFilterPredicate = new NumericFilterPredicate();
    clearHumidityTimeseriesFilterPredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER_OR_EQUAL);
    FilterPredicateValue<Double> clearHumidityTimeseriesPredicateValue = new FilterPredicateValue<>(60.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "humidityAlarmThreshold"));
    clearHumidityTimeseriesFilterPredicate.setValue(clearHumidityTimeseriesPredicateValue);
    clearHumidityTimeseriesFilter.setPredicate(clearHumidityTimeseriesFilterPredicate);
    clearHumidityCondition.setCondition(Collections.singletonList(clearHumidityTimeseriesFilter));
    clearHumidityRule.setCondition(clearHumidityCondition);
    clearHumidityRule.setAlarmDetails("Current humidity = ${humidity}");
    lowHumidity.setClearRule(clearHumidityRule);
    deviceProfileData.setAlarms(Arrays.asList(highTemperature, lowHumidity));
    DeviceProfile savedThermostatDeviceProfile = deviceProfileService.saveDeviceProfile(thermostatDeviceProfile);
    DeviceId t1Id = createDevice(demoTenant.getId(), null, savedThermostatDeviceProfile.getId(), "Thermostat T1", "T1_TEST_TOKEN", "Demo device for Thermostats dashboard").getId();
    DeviceId t2Id = createDevice(demoTenant.getId(), null, savedThermostatDeviceProfile.getId(), "Thermostat T2", "T2_TEST_TOKEN", "Demo device for Thermostats dashboard").getId();
    attributesService.save(demoTenant.getId(), t1Id, DataConstants.SERVER_SCOPE, Arrays.asList(new BaseAttributeKvEntry(System.currentTimeMillis(), new DoubleDataEntry("latitude", 37.3948)), new BaseAttributeKvEntry(System.currentTimeMillis(), new DoubleDataEntry("longitude", -122.1503)), new BaseAttributeKvEntry(System.currentTimeMillis(), new BooleanDataEntry("temperatureAlarmFlag", true)), new BaseAttributeKvEntry(System.currentTimeMillis(), new BooleanDataEntry("humidityAlarmFlag", true)), new BaseAttributeKvEntry(System.currentTimeMillis(), new LongDataEntry("temperatureAlarmThreshold", (long) 20)), new BaseAttributeKvEntry(System.currentTimeMillis(), new LongDataEntry("humidityAlarmThreshold", (long) 50))));
    attributesService.save(demoTenant.getId(), t2Id, DataConstants.SERVER_SCOPE, Arrays.asList(new BaseAttributeKvEntry(System.currentTimeMillis(), new DoubleDataEntry("latitude", 37.493801)), new BaseAttributeKvEntry(System.currentTimeMillis(), new DoubleDataEntry("longitude", -121.948769)), new BaseAttributeKvEntry(System.currentTimeMillis(), new BooleanDataEntry("temperatureAlarmFlag", true)), new BaseAttributeKvEntry(System.currentTimeMillis(), new BooleanDataEntry("humidityAlarmFlag", true)), new BaseAttributeKvEntry(System.currentTimeMillis(), new LongDataEntry("temperatureAlarmThreshold", (long) 25)), new BaseAttributeKvEntry(System.currentTimeMillis(), new LongDataEntry("humidityAlarmThreshold", (long) 30))));
    installScripts.loadDashboards(demoTenant.getId(), null);
}
Also used : BooleanFilterPredicate(org.thingsboard.server.common.data.query.BooleanFilterPredicate) Customer(org.thingsboard.server.common.data.Customer) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) DeviceId(org.thingsboard.server.common.data.id.DeviceId) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) DisabledDeviceProfileProvisionConfiguration(org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Tenant(org.thingsboard.server.common.data.Tenant) DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) PageLink(org.thingsboard.server.common.data.page.PageLink) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) SimpleAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.SimpleAlarmConditionSpec) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) DefaultDeviceProfileConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DefaultDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Example 62 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class DeviceProfileEdgeProcessor method processDeviceProfileToEdge.

public DownlinkMsg processDeviceProfileToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
    DeviceProfileId deviceProfileId = new DeviceProfileId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(action) {
        case ADDED:
        case UPDATED:
            DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(edgeEvent.getTenantId(), deviceProfileId);
            if (deviceProfile != null) {
                DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileMsgConstructor.constructDeviceProfileUpdatedMsg(msgType, deviceProfile);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceProfileUpdateMsg(deviceProfileUpdateMsg).build();
            }
            break;
        case DELETED:
            DeviceProfileUpdateMsg deviceProfileUpdateMsg = deviceProfileMsgConstructor.constructDeviceProfileDeleteMsg(deviceProfileId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceProfileUpdateMsg(deviceProfileUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileUpdateMsg(org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId)

Example 63 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class TbCoapDtlsCertificateVerifier method verifyCertificate.

@Override
public CertificateVerificationResult verifyCertificate(ConnectionId cid, ServerNames serverName, InetSocketAddress remotePeer, boolean clientUsage, boolean verifySubject, boolean truncateCertificatePath, CertificateMessage message) {
    try {
        CertPath certpath = message.getCertificateChain();
        X509Certificate[] chain = certpath.getCertificates().toArray(new X509Certificate[0]);
        for (X509Certificate cert : chain) {
            try {
                if (!skipValidityCheckForClientCert) {
                    cert.checkValidity();
                }
                String strCert = SslUtil.getCertificateString(cert);
                String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
                final ValidateDeviceCredentialsResponse[] deviceCredentialsResponse = new ValidateDeviceCredentialsResponse[1];
                CountDownLatch latch = new CountDownLatch(1);
                transportService.process(DeviceTransportType.COAP, TransportProtos.ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(), new TransportServiceCallback<>() {

                    @Override
                    public void onSuccess(ValidateDeviceCredentialsResponse msg) {
                        if (!StringUtils.isEmpty(msg.getCredentials())) {
                            deviceCredentialsResponse[0] = msg;
                        }
                        latch.countDown();
                    }

                    @Override
                    public void onError(Throwable e) {
                        log.error(e.getMessage(), e);
                        latch.countDown();
                    }
                });
                latch.await(10, TimeUnit.SECONDS);
                ValidateDeviceCredentialsResponse msg = deviceCredentialsResponse[0];
                if (msg != null && strCert.equals(msg.getCredentials())) {
                    DeviceProfile deviceProfile = msg.getDeviceProfile();
                    if (msg.hasDeviceInfo() && deviceProfile != null) {
                        tbCoapDtlsSessionInMemoryStorage.put(remotePeer, new TbCoapDtlsSessionInfo(msg, deviceProfile));
                    }
                    break;
                }
            } catch (InterruptedException | CertificateEncodingException | CertificateExpiredException | CertificateNotYetValidException e) {
                log.error(e.getMessage(), e);
                AlertMessage alert = new AlertMessage(AlertMessage.AlertLevel.FATAL, AlertMessage.AlertDescription.BAD_CERTIFICATE);
                throw new HandshakeException("Certificate chain could not be validated", alert);
            }
        }
        return new CertificateVerificationResult(cid, certpath, null);
    } catch (HandshakeException e) {
        log.trace("Certificate validation failed!", e);
        return new CertificateVerificationResult(cid, e, null);
    }
}
Also used : CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateExpiredException(java.security.cert.CertificateExpiredException) CertificateEncodingException(java.security.cert.CertificateEncodingException) CountDownLatch(java.util.concurrent.CountDownLatch) X509Certificate(java.security.cert.X509Certificate) CertificateVerificationResult(org.eclipse.californium.scandium.dtls.CertificateVerificationResult) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) CertPath(java.security.cert.CertPath) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse) HandshakeException(org.eclipse.californium.scandium.dtls.HandshakeException) AlertMessage(org.eclipse.californium.scandium.dtls.AlertMessage)

Example 64 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile 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)

Example 65 with DeviceProfile

use of org.thingsboard.server.common.data.DeviceProfile in project thingsboard by thingsboard.

the class BaseController method checkDeviceProfileId.

DeviceProfile checkDeviceProfileId(DeviceProfileId deviceProfileId, Operation operation) throws ThingsboardException {
    try {
        validateId(deviceProfileId, "Incorrect deviceProfileId " + deviceProfileId);
        DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(getCurrentUser().getTenantId(), deviceProfileId);
        checkNotNull(deviceProfile, "Device profile with id [" + deviceProfileId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE_PROFILE, operation, deviceProfileId, deviceProfile);
        return deviceProfile;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)110 Test (org.junit.Test)48 Device (org.thingsboard.server.common.data.Device)30 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)26 List (java.util.List)20 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)19 TbMsg (org.thingsboard.server.common.msg.TbMsg)19 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)18 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)18 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)17 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)17 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)16 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)16 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)16 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)14 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)13 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13 AttributeKvEntity (org.thingsboard.server.dao.model.sql.AttributeKvEntity)13 UUID (java.util.UUID)12