From b8dddac819e508f956415a78c0cb817c5edf3f3d Mon Sep 17 00:00:00 2001 From: Leonid Andreev Date: Fri, 24 Mar 2023 11:53:52 -0400 Subject: [PATCH] rearranged the geographicCoverage fields, to maintain the order in the ddi schema #3648 --- .../dataverse/export/ddi/DdiExportUtil.java | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java b/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java index 3ddc87069c0..dae637457ee 100644 --- a/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java @@ -511,38 +511,35 @@ private static void writeSummaryDescriptionElement(XMLStreamWriter xmlw, Dataset if (geographicCoverageDTO != null) { + List nationList = new ArrayList<>(); + List geogCoverList = new ArrayList<>(); + for (HashSet foo : geographicCoverageDTO.getMultipleCompound()) { - HashMap geoMap = new HashMap<>(); - // TODO: the order may still be wrong -L.A. (because of multiples) for (Iterator iterator = foo.iterator(); iterator.hasNext();) { FieldDTO next = iterator.next(); + /* our "country" field maps 1:1 to the DDI "": */ 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 "": */ + 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 "" entries, + * then all the "" ones: + */ + + for (String nationEntry : nationList) { + writeFullElement(xmlw, "nation", nationEntry); + } + for (String geogCoverEntry : geogCoverList) { + writeFullElement(xmlw, "geogCover", geogCoverEntry); } } @@ -550,11 +547,13 @@ private static void writeSummaryDescriptionElement(XMLStreamWriter xmlw, Dataset 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 foo : geographicBoundingBoxDTO.getMultipleCompound()) { xmlw.writeStartElement("geoBndBox"); HashMap geoBndBoxMap = new HashMap<>(); - for (Iterator iterator = foo.iterator(); iterator.hasNext();) { + /*for (*/Iterator iterator = foo.iterator(); + if (iterator.hasNext()) { FieldDTO next = iterator.next(); if (DatasetFieldConstant.westLongitude.equals(next.getTypeName())) { geoBndBoxMap.put("westBL", next.getSinglePrimitive()); @@ -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")); } @@ -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); }