use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareResponseMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) throws FunctionalException {
if (responseMessage.getDataObject() instanceof UpdateFirmwareResponseDto) {
final UpdateFirmwareResponseDto updateFirmwareResponse = (UpdateFirmwareResponseDto) responseMessage.getDataObject();
this.configurationService.handleUpdateFirmwareResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, updateFirmwareResponse);
} else {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new OsgpException(ComponentType.DOMAIN_SMART_METERING, "DataObject for response message should be of type UpdateFirmwareResponseDto"));
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendOkResponseMessageContainingFirmwareVersions.
@Test
void processMessageShouldSendOkResponseMessageContainingFirmwareVersions() throws OsgpException, JMSException {
// arrange
final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
final UpdateFirmwareResponseDto updateFirmwareResponseDto = new UpdateFirmwareResponseDto(firmwareFileDto.getFirmwareIdentification());
final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenReturn(updateFirmwareResponseDto);
// act
this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
// assert
verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
assertThat(responseMessageArgumentCaptor.getValue().getDataObject()).isSameAs(updateFirmwareResponseDto);
assertThat(responseMessageArgumentCaptor.getValue().getResult()).isSameAs(ResponseMessageResultType.OK);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto in project open-smart-grid-platform by OSGP.
the class UpdateFirmwareCommandExecutor method execute.
@Override
public UpdateFirmwareResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice device, final UpdateFirmwareRequestDto updateFirmwareRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
final String firmwareIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
final FirmwareFile firmwareFile = this.getFirmwareFile(updateFirmwareRequestDto, messageMetadata);
final ImageTransfer transfer = new ImageTransfer(conn, this.imageTransferProperties, this.getImageIdentifier(firmwareIdentification, firmwareFile), firmwareFile.getByteArray());
try {
this.prepare(transfer);
this.transfer(transfer);
if (!firmwareFile.isMbusFirmware()) {
this.verify(transfer);
this.activate(transfer);
} else {
this.activateWithoutVerification(transfer);
}
return new UpdateFirmwareResponseDto(firmwareIdentification);
} catch (final ImageTransferException | ProtocolAdapterException e) {
throw new ProtocolAdapterException(EXCEPTION_MSG_UPDATE_FAILED, e);
}
}
Aggregations