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);
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations