public void testLoadLayerInfo() {
    LayerInfoImpl layer = mockLayer("testLayer");

    assertNull(LegacyTileLayerInfoLoader.load(layer));

    LegacyTileLayerInfoLoader.save(defaultVectorInfo, layer.getMetadata());

    GeoServerTileLayerInfo info2 = LegacyTileLayerInfoLoader.load(layer);

    defaultVectorInfo.setId(layer.getId());
    defaultVectorInfo.setName(tileLayerName(layer));
    assertEquals(defaultVectorInfo, info2);
  }
  public void testLoadLayerGroup() {
    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);

    info.setId(lg.getId());
    info.setName(GWC.tileLayerName(lg));
    assertEquals(info, actual);
  }
示例#3
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);
      }
    }
  }
示例#4
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);
      }
    }
  }
  /**
   * Creates a cached tile layer from the given Layer Group
   *
   * @param info the layer group to cache
   * @param defaults default configuration
   */
  public static GeoServerTileLayerInfoImpl loadOrCreate(
      final LayerGroupInfo groupInfo, final GWCConfig defaults) {

    GeoServerTileLayerInfoImpl info = LegacyTileLayerInfoLoader.load(groupInfo);
    if (info == null) {
      info = create(defaults);
      checkAutomaticStyles(groupInfo, info);
    }
    info.setName(tileLayerName(groupInfo));
    info.setId(groupInfo.getId());
    return info;
  }
  public void testLoadLayerInfoAutoCacheStyles() {
    GeoServerTileLayerInfo info = defaultVectorInfo;
    info.setAutoCacheStyles(true);

    LayerInfoImpl layer = mockLayer("testLayer", "style1", "style2");
    assertNull(LegacyTileLayerInfoLoader.load(layer));

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

    GeoServerTileLayerInfo actual;
    actual = LegacyTileLayerInfoLoader.load(layer);

    TileLayerInfoUtil.setCachedStyles(info, "default", ImmutableSet.of("style1", "style2"));

    info.setId(layer.getId());
    info.setName(tileLayerName(layer));
    assertEquals(info, actual);

    layer.setDefaultStyle(null);
    TileLayerInfoUtil.setCachedStyles(info, null, ImmutableSet.of("style1", "style2"));

    actual = LegacyTileLayerInfoLoader.load(layer);
    assertEquals(ImmutableSet.of("style1", "style2"), actual.cachedStyles());
  }
  /**
   * Creates a cached tile layer from the given Layer
   *
   * @param info the layer to cache
   * @param defaults default configuration
   */
  public static GeoServerTileLayerInfoImpl loadOrCreate(
      final LayerInfo layerInfo, final GWCConfig defaults) {
    GeoServerTileLayerInfoImpl info = LegacyTileLayerInfoLoader.load(layerInfo);
    if (info == null) {
      info = create(defaults);
      final ResourceInfo resource = layerInfo.getResource();
      if (resource instanceof FeatureTypeInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultVectorCacheFormats());
      } else if (resource instanceof CoverageInfo) {
        info.getMimeFormats().clear();
        info.getMimeFormats().addAll(defaults.getDefaultCoverageCacheFormats());
      }

      checkAutomaticStyles(layerInfo, info);
    }
    info.setName(tileLayerName(layerInfo));
    info.setId(layerInfo.getId());
    return info;
  }