From 3a7de3c6776944060a6fd33dffd308399f04e3a0 Mon Sep 17 00:00:00 2001 From: Parth Panchal <83201188+parthp2107@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:31:53 +0530 Subject: [PATCH] Fixed #2188: Can add and remove more than 10 tags at once. (#5040) * Fixed adding more than 10 tags at a time --- .../openmetadata/catalog/util/JsonUtils.java | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java index 4473a6b58a1..4eb5c155f76 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java @@ -183,12 +183,46 @@ public final class JsonUtils { // sort the operations by path if (!otherOperations.isEmpty()) { - otherOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); + ArrayList paths = new ArrayList<>(); + for (JsonObject jsonObject : otherOperations) { + paths.add(jsonObject.getString("path")); + } + for (String path : paths) { + if (path.matches("^[a-zA-Z]*$")) { + otherOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); + } else if (path.matches(".*\\d.*")) { + otherOperations.sort( + Comparator.comparing( + jsonObject -> { + String pathValue = jsonObject.getString("path"); + String tagIndex = pathValue.replaceAll("\\D", ""); + return tagIndex.isEmpty() ? 0 : Integer.parseInt(tagIndex); + })); + } + } } if (!removeOperations.isEmpty()) { - removeOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); - // reverse sort only the remove operations - Collections.reverse(removeOperations); + ArrayList paths = new ArrayList<>(); + for (JsonObject jsonObject : removeOperations) { + paths.add(jsonObject.getString("path")); + } + for (String path : paths) { + if (path.matches("^[a-zA-Z]*$")) { + removeOperations.sort(Comparator.comparing(jsonObject -> jsonObject.getString("path"))); + // reverse sort only the remove operations + Collections.reverse(removeOperations); + } else if (path.matches(".*\\d.*")) { + removeOperations.sort( + Comparator.comparing( + jsonObject -> { + String pathValue = jsonObject.getString("path"); + String tagIndex = pathValue.replaceAll("\\D", ""); + return tagIndex.isEmpty() ? 0 : Integer.parseInt(tagIndex); + })); + // reverse sort only the remove operations + Collections.reverse(removeOperations); + } + } } // Build new sorted patch