Skip to content

Commit

Permalink
simplified optional
Browse files Browse the repository at this point in the history
  • Loading branch information
turingtestfail committed Aug 2, 2024
1 parent 829d679 commit e9c5255
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ private ReferencedEnvelope layersToBBBox(List<RawLayer> layers, ProjType projTyp
layer.isLayerGroup()
? ((LayerGroupInfo) layer.getPublishedInfo()).getBounds()
: ((LayerInfo) layer.getPublishedInfo())
.getResource()
.boundingBox();
.getResource()
.boundingBox();
if (i == 0) {
bbbox =
layerBbbox.transform(
Expand Down Expand Up @@ -592,8 +592,8 @@ private MapMLLayerMetadata layerToMapMLLayerMetadata(RawLayer layer, String styl
tileLayerExists =
gwc.hasTileLayer(isLayerGroup ? layerGroupInfo : layerInfo)
&& gwc.getTileLayer(isLayerGroup ? layerGroupInfo : layerInfo)
.getGridSubset(projType.value())
!= null;
.getGridSubset(projType.value())
!= null;
boolean useTiles = Boolean.TRUE.equals(layerMeta.get(MAPML_USE_TILES, Boolean.class));
boolean useFeatures = useFeatures(layer, layerMeta);

Expand Down Expand Up @@ -1037,16 +1037,16 @@ private List<Extent> prepareExtents() throws IOException {
extentZoomInput.setMin(
scaleDenominators != null
? String.valueOf(
tiledCRS.getMinZoomForDenominator(
scaleDenominators.getMaxValue().intValue()))
tiledCRS.getMinZoomForDenominator(
scaleDenominators.getMaxValue().intValue()))
: "0");
int mxz = PREVIEW_TCRS_MAP.get(projType.value()).getScales().length - 1;
// passing in min sld denominator to get max zoom
String maxZoom =
scaleDenominators != null
? String.valueOf(
tiledCRS.getMaxZoomForDenominator(
scaleDenominators.getMinValue().intValue()))
tiledCRS.getMaxZoomForDenominator(
scaleDenominators.getMinValue().intValue()))
: String.valueOf(mxz);
extentZoomInput.setMax(maxZoom);
extentList.add(extentZoomInput);
Expand Down Expand Up @@ -1706,17 +1706,17 @@ public String getMapMLHTMLDocument() {
if (mapMLLayerMetadata.isLayerGroup()) {
layerLabel +=
getLabel(
mapMLLayerMetadata.getLayerGroupInfo(),
mapMLLayerMetadata.getLayerName(),
request)
mapMLLayerMetadata.getLayerGroupInfo(),
mapMLLayerMetadata.getLayerName(),
request)
+ ",";

} else {
layerLabel +=
getLabel(
mapMLLayerMetadata.getLayerInfo(),
mapMLLayerMetadata.getLayerName(),
request)
mapMLLayerMetadata.getLayerInfo(),
mapMLLayerMetadata.getLayerName(),
request)
+ ",";
}
}
Expand Down Expand Up @@ -1776,7 +1776,7 @@ private List<SimpleFeatureType> getFeatureTypes() {
&& mapLayerInfo.getFeature() != null
&& mapLayerInfo.getFeature().getFeatureType() != null
&& mapLayerInfo.getFeature().getFeatureType()
instanceof SimpleFeatureType) {
instanceof SimpleFeatureType) {
featureTypes.add(
(SimpleFeatureType) mapLayerInfo.getFeature().getFeatureType());
} else if (mapLayerInfo.getType() == MapLayerInfo.TYPE_RASTER) {
Expand Down Expand Up @@ -1964,9 +1964,9 @@ private String serviceLink(List arguments) {
arguments.get(2) != null
? getParametersFromQuery(arguments.get(2).toString())
: request.getKvp().entrySet().stream()
.collect(
Collectors.toMap(
Map.Entry::getKey, e -> e.getValue().toString()));
.collect(
Collectors.toMap(
Map.Entry::getKey, e -> e.getValue().toString()));

return ResponseUtils.buildURL(baseURL, request.getPath(), kvp, URLMangler.URLType.SERVICE);
}
Expand Down Expand Up @@ -1997,8 +1997,8 @@ private Map<String, Object> getMapRequestElementsToModel(
URLEncoder.encode(p.getKey(), StandardCharsets.UTF_8)
+ "="
+ URLEncoder.encode(
p.getValue().toString(),
StandardCharsets.UTF_8))
p.getValue().toString(),
StandardCharsets.UTF_8))
.reduce((p1, p2) -> p1 + "&" + p2)
.orElse("");
String path = request.getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.text.StringEscapeUtils;
import org.geoserver.mapml.xml.BodyContent;
import org.geoserver.mapml.xml.Coordinates;
import org.geoserver.mapml.xml.Feature;
import org.geoserver.mapml.xml.GeometryContent;
Expand Down Expand Up @@ -254,60 +255,29 @@ private String[] formatCoordStrings(String xy) {

private static Optional<Map<String, String>> getTemplateAttributes(
Optional<Mapml> templateOptional) {
if (templateOptional.isPresent()) {
if (templateOptional.get().getBody() != null
&& templateOptional.get().getBody().getFeatures() != null
&& templateOptional.get().getBody().getFeatures().size() > 0
&& templateOptional.get().getBody().getFeatures().get(0).getProperties() != null
&& templateOptional
.get()
.getBody()
.getFeatures()
.get(0)
.getProperties()
.getOtherAttributes()
!= null
&& !templateOptional
.get()
.getBody()
.getFeatures()
.get(0)
.getProperties()
.getOtherAttributes()
.isEmpty()
&& templateOptional // there needs to be an even number of values because they
// are actually key value pairs
.get()
.getBody()
.getFeatures()
.get(0)
.getProperties()
.getOtherAttributes()
.values()
.size()
% 2
== 0) {
List<String> values =
new ArrayList<>(
templateOptional
.get()
.getBody()
.getFeatures()
.get(0)
.getProperties()
.getOtherAttributes()
.values());
Map<String, String> attributePairs =
IntStream.range(0, values.size() / 2)
.boxed()
.collect(
Collectors.toMap(
i -> values.get(i * 2),
i -> values.get(i * 2 + 1)));
return Optional.of(attributePairs);
}
}
return Optional.empty();

return templateOptional
.map(Mapml::getBody)
.map(BodyContent::getFeatures)
.filter(features -> features != null && !features.isEmpty())
.map(features -> features.get(0))
.map(Feature::getProperties)
.map(PropertyContent::getOtherAttributes)
.filter(
attributes ->
attributes != null
&& !attributes.isEmpty()
&& attributes.values().size() % 2 == 0)
.map(
attributes -> {
List<String> values = new ArrayList<>(attributes.values());
return IntStream.range(0, values.size() / 2)
.boxed()
.collect(
Collectors.toMap(
i -> values.get(i * 2),
i -> values.get(i * 2 + 1)));
});
}

/** Collects the attributes representation as a HTML table */
Expand Down

0 comments on commit e9c5255

Please sign in to comment.