use of com.alliander.osgp.dto.valueobjects.PowerUsageDataDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method getPowerUsageHistory.
@Override
public void getPowerUsageHistory(final GetPowerUsageHistoryDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
final List<DeviceOutputSetting> deviceOutputSettingsLightRelays = this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT);
final List<PowerUsageDataDto> powerUsageHistoryData = new Iec61850PowerUsageHistoryCommand().getPowerUsageHistoryDataFromDevice(this.iec61850Client, deviceConnection, deviceRequest.getPowerUsageHistoryContainer(), deviceOutputSettingsLightRelays);
final GetPowerUsageHistoryDeviceResponse deviceResponse = new GetPowerUsageHistoryDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, powerUsageHistoryData);
deviceResponseHandler.handleResponse(deviceResponse);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.dto.valueobjects.PowerUsageDataDto in project Protocol-Adapter-OSLP by OSGP.
the class OslpDeviceService method handleOslpResponseGetPowerUsageHistory.
private void handleOslpResponseGetPowerUsageHistory(final GetPowerUsageHistoryDeviceRequest deviceRequest, final OslpEnvelope oslpResponse, final Pager pager, final List<PowerUsageDataDto> powerUsageHistoryData, final DeviceResponseHandler deviceResponseHandler, final String ipAddress, final String domain, final String domainVersion, final String messageType, final int retryCount, final boolean isScheduled) {
this.saveOslpResponseLogEntry(deviceRequest, oslpResponse);
this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
// Get response status
DeviceMessageStatus status;
if (oslpResponse.getPayloadMessage().hasGetPowerUsageHistoryResponse()) {
final Oslp.GetPowerUsageHistoryResponse getPowerUsageHistoryResponse = oslpResponse.getPayloadMessage().getGetPowerUsageHistoryResponse();
status = this.mapper.map(getPowerUsageHistoryResponse.getStatus(), DeviceMessageStatus.class);
powerUsageHistoryData.addAll(this.mapper.mapAsList(getPowerUsageHistoryResponse.getPowerUsageDataList(), PowerUsageDataDto.class));
if (pager.getNumberOfPages() == 1 && getPowerUsageHistoryResponse.hasPageInfo()) {
pager.setNumberOfPages(getPowerUsageHistoryResponse.getPageInfo().getTotalPages());
}
} else {
status = DeviceMessageStatus.FAILURE;
}
if (pager.isLastPage() || status != DeviceMessageStatus.OK) {
// Stop processing pages and handle device response.
this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
final GetPowerUsageHistoryDeviceResponse deviceResponse = new GetPowerUsageHistoryDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), status, powerUsageHistoryData);
deviceResponseHandler.handleResponse(deviceResponse);
} else {
// Process next page
pager.nextPage();
try {
this.processOslpRequestGetPowerUsageHistory(deviceRequest, pager, powerUsageHistoryData, deviceResponseHandler, ipAddress, domain, domainVersion, messageType, retryCount, isScheduled);
} catch (final IOException e) {
LOGGER.error("IOException", e);
final GetPowerUsageHistoryDeviceResponse deviceResponse = new GetPowerUsageHistoryDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE, null);
deviceResponseHandler.handleResponse(deviceResponse);
}
}
}
use of com.alliander.osgp.dto.valueobjects.PowerUsageDataDto in project Protocol-Adapter-OSLP by OSGP.
the class OslpDeviceService method buildDeviceResponseGetActualPowerUsage.
private DeviceResponse buildDeviceResponseGetActualPowerUsage(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse) {
PowerUsageDataDto actualPowerUsageData = null;
DeviceMessageStatus status = null;
if (oslpResponse.getPayloadMessage().hasGetActualPowerUsageResponse()) {
final Oslp.GetActualPowerUsageResponse response = oslpResponse.getPayloadMessage().getGetActualPowerUsageResponse();
actualPowerUsageData = this.mapper.map(response.getPowerUsageData(), PowerUsageDataDto.class);
status = this.mapper.map(response.getStatus(), DeviceMessageStatus.class);
} else {
status = DeviceMessageStatus.FAILURE;
}
return new GetActualPowerUsageDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), status, actualPowerUsageData);
}
use of com.alliander.osgp.dto.valueobjects.PowerUsageDataDto in project Protocol-Adapter-OSLP by OSGP.
the class OslpDeviceService method doGetPowerUsageHistory.
@Override
public void doGetPowerUsageHistory(final OslpEnvelope oslpRequest, final PowerUsageHistoryResponseMessageDataContainerDto powerUsageHistoryResponseMessageDataContainer, final GetPowerUsageHistoryDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final String ipAddress, final String domain, final String domainVersion, final String messageType, final int retryCount, final boolean isScheduled) throws IOException {
LOGGER.info("doGetPowerUsageHistory() for device: {}.", deviceRequest.getDeviceIdentification());
this.saveOslpRequestLogEntry(deviceRequest, oslpRequest);
final List<PowerUsageDataDto> powerUsageHistoryData = powerUsageHistoryResponseMessageDataContainer.getPowerUsageData();
final PageInfoDto pageInfo = powerUsageHistoryResponseMessageDataContainer.getPageInfo();
final Pager pager = new Pager(pageInfo.getTotalPages(), pageInfo.getPageSize(), pageInfo.getCurrentPage());
final OslpResponseHandler oslpResponseHandler = new OslpResponseHandler() {
@Override
public void handleResponse(final OslpEnvelope oslpResponse) {
OslpDeviceService.this.handleOslpResponseGetPowerUsageHistory(deviceRequest, oslpResponse, pager, powerUsageHistoryData, deviceResponseHandler, ipAddress, domain, domainVersion, messageType, retryCount, isScheduled);
}
@Override
public void handleException(final Throwable t) {
OslpDeviceService.this.handleException(t, deviceRequest, deviceResponseHandler);
}
};
this.sendMessage(ipAddress, oslpRequest, oslpResponseHandler, deviceRequest);
}
use of com.alliander.osgp.dto.valueobjects.PowerUsageDataDto in project Protocol-Adapter-OSLP by OSGP.
the class PowerUsageDataConverter method convertFrom.
@Override
public PowerUsageDataDto convertFrom(final Oslp.PowerUsageData source, final Type<PowerUsageDataDto> destinationType, final MappingContext context) {
// Check the input parameter.
if (source == null) {
return null;
}
// Parse the time stamp.
final DateTime recordTime = this.mapperFacade.map(source.getRecordTime(), DateTime.class);
// Get the other values.
final MeterTypeDto meterType = MeterTypeDto.valueOf(source.getMeterType().name());
final long totalConsumedEnergy = source.getTotalConsumedEnergy();
final long actualConsumedPower = source.getActualConsumedPower();
// Construct PowerUsageData instance.
final PowerUsageDataDto powerUsageData = new PowerUsageDataDto(recordTime, meterType, totalConsumedEnergy, actualConsumedPower);
// Check SsldData.
if (source.getSsldData() != null) {
final Oslp.SsldData oslpSsldData = source.getSsldData();
// Map the RelayData list.
final List<RelayDataDto> list = this.mapperFacade.mapAsList(oslpSsldData.getRelayDataList(), RelayDataDto.class);
// Construct SsldData instance using the RelayData list and the
// other values.
final SsldDataDto ssldData = SsldDataDto.newBuilder().withActualCurrent1(oslpSsldData.getActualCurrent1()).withActualCurrent2(oslpSsldData.getActualCurrent2()).withActualCurrent3(oslpSsldData.getActualCurrent3()).withActualPower1(oslpSsldData.getActualPower1()).withActualPower2(oslpSsldData.getActualPower2()).withActualPower3(oslpSsldData.getActualPower3()).withAveragePowerFactor1(oslpSsldData.getAveragePowerFactor1()).withAveragePowerFactor2(oslpSsldData.getAveragePowerFactor2()).withAveragePowerFactor3(oslpSsldData.getAveragePowerFactor3()).withRelayData(list).build();
// Set SsldData instance in the PowerUsageData instance.
powerUsageData.setSsldData(ssldData);
}
// Check PsldData.
if (source.getPsldData() != null) {
final Oslp.PsldData oslpPsldData = source.getPsldData();
// Construct PsldData instance using the value.
final PsldDataDto psldData = new PsldDataDto(oslpPsldData.getTotalLightingHours());
// Set PsldData instance in the PowerUsageData instance.
powerUsageData.setPsldData(psldData);
}
return powerUsageData;
}
Aggregations