Search in sources :

Example 1 with UpdateFirmwareResponseDto

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"));
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 2 with 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);
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateFirmwareResponseDto

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);
    }
}
Also used : UpdateFirmwareResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) ImageTransferException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)

Aggregations

UpdateFirmwareResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareResponseDto)3 ObjectMessage (javax.jms.ObjectMessage)1 Test (org.junit.jupiter.api.Test)1 FirmwareFile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile)1 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)1 ImageTransferException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ImageTransferException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)1 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)1 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)1