aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/main/java/org/onap
diff options
context:
space:
mode:
authorelinuxhenrik <henrik.b.andersson@est.tech>2018-09-18 13:18:03 +0200
committerelinuxhenrik <henrik.b.andersson@est.tech>2018-09-18 21:47:48 +0200
commit5a61d0cb812ddd313953f7bbf5832cc5fb08240d (patch)
tree216f832d11c1bef94b45fb7bc0b30408a3c69134 /datafile-app-server/src/main/java/org/onap
parentf394594ec70aaf1eefa4f23b80226c3426dbc17a (diff)
Adapt to new VES specification for notifications
Change-Id: I0ba8e67714679dc02fb08ce94787b1f98034a6c4 Issue-ID: DCAEGEN2-782 Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Diffstat (limited to 'datafile-app-server/src/main/java/org/onap')
-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) {