Пример #1
0
  private synchronized int getConnectionCount() {
    int count = 0;

    CloseableIterator<DataStoreInfo> i = getDataStores();
    try {
      for (; i.hasNext(); ) {
        DataStoreInfo meta = i.next();

        if (!meta.isEnabled()) {
          // Don't count connections from disabled datastores.
          continue;
        }

        try {
          meta.getDataStore(null);
        } catch (Throwable notAvailable) {
          // TODO: Logging.
          continue;
        }

        count += 1;
      }
    } finally {
      i.close();
    }

    return count;
  }
Пример #2
0
  private synchronized int getLockCount() {
    int count = 0;

    CloseableIterator<DataStoreInfo> i = getDataStores();
    try {
      for (; i.hasNext(); ) {
        DataStoreInfo meta = (DataStoreInfo) i.next();

        if (!meta.isEnabled()) {
          // Don't count locks from disabled datastores.
          continue;
        }

        try {
          DataAccess store = meta.getDataStore(null);
          if (store instanceof DataStore) {
            LockingManager lockingManager = ((DataStore) store).getLockingManager();
            if (lockingManager != null) {
              // we can't actually *count* locks right now?
              // count += lockingManager.getLockSet().size();
            }
          }
        } catch (IllegalStateException notAvailable) {
          continue;
        } catch (Throwable huh) {
          continue;
        }
      }
    } finally {
      i.close();
    }
    return count;
  }
Пример #3
0
  private static List<DataStoreInfo> findGeoGigStores(
      Catalog catalog, org.opengis.filter.Filter filter) {
    List<DataStoreInfo> geogigStores;
    CloseableIterator<DataStoreInfo> stores = catalog.list(DataStoreInfo.class, filter);
    try {
      geogigStores = Lists.newArrayList(stores);
    } finally {
      stores.close();
    }

    return geogigStores;
  }
Пример #4
0
  private JSONArr layers(StoreInfo store, JSONArr list) throws IOException {
    Catalog cat = geoServer.getCatalog();
    WorkspaceInfo ws = store.getWorkspace();

    Filter filter = and(equal("store", store), equal("namespace.prefix", ws.getName()));
    try (CloseableIterator<ResourceInfo> layers = cat.list(ResourceInfo.class, filter); ) {
      while (layers.hasNext()) {
        ResourceInfo r = layers.next();
        for (LayerInfo l : cat.getLayers(r)) {
          layer(list.addObject(), l, true);
        }
      }
    }

    return list;
  }
Пример #5
0
  int layerCount(StoreInfo store) throws IOException {
    Catalog cat = geoServer.getCatalog();
    WorkspaceInfo ws = store.getWorkspace();

    Filter filter = and(equal("store", store), equal("namespace.prefix", ws.getName()));
    int count = 0;
    try (CloseableIterator<ResourceInfo> layers = cat.list(ResourceInfo.class, filter); ) {
      while (layers.hasNext()) {
        ResourceInfo r = layers.next();
        for (LayerInfo l : cat.getLayers(r)) {
          if (l != null) {
            count++;
          }
        }
      }
    }
    return count;
  }
 public void testGetDomain() throws IOException {
   Name name = new NameImpl(DC.NAMESPACE, "type");
   CloseableIterator<String> domain = store.getDomain(new NameImpl(CSW.NAMESPACE, "Record"), name);
   assertTrue(domain.hasNext());
   assertEquals("http://purl.org/dc/dcmitype/Dataset", domain.next());
   assertEquals("http://purl.org/dc/dcmitype/Image", domain.next());
   assertEquals("http://purl.org/dc/dcmitype/Service", domain.next());
   assertEquals("http://purl.org/dc/dcmitype/Text", domain.next());
   assertFalse(domain.hasNext());
   domain.close();
 }
Пример #7
0
  public static List<DataStoreInfo> findGeogitStores(Request request) {
    List<DataStoreInfo> geogitStores;

    Catalog catalog = getCatalog(request);
    org.opengis.filter.Filter filter =
        Predicates.equal("type", GeoGitDataStoreFactory.DISPLAY_NAME);
    CloseableIterator<DataStoreInfo> stores = catalog.list(DataStoreInfo.class, filter);
    try {
      Predicate<DataStoreInfo> enabled =
          new Predicate<DataStoreInfo>() {
            @Override
            public boolean apply(@Nullable DataStoreInfo input) {
              return input.isEnabled();
            }
          };
      geogitStores = ImmutableList.copyOf(Iterators.filter(stores, enabled));
    } finally {
      stores.close();
    }

    return geogitStores;
  }
Пример #8
0
  private JSONObj resource(JSONObj obj, StoreInfo store, String name, HttpServletRequest req)
      throws IOException {
    obj.put("name", name);
    if (store instanceof DataStoreInfo) {
      DataStoreInfo data = (DataStoreInfo) store;

      @SuppressWarnings("rawtypes")
      DataAccess dataStore = data.getDataStore(new NullProgressListener());
      FeatureType schema;
      org.geotools.data.ResourceInfo info;
      if (dataStore instanceof DataStore) {
        schema = ((DataStore) dataStore).getSchema(name);
        info = ((DataStore) dataStore).getFeatureSource(name).getInfo();
      } else {
        NameImpl qname = new NameImpl(name);
        schema = dataStore.getSchema(qname);
        info = dataStore.getFeatureSource(qname).getInfo();
      }
      String title = info.getTitle() == null ? WordUtils.capitalize(name) : info.getTitle();
      String description = info.getDescription() == null ? "" : info.getDescription();
      obj.put("title", title);
      obj.put("description", description);

      JSONArr keywords = obj.putArray("keywords");
      keywords.raw().addAll(info.getKeywords());
      IO.bounds(obj.putObject("bounds"), info.getBounds());
      IO.schema(obj.putObject("schema"), schema, false);
    }
    if (store instanceof CoverageStoreInfo) {
      CoverageStoreInfo data = (CoverageStoreInfo) store;
      GridCoverageReader r = data.getGridCoverageReader(null, null);
      obj.put("title", WordUtils.capitalize(name));
      obj.put("description", "");
      if (r instanceof GridCoverage2DReader) {
        GridCoverage2DReader reader = (GridCoverage2DReader) r;
        CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem(name);
        IO.schemaGrid(obj.putObject("schema"), crs, false);
      } else {
        IO.schemaGrid(obj.putObject("schema"), AbstractGridFormat.getDefaultCRS(), false);
      }
    }

    JSONArr layers = obj.putArray("layers");
    Catalog cat = geoServer.getCatalog();
    if (store instanceof CoverageStoreInfo) {
      // coverage store does not respect native name so we search by id
      for (CoverageInfo info : cat.getCoveragesByCoverageStore((CoverageStoreInfo) store)) {
        layers(info, layers);
      }
    } else {
      Filter filter =
          and(equal("namespace.prefix", store.getWorkspace().getName()), equal("nativeName", name));
      try (CloseableIterator<ResourceInfo> published = cat.list(ResourceInfo.class, filter); ) {
        while (published.hasNext()) {
          ResourceInfo info = published.next();
          if (!info.getStore().getId().equals(store.getId())) {
            continue; // native name is not enough, double check store id
          }
          layers(info, layers);
        }
      }
    }
    return obj;
  }