Skip to content

Commit

Permalink
Merge pull request #1054 from ZakarFin/make-featuresurl-optional
Browse files Browse the repository at this point in the history
Statslayer: Use layer url as default with an option to override it with attributes
  • Loading branch information
ZakarFin authored Mar 6, 2024
2 parents 52cac64 + 7e48284 commit 6ebd358
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public String getAttributes() {

public void setAttributes(String attributes) {
this.attributes = attributes;
// force getStatsJSON to recalculate
this.stats = null;
}

public JSONObject asJSON() {
Expand All @@ -71,7 +73,7 @@ public String getIdProperty() {
}

public String getFeaturesUrl() {
return getStatsJSON().optString("featuresUrl");
return getStatsJSON().optString("featuresUrl", getUrl());
}

private JSONObject getStatsJSON() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,33 @@ public void testGeoJSONResourceFileWorks() throws MismatchedDimensionException,
}
}

@Test
public void testFeaturesUrl() throws MismatchedDimensionException, FactoryException, TransformException, ServiceException, IOException, JSONException {
String endPoint = "https://my.domain";
String overridingEndPoint = endPoint + "/feat";
RegionSet kunnatJSON = new RegionSet();
kunnatJSON.setId(-1);
kunnatJSON.setUrl(endPoint);
kunnatJSON.setName("oskari:kunnat2013");
kunnatJSON.setSrs_name("EPSG:3067");
assertEquals("Should return url when attributes NOT defined", endPoint, kunnatJSON.getFeaturesUrl());

kunnatJSON.setAttributes(getAttributes("kuntakoodi", "kuntanimi", overridingEndPoint));
assertEquals("Should return features url when attributes ARE defined", overridingEndPoint, kunnatJSON.getFeaturesUrl());

overridingEndPoint = null;
kunnatJSON.setAttributes(getAttributes("kuntakoodi", "kuntanimi", overridingEndPoint));
assertEquals("Should return url when attributes ARE defined WITHOUT features url", endPoint, kunnatJSON.getFeaturesUrl());
}

private String getAttributes(String regionIdTag, String nameIdTag, String featuresUrl) throws JSONException {
JSONObject attributes = new JSONObject();
JSONObject statistics = new JSONObject();
statistics.put("regionIdTag", regionIdTag);
statistics.put("nameIdTag", nameIdTag);
statistics.put("featuresUrl", featuresUrl);
if (featuresUrl != null) {
statistics.put("featuresUrl", featuresUrl);
}
attributes.put("statistics", statistics);
return attributes.toString();
}
Expand Down

0 comments on commit 6ebd358

Please sign in to comment.