if (permittedNetworks != null && !permittedNetworks.isEmpty()) { Set<DeviceVO> allowed = deviceType.getDevices().stream() .filter(device -> permittedNetworks.contains(device.getNetworkId())) .collect(Collectors.toSet()); deviceType.setDevices(allowed);
public void unregisterDevice(DeviceVO device) { final Filter deviceFilter = new Filter(device.getNetworkId(), device.getDeviceTypeId(), device.getDeviceId(), null, null); subscriberTable.row(deviceFilter.getFirstKey()).clear(); }
if (device.getNetworkId() == null) { logger.error("notification/insert. No network specified for device with Device ID = {}", deviceId); throw new HiveException(String.format(Messages.DEVICE_IS_NOT_CONNECTED_TO_NETWORK, deviceId), SC_FORBIDDEN);
if (names != null) { filters = names.stream().map(name -> new Filter(device.getNetworkId(), device.getDeviceTypeId(), deviceId, eventName, name)) .collect(Collectors.toSet()); } else { filters = Collections.singleton(new Filter(device.getNetworkId(), device.getDeviceTypeId(), deviceId, eventName, null));
return networks.contains(device.getNetworkId()); return networks.contains(device.getNetworkId()) && deviceTypes.contains(device.getDeviceTypeId());
asyncResponse.resume(response); } else { if (device.getNetworkId() == null) { logger.warn("DeviceNotification insert proceed with error. FORBIDDEN: Device {} is not connected to network.", deviceId); Response response = ResponseFactory.response(FORBIDDEN, new ErrorResponse(FORBIDDEN.getStatusCode(),
command.setId(Math.abs(new Random().nextInt())); command.setDeviceId(device.getDeviceId()); command.setNetworkId(device.getNetworkId()); command.setDeviceTypeId(device.getDeviceTypeId()); command.setIsUpdated(false);
public CompletableFuture<Pair<Long, DeviceCommand>> sendSubscribeToUpdateRequest(final long commandId, final DeviceVO device, BiConsumer<DeviceCommand, Long> callback) { CompletableFuture<Pair<Long, DeviceCommand>> future = new CompletableFuture<>(); final Long subscriptionId = idGenerator.generate(); Consumer<Response> responseConsumer = response -> { Action resAction = response.getBody().getAction(); if (resAction.equals(Action.COMMAND_UPDATE_SUBSCRIBE_RESPONSE)) { future.complete(Pair.of(response.getBody().cast(CommandUpdateSubscribeResponse.class).getSubscriptionId(), response.getBody().cast(CommandUpdateSubscribeResponse.class).getDeviceCommand())); } else if (resAction.equals(COMMAND_UPDATE_EVENT)) { callback.accept(response.getBody().cast(CommandUpdateEvent.class).getDeviceCommand(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction); } }; Filter filter = new Filter(device.getNetworkId(), device.getDeviceTypeId(), Long.toString(commandId), COMMAND_UPDATE_EVENT.name(), null); rpcClient.call(Request.newBuilder() .withBody(new CommandUpdateSubscribeRequest(commandId, device.getDeviceId(), subscriptionId, filter)) .build(), responseConsumer); return future; }
public DeviceNotification convertWrapperToNotification(DeviceNotificationWrapper notificationSubmit, DeviceVO device) { DeviceNotification notification = new DeviceNotification(); notification.setId(Math.abs(new Random().nextInt())); notification.setDeviceId(device.getDeviceId()); notification.setNetworkId(device.getNetworkId()); notification.setDeviceTypeId(device.getDeviceTypeId()); if (notificationSubmit.getTimestamp() == null) { notification.setTimestamp(timestampService.getDate()); } else { notification.setTimestamp(notificationSubmit.getTimestamp()); } notification.setNotification(notificationSubmit.getNotification()); notification.setParameters(notificationSubmit.getParameters()); return notification; }
public static Device convertToEntity(DeviceVO dc) { Device entity = null; if (dc != null) { entity = new Device(); entity.setId(dc.getId()); entity.setDeviceId(dc.getDeviceId()); entity.setName(dc.getName()); entity.setData(dc.getData()); entity.setBlocked(dc.getBlocked()); Network network = new Network(); network.setId(dc.getNetworkId()); entity.setNetwork(network); DeviceType deviceType = new DeviceType(); deviceType.setId(dc.getDeviceTypeId()); entity.setDeviceType(deviceType); } return entity; }