Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openaire fix for multiple productionPlaces #11194

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/sphinx-guides/source/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ v6.6

- **/api/metadatablocks** is no longer returning duplicated metadata properties and does not omit metadata properties when called.
- **/api/roles**: :ref:`show-role` now properly returns 403 Forbidden instead of 401 Unauthorized when you pass a working API token that doesn't have the right permission.
- openaire implementation can now correctly process one or multiple productionPlaces as geolocation.

v6.5
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,16 @@ private static void writeDescriptionElement(XMLStreamWriter xmlw, String descrip
*/
public static void writeGeoLocationsElement(XMLStreamWriter xmlw, DatasetVersionDTO datasetVersionDTO, String language) throws XMLStreamException {
// geoLocation -> geoLocationPlace
String geoLocationPlace = dto2Primitive(datasetVersionDTO, DatasetFieldConstant.productionPlace);
List<String> geoLocationPlaces = dto2MultiplePrimitive(datasetVersionDTO, DatasetFieldConstant.productionPlace);
boolean geoLocations_check = false;

// write geoLocations
geoLocations_check = writeOpenTag(xmlw, "geoLocations", geoLocations_check);
writeGeolocationPlace(xmlw, geoLocationPlace, language);
if (geoLocationPlaces != null) {
for (String geoLocationPlace : geoLocationPlaces) {
writeGeolocationPlace(xmlw, geoLocationPlace, language);
}
}

// get DatasetFieldConstant.geographicBoundingBox
for (Map.Entry<String, MetadataBlockDTO> entry : datasetVersionDTO.getMetadataBlocks().entrySet()) {
Expand Down Expand Up @@ -1457,6 +1461,26 @@ private static String dto2Primitive(DatasetVersionDTO datasetVersionDTO, String
}
return null;
}

/**
*
* @param datasetVersionDTO
* @param datasetFieldTypeName
* @return List<String> Multiple Primitive
*
*/
private static List<String> dto2MultiplePrimitive(DatasetVersionDTO datasetVersionDTO, String datasetFieldTypeName) {
// give the single value of the given metadata
for (Map.Entry<String, MetadataBlockDTO> entry : datasetVersionDTO.getMetadataBlocks().entrySet()) {
MetadataBlockDTO value = entry.getValue();
for (FieldDTO fieldDTO : value.getFields()) {
if (datasetFieldTypeName.equals(fieldDTO.getTypeName())) {
return fieldDTO.getMultiplePrimitive();
}
}
}
return null;
}

/**
* Write a full tag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,54 @@ public void testWriteDescriptionsElement() throws XMLStreamException, IOExceptio
stringWriter.toString());
}

/**
* Test: 18, GeoLocation (with point, box and polygon sub-properties) (R)
*
* description
*
* @throws javax.xml.stream.XMLStreamException
* @throws java.io.IOException
*/
@Test
public void testWriteGeoLocationsElement() throws XMLStreamException, IOException {
// given
DatasetDTO datasetDto = mapObjectFromJsonTestFile("export/dataset-all-defaults-multiple-geo.txt", DatasetDTO.class);
DatasetVersionDTO dto = datasetDto.getDatasetVersion();

// when
OpenAireExportUtil.writeGeoLocationsElement(xmlWriter, dto, null);
xmlWriter.flush();

//then
assertEquals("<geoLocations>"
+ "<geoLocation>"
+ "<geoLocationPlace>University of Stuttgart"
+ "</geoLocationPlace>"
+ "</geoLocation>"
+ "<geoLocation>"
+ "<geoLocationPlace>University of Vienna"
+ "</geoLocationPlace>"
+ "</geoLocation>"
+ "<geoLocation>"
+ "<geoLocationBox>"
+ "<westBoundLongitude>10</westBoundLongitude>"
+ "<eastBoundLongitude>20</eastBoundLongitude>"
+ "<southBoundLatitude>40</southBoundLatitude>"
+ "<northBoundLatitude>30</northBoundLatitude>"
+ "</geoLocationBox>"
+ "</geoLocation>"
+ "<geoLocation>"
+ "<geoLocationBox>"
+ "<eastBoundLongitude>60</eastBoundLongitude>"
+ "<southBoundLatitude>80</southBoundLatitude>"
+ "<northBoundLatitude>70</northBoundLatitude>"
+ "<westBoundLongitude>50</westBoundLongitude>"
+ "</geoLocationBox>"
+ "</geoLocation>"
+ "</geoLocations>",
stringWriter.toString());
}

/**
* Test: 18, GeoLocation (with point, box and polygon sub-properties) (R)
*
Expand All @@ -921,11 +969,13 @@ public void testWriteGeoLocationElement() throws XMLStreamException, IOException
// when
OpenAireExportUtil.writeGeoLocationsElement(xmlWriter, dto, null);
xmlWriter.flush();

//then
assertEquals("<geoLocations>"
+ "<geoLocation>"
+ "<geoLocationPlace>ProductionPlace</geoLocationPlace></geoLocation>"
+ "<geoLocationPlace>University of Stuttgart"
+ "</geoLocationPlace>"
+ "</geoLocation>"
+ "<geoLocation>"
+ "<geoLocationBox>"
+ "<westBoundLongitude>10</westBoundLongitude>"
Expand All @@ -941,7 +991,8 @@ public void testWriteGeoLocationElement() throws XMLStreamException, IOException
+ "<northBoundLatitude>70</northBoundLatitude>"
+ "<westBoundLongitude>50</westBoundLongitude>"
+ "</geoLocationBox>"
+ "</geoLocation></geoLocations>",
+ "</geoLocation>"
+ "</geoLocations>",
stringWriter.toString());
}

Expand Down
Loading