Example usage for org.joda.time DateTime DateTime

List of usage examples for org.joda.time DateTime DateTime

Introduction

In this page you can find the example usage for org.joda.time DateTime DateTime.

Prototype

public DateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.alliander.osgp.acceptancetests.DateUtils.java

License:Open Source License

public static XMLGregorianCalendar convertToXMLGregorianCalendar(final String dateString, final String format)
        throws DatatypeConfigurationException, ParseException {
    if (dateString == null || dateString.isEmpty()) {
        return null;
    }//w  w  w. ja v a  2 s  . c  o m

    final SimpleDateFormat sdf = new SimpleDateFormat(format);
    final DateTime dateTime = new DateTime(sdf.parse(dateString));
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(dateTime.toGregorianCalendar());
}

From source file:com.alliander.osgp.acceptancetests.devicemonitoring.GetActualPowerUsageSteps.java

License:Open Source License

@DomainStep("a get actual power usage response message with correlationId (.*), deviceId (.*), qresult (.*), qdescription (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*) is found in the queue (.*)")
public void givenAGetActualPowerUsageResponseMessageIsFoundInQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final String recordTime,
        final String meterType, final String totalConsumedEnergy, final String actualConsumedPower,
        final String psldDataTotalLightHours, final String actualCurrent1, final String actualCurrent2,
        final String actualCurrent3, final String actualPower1, final String actualPower2,
        final String actualPower3, final String averagePowerFactor1, final String averagePowerFactor2,
        final String averagePowerFactor3, final String relayData1Index, final String relayData1LightingMinutes,
        final String relayData2Index, final String relayData2LightingMinutes, final Boolean isFound) {
    LOGGER.info(/*  w  w w  .ja  v  a2  s .  co  m*/
            "GIVEN: \"a get actual power usage response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found {}\".",
            correlationId, deviceId, qresult, qdescription, isFound);

    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);

            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;

            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            } else {

                final MeterType metertype = StringUtils.isBlank(meterType) ? null
                        : Enum.valueOf(MeterType.class, meterType);

                DateTime dateTime = null;
                if (!recordTime.equals("")) {
                    final Date date = new SimpleDateFormat("yyyyMMddHHmmss").parse(recordTime);
                    dateTime = new DateTime(date);
                }

                PowerUsageData powerUsageData = null;
                if (!totalConsumedEnergy.equals("") && !actualConsumedPower.equals("")) {
                    powerUsageData = new PowerUsageData(dateTime, metertype,
                            Long.parseLong(totalConsumedEnergy), Long.parseLong(actualConsumedPower));

                    final PsldData psldData = new PsldData(Integer.valueOf(psldDataTotalLightHours));

                    final List<RelayData> relayDataList = new ArrayList<RelayData>();
                    // Create RelayData instances for relay indexes and
                    // minutes
                    // lighting time.
                    relayDataList.add(new RelayData(Integer.parseInt(relayData1Index),
                            Integer.parseInt(relayData1LightingMinutes)));
                    relayDataList.add(new RelayData(Integer.parseInt(relayData2Index),
                            Integer.parseInt(relayData2LightingMinutes)));

                    // Construct SsldData using the list of RelayData.
                    final SsldData ssldData = new SsldData(Integer.valueOf(actualCurrent1),
                            Integer.valueOf(actualCurrent2), Integer.valueOf(actualCurrent3),
                            Integer.valueOf(actualPower1), Integer.valueOf(actualPower2),
                            Integer.valueOf(actualPower3), Integer.valueOf(averagePowerFactor1),
                            Integer.valueOf(averagePowerFactor2), Integer.valueOf(averagePowerFactor3),
                            relayDataList);

                    powerUsageData.setPsldData(psldData);
                    powerUsageData.setSsldData(ssldData);

                    dataObject = powerUsageData;
                }
            }
            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    result, exception, dataObject);

            when(messageMock.getObject()).thenReturn(message);

        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        } catch (final ParseException e) {
            LOGGER.error("ParseException", e);
        }

        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class)))
                .thenReturn(messageMock);
    } else {
        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.acceptancetests.devicemonitoring.GetPowerUsageHistorySteps.java

License:Open Source License

@DomainStep("a get power usage history response message with correlationId (.*), deviceId (.*), qresult (.*), qdescription (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*) is found in the queue (.*)")
public void givenAGetPowerUsageHistoryResponseMessageIsFoundInQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final String fromDate,
        final String untilDate, final String recordTime, final String meterType,
        final String totalConsumedEnergy, final String actualConsumedPower,
        final String psldDataTotalLightHours, final String actualCurrent1, final String actualCurrent2,
        final String actualCurrent3, final String actualPower1, final String actualPower2,
        final String actualPower3, final String averagePowerFactor1, final String averagePowerFactor2,
        final String averagePowerFactor3, final String relayData1Index, final String relayData1LightingMinutes,
        final String relayData2Index, final String relayData2LightingMinutes, final Boolean isFound)
        throws ParseException {
    LOGGER.info(/*from  www. j a v a2 s .c o m*/
            "GIVEN: \"a get power usage history response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found {}\".",
            correlationId, deviceId, qresult, qdescription, isFound);

    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);

            final MeterType metertype = StringUtils.isBlank(meterType) ? null
                    : Enum.valueOf(MeterType.class, meterType);

            DateTime dateTime = null;
            if (!recordTime.equals("")) {
                final Date date = new SimpleDateFormat("yyyyMMddHHmmss").parse(recordTime);
                dateTime = new DateTime(date);
            }

            final com.alliander.osgp.domain.core.valueobjects.PowerUsageData powerUsageData = new com.alliander.osgp.domain.core.valueobjects.PowerUsageData(
                    dateTime, metertype, Long.parseLong(totalConsumedEnergy),
                    Long.parseLong(actualConsumedPower));

            final List<com.alliander.osgp.domain.core.valueobjects.RelayData> list = new ArrayList<>();
            list.add(new com.alliander.osgp.domain.core.valueobjects.RelayData(Integer.valueOf(relayData1Index),
                    Integer.valueOf(relayData1LightingMinutes)));
            list.add(new com.alliander.osgp.domain.core.valueobjects.RelayData(Integer.valueOf(relayData2Index),
                    Integer.valueOf(relayData2LightingMinutes)));

            final com.alliander.osgp.domain.core.valueobjects.SsldData ssldData = new com.alliander.osgp.domain.core.valueobjects.SsldData(
                    Integer.valueOf(actualCurrent1), Integer.valueOf(actualCurrent2),
                    Integer.valueOf(actualCurrent3), Integer.valueOf(actualPower1),
                    Integer.valueOf(actualPower2), Integer.valueOf(actualPower3),
                    Integer.valueOf(averagePowerFactor1), Integer.valueOf(averagePowerFactor2),
                    Integer.valueOf(averagePowerFactor3), list);

            powerUsageData.setSsldData(ssldData);

            final List<com.alliander.osgp.domain.core.valueobjects.PowerUsageData> powerUsageDatas = new ArrayList<com.alliander.osgp.domain.core.valueobjects.PowerUsageData>();
            powerUsageDatas.add(powerUsageData);

            final com.alliander.osgp.domain.core.valueobjects.PowerUsageHistoryResponse powerUsageHistoryResponse = new com.alliander.osgp.domain.core.valueobjects.PowerUsageHistoryResponse(
                    powerUsageDatas);

            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    ResponseMessageResultType.valueOf(qresult), null, powerUsageHistoryResponse);

            when(messageMock.getObject()).thenReturn(message);

        } catch (final JMSException e) {
            LOGGER.error("JMSException", e);
        }

        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class)))
                .thenReturn(messageMock);
    } else {
        when(this.publicLightingResponsesJmsTemplate.receiveSelected(any(String.class))).thenReturn(null);
    }
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientRTUEventListener.java

