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