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