Exemplo n.º 1
0
  @Test
  public void testDropCoverageStore() throws Exception {
    // build the store
    Catalog cat = getCatalog();
    CatalogBuilder cb = new CatalogBuilder(cat);
    CoverageStoreInfo store = cb.buildCoverageStore("dem");
    store.setURL(MockData.class.getResource("tazdem.tiff").toExternalForm());
    store.setType("GeoTIFF");
    cat.add(store);

    // build the coverage
    cb.setStore(store);
    CoverageInfo ci = cb.buildCoverage();
    cat.add(ci);

    // build the layer
    LayerInfo layer = cb.buildLayer(ci);
    cat.add(layer);

    // grab a reader just to inizialize the code
    ci.getGridCoverage(null, null);
    ci.getGridCoverageReader(null, GeoTools.getDefaultHints());

    // now drop the store
    CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(cat);
    visitor.visit(store);

    // and reload (GEOS-4782 -> BOOM!)
    getGeoServer().reload();
  }
  @Test
  public void testWorkspaceRemoveAndReadd() {
    // remove all workspaces
    Catalog catalog = getCatalog();
    NamespaceInfo defaultNamespace = catalog.getDefaultNamespace();
    WorkspaceInfo defaultWs = catalog.getDefaultWorkspace();
    List<WorkspaceInfo> workspaces = catalog.getWorkspaces();
    CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(catalog);
    for (WorkspaceInfo ws : workspaces) {
      visitor.visit(ws);
    }
    assertEquals(0, catalog.getWorkspaces().size());
    assertEquals(0, catalog.getNamespaces().size());

    // add back one (this would NPE)
    catalog.add(defaultNamespace);
    catalog.add(defaultWs);
    assertEquals(1, catalog.getWorkspaces().size());
    assertEquals(1, catalog.getNamespaces().size());

    // get back by name (this would NPE too)
    assertNotNull(catalog.getNamespaceByURI(defaultNamespace.getURI()));
  }
Exemplo n.º 3
0
  @RequestMapping(value = "/{wsName}/{name}", method = RequestMethod.DELETE)
  public @ResponseBody JSONObj delete(
      @PathVariable String wsName,
      @PathVariable String name,
      @RequestParam(value = "recurse", defaultValue = "false") boolean recurse,
      HttpServletRequest req) {
    StoreInfo store = findStore(wsName, name, geoServer.getCatalog());
    Catalog cat = geoServer.getCatalog();

    List<ResourceInfo> layers = cat.getResourcesByStore(store, ResourceInfo.class);
    if (layers.isEmpty()) {
      cat.remove(store);
    } else if (recurse) {
      CascadeDeleteVisitor delete = new CascadeDeleteVisitor(cat);
      if (store instanceof DataStoreInfo) {
        delete.visit((DataStoreInfo) store);
      } else if (store instanceof CoverageStoreInfo) {
        delete.visit((CoverageStoreInfo) store);
      } else if (store instanceof WMSStoreInfo) {
        delete.visit((WMSStoreInfo) store);
      } else {
        throw new IllegalStateException(
            "Unable to delete " + name + " - expected data store, coverage store or wms store");
      }
    } else {
      StringBuilder message = new StringBuilder();
      message.append("Use recurse=true to remove ").append(name).append(" along with layers:");
      for (ResourceInfo l : layers) {
        message.append(' ').append(l.getName());
      }
      throw new IllegalStateException(message.toString());
    }
    JSONObj json = new JSONObj();
    json.put("name", name).put("workspace", wsName);
    return json;
  }