Skip to content

Commit

Permalink
Merge pull request OSGP#93 from OSGP/feature/FDP-2929-alarm-command
Browse files Browse the repository at this point in the history
FDP-2929 ~ Fixes result handling for alarm thresholds
  • Loading branch information
loesimmens authored Jan 28, 2025
2 parents 7e88834 + 1a5cfc8 commit 8c12f22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(':')
Expand All @@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8c12f22

Please sign in to comment.