Search in sources :

Example 71 with DeviceProfile

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

the class BaseDeviceProfileControllerTest method testFindDeviceProfileInfos.

@Test
public void testFindDeviceProfileInfos() throws Exception {
    List<DeviceProfile> deviceProfiles = new ArrayList<>();
    PageLink pageLink = new PageLink(17);
    PageData<DeviceProfile> deviceProfilePageData = doGetTypedWithPageLink("/api/deviceProfiles?", new TypeReference<PageData<DeviceProfile>>() {
    }, pageLink);
    Assert.assertFalse(deviceProfilePageData.hasNext());
    Assert.assertEquals(1, deviceProfilePageData.getTotalElements());
    deviceProfiles.addAll(deviceProfilePageData.getData());
    for (int i = 0; i < 28; i++) {
        DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile" + i, null);
        deviceProfiles.add(doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class));
    }
    List<DeviceProfileInfo> loadedDeviceProfileInfos = new ArrayList<>();
    pageLink = new PageLink(17);
    PageData<DeviceProfileInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", new TypeReference<PageData<DeviceProfileInfo>>() {
        }, pageLink);
        loadedDeviceProfileInfos.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(deviceProfiles, idComparator);
    Collections.sort(loadedDeviceProfileInfos, deviceProfileInfoIdComparator);
    List<DeviceProfileInfo> deviceProfileInfos = deviceProfiles.stream().map(deviceProfile -> new DeviceProfileInfo(deviceProfile.getId(), deviceProfile.getName(), deviceProfile.getImage(), deviceProfile.getDefaultDashboardId(), deviceProfile.getType(), deviceProfile.getTransportType())).collect(Collectors.toList());
    Assert.assertEquals(deviceProfileInfos, loadedDeviceProfileInfos);
    for (DeviceProfile deviceProfile : deviceProfiles) {
        if (!deviceProfile.isDefault()) {
            doDelete("/api/deviceProfile/" + deviceProfile.getId().getId().toString()).andExpect(status().isOk());
        }
    }
    pageLink = new PageLink(17);
    pageData = doGetTypedWithPageLink("/api/deviceProfileInfos?", new TypeReference<PageData<DeviceProfileInfo>>() {
    }, pageLink);
    Assert.assertFalse(pageData.hasNext());
    Assert.assertEquals(1, pageData.getTotalElements());
}
Also used : DeviceProfileType(org.thingsboard.server.common.data.DeviceProfileType) DynamicMessage(com.google.protobuf.DynamicMessage) Descriptors(com.google.protobuf.Descriptors) Device(org.thingsboard.server.common.data.Device) Tenant(org.thingsboard.server.common.data.Tenant) ArrayList(java.util.ArrayList) User(org.thingsboard.server.common.data.User) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) After(org.junit.After) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DeviceProfileProvisionType(org.thingsboard.server.common.data.DeviceProfileProvisionType) Before(org.junit.Before) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) PageLink(org.thingsboard.server.common.data.page.PageLink) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProtoTransportPayloadConfiguration(org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration) Authority(org.thingsboard.server.common.data.security.Authority) Collectors(java.util.stream.Collectors) List(java.util.List) JsonFormat(com.google.protobuf.util.JsonFormat) Ignore(org.junit.Ignore) DynamicSchema(com.github.os72.protobuf.dynamic.DynamicSchema) PageData(org.thingsboard.server.common.data.page.PageData) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Assert(org.junit.Assert) MqttDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration) TransportPayloadTypeConfiguration(org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) DeviceProfileInfo(org.thingsboard.server.common.data.DeviceProfileInfo) ArrayList(java.util.ArrayList) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) PageData(org.thingsboard.server.common.data.page.PageData) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 72 with DeviceProfile

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

the class BaseDeviceProfileControllerTest method testChangeDeviceProfileTransportTypeWithExistingDevices.

@Test
public void testChangeDeviceProfileTransportTypeWithExistingDevices() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    Device device = new Device();
    device.setName("Test device");
    device.setType("default");
    device.setDeviceProfileId(savedDeviceProfile.getId());
    doPost("/api/device", device, Device.class);
    savedDeviceProfile.setTransportType(DeviceTransportType.MQTT);
    doPost("/api/deviceProfile", savedDeviceProfile).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Can't change device profile transport type because devices referenced it")));
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Device(org.thingsboard.server.common.data.Device) Test(org.junit.Test)

Example 73 with DeviceProfile

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

the class BaseDeviceProfileControllerTest method testDeleteDeviceProfile.

@Test
public void testDeleteDeviceProfile() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    doDelete("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()).andExpect(status().isOk());
    doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString()).andExpect(status().isNotFound());
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 74 with DeviceProfile

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

the class BaseDeviceProfileControllerTest method testFindDeviceProfileById.

