public void deleteTimers(UserKey userKey, DashBoard dash) { for (Widget widget : dash.widgets) { if (widget instanceof DeviceTiles) { DeviceTiles deviceTiles = (DeviceTiles) widget; deleteTimers(userKey, dash.id, deviceTiles); } else if (widget instanceof Timer) { delete(userKey, (Timer) widget, dash.id, -1L, -1L); } else if (widget instanceof Eventor) { delete(userKey, (Eventor) widget, dash.id); } } }
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(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String dashString = message.body; if (dashString == null || dashString.isEmpty()) { throw new IllegalCommandException("Income create dash message is empty."); } if (dashString.length() > holder.limits.profileSizeLimitBytes) { throw new NotAllowedException("User dashboard is larger then limit.", message.id); } log.debug("Trying to parse user dash : {}", dashString); DashBoard updatedDash = JsonParser.parseDashboard(dashString, message.id); if (updatedDash == null) { throw new IllegalCommandException("Project parsing error."); } log.debug("Saving dashboard."); User user = state.user; DashBoard existingDash = user.profile.getDashByIdOrThrow(updatedDash.id); TimerWorker timerWorker = holder.timerWorker; timerWorker.deleteTimers(state.userKey, existingDash); updatedDash.addTimers(timerWorker, state.userKey); existingDash.updateFields(updatedDash); user.profile.cleanPinStorage(existingDash, false, true); user.lastModifiedTs = existingDash.updatedAt; 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); }