Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jan 24, 2019
1 parent 4bedc4c commit b089040
Showing 1 changed file with 26 additions and 22 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
Expand Down Expand Up @@ -66,6 +68,7 @@
import org.geoserver.wfs3.response.TilingSchemesDocument; import org.geoserver.wfs3.response.TilingSchemesDocument;
import org.geotools.styling.Style; import org.geotools.styling.Style;
import org.geotools.styling.StyledLayerDescriptor; import org.geotools.styling.StyledLayerDescriptor;
import org.geotools.util.logging.Logging;
import org.geowebcache.config.DefaultGridsets; import org.geowebcache.config.DefaultGridsets;
import org.opengis.filter.FilterFactory2; import org.opengis.filter.FilterFactory2;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
Expand All @@ -76,6 +79,7 @@


/** WFS 3.0 implementation */ /** WFS 3.0 implementation */
public class DefaultWebFeatureService30 implements WebFeatureService30, ApplicationContextAware { public class DefaultWebFeatureService30 implements WebFeatureService30, ApplicationContextAware {
private static final Logger LOGGER = Logging.getLogger(DefaultWebFeatureService30.class);


private final GeoServerDataDirectory dataDirectory; private final GeoServerDataDirectory dataDirectory;
private FilterFactory2 filterFactory; private FilterFactory2 filterFactory;
Expand Down Expand Up @@ -153,7 +157,7 @@ public FeatureCollectionResponse getFeature(org.geoserver.wfs3.GetFeatureType re
request.setStartIndex(BigInteger.ZERO); request.setStartIndex(BigInteger.ZERO);
} }


WFS3GetFeature gf = new WFS3GetFeature(getServiceInfo(), getCatalog()); WFS3GetFeature gf = new WFS3GetFeature(getService(), getCatalog());
gf.setFilterFactory(filterFactory); gf.setFilterFactory(filterFactory);
gf.setStoredQueryProvider(getStoredQueryProvider()); gf.setStoredQueryProvider(getStoredQueryProvider());
FeatureCollectionResponse response = gf.run(new GetFeatureRequest.WFS20(request)); FeatureCollectionResponse response = gf.run(new GetFeatureRequest.WFS20(request));
Expand Down Expand Up @@ -201,10 +205,6 @@ public OpenAPI api(APIRequest request) {
return new OpenAPIBuilder().build(request, getService(), extensions); return new OpenAPIBuilder().build(request, getService(), extensions);
} }


public WFSInfo getServiceInfo() {
return geoServer.getService(WFSInfo.class);
}

