Skip to content

Commit

Permalink
rearranged the geographicCoverage fields, to maintain the order in th…
Browse files Browse the repository at this point in the history
…e ddi schema #3648
  • Loading branch information
landreev committed Mar 24, 2023
1 parent 1517b59 commit b8dddac
Showing 1 changed file with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,50 +511,49 @@ private static void writeSummaryDescriptionElement(XMLStreamWriter xmlw, Dataset

if (geographicCoverageDTO != null) {

List<String> nationList = new ArrayList<>();
List<String> geogCoverList = new ArrayList<>();

for (HashSet<FieldDTO> foo : geographicCoverageDTO.getMultipleCompound()) {
HashMap<String, String> geoMap = new HashMap<>();
// TODO: the order may still be wrong -L.A. (because of multiples)
for (Iterator<FieldDTO> iterator = foo.iterator(); iterator.hasNext();) {
FieldDTO next = iterator.next();
/* our "country" field maps 1:1 to the DDI "<nation>": */
if (DatasetFieldConstant.country.equals(next.getTypeName())) {
geoMap.put("country", next.getSinglePrimitive());
}
if (DatasetFieldConstant.city.equals(next.getTypeName())) {
geoMap.put("city", next.getSinglePrimitive());
nationList.add(next.getSinglePrimitive());
}
if (DatasetFieldConstant.state.equals(next.getTypeName())) {
geoMap.put("state", next.getSinglePrimitive());
/* city, state and otherGeographicCoverage all exported as "<geogCover>": */
if (DatasetFieldConstant.city.equals(next.getTypeName())
|| DatasetFieldConstant.state.equals(next.getTypeName())
|| DatasetFieldConstant.otherGeographicCoverage.equals(next.getTypeName())) {
geogCoverList.add(next.getSinglePrimitive());
}
if (DatasetFieldConstant.otherGeographicCoverage.equals(next.getTypeName())) {
geoMap.put("otherGeographicCoverage", next.getSinglePrimitive());
}
}

if (geoMap.get("country") != null) {
writeFullElement(xmlw, "nation", geoMap.get("country"));
}
if (geoMap.get("city") != null) {
writeFullElement(xmlw, "geogCover", geoMap.get("city"));
}
if (geoMap.get("state") != null) {
writeFullElement(xmlw, "geogCover", geoMap.get("state"));
}
if (geoMap.get("otherGeographicCoverage") != null) {
writeFullElement(xmlw, "geogCover", geoMap.get("otherGeographicCoverage"));
}
}

/**
* And now we can write all the fields encountered, first the "<nation>" entries,
* then all the "<geogCover>" ones:
*/

for (String nationEntry : nationList) {
writeFullElement(xmlw, "nation", nationEntry);
}
for (String geogCoverEntry : geogCoverList) {
writeFullElement(xmlw, "geogCover", geogCoverEntry);
}
}

/* TODO: if exists? - L.A. */
writeFullElementList(xmlw, "geogUnit", dto2PrimitiveList(datasetVersionDTO, DatasetFieldConstant.geographicUnit));

/* TODO: it really looks like only 1 geoBndBox is allowed in the DDI - ? */
/* So, I'm just going to arbitrarily use the first one, and ignore the rest! -L.A. */
if (geographicBoundingBoxDTO != null) {
for (HashSet<FieldDTO> foo : geographicBoundingBoxDTO.getMultipleCompound()) {
xmlw.writeStartElement("geoBndBox");
HashMap<String, String> geoBndBoxMap = new HashMap<>();
for (Iterator<FieldDTO> iterator = foo.iterator(); iterator.hasNext();) {
/*for (*/Iterator<FieldDTO> iterator = foo.iterator();
if (iterator.hasNext()) {
FieldDTO next = iterator.next();
if (DatasetFieldConstant.westLongitude.equals(next.getTypeName())) {
geoBndBoxMap.put("westBL", next.getSinglePrimitive());
Expand All @@ -570,6 +569,8 @@ private static void writeSummaryDescriptionElement(XMLStreamWriter xmlw, Dataset
}
}

/* Once again, order is important! */

if (geoBndBoxMap.get("westBL") != null) {
writeFullElement(xmlw, "westBL", geoBndBoxMap.get("westBL"));
}
Expand Down Expand Up @@ -599,7 +600,7 @@ private static void writeSummaryDescriptionElement(XMLStreamWriter xmlw, Dataset
}


/* finally, any "kind of data" entries we may have saved earlier: -L.A.*/
/* finally, any "kind of data" entries: */
if (kindOfDataDTO != null) {
writeMultipleElement(xmlw, "dataKind", kindOfDataDTO, lang);
}
Expand Down

0 comments on commit b8dddac

Please sign in to comment.