public Tag copy() { return new Tag(id, name, deviceIds); }
public static Tag[] copyTags(Tag[] tagsToCopy) { if (tagsToCopy.length == 0) { return tagsToCopy; } Tag[] copy = new Tag[tagsToCopy.length]; for (int i = 0; i < copy.length; i++) { copy[i] = tagsToCopy[i].copy(); } return copy; }
public void deleteDeviceFromTags(DashBoard dash, int deviceId) { for (Tag tag : dash.tags) { tag.deleteDevice(deviceId); } }
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(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()); }