License:Open Source License

@Override
public void newReport(final Report report) {
    final DateTime timeOfEntry = report.getTimeOfEntry() == null ? null
            : new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET);

    final String reportDescription = String.format("device: %s, reportId: %s, timeOfEntry: %s, sqNum: %s%s%s",
            this.deviceIdentification, report.getRptId(), timeOfEntry == null ? "-" : timeOfEntry,
            report.getSqNum(), report.getSubSqNum() == null ? "" : " subSqNum: " + report.getSubSqNum(),
            report.isMoreSegmentsFollow() ? " (more segments follow for this sqNum)" : "");

    this.logger.info("newReport for {}", reportDescription);
    boolean skipRecordBecauseOfOldSqNum = false;

    if (report.isBufOvfl()) {
        this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.",
                reportDescription);/*from   w  ww  .  j  a  v  a2 s .  c  om*/
    } else if (this.firstNewSqNum != null && report.getSqNum() != null) {
        if (report.getSqNum() < this.firstNewSqNum) {
            skipRecordBecauseOfOldSqNum = true;
        }
    }

    if (skipRecordBecauseOfOldSqNum) {
        this.logger.warn(
                "Skipping report because SqNum: {} is less than what should be the first new value: {}",
                report.getSqNum(), this.firstNewSqNum);
        return;
    }

    final Iec61850ReportHandler reportHandler = REPORT_HANDLERS.get(report.getDataSetRef());
    if (reportHandler == null) {
        this.logger.warn("Skipping report because dataset is not supported {}", report.getDataSetRef());
        return;
    }

    this.logReportDetails(report);
    try {
        this.processDataSet(report.getDataSet(), reportDescription, reportHandler);
    } catch (final ProtocolAdapterException e) {
        this.logger.warn("Unable to process report, discarding report", e);
    }
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientRTUEventListener.java

