Search in sources :

Example 1 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class FirmwareService method updateFirmware.

public UpdateFirmwareResponseDto updateFirmware(final DlmsConnectionManager conn, final DlmsDevice device, final FirmwareFileDto firmwareFileDto, final MessageMetadata messageMetadata) throws OsgpException {
    LOGGER.info("Updating firmware of device {} to firmware with identification {} using included firmware file", device, firmwareFileDto.getFirmwareIdentification());
    if (ArrayUtils.isEmpty(firmwareFileDto.getFirmwareFile())) {
        throw new ProtocolAdapterException(String.format(EXCEPTION_MSG_FIRMWARE_FILE_NOT_AVAILABLE, firmwareFileDto.getFirmwareIdentification()));
    }
    this.firmwareRepository.store(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getFirmwareFile());
    this.imageIdentifierRepository.store(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getImageIdentifier());
    return this.executeFirmwareUpdate(conn, device, new UpdateFirmwareRequestDto(firmwareFileDto.getFirmwareIdentification(), firmwareFileDto.getDeviceIdentification()), messageMetadata);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 2 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class FirmwareServiceTest method init.

@BeforeAll
public static void init() {
    messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
    updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileResponseMessageProcessor method createUpdateFirmwareRequestDto.

private UpdateFirmwareRequestDto createUpdateFirmwareRequestDto(final Serializable messageObject) {
    if (messageObject instanceof ProtocolResponseMessage) {
        final ProtocolResponseMessage protocolResponseMessage = (ProtocolResponseMessage) messageObject;
        final Serializable dataObject = protocolResponseMessage.getDataObject();
        if (dataObject instanceof FirmwareFileDto) {
            final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) dataObject;
            return new UpdateFirmwareRequestDto(firmwareFileDto.getFirmwareIdentification(), protocolResponseMessage.getDeviceIdentification());
        }
    }
    LOGGER.warn("Firmware Identification not present.");
    return null;
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) Serializable(java.io.Serializable) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 4 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    MessageMetadata metadata = null;
    Device device = null;
    String firmwareFileIdentification = StringUtils.EMPTY;
    try {
        metadata = MessageMetadata.fromMessage(message);
        LOGGER.info("[{}] - Received message of messageType: {}, organisationIdentification: {}, deviceIdentification: {}", metadata.getCorrelationUid(), metadata.getMessageType(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
        device = this.deviceRepository.findByDeviceIdentification(metadata.getDeviceIdentification());
        final RequestMessage requestMessage = (RequestMessage) message.getObject();
        final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestMessage.getRequest();
        firmwareFileIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
        final FirmwareFile firmwareFile = this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification);
        final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFileIdentification, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile.getFile(), firmwareFile.getImageIdentifier());
        this.sendSuccesResponse(metadata, device.getProtocolInfo(), firmwareFileDto);
    } catch (final Exception e) {
        LOGGER.error("Exception while retrieving firmware file: {}", firmwareFileIdentification);
        final OsgpException osgpException = new OsgpException(ComponentType.OSGP_CORE, "Exception while retrieving firmware file.", e);
        this.sendFailureResponse(metadata, device.getProtocolInfo(), osgpException);
    }
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 5 with UpdateFirmwareRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto in project open-smart-grid-platform by OSGP.

the class GetFirmwareFileMessageProcessorTest method processMessageShouldSendFirmwareFile.

@Test
public void processMessageShouldSendFirmwareFile() throws JMSException {
    // arrange
    final String correlationUid = "corr-uid-1";
    final String organisationIdentification = "test-org";
    final String deviceIdentification = "dvc-1";
    final String firmwareFileIdentification = "fw";
    final byte[] firmwareFileBytes = firmwareFileIdentification.getBytes();
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareFileIdentification, deviceIdentification);
    final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, updateFirmwareRequestDto);
    final ObjectMessage message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(DeviceFunction.GET_FIRMWARE_FILE.name()).withDeviceIdentification(deviceIdentification).withObject(requestMessage).build();
    when(this.deviceMock.getDeviceIdentification()).thenReturn(deviceIdentification);
    when(this.deviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(this.deviceMock);
    when(this.firmwareFileMock.getFilename()).thenReturn(firmwareFileIdentification);
    when(this.firmwareFileMock.getFile()).thenReturn(firmwareFileBytes);
    when(this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification)).thenReturn(this.firmwareFileMock);
    final byte[] expectedFile = firmwareFileBytes;
    final String expectedMessageType = DeviceFunction.GET_FIRMWARE_FILE.name();
    final ArgumentCaptor<ProtocolResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ProtocolResponseMessage.class);
    final ArgumentCaptor<String> messageTypeCaptor = ArgumentCaptor.forClass(String.class);
    // act
    this.getFirmwareFileMessageProcessor.processMessage(message);
    // assert
    verify(this.protocolResponseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture(), messageTypeCaptor.capture(), nullable(ProtocolInfo.class), any(MessageMetadata.class));
    final FirmwareFileDto actualFirmwareFileDto = (FirmwareFileDto) responseMessageArgumentCaptor.getValue().getDataObject();
    final String actualMessageType = messageTypeCaptor.getValue();
    assertThat(actualFirmwareFileDto.getFirmwareFile()).isEqualTo(expectedFile);
    assertThat(actualFirmwareFileDto.getDeviceIdentification()).isEqualTo(deviceIdentification);
    assertThat(actualFirmwareFileDto.getFirmwareIdentification()).isEqualTo(firmwareFileIdentification);
    assertThat(actualMessageType).isEqualTo(expectedMessageType);
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ObjectMessage(javax.jms.ObjectMessage) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)14 Test (org.junit.jupiter.api.Test)8 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)7 ObjectMessage (javax.jms.ObjectMessage)6 ObjectMessageBuilder (org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder)6 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)5 FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)4 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)3 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)2 Device (org.opensmartgridplatform.domain.core.entities.Device)2 Serializable (java.io.Serializable)1 JMSException (javax.jms.JMSException)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)1 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)1 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)1 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1