Skip to content

Commit

Permalink
Have OGC API features build fully and pass QA
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime authored and jodygarnett committed Nov 4, 2024
1 parent ce448e4 commit ef583aa
Show file tree
Hide file tree
Showing 37 changed files with 91 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public FeatureReader<SimpleFeatureType, SimpleFeature> getFeatureReader(
DGGSFeatureSource source = getFeatureSource(query.getTypeName());
@SuppressWarnings("PMD.CloseResource") // wrapped and returned
SimpleFeatureIterator features = source.getFeatures(query).features();
return new FeatureReader<SimpleFeatureType, SimpleFeature>() {
return new FeatureReader<>() {
@Override
public SimpleFeatureType getFeatureType() {
return source.getSchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public void accepts(FeatureVisitor visitor, ProgressListener progress) throws IO
if (visit((MatrixAggregate) visitor)) return;
} else if (visitor instanceof GroupedMatrixAggregate) {
if (visit((GroupedMatrixAggregate) visitor)) return;
} else {
delegate.accepts(visitor, progress);
}
delegate.accepts(visitor, progress);
}

private boolean visit(MatrixAggregate visitor) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum DatelineLocation {
West,
/** Crossing the dateline, majority of points in the east empisphere */
East
};
}

/**
* Wraps a dateline crossing polygon so that its longitudes are all packed on one side. Will not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public H3Zone getZone(double lat, double lon, int resolution) {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> zonesFromEnvelope(
Envelope envelope, int targetResolution, boolean compact) {
Envelope intersection = envelope.intersection(WORLD);
Expand Down Expand Up @@ -287,6 +288,7 @@ public List<AttributeDescriptor> getExtraProperties() {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> neighbors(String id, int radius) {
// Using H3 facilities. Upside fast and accurate (considering dateline and pole neighbors
// too), downside, will quickly go OOM, radius should be limited
Expand Down Expand Up @@ -324,6 +326,7 @@ public Zone point(Point point, int resolution) {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> polygon(Polygon polygon, int resolution, boolean compact) {
List<GeoCoord> shell = getGeoCoords(polygon.getExteriorRing());
List<List<GeoCoord>> holes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private String toZoneId(List<Object> idList) {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> zonesFromEnvelope(
Envelope envelope, int targetResolution, boolean compact) {
// WAY USING DIRECT LIBRARY CALLS. Faster, but memory bound.
Expand Down Expand Up @@ -374,6 +375,7 @@ public List<AttributeDescriptor> getExtraProperties() {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> neighbors(String id, int radius) {
Set<String> result = new HashSet<>();
// temporary add to work as an exclusion mask too
Expand Down Expand Up @@ -417,6 +419,7 @@ public Iterator<Zone> neighbors(String id, int radius) {
}

@Override
@SuppressWarnings("PMD.UnnecessaryCast")
public Iterator<Zone> children(String zoneId, int resolution) {
Zone parent = getZone(zoneId);
if (parent.getResolution() >= resolution) return new EmptyIterator<>();
Expand Down Expand Up @@ -480,7 +483,7 @@ public Iterator<Zone> polygon(Polygon polygon, int resolution, boolean compact)
&& testContains(prepared, zone.getCenter()))
|| testContains(prepared, zone.getBoundary());
},
zone -> (Zone) zone);
zone -> zone);
// if compact iteration, we are done
if (compact) return compactIterator;
// otherwise expand the cells that are at a lower resolution using the fast children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public List<Link> getLinks() {
}

@JacksonXmlProperty(localName = "Collection")
@SuppressWarnings({"PMD.CloseResource", "PMD.EmptyWhileStmt"})
@SuppressWarnings({"PMD.CloseResource", "PMD.EmptyControlStatement"})
public Iterator<CollectionDocument> getCollections() {
CloseableIterator<FeatureTypeInfo> featureTypes =
geoServer.getCatalog().list(FeatureTypeInfo.class, Filter.INCLUDE);
return new Iterator<CollectionDocument>() {
return new Iterator<>() {

CollectionDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ public SimpleFeatureCollection areaSpaceAggregation(
q.getHints().put(VIRTUAL_TABLE_PARAMETERS, singletonMap(VP_RESOLUTION, resolution));
SimpleFeatureSource fs = (SimpleFeatureSource) ft.getFeatureSource(null, null);
List<Expression> expressions =
Arrays.stream(variables)
.map(v -> (Expression) FF.property(v))
.collect(Collectors.toList());
Arrays.stream(variables).map(v -> FF.property(v)).collect(Collectors.toList());
// run a full aggregate and build the feature
List<Expression> timeGroupExpressions = getTimeGroup(ft);
GroupedMatrixAggregate aggregate =
Expand Down Expand Up @@ -283,9 +281,7 @@ public SimpleFeatureCollection areaTimeAggregation(
q.getHints().put(VIRTUAL_TABLE_PARAMETERS, singletonMap(VP_RESOLUTION, resolution));
SimpleFeatureSource fs = (SimpleFeatureSource) ft.getFeatureSource(null, null);
List<Expression> expressions =
Arrays.stream(variables)
.map(v -> (Expression) FF.property(v))
.collect(Collectors.toList());
Arrays.stream(variables).map(v -> FF.property(v)).collect(Collectors.toList());
// run a full aggregate and build the feature
GroupedMatrixAggregate aggregate =
new GroupedMatrixAggregate(
Expand Down Expand Up @@ -360,9 +356,7 @@ public SimpleFeatureCollection areaSpaceTimeAggregation(
q.getHints().put(VIRTUAL_TABLE_PARAMETERS, singletonMap(VP_RESOLUTION, resolution));
SimpleFeatureSource fs = (SimpleFeatureSource) ft.getFeatureSource(null, null);
List<Expression> expressions =
Arrays.stream(variables)
.map(v -> (Expression) FF.property(v))
.collect(Collectors.toList());
Arrays.stream(variables).map(v -> FF.property(v)).collect(Collectors.toList());
// run a full aggregate and build the feature
MatrixAggregate aggregate = new MatrixAggregate(expressions, Arrays.asList(functions));
fs.getFeatures(q).accepts(aggregate, null);
Expand Down Expand Up @@ -476,9 +470,7 @@ public SimpleFeatureCollection positionTimeAggregate(
q.getHints().put(VIRTUAL_TABLE_PARAMETERS, singletonMap(VP_RESOLUTION, resolution));
SimpleFeatureSource fs = (SimpleFeatureSource) ft.getFeatureSource(null, null);
List<Expression> expressions =
Arrays.stream(variables)
.map(v -> (Expression) FF.property(v))
.collect(Collectors.toList());
Arrays.stream(variables).map(v -> FF.property(v)).collect(Collectors.toList());
// run a full aggregate and build the feature
GroupedMatrixAggregate aggregate =
new GroupedMatrixAggregate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public boolean containsAll(Collection<?> o) {
@Override
public boolean isEmpty() {
try (CloseableIterator<GroupByResult> it = result.getIterator()) {
return features().hasNext();
return it.hasNext();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum Priority {
high,
medium,
low
};
}

public static class ChangedItem {
Priority priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static Filter toFilter(ReferencedEnvelope[] bboxes) {
return FF.bbox(FF.property(""), bboxes[0]);
} else if (bboxes instanceof ReferencedEnvelope[]) {
List<Filter> filters =
Stream.of((ReferencedEnvelope[]) bboxes)
Stream.of(bboxes)
.map(e -> FF.bbox(FF.property(""), e))
.collect(Collectors.toList());
return FF.or(filters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private void dispatchService(Request dr, HandlerMethod handler) {
public static APIService getApiServiceAnnotation(Class<?> clazz) {
APIService annotation = null;
while (annotation == null && clazz != null) {
annotation = (APIService) clazz.getAnnotation(APIService.class);
annotation = clazz.getAnnotation(APIService.class);
if (annotation == null) {
clazz = clazz.getSuperclass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static Schema<?> getSchema(Class<?> binding) {
}

private static Schema<?> getGeometrySchema(Class<?> binding) {
Schema schema = new Schema();
Schema schema = new Schema<>();
String ref;
String description;
if (Point.class.isAssignableFrom(binding)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@RequestMapping(path = APIDispatcher.ROOT_PATH + "/hello/v1")
public class HelloController {

static interface HelloServiceInfo extends ServiceInfo {};
static interface HelloServiceInfo extends ServiceInfo {}

String defaultValue = "hello";

Expand All @@ -51,13 +51,13 @@ public Message hello(@RequestParam(name = "message", required = false) String me
public ResponseEntity echo(@RequestBody Message message) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
return new ResponseEntity<String>(message.getMessage(), headers, HttpStatus.CREATED);
return new ResponseEntity<>(message.getMessage(), headers, HttpStatus.CREATED);
}

@DeleteMapping(path = "delete")
@ResponseBody
public ResponseEntity<String> delete() {
return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@PutMapping(path = "default")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<Link> getLinks() {
public Iterator<CollectionDocument> getCollections() {
CloseableIterator<CoverageInfo> coverages =
geoServer.getCatalog().list(CoverageInfo.class, Filter.INCLUDE);
return new Iterator<CollectionDocument>() {
return new Iterator<>() {

CollectionDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<Link> getLinks() {
public Iterator<CollectionDocument> getCollections() {
CloseableIterator<FeatureTypeInfo> featureTypes =
geoServer.getCatalog().list(FeatureTypeInfo.class, Filter.INCLUDE);
return new Iterator<CollectionDocument>() {
return new Iterator<>() {

CollectionDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public OpenAPI build(WFSInfo wfs) throws IOException {

// list of valid filter-lang values
Parameter filterLang = parameters.get("filter-lang");
filterLang.getSchema().setEnum(new ArrayList(APIFilterParser.SUPPORTED_ENCODINGS));
filterLang.getSchema().setEnum(new ArrayList<>(APIFilterParser.SUPPORTED_ENCODINGS));

// provide actual values for limit
Parameter limit = parameters.get("limit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ protected void addLinks(
protected FeatureTypeInfo getFeatureType(GetFeatureRequest request) {
// OGC API Features always have a collection reference, so one query
return Optional.ofNullable(request.getQueries())
.filter(qs -> qs.size() > 0)
.filter(qs -> !qs.isEmpty())
.map(qs -> qs.get(0))
.map(q -> q.getTypeNames())
.filter(tns -> tns.size() > 0)
.filter(tns -> !tns.isEmpty())
.map(tns -> tns.get(0))
.map(tn -> new NameImpl(tn.getNamespaceURI(), tn.getLocalPart()))
.map(tn -> gs.getCatalog().getFeatureTypeByName(tn))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Iterator<ImagesCollectionDocument> getCollections() {
boolean skipInvalid =
gs.getGlobal().getResourceErrorHandling()
== ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS;
return new Iterator<ImagesCollectionDocument>() {
return new Iterator<>() {

ImagesCollectionDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ public ResponseEntity deleteImage(

imageListeners.imageRemoved(info, feature);

return new ResponseEntity(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Iterator<CollectionDocument> getCollections() {
@SuppressWarnings("PMD.CloseResource") // wrapped and returned
CloseableIterator<PublishedInfo> publisheds =
geoServer.getCatalog().list(PublishedInfo.class, Filter.INCLUDE);
return new Iterator<CollectionDocument>() {
return new Iterator<>() {

CollectionDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
package org.geoserver.ogcapi.v1.maps;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import com.jayway.jsonpath.DocumentContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.nodes.DataNode;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
Expand Down Expand Up @@ -47,8 +44,7 @@ public void testDatetimeHTMLMapsFormat() throws Exception {
Document document =
getAsJSoup(
"ogc/maps/v1/collections/sf:TimeWithStartEnd/styles/Default/map?f=html&datetime=2012-02-12T00:00:00Z");
boolean found = searchParameter(document, "\"datetime\": '2012-02-12T00:00:00Z'");
assertTrue(found);
assertEquals("2012-02-12T00:00:00Z", getParameterValue(document, "datetime"));
}

@Test
Expand All @@ -57,27 +53,15 @@ public void testHTMLNoDatetime() throws Exception {
// failed here when no datetime provided, FTL processing error, null on js_string
Document document =
getAsJSoup("ogc/maps/v1/collections/sf:TimeWithStartEnd/styles/Default/map?f=html");
boolean found = searchParameter(document, "\"datetime\": '2012-02-12T00:00:00Z'");
assertFalse(found);
assertNull(getParameterValue(document, "datetime"));
}

private static boolean searchParameter(Document document, String keyValue) {
Elements scriptsOnPage = document.select("script");
Matcher matcher = null;
// check that the datetime is in the javascript parameters
String keyToFind = "datetime";
Pattern pattern = Pattern.compile("\"" + keyToFind + "\":\\s*'(.*?)'");
boolean found = false;
for (Element element : scriptsOnPage) {
for (DataNode node : element.dataNodes()) {
matcher = pattern.matcher(node.getWholeData());
while (matcher.find()) {
if (matcher.group().equals(keyValue)) {
found = true;
}
}
}
}
return found;
private static String getParameterValue(Document document, String key) {
Elements parameters = document.select("input[type='hidden'][title='" + key + "']");
if (parameters.isEmpty()) return null;
if (parameters.size() > 1)
fail("Found more than one element with key " + key + ": " + parameters);
Element parameter = parameters.first();
return parameter.attr("value");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ public void visit(TextSymbolizer text) {
}
}

if (text instanceof TextSymbolizer) {
if (((TextSymbolizer) text).getGraphic() != null)
((TextSymbolizer) text).getGraphic().accept(this);
}
if (text.getGraphic() != null) text.getGraphic().accept(this);

if (text.getFill() != null) {
text.getFill().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enum LayerType {
polygon,
geometry,
raster
};
}

String id;
LayerType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public StylesDocument(Catalog catalog) {
public Iterator<StyleDocument> getStyles() {
// full scan (we might add paging/filtering later)
CloseableIterator<StyleInfo> styles = catalog.list(StyleInfo.class, Filter.INCLUDE);
return new Iterator<StyleDocument>() {
return new Iterator<>() {

StyleDocument next;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public ResponseEntity postStyle(
// validation
if (validate == only || validate == yes) {
validate(mimeType, content, handler);
return new ResponseEntity(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
String styleId = getStyleId(mimeType, handler, content);
StyleInfo styleInfo = getStyleInfo(styleId, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,6 @@ public boolean canGenerateThumbnail(StyleInfo styleInfo) {
LOGGER.log(Level.FINER, "Could not setup thumbnail", e);
}
// if we have at least a layer, we can work it
return request.getLayers().size() > 0;
return !request.getLayers().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Iterator<TiledCollectionDocument> getCollections() {
boolean skipInvalid =
gs.getGlobal().getResourceErrorHandling()
== ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS;
return new Iterator<TiledCollectionDocument>() {
return new Iterator<>() {

TiledCollectionDocument next;

Expand Down
Loading

0 comments on commit ef583aa

Please sign in to comment.