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;
}
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"));
}
}
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);
}
}
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);
}
}
Aggregations