@BeforeClass
  public static void setUpData() throws Exception {
    MonitorDAO dao = new MemoryMonitorDAO();
    new MonitorTestData(dao).setup();

    MonitorConfig mc =
        new MonitorConfig() {

          @Override
          public MonitorDAO createDAO() {
            MonitorDAO dao = new MemoryMonitorDAO();
            try {
              new MonitorTestData(dao).setup();
              return dao;
            } catch (java.text.ParseException e) {
              throw new RuntimeException(e);
            }
          }

          @Override
          public BboxMode getBboxMode() {
            return BboxMode.FULL;
          }
        };

    GeoServer gs = createMock(GeoServer.class);
    monitor = new Monitor(mc);
    monitor.setServer(gs);

    catalog = new CatalogImpl();

    expect(gs.getCatalog()).andStubReturn(catalog);
    replay(gs);

    NamespaceInfo ns = catalog.getFactory().createNamespace();
    ns.setPrefix("acme");
    ns.setURI("http://acme.org");
    catalog.add(ns);
    DataStoreInfo ds = catalog.getFactory().createDataStore();
    FeatureTypeInfo ftFoo = catalog.getFactory().createFeatureType();
    ftFoo.setName("foo");
    ftFoo.setSRS("EPSG:4326");
    ftFoo.setNamespace(ns);
    ftFoo.setStore(ds);
    catalog.add(ftFoo);
    FeatureTypeInfo ftBar = catalog.getFactory().createFeatureType();
    ftBar.setName("bar");
    ftBar.setSRS("EPSG:3348");
    ftBar.setNamespace(ns);
    ftBar.setStore(ds);
    catalog.add(ftBar);
  }
  private void configureGeogigDataStore() throws Exception {

    helper.insertAndAdd(helper.lines1);
    helper.getGeogig().command(CommitOp.class).call();

    Catalog catalog = getCatalog();
    CatalogFactory factory = catalog.getFactory();
    NamespaceInfo ns = factory.createNamespace();
    ns.setPrefix(WORKSPACE);
    ns.setURI(NAMESPACE);
    catalog.add(ns);
    WorkspaceInfo ws = factory.createWorkspace();
    ws.setName(ns.getName());
    catalog.add(ws);

    DataStoreInfo ds = factory.createDataStore();
    ds.setEnabled(true);
    ds.setDescription("Test Geogig DataStore");
    ds.setName(STORE);
    ds.setType(GeoGigDataStoreFactory.DISPLAY_NAME);
    ds.setWorkspace(ws);
    Map<String, Serializable> connParams = ds.getConnectionParameters();

    Optional<URI> geogigDir = helper.getGeogig().command(ResolveGeogigURI.class).call();
    File repositoryUrl = new File(geogigDir.get()).getParentFile();
    assertTrue(repositoryUrl.exists() && repositoryUrl.isDirectory());

    connParams.put(GeoGigDataStoreFactory.REPOSITORY.key, repositoryUrl);
    connParams.put(GeoGigDataStoreFactory.DEFAULT_NAMESPACE.key, ns.getURI());
    catalog.add(ds);

    DataStoreInfo dsInfo = catalog.getDataStoreByName(WORKSPACE, STORE);
    assertNotNull(dsInfo);
    assertEquals(GeoGigDataStoreFactory.DISPLAY_NAME, dsInfo.getType());
    DataAccess<? extends FeatureType, ? extends Feature> dataStore = dsInfo.getDataStore(null);
    assertNotNull(dataStore);
    assertTrue(dataStore instanceof GeoGigDataStore);

    FeatureTypeInfo fti = factory.createFeatureType();
    fti.setNamespace(ns);
    fti.setCatalog(catalog);
    fti.setStore(dsInfo);
    fti.setSRS("EPSG:4326");
    fti.setName("Lines");
    fti.setAdvertised(true);
    fti.setEnabled(true);
    fti.setCqlFilter("INCLUDE");
    fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
    ReferencedEnvelope bounds = new ReferencedEnvelope(-180, 180, -90, 90, CRS.decode("EPSG:4326"));
    fti.setNativeBoundingBox(bounds);
    fti.setLatLonBoundingBox(bounds);
    catalog.add(fti);

    fti = catalog.getFeatureType(fti.getId());

    FeatureSource<? extends FeatureType, ? extends Feature> featureSource;
    featureSource = fti.getFeatureSource(null, null);
    assertNotNull(featureSource);
  }
Esempio n. 3
0
  @Test
  public void testAddFeatureType() throws Exception {
    testAddDataStore();
    testAddNamespace();

    DataStoreInfo ds =
        dao.getStoreByName(dao.getWorkspaceByName("acme"), "widgets", DataStoreInfo.class);
    NamespaceInfo ns = dao.getNamespaceByPrefix("acme");

    assertNull(dao.getResourceByName(ns, "anvil", FeatureTypeInfo.class));

    FeatureTypeInfo ft = dao.getCatalog().getFactory().createFeatureType();
    ft.setName("anvil");
    ft.setNativeName("anvil");
    ft.setStore(ds);
    ft.setNamespace(ns);

    dao.add(ft);

    assertNotNull(dao.getResourceByName(ns, "anvil", FeatureTypeInfo.class));
  }
