in SdmxEdiParser/src/main/java/org/sdmxsource/sdmx/ediparser/engine/writer/impl/EDIDataWriterEngineImpl.java [436:546]
private void flushAttributeValue(String attributeId, String conceptValue) {
if (conceptValue == null) {
conceptValue = "";
}
startMessage();
if (currentPOS == POSITION.OBS) {
//Store the observation attribute that comes in the data segment, and exit the method
if (attributeId.equals(SDMX_EDI_ATTRIBUTES.OBS_STATUS)) {
currentObsStatus = conceptValue;
return;
} else if (attributeId.equals(obsConf)) {
currentObsConf = conceptValue;
return;
} else if (attributeId.equals(obsPreBreak)) {
if (conceptValue == null || conceptValue.equals(SdmxConstants.MISSING_DATA_VALUE)) {
currentObsPreBreak = EDI_CONSTANTS.MISSING_VAL;
} else {
currentObsPreBreak = conceptValue;
}
return;
}
}
hasAttributes = true;
hasFootnoteSection = true;
//If we have not exited the method, then store the attribute in the temp attribute writer.
//1. What is the attachment level
if ("TIME_FORMAT".equals(attributeId)) {
//Ignore this - The Time Format should not be output at the attribute level
//Time format is part of the ARR segment before the first observation, the time format code indicates if it is asingle observation
//a range, and it includes format.
return;
}
AttributeBean attribute = dsd.getAttribute(attributeId);
if (attribute == null) {
throw new SdmxException("Data Structure '" + dsd.getId() + "' does not contain an attribute with identifier: " + attributeId);
}
switch (attribute.getAttachmentLevel()) {
case DATA_SET:
if (currentPOS != POSITION.DATASET) {
throw new SdmxException("Can not write a dataset attribute '" + attributeId + "' when currently processing output for " + currentPOS);
}
break;
case DIMENSION_GROUP:
if (currentPOS != POSITION.SERIES) {
throw new SdmxException("Can not write a series attribute '" + attributeId + "' when currently processing output for " + currentPOS);
}
break;
case GROUP:
if (currentPOS != POSITION.GROUP) {
throw new SdmxException("Can not write a group attribute '" + attributeId + "' when currently processing output for " + currentPOS);
}
break;
case OBSERVATION:
if (currentPOS != POSITION.OBS) {
throw new SdmxException("Can not write a observation attribute '" + attributeId + "' when currently processing output for " + currentPOS);
}
break;
}
boolean isCoded = attribute.hasCodedRepresentation();
createSeriesKey();
String outputKey = currentSeriesKey;
int keyLength = dimensionIds.size();
if (attribute.getAttachmentLevel() == ATTRIBUTE_ATTACHMENT_LEVEL.DIMENSION_GROUP) {
outputKey = seriesAttributeKeyCreator.get(attribute).createSubKey();
} else if (attribute.getAttachmentLevel() == ATTRIBUTE_ATTACHMENT_LEVEL.DATA_SET) {
keyLength = 0;
outputKey = "";
} else if (currentPOS == POSITION.OBS) {
// Convert currentObsDate into EDI format
EDI_TIME_FORMAT ediTimeFormat = EDI_TIME_FORMAT.parseTimeFormat(timeFormat, false);
String ediObsTime = ediTimeFormat.formatDate(currentObsDate);
outputKey += EDI_CONSTANTS.COLON + ediObsTime + EDI_CONSTANTS.COLON + EDI_TIME_FORMAT.parseTimeFormat(timeFormat, false).getEdiValue();
keyLength += 2;
}
OutputStreamWriter osw = getAttributeWriter();
if (currentAttributeKey == null || !outputKey.equals(currentAttributeKey)) {
write(osw, EDIDataWriterUtil.parseAttributeAttachment(keyLength, outputKey));
writeLineSeparator(osw);
currentAttributeKey = outputKey;
}
boolean writeAttr;
if (currentDatasetHeader.getAction() == DATASET_ACTION.DELETE) {
// For delete messages, write blank attributes (they are being deleted!)
writeAttr = true;
} else {
// For all other message types, only write the attribute if it has a value
if (conceptValue.length() > 0) {
writeAttr = true;
} else {
writeAttr = false;
}
}
if (writeAttr) {
write(osw, EDIDataWriterUtil.parseAttributeIdentifier(attributeId, isCoded));
writeLineSeparator(osw);
List<String> values = EDIDataWriterUtil.parseAttributeValue(conceptValue, isCoded);
for (String val : values) {
write(osw, val);
writeLineSeparator(osw);
}
}
}