Search in sources :

Example 1 with SmartMeteringDevice

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.

the class InstallationMapperTest method mapsSmartMeteringDeviceToSmartMeter.

@Test
public void mapsSmartMeteringDeviceToSmartMeter() {
    final SmartMeteringDevice source = new SmartMeteringDevice();
    source.setDeviceIdentification("device1");
    source.setDeviceType("typeA");
    source.setCommunicationMethod("skype");
    source.setCommunicationProvider("theInternet");
    source.setIccId("value");
    source.setProtocolName("protocolName");
    source.setProtocolVersion("latestVersion");
    source.setMasterKey("masterKey".getBytes());
    source.setGlobalEncryptionUnicastKey("globalEncryptionUnicastKey".getBytes());
    source.setAuthenticationKey("authenticationKey".getBytes());
    source.setSupplier("supplier");
    source.setHls3Active(true);
    source.setHls4Active(true);
    source.setHls3Active(true);
    source.setDeliveryDate(new Date());
    source.setMbusIdentificationNumber("12345678");
    source.setMbusManufacturerIdentification("XYZ");
    source.setMbusVersion((short) 66);
    source.setMbusDeviceTypeIdentification((short) 3);
    source.setMbusDefaultKey("mbusDefaultKey".getBytes());
    final SmartMeter result = this.mapperFactory.getMapperFacade().map(source, SmartMeter.class);
    final SmartMeter expected = this.toSmartMeter(source);
    assertThat(result).isEqualToIgnoringGivenFields(expected, "id", "creationTime", "modificationTime", "version");
}
Also used : SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with SmartMeteringDevice

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.

the class SmartMeteringInstallationEndpoint method addDevice.

@PayloadRoot(localPart = "AddDeviceRequest", namespace = SMARTMETER_INSTALLATION_NAMESPACE)
@ResponsePayload
public AddDeviceAsyncResponse addDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddDeviceRequest request, @MessagePriority final String messagePriority, @ScheduleTime final String scheduleTime, @ResponseUrl final String responseUrl, @BypassRetry final String bypassRetry) throws OsgpException {
    log.info("Incoming AddDeviceRequest for meter: {}.", request.getDevice().getDeviceIdentification());
    AsyncResponse asyncResponse = null;
    try {
        final SmartMeteringDevice device = this.installationMapper.map(request.getDevice(), SmartMeteringDevice.class);
        final DeviceModel deviceModel = new DeviceModel(request.getDeviceModel().getManufacturer(), request.getDeviceModel().getModelCode(), "");
        final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(device, deviceModel);
        final RequestMessageMetadata requestMessageMetadata = RequestMessageMetadata.newBuilder().withOrganisationIdentification(organisationIdentification).withDeviceIdentification(device.getDeviceIdentification()).withDeviceFunction(null).withMessageType(MessageType.ADD_METER).withMessagePriority(messagePriority).withScheduleTime(scheduleTime).withBypassRetry(bypassRetry).build();
        asyncResponse = this.requestService.enqueueAndSendRequest(requestMessageMetadata, addSmartMeterRequest);
        this.saveResponseUrlIfNeeded(asyncResponse.getCorrelationUid(), responseUrl);
    } catch (final ConstraintViolationException e) {
        log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.WS_CORE, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        log.error("Exception: {} while adding device: {} for organisation {}.", e.getMessage(), request.getDevice().getDeviceIdentification(), organisationIdentification, e);
        this.handleException(e);
    }
    return this.installationMapper.map(asyncResponse, AddDeviceAsyncResponse.class);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) AddSmartMeterRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) CoupleMbusDeviceByChannelAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceByChannelAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AsyncResponse) AddDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.AddDeviceAsyncResponse) DecoupleMbusDeviceByChannelAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceByChannelAsyncResponse) DecoupleMbusDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceAsyncResponse) CoupleMbusDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 3 with SmartMeteringDevice

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice 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 4 with SmartMeteringDevice

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.

the class InstallationMapperTest method testSmartMeteringDeviceToSmartMeteringDeviceDtoMapping.

