Search in sources :

Example 26 with DeviceProfile

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

the class BaseOtaPackageServiceTest method testDeleteFirmwareWithReferenceByDeviceProfile.

@Test
public void testDeleteFirmwareWithReferenceByDeviceProfile() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Test Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    OtaPackage firmware = new OtaPackage();
    firmware.setTenantId(tenantId);
    firmware.setDeviceProfileId(savedDeviceProfile.getId());
    firmware.setType(FIRMWARE);
    firmware.setTitle(TITLE);
    firmware.setVersion(VERSION);
    firmware.setFileName(FILE_NAME);
    firmware.setContentType(CONTENT_TYPE);
    firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
    firmware.setChecksum(CHECKSUM);
    firmware.setData(DATA);
    firmware.setDataSize(DATA_SIZE);
    OtaPackage savedFirmware = otaPackageService.saveOtaPackage(firmware);
    savedDeviceProfile.setFirmwareId(savedFirmware.getId());
    deviceProfileService.saveDeviceProfile(savedDeviceProfile);
    try {
        thrown.expect(DataValidationException.class);
        thrown.expectMessage("The otaPackage referenced by the device profile cannot be deleted!");
        otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
    } finally {
        deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
        otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) OtaPackage(org.thingsboard.server.common.data.OtaPackage) Test(org.junit.Test)

Example 27 with DeviceProfile

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

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

the class AbstractMqttIntegrationTest method processBeforeTest.

protected void processBeforeTest(String deviceName, String gatewayName, TransportPayloadType payloadType, String telemetryTopic, String attributesTopic, String telemetryProtoSchema, String attributesProtoSchema, String rpcResponseProtoSchema, String rpcRequestProtoSchema, String provisionKey, String provisionSecret, DeviceProfileProvisionType provisionType, boolean enableCompatibilityWithJsonPayloadFormat, boolean useJsonPayloadFormatForDefaultDownlinkTopics) throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(savedTenant.getId());
    tenantAdmin.setEmail("tenant" + atomicInteger.getAndIncrement() + "@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
    Device device = new Device();
    device.setName(deviceName);
    device.setType("default");
    Device gateway = new Device();
    gateway.setName(gatewayName);
    gateway.setType("default");
    ObjectNode additionalInfo = mapper.createObjectNode();
    additionalInfo.put("gateway", true);
    gateway.setAdditionalInfo(additionalInfo);
    if (payloadType != null) {
        DeviceProfile mqttDeviceProfile = createMqttDeviceProfile(payloadType, telemetryTopic, attributesTopic, telemetryProtoSchema, attributesProtoSchema, rpcResponseProtoSchema, rpcRequestProtoSchema, provisionKey, provisionSecret, provisionType, enableCompatibilityWithJsonPayloadFormat, useJsonPayloadFormatForDefaultDownlinkTopics);
        deviceProfile = doPost("/api/deviceProfile", mqttDeviceProfile, DeviceProfile.class);
        device.setType(deviceProfile.getName());
        device.setDeviceProfileId(deviceProfile.getId());
        gateway.setType(deviceProfile.getName());
        gateway.setDeviceProfileId(deviceProfile.getId());
    }
    savedDevice = doPost("/api/device", device, Device.class);
    DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    savedGateway = doPost("/api/device", gateway, Device.class);
    DeviceCredentials gatewayCredentials = doGet("/api/device/" + savedGateway.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    assertEquals(savedDevice.getId(), deviceCredentials.getDeviceId());
    accessToken = deviceCredentials.getCredentialsId();
    assertNotNull(accessToken);
    assertEquals(savedGateway.getId(), gatewayCredentials.getDeviceId());
    gatewayAccessToken = gatewayCredentials.getCredentialsId();
    assertNotNull(gatewayAccessToken);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.thingsboard.server.common.data.Device) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 29 with DeviceProfile

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

the class JpaDeviceProfileDao method saveAndFlush.

@Transactional
@Override
public DeviceProfile saveAndFlush(TenantId tenantId, DeviceProfile deviceProfile) {
    DeviceProfile result = save(tenantId, deviceProfile);
    deviceProfileRepository.flush();
    return result;
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with DeviceProfile

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

the class TelemetryEdgeProcessor method getDefaultQueueNameAndRuleChainId.

private Pair<String, RuleChainId> getDefaultQueueNameAndRuleChainId(TenantId tenantId, EntityId entityId) {
    if (EntityType.DEVICE.equals(entityId.getEntityType())) {
        DeviceProfile deviceProfile = deviceProfileCache.get(tenantId, new DeviceId(entityId.getId()));
        RuleChainId ruleChainId;
        String queueName;
        if (deviceProfile == null) {
            log.warn("[{}] Device profile is null!", entityId);
            ruleChainId = null;
            queueName = ServiceQueue.MAIN;
        } else {
            ruleChainId = deviceProfile.getDefaultRuleChainId();
            String defaultQueueName = deviceProfile.getDefaultQueueName();
            queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
        }
        return new ImmutablePair<>(queueName, ruleChainId);
    } else {
        return new ImmutablePair<>(ServiceQueue.MAIN, null);
    }
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DeviceId(org.thingsboard.server.common.data.id.DeviceId) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId)

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