Search in sources :

Example 1 with ProtocolInfo

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);
}
Also used : ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) DlmsDeviceBuilder(org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 2 with ProtocolInfo

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;
}
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 ProtocolInfo

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);
}
Also used : EventDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto) ArrayList(java.util.ArrayList) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ProtocolInfo

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());
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) AddSmartMeterRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) Test(org.junit.jupiter.api.Test)

Example 5 with ProtocolInfo

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo)

Aggregations

ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)15 Device (org.opensmartgridplatform.domain.core.entities.Device)4 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 Test (org.junit.jupiter.api.Test)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 DlmsDeviceBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DlmsDeviceBuilder)2 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)2 EventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventDto)2 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 JMSException (javax.jms.JMSException)1 ObjectMessage (javax.jms.ObjectMessage)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 DeviceBuilder (org.opensmartgridplatform.cucumber.platform.smartmetering.builders.entities.DeviceBuilder)1