Search in sources :

Example 1 with FirmwareModule

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

the class DlmsDeviceSteps method createDeviceInCoreDatabase.

private Device createDeviceInCoreDatabase(final Map<String, String> inputSettings) {
    Device device;
    final ProtocolInfo protocolInfo = this.getProtocolInfo(inputSettings);
    final DeviceModel deviceModel = this.getDeviceModel(inputSettings);
    final boolean isSmartMeter = this.isSmartMeter(inputSettings);
    if (isSmartMeter) {
        final SmartMeter smartMeter = new SmartMeterBuilder().withSettings(inputSettings).setProtocolInfo(protocolInfo).setDeviceModel(deviceModel).build();
        device = this.smartMeterRepository.save(smartMeter);
    } else {
        device = new DeviceBuilder(this.deviceRepository).withSettings(inputSettings).setProtocolInfo(protocolInfo).setDeviceModel(deviceModel).build();
        device = this.deviceRepository.save(device);
    }
    final Map<FirmwareModule, String> firmwareModuleVersions = this.deviceFirmwareModuleSteps.getFirmwareModuleVersions(inputSettings, isSmartMeter);
    if (!firmwareModuleVersions.isEmpty()) {
        device.setFirmwareVersions(firmwareModuleVersions);
        device = this.deviceRepository.save(device);
    }
    if (inputSettings.containsKey(PlatformSmartmeteringKeys.GATEWAY_DEVICE_IDENTIFICATION)) {
        final Device gatewayDevice = this.deviceRepository.findByDeviceIdentification(inputSettings.get(PlatformSmartmeteringKeys.GATEWAY_DEVICE_IDENTIFICATION));
        device.updateGatewayDevice(gatewayDevice);
        device = this.deviceRepository.save(device);
    }
    return device;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DeviceBuilder) DlmsDeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder) Device(org.opensmartgridplatform.domain.core.entities.Device) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) SmartMeterBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.SmartMeterBuilder)

Example 2 with FirmwareModule

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

the class DeviceFirmwareModuleSteps method aDeviceWithDeviceFirmwareVersion.

@Given("^a device firmware version$")
public void aDeviceWithDeviceFirmwareVersion(final Map<String, String> settings) throws Throwable {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final Device device = this.deviceRepository.findByDeviceIdentificationWithFirmwareModules(deviceIdentification);
    final Map<FirmwareModule, String> configuredVersionsPerType = this.getFirmwareModuleVersions(settings);
    for (final Map.Entry<FirmwareModule, String> configuredVersionsPerTypeEntry : configuredVersionsPerType.entrySet()) {
        final DeviceFirmwareModule deviceFirmwareModule = new DeviceFirmwareModule(device, configuredVersionsPerTypeEntry.getKey(), configuredVersionsPerTypeEntry.getValue());
        this.deviceFirmwareModuleRepository.save(deviceFirmwareModule);
    }
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) ReadSettingsHelper.getNullOrNonEmptyString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getNullOrNonEmptyString) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) Map(java.util.Map) Given(io.cucumber.java.en.Given)

Example 3 with FirmwareModule

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

the class FirmwareSteps method assertFirmwareFileHasModuleVersions.

protected void assertFirmwareFileHasModuleVersions(final String identification, final Map<String, String> expectedmoduleVersions) {
    final Firmware expectedFirmware = this.createAndGetFirmware(expectedmoduleVersions);
    final FirmwareFile databaseFirmwareFile = this.firmwareFileRepository.findByIdentification(identification);
    assertThat(databaseFirmwareFile).isNotNull().as("Firmware File {} should exist", identification);
    final Map<FirmwareModule, String> databaseModuleVersions = databaseFirmwareFile.getModuleVersions();
    assertThat(databaseModuleVersions).hasSameSizeAs(expectedmoduleVersions);
    final FirmwareModuleData expectedFirmwareModuleData = expectedFirmware.getFirmwareModuleData();
    for (final Entry<FirmwareModule, String> entry : databaseModuleVersions.entrySet()) {
        final String version = entry.getValue();
        switch(entry.getKey().getDescription()) {
            case COMMUNICATION_MODULE_ACTIVE_FIRMWARE:
                assertThat(expectedFirmwareModuleData.getModuleVersionComm()).isEqualTo(version);
                break;
            case FUNCTIONAL:
                assertThat(expectedFirmwareModuleData.getModuleVersionFunc()).isEqualTo(version);
                break;
            case M_BUS:
                assertThat(expectedFirmwareModuleData.getModuleVersionMbus()).isEqualTo(version);
                break;
            case M_BUS_DRIVER_ACTIVE_FIRMWARE:
                assertThat(expectedFirmwareModuleData.getModuleVersionMBusDriverActive()).isEqualTo(version);
                break;
            case MODULE_ACTIVE_FIRMWARE:
                assertThat(expectedFirmwareModuleData.getModuleVersionMa()).isEqualTo(version);
                break;
            case SECURITY:
                assertThat(expectedFirmwareModuleData.getModuleVersionSec()).isEqualTo(version);
                break;
            case SIMPLE_VERSION_INFO:
                assertThat(expectedFirmwareModuleData.getModuleVersionSimple()).isEqualTo(version);
                break;
            default:
        }
    }
}
Also used : FirmwareModuleData(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FirmwareModuleData) Firmware(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.Firmware) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile)

