diff options
author | fkrzywka <filip.krzywka@nokia.com> | 2018-07-31 14:22:59 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 10:50:43 +0200 |
commit | 63f1796ec022705504742a5bd1700f9e20c33540 (patch) | |
tree | 63473c3fdbff6c0bc7a7606d26cb2dc8be5a1de4 /hv-collector-utils/src/main | |
parent | d76905b9c98ec32f17bb9568ff80c04068aa213e (diff) |
Move MessageParametersParser
To avoid dependency of utilities module on modules other than domain
Change-Id: I90ef8640a86501315d84848118d3e748aafd095c
Signed-off-by: fkrzywka <filip.krzywka@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-utils/src/main')
2 files changed, 0 insertions, 103 deletions
diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt deleted file mode 100644 index d115675d..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * 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 - * - * 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========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.messages - -import com.google.protobuf.ByteString -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.newBuilder -import javax.json.JsonObject - -/** - * @author Jakub Dudycz <jakub.dudycz@nokia.com> - * @since July 2018 - */ -class CommonEventHeaderParser { - fun parse(json: JsonObject): CommonEventHeader = newBuilder() - .setVersion(json.getString("version")) - .setDomain(Domain.valueOf(json.getString("domain"))) - .setSequence(json.getInt("sequence")) - .setPriority(Priority.forNumber(json.getInt("priority"))) - .setEventId(json.getString("version")) - .setEventName(json.getString("version")) - .setEventType(json.getString("version")) - .setStartEpochMicrosec(json.getJsonNumber("startEpochMicrosec").longValue()) - .setLastEpochMicrosec(json.getJsonNumber("lastEpochMicrosec").longValue()) - .setNfNamingCode(json.getString("nfNamingCode")) - .setNfcNamingCode(json.getString("nfcNamingCode")) - .setReportingEntityId(json.getString("reportingEntityId")) - .setReportingEntityName(ByteString.copyFromUtf8(json.getString("reportingEntityName"))) - .setSourceId(ByteString.copyFromUtf8(json.getString("sourceId"))) - .setSourceName(json.getString("sourceName")) - .build() - -} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt deleted file mode 100644 index 1621ba59..00000000 --- a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * 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 - * - * 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========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.messages - -import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters -import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType -import javax.json.JsonArray - -/** - * @author Jakub Dudycz <jakub.dudycz@nokia.com> - * @since July 2018 - */ -class MessageParametersParser( - private val commonEventHeaderParser: CommonEventHeaderParser = CommonEventHeaderParser()) { - - fun parse(request: JsonArray): List<MessageParameters> = - try { - request - .map { it.asJsonObject() } - .map { - val commonEventHeader = commonEventHeaderParser - .parse(it.getJsonObject("commonEventHeader")) - val messageType = MessageType.valueOf(it.getString("messageType")) - val messagesAmount = it.getJsonNumber("messagesAmount")?.longValue() - ?: throw ParsingException("\"messagesAmount\" could not be parsed from message.", - NullPointerException()) - MessageParameters(commonEventHeader, messageType, messagesAmount) - } - } catch (e: Exception) { - throw ParsingException("Parsing request body failed", e) - } - - internal class ParsingException(message: String, cause: Exception) : Exception(message, cause) -} |