Search in sources :

Example 1 with DeviceModel

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceModel 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 2 with DeviceModel

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceModel 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 3 with DeviceModel

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

the class SmartMeterServiceTest method testStoreMeterWithUnknownProtocolInfo.

@Test
void testStoreMeterWithUnknownProtocolInfo() {
    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();
    when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(any(), any())).thenReturn(null);
    FunctionalException exception = Assertions.assertThrows(FunctionalException.class, () -> {
        this.smartMeterService.storeMeter(organisationIdentification, addSmartMeterRequest, smartMeter);
    });
    assertThat(exception.getExceptionType()).isEqualTo(FunctionalExceptionType.UNKNOWN_PROTOCOL_NAME_OR_VERSION);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) AddSmartMeterRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Test(org.junit.jupiter.api.Test)

Example 4 with DeviceModel

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

the class DeviceManagementEndpoint method addRtuDevice.

@PayloadRoot(localPart = "AddRtuDeviceRequest", namespace = NAMESPACE)
@ResponsePayload
public AddRtuDeviceAsyncResponse addRtuDevice(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddRtuDeviceRequest request) throws OsgpException {
    LOGGER.info("Incoming AddRtuDeviceRequest for device: {}.", request.getRtuDevice().getDeviceIdentification());
    AddRtuDeviceAsyncResponse response = null;
    try {
        response = new AddRtuDeviceAsyncResponse();
        final RtuDevice rtuDevice = this.mapper.map(request.getRtuDevice(), RtuDevice.class);
        final DeviceModel deviceModel = new DeviceModel(request.getDeviceModel().getManufacturer(), request.getDeviceModel().getModelCode(), "");
        final String correlationUid = this.service.enqueueAddRtuDeviceRequest(organisationIdentification, rtuDevice.getDeviceIdentification(), new org.opensmartgridplatform.domain.core.valueobjects.AddRtuDeviceRequest(rtuDevice, deviceModel));
        response.setCorrelationUid(correlationUid);
        response.setDeviceId(request.getRtuDevice().getDeviceIdentification());
    } catch (final Exception e) {
        this.handleException(LOGGER, e);
    }
    return response;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) AddRtuDeviceAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.AddRtuDeviceAsyncResponse) RtuDevice(org.opensmartgridplatform.domain.core.valueobjects.RtuDevice) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

DeviceModel (org.opensmartgridplatform.domain.core.valueobjects.DeviceModel)4 AddSmartMeterRequest (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest)3 SmartMeteringDevice (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice)3 Test (org.junit.jupiter.api.Test)2 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)2 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)2 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)2 ConstraintViolationException (javax.validation.ConstraintViolationException)1 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException)1 AddRtuDeviceAsyncResponse (org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.AddRtuDeviceAsyncResponse)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