Search in sources :

Example 1 with SsldPendingFirmwareUpdate

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);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with 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;
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)

Example 3 with SsldPendingFirmwareUpdate

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

Example 4 with SsldPendingFirmwareUpdate

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;
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 5 with 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);
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Device(org.opensmartgridplatform.domain.core.entities.Device) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Test(org.junit.jupiter.api.Test)

Aggregations

SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)11 Test (org.junit.jupiter.api.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Date (java.util.Date)3 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)2 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)2 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)2 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)2 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)2 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)2 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)2 ComponentType (org.opensmartgridplatform.shared.exceptionhandling.ComponentType)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Given (io.cucumber.java.en.Given)1 ArrayList (java.util.ArrayList)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Device (org.opensmartgridplatform.domain.core.entities.Device)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1