use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto in project open-smart-grid-platform by OSGP.
the class ActualPowerQualityDtoConverter method convert.
@Override
public ActualPowerQualityResponse convert(final ActualPowerQualityResponseDto source, final Type<? extends ActualPowerQualityResponse> destinationType, final MappingContext mappingContext) {
if (source.getActualPowerQualityData() != null) {
final ActualPowerQualityDataDto responseDataDto = source.getActualPowerQualityData();
final List<PowerQualityObject> powerQualityObjects = new ArrayList<>(this.mapperFacade.mapAsList(responseDataDto.getPowerQualityObjects(), PowerQualityObject.class));
final List<PowerQualityValue> powerQualityValues = this.makePowerQualityValues(responseDataDto);
final ActualPowerQualityData actualPowerQualityData = new ActualPowerQualityData(powerQualityObjects, powerQualityValues);
return new ActualPowerQualityResponse(actualPowerQualityData);
} else {
return new ActualPowerQualityResponse(null);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto in project open-smart-grid-platform by OSGP.
the class GetActualPowerQualityCommandExecutor method makeActualPowerQualityResponseDto.
private ActualPowerQualityResponseDto makeActualPowerQualityResponseDto(final List<GetResult> resultList, final List<PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
final ActualPowerQualityResponseDto responseDto = new ActualPowerQualityResponseDto();
final ActualPowerQualityDataDto actualPowerQualityDataDto = this.makeActualPowerQualityDataDto(resultList, metadatas);
responseDto.setActualPowerQualityDataDto(actualPowerQualityDataDto);
return responseDto;
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto in project open-smart-grid-platform by OSGP.
the class ActualPowerQualityResponseDataMapperTest method testConvertActualPowerQualityResponse.
@Test
public void testConvertActualPowerQualityResponse() {
final ActualPowerQualityDataDto responseDto = new ActualPowerQualityDataDto(new ArrayList<PowerQualityObjectDto>(), this.makePowerQualityValueDtos());
final ActualPowerQualityData response = this.mapper.map(responseDto, ActualPowerQualityData.class);
assertThat(response).isNotNull();
assertThat(response.getPowerQualityValues()).hasSize(EXPECTED_CLASS.length);
int i = 0;
for (final PowerQualityValue powerQualityValue : response.getPowerQualityValues()) {
final Class<?> clazz = powerQualityValue.getValue().getClass();
assertThat(clazz).withFailMessage("the return class should be of the same type").isEqualTo(EXPECTED_CLASS[i++]);
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto in project open-smart-grid-platform by OSGP.
the class GetActualPowerQualityCommandExecutor method makeActualPowerQualityDataDto.
private ActualPowerQualityDataDto makeActualPowerQualityDataDto(final List<GetResult> resultList, final List<PowerQualityObjectMetadata> metadatas) throws ProtocolAdapterException {
final List<PowerQualityObjectDto> powerQualityObjects = new ArrayList<>();
final List<PowerQualityValueDto> powerQualityValues = new ArrayList<>();
int idx = 0;
for (final PowerQualityObjectMetadata metadata : metadatas) {
final PowerQualityObjectDto powerQualityObject;
final PowerQualityValueDto powerQualityValue;
if (metadata.getClassId() == CLASS_ID_CLOCK) {
final GetResult resultTime = resultList.get(idx++);
final CosemDateTimeDto cosemDateTime = this.dlmsHelper.readDateTime(resultTime, "Actual Power Quality - Time");
powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
powerQualityValue = new PowerQualityValueDto(cosemDateTime.asDateTime().toDate());
} else if (metadata.getClassId() == CLASS_ID_REGISTER) {
final GetResult resultValue = resultList.get(idx++);
final GetResult resultScalerUnit = resultList.get(idx++);
final DlmsMeterValueDto meterValue = this.dlmsHelper.getScaledMeterValue(resultValue, resultScalerUnit, "Actual Power Quality - " + metadata.getObisCode());
final BigDecimal value = meterValue != null ? meterValue.getValue() : null;
final String unit = meterValue != null ? meterValue.getDlmsUnit().getUnit() : null;
powerQualityValue = new PowerQualityValueDto(value);
powerQualityObject = new PowerQualityObjectDto(metadata.name(), unit);
} else if (metadata.getClassId() == CLASS_ID_DATA) {
final GetResult resultValue = resultList.get(idx++);
final Integer meterValue = this.dlmsHelper.readInteger(resultValue, "Actual Power Quality - " + metadata.getObisCode());
powerQualityValue = meterValue != null ? new PowerQualityValueDto(new BigDecimal(meterValue)) : null;
powerQualityObject = new PowerQualityObjectDto(metadata.name(), null);
} else {
throw new ProtocolAdapterException(String.format("Unsupported ClassId {} for logical name {}", metadata.getClassId(), metadata.obisCode));
}
powerQualityObjects.add(powerQualityObject);
powerQualityValues.add(powerQualityValue);
}
return new ActualPowerQualityDataDto(powerQualityObjects, powerQualityValues);
}
Aggregations