Source:
boolean updateItemChildren(Map<String, JsonObject> items) { List<Item> itemList = new LinkedList<>(); boolean updated = false; for (Entry<String, JsonObject> entry : items.entrySet()) { String itemId = entry.getKey(); JsonObject updateData = entry.getValue(); if (updateData.has("children")) { Item parentItem; List<Item> children; try (ItemManager manager = new ItemManager()) { parentItem = manager.load(itemId); children = new LinkedList<>(); Iterator<JsonElement> iterator = updateData.get("children").getAsJsonArray().iterator(); while (iterator.hasNext()) { String childId = iterator.next().getAsString(); Item child = manager.load(childId); children.add(child); } parentItem.setChildren(children); if (updateData.has("displayedChildren")) { Iterator<JsonElement> displayedIterator = updateData.get("displayedChildren").getAsJsonArray().iterator(); List<String> displayedChildren = new ArrayList<>(); while (displayedIterator.hasNext()) { String childId = displayedIterator.next().getAsString(); displayedChildren.add(childId); } parentItem.setDisplayedChildren(displayedChildren); } } itemList.add(parentItem); } else { log.error("Incoming JSON Object has no children"); throw new BadRequestException(); } } if (!itemList.isEmpty()) { try (ItemManager manager = new ItemManager()) { updated = manager.mergeAll(itemList); } if (updated) { log.info("Updated items", itemList.size()); try (ThumbnailManager thumbMan = new ThumbnailManager()) { for (Item item : itemList) { thumbMan.updateDirtyBits(item.getId()); } log.debug("Updated thumbs for items", itemList.size()); } try (StatusManager statusMan = new StatusManager()) { Status status = new Status(); status.setStatusName(Status.StatusName.STRUCTURE_UPDATE); if (statusMan.save(status)) { log.debug("Status Manager updated structure status after items were updated."); } else { log.warn("Status Manager did not update the structure status after updating items. This could lead to inconsistencies in the data"); } } } else { log.warn("Could not update items.", itemList.size()); } } return updated; }

Target:
private boolean updateItemChildren(Map<String, JsonObject> items) { List<Item> itemList = new LinkedList<>(); boolean updated = false; for (Entry<String, JsonObject> entry : items.entrySet()) { String itemId = entry.getKey(); JsonObject updateData = entry.getValue(); if (updateData.has("children")) { Item parentItem; List<Item> children; try (ItemManager manager = new ItemManager()) { parentItem = manager.load(itemId); children = new LinkedList<>(); Iterator<JsonElement> iterator = updateData.get("children").getAsJsonArray().iterator(); while (iterator.hasNext()) { String childId = iterator.next().getAsString(); Item child = manager.load(childId); children.add(child); } parentItem.setChildren(children); if (updateData.has("displayedChildren")) { Iterator<JsonElement> displayedIterator = updateData.get("displayedChildren").getAsJsonArray().iterator(); List<String> displayedChildren = new ArrayList<>(); while (displayedIterator.hasNext()) { String childId = displayedIterator.next().getAsString(); displayedChildren.add(childId); } parentItem.setDisplayedChildren(displayedChildren); } } itemList.add(parentItem); } else { log.error("Incoming JSON Object has no children"); throw new BadRequestException(); } } if (!itemList.isEmpty()) { try (ItemManager manager = new ItemManager()) { updated = manager.mergeAll(itemList); } if (updated) { log.info("Updated items", itemList.size()); try (ThumbnailManager thumbMan = new ThumbnailManager()) { for (Item item : itemList) { thumbMan.updateDirtyBits(item.getId()); } log.debug("Updated thumbs for items", itemList.size()); } try (StatusManager statusMan = new StatusManager()) { Status status = new Status(); status.setStatusName(Status.StatusName.STRUCTURE_UPDATE); if (statusMan.save(status)) { log.debug("Status Manager updated structure status after items were updated."); } else { log.warn("Status Manager did not update the structure status after updating items. This could lead to inconsistencies in the data"); } } } else { log.warn("Could not update items.", itemList.size()); } } return updated; }