示例#1
0
  /**
   * Adds a settings configuration to the test setup. If the settings object already exists it is
   * simply reverted to its original state.
   *
   * @param workspace The optional workspace for the settings, may be <code>null</code>
   * @param geoServer The GeoServer configuration object.
   */
  public void addSettings(String workspace, GeoServer geoServer) {
    WorkspaceInfo ws =
        workspace != null ? geoServer.getCatalog().getWorkspaceByName(workspace) : null;

    GeoServerInfo global = geoServer.getGlobal();
    SettingsInfo settings = ws != null ? geoServer.getSettings(ws) : global.getSettings();
    if (settings == null) {
      settings = geoServer.getFactory().createSettings();
    }
    settings.setWorkspace(ws);
    settings.getContact().setContactPerson("Andrea Aime");
    settings.setNumDecimals(8);
    settings.setOnlineResource("http://geoserver.org");
    settings.setVerbose(false);
    settings.setVerboseExceptions(false);
    settings.setLocalWorkspaceIncludesPrefix(false);

    if (ws != null) {
      if (settings.getId() != null) {
        geoServer.save(settings);
      } else {
        geoServer.add(settings);
      }
    } else {
      // global
      geoServer.save(global);
    }
  }
示例#2
0
  /**
   * Adds a service configuration to the test setup. If the service object already exists it is
   * simply reverted to its original state.
   *
   * @param serviceClass The class of the service
   * @param workspace The optional workspace for the service, may be <code>null</code>
   * @param geoServer The GeoServer configuration object.
   */
  public <T extends ServiceInfo> void addService(
      Class<T> serviceClass, String workspace, GeoServer geoServer) {

    Catalog catalog = geoServer.getCatalog();

    List<XStreamServiceLoader> loaders = GeoServerExtensions.extensions(XStreamServiceLoader.class);
    for (XStreamServiceLoader loader : loaders) {
      if (serviceClass.equals(loader.getServiceClass())) {
        // create a new one
        T created = (T) loader.create(geoServer);

        // grab the old one, if it exists
        T old = null;
        WorkspaceInfo ws = null;
        if (workspace != null) {
          ws = catalog.getWorkspaceByName(workspace);
          old = geoServer.getService(ws, serviceClass);
        } else {
          old = geoServer.getService(serviceClass);
        }

        if (old != null) {
          // update the old copy
          OwsUtils.copy(created, old, serviceClass);
          geoServer.save(old);
        } else {
          // add the new one
          created.setWorkspace(ws);
          geoServer.add(created);
        }

        break;
      }
    }
  }