aboutsummaryrefslogtreecommitdiffstats
path: root/cps-tbdmt-service/src/main
diff options
context:
space:
mode:
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);
}