Search in sources :

Example 6 with Device

use of org.opensmartgridplatform.domain.core.entities.Device 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 7 with Device

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

the class DeviceAuthorizationSteps method aDeviceAuthorization.

/**
 * Generic method which adds a device authorization using the settings.
 *
 * @param settings The settings for the device authorization to be used.
 */
@Given("^a device authorization$")
@Transactional("txMgrCore")
public void aDeviceAuthorization(final Map<String, String> settings) {
    final Device device = this.deviceRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final Organisation organization = this.organizationRepository.findByOrganisationIdentification(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
    final DeviceFunctionGroup functionGroup = getEnum(settings, PlatformKeys.KEY_DEVICE_FUNCTION_GROUP, DeviceFunctionGroup.class, DeviceFunctionGroup.OWNER);
    final DeviceAuthorization authorization = device.addAuthorization(organization, functionGroup);
    this.deviceAuthorizationRepository.save(authorization);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Device

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

the class DeviceAuthorizationSteps method thenTheEntityDeviceAuthorizationsExist.

/**
 * The test passes if all the device authorizations are created as expected in the database.
 *
 * @param expectedEntity The expected settings.
 */
@Then("^the entity device authorizations exist$")
public void thenTheEntityDeviceAuthorizationsExist(final Map<String, String> expectedEntity) {
    final String authorizationsStringList = expectedEntity.get(PlatformKeys.KEY_DEVICE_FUNCTION_GROUP);
    final String[] authorizations = StringUtils.split(authorizationsStringList, ',');
    final Device device = this.deviceRepository.findByDeviceIdentification(expectedEntity.get(PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    Wait.until(() -> {
        final List<String> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device).stream().map(da -> da.getFunctionGroup().name()).collect(Collectors.toList());
        assertThat(storedDeviceAuthorizations).contains(authorizations);
    });
    final List<DeviceAuthorization> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device);
    final String organizationIdentification = getString(expectedEntity, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    for (final String authorization : authorizations) {
        assertThat(this.entityDeviceHasAuthorization(authorization, organizationIdentification, storedDeviceAuthorizations)).isTrue();
    }
}
Also used : DeviceAuthorizationRepository(org.opensmartgridplatform.domain.core.repositories.DeviceAuthorizationRepository) Then(io.cucumber.java.en.Then) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) ReadSettingsHelper.getEnum(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getEnum) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) List(java.util.List) Device(org.opensmartgridplatform.domain.core.entities.Device) OrganisationRepository(org.opensmartgridplatform.domain.core.repositories.OrganisationRepository) Given(io.cucumber.java.en.Given) PlatformKeys(org.opensmartgridplatform.cucumber.platform.PlatformKeys) Map(java.util.Map) Wait(org.opensmartgridplatform.cucumber.core.Wait) PlatformDefaults(org.opensmartgridplatform.cucumber.platform.PlatformDefaults) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Transactional(org.springframework.transaction.annotation.Transactional) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Example 9 with Device

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

the class DeviceAuthorizationSteps method thenTheEntityDeviceAuthorizationDoesNotExist.

/**
 * The test passes if the device authorizations are NOT created as expected in the database.
 *
 * @param expectedEntity The expected settings.
 */
@Then("^the entity device authorization does not exist$")
public void thenTheEntityDeviceAuthorizationDoesNotExist(final Map<String, String> expectedEntity) {
    final String expectedAuthorization = expectedEntity.get(PlatformKeys.KEY_DEVICE_FUNCTION_GROUP);
    final Device device = this.deviceRepository.findByDeviceIdentification(expectedEntity.get(PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    Wait.until(() -> {
        final List<DeviceAuthorization> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device);
        final String organizationIdentification = getString(expectedEntity, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
        assertThat(this.entityDeviceHasAuthorization(expectedAuthorization, organizationIdentification, storedDeviceAuthorizations)).isFalse();
    });
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Example 10 with Device

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

the class DeviceFirmwareModuleSteps method aDeviceWithDeviceFirmwareVersion.

@Given("^a device firmware version$")
public void aDeviceWithDeviceFirmwareVersion(final Map<String, String> settings) throws Throwable {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION);
    final Device device = this.deviceRepository.findByDeviceIdentificationWithFirmwareModules(deviceIdentification);
    final Map<FirmwareModule, String> configuredVersionsPerType = this.getFirmwareModuleVersions(settings);
    for (final Map.Entry<FirmwareModule, String> configuredVersionsPerTypeEntry : configuredVersionsPerType.entrySet()) {
        final DeviceFirmwareModule deviceFirmwareModule = new DeviceFirmwareModule(device, configuredVersionsPerTypeEntry.getKey(), configuredVersionsPerTypeEntry.getValue());
        this.deviceFirmwareModuleRepository.save(deviceFirmwareModule);
    }
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) ReadSettingsHelper.getNullOrNonEmptyString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getNullOrNonEmptyString) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) FirmwareModule(org.opensmartgridplatform.domain.core.entities.FirmwareModule) DeviceFirmwareModule(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareModule) Map(java.util.Map) Given(io.cucumber.java.en.Given)

Aggregations

Device (org.opensmartgridplatform.domain.core.entities.Device)179 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)49 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)36 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)35 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)32 Test (org.junit.jupiter.api.Test)27 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)27 Transactional (org.springframework.transaction.annotation.Transactional)24 Then (io.cucumber.java.en.Then)21 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)18 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)17 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)12 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)11 Date (java.util.Date)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9