Search in sources :

Example 21 with Manufacturer

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

the class FirmwareManagementEndpoint method addManufacturer.

@PayloadRoot(localPart = "AddManufacturerRequest", namespace = NAMESPACE)
@ResponsePayload
public AddManufacturerResponse addManufacturer(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddManufacturerRequest request) throws OsgpException {
    LOGGER.info("Adding manufacturer:{}.", request.getManufacturer().getName());
    final AddManufacturerResponse addManufacturerResponse = new AddManufacturerResponse();
    try {
        this.firmwareManagementService.addManufacturer(organisationIdentification, new Manufacturer(request.getManufacturer().getCode(), request.getManufacturer().getName(), request.getManufacturer().isUsePrefix()));
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception adding manufacturer", e);
        this.handleException(e);
    } catch (final FunctionalException e) {
        LOGGER.error("Exception adding manufacturer: {} ", e.getMessage(), e);
        if (FunctionalExceptionType.EXISTING_MANUFACTURER == e.getExceptionType()) {
            addManufacturerResponse.setResult(OsgpResultType.NOT_OK);
            addManufacturerResponse.setDescription(ADD_MANUFACTURER_EXISTING_MANUFACTURER);
            return addManufacturerResponse;
        }
        this.handleException(e);
    } catch (final Exception e) {
        LOGGER.error("Exception: {} while adding manufacturer: {} for organisation {}", e.getMessage(), request.getManufacturer().getCode(), organisationIdentification, e);
        this.handleException(e);
    }
    addManufacturerResponse.setResult(OsgpResultType.OK);
    return addManufacturerResponse;
}
Also used : AddManufacturerResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddManufacturerResponse) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 22 with Manufacturer

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

the class DlmsDeviceSteps method getDeviceModel.

private DeviceModel getDeviceModel(final Map<String, String> inputSettings) {
    final String manufacturerCode = inputSettings.get(PlatformSmartmeteringKeys.MANUFACTURER_CODE);
    final String modelCode = inputSettings.get(PlatformSmartmeteringKeys.DEVICE_MODEL_CODE);
    if (manufacturerCode != null && modelCode != null) {
        final Manufacturer manufacturer = this.manufacturerRepository.findByCode(manufacturerCode);
        return this.deviceModelRepository.findByManufacturerAndModelCode(manufacturer, modelCode);
    }
    return null;
}
Also used : Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer)

Example 23 with Manufacturer

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

the class RtuDeviceService method addDeviceModel.

private void addDeviceModel(final org.opensmartgridplatform.domain.core.valueobjects.DeviceModel deviceModel, final org.opensmartgridplatform.domain.core.entities.RtuDevice rtuDeviceEntity) throws FunctionalException {
    final Manufacturer manufacturer = this.manufacturerRepository.findByCode(deviceModel.getManufacturer());
    final DeviceModel deviceModelEntity = this.deviceModelRepository.findByManufacturerAndModelCode(manufacturer, deviceModel.getModelCode());
    if (deviceModelEntity == null) {
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.DOMAIN_DISTRIBUTION_AUTOMATION);
    }
    rtuDeviceEntity.setDeviceModel(deviceModelEntity);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 24 with Manufacturer

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

the class FirmwareManagementService method changeFirmware.

/**
 * Updates a FirmwareFile to the platform. Throws exception if {@link FirmwareFile} doesn't exist.
 */
