@Override public boolean setProperty(WidgetProperty property, String propertyValue) { switch (property) { case OPACITY : this.opacity = Integer.parseInt(propertyValue); return true; case SCALE : this.scale = Integer.parseInt(propertyValue); return true; case ROTATION : this.rotation = Integer.parseInt(propertyValue); return true; case URLS : this.urls = propertyValue.split(StringUtils.BODY_SEPARATOR_STRING); return true; case URL : String[] split = StringUtils.split2(propertyValue); if (split.length == 2) { int index = Integer.parseInt(split[0]) - 1; if (index >= 0 && index < urls.length) { this.urls = ArrayUtil.copyAndReplace(this.urls, split[1], index); return true; } } return false; default: return super.setProperty(property, propertyValue); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] messageParts = StringUtils.split2(message.body);
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); int tagId = Integer.parseInt(split[1]); Profile profile = user.profile; DashBoard dash = profile.getDashByIdOrThrow(dashId); log.debug("Deleting tag with id {}.", tagId); profile.deleteTag(dash, tagId); user.lastModifiedTs = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
String[] split = split2(message.body);
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = StringUtils.split2(message.body); int dashId = Integer.parseInt(split[0]); int deviceId = Integer.parseInt(split[1]); DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Device device = user.profile.getDeviceById(dash, deviceId); if (device == null) { ctx.writeAndFlush(illegalCommandBody(message.id), ctx.voidPromise()); } else { if (ctx.channel().isWritable()) { ctx.writeAndFlush(makeUTF8StringMessage(MOBILE_GET_DEVICE, message.id, device.toString()), ctx.voidPromise()); } } }
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } var dashId = Integer.parseInt(split[0]); var widgetId = Long.parseLong(split[1]); var user = state.user; var dash = user.profile.getDashByIdOrThrow(dashId); var widget = dash.getWidgetByIdOrThrow(widgetId); if (ctx.channel().isWritable()) { var widgetString = JsonParser.toJson(widget); ctx.writeAndFlush( makeUTF8StringMessage(GET_WIDGET, message.id, widgetString), ctx.voidPromise() ); log.debug("Get widget {}.", widgetString); } }
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message, int settingsSizeLimit) { String[] split = StringUtils.split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); String dashSettingsString = split[1]; if (dashSettingsString == null || dashSettingsString.isEmpty()) { throw new IllegalCommandException("Income dash settings message is empty."); } if (dashSettingsString.length() > settingsSizeLimit) { throw new NotAllowedException("User dashboard setting message is larger then limit.", message.id); } log.debug("Trying to parse project settings : {}", dashSettingsString); DashboardSettings settings = JsonParser.parseDashboardSettings(dashSettingsString, message.id); User user = state.user; DashBoard existingDash = user.profile.getDashByIdOrThrow(dashId); existingDash.updateSettings(settings); user.lastModifiedTs = existingDash.updatedAt; ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var splitBody = split2(message.body); var user = state.user; var energyAmountToAdd = Integer.parseInt(splitBody[0]); ResponseMessage response; if (splitBody.length == 2 && isValidTransactionId(splitBody[1])) { double price = calcPrice(energyAmountToAdd); insertPurchase(user.email, energyAmountToAdd, price, splitBody[1]); user.addEnergy(energyAmountToAdd); response = ok(message.id); } else { if (!wasErrorPrinted) { log.warn("Purchase {} with invalid transaction id '{}'. {} ({}).", splitBody[0], splitBody[1], user.email, state.version); wasErrorPrinted = true; } response = notAllowed(message.id); } ctx.writeAndFlush(response, ctx.voidPromise()); }
@Override protected void channelRead0(ChannelHandlerContext ctx, GetServerMessage msg) { String[] parts = StringUtils.split2(msg.body);
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); String deviceString = split[1]; if (deviceString == null || deviceString.isEmpty()) { throw new IllegalCommandException("Income tag message is empty."); } Profile profile = user.profile; DashBoard dash = profile.getDashByIdOrThrow(dashId); Tag newTag = JsonParser.parseTag(deviceString, message.id); log.debug("Creating new tag {}.", newTag); if (newTag.isNotValid()) { throw new IllegalCommandException("Income tag name is not valid."); } for (Tag tag : dash.tags) { if (tag.id == newTag.id || tag.name.equals(newTag.name)) { throw new IllegalCommandException("Tag with same id/name already exists."); } } profile.addTag(dash, newTag); user.lastModifiedTs = System.currentTimeMillis(); if (ctx.channel().isWritable()) { ctx.writeAndFlush(makeUTF8StringMessage(CREATE_TAG, message.id, newTag.toString()), ctx.voidPromise()); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); int deviceId = Integer.parseInt(split[1]); User user = state.user; DashBoard dash = state.user.profile.getDashByIdOrThrow(dashId); log.debug("Deleting device with id {}.", deviceId); Device device = user.profile.deleteDevice(dash, deviceId); user.profile.cleanPinStorageForDevice(deviceId); user.profile.deleteDeviceFromTags(dash, deviceId); holder.tokenManager.deleteDevice(device); Session session = holder.sessionDao.get(state.userKey); session.closeHardwareChannelByDeviceId(dashId, deviceId); user.lastModifiedTs = System.currentTimeMillis(); holder.blockingIOProcessor.executeHistory(() -> { try { holder.reportingDiskDao.delete(user, dashId, deviceId); } catch (Exception e) { log.warn("Error removing device data. Reason : {}.", e.getMessage()); } }); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); String deviceString = split[1]; if (deviceString == null || deviceString.isEmpty()) { throw new IllegalCommandException("Income device message is empty."); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Device newDevice = JsonParser.parseDevice(deviceString, message.id); log.debug("Updating new device {}.", deviceString); if (newDevice.isNotValid()) { throw new IllegalCommandException("Income device message is not valid."); } Device existingDevice = user.profile.getDeviceById(dash, newDevice.id); if (existingDevice == null) { log.debug("Attempt to update device with non existing id."); ctx.writeAndFlush(illegalCommandBody(message.id), ctx.voidPromise()); return; } existingDevice.update(newDevice); dash.updatedAt = System.currentTimeMillis(); user.lastModifiedTs = dash.updatedAt; ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] split = StringUtils.split2(message.body);
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); String tagString = split[1]; if (tagString == null || tagString.isEmpty()) { throw new IllegalCommandException("Income tag message is empty."); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Tag newTag = JsonParser.parseTag(tagString, message.id); log.debug("Updating new tag {}.", tagString); if (newTag.isNotValid()) { throw new IllegalCommandException("Income tag name is not valid."); } Tag existingTag = user.profile.getTagById(dash, newTag.id); if (existingTag == null) { throw new IllegalCommandException("Attempt to update tag with non existing id."); } existingTag.update(newTag); user.lastModifiedTs = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body);
if (message.body.contains(StringUtils.BODY_SEPARATOR_STRING)) { newFlow = true; token = split2(message.body)[0]; } else { newFlow = false;
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); int dashId = Integer.parseInt(split[0]); DashBoard dash = user.profile.getDashByIdOrThrow(dashId); String deviceString = split[1]; if (deviceString == null || deviceString.isEmpty()) { throw new IllegalCommandException("Income device message is empty."); } Device temporaryDevice = JsonParser.parseDevice(deviceString, message.id); if (temporaryDevice.isNotValid()) { throw new IllegalCommandException("Income device message is not valid."); } for (Device device : dash.devices) { if (device.id == temporaryDevice.id) { throw new NotAllowedException("Device with same id already exists.", message.id); } } String tempToken = TokenGeneratorUtil.generateNewToken(); holder.tokenManager.assignToken(user, dash, temporaryDevice, tempToken, true); if (ctx.channel().isWritable()) { ctx.writeAndFlush(makeASCIIStringMessage(GET_PROVISION_TOKEN, message.id, temporaryDevice.toString()), ctx.voidPromise()); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body);
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body);
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body);