diff --git a/application/src/main/kotlin/org/gxf/crestdeviceservice/command/generator/AnalogAlarmsThresholdCommandGenerator.kt b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/generator/AnalogAlarmsThresholdCommandGenerator.kt index 1ab7a7a6..9466ea14 100644 --- a/application/src/main/kotlin/org/gxf/crestdeviceservice/command/generator/AnalogAlarmsThresholdCommandGenerator.kt +++ b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/generator/AnalogAlarmsThresholdCommandGenerator.kt @@ -4,8 +4,8 @@ package org.gxf.crestdeviceservice.command.generator import org.gxf.crestdeviceservice.command.entity.Command -import org.gxf.crestdeviceservice.command.exception.CommandValidationException import org.gxf.crestdeviceservice.command.mapper.AnalogAlarmThresholdCalculator +import org.gxf.crestdeviceservice.command.mapper.AnalogAlarmsThresholdTranslator import org.springframework.stereotype.Component @Component @@ -15,7 +15,7 @@ class AnalogAlarmsThresholdCommandGenerator : CommandGenerator { override fun generateCommandString(command: Command): String { val commandValue = command.commandValue!! val port = commandValue.substringBefore(':') - val channel = translatePortToChannel(port) + val channel = AnalogAlarmsThresholdTranslator.translatePortToChannel(port) val pressureValues = commandValue .substringAfter(':') @@ -25,11 +25,4 @@ class AnalogAlarmsThresholdCommandGenerator : CommandGenerator { .joinToString(",") return "$channel:$pressureValues" } - - private fun translatePortToChannel(port: String) = - when (port) { - "3" -> "AL6" - "4" -> "AL7" - else -> throw CommandValidationException("Device port unknown: $port") - } } diff --git a/application/src/main/kotlin/org/gxf/crestdeviceservice/command/mapper/AnalogAlarmsThresholdTranslator.kt b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/mapper/AnalogAlarmsThresholdTranslator.kt new file mode 100644 index 00000000..a88d73fc --- /dev/null +++ b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/mapper/AnalogAlarmsThresholdTranslator.kt @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 +package org.gxf.crestdeviceservice.command.mapper + +import org.gxf.crestdeviceservice.command.exception.CommandValidationException + +object AnalogAlarmsThresholdTranslator { + fun translatePortToChannel(port: String) = + when (port) { + "3" -> "AL6" + "4" -> "AL7" + else -> throw CommandValidationException("Device port unknown: $port") + } +} diff --git a/application/src/main/kotlin/org/gxf/crestdeviceservice/command/resulthandler/AnalogAlarmThresholdResultHandler.kt b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/resulthandler/AnalogAlarmThresholdResultHandler.kt index 6a5bd251..7c105266 100644 --- a/application/src/main/kotlin/org/gxf/crestdeviceservice/command/resulthandler/AnalogAlarmThresholdResultHandler.kt +++ b/application/src/main/kotlin/org/gxf/crestdeviceservice/command/resulthandler/AnalogAlarmThresholdResultHandler.kt @@ -5,6 +5,7 @@ package org.gxf.crestdeviceservice.command.resulthandler import com.fasterxml.jackson.databind.JsonNode import org.gxf.crestdeviceservice.command.entity.Command +import org.gxf.crestdeviceservice.command.mapper.AnalogAlarmsThresholdTranslator import org.gxf.crestdeviceservice.command.service.CommandFeedbackService import org.gxf.crestdeviceservice.command.service.CommandService import org.springframework.stereotype.Component @@ -31,5 +32,9 @@ class AnalogAlarmThresholdResultHandler( return body.urcs().any { it in fullErrorUrcs } } - private fun getChannelFromCommand(command: Command) = command.commandValue?.substringBefore(':') + private fun getChannelFromCommand(command: Command): String { + val commandValue = command.commandValue!! + val port = commandValue.substringBefore(':') + return AnalogAlarmsThresholdTranslator.translatePortToChannel(port) + } } diff --git a/application/src/test/kotlin/org/gxf/crestdeviceservice/CommandFactory.kt b/application/src/test/kotlin/org/gxf/crestdeviceservice/CommandFactory.kt index 39cd21ca..beae3f30 100644 --- a/application/src/test/kotlin/org/gxf/crestdeviceservice/CommandFactory.kt +++ b/application/src/test/kotlin/org/gxf/crestdeviceservice/CommandFactory.kt @@ -6,7 +6,6 @@ package org.gxf.crestdeviceservice import java.time.Instant import java.util.UUID import org.gxf.crestdeviceservice.TestConstants.ANALOG_ALARM_THRESHOLDS_MILLIBAR_PORT_3 -import org.gxf.crestdeviceservice.TestConstants.ANALOG_ALARM_THRESHOLDS_PAYLOAD_PORT_3 import org.gxf.crestdeviceservice.TestConstants.CORRELATION_ID import org.gxf.crestdeviceservice.TestConstants.DEVICE_ID import org.gxf.crestdeviceservice.TestConstants.timestamp @@ -66,7 +65,7 @@ object CommandFactory { status = status, ) - fun analogAlarmThresholdsCommandInProgess(value: String = ANALOG_ALARM_THRESHOLDS_PAYLOAD_PORT_3) = + fun analogAlarmThresholdsCommandInProgess(value: String = ANALOG_ALARM_THRESHOLDS_MILLIBAR_PORT_3) = pendingAnalogAlarmThresholdsCommand(value = value).start() fun rebootCommandInProgress() = pendingRebootCommand().start()