Search in sources :

Example 1 with DeviceId

use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.

the class DeviceServiceImpl method findDevicesByQuery.

@Override
public ListenableFuture<List<Device>> findDevicesByQuery(DeviceSearchQuery query) {
    ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(query.toEntitySearchQuery());
    ListenableFuture<List<Device>> devices = Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<Device>>) relations1 -> {
        EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
        List<ListenableFuture<Device>> futures = new ArrayList<>();
        for (EntityRelation relation : relations1) {
            EntityId entityId = direction == EntitySearchDirection.FROM ? relation.getTo() : relation.getFrom();
            if (entityId.getEntityType() == EntityType.DEVICE) {
                futures.add(findDeviceByIdAsync(new DeviceId(entityId.getId())));
            }
        }
        return Futures.successfulAsList(futures);
    });
    devices = Futures.transform(devices, new Function<List<Device>, List<Device>>() {

        @Nullable
        @Override
        public List<Device> apply(@Nullable List<Device> deviceList) {
            return deviceList == null ? Collections.emptyList() : deviceList.stream().filter(device -> query.getDeviceTypes().contains(device.getType())).collect(Collectors.toList());
        }
    });
    return devices;
}
Also used : java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Cache(org.springframework.cache.Cache) Cacheable(org.springframework.cache.annotation.Cacheable) EntitySearchDirection(org.thingsboard.server.common.data.relation.EntitySearchDirection) Autowired(org.springframework.beans.factory.annotation.Autowired) CacheEvict(org.springframework.cache.annotation.CacheEvict) TextPageData(org.thingsboard.server.common.data.page.TextPageData) TenantId(org.thingsboard.server.common.data.id.TenantId) DataValidator(org.thingsboard.server.dao.service.DataValidator) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) org.thingsboard.server.common.data(org.thingsboard.server.common.data) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) EntityId(org.thingsboard.server.common.data.id.EntityId) Nullable(javax.annotation.Nullable) DEVICE_CACHE(org.thingsboard.server.common.data.CacheConstants.DEVICE_CACHE) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Function(com.google.common.base.Function) DeviceCredentialsType(org.thingsboard.server.common.data.security.DeviceCredentialsType) DaoUtil.toUUIDs(org.thingsboard.server.dao.DaoUtil.toUUIDs) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Validator(org.thingsboard.server.dao.service.Validator) Collectors(java.util.stream.Collectors) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) AbstractEntityService(org.thingsboard.server.dao.entity.AbstractEntityService) CustomerDao(org.thingsboard.server.dao.customer.CustomerDao) PaginatedRemover(org.thingsboard.server.dao.service.PaginatedRemover) TenantDao(org.thingsboard.server.dao.tenant.TenantDao) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) DeviceSearchQuery(org.thingsboard.server.common.data.device.DeviceSearchQuery) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) StringUtils(org.springframework.util.StringUtils) CustomerId(org.thingsboard.server.common.data.id.CustomerId) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) Function(com.google.common.base.Function) AsyncFunction(com.google.common.util.concurrent.AsyncFunction) EntitySearchDirection(org.thingsboard.server.common.data.relation.EntitySearchDirection) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Nullable(javax.annotation.Nullable)

Example 2 with DeviceId

use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.

the class DeviceCredentialsEntity method toData.

@Override
public DeviceCredentials toData() {
    DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(getId()));
    deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(getId()));
    if (deviceId != null) {
        deviceCredentials.setDeviceId(new DeviceId(toUUID(deviceId)));
    }
    deviceCredentials.setCredentialsType(credentialsType);
    deviceCredentials.setCredentialsId(credentialsId);
    deviceCredentials.setCredentialsValue(credentialsValue);
    return deviceCredentials;
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) DeviceCredentialsId(org.thingsboard.server.common.data.id.DeviceCredentialsId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 3 with DeviceId

use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.

the class DeviceCredentialsEntity method toData.

@Override
public DeviceCredentials toData() {
    DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(id));
    deviceCredentials.setCreatedTime(UUIDs.unixTimestamp(id));
    if (deviceId != null) {
        deviceCredentials.setDeviceId(new DeviceId(deviceId));
    }
    deviceCredentials.setCredentialsType(credentialsType);
    deviceCredentials.setCredentialsId(credentialsId);
    deviceCredentials.setCredentialsValue(credentialsValue);
    return deviceCredentials;
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) DeviceCredentialsId(org.thingsboard.server.common.data.id.DeviceCredentialsId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 4 with DeviceId

use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.

the class BaseDeviceControllerTest method testSaveDeviceCredentialsWithNonExistentDevice.

@Test
public void testSaveDeviceCredentialsWithNonExistentDevice() throws Exception {
    Device device = new Device();
    device.setName("My device");
    device.setType("default");
    Device savedDevice = doPost("/api/device", device, Device.class);
    DeviceCredentials deviceCredentials = doGet("/api/device/" + savedDevice.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    deviceCredentials.setDeviceId(new DeviceId(UUIDs.timeBased()));
    doPost("/api/device/credentials", deviceCredentials).andExpect(status().isNotFound());
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials) Test(org.junit.Test)

Example 5 with DeviceId

use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.

the class JpaDeviceDaoTest method getDevice.

private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
    Device device = new Device();
    device.setId(new DeviceId(deviceId));
    device.setTenantId(new TenantId(tenantId));
    device.setCustomerId(new CustomerId(customerID));
    device.setName("SEARCH_TEXT");
    return device;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) Device(org.thingsboard.server.common.data.Device) DeviceId(org.thingsboard.server.common.data.id.DeviceId) CustomerId(org.thingsboard.server.common.data.id.CustomerId)

Aggregations

DeviceId (org.thingsboard.server.common.data.id.DeviceId)42 Test (org.junit.Test)21 Device (org.thingsboard.server.common.data.Device)12 TenantId (org.thingsboard.server.common.data.id.TenantId)10 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)9 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)8 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)8 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)8 ArrayList (java.util.ArrayList)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Event (org.thingsboard.server.common.data.Event)6 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 UUID (java.util.UUID)5 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)5 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 DeviceAttributes (org.thingsboard.server.extensions.api.device.DeviceAttributes)5 DeviceMetaData (org.thingsboard.server.extensions.api.device.DeviceMetaData)5 Customer (org.thingsboard.server.common.data.Customer)3 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)3