public void writeObservation()

in SdmxDataParser/src/main/java/org/sdmxsource/sdmx/dataparser/engine/writer/streaming/StreamGenericDataWriterEngine.java [342:449]


    public void writeObservation(String obsConceptId, String obsConceptValue, String obsValue, AnnotationBean... annotations) {
        if (DimensionBean.TIME_DIMENSION_FIXED_ID.equals(obsConceptId)) {
            if (schemaVersion == SDMX_SCHEMA.VERSION_TWO_POINT_ONE) {
                obsConceptValue = DateUtil.formatDateForSdmxVersion21(obsConceptValue);
            } else if (schemaVersion == SDMX_SCHEMA.VERSION_TWO) {
                obsConceptValue = DateUtil.formatDateForSdmxVersion2(obsConceptValue);
            } else if (schemaVersion == SDMX_SCHEMA.VERSION_ONE) {
                obsConceptValue = DateUtil.formatDateForSdmxVersion1(obsConceptValue);
            }
        }
        obsConceptId = getComponentId(obsConceptId);

        super.writeObservation(obsConceptId, obsConceptValue, obsValue, annotations);

        try {
            switch (currentPosition) {
                case OBSERVATION:
                    writeEndObs();
                    break;
                case OBSERVATION_ATTRIBUTE:
                    writer.writeEndElement(); //END ATTRIBUTES
                    writeEndObs();
                    break;
                case SERIES_KEY_ATTRIBUTE:
                    writer.writeEndElement(); //END ATTRIBUTES
                    break;
                case SERIES_KEY:
                    if (!isFlat) {
                        writer.writeEndElement(); //END SERIES KEY
                    }
                    break;
                case GROUP:
                    if (isTwoPointOne()) {
                        writer.writeEndElement(); //END GROUP
                    } else {
                        throw new SdmxSemmanticException("Attempting to write observation to group , an observation must belong to a series");
                    }
                    break;
                case GROUP_KEY:
                    if (isTwoPointOne()) {
                        writer.writeEndElement(); //END GROUP_KEY
                        writer.writeEndElement(); //END GROUP
                    } else {
                        throw new SdmxSemmanticException("Attempting to write observation to group , an observation must belong to a series");
                    }
                    break;
                case GROUP_KEY_ATTRIBUTE:
                    if (isTwoPointOne()) {
                        writer.writeEndElement(); //END GROUP_KEY_ATTRIBUTE
                        writer.writeEndElement(); //END GROUP
                    } else {
                        throw new SdmxSemmanticException("Attempting to write observation to group , an observation must belong to a series");
                    }
                    break;
                default:
                    if (!isTwoPointOne()) {
                        throw new IllegalArgumentException("An observation may only be written while inside a series");
                    }
            }
            currentPosition = POSITION.OBSERVATION;
            startElement(writer, GENERIC_NS, "Obs");  //WRITE THE OBS NODE

            if (isFlat) {
                componentVals.put(obsConceptId, obsConceptValue);
                writeAnnotations(writer, annotations);
                startElement(writer, GENERIC_NS, "ObsKey");
                for (String componentId : seriesKey) {
                    startElement(writer, GENERIC_NS, "Value");
                    writer.writeAttribute("id", componentId);
                    writer.writeAttribute("value", componentVals.get(componentId));
                    writer.writeEndElement(); //END Value
                }
                writer.writeEndElement(); //END ObsKey

            } else if (isTwoPointOne()) {
                writeAnnotations(writer, annotations);

                startElement(writer, GENERIC_NS, "ObsDimension");
                if (isCrossSectional) {
                    writer.writeAttribute("id", obsConceptId);
                }
                writer.writeAttribute("value", obsConceptValue);
                writer.writeEndElement(); //END ObsDimension
            } else {
                obsAnnotations = annotations;
                startElement(writer, GENERIC_NS, "Time");
                writer.writeCharacters(obsConceptValue);
                writer.writeEndElement(); //END Time
            }
            startElement(writer, GENERIC_NS, "ObsValue");
            if (ObjectUtil.validString(obsValue)) {
                writer.writeAttribute("value", obsValue);
            }
            writer.writeEndElement(); //END ObsValue
            if (isFlat) {
                // Write the Series Attributes as Observation Level Attributes
                // NOTE - we do not want to write the Series Keys here, so they need to be removed
                Map<String, String> componentValsClone = new LinkedHashMap<>(componentVals);
                seriesKey.forEach(componentValsClone.keySet()::remove);
                for (var entry : componentValsClone.entrySet()) {
                    writeAttributeValue(entry.getKey(), entry.getValue());
                }
            }
        } catch (XMLStreamException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }