aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/main
diff options
context:
space:
mode:
authorVijay Venkatesh Kumar <vv770d@att.com>2018-09-19 13:48:47 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-19 13:48:47 +0000
commit7051ab4c0776b0978afbb9507b6886996eb5748c (patch)
tree265135a84d7f02d69d4fb0337a6e31d749cb2a0a /datafile-app-server/src/main
parent93adeb4a2503fbdb4d8e06d777a4aa836b28d720 (diff)
parent5a61d0cb812ddd313953f7bbf5832cc5fb08240d (diff)
Merge "Adapt to new VES specification for notifications"
Diffstat (limited to 'datafile-app-server/src/main')
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java62
1 files changed, 41 insertions, 21 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
index 98f3a72a..c71d1435 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java
@@ -28,6 +28,8 @@ import java.util.stream.StreamSupport;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;
@@ -40,12 +42,17 @@ import reactor.core.publisher.Mono;
*/
public class DmaapConsumerJsonParser {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DmaapConsumerJsonParser.class);
+
private static final String EVENT = "event";
private static final String NOTIFICATION_FIELDS = "notificationFields";
private static final String CHANGE_IDENTIFIER = "changeIdentifier";
private static final String CHANGE_TYPE = "changeType";
private static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion";
+ private static final String ARRAY_OF_NAMED_HASH_MAP = "arrayOfNamedHashMap";
+ private static final String NAME = "name";
+ private static final String HASH_MAP = "hashMap";
private static final String LOCATION = "location";
private static final String COMPRESSION = "compression";
private static final String FILE_FORMAT_TYPE = "fileFormatType";
@@ -93,21 +100,20 @@ public class DmaapConsumerJsonParser {
String changeIdentifier = getValueFromJson(notificationFields, CHANGE_IDENTIFIER);
String changeType = getValueFromJson(notificationFields, CHANGE_TYPE);
String notificationFieldsVersion = getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION);
- JsonArray arrayOfAdditionalFields = notificationFields.getAsJsonArray("arrayOfAdditionalFields");
+ JsonArray arrayOfNamedHashMap = notificationFields.getAsJsonArray(ARRAY_OF_NAMED_HASH_MAP);
if (isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)
- && arrayOfAdditionalFields != null) {
- Mono<List<FileData>> res =
- getFileDataFromJson(changeIdentifier, changeType, arrayOfAdditionalFields);
+ && arrayOfNamedHashMap != null) {
+ Mono<List<FileData>> res = getAllFileDataFromJson(changeIdentifier, changeType, arrayOfNamedHashMap);
return res;
}
if (!isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion)) {
return Mono.error(
new DmaapNotFoundException("FileReady event header is missing information. " + jsonObject));
- } else if (arrayOfAdditionalFields != null) {
- return Mono.error(new DmaapNotFoundException(
- "FileReady event arrayOfAdditionalFields is missing. " + jsonObject));
+ } else if (arrayOfNamedHashMap != null) {
+ return Mono.error(
+ new DmaapNotFoundException("FileReady event arrayOfNamedHashMap is missing. " + jsonObject));
}
return Mono.error(
new DmaapNotFoundException("FileReady event does not contain correct information. " + jsonObject));
@@ -117,30 +123,43 @@ public class DmaapConsumerJsonParser {
}
- private Mono<List<FileData>> getFileDataFromJson(String changeIdentifier, String changeType,
+ private Mono<List<FileData>> getAllFileDataFromJson(String changeIdentifier, String changeType,
JsonArray arrayOfAdditionalFields) {
List<FileData> res = new ArrayList<>();
for (int i = 0; i < arrayOfAdditionalFields.size(); i++) {
if (arrayOfAdditionalFields.get(i) != null) {
JsonObject fileInfo = (JsonObject) arrayOfAdditionalFields.get(i);
- String fileFormatType = getValueFromJson(fileInfo, FILE_FORMAT_TYPE);
- String fileFormatVersion = getValueFromJson(fileInfo, FILE_FORMAT_VERSION);
- String location = getValueFromJson(fileInfo, LOCATION);
- String compression = getValueFromJson(fileInfo, COMPRESSION);
- if (isFileFormatFieldsNotEmpty(fileFormatVersion, fileFormatType)
- && isLocationAndCompressionNotEmpty(location, compression)) {
- res.add(ImmutableFileData.builder().changeIdentifier(changeIdentifier).changeType(changeType)
- .location(location).compression(compression).fileFormatType(fileFormatType)
- .fileFormatVersion(fileFormatVersion).build());
+ FileData fileData = getFileDataFromJson(fileInfo, changeIdentifier, changeType);
+
+ if (fileData != null) {
+ res.add(fileData);
} else {
- return Mono.error(new DmaapNotFoundException(
- "FileReady event does not contain correct file format information. " + fileInfo));
+ LOGGER.error("Unable to collect file from xNF. File information wrong. " + fileInfo);
}
}
}
return Mono.just(res);
}
+ private FileData getFileDataFromJson(JsonObject fileInfo, String changeIdentifier, String changeType) {
+ FileData fileData = null;
+
+ String name = getValueFromJson(fileInfo, NAME);
+ JsonObject data = fileInfo.getAsJsonObject(HASH_MAP);
+ String fileFormatType = getValueFromJson(data, FILE_FORMAT_TYPE);
+ String fileFormatVersion = getValueFromJson(data, FILE_FORMAT_VERSION);
+ String location = getValueFromJson(data, LOCATION);
+ String compression = getValueFromJson(data, COMPRESSION);
+
+ if (isFileFormatFieldsNotEmpty(fileFormatVersion, fileFormatType)
+ && isNameAndLocationAndCompressionNotEmpty(name, location, compression)) {
+ fileData = ImmutableFileData.builder().changeIdentifier(changeIdentifier).changeType(changeType)
+ .location(location).compression(compression).fileFormatType(fileFormatType)
+ .fileFormatVersion(fileFormatVersion).build();
+ }
+ return fileData;
+ }
+
private String getValueFromJson(JsonObject jsonObject, String jsonKey) {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
@@ -157,8 +176,9 @@ public class DmaapConsumerJsonParser {
&& (fileFormatType != null && !fileFormatType.isEmpty()));
}
- private boolean isLocationAndCompressionNotEmpty(String location, String compression) {
- return (location != null && !location.isEmpty()) && (compression != null && !compression.isEmpty());
+ private boolean isNameAndLocationAndCompressionNotEmpty(String name, String location, String compression) {
+ return (name != null && !name.isEmpty()) && (location != null && !location.isEmpty())
+ && (compression != null && !compression.isEmpty());
}
private boolean containsHeader(JsonObject jsonObject) {