Skip to content

Commit

Permalink
Merge pull request #373 from groldan/improved_catalog_resolving
Browse files Browse the repository at this point in the history
Improved resolving of catalog property for CatalogInfo objects
  • Loading branch information
groldan authored Nov 18, 2023
2 parents 3c7b9b2 + 9782f0a commit 895f713
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ private void setDefaultStyle(LayerInfo layer, ResultSet rs) {
if (null != defaultStyle) {
String styleId = defaultStyle.getId();
defaultStyle = mapStyle(styleId, "defaultStyle", rs);
layer.setDefaultStyle(ModificationProxy.create(defaultStyle, StyleInfo.class));
if (null == defaultStyle) {
layer.setDefaultStyle(null);
} else {
layer.setDefaultStyle(ModificationProxy.create(defaultStyle, StyleInfo.class));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@
*/
public class InfoEventResolver {

private final Catalog rawCatalog;
private final GeoServer geoserverConfig;

private Function<Info, Info> configInfoResolver;
private Function<CatalogInfo, CatalogInfo> catalogInfoResolver;
// REVISIT: merge ProxyUtils with ResolvingProxyResolver
private ProxyUtils proxyUtils;

public InfoEventResolver(@NonNull Catalog rawCatalog, @NonNull GeoServer geoserverConfig) {
this.rawCatalog = rawCatalog;
this.geoserverConfig = geoserverConfig;

proxyUtils = new ProxyUtils(rawCatalog, Optional.of(geoserverConfig));

configInfoResolver =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.geoserver.catalog.plugin.resolving;

import lombok.NonNull;

import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogInfo;
import org.geoserver.catalog.Info;
Expand All @@ -13,12 +15,14 @@
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.catalog.StoreInfo;
import org.geoserver.catalog.StyleInfo;
import org.geoserver.catalog.WMSLayerInfo;
import org.geoserver.catalog.impl.LayerGroupStyle;
import org.geoserver.catalog.impl.ModificationProxy;
import org.geoserver.catalog.impl.StoreInfoImpl;
import org.geoserver.catalog.impl.StyleInfoImpl;
import org.geoserver.catalog.plugin.forwarding.ResolvingCatalogFacadeDecorator;

import java.util.Collection;
import java.util.Objects;
import java.util.function.UnaryOperator;

Expand All @@ -45,65 +49,62 @@ public static <I extends Info> CatalogPropertyResolver<I> of(Catalog catalog) {
}

public @Override T apply(T i) {
return resolve(i);
}

private <I> I resolve(I i) {
i = null == i ? null : ModificationProxy.unwrap(i);
if (i instanceof StoreInfo) setCatalog((StoreInfo) i);
else if (i instanceof ResourceInfo) setCatalog((ResourceInfo) i);
else if (i instanceof StyleInfo) setCatalog((StyleInfo) i);
else if (i instanceof PublishedInfo) setCatalog((PublishedInfo) i);
else if (i instanceof LayerGroupStyle) setCatalog((LayerGroupStyle) i);
return i;
}

private void setCatalog(PublishedInfo i) {
private void resolve(Collection<?> list) {
if (null != list) list.forEach(this::resolve);
}

private void setCatalog(@NonNull PublishedInfo i) {
if (i instanceof LayerInfo) setCatalog((LayerInfo) i);
else if (i instanceof LayerGroupInfo) setCatalog((LayerGroupInfo) i);
}

private void setCatalog(LayerInfo i) {
if (null == i) return;
ResourceInfo resource = i.getResource();
if (null != resource) {
if (null == resource.getCatalog()) {
setCatalog(resource);
}
StoreInfo store = resource.getStore();
if (null != store && null == store.getCatalog()) setCatalog(store);
}
setCatalog(i.getDefaultStyle());
if (i.getStyles() != null) i.getStyles().forEach(this::setCatalog);
private void setCatalog(@NonNull LayerInfo i) {
resolve(i.getResource());
resolve(i.getDefaultStyle());
resolve(i.getStyles());
}

private void setCatalog(LayerGroupInfo i) {
if (null == i) return;
if (i.getLayerGroupStyles() != null) i.getLayerGroupStyles().forEach(this::setCatalog);

if (i.getLayers() != null) i.getLayers().forEach(this::setCatalog);

setCatalog(i.getRootLayer());
setCatalog(i.getRootLayerStyle());
private void setCatalog(@NonNull LayerGroupInfo i) {
resolve(i.getRootLayer());
resolve(i.getRootLayerStyle());
resolve(i.getLayers());
resolve(i.getStyles());
resolve(i.getLayerGroupStyles());
}

private void setCatalog(LayerGroupStyle i) {
if (null == i) return;
private void setCatalog(@NonNull LayerGroupStyle i) {

// TODO: check if this would result in a stack overflow
// if(null!=i.getLayers())i.getLayers().forEach(this::setCatalog);
// if(null != i.getStyles())i.getStyles().forEach(this::setCatalog);
}

private void setCatalog(StoreInfo i) {
if (null == i) return;
i = ModificationProxy.unwrap(i);
private void setCatalog(@NonNull StoreInfo i) {
if (i instanceof StoreInfoImpl) ((StoreInfoImpl) i).setCatalog(catalog);
}

private void setCatalog(ResourceInfo i) {
if (null == i) return;
i = ModificationProxy.unwrap(i);
private void setCatalog(@NonNull ResourceInfo i) {
i.setCatalog(catalog);
resolve(i.getStore());
if (i instanceof WMSLayerInfo) {
resolve(((WMSLayerInfo) i).getAllAvailableRemoteStyles());
}
}

private void setCatalog(StyleInfo i) {
if (null == i) return;
i = ModificationProxy.unwrap(i);
private void setCatalog(@NonNull StyleInfo i) {
if (i instanceof StyleInfoImpl) ((StyleInfoImpl) i).setCatalog(catalog);
}
}

0 comments on commit 895f713

Please sign in to comment.