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