summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java31
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java35
2 files changed, 28 insertions, 38 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
index 8968eeb323..84e4f6d7c9 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
@@ -22,22 +22,17 @@ package org.openecomp.core.utilities.json;
import org.json.JSONException;
import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
-/**
- * The type Json schema data generator.
- */
public class JsonSchemaDataGenerator {
private static final String ROOT = "root";
- private static final Logger logger = LoggerFactory.getLogger(JsonSchemaDataGenerator.class);
- /**
- * The Include defaults.
- */
+ private static final Logger logger =
+ (Logger) LoggerFactory.getLogger(JsonSchemaDataGenerator.class);
boolean includeDefaults = true;
private JSONObject root;
private Map<String, Object> referencesData;
@@ -54,11 +49,6 @@ public class JsonSchemaDataGenerator {
root = new JSONObject(jsonSchema);
}
- /**
- * Sets include defaults.
- *
- * @param includeDefaults the include defaults
- */
public void setIncludeDefaults(boolean includeDefaults) {
this.includeDefaults = includeDefaults;
}
@@ -66,15 +56,16 @@ public class JsonSchemaDataGenerator {
/**
* Generates json data that conform to the schema according to turned on flags.
*
- * @return json that conform to the schema.
+ * @return json that conform to the schema
*/
public String generateData() {
referencesData = new HashMap<>();
JSONObject data = new JSONObject();
generateData(ROOT, root,
- data); // "root" is dummy name to represent the top level object (which, as apposed to
- // inner objects, doesn't have a name in the schema)
+ data);
+ // "root" is dummy name to represent the top level object
+ // (which, as apposed to inner objects, doesn't have a name in the schema)
return data.has(ROOT) ? data.get(ROOT).toString() : data.toString();
}
@@ -161,12 +152,12 @@ public class JsonSchemaDataGenerator {
default:
break;
}
- } catch (JSONException e0) {
+ } catch (JSONException exception) {
Object defaultValue = property.get(JsonSchemaKeyword.DEFAULT);
logger.error(String.format(
"Invalid schema: '%s' property type is '%s' but it has a default value which is not: %s.",
- propertyName, propertyType, defaultValue), e0);
- throw e0;
+ propertyName, propertyType, defaultValue), exception);
+ throw exception;
}
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
index 6ae3677a8d..87c75fce62 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
@@ -20,14 +20,13 @@
package org.openecomp.core.utilities.json;
-
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
-import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
import org.everit.json.schema.EnumSchema;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
@@ -82,17 +81,17 @@ public class JsonUtil {
* @return the t
*/
public static <T> T json2Object(String json, Class<T> classOfT) {
- T type;
+ T typ;
try {
try (Reader br = new StringReader(json)) {
- type = new Gson().fromJson(br, classOfT);
- } catch (IOException e0) {
- throw e0;
+ typ = new Gson().fromJson(br, classOfT);
+ } catch (IOException exception) {
+ throw exception;
}
- } catch (JsonIOException | JsonSyntaxException | IOException e0) {
- throw new RuntimeException(e0);
+ } catch (JsonIOException | JsonSyntaxException | IOException exception) {
+ throw new RuntimeException(exception);
}
- return type;
+ return typ;
}
/**
@@ -109,8 +108,8 @@ public class JsonUtil {
try (Reader br = new BufferedReader(new InputStreamReader(is))) {
type = new Gson().fromJson(br, classOfT);
}
- } catch (JsonIOException | JsonSyntaxException | IOException e0) {
- throw new RuntimeException(e0);
+ } catch (JsonIOException | JsonSyntaxException | IOException exception) {
+ throw new RuntimeException(exception);
} finally {
if (is != null) {
try {
@@ -153,16 +152,16 @@ public class JsonUtil {
.collect(Collectors.toList());
}
- private static String mapValidationExceptionToMessage(ValidationException e0) {
- if (e0.getViolatedSchema() instanceof EnumSchema) {
- return mapEnumViolationToMessage(e0);
+ private static String mapValidationExceptionToMessage(ValidationException exception) {
+ if (exception.getViolatedSchema() instanceof EnumSchema) {
+ return mapEnumViolationToMessage(exception);
}
- return e0.getMessage();
+ return exception.getMessage();
}
- private static String mapEnumViolationToMessage(ValidationException e1) {
- Set<Object> possibleValues = ((EnumSchema) e1.getViolatedSchema()).getPossibleValues();
- return e1.getMessage().replaceFirst("enum value", possibleValues.size() == 1
+ private static String mapEnumViolationToMessage(ValidationException exception) {
+ Set<Object> possibleValues = ((EnumSchema) exception.getViolatedSchema()).getPossibleValues();
+ return exception.getMessage().replaceFirst("enum value", possibleValues.size() == 1
? String.format("value. %s is the only possible value for this field",
possibleValues.iterator().next())
: String.format("value. Possible values: %s", CommonMethods