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