@Test
public void testSmartMeteringDeviceToSmartMeteringDeviceDtoMapping() {
    final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
    smartMeteringDevice.setDeviceIdentification("device1");
    smartMeteringDevice.setDeviceType("typeA");
    smartMeteringDevice.setCommunicationMethod("skype");
    smartMeteringDevice.setCommunicationProvider("theInternet");
    smartMeteringDevice.setIccId("value");
    smartMeteringDevice.setProtocolName("protocolName");
    smartMeteringDevice.setProtocolVersion("latestVersion");
    smartMeteringDevice.setMasterKey("masterKey".getBytes());
    smartMeteringDevice.setGlobalEncryptionUnicastKey("globalEncryptionUnicastKey".getBytes());
    smartMeteringDevice.setAuthenticationKey("authenticationKey".getBytes());
    smartMeteringDevice.setSupplier("supplier");
    smartMeteringDevice.setHls3Active(true);
    smartMeteringDevice.setHls4Active(true);
    smartMeteringDevice.setHls5Active(true);
    smartMeteringDevice.setDeliveryDate(new Date());
    smartMeteringDevice.setMbusIdentificationNumber("12345678");
    smartMeteringDevice.setMbusManufacturerIdentification("XYZ");
    smartMeteringDevice.setMbusVersion((short) 112);
    smartMeteringDevice.setMbusDeviceTypeIdentification((short) 3);
    smartMeteringDevice.setMbusDefaultKey("mbusDefaultKey".getBytes());
    final SmartMeteringDeviceDto smartMeteringDeviceDto = this.mapperFactory.getMapperFacade().map(smartMeteringDevice, SmartMeteringDeviceDto.class);
    assertThat(smartMeteringDevice).isNotNull();
    assertThat(smartMeteringDeviceDto).isNotNull();
    assertThat(smartMeteringDeviceDto).isEqualToIgnoringGivenFields(smartMeteringDevice, "hls3Active", "hls4Active", "hls5Active");
    assertThat(smartMeteringDeviceDto.isHls3Active()).isEqualTo(smartMeteringDevice.isHls3Active());
    assertThat(smartMeteringDeviceDto.isHls4Active()).isEqualTo(smartMeteringDevice.isHls4Active());
    assertThat(smartMeteringDeviceDto.isHls5Active()).isEqualTo(smartMeteringDevice.isHls5Active());
    assertThat(smartMeteringDeviceDto).isNotNull().isEqualToIgnoringGivenFields(smartMeteringDevice, "ipAddress", "btsId", "cellId");
}
Also used : SmartMeteringDeviceDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDto) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with SmartMeteringDevice

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice in project open-smart-grid-platform by OSGP.

the class InstallationService method addMeter.

public void addMeter(final MessageMetadata messageMetadata, final AddSmartMeterRequest addSmartMeterRequest) throws FunctionalException {
    final String organisationId = messageMetadata.getOrganisationIdentification();
    final String deviceId = messageMetadata.getDeviceIdentification();
    LOGGER.debug("addMeter for organisationIdentification: {} for deviceIdentification: {}", organisationId, deviceId);
    final SmartMeteringDevice smartMeteringDevice = addSmartMeterRequest.getDevice();
    final String deviceIdentification = messageMetadata.getDeviceIdentification();
    this.smartMeterService.validateSmartMeterDoesNotExist(deviceIdentification);
    final SmartMeter smartMeter = this.smartMeterService.convertSmartMeter(smartMeteringDevice);
    this.smartMeterService.storeMeter(organisationId, addSmartMeterRequest, smartMeter);
    final SmartMeteringDeviceDto requestDto = this.mapperFactory.getMapperFacade().map(smartMeteringDevice, SmartMeteringDeviceDto.class);
    this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata);
}
Also used : SmartMeteringDeviceDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDto) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter)

Aggregations

SmartMeteringDevice (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice)10 Test (org.junit.jupiter.api.Test)6 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)4 DeviceModel (org.opensmartgridplatform.domain.core.valueobjects.DeviceModel)3 AddSmartMeterRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest)3 Date (java.util.Date)2 Device (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.Device)2 SmartMeteringDeviceDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDto)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 ConstraintViolationException (javax.validation.ConstraintViolationException)1 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.common.AsyncResponse)1 AddDeviceAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.AddDeviceAsyncResponse)1 CoupleMbusDeviceAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceAsyncResponse)1 CoupleMbusDeviceByChannelAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.CoupleMbusDeviceByChannelAsyncResponse)1 DecoupleMbusDeviceAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceAsyncResponse)1 DecoupleMbusDeviceByChannelAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.smartmetering.installation.DecoupleMbusDeviceByChannelAsyncResponse)1 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)1 ProtocolInfo (org.opensmartgridplatform.domain.core.entities.ProtocolInfo)1 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1