/** * This method is called only the first time the {@link GWCConfig} is initialized and is used to * maintain backwards compatibility with the old GWC defaults. */ private void createDefaultTileLayerInfos(final GWCConfig defaultSettings) { checkArgument(defaultSettings.isSane()); for (LayerInfo layer : rawCatalog.getLayers()) { if (!CatalogConfiguration.isLayerExposable(layer)) { continue; } try { GeoServerTileLayerInfo tileLayerInfo; tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaultSettings); tileLayerCatalog.save(tileLayerInfo); MetadataMap metadata = layer.getMetadata(); if (metadata.containsKey(LegacyTileLayerInfoLoader.CONFIG_KEY_ENABLED)) { LegacyTileLayerInfoLoader.clear(metadata); rawCatalog.save(layer); } } catch (RuntimeException e) { LOGGER.log( Level.WARNING, "Error occurred saving default GWC Tile Layer settings for Layer '" + layer.getName() + "'", e); } } for (LayerGroupInfo layer : rawCatalog.getLayerGroups()) { try { GeoServerTileLayerInfo tileLayerInfo; tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaultSettings); tileLayerCatalog.save(tileLayerInfo); MetadataMap metadata = layer.getMetadata(); if (metadata.containsKey(LegacyTileLayerInfoLoader.CONFIG_KEY_ENABLED)) { LegacyTileLayerInfoLoader.clear(metadata); rawCatalog.save(layer); } } catch (RuntimeException e) { LOGGER.log( Level.WARNING, "Error occurred saving default GWC Tile Layer settings for LayerGroup '" + tileLayerName(layer) + "'", e); } } }
/** * Migrates the configuration of geoserver tile layers from the Layer/GroupInfo metadata maps to * the {@link #tileLayerCatalog} */ private void moveTileLayerInfosToTileLayerCatalog() { for (LayerInfo layer : rawCatalog.getLayers()) { if (!CatalogConfiguration.isLayerExposable(layer)) { continue; } try { GeoServerTileLayerInfo tileLayerInfo; tileLayerInfo = LegacyTileLayerInfoLoader.load(layer); if (tileLayerInfo != null) { tileLayerCatalog.save(tileLayerInfo); MetadataMap metadata = layer.getMetadata(); LegacyTileLayerInfoLoader.clear(metadata); rawCatalog.save(layer); } } catch (RuntimeException e) { LOGGER.log( Level.WARNING, "Error migrating GWC Tile Layer settings for Layer '" + layer.getName() + "'", e); } } for (LayerGroupInfo layer : rawCatalog.getLayerGroups()) { try { GeoServerTileLayerInfo tileLayerInfo; tileLayerInfo = LegacyTileLayerInfoLoader.load(layer); if (tileLayerInfo != null) { tileLayerCatalog.save(tileLayerInfo); MetadataMap metadata = layer.getMetadata(); LegacyTileLayerInfoLoader.clear(metadata); rawCatalog.save(layer); } } catch (RuntimeException e) { LOGGER.log( Level.WARNING, "Error occurred saving default GWC Tile Layer settings for LayerGroup '" + tileLayerName(layer) + "'", e); } } }
public static GeoServerTileLayerInfoImpl load(final LayerInfo layer) { MetadataMap metadataMap = layer.getMetadata(); if (!hasTileLayerDef(metadataMap)) { return null; } GeoServerTileLayerInfoImpl tileLayerInfo = load(metadataMap); if (metadataMap.containsKey(CONFIG_KEY_CACHED_STYLES)) { final String defaultStyle = layer.getDefaultStyle() == null ? "" : layer.getDefaultStyle().prefixedName(); String cachedStylesStr = metadataMap.get(CONFIG_KEY_CACHED_STYLES, String.class); Set<String> cachedStyles = unmarshalSet(cachedStylesStr); TileLayerInfoUtil.setCachedStyles(tileLayerInfo, defaultStyle, cachedStyles); } TileLayerInfoUtil.checkAutomaticStyles(layer, tileLayerInfo); tileLayerInfo.setName(tileLayerName(layer)); tileLayerInfo.setId(layer.getId()); return tileLayerInfo; }