From 2c4c61213c9f2f8fba83a2244fa7afe0a6feb481 Mon Sep 17 00:00:00 2001 From: Eli Halych Date: Mon, 7 Dec 2020 13:13:53 +0000 Subject: Allow customization of commonEventHeadres before request is sent Details: - Python handler is allowed to take --data argument with fields to be overriden. - In python handler the original dictionary from config.json is merged with custom sourceName and reportingEntityName if provided. - Java source code generates default sourceName and reportingEntityName as part of default data in the form of "default-XXX", where XXX is YEAR, MONTH and DAY as integers. - If such default data is received in the request body, don't override them with default values. - BUG FIXED: the previous solution used abstract path that could be "/" that resulted in empty strings for sourceName and reportingEntityName. Issue-ID: INT-1800 Signed-off-by: Eli Halych Change-Id: Ic88c5606a44abac64f842f28621332f3f86b83c6 --- .../org/onap/pnfsimulator/message/JSONObjectFactory.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'test/mocks/masspnfsim/pnf-sim-lightweight/src') diff --git a/test/mocks/masspnfsim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java b/test/mocks/masspnfsim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java index ded991044..7c12983f0 100644 --- a/test/mocks/masspnfsim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java +++ b/test/mocks/masspnfsim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java @@ -50,6 +50,7 @@ import static org.onap.pnfsimulator.message.MessageConstants.VERSION; import static org.onap.pnfsimulator.message.MessageConstants.VERSION_NUMBER; import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION; import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION_NUMBER; +import java.util.Calendar; import java.io.File; import java.util.List; import java.util.TimeZone; @@ -61,6 +62,7 @@ final class JSONObjectFactory { static JSONObject generateConstantCommonEventHeader() { JSONObject commonEventHeader = new JSONObject(); long timestamp = System.currentTimeMillis(); + String nodeName = generateDefaultName(); commonEventHeader.put(EVENT_ID, generateEventId()); commonEventHeader.put(TIME_ZONE_OFFSET, generateTimeZone(timestamp)); commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp); @@ -70,8 +72,6 @@ final class JSONObjectFactory { commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject()); commonEventHeader.put(VERSION, VERSION_NUMBER); commonEventHeader.put(VES_EVENT_LISTENER_VERSION, VES_EVENT_LISTENER_VERSION_NUMBER); - String absPath = new File("").getAbsolutePath(); - String nodeName = absPath.substring(absPath.lastIndexOf(File.separator)+1); commonEventHeader.put(SOURCE_NAME, nodeName); commonEventHeader.put(REPORTING_ENTITY_NAME, nodeName); return commonEventHeader; @@ -118,6 +118,15 @@ final class JSONObjectFactory { return String.format("FileReady_%s", timeAsString); } + static String generateDefaultName() { + String defaultName = "default"; + int year = Calendar.getInstance().get(Calendar.YEAR); + int month = Calendar.getInstance().get(Calendar.MONTH); + int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); + + return defaultName + "-" + year + month + day; + } + static String generateTimeZone(long timestamp) { TimeZone timeZone = TimeZone.getDefault(); int offsetInMillis = timeZone.getOffset(timestamp); -- cgit 1.2.3-korg