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