use of org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate 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.entities.SsldPendingFirmwareUpdate 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.entities.SsldPendingFirmwareUpdate 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.entities.SsldPendingFirmwareUpdate 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.entities.SsldPendingFirmwareUpdate in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testUpdateFirmwareForSsld.
@Test
void testUpdateFirmwareForSsld() throws FunctionalException {
final Device device = this.getMockDevice(Ssld.class);
final FirmwareFile firmwareFile = new FirmwareFile.Builder().withFilename("firmware-test").build();
firmwareFile.addFirmwareModule(new FirmwareModule("functional"), VERSION_1);
when(this.firmwareUpdateMessageDataContainer.getFirmwareUrl()).thenReturn("/firmware-test");
when(this.deviceDomainService.searchActiveDevice(CORRELATION_IDS.getDeviceIdentification(), ComponentType.DOMAIN_CORE)).thenReturn(device);
when(this.firmwareFileRepository.findByFilename("firmware-test")).thenReturn(Collections.singletonList(firmwareFile));
this.firmwareManagementService.updateFirmware(CORRELATION_IDS, this.firmwareUpdateMessageDataContainer, 0L, "", 0);
verify(this.ssldPendingFirmwareUpdateRepository).save(this.ssldPendingFirmwareUpdateArgumentCaptor.capture());
final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate = this.ssldPendingFirmwareUpdateArgumentCaptor.getValue();
final SsldPendingFirmwareUpdate expectedSsldPendingFirmwareUpdate = new SsldPendingFirmwareUpdate(DEVICE_IDENTIFICATION, FirmwareModuleType.FUNCTIONAL, VERSION_1, ORGANISATION_IDENTIFICATION, CORRELATION_UID);
assertThat(ssldPendingFirmwareUpdate).isEqualTo(expectedSsldPendingFirmwareUpdate);
}
Aggregations