Search in sources :

Example 6 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class ConfigurationService method handleGetFirmwareVersionResponse.

/**
 * Maps the firmware Dto's to value objects and sends it back to the ws-adapter layer
 *
 * @param messageMetadata contains the message meta data
 * @param deviceResult indicates whether the execution was successful
 * @param exception contains the exception if one was thrown
 * @param firmwareVersionList contains the firmware result list
 */
public void handleGetFirmwareVersionResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final List<FirmwareVersionDto> firmwareVersionList) {
    log.info("handleGetFirmwareVersionResponse for MessageType: {}", messageMetadata.getMessageType());
    ResponseMessageResultType result = deviceResult;
    if (exception != null) {
        log.error("Get firmware version response not ok. Unexpected Exception", exception);
        result = ResponseMessageResultType.NOT_OK;
    }
    final List<FirmwareVersion> firmwareVersions = this.configurationMapper.mapAsList(firmwareVersionList, FirmwareVersion.class);
    final FirmwareVersionResponse firmwareVersionResponse = new FirmwareVersionResponse(firmwareVersions);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(firmwareVersionResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
    this.firmwareService.saveFirmwareVersionsReturnedFromDevice(messageMetadata.getDeviceIdentification(), firmwareVersions);
}
Also used : FirmwareVersionResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FirmwareVersionResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 7 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareVersionGasConverter method convertFrom.

@Override
public FirmwareVersion convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.FirmwareVersionGas source, final Type<FirmwareVersion> destinationType, final MappingContext mappingContext) {
    if (source == null) {
        return null;
    }
    final FirmwareModuleType type = FirmwareModuleType.forDescription(source.getFirmwareModuleType().name());
    final String version = Hex.encodeHexString(source.getVersion());
    return new FirmwareVersion(type, version);
}
Also used : FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 8 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method checkSsldPendingFirmwareUpdateReturnsTrueAndDeletesPendingUpdateWithMatchingCorrelationUid.

@Test
void checkSsldPendingFirmwareUpdateReturnsTrueAndDeletesPendingUpdateWithMatchingCorrelationUid() {
    final String correlationUid = "correlation-uid-matching-pending-update";
    final CorrelationIds ids = new CorrelationIds(ORGANISATION_IDENTIFICATION, DEVICE_IDENTIFICATION, correlationUid);
    final List<FirmwareVersion> firmwareVersions = Collections.singletonList(new FirmwareVersion(FirmwareModuleType.FUNCTIONAL, VERSION_2));
    final SsldPendingFirmwareUpdate matchingPendingFirmwareUpdate = this.anSsldPendingFirmwareUpdate(437L, new Date(), DEVICE_IDENTIFICATION, correlationUid);
    when(this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(Arrays.asList(this.anSsldPendingFirmwareUpdate(457198L, new Date(), DEVICE_IDENTIFICATION, "some-other-correlation-uid"), matchingPendingFirmwareUpdate, this.anSsldPendingFirmwareUpdate(94085089L, new Date(), DEVICE_IDENTIFICATION, "yet-another-correlation-uid")));
    final boolean hasPendingFirmwareUpdate = this.firmwareManagementService.checkSsldPendingFirmwareUpdate(ids, firmwareVersions);
    assertThat(hasPendingFirmwareUpdate).isTrue();
    verify(this.ssldPendingFirmwareUpdateRepository).delete(matchingPendingFirmwareUpdate);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class BundleService method checkIfAdditionalActionIsNeeded.

private void checkIfAdditionalActionIsNeeded(final MessageMetadata messageMetadata, final BundleMessagesRequestDto bundleMessagesRequestDto) throws FunctionalException {
    for (final ActionResponseDto action : bundleMessagesRequestDto.getAllResponses()) {
        if (action instanceof CoupleMbusDeviceByChannelResponseDto) {
            this.mBusGatewayService.handleCoupleMbusDeviceByChannelResponse(messageMetadata, (CoupleMbusDeviceByChannelResponseDto) action);
        } else if (action instanceof DecoupleMbusDeviceResponseDto) {
            this.mBusGatewayService.handleDecoupleMbusDeviceResponse(messageMetadata, (DecoupleMbusDeviceResponseDto) action);
        } else if (action instanceof SetDeviceLifecycleStatusByChannelResponseDto) {
            this.managementService.setDeviceLifecycleStatusByChannel((SetDeviceLifecycleStatusByChannelResponseDto) action);
        } else if (action instanceof EventMessageDataResponseDto) {
            this.eventService.enrichEvents(messageMetadata, (EventMessageDataResponseDto) action);
        } else if (action instanceof FirmwareVersionResponseDto) {
            final List<FirmwareVersion> firmwareVersions = this.configurationMapper.mapAsList(((FirmwareVersionResponseDto) action).getFirmwareVersions(), FirmwareVersion.class);
            this.firmwareService.saveFirmwareVersionsReturnedFromDevice(messageMetadata.getDeviceIdentification(), firmwareVersions);
        } else if (action instanceof FirmwareVersionGasResponseDto) {
            final FirmwareVersionGasResponseDto firmwareVersionGasResponseDto = (FirmwareVersionGasResponseDto) action;
            final FirmwareVersion firmwareVersion = this.configurationMapper.map(firmwareVersionGasResponseDto.getFirmwareVersion(), FirmwareVersion.class);
            this.firmwareService.saveFirmwareVersionsReturnedFromDevice(firmwareVersionGasResponseDto.getFirmwareVersion().getMbusDeviceIdentification(), Arrays.asList(firmwareVersion));
        }
    }
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) SetDeviceLifecycleStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto) DecoupleMbusDeviceResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto) FirmwareVersionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionResponseDto) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) CoupleMbusDeviceByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto) FirmwareVersionGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionGasResponseDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 10 with FirmwareVersion

use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method handleGetFirmwareVersionResponse.

public void handleGetFirmwareVersionResponse(final List<FirmwareVersionDto> firmwareVersionsDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device firmware version", e);
    }
    final List<FirmwareVersion> firmwareVersions = this.domainCoreMapper.mapAsList(firmwareVersionsDto, FirmwareVersion.class);
    this.checkFirmwareHistory(ids.getDeviceIdentification(), firmwareVersions);
    final boolean hasPendingFirmwareUpdate = this.checkSsldPendingFirmwareUpdate(ids, firmwareVersions);
    if (!hasPendingFirmwareUpdate) {
        final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject((Serializable) firmwareVersions).withMessagePriority(messagePriority).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
        this.webServiceResponseMessageSender.send(responseMessage);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) Serializable(java.io.Serializable) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Aggregations

FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)23 Test (org.junit.jupiter.api.Test)13 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)9 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)9 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)8 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)8 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)8 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)8 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)5 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)5 Date (java.util.Date)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)4 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Collection (java.util.Collection)2