License:Open Source License

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification)
            .append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString()))
            .append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(")
                .append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET))
                .append(')').append(System.lineSeparator());
    }//from w  w w .  j  a  va  2  s .  c  o m
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if (reasonCodes != null && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t")
                    .append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue())
                            : reasonCode)
                    .append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo())
                    .append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(")
            .append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')')
            .append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if (members != null && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                sb.append("\t                   \t\t").append(member);
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientSSLDEventListener.java

License:Open Source License

private DateTime getTimeOfEntry(final Report report) {
    return report.getTimeOfEntry() == null ? null
            : new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET);
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientSSLDEventListener.java

License:Open Source License

private DateTime determineDateTime(final FcModelNode evnRpn, final DateTime timeOfEntry) {

    final BdaTimestamp trgTimeNode = (BdaTimestamp) evnRpn.getChild(EVENT_NODE_TRIGGER_TIME);
    if (trgTimeNode != null && trgTimeNode.getDate() != null) {
        return new DateTime(trgTimeNode.getDate());
    }/* ww w .j  a v a2 s . c  o  m*/

    if (timeOfEntry != null) {
        /*
         * Use the reports time of entry for the event. The trigger time
         * will appear in the description with the event notification.
         * 
         * See: determineDescription(FcModelNode)
         */
        return timeOfEntry;
    }

    /*
     * No time of entry or trigger time available for the report. As a
     * fallback use the time the report is processed here as event time.
     */
    return DateTime.now();
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientSSLDEventListener.java

License:Open Source License

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification)
            .append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString()))
            .append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(")
                .append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET))
                .append(')').append(System.lineSeparator());
    }//from   w  w  w  . j a v a  2 s  .c  om
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if (reasonCodes != null && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t")
                    .append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue())
                            : reasonCode)
                    .append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo())
                    .append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(")
            .append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')')
            .append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if (members != null && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                if (member.getReference().toString().contains("CSLC.EvnRpn")) {
                    sb.append(this.evnRpnInfo("\t                   \t\t", member));
                }
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientSSLDEventListener.java

License:Open Source License

private String evnRpnInfo(final String linePrefix, final FcModelNode evnRpn) {
    final StringBuilder sb = new StringBuilder();

    final BdaInt8U evnTypeNode = (BdaInt8U) evnRpn.getChild(EVENT_NODE_EVENT_TYPE);
    sb.append(linePrefix).append(EVENT_NODE_EVENT_TYPE).append(": ");
    if (evnTypeNode == null) {
        sb.append("null");
    } else {/*from  w w  w.  j  a v a  2  s. c o m*/
        final short evnType = evnTypeNode.getValue();
        sb.append(evnType).append(" = ").append(EventType.forCode(evnType).getDescription());
    }
    sb.append(System.lineSeparator());

    final BdaInt8U swNumNode = (BdaInt8U) evnRpn.getChild(EVENT_NODE_SWITCH_NUMBER);
    sb.append(linePrefix).append(EVENT_NODE_SWITCH_NUMBER).append(": ");
    if (swNumNode == null) {
        sb.append("null");
    } else {
        final short swNum = swNumNode.getValue();
        sb.append(swNum).append(" = ").append("get external index for switch " + swNum);
    }
    sb.append(System.lineSeparator());

    final BdaInt8U trgTypeNode = (BdaInt8U) evnRpn.getChild(EVENT_NODE_TRIGGER_TYPE);
    sb.append(linePrefix).append(EVENT_NODE_TRIGGER_TYPE).append(": ");
    if (trgTypeNode == null) {
        sb.append("null");
    } else {
        final short trgType = trgTypeNode.getValue();
        sb.append(trgType).append(" = ").append(TRG_TYPE_DESCRIPTION_PER_CODE.get(trgType));
    }
    sb.append(System.lineSeparator());

    final BdaBoolean swValNode = (BdaBoolean) evnRpn.getChild(EVENT_NODE_SWITCH_VALUE);
    sb.append(linePrefix).append(EVENT_NODE_SWITCH_VALUE).append(": ");
    if (swValNode == null) {
        sb.append("null");
    } else {
        final boolean swVal = swValNode.getValue();
        sb.append(swVal).append(" = ").append(swVal ? "ON" : "OFF");
    }
    sb.append(System.lineSeparator());

    final BdaTimestamp trgTimeNode = (BdaTimestamp) evnRpn.getChild(EVENT_NODE_TRIGGER_TIME);
    sb.append(linePrefix).append(EVENT_NODE_TRIGGER_TIME).append(": ");
    if (trgTimeNode == null || trgTimeNode.getDate() == null) {
        sb.append("null");
    } else {
        final DateTime trgTime = new DateTime(trgTimeNode.getDate());
        sb.append(trgTime);
    }
    sb.append(System.lineSeparator());

    final BdaVisibleString remarkNode = (BdaVisibleString) evnRpn.getChild(EVENT_NODE_REMARK);
    sb.append(linePrefix).append(EVENT_NODE_REMARK).append(": ");
    if (remarkNode == null) {
        sb.append("null");
    } else {
        final String remark = remarkNode.getStringValue();
        sb.append(remark);
    }
    sb.append(System.lineSeparator());

    return sb.toString();
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850PowerUsageHistoryCommand.java

License:Open Source License

private List<PowerUsageDataDto> getPowerUsageHistoryDataFromRelay(final Iec61850Client iec61850Client,
        final DeviceConnection deviceConnection, final TimePeriodDto timePeriod,
        final DeviceOutputSetting deviceOutputSetting) throws NodeReadException {
    final List<PowerUsageDataDto> powerUsageHistoryDataFromRelay = new ArrayList<>();

    final int relayIndex = deviceOutputSetting.getExternalId();

    final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
    final NodeContainer onIntervalBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode,
            DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(),
            onIntervalBuffer.getFcmodelNode());

    final Short lastIndex = onIntervalBuffer.getUnsignedByte(SubDataAttribute.LAST_INDEX).getValue();

    /*//from ww  w. j  av a  2  s. c  om
     * Last index is the last index written in the 60-entry buffer. When the
     * last buffer entry is written, the next entry will be placed at the
     * first position in the buffer (cyclically). To preserve the order of
     * entries written in the response, iteration starts with the next index
     * (oldest entry) and loops from there.
     */
    final int numberOfEntries = 60;
    final int idxOldest = (lastIndex + 1) % numberOfEntries;

    for (int i = 0; i < numberOfEntries; i++) {
        final int bufferIndex = (idxOldest + i) % numberOfEntries;
        final NodeContainer indexedItvNode = onIntervalBuffer
                .getChild(SubDataAttribute.INTERVAL.getDescription() + (bufferIndex + 1));
        LOGGER.info("device: {}, itv{}: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1,
                indexedItvNode);

        final Integer itvNode = indexedItvNode.getInteger(SubDataAttribute.INTERVAL).getValue();
        LOGGER.info("device: {}, itv{}.itv: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1,
                itvNode);

        final DateTime date = new DateTime(indexedItvNode.getDate(SubDataAttribute.DAY));
        LOGGER.info("device: {}, itv{}.day: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1,
                date);

        final int totalMinutesOnForDate = itvNode;
        final boolean includeEntryInResponse = this.timePeriodContainsDateTime(timePeriod, date,
                deviceConnection.getDeviceIdentification(), relayIndex, bufferIndex);
        if (!includeEntryInResponse) {
            continue;
        }

        // MeterType.AUX hard-coded (not supported).
        final PowerUsageDataDto powerUsageData = new PowerUsageDataDto(date, MeterTypeDto.AUX, 0, 0);
        final List<RelayDataDto> relayDataList = new ArrayList<>();
        final RelayDataDto relayData = new RelayDataDto(relayIndex, totalMinutesOnForDate);
        relayDataList.add(relayData);
        final SsldDataDto ssldData = new SsldDataDto(0, 0, 0, 0, 0, 0, 0, 0, 0, relayDataList);
        powerUsageData.setSsldData(ssldData);
        powerUsageHistoryDataFromRelay.add(powerUsageData);
    }

    return powerUsageHistoryDataFromRelay;
}