Example 4 with FirmwareModule

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

the class FirmwareManagementService method firmwareFileContainsAllOfTheseModules.

private static boolean firmwareFileContainsAllOfTheseModules(final FirmwareFile file, final List<FirmwareVersion> firmwareVersions) {
    int numberOfModulesFound = 0;
    final Map<FirmwareModule, String> moduleVersionsInFile = file.getModuleVersions();
    for (final FirmwareVersion firmwareVersion : firmwareVersions) {
        final FirmwareModule module = createFirmwareModule(firmwareVersion);
        if (moduleVersionsInFile.containsKey(module) && moduleVersionsInFile.get(module).equals(firmwareVersion.getVersion())) {
            // module found in this file
            numberOfModulesFound++;
            // check if all different modules are in this file
            if (numberOfModulesFound == firmwareVersions.size()) {
                return true;
            }
        }
    }
    return false;
}
Also used : FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 5 with FirmwareModule

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

the class FirmwareManagementService method createSsldPendingFirmwareUpdateRecord.

private void createSsldPendingFirmwareUpdateRecord(final CorrelationIds ids, final String firmwareUrl) {
    try {
        final String firmwareFilename = getFirmwareFilename(firmwareUrl);
        final List<FirmwareFile> firmwareFiles = this.firmwareFileRepository.findByFilename(firmwareFilename);
        Assert.isTrue(firmwareFiles.size() == 1, "Expected 1 firmware file for filename: " + firmwareFilename);
        final FirmwareFile firmwareFile = firmwareFiles.get(0);
        final Map<FirmwareModule, String> firmwareModuleVersions = firmwareFile.getModuleVersions();
        Assert.isTrue(firmwareModuleVersions.size() == 1, "Expected 1 firmware module for: " + firmwareModuleVersions);
        final Entry<FirmwareModule, String> firmwareModuleVersion = firmwareModuleVersions.entrySet().iterator().next();
        final FirmwareModuleType firmwareModuleType = FirmwareModuleType.valueOf(firmwareModuleVersion.getKey().getDescription().toUpperCase());
        final String firmwareVersion = firmwareModuleVersion.getValue();
        SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = new SsldPendingFirmwareUpdate(ids.getDeviceIdentification(), firmwareModuleType, firmwareVersion, ids.getOrganisationIdentification(), ids.getCorrelationUid());
        ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository.save(ssldPendingFirmwareUpdate);
        LOGGER.info("Saved pending fimware update record for SSLD: {}, {}", ids.getDeviceIdentification(), ssldPendingFirmwareUpdate);
    } catch (final Exception e) {
        LOGGER.error("Caught exception when creating pending firmware update record for SSLD: {}", ids.getDeviceIdentification(), e);
    }
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException)

Aggregations

FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)23 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)14 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 Test (org.junit.jupiter.api.Test)8 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)8 Device (org.opensmartgridplatform.domain.core.entities.Device)7 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)5 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)5 ReadSettingsHelper.getNullOrNonEmptyString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getNullOrNonEmptyString)4 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)4 DeviceFirmwareModule (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule)3 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)3 SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Given (io.cucumber.java.en.Given)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Firmware (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.Firmware)2