Search in sources :

Example 11 with FirmwareVersion

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

the class FirmwareManagementService method checkFirmwareHistoryForModuleVersionsNotCurrentlyInstalled.

/**
 * @param deviceId the id of the device we are checking
 * @param firmwareVersions the list of firmware modules versions (so type and version) to check if
 *     they are currently installed on the device, using the history of the devices firmware
 *     history
 * @return a list of firmware module versions not present in the the devices firmware history
 */
private List<FirmwareVersion> checkFirmwareHistoryForModuleVersionsNotCurrentlyInstalled(final String deviceId, final List<FirmwareVersion> firmwareVersions) {
    if (firmwareVersions.isEmpty()) {
        return firmwareVersions;
    }
    // copy input parameter
    final List<FirmwareVersion> firmwareVersionsToCheck = new ArrayList<>(firmwareVersions);
    // gets list of all historically installed modules
    final Device device = this.deviceRepository.findByDeviceIdentification(deviceId);
    final List<DeviceFirmwareFile> deviceFirmwareFiles = this.deviceFirmwareFileRepository.findByDeviceOrderByInstallationDateAsc(device);
    // Transform this list so it contains only the latest entry for each
    // moduleType
    final Map<String, FirmwareVersionWithInstallationDate> currentlyInstalledFirmwareVersionsPerType = new HashMap<>();
    for (final DeviceFirmwareFile firmwareFile : deviceFirmwareFiles) {
        final Map<FirmwareModule, String> fwms = firmwareFile.getFirmwareFile().getModuleVersions();
        final Date installationDate = firmwareFile.getInstallationDate();
        for (final Map.Entry<FirmwareModule, String> entry : fwms.entrySet()) {
            final String version = entry.getValue();
            final FirmwareModule fwm = entry.getKey();
            // of a later date
            if (currentlyInstalledFirmwareVersionsPerType.containsKey(fwm.getDescription()) && currentlyInstalledFirmwareVersionsPerType.get(fwm.getDescription()).getInstallationDate().before(installationDate)) {
                currentlyInstalledFirmwareVersionsPerType.replace(fwm.getDescription(), new FirmwareVersionWithInstallationDate(installationDate, new FirmwareVersion(FirmwareModuleType.forDescription(fwm.getDescription()), version)));
            } else {
                // no other module of this type found yet so just add it
                currentlyInstalledFirmwareVersionsPerType.put(fwm.getDescription(), new FirmwareVersionWithInstallationDate(installationDate, new FirmwareVersion(FirmwareModuleType.forDescription(fwm.getDescription()), version)));
            }
        }
    }
    final List<FirmwareVersion> latestfirmwareVersionsOfEachModuleTypeInHistory = currentlyInstalledFirmwareVersionsPerType.values().stream().map(e -> new FirmwareVersion(e.getFirmwareVersion().getFirmwareModuleType(), e.getFirmwareVersion().getVersion())).collect(Collectors.toList());
    // remove the latest history (module)versions from the firmwareVersions
    // parameter
    firmwareVersionsToCheck.removeAll(latestfirmwareVersionsOfEachModuleTypeInHistory);
    return firmwareVersionsToCheck;
}
Also used : Date(java.util.Date) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) LoggerFactory(org.slf4j.LoggerFactory) Identification(org.opensmartgridplatform.shared.validation.Identification) Autowired(org.springframework.beans.factory.annotation.Autowired) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) Locale(java.util.Locale) Map(java.util.Map) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Collection(java.util.Collection) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceFirmwareFileRepository(org.opensmartgridplatform.domain.core.repositories.DeviceFirmwareFileRepository) FirmwareFileRepository(org.opensmartgridplatform.domain.core.repositories.FirmwareFileRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Service(org.springframework.stereotype.Service) DeviceModelRepository(org.opensmartgridplatform.domain.core.repositories.DeviceModelRepository) ManufacturerRepository(org.opensmartgridplatform.domain.core.repositories.ManufacturerRepository) ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Logger(org.slf4j.Logger) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Device(org.opensmartgridplatform.domain.core.entities.Device) SsldPendingFirmwareUpdateRepository(org.opensmartgridplatform.domain.core.repositories.SsldPendingFirmwareUpdateRepository) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Comparator(java.util.Comparator) DeviceFunction(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunction) MessagePriorityEnum(org.opensmartgridplatform.shared.wsheaderattribute.priority.MessagePriorityEnum) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) HashMap(java.util.HashMap) Device(org.opensmartgridplatform.domain.core.entities.Device) ArrayList(java.util.ArrayList) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Date(java.util.Date) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with FirmwareVersion

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

the class FirmwareManagementService method checkFirmwareHistoryForVersion.

/**
 * @param deviceId the id of the device we are checking
 * @param firmwareVersions the list of firmware versions to check if they are in the history of
 *     the devices firmware history
 * @return a list of firmware versions not present in the the devices firmware history
 */
