Search in sources :

Example 1 with DeviceModel

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

the class DlmsDeviceSteps method theDlmsDeviceWithIdentificationExistsWithDeviceModel.

@Then("^the dlms device with identification \"([^\"]*)\" exists with device model$")
public void theDlmsDeviceWithIdentificationExistsWithDeviceModel(final String deviceIdentification, final Map<String, String> deviceModelAttributes) throws Throwable {
    this.theDlmsDeviceWithIdentificationExists(deviceIdentification);
    final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
    final DeviceModel deviceModel = device.getDeviceModel();
    assertThat(deviceModel.getModelCode()).as(PlatformKeys.DEVICEMODEL_MODELCODE).isEqualTo(deviceModelAttributes.get(PlatformKeys.DEVICEMODEL_MODELCODE));
    final Manufacturer manufacturer = deviceModel.getManufacturer();
    assertThat(manufacturer.getCode()).as(PlatformKeys.MANUFACTURER_CODE).isEqualTo(deviceModelAttributes.get(PlatformKeys.MANUFACTURER_CODE));
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Device(org.opensmartgridplatform.domain.core.entities.Device) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Then(io.cucumber.java.en.Then)

Example 2 with DeviceModel

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

the class DlmsDeviceSteps method createDeviceInCoreDatabase.

private Device createDeviceInCoreDatabase(final Map<String, String> inputSettings) {
    Device device;
    final ProtocolInfo protocolInfo = this.getProtocolInfo(inputSettings);
    final DeviceModel deviceModel = this.getDeviceModel(inputSettings);
    final boolean isSmartMeter = this.isSmartMeter(inputSettings);
    if (isSmartMeter) {
        final SmartMeter smartMeter = new SmartMeterBuilder().withSettings(inputSettings).setProtocolInfo(protocolInfo).setDeviceModel(deviceModel).build();
        device = this.smartMeterRepository.save(smartMeter);
    } else {
        device = new DeviceBuilder(this.deviceRepository).withSettings(inputSettings).setProtocolInfo(protocolInfo).setDeviceModel(deviceModel).build();
        device = this.deviceRepository.save(device);
    }
    final Map<FirmwareModule, String> firmwareModuleVersions = this.deviceFirmwareModuleSteps.getFirmwareModuleVersions(inputSettings, isSmartMeter);
    if (!firmwareModuleVersions.isEmpty()) {
        device.setFirmwareVersions(firmwareModuleVersions);
        device = this.deviceRepository.save(device);
    }
    if (inputSettings.containsKey(PlatformSmartmeteringKeys.GATEWAY_DEVICE_IDENTIFICATION)) {
        final Device gatewayDevice = this.deviceRepository.findByDeviceIdentification(inputSettings.get(PlatformSmartmeteringKeys.GATEWAY_DEVICE_IDENTIFICATION));
        device.updateGatewayDevice(gatewayDevice);
        device = this.deviceRepository.save(device);
    }
    return device;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DeviceBuilder) DlmsDeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder) Device(org.opensmartgridplatform.domain.core.entities.Device) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) SmartMeterBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.SmartMeterBuilder)

Example 3 with DeviceModel

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

the class LightMeasurementDeviceSteps method aLightMeasurementDevice.

