protected Keyable processSeriesNode()

in SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/reader/CompactDataReaderEngine.java [323:439]


    protected Keyable processSeriesNode() {
        //Clear values
        keyValues.clear();
        attributeValues.clear();
        TIME_FORMAT timeFormat = null;
        String timeValue = null;
        Set<String> unknownConcepts = new HashSet<String>();
        for (int i = 0; i < parser.getAttributeCount(); i++) {
            String attributeId = getComponentId(parser.getAttributeLocalName(i));
            String attributeValue = parser.getAttributeValue(i);
            if (attributeId.equals(timeConcept)) {
                timeValue = attributeValue;
                timeFormat = DateUtil.getTimeFormatOfDate(timeValue);
            } else if (dimensionConcepts.contains(attributeId)) {
                keyValues.put(attributeId, attributeValue);
            } else if (seriesAttributes.contains(attributeId)) {
                attributeValues.put(attributeId, attributeValue);
            } else if (datasetPosition == DATASET_POSITION.OBSERAVTION_AS_SERIES) {
                //This attribute was not found as a series level attribute, it could still be an observation level attribute
                //But this is only allowed if we are processing this series node as a FLAT obs node which is both an obs and key
                //In which case this attributeName could be an observation attribute, the primary measure, or the time concept.
                if (!observationAttributes.contains(attributeId)
                        && !attributeId.equals(primaryMeasureConcept)
                        && !attributeId.equals(timeConcept)) {
                    unknownConcepts.add(attributeId);
                }
            } else {
                unknownConcepts.add(attributeId);
            }
        }


        //System.out.println(keyValues);
        List<KeyValue> key = new ArrayList<KeyValue>();
        for (String dimensionConcept : dimensionConcepts) {
            String conceptValue = null;
            if (keyValues.containsKey(dimensionConcept)) {
                conceptValue = keyValues.get(dimensionConcept);
            } else {
                conceptValue = rolledUpAttributes.get(dimensionConcept);
            }
            if (conceptValue == null && datasetHeaderBean.getAction() != DATASET_ACTION.DELETE) {
                if (!isTimeSeries() && getCrossSectionConcept().equals(dimensionConcept)) {
                    //This is expected
                } else {
                    throw new SdmxSemmanticException("Missing series key value for concept: " + dimensionConcept);
                }
            } else {
                KeyValue kv = new KeyValueImpl(conceptValue, dimensionConcept);
                key.add(kv);
            }
        }

        if (unknownConcepts.size() > 0) {
            StringBuilder sb = new StringBuilder();
            String concat = "";
            for (KeyValue kv : key) {
                sb.append(concat + kv.getCode());
                concat = ", ";
            }
            concat = "";
            String series = sb.toString();
            sb = new StringBuilder();
            for (String unknownconcept : unknownConcepts) {
                sb.append(concat + unknownconcept);
                concat = ", ";
            }
            throw new SdmxSemmanticException("Unknown concept(s) '" + sb.toString() + "' reported for series : " + series);
        }

        List<KeyValue> attributes = new ArrayList<KeyValue>();
        try {
            processAttributes(seriesAttributes, attributes);
        } catch (SdmxException e) {
            throw new SdmxException(e, "Error while procesing series attributes");
        }


        //Clear values
        keyValues.clear();
        attributeValues.clear();

        if (isTimeSeries()) {
            if (datasetPosition == DATASET_POSITION.SERIES) {
                try {
                    while (runAheadParser.hasNext()) {
                        int event = runAheadParser.next();
                        if (event == XMLStreamConstants.START_ELEMENT) {
                            if (runAheadParser.getLocalName().equals("Obs")) {
                                processObservation(runAheadParser);
                                timeFormat = DateUtil.getTimeFormatOfDate(obsTime);
                                break;
                            }
                        } else if (event == XMLStreamConstants.END_ELEMENT) {
                            if (runAheadParser.getLocalName().equals("Series")) {
                                break;
                            }
                        }
                    }
                } catch (XMLStreamException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
        if (isTimeSeries()) {
            currentKey = new KeyableImpl(currentDataflow, currentDsd, key, attributes, timeFormat);
        } else {
            currentKey = new KeyableImpl(currentDataflow, currentDsd, key, attributes, timeFormat, getCrossSectionConcept(), timeValue);
        }
        if (datasetPosition == DATASET_POSITION.OBSERAVTION_AS_SERIES) {
            currentObs = processObsNode(parser);
            timeFormat = currentObs.getObsTimeFormat();
        }

        attributeValues.clear();
        return currentKey;
    }