use of org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile 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.DeviceFirmwareFile 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.DeviceFirmwareFile in project open-smart-grid-platform by OSGP.
the class DeviceFirmwareFileSteps method aDeviceFirmware.
/**
* Generic method which adds a device firmware using the settings.
*
* @param settings The settings for the device to be used.
*/
@Given("^a device firmware$")
public void aDeviceFirmware(final Map<String, String> settings) {
// Get the device
final Device device = this.deviceRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
// Get the firmware file
final FirmwareFile firmwareFile = this.getFirmwareFile(getString(settings, PlatformKeys.FIRMWARE_FILE_FILENAME));
final Date installationDate = getDateTime2(getString(settings, PlatformKeys.FIRMWARE_INSTALLATION_DATE), DateTime.now()).toDate();
final String installedBy = getString(settings, PlatformKeys.FIRMWARE_INSTALLED_BY, PlatformDefaults.FIRMWARE_INSTALLED_BY);
final DeviceFirmwareFile deviceFirmwareFile = new DeviceFirmwareFile(device, firmwareFile, installationDate, installedBy);
this.deviceFirmwareFileRepository.save(deviceFirmwareFile);
}
use of org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile in project open-smart-grid-platform by OSGP.
the class FirmwareManagementEndpoint method getDeviceFirmwareHistory.
// === FIRMWARE HISTORY LOGIC ===
@PayloadRoot(localPart = "GetDeviceFirmwareHistoryRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDeviceFirmwareHistoryResponse getDeviceFirmwareHistory(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDeviceFirmwareHistoryRequest request) throws OsgpException {
LOGGER.info("Get the firmware history for organisation {} from the device {} .", organisationIdentification, request.getDeviceIdentification());
final GetDeviceFirmwareHistoryResponse response = new GetDeviceFirmwareHistoryResponse();
try {
final Device device = this.deviceRepository.findByDeviceIdentification(request.getDeviceIdentification());
final DeviceFirmwareHistory output = new DeviceFirmwareHistory();
output.setDeviceIdentification(request.getDeviceIdentification());
output.setDeviceModel(this.firmwareManagementMapper.map(device.getDeviceModel(), org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceModel.class));
final List<org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceFirmware> deviceFirmwares = new ArrayList<>();
// mapper, just to null the Firmware's file
for (final DeviceFirmwareFile deviceFirmwareFile : this.firmwareManagementService.getDeviceFirmwareFiles(organisationIdentification, request.getDeviceIdentification())) {
final org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceFirmware temp = this.firmwareManagementMapper.map(deviceFirmwareFile, org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceFirmware.class);
temp.getFirmware().setFile(null);
deviceFirmwares.add(temp);
}
output.getDeviceFirmwares().addAll(this.firmwareManagementMapper.mapAsList(deviceFirmwares, org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceFirmware.class));
response.setDeviceFirmwareHistory(output);
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception get firmware history", e);
this.handleException(e);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile in project open-smart-grid-platform by OSGP.
the class DeviceFirmwareConverter method convertTo.
@Override
public DeviceFirmwareFile convertTo(final DeviceFirmware source, final Type<DeviceFirmwareFile> destinationType, final MappingContext mappingContext) {
final Device device = this.deviceRepository.findByDeviceIdentification(source.getDeviceIdentification());
final FirmwareFile firmwareFile = this.firmwareFileRepository.findById(Long.valueOf(source.getFirmware().getId())).orElse(null);
return new DeviceFirmwareFile(device, firmwareFile, source.getInstallationDate().toGregorianCalendar().getTime(), source.getInstalledBy());
}
Aggregations