aboutsummaryrefslogtreecommitdiffstats
path: root/datafile-app-server
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
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')
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java62
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java117
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java43
3 files changed, 140 insertions, 82 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) {
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
index dc51343d..4aad5f45 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java
@@ -16,21 +16,22 @@
package org.onap.dcaegen2.collectors.datafile.service;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-
import java.util.List;
import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -42,122 +43,150 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingCorrectJson_validationNotThrowingAnException() throws DmaapNotFoundException {
- // given
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
.fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
- String messageString = message.toString();
-
- String parsedString = message.getParsed();
-
FileData expectedFileData = ImmutableFileData.builder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
.compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
- // when
+
+ String messageString = message.toString();
+ String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- List<FileData> listOfFileData = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
- // then
- Assertions.assertNotNull(listOfFileData);
- Assertions.assertEquals(expectedFileData, listOfFileData.get(0));
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(expectedFileData, fileDataResult.get(0));
}
@Test
- void whenPassingCorrectJsonWihoutLocation_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().compression("gzip")
+ void whenPassingCorrectJsonWihoutName_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
.fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
+ JsonElement jsonElement = new JsonParser().parse(parsedString);
+ Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
+ .getJsonObjectFromAnArray(jsonElement);
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
+ }
+
+ @Test
+ void whenPassingCorrectJsonWihoutLocation_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+
+ String messageString = message.toString();
+ String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutCompression_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutCompression_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
.fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatType_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingCorrectJsonWihoutFileFormatType_noFileData() {
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
.fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
.changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(0, fileDataResult.size());
}
@Test
- void whenPassingCorrectJsonWihoutFileFormatVersion_validationThrowingAnException() {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ void whenPassingOneCorrectJsonWihoutFileFormatVersionAndOneCorrect_oneFileData() {
+ AdditionalField additionalFaultyField =
+ new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").build();
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
- .fileFormatType("org.3GPP.32.435#measCollec").build();
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
- .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField).build();
+ .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalFaultyField)
+ .addAdditionalField(additionalField).build();
String messageString = message.toString();
-
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription()
- .expectError(DmaapNotFoundException.class).verify();
+
+ List<FileData> fileDataResult = dmaapConsumerJsonParser.getJsonObject(Mono.just((messageString))).block();
+
+ assertNotNull(fileDataResult);
+ assertEquals(1, fileDataResult.size());
}
- // Fixed temprarily
@Test
void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() {
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES_INVALID")
.changeType("FileReady_INVALID").notificationFieldsVersion("1.0_INVALID").build();
- String incorrectMessageString = message.toString();
+ String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
+
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
@@ -165,15 +194,15 @@ class DmaapConsumerJsonParserTest {
@Test
void whenPassingJsonWithNullJsonElement_validationThrowingAnException() {
JsonMessage message = new JsonMessage.JsonMessageBuilder().build();
- String incorrectMessageString = message.toString();
+ String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
-
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser)
.getJsonObjectFromAnArray(jsonElement);
+
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
index 264a9945..14251406 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java
@@ -2,17 +2,15 @@
* ============LICENSE_START======================================================================
* Copyright (C) 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
* ============LICENSE_END========================================================================
*/
@@ -42,12 +40,13 @@ public class JsonMessage {
/**
* Gets the message in parsed format.
+ *
* @return the massage in parsed format.
*/
public String getParsed() {
StringBuffer additionalFieldsString = new StringBuffer();
if (arrayOfAdditionalFields.size() > 0) {
- additionalFieldsString.append("\"arrayOfAdditionalFields\": [");
+ additionalFieldsString.append("\"arrayOfNamedHashMap\": [");
for (Iterator<AdditionalField> iterator = arrayOfAdditionalFields.iterator(); iterator.hasNext();) {
AdditionalField additionalField = iterator.next();
additionalFieldsString.append(additionalField.toString());
@@ -82,6 +81,7 @@ public class JsonMessage {
}
public static class AdditionalField {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
@@ -89,17 +89,19 @@ public class JsonMessage {
@Override
public String toString() {
- return "{"
+ return "{" + getAsStringIfParameterIsSet("name", name, true)
+ + "\"hashMap\":{"
+ getAsStringIfParameterIsSet("location", location,
compression != null || fileFormatType != null || fileFormatVersion != null)
+ getAsStringIfParameterIsSet("compression", compression,
fileFormatType != null || fileFormatVersion != null)
+ getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null)
- + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) + "}";
+ + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) + "}}";
}
private AdditionalField(AdditionalFieldBuilder builder) {
+ this.name = builder.name;
this.location = builder.location;
this.compression = builder.compression;
this.fileFormatType = builder.fileFormatType;
@@ -109,11 +111,17 @@ public class JsonMessage {
}
public static class AdditionalFieldBuilder {
+ private String name;
private String location;
private String compression;
private String fileFormatType;
private String fileFormatVersion;
+ public AdditionalFieldBuilder name(String name) {
+ this.name = name;
+ return this;
+ }
+
public AdditionalFieldBuilder location(String location) {
this.location = location;
return this;
@@ -190,14 +198,15 @@ public class JsonMessage {
* @param args Not used
*/
public static void main(String[] args) {
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
.location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
.fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
- AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder()
- .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
- .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
+ AdditionalField secondAdditionalField =
+ new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz")
+ .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip")
+ .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build();
JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES")
- .changeType("FileReady").notificationFieldsVersion("1.0").addAdditionalField(additionalField)
+ .changeType("FileReady").notificationFieldsVersion("2.0").addAdditionalField(additionalField)
.addAdditionalField(secondAdditionalField).build();
System.out.println(message.toString());
}