Search in sources :

Example 36 with DeviceProfile

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

the class DefaultTransportService method sendToRuleEngine.

private void sendToRuleEngine(TenantId tenantId, DeviceId deviceId, CustomerId customerId, TransportProtos.SessionInfoProto sessionInfo, JsonObject json, TbMsgMetaData metaData, SessionMsgType sessionMsgType, TbQueueCallback callback) {
    DeviceProfileId deviceProfileId = new DeviceProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
    DeviceProfile deviceProfile = deviceProfileCache.get(deviceProfileId);
    RuleChainId ruleChainId;
    String queueName;
    if (deviceProfile == null) {
        log.warn("[{}] Device profile is null!", deviceProfileId);
        ruleChainId = null;
        queueName = ServiceQueue.MAIN;
    } else {
        ruleChainId = deviceProfile.getDefaultRuleChainId();
        String defaultQueueName = deviceProfile.getDefaultQueueName();
        queueName = defaultQueueName != null ? defaultQueueName : ServiceQueue.MAIN;
    }
    TbMsg tbMsg = TbMsg.newMsg(queueName, sessionMsgType.name(), deviceId, customerId, metaData, gson.toJson(json), ruleChainId, null);
    sendToRuleEngine(tenantId, tbMsg, callback);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) ByteString(com.google.protobuf.ByteString) UUID(java.util.UUID) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Example 37 with DeviceProfile

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

the class DefaultTransportService method onDeviceUpdate.

private void onDeviceUpdate(Device device) {
    long deviceIdMSB = device.getId().getId().getMostSignificantBits();
    long deviceIdLSB = device.getId().getId().getLeastSignificantBits();
    long deviceProfileIdMSB = device.getDeviceProfileId().getId().getMostSignificantBits();
    long deviceProfileIdLSB = device.getDeviceProfileId().getId().getLeastSignificantBits();
    sessions.forEach((id, md) -> {
        if ((md.getSessionInfo().getDeviceIdMSB() == deviceIdMSB && md.getSessionInfo().getDeviceIdLSB() == deviceIdLSB)) {
            DeviceProfile newDeviceProfile;
            if (md.getSessionInfo().getDeviceProfileIdMSB() != deviceProfileIdMSB || md.getSessionInfo().getDeviceProfileIdLSB() != deviceProfileIdLSB) {
                // TODO: if transport types are different - we should close the session.
                newDeviceProfile = deviceProfileCache.get(new DeviceProfileId(new UUID(deviceProfileIdMSB, deviceProfileIdLSB)));
            } else {
                newDeviceProfile = null;
            }
            TransportProtos.SessionInfoProto newSessionInfo = TransportProtos.SessionInfoProto.newBuilder().mergeFrom(md.getSessionInfo()).setDeviceProfileIdMSB(deviceProfileIdMSB).setDeviceProfileIdLSB(deviceProfileIdLSB).setDeviceName(device.getName()).setDeviceType(device.getType()).build();
            if (device.getAdditionalInfo().has("gateway") && device.getAdditionalInfo().get("gateway").asBoolean() && device.getAdditionalInfo().has(OVERWRITE_ACTIVITY_TIME) && device.getAdditionalInfo().get(OVERWRITE_ACTIVITY_TIME).isBoolean()) {
                md.setOverwriteActivityTime(device.getAdditionalInfo().get(OVERWRITE_ACTIVITY_TIME).asBoolean());
            }
            md.setSessionInfo(newSessionInfo);
            transportCallbackExecutor.submit(() -> md.getListener().onDeviceUpdate(newSessionInfo, device, Optional.ofNullable(newDeviceProfile)));
        }
    });
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) UUID(java.util.UUID)

Example 38 with DeviceProfile

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

the class AbstractServiceTest method createDeviceProfile.

protected DeviceProfile createDeviceProfile(TenantId tenantId, String name) {
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setTenantId(tenantId);
    deviceProfile.setName(name);
    deviceProfile.setType(DeviceProfileType.DEFAULT);
    deviceProfile.setTransportType(DeviceTransportType.DEFAULT);
    deviceProfile.setDescription(name + " Test");
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    DefaultDeviceProfileConfiguration configuration = new DefaultDeviceProfileConfiguration();
    DefaultDeviceProfileTransportConfiguration transportConfiguration = new DefaultDeviceProfileTransportConfiguration();
    deviceProfileData.setConfiguration(configuration);
    deviceProfileData.setTransportConfiguration(transportConfiguration);
    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) DefaultDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileTransportConfiguration) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData)

Example 39 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testFindDeviceProfileInfoById.

@Test
public void testFindDeviceProfileInfoById() {
    DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
    DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
    DeviceProfileInfo foundDeviceProfileInfo = deviceProfileService.findDeviceProfileInfoById(tenantId, savedDeviceProfile.getId());
    Assert.assertNotNull(foundDeviceProfileInfo);
    Assert.assertEquals(savedDeviceProfile.getId(), foundDeviceProfileInfo.getId());
    Assert.assertEquals(savedDeviceProfile.getName(), foundDeviceProfileInfo.getName());
    Assert.assertEquals(savedDeviceProfile.getType(), foundDeviceProfileInfo.getType());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) Test(org.junit.Test)

Example 40 with DeviceProfile

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

the class BaseDeviceProfileServiceTest method testFindDefaultDeviceProfile.

@Test
public void testFindDefaultDeviceProfile() {
    DeviceProfile foundDefaultDeviceProfile = deviceProfileService.findDefaultDeviceProfile(tenantId);
    Assert.assertNotNull(foundDefaultDeviceProfile);
    Assert.assertNotNull(foundDefaultDeviceProfile.getId());
    Assert.assertNotNull(foundDefaultDeviceProfile.getName());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

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