public void deleteTag(DashBoard dash, int tagId) { int existingTagIndex = getTagIndexByIdOrThrow(dash, tagId); dash.tags = ArrayUtil.remove(dash.tags, existingTagIndex, Tag.class); }
@Override public void deleteDevice(int deviceId) { Tile[] localTiles = this.tiles; int index = getTileIndexByDeviceId(localTiles, deviceId); if (index != -1) { this.tiles = localTiles.length == 1 ? EMPTY_DEVICE_TILES : ArrayUtil.remove(localTiles, index, Tile.class); } for (TileTemplate tileTemplate : this.templates) { tileTemplate.deviceIds = ArrayUtil.deleteFromArray(tileTemplate.deviceIds, deviceId); } } }
public Device deleteDevice(DashBoard dash, int deviceId) { int existingDeviceIndex = getDeviceIndexByIdOrThrow(dash, deviceId); Device deviceToRemove = dash.devices[existingDeviceIndex]; dash.devices = ArrayUtil.remove(dash.devices, existingDeviceIndex, Device.class); dash.eraseWidgetValuesForDevice(deviceId); return deviceToRemove; }
public void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var id = message.body; var user = state.user; var existingAppIndex = user.profile.getAppIndexById(id); if (existingAppIndex == -1) { throw new NotAllowedException("App with passed is not exists.", message.id); } var projectIds = user.profile.apps[existingAppIndex].projectIds; var result = new ArrayList<DashBoard>(); for (DashBoard dash : user.profile.dashBoards) { if (ArrayUtil.contains(projectIds, dash.id)) { timerWorker.deleteTimers(state.userKey, dash); tokenManager.deleteDash(dash); sessionDao.closeHardwareChannelByDashId(state.userKey, dash.id); } else { result.add(dash); } } user.profile.dashBoards = result.toArray(new DashBoard[0]); user.profile.apps = ArrayUtil.remove(user.profile.apps, existingAppIndex, App.class); user.lastModifiedTs = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] split = split3(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); long widgetId = Long.parseLong(split[1]); long tileId = Long.parseLong(split[2]); User user = state.user; DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Widget widget = dash.getWidgetByIdOrThrow(widgetId); if (!(widget instanceof DeviceTiles)) { throw new IllegalCommandException("Income widget id is not DeviceTiles."); } DeviceTiles deviceTiles = (DeviceTiles) widget; int existingTileIndex = deviceTiles.getTileTemplateIndexByIdOrThrow(tileId); log.debug("Deleting tile template dashId : {}, widgetId : {}, tileId : {}.", dash, widgetId, tileId); TileTemplate tileTemplate = deviceTiles.templates[existingTileIndex]; user.addEnergy(tileTemplate.getPrice()); deviceTiles.templates = ArrayUtil.remove(deviceTiles.templates, existingTileIndex, TileTemplate.class); deviceTiles.deleteDeviceTilesByTemplateId(tileId); user.profile.cleanPinStorageForTileTemplate(dash, tileTemplate, true); dash.updatedAt = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
private static void deleteDash(Holder holder, MobileStateHolder state, int dashId) { User user = state.user; int index = user.profile.getDashIndexOrThrow(dashId); log.debug("Deleting dashboard {}.", dashId); DashBoard dash = user.profile.dashBoards[index]; user.addEnergy(dash.energySum()); holder.timerWorker.deleteTimers(state.userKey, dash); holder.tokenManager.deleteDash(dash); holder.sessionDao.closeHardwareChannelByDashId(state.userKey, dashId); holder.reportScheduler.cancelStoredFuture(user, dashId); holder.blockingIOProcessor.executeHistory(() -> { for (Device device : dash.devices) { try { holder.reportingDiskDao.delete(state.user, dashId, device.id); } catch (Exception e) { log.warn("Error removing device data. Reason : {}.", e.getMessage()); } } }); user.profile.dashBoards = ArrayUtil.remove(user.profile.dashBoards, index, DashBoard.class); }
reportingWidget.reports = ArrayUtil.remove(reportingWidget.reports, existingReportIndex, Report.class); dash.updatedAt = System.currentTimeMillis();