From 4fcf04234e5e1b1d4338f12d982a45edf317d795 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 13 Jun 2018 16:50:59 +0100 Subject: Add YAML plugin and cleanup for checkstyle Bringing in the APEX YAML plugin, allows events with YAML bodies to be consumed by APEX. Also clean up of event protocol interface to make it not specific for JSON. Also some checkstyle changes on classes impacted by event protocol interface change. Change-Id: I7c3867ac508096fd8acad2488e61db87dfa1d6bd Issue-ID: POLICY-862 Signed-off-by: liamfallon --- .../context/schema/avro/AvroSchemaHelper.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'plugins/plugins-context/context-schema/context-schema-avro/src/main') diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java index b4cc38602..5fba274ce 100644 --- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -113,11 +113,19 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } @Override - public Object createNewInstance(final JsonElement jsonElement) { - final Gson gson = new GsonBuilder().serializeNulls().create(); - final String elementJsonString = gson.toJson(jsonElement); + public Object createNewInstance(final Object incomingObject) { + if (incomingObject instanceof JsonElement) { + final Gson gson = new GsonBuilder().serializeNulls().create(); + final String elementJsonString = gson.toJson((JsonElement) incomingObject); - return createNewInstance(elementJsonString); + return createNewInstance(elementJsonString); + } + else { + final String returnString = getUserKey().getID() + ": the object \"" + incomingObject + + "\" is not an instance of JsonObject"; + LOGGER.warn(returnString); + throw new ContextRuntimeException(returnString); + } } @Override @@ -191,7 +199,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } @Override - public String marshal2Json(final Object object) { + public String marshal2String(final Object object) { // Condition the object for Avro encoding final Object conditionedObject = avroObjectMapper.mapToAvro(object); @@ -217,9 +225,9 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } @Override - public JsonElement marshal2JsonElement(final Object schemaObject) { + public JsonElement marshal2Object(final Object schemaObject) { // Get the object as a Json string - final String schemaObjectAsString = marshal2Json(schemaObject); + final String schemaObjectAsString = marshal2String(schemaObject); // Get a Gson instance to convert the Json string to an object created by Json final Gson gson = new Gson(); -- cgit 1.2.3-korg