use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType in project open-smart-grid-platform by OSGP.
the class FirmwareFileSteps method aPendingFirmwareUpdateRecordForAnSsld.
@Given("^a pending firmware update record for an ssld$")
@Transactional("txMgrCore")
public void aPendingFirmwareUpdateRecordForAnSsld(final Map<String, String> settings) {
final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
final FirmwareModuleType firmwareModuleType = getEnum(settings, PlatformKeys.FIRMWARE_MODULE_VERSION_FUNC, FirmwareModuleType.class);
final String firmwareVersion = getString(settings, PlatformKeys.FIRMWARE_VERSION);
final String organisationIdentification = getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION);
SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = new SsldPendingFirmwareUpdate(deviceIdentification, firmwareModuleType, firmwareVersion, organisationIdentification, "correlationUid");
ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository.save(ssldPendingFirmwareUpdate);
}
use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method checkSsldPendingFirmwareUpdate.
boolean checkSsldPendingFirmwareUpdate(final CorrelationIds ids, final List<FirmwareVersion> firmwareVersions) {
final String deviceIdentification = ids.getDeviceIdentification();
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification).stream().filter(pendingUpdate -> pendingUpdate.getCorrelationUid().equals(ids.getCorrelationUid())).findAny().orElse(null);
if (ssldPendingFirmwareUpdate == null) {
return false;
}
LOGGER.info("Found SSLD pending firmware update record for device identification: {}, {}.", deviceIdentification, ssldPendingFirmwareUpdate);
final FirmwareModuleType expectedFirmwareModuleType = ssldPendingFirmwareUpdate.getFirmwareModuleType();
final String expectedFirmwareVersion = ssldPendingFirmwareUpdate.getFirmwareVersion();
final boolean foundExpectedFirmwareVersion = firmwareVersions.stream().anyMatch(fv -> expectedFirmwareModuleType.equals(fv.getFirmwareModuleType()) && expectedFirmwareVersion.equals(fv.getVersion()));
if (foundExpectedFirmwareVersion) {
LOGGER.info("Expected firmware version from SSLD pending firmware update record matches firmware version as retrieved from device identification: {}, firmware version: {}, firmware module type: {}.", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType);
} else {
LOGGER.error("Expected firmware version from SSLD pending firmware update record does )not match firmware version as retrieved from device identification: {}, expected firmware version: {}, expected firmware module type: {}, actual firmware version and module type list: {}", deviceIdentification, expectedFirmwareVersion, expectedFirmwareModuleType, firmwareVersions);
}
this.ssldPendingFirmwareUpdateRepository.delete(ssldPendingFirmwareUpdate);
return true;
}
use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType 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);
}
}
use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method anSsldPendingFirmwareUpdate.
private SsldPendingFirmwareUpdate anSsldPendingFirmwareUpdate(final Long id, final Date creationTime, final String deviceIdentification, final String correlationUid) {
final FirmwareModuleType firmwareModuleType = FirmwareModuleType.FUNCTIONAL;
final String firmwareVersion = "test-version";
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = new SsldPendingFirmwareUpdate(deviceIdentification, firmwareModuleType, firmwareVersion, ORGANISATION_IDENTIFICATION, correlationUid);
ReflectionTestUtils.setField(ssldPendingFirmwareUpdate, "id", id, Long.class);
ReflectionTestUtils.setField(ssldPendingFirmwareUpdate, "creationTime", creationTime, Date.class);
return ssldPendingFirmwareUpdate;
}
use of org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType 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);
}
Aggregations