Esempio n. 4
0
  /**
   * Adds a vector layer to the catalog setup.
   *
   * <p>The layer is created within a store named <code>qName.getPrefix()</code>, creating it if it
   * does not exist. The resulting store is a {@link PropertyDataStore} that points at the directory
   * <code>getDataDirectoryRoot()/qName.getPrefix()</code>. Similarily the layer and store are
   * created within a workspace named <code>qName.getPrefix()</code>, which is created if it does
   * not already exist.
   *
   * <p>The properties data for the layer is copied from the classpath, with a file name of "<code>
   * filename</code>.properties". The <tt>scope</tt> parameter is used as the class from which to
   * load the properties file relative to.
   *
   * <p>The <tt>props</tt> parameter is used to define custom properties for the layer. See the
   * {@link LayerProperty} class for supported properties.
   */
  public void addVectorLayer(
      QName qName, Map<LayerProperty, Object> props, String filename, Class scope, Catalog catalog)
      throws IOException {
    String prefix = qName.getPrefix();
    String name = qName.getLocalPart();
    String uri = qName.getNamespaceURI();

    // configure workspace if it doesn;t already exist
    if (catalog.getWorkspaceByName(prefix) == null) {
      addWorkspace(prefix, uri, catalog);
    }

    // configure store if it doesn't already exist

    File storeDir = catalog.getResourceLoader().findOrCreateDirectory(prefix);

    DataStoreInfo store = catalog.getDataStoreByName(prefix);
    if (store == null) {
      store = catalog.getFactory().createDataStore();
      store.setName(prefix);
      store.setWorkspace(catalog.getWorkspaceByName(prefix));
      store.setEnabled(true);

      store.getConnectionParameters().put(PropertyDataStoreFactory.DIRECTORY.key, storeDir);
      store.getConnectionParameters().put(PropertyDataStoreFactory.NAMESPACE.key, uri);
      catalog.add(store);
    }

    // copy the properties file over

    catalog.getResourceLoader().copyFromClassPath(filename, new File(storeDir, filename), scope);

    // configure feature type
    FeatureTypeInfo featureType = catalog.getFactory().createFeatureType();
    featureType.setStore(store);
    featureType.setNamespace(catalog.getNamespaceByPrefix(prefix));
    featureType.setName(LayerProperty.NAME.get(props, name));
    featureType.setNativeName(FilenameUtils.getBaseName(filename));
    featureType.setTitle(name);
    featureType.setAbstract("abstract about " + name);

    Integer srs = LayerProperty.SRS.get(props, SRS.get(qName));
    if (srs == null) {
      srs = 4326;
    }
    featureType.setSRS("EPSG:" + srs);
    try {
      featureType.setNativeCRS(CRS.decode("EPSG:" + srs));
    } catch (Exception e) {
      LOGGER.warning("Failed to decode EPSG:" + srs + ", setting the native SRS to null");
    }
    featureType.setNumDecimals(8);
    featureType.getKeywords().add(new Keyword(name));
    featureType.setEnabled(true);
    featureType.setProjectionPolicy(
        LayerProperty.PROJECTION_POLICY.get(props, ProjectionPolicy.NONE));
    featureType.setLatLonBoundingBox(
        LayerProperty.LATLON_ENVELOPE.get(props, DEFAULT_LATLON_ENVELOPE));
    featureType.setNativeBoundingBox(LayerProperty.ENVELOPE.get(props, null));

    FeatureTypeInfo ft = catalog.getFeatureTypeByDataStore(store, name);
    LayerInfo layer = catalog.getLayerByName(new NameImpl(prefix, name));
    if (ft == null) {
      ft = featureType;
      catalog.add(featureType);
    } else {
      if (layer == null) {
        // handles the case of layer removed, but feature type not
        catalog.remove(ft);
        ft = featureType;
        catalog.add(featureType);
      } else {
        new CatalogBuilder(catalog).updateFeatureType(ft, featureType);
        catalog.save(ft);
      }
    }

    if (layer == null
        || !layer.getResource().getNamespace().equals(catalog.getNamespaceByPrefix(prefix))) {
      layer = catalog.getFactory().createLayer();
    }

    layer.setResource(ft);

    StyleInfo defaultStyle = null;
    if (LayerProperty.STYLE.get(props, null) != null) {
      defaultStyle = catalog.getStyleByName(LayerProperty.STYLE.get(props, null));
    } else {
      // look for a style matching the layer name
      defaultStyle = catalog.getStyleByName(name);
      if (defaultStyle == null) {
        // see if the resource exists and we just need to create it
        if (getClass().getResource(name + ".sld") != null) {
          addStyle(name, catalog);
          defaultStyle = catalog.getStyleByName(name);
        }
      }
    }

    if (defaultStyle == null) {
      defaultStyle = catalog.getStyleByName(DEFAULT_VECTOR_STYLE);
    }

    layer.getStyles().clear();
    layer.setDefaultStyle(defaultStyle);
    layer.setType(LayerInfo.Type.VECTOR);
    layer.setEnabled(true);

    if (layer.getId() == null) {
      catalog.add(layer);
    } else {
      catalog.save(layer);
    }
  }