Example #1
0
  public void validate(LayerInfo lyr, boolean isNew) {
    if (lyr.isEnabled() == false) {
      // short-circuit - for disabled layers we don't need to validate
      // anything because it won't cause service exceptions for anyone
      return;
    }

    if (lyr.getResource() == null
        || (hasGeometry(lyr)
            && (lyr.getResource().getSRS() == null
                || lyr.getResource().getLatLonBoundingBox() == null)))
      throw new RuntimeException("Layer's resource is not fully configured");

    // Resource-dependent checks
    if (lyr.getType() == PublishedType.RASTER) {
      if (!(lyr.getResource() instanceof CoverageInfo))
        throw new RuntimeException("Layer with type RASTER doesn't have a coverage associated");
      CoverageInfo cvinfo = (CoverageInfo) lyr.getResource();
      try {
        cvinfo
            .getCatalog()
            .getResourcePool()
            .getGridCoverageReader(cvinfo, GeoTools.getDefaultHints());
      } catch (Throwable t) {
        throw new RuntimeException("Couldn't connect to raster layer's resource");
      }
    } else if (lyr.getType() == PublishedType.VECTOR) {
      if (!(lyr.getResource() instanceof FeatureTypeInfo))
        throw new RuntimeException("Layer with type VECTOR doesn't have a featuretype associated");
      FeatureTypeInfo ftinfo = (FeatureTypeInfo) lyr.getResource();
    } else throw new RuntimeException("Layer is neither RASTER nor VECTOR type");

    // Style-dependent checks
    if (hasGeometry(lyr) && (lyr.getDefaultStyle() == null || lyr.getStyles().contains(null)))
      throw new RuntimeException("Layer has null styles!");
  }