@Test
public void testFindDeviceProfileById() throws Exception {
    DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", null);
    DeviceProfile savedDeviceProfile = doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class);
    DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + savedDeviceProfile.getId().getId().toString(), DeviceProfile.class);
    Assert.assertNotNull(foundDeviceProfile);
    Assert.assertEquals(savedDeviceProfile, foundDeviceProfile);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) Test(org.junit.Test)

Example 75 with DeviceProfile

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

the class CoapEfentoTransportResource method processMeasurementsRequest.

private void processMeasurementsRequest(CoapExchange exchange, Request request) {
    byte[] bytes = request.getPayload();
    try {
        MeasurementsProtos.ProtoMeasurements protoMeasurements = MeasurementsProtos.ProtoMeasurements.parseFrom(bytes);
        log.trace("Successfully parsed Efento ProtoMeasurements: [{}]", protoMeasurements.getCloudToken());
        String token = protoMeasurements.getCloudToken();
        transportService.process(DeviceTransportType.COAP, TransportProtos.ValidateDeviceTokenRequestMsg.newBuilder().setToken(token).build(), new CoapDeviceAuthCallback(exchange, (msg, deviceProfile) -> {
            TransportProtos.SessionInfoProto sessionInfo = SessionInfoCreator.create(msg, transportContext, UUID.randomUUID());
            UUID sessionId = new UUID(sessionInfo.getSessionIdMSB(), sessionInfo.getSessionIdLSB());
            try {
                validateEfentoTransportConfiguration(deviceProfile);
                List<EfentoMeasurements> efentoMeasurements = getEfentoMeasurements(protoMeasurements, sessionId);
                transportService.process(sessionInfo, transportContext.getEfentoCoapAdaptor().convertToPostTelemetry(sessionId, efentoMeasurements), new CoapEfentoCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
                reportSubscriptionInfo(sessionInfo, false, false);
            } catch (AdaptorException e) {
                log.error("[{}] Failed to decode Efento ProtoMeasurements: ", sessionId, e);
                exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
            }
        }));
    } catch (Exception e) {
        log.error("Failed to decode Efento ProtoMeasurements: ", e);
        exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
    }
}
Also used : CONFIGURATION(org.thingsboard.server.transport.coap.CoapTransportService.CONFIGURATION) JsonObject(com.google.gson.JsonObject) CoapExchange(org.eclipse.californium.core.server.resources.CoapExchange) Response(org.eclipse.californium.core.coap.Response) Exchange(org.eclipse.californium.core.network.Exchange) CoapDeviceAuthCallback(org.thingsboard.server.transport.coap.callback.CoapDeviceAuthCallback) MeasurementTypeProtos(org.thingsboard.server.gen.transport.coap.MeasurementTypeProtos) EfentoCoapDeviceTypeConfiguration(org.thingsboard.server.common.data.device.profile.EfentoCoapDeviceTypeConfiguration) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) CoapEfentoUtils(org.thingsboard.server.transport.coap.efento.utils.CoapEfentoUtils) Resource(org.eclipse.californium.core.server.resources.Resource) CURRENT_TIMESTAMP(org.thingsboard.server.transport.coap.CoapTransportService.CURRENT_TIMESTAMP) DEVICE_INFO(org.thingsboard.server.transport.coap.CoapTransportService.DEVICE_INFO) AbstractCoapTransportResource(org.thingsboard.server.transport.coap.AbstractCoapTransportResource) Map(java.util.Map) MEASUREMENTS(org.thingsboard.server.transport.coap.CoapTransportService.MEASUREMENTS) DeviceTransportType(org.thingsboard.server.common.data.DeviceTransportType) MeasurementsProtos(org.thingsboard.server.gen.transport.coap.MeasurementsProtos) CoapOkCallback(org.thingsboard.server.transport.coap.callback.CoapOkCallback) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) CoapTransportContext(org.thingsboard.server.transport.coap.CoapTransportContext) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) AdaptorException(org.thingsboard.server.common.transport.adaptor.AdaptorException) List(java.util.List) Request(org.eclipse.californium.core.coap.Request) CoapEfentoCallback(org.thingsboard.server.transport.coap.callback.CoapEfentoCallback) TreeMap(java.util.TreeMap) CoAP(org.eclipse.californium.core.coap.CoAP) CoapDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration) CollectionUtils(org.springframework.util.CollectionUtils) Data(lombok.Data) DeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) AllArgsConstructor(lombok.AllArgsConstructor) SessionInfoCreator(org.thingsboard.server.common.transport.auth.SessionInfoCreator) AdaptorException(org.thingsboard.server.common.transport.adaptor.AdaptorException) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) CoapEfentoCallback(org.thingsboard.server.transport.coap.callback.CoapEfentoCallback) MeasurementsProtos(org.thingsboard.server.gen.transport.coap.MeasurementsProtos) CoapDeviceAuthCallback(org.thingsboard.server.transport.coap.callback.CoapDeviceAuthCallback) AdaptorException(org.thingsboard.server.common.transport.adaptor.AdaptorException)

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