@Transactional(value = "writableTransactionManager")
public void changeFirmware(@Identification final String organisationIdentification, final int id, final FirmwareFileRequest firmwareFileRequest, final String manufacturer, final String modelCode, final FirmwareModuleData firmwareModuleData) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_FIRMWARE);
    FirmwareFile changedFirmwareFile = this.firmwareFileRepository.findById((long) id).orElseThrow(supplyFirmwareFileNotFoundException(id, firmwareFileRequest.getFileName()));
    final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer);
    if (databaseManufacturer == null) {
        LOGGER.info("Manufacturer {} doesn't exist.", manufacturer);
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_MANUFACTURER, ComponentType.WS_CORE, new UnknownEntityException(Manufacturer.class, manufacturer));
    }
    final DeviceModel databaseDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, modelCode);
    if (databaseDeviceModel == null) {
        LOGGER.info("DeviceModel unknown for manufacturer {} and model code {}.", manufacturer, modelCode);
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new UnknownEntityException(DeviceModel.class, modelCode));
    }
    changedFirmwareFile.setDescription(firmwareFileRequest.getDescription());
    /*
     * A firmware file has been changed to be related to (possibly) multiple
     * device models to be usable across different value streams for all
     * kinds of devices.
     *
     * This code mimics the earlier behavior with a single device model
     * linked to the firmware file, where the device model is changed.
     *
     * If multiple device models are related, it is not clear what to do,
     * and which if the device models (if any) should be removed. In such
     * case the device model will be added for now.
     *
     * 2021-06-02: In case of multiple DeviceModels all existing must be deleted
     * and all new DeviceModels in the request must be added
     */
    final Set<DeviceModel> existingDeviceModels = changedFirmwareFile.getDeviceModels();
    if (existingDeviceModels.size() > 1) {
        LOGGER.warn("Change Firmware (FirmwareFile id={}) with {} existing DeviceModels, adding {}", changedFirmwareFile.getId(), existingDeviceModels.size(), databaseDeviceModel);
    } else {
        LOGGER.warn("Change Firmware (FirmwareFile id={}) with {} existing DeviceModel(s), replacing by {}", changedFirmwareFile.getId(), existingDeviceModels.size(), databaseDeviceModel);
    }
    existingDeviceModels.clear();
    changedFirmwareFile.addDeviceModel(databaseDeviceModel);
    changedFirmwareFile.setFilename(firmwareFileRequest.getFileName());
    changedFirmwareFile.updateFirmwareModuleData(firmwareModuleData.getVersionsByModule(this.firmwareModuleRepository, false));
    changedFirmwareFile.setPushToNewDevices(firmwareFileRequest.isPushToNewDevices());
    changedFirmwareFile.setActive(firmwareFileRequest.isActive());
    // Save the changed firmware entity
    changedFirmwareFile = this.firmwareFileRepository.save(changedFirmwareFile);
    // Set all devicefirmwares.pushToNewDevices on false
    if (firmwareFileRequest.isPushToNewDevices()) {
        final List<FirmwareFile> firmwareFiles = this.firmwareFileRepository.findByDeviceModel(databaseDeviceModel);
        firmwareFiles.remove(changedFirmwareFile);
        this.setPushToNewDevicesToFalse(firmwareFiles);
    }
    this.firmwareFileRepository.save(changedFirmwareFile);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Manufacturer

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

the class FirmwareManagementService method addOrChangeFirmware.

@Transactional(value = "writableTransactionManager")
public void addOrChangeFirmware(@Identification final String organisationIdentification, final FirmwareFileRequest firmwareFileRequest, final byte[] file, final List<org.opensmartgridplatform.domain.core.valueobjects.DeviceModel> deviceModels, final FirmwareModuleData firmwareModuleData) throws OsgpException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, PlatformFunction.CREATE_FIRMWARE);
    // find for each DeviceModel from the WebServcies the corresponding entities
    // There should be at least one DeviceModel. If none found a FunctionalException should be
    // raised
    // Each DeviceModel can have it's own Manufacturer (at least a theory)
    // if a Manufacturer entity related to the DeviceModel can not be found a FunctionalException
    // should be raised
    // if one of the DeviceModel entities can not be found a FunctionalException should be raised
    final List<DeviceModel> databaseDeviceModels = new ArrayList<>();
    for (final org.opensmartgridplatform.domain.core.valueobjects.DeviceModel deviceModel : deviceModels) {
        final Manufacturer databaseManufacturer = this.findManufacturerByCode(deviceModel.getManufacturer());
        final DeviceModel databaseDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, deviceModel.getModelCode());
        if (databaseDeviceModel == null) {
            LOGGER.info("DeviceModel doesn't exist.");
            throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new UnknownEntityException(DeviceModel.class, deviceModel.getModelCode()));
        }
        databaseDeviceModels.add(databaseDeviceModel);
    }
    if (!deviceModels.isEmpty() && databaseDeviceModels.isEmpty()) {
        LOGGER.info("No DeviceModels found.");
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE);
    }
    final Map<FirmwareModule, String> firmwareVersionsByModule = firmwareModuleData.getVersionsByModule(this.firmwareModuleRepository, true);
    final FirmwareFile firmwareFile = this.insertOrUdateDatabase(firmwareFileRequest, file);
    firmwareFile.updateFirmwareDeviceModels(databaseDeviceModels);
    firmwareFile.updateFirmwareModuleData(firmwareVersionsByModule);
    this.firmwareFileRepository.save(firmwareFile);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) ArrayList(java.util.ArrayList) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)30 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)18 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)10 Transactional (org.springframework.transaction.annotation.Transactional)10 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)7 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)6 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)6 Device (org.opensmartgridplatform.domain.core.entities.Device)5 Then (io.cucumber.java.en.Then)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)3 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)2 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)2 Given (io.cucumber.java.en.Given)1 Date (java.util.Date)1