Skip to content

Commit

Permalink
Merge pull request #472 from AuScope/AUS-4228
Browse files Browse the repository at this point in the history
AUS-4228 Fix WMS requesting tiles outside bounds
  • Loading branch information
stuartwoodman authored Aug 23, 2024
2 parents edc902e + 52f3686 commit aee4e60
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -531,7 +532,29 @@ private void mergeRecords(CSWServiceItem cswService, CSWRecord destination, CSWR
targetSet.addAll(destination.getOnlineResources());
targetSet.addAll(source.getOnlineResources());
destination.setOnlineResources(new ArrayList<AbstractCSWOnlineResource>(targetSet));


// Merge CSWGeographicElements, only legitimate BBOX coords allowed
Set<CSWGeographicElement> geoElemSet = new HashSet<CSWGeographicElement>();
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<String> constraintSet = new HashSet<>();
constraintSet.addAll(Arrays.asList(destination.getConstraints()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aee4e60

Please sign in to comment.