Esempio n. 1
0
  LayerInfo createLayer(ResourceInfo r, String name, NamespaceInfo ns) {
    String lId = newId();
    StyleInfo s = styles.peekLast();

    final LayerInfo l = createNiceMock(LayerInfo.class);
    layers.add(l);

    expect(l.getId()).andReturn(lId).anyTimes();
    expect(l.getName()).andReturn(name).anyTimes();
    expect(l.getType()).andReturn(LayerInfo.Type.VECTOR).anyTimes();
    expect(l.getResource()).andReturn(r).anyTimes();
    expect(l.getDefaultStyle()).andReturn(s).anyTimes();
    expect(l.isEnabled()).andReturn(true).anyTimes();
    expect(l.isAdvertised()).andReturn(true).anyTimes();

    expect(catalog.getLayer(lId)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(name)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(ns.getPrefix() + ":" + name)).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(new NameImpl(ns.getPrefix(), name))).andReturn(l).anyTimes();
    expect(catalog.getLayerByName(new NameImpl(ns.getURI(), name))).andReturn(l).anyTimes();
    expect(catalog.getLayers(r)).andReturn(Arrays.asList(l)).anyTimes();
    l.accept((CatalogVisitor) anyObject());
    expectLastCall()
        .andAnswer(
            new VisitAnswer() {
              @Override
              protected void doVisit(CatalogVisitor visitor) {
                visitor.visit(l);
              }
            })
        .anyTimes();

    callback.onLayer(name, l, this);
    return l;
  }
  void visitStore(StoreInfo store) {
    // drill down into layers (into resources since we cannot scan layers)
    List<ResourceInfo> resources = catalog.getResourcesByStore(store, ResourceInfo.class);
    for (ResourceInfo ri : resources) {
      List<LayerInfo> layers = catalog.getLayers(ri);
      for (LayerInfo li : layers) {
        li.accept(this);
      }
    }

    catalog.remove(store);
  }
Esempio n. 3
0
  void visitStore(StoreInfo store) {
    // drill down into layers (into resources since we cannot scan layers)
    List<ResourceInfo> resources = catalog.getResourcesByStore(store, ResourceInfo.class);
    for (ResourceInfo ri : resources) {
      List<LayerInfo> layers = catalog.getLayers(ri);
      if (!layers.isEmpty()) {
        for (LayerInfo li : layers) {
          li.accept(this);
        }
      } else {
        // no layers for the resource, delete directly
        ri.accept(this);
      }
    }

    catalog.remove(store);
  }
Esempio n. 4
0
  public void visit(StyleInfo style) {
    // remove style references in layers
    List<LayerInfo> layers = catalog.getLayers();
    for (LayerInfo layer : layers) {
      removeStyleInLayer(layer, style);
    }

    // groups can also refer to style, reset each reference to the
    // associated layer default style
    List<LayerGroupInfo> groups = catalog.getLayerGroups();
    for (LayerGroupInfo group : groups) {
      removeStyleInLayerGroup(group, style);
    }

    // finally remove the style
    catalog.remove(style);
  }
  public void visit(StyleInfo style) {
    // add users of this style among the related objects: layers
    List<LayerInfo> layer = catalog.getLayers();
    for (LayerInfo li : layer) {
      // if it's the default style, reset it to the default one
      if (li.getDefaultStyle().equals(style)) {
        try {
          li.setDefaultStyle(new CatalogBuilder(catalog).getDefaultStyle(li.getResource()));
          catalog.save(li);
        } catch (IOException e) {
          // we fall back on the default style (since we cannot roll back the
          // entire operation, no transactions in the catalog)
          LOGGER.log(
              Level.WARNING,
              "Could not find default style for resource "
                  + li.getResource()
                  + " resetting the default to null");
          li.setDefaultStyle(null);
        }
      }
      // remove it also from the associated styles
      if (li.getStyles().remove(style)) catalog.save(li);
    }

    // groups can also refer styles, reset each reference to the
    // associated layer default style
    List<LayerGroupInfo> groups = catalog.getLayerGroups();
    for (LayerGroupInfo group : groups) {
      List<StyleInfo> styles = group.getStyles();
      boolean dirty = false;
      for (int i = 0; i < styles.size(); i++) {
        StyleInfo si = styles.get(i);
        if (si != null && si.equals(style)) {
          styles.set(i, group.getLayers().get(i).getDefaultStyle());
          dirty = true;
        }
      }
      if (dirty) catalog.save(group);
    }

    // finally remove the style
    catalog.remove(style);
  }
Esempio n. 6
0
  @Test
  public void testAttributeCache() throws Exception {
    final Catalog catalog = getCatalog();
    ResourcePool pool = ResourcePool.create(catalog);

    // clean up the lakes type
    FeatureTypeInfo oldInfo =
        catalog.getFeatureTypeByName(
            MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
    List<LayerInfo> layers = catalog.getLayers(oldInfo);
    for (LayerInfo layerInfo : layers) {
      catalog.remove(layerInfo);
    }
    catalog.remove(oldInfo);

    // rebuild as new
    CatalogBuilder builder = new CatalogBuilder(catalog);
    builder.setStore(
        catalog.getStoreByName(MockData.CITE_PREFIX, MockData.CITE_PREFIX, DataStoreInfo.class));
    FeatureTypeInfo info =
        builder.buildFeatureType(
            new NameImpl(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()));

    // non persisted state, caching should not occurr
    List<AttributeTypeInfo> att1 = pool.getAttributes(info);
    List<AttributeTypeInfo> att2 = pool.getAttributes(info);
    assertNotSame(att1, att2);
    assertEquals(att1, att2);

    // save it, making it persistent
    catalog.add(info);

    // first check caching actually works against persisted type infos
    List<AttributeTypeInfo> att3 = pool.getAttributes(info);
    List<AttributeTypeInfo> att4 = pool.getAttributes(info);
    assertSame(att3, att4);
    assertNotSame(att1, att3);
    assertEquals(att1, att3);
  }