Search in sources :

Example 1 with GetPowerQualityProfileResponseDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto in project open-smart-grid-platform by OSGP.

the class AbstractGetPowerQualityProfileHandler method handle.

protected GetPowerQualityProfileResponseDto handle(final DlmsConnectionManager conn, final DlmsDevice device, final GetPowerQualityProfileRequestDataDto getPowerQualityProfileRequestDataDto) throws ProtocolAdapterException {
    final String profileType = getPowerQualityProfileRequestDataDto.getProfileType();
    final List<Profile> profiles = this.determineProfileForDevice(profileType);
    final GetPowerQualityProfileResponseDto response = new GetPowerQualityProfileResponseDto();
    final List<PowerQualityProfileDataDto> responseDatas = new ArrayList<>();
    for (final Profile profile : profiles) {
        final ObisCode obisCode = this.makeObisCode(profile.getObisCodeValuesDto());
        final DateTime beginDateTime = new DateTime(getPowerQualityProfileRequestDataDto.getBeginDate());
        final DateTime endDateTime = new DateTime(getPowerQualityProfileRequestDataDto.getEndDate());
        // all value types that can be selected within this profile.
        final List<GetResult> captureObjects = this.retrieveCaptureObjects(conn, device, obisCode);
        // the values that are allowed to be retrieved from the meter, used
        // as filter either before (SMR 5.1+) or
        // after data retrieval
        final Map<Integer, CaptureObjectDefinitionDto> selectableCaptureObjects = this.createSelectableCaptureObjects(captureObjects, profile.getLogicalNames());
        // the units of measure for all Selectable Capture objects
        final List<ScalerUnitInfo> scalerUnitInfos = this.createScalerUnitInfos(conn, device, selectableCaptureObjects.values());
        final List<GetResult> bufferList = this.retrieveBuffer(conn, device, obisCode, beginDateTime, endDateTime, new ArrayList<>(selectableCaptureObjects.values()));
        final PowerQualityProfileDataDto responseDataDto = this.processData(profile, captureObjects, scalerUnitInfos, selectableCaptureObjects, bufferList);
        responseDatas.add(responseDataDto);
    }
    response.setPowerQualityProfileDatas(responseDatas);
    return response;
}
Also used : PowerQualityProfileDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityProfileDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) ObisCode(org.openmuc.jdlms.ObisCode) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) CaptureObjectDefinitionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto) ScalerUnitInfo(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.ScalerUnitInfo) GetPowerQualityProfileResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto)

Example 2 with GetPowerQualityProfileResponseDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto in project open-smart-grid-platform by OSGP.

the class GetPowerQualityProfileResponseMessageProcessor method handleMessage.

@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) throws FunctionalException {
    if (responseMessage.getDataObject() instanceof GetPowerQualityProfileResponseDto) {
        final GetPowerQualityProfileResponseDto getPowerQualityProfileResponseDto = (GetPowerQualityProfileResponseDto) responseMessage.getDataObject();
        this.monitoringService.handleGetPowerQualityProfileResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, getPowerQualityProfileResponseDto);
    } else {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new OsgpException(ComponentType.DOMAIN_SMART_METERING, "DataObject for response message should be of type GetPowerQualityProfileResponseDto"));
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetPowerQualityProfileResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 3 with GetPowerQualityProfileResponseDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto in project open-smart-grid-platform by OSGP.

the class GetPowerQualityProfileNoSelectiveAccessHandlerTest method testHandlePublicProfileWithoutSelectiveAccess.

