Search in sources :

Example 96 with Device

use of org.opensmartgridplatform.domain.core.entities.Device 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 97 with Device

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

the class FirmwareManagementService method tryToAddDeviceFirmwareFile.

public void tryToAddDeviceFirmwareFile(final String deviceIdentification, final List<FirmwareVersion> firmwareVersionsNotCurrent) {
    if (firmwareVersionsNotCurrent.isEmpty()) {
        LOGGER.info("No firmware to look for, concerning device {}, so nothing to add.", deviceIdentification);
        return;
    }
    final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
    for (final FirmwareFile file : this.getAvailableFirmwareFilesForDeviceModel(device.getDeviceModel())) {
        if (firmwareFileContainsAllOfTheseModules(file, firmwareVersionsNotCurrent)) {
            // file found, insert a record into the history
            final DeviceFirmwareFile deviceFirmwareFile = new DeviceFirmwareFile(device, file, new Date(), INSTALLER);
            this.deviceFirmwareFileRepository.save(deviceFirmwareFile);
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Added new record to deviceFirmwareFile for device: {} with following modules (ModulesType/Versions):{} " + ", using file: {}", deviceIdentification, firmwareVersionsNotCurrent.toString(), file.getFilename());
            }
            return;
        }
    }
    LOGGER.warn("Could not find any firmware file for device: {} that contains (all of) the following modules (ModulesType/Versions):{}", deviceIdentification, firmwareVersionsNotCurrent);
}
Also used : DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Date(java.util.Date)

Example 98 with Device

use of org.opensmartgridplatform.domain.core.entities.Device 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 99 with Device

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

the class FirmwareManagementService method switchFirmware.

// === SWITCH TO OTHER FIRMWARE VERSION ===
public void switchFirmware(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String messageType, final int messagePriority, final String version) throws FunctionalException {
    LOGGER.debug("switchFirmware called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    this.findOrganisation(organisationIdentification);
    final Device device = this.findActiveDevice(deviceIdentification);
    this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, version), messageType, messagePriority, device.getIpAddress());
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage)

Example 100 with Device

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

the class TransactionalDeviceService method updateDeviceCdmaSettings.

public void updateDeviceCdmaSettings(final String deviceIdentification, final CdmaSettings cdmaSettings) throws FunctionalException {
    final Device device = this.deviceDomainService.searchDevice(deviceIdentification);
    device.updateCdmaSettings(cdmaSettings);
    this.deviceDomainService.saveDevice(device);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device)

Aggregations

Device (org.opensmartgridplatform.domain.core.entities.Device)179 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)49 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)36 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)35 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)32 Test (org.junit.jupiter.api.Test)27 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)27 Transactional (org.springframework.transaction.annotation.Transactional)24 Then (io.cucumber.java.en.Then)21 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)18 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)17 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)12 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)11 Date (java.util.Date)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9