aboutsummaryrefslogtreecommitdiffstats
path: root/cps-tbdmt-service/src/main
diff options
context:
space:
mode:
authorNiranjana <niranjana.y60@wipro.com>2022-03-10 11:52:19 +0000
committerNiranjana <niranjana.y60@wipro.com>2022-03-14 13:52:55 +0000
commit26d2e7029f32260246e0bfc21dde0b17006b28bd (patch)
tree87b93d507a5d8d13c91e45444b77989b8b910a2e /cps-tbdmt-service/src/main
parenta9c4c58fdb558ddb4ef11581c001f44b3954ab4d (diff)
Remove extra brackets in the result of output transformation
Issue-ID: CPS-920 Signed-off-by: Niranjana <niranjana.y60@wipro.com> Change-Id: I130f80c687bb2a9ccdf0ed45c387d7cfc167face
Diffstat (limited to 'cps-tbdmt-service/src/main')
-rw-r--r--cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
index 5b3bc60..1c0f285 100644
--- a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
+++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2021 Wipro Limited.
+ * Copyright (C) 2021-2022 Wipro Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -150,7 +150,7 @@ public class ExecutionBusinessLogic {
return result;
} else {
final List<JsonElement> json = transform(template, result);
- return new Gson().toJson(json);
+ return removeExtraBracketsIfAny(json, result);
}
}
} catch (final CpsClientException e) {
@@ -209,6 +209,30 @@ public class ExecutionBusinessLogic {
}
+ private static String removeExtraBracketsIfAny(final List<JsonElement> jsonElementList, final String result) {
+
+ final Gson gson = new Gson();
+ final List<JsonElement> updatedResult = new ArrayList<>();
+ if (jsonElementList.size() == 1) {
+ if (gson.fromJson(result, JsonElement.class).isJsonArray()) {
+ return gson.toJson(jsonElementList);
+ }
+ return gson.toJson(jsonElementList.get(0));
+ }
+ if (jsonElementList.size() > 1) {
+ jsonElementList.forEach(jsonElement -> {
+ if (jsonElement.isJsonArray() && jsonElement.getAsJsonArray().size() == 1) {
+ updatedResult.add(jsonElement.getAsJsonArray().get(0));
+ } else {
+ updatedResult.add(jsonElement);
+ }
+ });
+ return gson.toJson(updatedResult);
+ }
+ return gson.toJson(jsonElementList);
+
+ }
+
private String generateXpath(final String xpathTemplate, final Map<String, String> templateParameters) {
return new Jinjava().render(xpathTemplate, templateParameters);
}