Beispiel #1
0
  /**
   * 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);
      }
    }
  }
Beispiel #2
0
  /**
   * 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 void testClear() {
    LayerGroupInfoImpl lg = mockGroup("tesGroup", mockLayer("L1"), mockLayer("L2"));

    assertNull(LegacyTileLayerInfoLoader.load(lg));
    GeoServerTileLayerInfo info = defaultVectorInfo;
    info.getMimeFormats().clear();
    info.getMimeFormats().addAll(defaults.getDefaultOtherCacheFormats());

    LegacyTileLayerInfoLoader.save(info, lg.getMetadata());

    GeoServerTileLayerInfo actual;
    actual = LegacyTileLayerInfoLoader.load(lg);
    assertNotNull(actual);

    LegacyTileLayerInfoLoader.clear(lg.getMetadata());
    assertNull(LegacyTileLayerInfoLoader.load(lg));
  }