use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class DlmsDeviceSteps method createDlmsDeviceInProtocolAdapterDatabase.
private void createDlmsDeviceInProtocolAdapterDatabase(final Map<String, String> inputSettings) {
final ProtocolInfo protocolInfo = this.getProtocolInfo(inputSettings);
final DlmsDeviceBuilder dlmsDeviceBuilder = new DlmsDeviceBuilder().setProtocolName(protocolInfo);
final DlmsDevice dlmsDevice = dlmsDeviceBuilder.withSettings(inputSettings).build();
this.dlmsDeviceRepository.save(dlmsDevice);
this.createDlmsDeviceInSecretManagementDatabase(dlmsDevice, inputSettings);
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo 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.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class EventServiceTest method testWrongEventCode.
@Test
void testWrongEventCode() {
final FunctionalException functionalException = Assertions.assertThrows(FunctionalException.class, () -> {
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(protocolInfo.getProtocol()).thenReturn("SMR");
when(this.smartMeter.getProtocolInfo()).thenReturn(protocolInfo);
final EventDto event = new EventDto(new DateTime(), 266, 2, "STANDARD_EVENT_LOG");
final ArrayList<EventDto> events = new ArrayList<>();
events.add(event);
final EventMessageDataResponseDto responseDto = new EventMessageDataResponseDto(events);
this.eventService.enrichEvents(this.deviceMessageMetadata, responseDto);
});
assertThat(functionalException.getExceptionType()).isEqualTo(FunctionalExceptionType.VALIDATION_ERROR);
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class SmartMeterServiceTest method testStoreMeter.
@Test
void testStoreMeter() throws FunctionalException {
final String organisationIdentification = "org-1";
final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
final DeviceModel deviceModel = new DeviceModel();
final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(smartMeteringDevice, deviceModel);
final SmartMeter smartMeter = new SmartMeter();
final Manufacturer manufacturer = new Manufacturer();
final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(any(), any())).thenReturn(protocolInfo);
when(this.manufacturerRepository.findByCode(any())).thenReturn(manufacturer);
when(this.deviceModelRepository.findByManufacturerAndModelCode(any(), any())).thenReturn(new org.opensmartgridplatform.domain.core.entities.DeviceModel());
when(this.smartMeterRepository.save(any())).thenReturn(smartMeter);
this.smartMeterService.storeMeter(organisationIdentification, addSmartMeterRequest, smartMeter);
verify(this.protocolInfoRepository).findByProtocolAndProtocolVersion(any(), any());
verify(this.manufacturerRepository).findByCode(any());
verify(this.deviceModelRepository).findByManufacturerAndModelCode(any(), any());
verify(this.deviceAuthorizationRepository).save(any());
verify(this.organisationRepository).findByOrganisationIdentification(organisationIdentification);
verify(this.smartMeterRepository).save(any());
}
use of org.opensmartgridplatform.domain.core.entities.ProtocolInfo in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method updateDeviceProtocol.
public void updateDeviceProtocol(final String organisationIdentification, @Identification final String deviceIdentification, final String protocol, final String protocolVersion) throws FunctionalException {
LOGGER.debug("Updating protocol for device [{}] on behalf of organisation [{}] to protocol: {}, version: {}", deviceIdentification, organisationIdentification, protocol, protocolVersion);
final Organisation organisation = this.findOrganisation(organisationIdentification);
this.isAllowed(organisation, PlatformFunction.UPDATE_DEVICE_PROTOCOL);
final Device device = this.findDevice(deviceIdentification);
final ProtocolInfo protocolInfo = this.findProtocolInfo(protocol, protocolVersion);
if (protocolInfo.equals(device.getProtocolInfo())) {
LOGGER.info("Not updating protocol: {}, version: {} on device {} since it is already configured", protocol, protocolVersion, deviceIdentification);
return;
}
device.updateProtocol(protocolInfo);
this.deviceRepository.save(device);
LOGGER.info("Organisation {} configured protocol: {}, version: {} on device {}", organisationIdentification, protocol, protocolVersion, deviceIdentification);
}
Aggregations