/** * Expecting only strings like "1.2.2" */ private static int parseToSingleInt(String version) { try { var parts = split3('.', version); return parse(parts); } catch (Exception e) { log.debug("Error parsing app versionSingleNumber {}. Reason : {}.", version, e.getMessage()); } return 0; }
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var splitBody = StringUtils.split3(message.body); var dashId = Integer.parseInt(splitBody[0]); var uid = splitBody[1]; var token = splitBody[2]; var dash = state.user.profile.getDashByIdOrThrow(dashId); var notification = dash.getNotificationWidget(); if (notification == null) { log.error("No notification widget."); ctx.writeAndFlush(notAllowed(message.id), ctx.voidPromise()); return; } switch (state.version.osType) { case ANDROID : notification.androidTokens.put(uid, token); break; case IOS : notification.iOSTokens.put(uid, token); break; } ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] messageParts = StringUtils.split3(message.body); if (messageParts.length < 2) { throw new IllegalCommandException("Wrong income message format."); } String[] dashIdAndDeviceId = split2Device(messageParts[0]); int dashId = Integer.parseInt(dashIdAndDeviceId[0]); long widgetId = Long.parseLong(messageParts[1]); int streamIndex = -1; if (message.body.length() == 3) { streamIndex = Integer.parseInt(messageParts[2]); } int targetId = -1; if (dashIdAndDeviceId.length == 2) { targetId = Integer.parseInt(dashIdAndDeviceId[1]); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Widget widget = dash.getWidgetById(widgetId); if (widget == null) { widget = dash.getWidgetByIdInDeviceTilesOrThrow(widgetId); } Superchart enhancedHistoryGraph = (Superchart) widget; if (streamIndex == -1 || streamIndex > enhancedHistoryGraph.dataStreams.length - 1) { delete(holder, ctx.channel(), message.id, user, dash, targetId, enhancedHistoryGraph.dataStreams); } else { delete(holder, ctx.channel(), message.id, user, dash, targetId, enhancedHistoryGraph.dataStreams[streamIndex]); } }
@Override public PinStorageKey deserializeKey(String key, DeserializationContext ctx) { //parsing "123-v24" String[] split = StringUtils.split3(StringUtils.DEVICE_SEPARATOR, key); int deviceId = Integer.parseInt(split[0]); PinType pinType = PinType.getPinType(split[1].charAt(0)); short pin = 0; try { pin = NumberUtil.parsePin(split[1].substring(1)); } catch (NumberFormatException e) { //special case for outdated data format. return new PinStorageKey(deviceId, pinType, pin); } if (split.length == 3) { WidgetProperty widgetProperty = WidgetProperty.getProperty(split[2]); if (widgetProperty == null) { widgetProperty = WidgetProperty.LABEL; } return new PinPropertyStorageKey(deviceId, pinType, pin, widgetProperty); } else { return new PinStorageKey(deviceId, pinType, pin); } } }
String[] splitBody = split3(body);
String[] splitBody = split3(split[1]);
String[] messageParts = StringUtils.split3(message.body);
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()); }
String[] splitBody = split3(body);
SessionDao sessionDao = holder.sessionDao; String[] bodyParts = split3(message.body);
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] split = split3(message.body); if (split.length < 3) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); long widgetId = Long.parseLong(split[1]); String tileTemplateString = split[2]; if (tileTemplateString == null || tileTemplateString.isEmpty()) { throw new IllegalCommandException("Income tile template message is empty."); } 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; TileTemplate newTileTemplate = JsonParser.parseTileTemplate(tileTemplateString, message.id); int existingTileTemplateIndex = deviceTiles.getTileTemplateIndexByIdOrThrow(newTileTemplate.id); TileTemplate existingTileTemplate = deviceTiles.templates[existingTileTemplateIndex]; deviceTiles.recreateTilesIfNecessary(newTileTemplate, existingTileTemplate); log.debug("Updating tile template {}.", tileTemplateString); deviceTiles.replaceTileTemplate(newTileTemplate, existingTileTemplateIndex); user.profile.cleanPinStorage(dash, deviceTiles, false); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public void messageReceived(ChannelHandlerContext ctx, HardwareStateHolder state, StringMessage message) { var session = sessionDao.get(state.userKey); var split = split3(message.body);
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] split = split3(message.body);