package org.onap.cps.events;
import static org.onap.cps.events.model.EventPayload.Action.fromValue;
+import static org.onap.cps.utils.DataMapUtils.hasEntries;
import io.cloudevents.CloudEvent;
import io.micrometer.core.annotation.Timed;
+import java.io.Serializable;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
private CpsDataUpdatedEvent toCpsDataUpdatedEvent(final Anchor anchor, final OffsetDateTime observedTimestamp,
final DeltaReport deltaReport) {
final CloudEventData cloudEventData = new CloudEventData();
- cloudEventData.setSourceData(jsonObjectMapper.asJsonString(deltaReport.getSourceData()));
- cloudEventData.setTargetData(jsonObjectMapper.asJsonString(deltaReport.getTargetData()));
+ final Map<String, Serializable> sourceData = deltaReport.getSourceData();
+ final Map<String, Serializable> targetData = deltaReport.getTargetData();
+ if (hasEntries(sourceData)) {
+ cloudEventData.setSourceData(jsonObjectMapper.asJsonString(sourceData));
+ }
+ if (hasEntries(targetData)) {
+ cloudEventData.setTargetData(jsonObjectMapper.asJsonString(targetData));
+ }
final EventPayload updateEventData = new EventPayload();
updateEventData.setObservedTimestamp(DateTimeUtility.toString(observedTimestamp));
updateEventData.setDataspaceName(anchor.getDataspaceName());
.put("dataNodes", dataMaps).build();
}
+ public static boolean hasEntries(final Map<?, ?> map) {
+ return map != null && !map.isEmpty();
+ }
+
private static List<Map<String, Object>> toDataNodesWithIdentifier(final List<DataNode> dataNodeList,
final String prefix) {
final List<Map<String, Object>> dataMaps = new ArrayList<>(dataNodeList.size());
result.isEmpty()
}
+ def 'Check if a map is populated with #scenario.'() {
+ given: 'a map'
+ Map testMap = inputMap
+ when: 'checking if the map is populated'
+ boolean result = DataMapUtils.hasEntries(testMap)
+ then: 'the result contains expected value'
+ result == expectedResult
+ where: 'the following maps are checked'
+ scenario | inputMap || expectedResult
+ 'a null map' | null || false
+ 'an empty map' | [:] || false
+ 'a populated map' | [key: 'value'] || true
+ }
+
def dataNode = buildDataNode(
"/parent",[parentLeaf:'parentLeafValue', parentLeafList:['parentLeafListEntry1','parentLeafListEntry2']],[
buildDataNode('/parent/child-list[@id="1/2"]',[listElementLeaf:'listElement1leafValue'],noChildren),