Search in sources :

Example 1 with PowerUsageDataDto

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);
}
Also used : ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) DeviceOutputSetting(com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting) GetPowerUsageHistoryDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetPowerUsageHistoryDeviceResponse) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) Iec61850PowerUsageHistoryCommand(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850PowerUsageHistoryCommand) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) FunctionalException(com.alliander.osgp.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) Ssld(com.alliander.osgp.core.db.api.iec61850.entities.Ssld)

Example 2 with PowerUsageDataDto

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);
        }
    }
}
Also used : DeviceMessageStatus(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceMessageStatus) GetPowerUsageHistoryDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse) IOException(java.io.IOException) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) Oslp(com.alliander.osgp.oslp.Oslp)

Example 3 with PowerUsageDataDto

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);
}
Also used : DeviceMessageStatus(com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceMessageStatus) GetActualPowerUsageDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetActualPowerUsageDeviceResponse) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) Oslp(com.alliander.osgp.oslp.Oslp)

Example 4 with PowerUsageDataDto

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);
}
Also used : PageInfoDto(com.alliander.osgp.dto.valueobjects.PageInfoDto) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) OslpEnvelope(com.alliander.osgp.oslp.OslpEnvelope)

Example 5 with PowerUsageDataDto

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;
}
Also used : RelayDataDto(com.alliander.osgp.dto.valueobjects.RelayDataDto) SsldDataDto(com.alliander.osgp.dto.valueobjects.SsldDataDto) MeterTypeDto(com.alliander.osgp.dto.valueobjects.MeterTypeDto) PowerUsageDataDto(com.alliander.osgp.dto.valueobjects.PowerUsageDataDto) Oslp(com.alliander.osgp.oslp.Oslp) PsldDataDto(com.alliander.osgp.dto.valueobjects.PsldDataDto) DateTime(org.joda.time.DateTime)

Aggregations

PowerUsageDataDto (com.alliander.osgp.dto.valueobjects.PowerUsageDataDto)7 Oslp (com.alliander.osgp.oslp.Oslp)3 DeviceMessageStatus (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceMessageStatus)2 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)2 RelayDataDto (com.alliander.osgp.dto.valueobjects.RelayDataDto)2 SsldDataDto (com.alliander.osgp.dto.valueobjects.SsldDataDto)2 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 GetPowerUsageHistoryDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetPowerUsageHistoryDeviceResponse)1 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)1 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)1 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)1 Iec61850PowerUsageHistoryCommand (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850PowerUsageHistoryCommand)1 GetActualPowerUsageDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetActualPowerUsageDeviceResponse)1 GetPowerUsageHistoryDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse)1