Search in sources :

Example 1 with GetPowerUsageHistoryDeviceResponse

use of com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse 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 2 with GetPowerUsageHistoryDeviceResponse

use of com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse in project Protocol-Adapter-OSLP by OSGP.

the class PublicLightingGetPowerUsageHistoryRequestMessageProcessor method handleGetPowerUsageHistoryDeviceResponse.

protected void handleGetPowerUsageHistoryDeviceResponse(final DeviceResponse deviceResponse, final PowerUsageHistoryMessageDataContainerDto messageData, final DeviceResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final boolean isScheduled, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    PowerUsageHistoryResponseMessageDataContainerDto powerUsageHistoryResponseMessageDataContainerDto = null;
    Serializable dataObject;
    try {
        final GetPowerUsageHistoryDeviceResponse response = (GetPowerUsageHistoryDeviceResponse) deviceResponse;
        this.deviceResponseService.handleDeviceMessageStatus(response.getStatus());
        powerUsageHistoryResponseMessageDataContainerDto = new PowerUsageHistoryResponseMessageDataContainerDto(response.getPowerUsageHistoryData());
        dataObject = powerUsageHistoryResponseMessageDataContainerDto;
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        dataObject = messageData;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device power usage history", e);
    }
    final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, MessagePriorityEnum.DEFAULT.getPriority());
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(dataObject).scheduled(isScheduled).retryCount(retryCount).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) PowerUsageHistoryResponseMessageDataContainerDto(com.alliander.osgp.dto.valueobjects.PowerUsageHistoryResponseMessageDataContainerDto) Serializable(java.io.Serializable) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage) GetPowerUsageHistoryDeviceResponse(com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse) DeviceMessageMetadata(com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata) ResponseMessageResultType(com.alliander.osgp.shared.infra.jms.ResponseMessageResultType) OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(com.alliander.osgp.shared.exceptionhandling.TechnicalException)

Aggregations

GetPowerUsageHistoryDeviceResponse (com.alliander.osgp.adapter.protocol.oslp.elster.device.responses.GetPowerUsageHistoryDeviceResponse)2 IOException (java.io.IOException)2 DeviceMessageStatus (com.alliander.osgp.adapter.protocol.oslp.elster.device.DeviceMessageStatus)1 PowerUsageDataDto (com.alliander.osgp.dto.valueobjects.PowerUsageDataDto)1 PowerUsageHistoryResponseMessageDataContainerDto (com.alliander.osgp.dto.valueobjects.PowerUsageHistoryResponseMessageDataContainerDto)1 Oslp (com.alliander.osgp.oslp.Oslp)1 OsgpException (com.alliander.osgp.shared.exceptionhandling.OsgpException)1 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)1 DeviceMessageMetadata (com.alliander.osgp.shared.infra.jms.DeviceMessageMetadata)1 ProtocolResponseMessage (com.alliander.osgp.shared.infra.jms.ProtocolResponseMessage)1 ResponseMessageResultType (com.alliander.osgp.shared.infra.jms.ResponseMessageResultType)1 Serializable (java.io.Serializable)1 JMSException (javax.jms.JMSException)1