protected Keyable processSeriesNode()

in SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/reader/GenericDataReaderEngine.java [246:337]


    protected Keyable processSeriesNode() throws XMLStreamException {
        List<KeyValue> key;
        if (noSeries) {
            key = getKeyValues("ObsKey");
        } else {
            key = getKeyValues("SeriesKey");
        }
        List<KeyValue> attributes = null;
        TIME_FORMAT timeFormat = null;
        String obsValue = null;
        String obsConcept = null;

        //Send Run ahead parser to check the next node, if it is the attributes node then process it,
        //Also move forward to the first obs and get the time format, if we hit the end series node, without finding any obs then stop
        boolean inSeries = true;
        while (runAheadParser.hasNext()) {
            int event = runAheadParser.next();
            if (event == XMLStreamConstants.START_ELEMENT) {
                String nodeName = runAheadParser.getLocalName();
                if (inSeries && nodeName.equals("Attributes")) {
                    attributes = getKeyValues("Attributes");  //We have got the series key attributes
                } else if (nodeName.equals("Time")) {
                    obsConcept = runAheadParser.getElementText();
                    break;
                } else if (nodeName.equals("Obs")) {
                    if (!super.noSeries) {
                        inSeries = false; //We are no longer in a series, so we don't want to process obs attributes here
                    }
                } else if (nodeName.equals("ObsDimension")) {
                    obsConcept = runAheadParser.getAttributeValue(null, "value");
                    break;
                } else if (nodeName.equals("ObsValue")) {
                    //We are in a No series key situation here
                    obsValue = runAheadParser.getAttributeValue(null, "value");
                }
            } else if (event == XMLStreamConstants.END_ELEMENT) {
                String nodeName = runAheadParser.getLocalName();
                if (nodeName.equals("Series")) {
                    break;
                } else if (noSeries && nodeName.equals("Obs")) {
                    break;
                }
            }
        }

        if (noSeries) {
            List<KeyValue> seriesKey = new ArrayList<KeyValue>();
            String obsTime = null;
            for (KeyValue currentKeyValue : key) {
                if (currentKeyValue.getConcept().equals(DimensionBean.TIME_DIMENSION_FIXED_ID)) {
                    obsTime = currentKeyValue.getCode();
                } else {
                    seriesKey.add(currentKeyValue);
                }
            }
            List<KeyValue> seriesAttributes = new ArrayList<KeyValue>();
            List<KeyValue> obsAttributes = new ArrayList<KeyValue>();
            List<String> observationAttributeIds = DataStructureUtil.getObservationConcepts(currentDsd);
            if (attributes != null) {
                for (KeyValue currentKv : attributes) {
                    if (observationAttributeIds.contains(currentKv.getConcept())) {
                        obsAttributes.add(currentKv);
                    } else {
                        seriesAttributes.add(currentKv);
                    }
                }
            }
            timeFormat = DateUtil.getTimeFormatOfDate(obsTime);
            currentKey = new KeyableImpl(currentDataflow, currentDsd, seriesKey, seriesAttributes, timeFormat);
            currentObs = new ObservationImpl(currentKey, obsTime, obsValue, obsAttributes);
        } else {
            if (isTimeSeries()) {
                if (obsConcept != null && !obsConcept.isEmpty()) {
                    timeFormat = DateUtil.getTimeFormatOfDate(obsConcept);
                }
                currentKey = new KeyableImpl(currentDataflow, currentDsd, key, attributes, timeFormat);
            } else {
                List<KeyValue> seriesKey = new ArrayList<KeyValue>();
                String crossSectionTime = null;
                for (KeyValue currentKeyValue : key) {
                    if (currentKeyValue.getConcept().equals(DimensionBean.TIME_DIMENSION_FIXED_ID)) {
                        crossSectionTime = currentKeyValue.getCode();
                        timeFormat = DateUtil.getTimeFormatOfDate(crossSectionTime);
                    } else {
                        seriesKey.add(currentKeyValue);
                    }
                }
                currentKey = new KeyableImpl(currentDataflow, currentDsd, seriesKey, attributes, timeFormat, getCrossSectionConcept(), crossSectionTime);
            }
        }
        return currentKey;
    }