@Given("^a light measurement device$")
@Transactional("txMgrCore")
public LightMeasurementDevice aLightMeasurementDevice(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final LightMeasurementDevice lmd = new LightMeasurementDevice(deviceIdentification);
    final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.KEY_DEVICE_MODEL, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE));
    final DeviceModel deviceModel = deviceModels.get(0);
    lmd.setDeviceModel(deviceModel);
    if (settings.containsKey(PlatformKeys.KEY_DEVICE_TYPE)) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByName(getString(settings, PlatformKeys.IP_ADDRESS, this.configuration.getDeviceNetworkAddress()));
        } catch (final UnknownHostException e) {
            inetAddress = InetAddress.getLoopbackAddress();
        }
        lmd.updateRegistrationData(inetAddress, getString(settings, PlatformKeys.KEY_DEVICE_TYPE));
    }
    lmd.updateMetaData(getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_ALIAS), new Address(getString(settings, PlatformKeys.KEY_CITY, PlatformDefaults.DEFAULT_CONTAINER_CITY), getString(settings, PlatformKeys.KEY_POSTCODE, PlatformDefaults.DEFAULT_CONTAINER_POSTALCODE), getString(settings, PlatformKeys.KEY_STREET, PlatformDefaults.DEFAULT_CONTAINER_STREET), getInteger(settings, PlatformKeys.KEY_NUMBER, PlatformDefaults.DEFAULT_CONTAINER_NUMBER), getString(settings, PlatformKeys.KEY_NUMBER_ADDITION, PlatformDefaults.DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, PlatformKeys.KEY_MUNICIPALITY, PlatformDefaults.DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(settings.containsKey(PlatformKeys.KEY_LATITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LATITUDE)) ? getFloat(settings, PlatformKeys.KEY_LATITUDE, PlatformDefaults.DEFAULT_LATITUDE) : null, settings.containsKey(PlatformKeys.KEY_LONGITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LONGITUDE)) ? getFloat(settings, PlatformKeys.KEY_LONGITUDE, PlatformDefaults.DEFAULT_LONGITUDE) : null));
    lmd.setActivated(getBoolean(settings, PlatformKeys.KEY_ACTIVATED, PlatformDefaults.DEFAULT_ACTIVATED));
    lmd.setDescription(getString(settings, PlatformKeys.KEY_LMD_DESCRIPTION, PlatformDefaults.DEFAULT_LMD_DESCRIPTION));
    lmd.setCode(getString(settings, PlatformKeys.KEY_LMD_CODE, PlatformDefaults.DEFAULT_LMD_CODE));
    lmd.setColor(getString(settings, PlatformKeys.KEY_LMD_COLOR, PlatformDefaults.DEFAULT_LMD_COLOR));
    lmd.setDigitalInput(getShort(settings, PlatformKeys.KEY_LMD_DIGITAL_INPUT, PlatformDefaults.DEFAULT_LMD_DIGITAL_INPUT));
    this.setDefaultDeviceAuthorizationForDevice(lmd);
    return this.lightMeasurementDeviceRepository.findByDeviceIdentification(deviceIdentification);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) InetAddress(java.net.InetAddress) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DeviceModel

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

the class DeviceModelSteps method theEntityDeviceModelExists.

/**
 * Generic method to check if the device model is created as expected in the database.
 *
 * @param expectedEntity The expected settings.
 * @throws Throwable
 */
@Then("^the entity device model exists$")
public void theEntityDeviceModelExists(final Map<String, String> expectedEntity) throws Throwable {
    final String modelCode = getString(expectedEntity, PlatformKeys.KEY_DEVICE_MODEL_MODELCODE, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE);
    final String modelDescription = getString(expectedEntity, PlatformKeys.KEY_DEVICE_MODEL_DESCRIPTION, PlatformDefaults.DEFAULT_DEVICE_MODEL_DESCRIPTION);
    final Manufacturer manufacturer = this.manufacturerRepository.findByCode(getString(expectedEntity, PlatformKeys.MANUFACTURER_CODE, PlatformDefaults.DEFAULT_MANUFACTURER_CODE));
    final List<DeviceModel> entityList = this.deviceModelRepository.findByManufacturer(manufacturer);
    for (final DeviceModel deviceModel : entityList) {
        if (deviceModel.getModelCode().equals(modelCode)) {
            assertThat(deviceModel.getDescription()).isEqualTo(modelDescription);
            return;
        }
    }
    Assertions.fail();
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Example 5 with DeviceModel

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

the class DeviceModelSteps method theEntityDeviceModelDoesNotExists.

/**
 * Generic method to check if the device model is NOT created as expected in the database.
 *
 * @param entity The settings.
 * @throws Throwable
 */
@Then("^the entity device model does not exist$")
public void theEntityDeviceModelDoesNotExists(final Map<String, String> entity) throws Throwable {
    final String modelCode = getString(entity, PlatformKeys.KEY_DEVICE_MODEL_MODELCODE, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE);
    final Manufacturer manufacturer = this.manufacturerRepository.findByCode(getString(entity, PlatformKeys.MANUFACTURER_CODE, PlatformDefaults.DEFAULT_MANUFACTURER_CODE));
    final List<DeviceModel> entityList = this.deviceModelRepository.findByManufacturer(manufacturer);
    for (final DeviceModel deviceModel : entityList) {
        assertThat(deviceModel.getModelCode()).isNotEqualTo(modelCode);
    }
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Aggregations

DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)34 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)18 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)11 Transactional (org.springframework.transaction.annotation.Transactional)11 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)10 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)10 Device (org.opensmartgridplatform.domain.core.entities.Device)7 Then (io.cucumber.java.en.Then)5 ArrayList (java.util.ArrayList)5 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)5 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)5 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)5 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)4 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)4 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)4 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)4 ConstraintViolationException (javax.validation.ConstraintViolationException)3 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)3 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)3