use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class JpaAlarmDaoTest method testFindLatestByOriginatorAndType.
@Test
public void testFindLatestByOriginatorAndType() throws ExecutionException, InterruptedException {
System.out.println(System.currentTimeMillis());
UUID tenantId = UUID.fromString("d4b68f40-3e96-11e7-a884-898080180d6b");
UUID originator1Id = UUID.fromString("d4b68f41-3e96-11e7-a884-898080180d6b");
UUID originator2Id = UUID.fromString("d4b68f42-3e96-11e7-a884-898080180d6b");
UUID alarm1Id = UUID.fromString("d4b68f43-3e96-11e7-a884-898080180d6b");
UUID alarm2Id = UUID.fromString("d4b68f44-3e96-11e7-a884-898080180d6b");
UUID alarm3Id = UUID.fromString("d4b68f45-3e96-11e7-a884-898080180d6b");
saveAlarm(alarm1Id, tenantId, originator1Id, "TEST_ALARM");
saveAlarm(alarm2Id, tenantId, originator1Id, "TEST_ALARM");
saveAlarm(alarm3Id, tenantId, originator2Id, "TEST_ALARM");
assertEquals(3, alarmDao.find().size());
ListenableFuture<Alarm> future = alarmDao.findLatestByOriginatorAndType(new TenantId(tenantId), new DeviceId(originator1Id), "TEST_ALARM");
Alarm alarm = future.get();
assertNotNull(alarm);
assertEquals(alarm2Id, alarm.getId().getId());
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicMissingAttributesTest.
@Test
public void basicMissingAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("((typeof nonExistingVal === 'undefined') || nonExistingVal == true) && booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(clientAttributes, new ArrayList<>(), new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicConflictServerAttributesTest.
@Test
public void basicConflictServerAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("cs.doubleValue == 1.0 && cs.booleanValue == true && ss.doubleValue == 0.0 && ss.booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", true), 42));
List<AttributeKvEntry> serverAttributes = new ArrayList<>();
serverAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 0.0), 42));
serverAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(clientAttributes, serverAttributes, new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceController method assignDeviceToPublicCustomer.
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/customer/public/device/{deviceId}", method = RequestMethod.POST)
@ResponseBody
public Device assignDeviceToPublicCustomer(@PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException {
checkParameter(DEVICE_ID, strDeviceId);
try {
DeviceId deviceId = new DeviceId(toUUID(strDeviceId));
Device device = checkDeviceId(deviceId);
Customer publicCustomer = customerService.findOrCreatePublicCustomer(device.getTenantId());
Device savedDevice = checkNotNull(deviceService.assignDeviceToCustomer(deviceId, publicCustomer.getId()));
logEntityAction(deviceId, savedDevice, savedDevice.getCustomerId(), ActionType.ASSIGNED_TO_CUSTOMER, null, strDeviceId, publicCustomer.getId().toString(), publicCustomer.getName());
return savedDevice;
} catch (Exception e) {
logEntityAction(emptyId(EntityType.DEVICE), null, null, ActionType.ASSIGNED_TO_CUSTOMER, e, strDeviceId);
throw handleException(e);
}
}
use of org.thingsboard.server.common.data.id.DeviceId in project thingsboard by thingsboard.
the class DeviceController method getDevicesByIds.
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/devices", params = { "deviceIds" }, method = RequestMethod.GET)
@ResponseBody
public List<Device> getDevicesByIds(@RequestParam("deviceIds") String[] strDeviceIds) throws ThingsboardException {
checkArrayParameter("deviceIds", strDeviceIds);
try {
SecurityUser user = getCurrentUser();
TenantId tenantId = user.getTenantId();
CustomerId customerId = user.getCustomerId();
List<DeviceId> deviceIds = new ArrayList<>();
for (String strDeviceId : strDeviceIds) {
deviceIds.add(new DeviceId(toUUID(strDeviceId)));
}
ListenableFuture<List<Device>> devices;
if (customerId == null || customerId.isNullUid()) {
devices = deviceService.findDevicesByTenantIdAndIdsAsync(tenantId, deviceIds);
} else {
devices = deviceService.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId, customerId, deviceIds);
}
return checkNotNull(devices.get());
} catch (Exception e) {
throw handleException(e);
}
}
Aggregations