aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-06-13 16:50:59 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-06-14 11:22:00 +0100
commit4fcf04234e5e1b1d4338f12d982a45edf317d795 (patch)
treea17fb2a9dd70064145312b75c9d1019086cb11c1 /services/services-engine
parent2e1da7176952e013276ef29638a313f3a1b49c00 (diff)
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 <liam.fallon@ericsson.com>
Diffstat (limited to 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java3
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java78
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java188
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java54
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java2
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java84
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java2
7 files changed, 271 insertions, 140 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
index 552f949a2..99728c02e 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -160,7 +161,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
* @throws ApexEventException the apex event exception
*/
private String validKey(final String key) throws ApexEventException {
- if (key.matches(NAME_REGEXP)) {
+ if (key.matches(AxReferenceKey.LOCAL_NAME_REGEXP)) {
return key;
}
else {
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
index e40bc756c..07185c024 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReader.java
@@ -45,8 +45,16 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
// The amount of time to wait for input on the text block reader
private static final long TEXT_BLOCK_DELAY = 250;
- // Tag for the start of a text block
+ // Tag for the start and end of text blocks
private final String blockStartToken;
+ private final String blockEndToken;
+
+ // Indicates that text block processing starts at the first block of text
+ private final boolean delimiterAtStart;
+ private boolean blockEndTokenUsed = false;
+
+ // The thread used to read the text from the stream
+ Thread textConsumputionThread;
// The input stream for text
private InputStream inputStream;
@@ -54,37 +62,49 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
// The lines of input read from the input stream
private final Queue<String> textLineQueue = new LinkedBlockingQueue<>();
- // The thread used to read text from the input stream
- private Thread textConsumputionThread;
-
// True while EOF has not been seen on input
private boolean eofOnInputStream = false;
/**
- * Constructor, initialize the text block reader.
+ * Constructor, initialize the text block reader using token delimited event protocol parameters.
*
- * @param blockStartToken the block start token for the start of a text block
+ * @param tokenDelimitedParameters
+ * the token delimited event protocol parameters
*/
- public HeaderDelimitedTextBlockReader(final String blockStartToken) {
- this.blockStartToken = blockStartToken;
+ public HeaderDelimitedTextBlockReader(final EventProtocolTextTokenDelimitedParameters tokenDelimitedParameters) {
+ this(tokenDelimitedParameters.getStartDelimiterToken(), tokenDelimitedParameters.getEndDelimiterToken(),
+ tokenDelimitedParameters.isDelimiterAtStart());
}
/**
- * Constructor, initialize the text block reader using token delimited event protocol
- * parameters.
+ * Constructor, initialize the text block reader.
*
- * @param tokenDelimitedParameters the token delimited event protocol parameters
+ * @param blockStartToken
+ * the block start token for the start of a text block
+ * @param blockEndToken
+ * the block end token for the end of a text block
+ * @param delimiterAtStart
+ * indicates that text block processing starts at the first block of text
*/
- public HeaderDelimitedTextBlockReader(final EventProtocolTextTokenDelimitedParameters tokenDelimitedParameters) {
- this.blockStartToken = tokenDelimitedParameters.getDelimiterToken();
+ public HeaderDelimitedTextBlockReader(final String blockStartToken, final String blockEndToken,
+ final boolean delimiterAtStart) {
+ this.blockStartToken = blockStartToken;
+ this.delimiterAtStart = delimiterAtStart;
+
+ if (blockEndToken == null) {
+ this.blockEndToken = blockStartToken;
+ this.blockEndTokenUsed = false;
+ } else {
+ this.blockEndToken = blockEndToken;
+ this.blockEndTokenUsed = true;
+ }
}
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader#
- * init( java.io.InputStream)
+ * @see org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader# init(
+ * java.io.InputStream)
*/
@Override
public void init(final InputStream incomingInputStream) {
@@ -99,9 +119,7 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader#
- * readTextBlock()
+ * @see org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlockReader# readTextBlock()
*/
@Override
public TextBlock readTextBlock() throws IOException {
@@ -109,32 +127,42 @@ public class HeaderDelimitedTextBlockReader implements TextBlockReader, Runnable
final StringBuilder textBlockBuilder = new StringBuilder();
// Wait for the timeout period if there is no input
- if (!eofOnInputStream && textLineQueue.size() == 0) {
+ if (!eofOnInputStream && textLineQueue.isEmpty()) {
ThreadUtilities.sleep(TEXT_BLOCK_DELAY);
}
// Scan the lines in the queue
- while (textLineQueue.size() > 0) {
+ while (!textLineQueue.isEmpty()) {
// Scroll down in the available lines looking for the start of the text block
- if (textLineQueue.peek().startsWith(blockStartToken)) {
+ if (!delimiterAtStart || textLineQueue.peek().startsWith(blockStartToken)) {
// Process the input line header
textBlockBuilder.append(textLineQueue.remove());
textBlockBuilder.append('\n');
break;
} else {
- LOGGER.warn("invalid input on consumer: " + textLineQueue.remove());
+ String consumer = textLineQueue.remove();
+ LOGGER.warn("invalid input on consumer: {}", consumer);
}
}
// Get the rest of the text document
- while (textLineQueue.size() > 0 && !textLineQueue.peek().startsWith(blockStartToken)) {
+ while (!textLineQueue.isEmpty() && !textLineQueue.peek().startsWith(blockEndToken)
+ && !textLineQueue.peek().startsWith(blockStartToken)) {
+ // We just strip out block end tokens because we use block start tokens to delimit the blocks of text
+ textBlockBuilder.append(textLineQueue.remove());
+ textBlockBuilder.append('\n');
+ }
+
+ // Check if we should add the block end token to the end of the text block
+ if (!textLineQueue.isEmpty() && blockEndTokenUsed && textLineQueue.peek().startsWith(blockEndToken)) {
+ // Process the input line header
textBlockBuilder.append(textLineQueue.remove());
textBlockBuilder.append('\n');
}
// Condition the text block and return it
final String textBlock = textBlockBuilder.toString().trim();
- final boolean endOfText = (eofOnInputStream && textLineQueue.size() == 0 ? true : false);
+ final boolean endOfText = (eofOnInputStream && textLineQueue.isEmpty() ? true : false);
if (textBlock.length() > 0) {
return new TextBlock(endOfText, textBlock);
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
index 3b21a29ca..223843631 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JSONEventConverter.java
@@ -43,8 +43,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
/**
- * The Class Apex2JSONEventConverter converts {@link ApexEvent} instances to and from JSON string
- * representations of Apex events.
+ * The Class Apex2JSONEventConverter converts {@link ApexEvent} instances to and from JSON string representations of
+ * Apex events.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -57,8 +57,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.
+ * @see org.onap.policy.apex.service.engine.event.ApexEventProtocolConverter#init(org.onap.policy.
* apex.service.parameters.eventprotocol.EventProtocolParameters)
*/
@Override
@@ -76,9 +75,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String,
- * java.lang.Object)
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#toApexEvent(java.lang.String, java.lang.Object)
*/
@Override
public List<ApexEvent> toApexEvent(final String eventName, final Object eventObject) throws ApexEventException {
@@ -100,12 +97,12 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
}
// The list of events we will return
- final List<ApexEvent> eventList = new ArrayList<ApexEvent>();
+ final List<ApexEvent> eventList = new ArrayList<>();
try {
// We may have a single JSON object with a single event or an array of JSON objects
- final Object decodedJsonObject =
- new GsonBuilder().serializeNulls().create().fromJson(jsonEventString, Object.class);
+ final Object decodedJsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ Object.class);
// Check if we have a list of objects
if (decodedJsonObject instanceof List) {
@@ -121,15 +118,15 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
eventList.add(jsonObject2ApexEvent(eventName, (JsonObject) jsonListObject));
} else {
throw new ApexEventException("incoming event (" + jsonEventString
- + ") is a JSON object array containing an invalid object " + jsonListObject);
+ + ") is a JSON object array containing an invalid object " + jsonListObject);
}
}
} else {
eventList.add(jsonStringApexEvent(eventName, jsonEventString));
}
} catch (final Exception e) {
- final String errorString =
- "Failed to unmarshal JSON event: " + e.getMessage() + ", event=" + jsonEventString;
+ final String errorString = "Failed to unmarshal JSON event: " + e.getMessage() + ", event="
+ + jsonEventString;
LOGGER.warn(errorString, e);
throw new ApexEventException(errorString, e);
}
@@ -141,8 +138,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/*
* (non-Javadoc)
*
- * @see
- * org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.
+ * @see org.onap.policy.apex.service.engine.event.ApexEventConverter#fromApexEvent(org.onap.policy.
* apex.service.engine.event.ApexEvent)
*/
@Override
@@ -154,8 +150,8 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
}
// Get the event definition for the event from the model service
- final AxEvent eventDefinition =
- ModelService.getModel(AxEvents.class).get(apexEvent.getName(), apexEvent.getVersion());
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
// Use a GSON Json object to marshal the Apex event to JSON
final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
@@ -177,7 +173,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (!apexEvent.containsKey(fieldName)) {
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getID() + " event to Json. "
- + "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
+ + "Field \"" + fieldName + "\" is missing, but is mandatory. Fields: " + apexEvent;
LOGGER.debug(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
@@ -187,9 +183,9 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
final Object fieldValue = apexEvent.get(fieldName);
// Get the schema helper
- final SchemaHelper fieldSchemaHelper =
- new SchemaHelperFactory().createSchemaHelper(eventField.getKey(), eventField.getSchema());
- jsonObject.add(fieldName, fieldSchemaHelper.marshal2JsonElement(fieldValue));
+ final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ eventField.getSchema());
+ jsonObject.add(fieldName, (JsonElement)fieldSchemaHelper.marshal2Object(fieldValue));
}
// Output JSON string in a pretty format
@@ -199,20 +195,23 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method converts a JSON object into an Apex event.
*
- * @param eventName the name of the event
- * @param jsonEventString the JSON string that holds the event
+ * @param eventName
+ * the name of the event
+ * @param jsonEventString
+ * the JSON string that holds the event
* @return the apex event that we have converted the JSON object into
- * @throws ApexEventException thrown on unmarshaling exceptions
+ * @throws ApexEventException
+ * thrown on unmarshaling exceptions
*/
private ApexEvent jsonStringApexEvent(final String eventName, final String jsonEventString)
- throws ApexEventException {
+ throws ApexEventException {
// Use GSON to read the event string
- final JsonObject jsonObject =
- new GsonBuilder().serializeNulls().create().fromJson(jsonEventString, JsonObject.class);
+ final JsonObject jsonObject = new GsonBuilder().serializeNulls().create().fromJson(jsonEventString,
+ JsonObject.class);
if (jsonObject == null || !jsonObject.isJsonObject()) {
throw new ApexEventException(
- "incoming event (" + jsonEventString + ") is not a JSON object or an JSON object array");
+ "incoming event (" + jsonEventString + ") is not a JSON object or an JSON object array");
}
return jsonObject2ApexEvent(eventName, jsonObject);
@@ -221,19 +220,22 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method converts a JSON object into an Apex event.
*
- * @param eventName the name of the event
- * @param jsonObject the JSON object that holds the event
+ * @param eventName
+ * the name of the event
+ * @param jsonObject
+ * the JSON object that holds the event
* @return the apex event that we have converted the JSON object into
- * @throws ApexEventException thrown on unmarshaling exceptions
+ * @throws ApexEventException
+ * thrown on unmarshaling exceptions
*/
private ApexEvent jsonObject2ApexEvent(final String eventName, final JsonObject jsonObject)
- throws ApexEventException {
+ throws ApexEventException {
// Process the mandatory Apex header
final ApexEvent apexEvent = processApexEventHeader(eventName, jsonObject);
// Get the event definition for the event from the model service
- final AxEvent eventDefinition =
- ModelService.getModel(AxEvents.class).get(apexEvent.getName(), apexEvent.getVersion());
+ final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(apexEvent.getName(),
+ apexEvent.getVersion());
// Iterate over the input fields in the event
for (final AxField eventField : eventDefinition.getFields()) {
@@ -241,7 +243,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (!hasJSONField(jsonObject, fieldName)) {
if (!eventField.getOptional()) {
final String errorMessage = "error parsing " + eventDefinition.getID() + " event from Json. "
- + "Field \"" + fieldName + "\" is missing, but is mandatory.";
+ + "Field \"" + fieldName + "\" is missing, but is mandatory.";
LOGGER.debug(errorMessage);
throw new ApexEventException(errorMessage);
}
@@ -252,8 +254,8 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
if (fieldValue != null && !fieldValue.isJsonNull()) {
// Get the schema helper
- final SchemaHelper fieldSchemaHelper =
- new SchemaHelperFactory().createSchemaHelper(eventField.getKey(), eventField.getSchema());
+ final SchemaHelper fieldSchemaHelper = new SchemaHelperFactory().createSchemaHelper(eventField.getKey(),
+ eventField.getSchema());
apexEvent.put(fieldName, fieldSchemaHelper.createNewInstance(fieldValue));
} else {
apexEvent.put(fieldName, null);
@@ -266,48 +268,48 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method processes the event header of an Apex event.
*
- * @param eventName the name of the event
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
+ * @param eventName
+ * the name of the event
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
* @return an apex event constructed using the header fields of the event
- * @throws ApexEventRuntimeException the apex event runtime exception
- * @throws ApexEventException on invalid events with missing header fields
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
+ * @throws ApexEventException
+ * on invalid events with missing header fields
*/
private ApexEvent processApexEventHeader(final String eventName, final JsonObject jsonObject)
- throws ApexEventRuntimeException, ApexEventException {
+ throws ApexEventException {
// Get the event header fields
- // @formatter:off
- String name = getJSONStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD, jsonPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
- String version = getJSONStringField(jsonObject, ApexEvent.VERSION_HEADER_FIELD, jsonPars.getVersionAlias(), ApexEvent.VERSION_REGEXP, false);
- String namespace = getJSONStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD, jsonPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
- String source = getJSONStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(), ApexEvent.SOURCE_REGEXP, false);
- String target = getJSONStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(), ApexEvent.TARGET_REGEXP, false);
- // @formatter:on
+ // @formatter:off
+ String name = getJSONStringField(jsonObject, ApexEvent.NAME_HEADER_FIELD, jsonPars.getNameAlias(), ApexEvent.NAME_REGEXP, false);
+ String version = getJSONStringField(jsonObject, ApexEvent.VERSION_HEADER_FIELD, jsonPars.getVersionAlias(), ApexEvent.VERSION_REGEXP, false);
+ String namespace = getJSONStringField(jsonObject, ApexEvent.NAMESPACE_HEADER_FIELD, jsonPars.getNameSpaceAlias(), ApexEvent.NAMESPACE_REGEXP, false);
+ String source = getJSONStringField(jsonObject, ApexEvent.SOURCE_HEADER_FIELD, jsonPars.getSourceAlias(), ApexEvent.SOURCE_REGEXP, false);
+ String target = getJSONStringField(jsonObject, ApexEvent.TARGET_HEADER_FIELD, jsonPars.getTargetAlias(), ApexEvent.TARGET_REGEXP, false);
+ // @formatter:on
+
+ // Check that an event name has been specified
+ if (name == null && eventName == null) {
+ throw new ApexEventRuntimeException(
+ "event received without mandatory parameter \"name\" on configuration or on event");
+ }
// Check if an event name was specified on the event parameters
if (eventName != null) {
if (name != null && !eventName.equals(name)) {
- LOGGER.warn("The incoming event name \"" + name + "\" does not match the configured event name \""
- + eventName + "\", using configured event name");
+ LOGGER.warn("The incoming event name \"{}\" does not match the configured event name \"{}\", using configured event name",
+ name, eventName);
}
name = eventName;
- } else {
- if (name == null) {
- throw new ApexEventRuntimeException(
- "event received without mandatory parameter \"name\" on configuration or on event");
- }
}
// Now, find the event definition in the model service. If version is null, the newest event
// definition in the model service is used
final AxEvent eventDefinition = ModelService.getModel(AxEvents.class).get(name, version);
if (eventDefinition == null) {
- if (version == null) {
- throw new ApexEventRuntimeException(
- "an event definition for an event named \"" + name + "\" not found in Apex model");
- } else {
- throw new ApexEventRuntimeException("an event definition for an event named \"" + name
- + "\" with version \"" + version + "\" not found in Apex model");
- }
+ throw new ApexEventRuntimeException("an event definition for an event named \"" + name
+ + "\" with version \"" + version + "\" not found in Apex model");
}
// Use the defined event version if no version is specified on the incoming fields
@@ -318,9 +320,9 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
// Check the name space is OK if it is defined, if not, use the name space from the model
if (namespace != null) {
if (!namespace.equals(eventDefinition.getNameSpace())) {
- throw new ApexEventRuntimeException(
- "namespace \"" + namespace + "\" on event \"" + name + "\" does not match namespace \""
- + eventDefinition.getNameSpace() + "\" for that event in the Apex model");
+ throw new ApexEventRuntimeException("namespace \"" + namespace + "\" on event \"" + name
+ + "\" does not match namespace \"" + eventDefinition.getNameSpace()
+ + "\" for that event in the Apex model");
}
} else {
namespace = eventDefinition.getNameSpace();
@@ -342,17 +344,22 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method gets an event string field from a JSON object.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
- * @param fieldAlias the alias for the field to find in the event, overrides the field name if
- * it is not null
- * @param fieldRE the regular expression to check the field against for validity
- * @param mandatory true if the field is mandatory
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param fieldRE
+ * the regular expression to check the field against for validity
+ * @param mandatory
+ * true if the field is mandatory
* @return the value of the field in the JSON object or null if the field is optional
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
private String getJSONStringField(final JsonObject jsonObject, final String fieldName, final String fieldAlias,
- final String fieldRE, final boolean mandatory) throws ApexEventRuntimeException {
+ final String fieldRE, final boolean mandatory) {
// Get the JSON field for the string field
final JsonElement jsonField = getJSONField(jsonObject, fieldName, fieldAlias, mandatory);
@@ -368,7 +375,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
} catch (final Exception e) {
// The element is not a string so throw an error
throw new ApexEventRuntimeException("field \"" + fieldName + "\" with type \""
- + jsonField.getClass().getCanonicalName() + "\" is not a string value");
+ + jsonField.getClass().getCanonicalName() + "\" is not a string value");
}
// Is regular expression checking required
@@ -379,7 +386,7 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
// Check the event field against its regular expression
if (!fieldValueString.matches(fieldRE)) {
throw new ApexEventRuntimeException(
- "field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
+ "field \"" + fieldName + "\" with value \"" + fieldValueString + "\" is invalid");
}
return fieldValueString;
@@ -388,16 +395,20 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method gets an event field from a JSON object.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
- * @param fieldAlias the alias for the field to find in the event, overrides the field name if
- * it is not null
- * @param mandatory true if the field is mandatory
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
+ * @param fieldAlias
+ * the alias for the field to find in the event, overrides the field name if it is not null
+ * @param mandatory
+ * true if the field is mandatory
* @return the value of the field in the JSON object or null if the field is optional
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
private JsonElement getJSONField(final JsonObject jsonObject, final String fieldName, final String fieldAlias,
- final boolean mandatory) throws ApexEventRuntimeException {
+ final boolean mandatory) {
// Check if we should use the alias for this field
String fieldToFind = fieldName;
@@ -421,12 +432,15 @@ public class Apex2JSONEventConverter implements ApexEventProtocolConverter {
/**
* This method if a JSON object has a named field.
*
- * @param jsonObject the JSON object containing the JSON representation of the incoming event
- * @param fieldName the field name to find in the event
+ * @param jsonObject
+ * the JSON object containing the JSON representation of the incoming event
+ * @param fieldName
+ * the field name to find in the event
* @return true if the field is present
- * @throws ApexEventRuntimeException the apex event runtime exception
+ * @throws ApexEventRuntimeException
+ * the apex event runtime exception
*/
- private boolean hasJSONField(final JsonObject jsonObject, final String fieldName) throws ApexEventRuntimeException {
+ private boolean hasJSONField(final JsonObject jsonObject, final String fieldName) {
// check for the field
return jsonObject.has(fieldName);
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
index b4a4055d7..5f2b74204 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JSONEventProtocolParameters.java
@@ -51,11 +51,11 @@ public class JSONEventProtocolParameters extends EventProtocolTextCharDelimitedP
// Aliases for Apex event header fields
// @formatter:off
- private final String nameAlias = null;
- private final String versionAlias = null;
- private final String nameSpaceAlias = null;
- private final String sourceAlias = null;
- private final String targetAlias = null;
+ private String nameAlias = null;
+ private String versionAlias = null;
+ private String nameSpaceAlias = null;
+ private String sourceAlias = null;
+ private String targetAlias = null;
// @formatter:on
/**
@@ -131,5 +131,49 @@ public class JSONEventProtocolParameters extends EventProtocolTextCharDelimitedP
public String getTargetAlias() {
return targetAlias;
}
+
+ /**
+ * Sets the name alias.
+ *
+ * @param nameAlias the new name alias
+ */
+ public void setNameAlias(String nameAlias) {
+ this.nameAlias = nameAlias;
+ }
+
+ /**
+ * Sets the version alias.
+ *
+ * @param versionAlias the new version alias
+ */
+ public void setVersionAlias(String versionAlias) {
+ this.versionAlias = versionAlias;
+ }
+ /**
+ * Sets the name space alias.
+ *
+ * @param nameSpaceAlias the new name space alias
+ */
+ public void setNameSpaceAlias(String nameSpaceAlias) {
+ this.nameSpaceAlias = nameSpaceAlias;
+ }
+
+ /**
+ * Sets the source alias.
+ *
+ * @param sourceAlias the new source alias
+ */
+ public void setSourceAlias(String sourceAlias) {
+ this.sourceAlias = sourceAlias;
+ }
+
+ /**
+ * Sets the target alias.
+ *
+ * @param targetAlias the new target alias
+ */
+ public void setTargetAlias(String targetAlias) {
+ this.targetAlias = targetAlias;
+ }
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
index f74c0f47b..9a9888652 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
@@ -589,7 +589,7 @@ final class EngineWorker implements EngineService {
runtimeJsonStringBuilder.append("{\"EntryName\":");
runtimeJsonStringBuilder.append(gson.toJson(contextEntry.getKey()));
runtimeJsonStringBuilder.append(",\"EntryContent\":");
- runtimeJsonStringBuilder.append(gson.toJson(schemaHelper.marshal2Json(contextEntry.getValue())));
+ runtimeJsonStringBuilder.append(gson.toJson(schemaHelper.marshal2String(contextEntry.getValue())));
// End of context entry
runtimeJsonStringBuilder.append("}");
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
index 37fbd32bf..91a6403df 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
@@ -23,56 +23,100 @@ package org.onap.policy.apex.service.parameters.eventprotocol;
import org.onap.policy.apex.service.parameters.ApexParameterValidator;
/**
- * An event protocol parameter class for token delimited textual event protocols that may be
- * specialized by event protocol plugins that require plugin specific parameters.
+ * An event protocol parameter class for token delimited textual event protocols that may be specialized by event
+ * protocol plugins that require plugin specific parameters.
*
* <p>
* The following parameters are defined:
* <ol>
- * <li>delimiterToken: the token string that delimits text blocks that contain events.
+ * <li>startDelimiterToken: the token string that delimits the start of text blocks that contain events.
+ * <li>endDelimiterToken: the token string that delimits the end of text blocks that contain events, this parameter is
+ * optional and defaults to null.
+ * <li>delimiterAtStart: indicates if the first text block should have a delimiter at the start (true), or whether
+ * processing of the first block should begin at the start of the text (false). The parameter is optional and defaults
+ * to true.
* </ol>
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public abstract class EventProtocolTextTokenDelimitedParameters extends EventProtocolParameters
- implements ApexParameterValidator {
+ implements ApexParameterValidator {
// The delimiter token for text blocks
- private String delimiterToken = null;
+ private String startDelimiterToken = null;
+ private String endDelimiterToken = null;
+ private boolean delimiterAtStart = true;
/**
- * Constructor to create an event protocol parameters instance with the name of a sub class of
- * this class.
+ * Constructor to create an event protocol parameters instance with the name of a sub class of this class.
*
- * @param parameterClassName the class name of a sub class of this class
+ * @param parameterClassName
+ * the class name of a sub class of this class
*/
public EventProtocolTextTokenDelimitedParameters(final String parameterClassName) {
super(parameterClassName);
}
/**
- * Gets the delimiter token that delimits events in the text.
+ * Gets the start delimiter token that delimits events in the text.
*
- * @return the delimiter token
+ * @return the start delimiter token
*/
- public String getDelimiterToken() {
- return delimiterToken;
+ public String getStartDelimiterToken() {
+ return startDelimiterToken;
}
+ /**
+ * Sets the start delimiter token that delimits events in the text.
+ *
+ * @param startDelimiterToken
+ * delimiterToken the delimiter token
+ */
+ public void setStartDelimiterToken(final String startDelimiterToken) {
+ this.startDelimiterToken = startDelimiterToken;
+ }
+
+ /**
+ * Gets the end delimiter token that delimits events in the text.
+ *
+ * @return the end delimiter token
+ */
+ public String getEndDelimiterToken() {
+ return endDelimiterToken;
+ }
/**
- * Sets the delimiter token that delimits events in the text.
+ * Sets the end delimiter token that delimits events in the text.
*
- * @param delimiterToken the delimiter token
+ * @param endDelimiterToken
+ * delimiterToken the delimiter token
+ */
+ public void setEndDelimiterToken(final String endDelimiterToken) {
+ this.endDelimiterToken = endDelimiterToken;
+ }
+
+ /**
+ * Does there have to be a delimiter at the start of the first text block?
+ *
+ * @return true if there must be a delimiter at the start of the text block
*/
- public void setDelimiterToken(final String delimiterToken) {
- this.delimiterToken = delimiterToken;
+ public boolean isDelimiterAtStart() {
+ return delimiterAtStart;
}
+ /**
+ * Sets if there has to be a delimiter at the start of the first text block?
+ *
+ * @param delimiterAtStart
+ * true if there must be a delimiter at the start of the text block
+ */
+ public void setDelimiterAtStart(boolean delimiterAtStart) {
+ this.delimiterAtStart = delimiterAtStart;
+ }
@Override
public String toString() {
- return "EventProtocolTextCharDelimitedParameters {" + super.toString() + "} [delimiterToken=" + delimiterToken
- + "]";
+ return "EventProtocolTextTokenDelimitedParameters [startDelimiterToken=" + startDelimiterToken
+ + ", endDelimiterToken=" + endDelimiterToken + ", delimiterAtStart=" + delimiterAtStart + "]";
}
/*
@@ -86,8 +130,8 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro
errorMessageBuilder.append(super.validate());
- if (delimiterToken == null || delimiterToken.length() == 0) {
- errorMessageBuilder.append(" text delimiter token not specified or is blank\n");
+ if (startDelimiterToken == null || startDelimiterToken.length() == 0) {
+ errorMessageBuilder.append(" text start delimiter token not specified or is blank\n");
}
return errorMessageBuilder.toString();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
index 99f938e10..bac271319 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperTokenDelimitedEventProtocolParameters.java
@@ -46,7 +46,7 @@ public class SuperTokenDelimitedEventProtocolParameters extends EventProtocolTex
this.setLabel(SUPER_TOKEN_EVENT_PROTOCOL_LABEL);
// Set the starting and ending delimiters for text blocks of JSON events
- this.setDelimiterToken(SUPER_TOKEN_DELIMITER);
+ this.setStartDelimiterToken(SUPER_TOKEN_DELIMITER);
// Set the event protocol plugin class
this.setEventProtocolPluginClass(SuperTokenDelimitedEventConverter.class.getCanonicalName());