Search in sources :

Example 6 with DeviceFirmwareFile

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);
}
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 7 with DeviceFirmwareFile

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;
}
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 8 with DeviceFirmwareFile

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);
}
Also used : DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Device(org.opensmartgridplatform.domain.core.entities.Device) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Date(java.util.Date) Given(io.cucumber.java.en.Given)

Example 9 with 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;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Device(org.opensmartgridplatform.domain.core.entities.Device) ArrayList(java.util.ArrayList) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) GetDeviceFirmwareHistoryResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.GetDeviceFirmwareHistoryResponse) DeviceFirmwareHistory(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceFirmwareHistory) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 10 with DeviceFirmwareFile

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

Aggregations

DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)10 Device (org.opensmartgridplatform.domain.core.entities.Device)8 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)8 Date (java.util.Date)6 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)5 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)4 ArrayList (java.util.ArrayList)3 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)3 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 Serializable (java.io.Serializable)2 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2