Exemplo n.º 1
0
 @Override
 public synchronized List<FeatureSourceGeoResource> resources(IProgressMonitor monitor)
     throws IOException {
   if (resources == null) {
     DataAccess<?, ?> access = toDataAccess();
     resources = new ArrayList<FeatureSourceGeoResource>();
     for (Name name : access.getNames()) {
       FeatureSourceGeoResource geoResource = new FeatureSourceGeoResource(this, name);
       resources.add(geoResource);
     }
   }
   return resources;
 }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @RequestMapping(value = "/{wsName}/{name}", method = RequestMethod.POST)
  public @ResponseBody JSONObj create(
      @PathVariable String wsName,
      @PathVariable String name,
      @RequestBody JSONObj obj,
      HttpServletRequest req)
      throws IOException {
    Catalog cat = geoServer.getCatalog();
    CatalogFactory factory = cat.getFactory();

    WorkspaceInfo workspace = findWorkspace(wsName);
    StoreInfo store = null;

    JSONObj params = obj.object("connection");
    if (params == null) {
      throw new IllegalArgumentException("connection parameters required");
    }
    if (params.has("raster")) {
      String url = params.str("raster");
      CoverageStoreInfo info = factory.createCoverageStore();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setURL(url);
      info.setType(obj.str("type"));
      try {
        GridCoverageReader reader = info.getGridCoverageReader(null, null);
        Format format = reader.getFormat();
        info.setDescription(format.getDescription());
        info.setEnabled(true);
      } catch (IOException e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else if (params.has("url")
        && params.str("url").toLowerCase().contains("Service=WMS")
        && params.str("url").startsWith("http")) {
      WMSStoreInfo info = factory.createWebMapServer();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setCapabilitiesURL(params.str("url"));
      try {
        WebMapServer service = info.getWebMapServer(new NullProgressListener());
        info.setDescription(service.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else {
      HashMap map = new HashMap(params.raw());
      Map resolved = ResourcePool.getParams(map, cat.getResourceLoader());
      DataAccess dataStore = DataAccessFinder.getDataStore(resolved);
      if (dataStore == null) {
        throw new IllegalArgumentException(
            "Connection parameters incomplete (does not match an available data store, coverage store or wms store).");
      }
      DataStoreInfo info = factory.createDataStore();
      info.setWorkspace(workspace);
      info.setType(name);
      info.getConnectionParameters().putAll(map);
      try {
        info.setDescription(dataStore.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    }
    boolean refresh = define(store, obj);
    if (refresh) {
      LOG.log(
          Level.FINE, "Inconsistent: default connection used for store creation required refresh");
    }
    cat.add(store);

    return storeDetails(new JSONObj(), store, req);
  }
Exemplo n.º 4
0
 @Override
 protected DataStoreServiceInfo createInfo(IProgressMonitor monitor) throws IOException {
   DataAccess<?, ?> access = toDataAccess();
   ServiceInfo gtInfo = access.getInfo();
   return new DataStoreServiceInfo(factory, connectionParams, gtInfo);
 }