@Test
public void testHandlePublicProfileWithoutSelectiveAccess() throws ProtocolAdapterException {
    // SETUP
    final GetPowerQualityProfileRequestDataDto requestDto = new GetPowerQualityProfileRequestDataDto("PUBLIC", Date.from(Instant.now().minus(2, ChronoUnit.DAYS)), new Date(), new ArrayList<>());
    when(this.dlmsHelper.getAndCheck(any(DlmsConnectionManager.class), any(DlmsDevice.class), any(String.class), any(AttributeAddress.class))).thenReturn(this.createPartialNotAllowedCaptureObjects(), this.createProfileEntries(), this.createPartialNotAllowedCaptureObjects(), this.createProfileEntries());
    when(this.dlmsHelper.readLogicalName(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readObjectDefinition(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readLongNotNull(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readLong(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.convertDataObjectToDateTime(any(DataObject.class))).thenCallRealMethod();
    when(this.dlmsHelper.fromDateTimeValue(any())).thenCallRealMethod();
    when(this.dlmsHelper.getClockDefinition()).thenCallRealMethod();
    final GetPowerQualityProfileNoSelectiveAccessHandler handler = new GetPowerQualityProfileNoSelectiveAccessHandler(this.dlmsHelper);
    // EXECUTE
    final GetPowerQualityProfileResponseDto responseDto = handler.handle(this.conn, this.dlmsDevice, requestDto);
    // ASSERT
    assertThat(responseDto.getPowerQualityProfileResponseDatas().size()).isEqualTo(2);
    assertThat(responseDto.getPowerQualityProfileResponseDatas().get(0).getCaptureObjects().size()).isEqualTo(2);
    assertThat(responseDto.getPowerQualityProfileResponseDatas().get(0).getProfileEntries().size()).isEqualTo(4);
    for (final ProfileEntryDto profileEntryDto : responseDto.getPowerQualityProfileResponseDatas().get(0).getProfileEntries()) {
        assertThat(profileEntryDto.getProfileEntryValues().size()).isEqualTo(2);
    }
}
Also used : ProfileEntryDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ProfileEntryDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) GetPowerQualityProfileRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileRequestDataDto) GetPowerQualityProfileResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with GetPowerQualityProfileResponseDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto in project open-smart-grid-platform by OSGP.

the class GetPowerQualityProfileSelectiveAccessHandlerTest method testHandlePrivateProfileSelectiveAccess.

@Test
public void testHandlePrivateProfileSelectiveAccess() throws ProtocolAdapterException {
    // SETUP
    final GetPowerQualityProfileRequestDataDto requestDto = new GetPowerQualityProfileRequestDataDto("PRIVATE", Date.from(Instant.now().minus(2, ChronoUnit.DAYS)), new Date(), new ArrayList<>());
    when(this.dlmsHelper.getAndCheck(any(DlmsConnectionManager.class), any(DlmsDevice.class), any(String.class), any(AttributeAddress.class))).thenReturn(this.createCaptureObjects(), this.createProfileEntries(), this.createCaptureObjectsProfile2(), this.createProfileEntries());
    when(this.dlmsHelper.readLogicalName(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readObjectDefinition(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readLongNotNull(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.readLong(any(DataObject.class), any(String.class))).thenCallRealMethod();
    when(this.dlmsHelper.convertDataObjectToDateTime(any(DataObject.class))).thenCallRealMethod();
    when(this.dlmsHelper.fromDateTimeValue(any())).thenCallRealMethod();
    when(this.dlmsHelper.getClockDefinition()).thenCallRealMethod();
    final GetPowerQualityProfileSelectiveAccessHandler handler = new GetPowerQualityProfileSelectiveAccessHandler(this.dlmsHelper);
    // EXECUTE
    final GetPowerQualityProfileResponseDto responseDto = handler.handle(this.conn, this.dlmsDevice, requestDto);
    // ASSERT
    assertThat(responseDto.getPowerQualityProfileResponseDatas().size()).isEqualTo(2);
    assertThat(responseDto.getPowerQualityProfileResponseDatas().get(0).getCaptureObjects().size()).isEqualTo(3);
    assertThat(responseDto.getPowerQualityProfileResponseDatas().get(0).getProfileEntries().size()).isEqualTo(4);
    for (final ProfileEntryDto profileEntryDto : responseDto.getPowerQualityProfileResponseDatas().get(0).getProfileEntries()) {
        assertThat(profileEntryDto.getProfileEntryValues().size()).isEqualTo(3);
    }
}
Also used : ProfileEntryDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ProfileEntryDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) GetPowerQualityProfileRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileRequestDataDto) GetPowerQualityProfileResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

GetPowerQualityProfileResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileResponseDto)4 Date (java.util.Date)2 Test (org.junit.jupiter.api.Test)2 AttributeAddress (org.openmuc.jdlms.AttributeAddress)2 DataObject (org.openmuc.jdlms.datatypes.DataObject)2 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)2 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)2 GetPowerQualityProfileRequestDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.GetPowerQualityProfileRequestDataDto)2 ProfileEntryDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ProfileEntryDto)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 GetResult (org.openmuc.jdlms.GetResult)1 ObisCode (org.openmuc.jdlms.ObisCode)1 ScalerUnitInfo (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.ScalerUnitInfo)1 CaptureObjectDefinitionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CaptureObjectDefinitionDto)1 PowerQualityProfileDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityProfileDataDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1