public List<FirmwareVersion> checkFirmwareHistoryForVersion(final String deviceId, final List<FirmwareVersion> firmwareVersions) {
    if (firmwareVersions.isEmpty()) {
        return firmwareVersions;
    }
    // copy input parameter
    final List<FirmwareVersion> firmwareVersionsToCheck = new ArrayList<>(firmwareVersions);
    // get history
    final Device device = this.deviceRepository.findByDeviceIdentification(deviceId);
    final List<DeviceFirmwareFile> deviceFirmwareFiles = this.deviceFirmwareFileRepository.findByDeviceOrderByInstallationDateAsc(device);
    final List<FirmwareVersion> firmwareVersionsInHistory = deviceFirmwareFiles.stream().map(d -> d.getFirmwareFile().getModuleVersions().entrySet()).flatMap(Collection::stream).map(e -> new FirmwareVersion(FirmwareModuleType.forDescription(e.getKey().getDescription()), e.getValue())).collect(Collectors.toList());
    // remove the history versions
    firmwareVersionsToCheck.removeAll(firmwareVersionsInHistory);
    return firmwareVersionsToCheck;
}
Also used : Date(java.util.Date) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) LoggerFactory(org.slf4j.LoggerFactory) Identification(org.opensmartgridplatform.shared.validation.Identification) Autowired(org.springframework.beans.factory.annotation.Autowired) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) Locale(java.util.Locale) Map(java.util.Map) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) Collection(java.util.Collection) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) FirmwareUpdateMessageDataContainer(org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceFirmwareFileRepository(org.opensmartgridplatform.domain.core.repositories.DeviceFirmwareFileRepository) FirmwareFileRepository(org.opensmartgridplatform.domain.core.repositories.FirmwareFileRepository) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Service(org.springframework.stereotype.Service) DeviceModelRepository(org.opensmartgridplatform.domain.core.repositories.DeviceModelRepository) ManufacturerRepository(org.opensmartgridplatform.domain.core.repositories.ManufacturerRepository) ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Logger(org.slf4j.Logger) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Device(org.opensmartgridplatform.domain.core.entities.Device) SsldPendingFirmwareUpdateRepository(org.opensmartgridplatform.domain.core.repositories.SsldPendingFirmwareUpdateRepository) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Comparator(java.util.Comparator) DeviceFunction(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunction) MessagePriorityEnum(org.opensmartgridplatform.shared.wsheaderattribute.priority.MessagePriorityEnum) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Device(org.opensmartgridplatform.domain.core.entities.Device) ArrayList(java.util.ArrayList) Collection(java.util.Collection) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 13 with FirmwareVersion

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

the class FirmwareService method saveFirmwareVersionsReturnedFromDevice.

private void saveFirmwareVersionsReturnedFromDevice(final Device device, final List<FirmwareVersion> firmwareVersions) {
    for (final FirmwareVersion firmwareVersion : firmwareVersions) {
        final FirmwareModule firmwareModule = this.firmwareModuleRepository.findByDescriptionIgnoreCase(firmwareVersion.getFirmwareModuleType().getDescription());
        if (firmwareModule == null) {
            log.error("Unable to store firmware version {} for device {}, no firmware module found for description \"{}\"", firmwareVersion, device.getDeviceIdentification(), firmwareVersion.getFirmwareModuleType().getDescription());
            continue;
        }
        /*
       * The DeviceFirmwareModule has a id, that prevents duplicates in the database
       * The id of DeviceFirmwareModule is made with a combination of deviceId and firmwareModuleId
       * There for we can just add a new object to the database here
       */
        final DeviceFirmwareModule deviceFirmwareModule = new DeviceFirmwareModule(device, firmwareModule, firmwareVersion.getVersion());
        this.deviceFirmwareModuleRepository.save(deviceFirmwareModule);
    }
}
Also used : DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 14 with FirmwareVersion

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

the class FirmwareVersionConverter method convertFrom.

@Override
public FirmwareVersion convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.FirmwareVersion source, final Type<FirmwareVersion> destinationType, final MappingContext mappingContext) {
    if (source == null) {
        return null;
    }
    final FirmwareModuleType type = FirmwareModuleType.forDescription(source.getFirmwareModuleType().name());
    final String version = source.getVersion();
    return new FirmwareVersion(type, version);
}
Also used : FirmwareModuleType(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 15 with FirmwareVersion

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

the class DomainCoreMapperTest method testMapFirmwareVersionDtoList.

@Test
void testMapFirmwareVersionDtoList() {
    // Arrange
    final List<FirmwareVersionDto> firmwareVersionsDto = new ArrayList<>();
    final String version = "1";
    firmwareVersionsDto.add(new FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareModuleType.ACTIVE_FIRMWARE, version));
    final List<FirmwareVersion> expected = Arrays.asList(new FirmwareVersion(FirmwareModuleType.ACTIVE_FIRMWARE, version));
    // Act
    final List<FirmwareVersion> firmwareVersions = this.mapper.mapAsList(firmwareVersionsDto, FirmwareVersion.class);
    // Assert
    assertThat(firmwareVersions).isEqualTo(expected);
}
Also used : ArrayList(java.util.ArrayList) FirmwareVersionDto(org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion) Test(org.junit.jupiter.api.Test)

Aggregations

FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)23 Test (org.junit.jupiter.api.Test)13 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)9 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)9 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)8 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)8 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)8 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)8 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)5 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)5 Date (java.util.Date)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SsldPendingFirmwareUpdate (org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate)4 FirmwareModuleType (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleType)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 Collection (java.util.Collection)2