@Override @Override
public TilingSchemesDocument tilingSchemes(TilingSchemesRequest request) { public TilingSchemesDocument tilingSchemes(TilingSchemesRequest request) {
return new TilingSchemesDocument(gridSets); return new TilingSchemesDocument(gridSets);
Expand All @@ -213,7 +213,7 @@ public TilingSchemesDocument tilingSchemes(TilingSchemesRequest request) {
@Override @Override
public FeatureCollectionResponse getTile(org.geoserver.wfs3.GetFeatureType request) { public FeatureCollectionResponse getTile(org.geoserver.wfs3.GetFeatureType request) {


WFS3GetFeature gf = new WFS3GetFeature(getServiceInfo(), getCatalog()); WFS3GetFeature gf = new WFS3GetFeature(getService(), getCatalog());
gf.setFilterFactory(filterFactory); gf.setFilterFactory(filterFactory);
gf.setStoredQueryProvider(getStoredQueryProvider()); gf.setStoredQueryProvider(getStoredQueryProvider());
FeatureCollectionResponse response = gf.run(new GetFeatureRequest.WFS20(request)); FeatureCollectionResponse response = gf.run(new GetFeatureRequest.WFS20(request));
Expand Down Expand Up @@ -306,7 +306,7 @@ public void postStyles(
response.addHeader(HttpHeaders.LOCATION, url); response.addHeader(HttpHeaders.LOCATION, url);
} }


public String getStyleName(StyledLayerDescriptor sld) { private String getStyleName(StyledLayerDescriptor sld) {
String name = sld.getName(); String name = sld.getName();
if (name == null) { if (name == null) {
Style style = Styles.style(sld); Style style = Styles.style(sld);
Expand All @@ -322,36 +322,40 @@ public StylesDocument getStyles(GetStylesRequest request) throws IOException {
if (request.getLayerName() == null) { if (request.getLayerName() == null) {
// return only styles that are not associated to a layer, those will show up // return only styles that are not associated to a layer, those will show up
// in the layer association instead // in the layer association instead
final Set<StyleInfo> blacklist = getLayerAssociatedStyles(); final Set<StyleInfo> layerAssociatedStyles = getLayerAssociatedStyles();
addBuiltInStyles(blacklist); addBuiltInStyles(layerAssociatedStyles);
for (StyleInfo style : getCatalog().getStyles()) { for (StyleInfo style : getCatalog().getStyles()) {
if (blacklist.contains(style)) { if (layerAssociatedStyles.contains(style)) {
continue; continue;
} }
StyleDocument sd = buildStyleDocument(request, style); addStyleDocument(request, styles, style);

styles.add(sd);
} }
} else { } else {
final LayerInfo layer = getCatalog().getLayerByName(request.getLayerName()); final LayerInfo layer = getCatalog().getLayerByName(request.getLayerName());
if (layer.getDefaultStyle() != null) { if (layer.getDefaultStyle() != null) {
StyleDocument sd = buildStyleDocument(request, layer.getDefaultStyle()); addStyleDocument(request, styles, layer.getDefaultStyle());
styles.add(sd);
} }
if (layer.getStyles() != null) { if (layer.getStyles() != null) {
for (StyleInfo style : layer.getStyles()) { for (StyleInfo style : layer.getStyles()) {
if (style != null) { addStyleDocument(request, styles, style);
StyleDocument sd = buildStyleDocument(request, style);
styles.add(sd);
}
} }
} }
} }


return new StylesDocument(styles); return new StylesDocument(styles);
} }


public StyleDocument buildStyleDocument(GetStylesRequest request, StyleInfo style) { private void addStyleDocument(
GetStylesRequest request, List<StyleDocument> styles, StyleInfo style) {
try {
StyleDocument sd = buildStyleDocument(request, style);
styles.add(sd);
} catch (Exception e) {
LOGGER.log(Level.INFO, "Failed to process style " + style.getName(), e);
}
}

private StyleDocument buildStyleDocument(GetStylesRequest request, StyleInfo style) {
StyleDocument sd = StyleDocument.build(style); StyleDocument sd = StyleDocument.build(style);
String styleFormat = style.getFormat(); String styleFormat = style.getFormat();
if (styleFormat == null) { if (styleFormat == null) {
Expand All @@ -368,15 +372,15 @@ public StyleDocument buildStyleDocument(GetStylesRequest request, StyleInfo styl
return sd; return sd;
} }


public void addBuiltInStyles(Set<StyleInfo> blacklist) { private void addBuiltInStyles(Set<StyleInfo> blacklist) {
accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_POINT)); accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_POINT));
accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_LINE)); accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_LINE));
accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_POLYGON)); accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_POLYGON));
accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_GENERIC)); accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_GENERIC));
accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_RASTER)); accumulateStyle(blacklist, getCatalog().getStyleByName(StyleInfo.DEFAULT_RASTER));
} }


public Link buildLink(GetStylesRequest request, StyleDocument sd, String styleFormat) { private Link buildLink(GetStylesRequest request, StyleDocument sd, String styleFormat) {
String path; String path;
if (request.getLayerName() != null) { if (request.getLayerName() != null) {
FeatureTypeInfo featureType = getCatalog().getFeatureTypeByName(request.getLayerName()); FeatureTypeInfo featureType = getCatalog().getFeatureTypeByName(request.getLayerName());
Expand Down

0 comments on commit b089040

Please sign in to comment.