Skip to content

Commit 55cef85

Browse files
authored
Merge pull request #1110 from OSGP/feature/SMHE-1818_update_firmware_no_file
Method without connection should be implemented
2 parents 5605e8d + 3752239 commit 55cef85

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/DeviceRequestMessageProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ protected Serializable handleMessage(
239239
final MessageMetadata messageMetadata)
240240
throws OsgpException {
241241
throw new UnsupportedOperationException(
242-
"handleMessage(Serializable) should be overriden by a subclass, or usesDeviceConnection should return"
242+
"handleMessage(Serializable) should be overridden by a subclass, or usesDeviceConnection should return"
243243
+ " true.");
244244
}
245245

osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/UpdateFirmwareRequestMessageProcessor.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,46 @@ protected boolean usesDeviceConnection(final Serializable messageObject) {
5454
return super.usesDeviceConnection(messageObject);
5555
}
5656

57+
@Override
58+
protected Serializable handleMessage(
59+
final DlmsDevice device,
60+
final Serializable requestObject,
61+
final MessageMetadata messageMetadata)
62+
throws OsgpException {
63+
// This method will be invoked when usesDeviceConnection returns false (firmwareFile is not
64+
// available)
65+
final String deviceIdentification = messageMetadata.getDeviceIdentification();
66+
final String organisationIdentification = messageMetadata.getOrganisationIdentification();
67+
final String correlationUid = messageMetadata.getCorrelationUid();
68+
69+
final UpdateFirmwareRequestDto updateFirmwareRequestDto =
70+
(UpdateFirmwareRequestDto) requestObject;
71+
final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
72+
73+
LOGGER.info(
74+
"[{}] - Firmware file [{}] not available. Sending GetFirmwareFile request to core.",
75+
correlationUid,
76+
firmwareIdentification);
77+
final RequestMessage message =
78+
new RequestMessage(
79+
correlationUid,
80+
organisationIdentification,
81+
deviceIdentification,
82+
updateFirmwareRequestDto);
83+
this.osgpRequestMessageSender.sendWithReplyToThisInstance(
84+
message, MessageType.GET_FIRMWARE_FILE.name(), messageMetadata);
85+
return NO_RESPONSE;
86+
}
87+
5788
@Override
5889
protected Serializable handleMessage(
5990
final DlmsConnectionManager conn,
6091
final DlmsDevice device,
6192
final Serializable requestObject,
6293
final MessageMetadata messageMetadata)
6394
throws OsgpException {
95+
// This method will be invoked when usesDeviceConnection returns true (firmwareFile is
96+
// available)
6497
final String deviceIdentification = messageMetadata.getDeviceIdentification();
6598
final String organisationIdentification = messageMetadata.getOrganisationIdentification();
6699
final String correlationUid = messageMetadata.getCorrelationUid();
@@ -78,28 +111,12 @@ protected Serializable handleMessage(
78111
(UpdateFirmwareRequestDto) requestObject;
79112
final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
80113

81-
if (this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)) {
82-
LOGGER.info(
83-
"[{}] - Firmware file [{}] available. Updating firmware on device [{}]",
84-
correlationUid,
85-
firmwareIdentification,
86-
deviceIdentification);
87-
return this.configurationService.updateFirmware(
88-
conn, device, updateFirmwareRequestDto, messageMetadata);
89-
} else {
90-
LOGGER.info(
91-
"[{}] - Firmware file [{}] not available. Sending GetFirmwareFile request to core.",
92-
correlationUid,
93-
firmwareIdentification);
94-
final RequestMessage message =
95-
new RequestMessage(
96-
correlationUid,
97-
organisationIdentification,
98-
deviceIdentification,
99-
updateFirmwareRequestDto);
100-
this.osgpRequestMessageSender.sendWithReplyToThisInstance(
101-
message, MessageType.GET_FIRMWARE_FILE.name(), messageMetadata);
102-
return NO_RESPONSE;
103-
}
114+
LOGGER.info(
115+
"[{}] - Firmware file [{}] available. Updating firmware on device [{}]",
116+
correlationUid,
117+
firmwareIdentification,
118+
deviceIdentification);
119+
return this.configurationService.updateFirmware(
120+
conn, device, updateFirmwareRequestDto, messageMetadata);
104121
}
105122
}

osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/UpdateFirmwareRequestMessageProcessorTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ void processMessageTaskShouldSendFirmwareFileRequestWhenFirmwareFileNotAvailable
112112
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification)).thenReturn(false);
113113

114114
// Act
115-
this.processor.processMessageTasks(
116-
message.getObject(), messageMetadata, this.dlmsConnectionManagerMock, this.device);
115+
this.processor.processMessageTasks(message.getObject(), messageMetadata, null, this.device);
117116

118117
// Assert
119118
verify(this.osgpRequestMessageSender, times(1))
@@ -219,4 +218,23 @@ void testUsesDeviceConnection(final boolean isFirmwareFileAvailable) {
219218
assertThat(this.processor.usesDeviceConnection(updateFirmwareRequestDto))
220219
.isEqualTo(isFirmwareFileAvailable);
221220
}
221+
222+
@ParameterizedTest
223+
@ValueSource(booleans = {true, false})
224+
void testProcessMessage(final boolean isFirmwareFileAvailable) throws JMSException {
225+
final String firmwareIdentification = "unavailable";
226+
final String deviceIdentification = "unavailableEither";
227+
final UpdateFirmwareRequestDto updateFirmwareRequestDto =
228+
new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
229+
final ObjectMessage message =
230+
new ObjectMessageBuilder()
231+
.withObject(updateFirmwareRequestDto)
232+
.withCorrelationUid("123456")
233+
.build();
234+
235+
when(this.firmwareService.isFirmwareFileAvailable(firmwareIdentification))
236+
.thenReturn(isFirmwareFileAvailable);
237+
238+
this.processor.processMessage(message);
239+
}
222240
}

0 commit comments

Comments
 (0)