diff --git a/src/main/java/org/auscope/portal/core/services/CSWCacheService.java b/src/main/java/org/auscope/portal/core/services/CSWCacheService.java index 96acbab43..22cce134e 100644 --- a/src/main/java/org/auscope/portal/core/services/CSWCacheService.java +++ b/src/main/java/org/auscope/portal/core/services/CSWCacheService.java @@ -25,6 +25,7 @@ import org.auscope.portal.core.services.responses.csw.CSWOnlineResourceImpl; import org.auscope.portal.core.services.responses.csw.CSWRecord; import org.auscope.portal.core.services.responses.csw.CSWRecordTransformerFactory; +import org.auscope.portal.core.services.responses.csw.CSWGeographicElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; @@ -531,7 +532,29 @@ private void mergeRecords(CSWServiceItem cswService, CSWRecord destination, CSWR targetSet.addAll(destination.getOnlineResources()); targetSet.addAll(source.getOnlineResources()); destination.setOnlineResources(new ArrayList(targetSet)); - + + // Merge CSWGeographicElements, only legitimate BBOX coords allowed + Set geoElemSet = new HashSet(); + for (CSWGeographicElement geo : destination.getCSWGeographicElements()) { + if (geo != null) { + if (!geo.hasMissingCoords()) { + geoElemSet.add(geo); + } + } + } + for (CSWGeographicElement geo : source.getCSWGeographicElements()) { + if (geo != null) { + if (!geo.hasMissingCoords()) { + geoElemSet.add(geo); + } + } + } + if (geoElemSet.size() > 0) { + CSWGeographicElement geoElemArr[] = new CSWGeographicElement[geoElemSet.size()]; + geoElemSet.toArray(geoElemArr); + destination.setCSWGeographicElements(geoElemArr); + } + // Merge constraints, accessConstraints and useLimitConstraints (no dupes) Set constraintSet = new HashSet<>(); constraintSet.addAll(Arrays.asList(destination.getConstraints())); diff --git a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicBoundingBox.java b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicBoundingBox.java index c3955496b..654077fcc 100644 --- a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicBoundingBox.java +++ b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicBoundingBox.java @@ -44,14 +44,18 @@ public class CSWGeographicBoundingBox implements Serializable, CSWGeographicElem // The GeoJsonPolyogn instance of the bounding box, used for indexing geometry in Elasticsearch. private GeoJsonPolygon boundingPolygon; + // True iff this was constructed with missing source coords and a global default had to be substituted + private boolean missingSourceCoords; + /** - * Instantiates a new cSW geographic bounding box. + * Instantiates a new CSW geographic bounding box. */ public CSWGeographicBoundingBox() { + this.missingSourceCoords = false; } /** - * Instantiates a new cSW geographic bounding box. + * Instantiates a new CSW geographic bounding box. * * @param westBoundLongitude * the west bound longitude @@ -65,12 +69,23 @@ public CSWGeographicBoundingBox() { public CSWGeographicBoundingBox(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude) { + this.missingSourceCoords = Double.isNaN(westBoundLongitude) || Double.isNaN(eastBoundLongitude) || + Double.isNaN(southBoundLatitude) || Double.isNaN(northBoundLatitude); this.westBoundLongitude = Double.isNaN(westBoundLongitude) ? -180 : westBoundLongitude; this.eastBoundLongitude = Double.isNaN(eastBoundLongitude) ? 180 : eastBoundLongitude; this.southBoundLatitude = Double.isNaN(southBoundLatitude) ? -90 : southBoundLatitude; this.northBoundLatitude = Double.isNaN(northBoundLatitude) ? 90 : northBoundLatitude; } + /** + * Gets the missing source coordinates field + * + * @return true iff this was constructed with missing source coords and a global default had to be substituted + */ + public boolean hasMissingCoords() { + return missingSourceCoords; + } + /** * Gets the west bound longitude. * @@ -89,6 +104,7 @@ public double getWestBoundLongitude() { */ @Override public void setWestBoundLongitude(double westBoundLongitude) { + this.missingSourceCoords = this.missingSourceCoords || Double.isNaN(westBoundLongitude); this.westBoundLongitude = Double.isNaN(westBoundLongitude) ? -180 : westBoundLongitude; } @@ -110,6 +126,7 @@ public double getEastBoundLongitude() { */ @Override public void setEastBoundLongitude(double eastBoundLongitude) { + this.missingSourceCoords = this.missingSourceCoords || Double.isNaN(eastBoundLongitude); this.eastBoundLongitude = Double.isNaN(eastBoundLongitude) ? 180 : eastBoundLongitude; } @@ -131,6 +148,7 @@ public double getSouthBoundLatitude() { */ @Override public void setSouthBoundLatitude(double southBoundLatitude) { + this.missingSourceCoords = this.missingSourceCoords || Double.isNaN(southBoundLatitude); this.southBoundLatitude = Double.isNaN(southBoundLatitude) ? -90 : southBoundLatitude; } @@ -152,6 +170,7 @@ public double getNorthBoundLatitude() { */ @Override public void setNorthBoundLatitude(double northBoundLatitude) { + this.missingSourceCoords = this.missingSourceCoords || Double.isNaN(northBoundLatitude); this.northBoundLatitude = Double.isNaN(northBoundLatitude) ? 90 : northBoundLatitude; } diff --git a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicElement.java b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicElement.java index 74cd5e8aa..51b26e858 100644 --- a/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicElement.java +++ b/src/main/java/org/auscope/portal/core/services/responses/csw/CSWGeographicElement.java @@ -6,7 +6,7 @@ * An interface representing abstract geometry that can bound a record in a CSW response. */ public interface CSWGeographicElement { - + /** * Gets the west bound longitude. * @@ -91,4 +91,10 @@ public interface CSWGeographicElement { */ public void setBoundingPolygon(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude); + /** + * Gets the missing source coordinates field + * + * @return true iff this was constructed with missing source coords and a global default had to be substituted + */ + public boolean hasMissingCoords(); } diff --git a/src/main/java/org/auscope/portal/core/view/ViewCSWRecordFactory.java b/src/main/java/org/auscope/portal/core/view/ViewCSWRecordFactory.java index 34a4698fb..933f75e53 100644 --- a/src/main/java/org/auscope/portal/core/view/ViewCSWRecordFactory.java +++ b/src/main/java/org/auscope/portal/core/view/ViewCSWRecordFactory.java @@ -7,8 +7,6 @@ import java.util.Map; import java.util.TimeZone; -import javax.print.DocFlavor.STRING; - import org.auscope.portal.core.services.responses.csw.AbstractCSWOnlineResource; import org.auscope.portal.core.services.responses.csw.CSWGeographicBoundingBox; import org.auscope.portal.core.services.responses.csw.CSWGeographicElement;