forked from OSGP/sng-crest-device-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OSGP#97 from OSGP/feature/FDP-2874-get-analog-alar…
…m-thresholds-command Feature/fdp 2874 get analog alarm thresholds command
- Loading branch information
Showing
37 changed files
with
568 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...n/kotlin/org/gxf/crestdeviceservice/command/feedbackgenerator/CommandFeedbackGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.gxf.crestdeviceservice.command.feedbackgenerator | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import org.gxf.crestdeviceservice.command.entity.Command.CommandType | ||
|
||
interface CommandFeedbackGenerator { | ||
val supportedCommandType: CommandType | ||
|
||
fun generateFeedback(message: JsonNode): String | ||
} |
14 changes: 14 additions & 0 deletions
14
...in/org/gxf/crestdeviceservice/command/feedbackgenerator/CommandFeedbackGeneratorConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.gxf.crestdeviceservice.command.feedbackgenerator | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class CommandFeedbackGeneratorConfig { | ||
@Bean | ||
fun commandFeedbackGeneratorsByType(commandFeedbackGenerators: List<CommandFeedbackGenerator>) = | ||
commandFeedbackGenerators.associateBy { it.supportedCommandType } | ||
} |
24 changes: 24 additions & 0 deletions
24
...otlin/org/gxf/crestdeviceservice/command/feedbackgenerator/InfoAlarmsFeedbackGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.gxf.crestdeviceservice.command.feedbackgenerator | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import org.gxf.crestdeviceservice.command.entity.Command | ||
import org.gxf.crestdeviceservice.command.mapper.AnalogAlarmThresholdCalculator | ||
import org.gxf.crestdeviceservice.command.service.AlarmsInfoService | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class InfoAlarmsFeedbackGenerator(private val alarmsInfoService: AlarmsInfoService) : CommandFeedbackGenerator { | ||
val mapper = jacksonObjectMapper() | ||
|
||
override val supportedCommandType = Command.CommandType.INFO_ALARMS | ||
|
||
override fun generateFeedback(message: JsonNode): String { | ||
val alarmsInfo = alarmsInfoService.getAlarmsInfo(message) | ||
val calculatedAlarmsInfo = AnalogAlarmThresholdCalculator.calculateThresholdsFromDevice(alarmsInfo) | ||
return mapper.writeValueAsString(calculatedAlarmsInfo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...c/main/kotlin/org/gxf/crestdeviceservice/command/resulthandler/InfoAlarmsResultHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.gxf.crestdeviceservice.command.resulthandler | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import org.gxf.crestdeviceservice.command.entity.Command | ||
import org.gxf.crestdeviceservice.command.service.AlarmsInfoService | ||
import org.gxf.crestdeviceservice.command.service.CommandFeedbackService | ||
import org.gxf.crestdeviceservice.command.service.CommandService | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class InfoAlarmsResultHandler( | ||
commandService: CommandService, | ||
commandFeedbackService: CommandFeedbackService, | ||
private val alarmsInfoService: AlarmsInfoService, | ||
) : CommandResultHandler(commandService, commandFeedbackService) { | ||
private val errorUrcs = listOf("INFO:DLER", "INFO:ERR", "INFO:DLNA") | ||
|
||
override val supportedCommandType = Command.CommandType.INFO_ALARMS | ||
|
||
override fun hasSucceeded(command: Command, message: JsonNode) = | ||
try { | ||
alarmsInfoService.getAlarmsInfo(message) | ||
true | ||
} catch (_: Exception) { | ||
false | ||
} | ||
|
||
override fun hasFailed(command: Command, message: JsonNode): Boolean = message.urcs().any { it in errorUrcs } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
application/src/main/kotlin/org/gxf/crestdeviceservice/command/service/AlarmsInfoService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-FileCopyrightText: Copyright Contributors to the GXF project | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package org.gxf.crestdeviceservice.command.service | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import org.gxf.crestdeviceservice.command.entity.Command | ||
import org.gxf.crestdeviceservice.command.resulthandler.CommandResultHandler.Companion.downlinks | ||
import org.gxf.crestdeviceservice.model.AlarmsInfo | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class AlarmsInfoService { | ||
private val mapper = jacksonObjectMapper() | ||
|
||
fun getAlarmsInfo(message: JsonNode): AlarmsInfo { | ||
val downlink = message.downlinks().first { it.contains(Command.CommandType.INFO_ALARMS.downlink) } | ||
val json = downlink.substringAfter(", ") | ||
|
||
return mapper.readValue<AlarmsInfo>(json) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.