Search in sources :

Example 1 with ActualPowerQualityDataDto

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);
    }
}
Also used : ActualPowerQualityData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActualPowerQualityData) ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) PowerQualityObject(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PowerQualityObject) ActualPowerQualityResponse(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActualPowerQualityResponse) ArrayList(java.util.ArrayList) PowerQualityValue(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PowerQualityValue)

Example 2 with ActualPowerQualityDataDto

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;
}
Also used : ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) ActualPowerQualityResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityResponseDto)

Example 3 with ActualPowerQualityDataDto

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++]);
    }
}
Also used : ActualPowerQualityData(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActualPowerQualityData) ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) PowerQualityValue(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PowerQualityValue) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) Test(org.junit.jupiter.api.Test)

Example 4 with ActualPowerQualityDataDto

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);
}
Also used : ActualPowerQualityDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto) GetResult(org.openmuc.jdlms.GetResult) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) CosemDateTimeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PowerQualityObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto) PowerQualityValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto) DlmsMeterValueDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)

Aggregations

ActualPowerQualityDataDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityDataDto)4 ArrayList (java.util.ArrayList)2 ActualPowerQualityData (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActualPowerQualityData)2 PowerQualityValue (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PowerQualityValue)2 PowerQualityObjectDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityObjectDto)2 BigDecimal (java.math.BigDecimal)1 Test (org.junit.jupiter.api.Test)1 GetResult (org.openmuc.jdlms.GetResult)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ActualPowerQualityResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActualPowerQualityResponse)1 PowerQualityObject (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PowerQualityObject)1 ActualPowerQualityResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityResponseDto)1 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)1 DlmsMeterValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DlmsMeterValueDto)1 PowerQualityValueDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.PowerQualityValueDto)1