/**
   * This process returns a boolean value which indicates if the requested download does not exceed
   * the imposed limits, if present
   *
   * @param layerName the layer name
   * @param filter the filter
   * @param email the email
   * @param outputFormat the output format
   * @param targetCRS the target crs
   * @param roiCRS the roi crs
   * @param roi the roi
   * @param clip the crop to geometry
   * @param targetSizeX the size of the target image along the X axis
   * @param targetSizeY the size of the target image along the Y axis
   * @param bandIndices the band indices selected for output, in case of raster input
   * @param progressListener the progress listener
   * @return the boolean
   */
  @DescribeResult(name = "result", description = "Download Limits are respected or not!")
  public Boolean execute(
      @DescribeParameter(name = "layerName", min = 1, description = "Original layer to download")
          String layerName,
      @DescribeParameter(name = "filter", min = 0, description = "Optional Vectorial Filter")
          Filter filter,
      @DescribeParameter(name = "targetCRS", min = 0, description = "Target CRS")
          CoordinateReferenceSystem targetCRS,
      @DescribeParameter(name = "RoiCRS", min = 0, description = "Region Of Interest CRS")
          CoordinateReferenceSystem roiCRS,
      @DescribeParameter(name = "ROI", min = 0, description = "Region Of Interest") Geometry roi,
      @DescribeParameter(name = "cropToROI", min = 0, description = "Crop to ROI") Boolean clip,
      @DescribeParameter(
              name = "targetSizeX",
              min = 0,
              minValue = 1,
              description = "X Size of the Target Image (applies to raster data only)")
          Integer targetSizeX,
      @DescribeParameter(
              name = "targetSizeY",
              min = 0,
              minValue = 1,
              description = "Y Size of the Target Image (applies to raster data only)")
          Integer targetSizeY,
      @DescribeParameter(name = "selectedBands", description = "Band Selection Indices", min = 0)
          int[] bandIndices,
      ProgressListener progressListener)
      throws Exception {

    //
    // initial checks on mandatory params
    //
    // layer name
    if (layerName == null || layerName.length() <= 0) {
      throw new IllegalArgumentException("Empty or null layerName provided!");
    }
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(Level.FINE, "Estimator process called on resource: " + layerName);
    }
    if (clip == null) {
      clip = false;
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Clipping disabled");
      }
    }
    if (roi != null) {
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "ROI present");
      }
      DownloadUtilities.checkPolygonROI(roi);
      if (roiCRS == null) {
        throw new IllegalArgumentException("ROI without a CRS is not usable!");
      }
      roi.setUserData(roiCRS);
    }

    //
    // Move on with the real code
    //
    // checking for the resources on the GeoServer catalog
    LayerInfo layerInfo = catalog.getLayerByName(layerName);
    if (layerInfo == null) {
      // could not find any layer ... abruptly interrupt the process
      throw new IllegalArgumentException("Unable to locate layer: " + layerName);
    }
    ResourceInfo resourceInfo = layerInfo.getResource();
    if (resourceInfo == null) {
      // could not find any data store associated to the specified layer ... abruptly interrupt the
      // process
      throw new IllegalArgumentException("Unable to locate ResourceInfo for layer:" + layerName);
    }

    //
    // Get curent limits
    //
    DownloadServiceConfiguration limits = downloadServiceConfigurationGenerator.getConfiguration();
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(Level.FINE, "Getting configuration limits");
    }

    // ////
    // 1. DataStore -> look for vectorial data download
    // 2. CoverageStore -> look for raster data download
    // ////
    if (resourceInfo instanceof FeatureTypeInfo) {
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Working with Vectorial dataset");
      }
      final FeatureTypeInfo featureTypeInfo = (FeatureTypeInfo) resourceInfo;

      return new VectorEstimator(limits)
          .execute(featureTypeInfo, roi, clip, filter, targetCRS, progressListener);

    } else if (resourceInfo instanceof CoverageInfo) {
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Working with Raster dataset");
      }
      final CoverageInfo coverage = (CoverageInfo) resourceInfo;
      return new RasterEstimator(limits)
          .execute(
              progressListener,
              coverage,
              roi,
              targetCRS,
              clip,
              filter,
              targetSizeX,
              targetSizeY,
              bandIndices);
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(Level.FINE, "Working with a wrong Resource");
    }

    // the requested layer is neither a featuretype nor a coverage --> error
    final ProcessException ex =
        new ProcessException(
            "Could not complete the Download Process: target resource is of Illegal type --> "
                        + resourceInfo
                    != null
                ? resourceInfo.getClass().getCanonicalName()
                : "null");

    // Notify the listener if present
    if (progressListener != null) {
      progressListener.exceptionOccurred(ex);
    }
    throw ex;
  }
  @Override
  public Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor)
      throws ProcessException {
    if (started) throw new IllegalStateException("Process can only be run once");
    started = true;

    if (monitor == null) monitor = new NullProgressListener();
    try {
      monitor.started();
      monitor.setTask(Text.text("Grabbing arguments"));
      monitor.progress(10.0f);

      SimpleFeatureCollection inputFeatures =
          (SimpleFeatureCollection)
              Params.getValue(input, PearsonCorrelationProcessFactory.inputFeatures, null);
      String inputFields =
          (String) Params.getValue(input, PearsonCorrelationProcessFactory.inputFields, null);
      if (inputFeatures == null || inputFields == null) {
        throw new NullPointerException("All parameters required");
      }

      monitor.setTask(Text.text("Processing ..."));
      monitor.progress(25.0f);

      if (monitor.isCanceled()) {
        return null; // user has canceled this operation
      }

      // start process
      PearsonOperation operation = new PearsonOperation();
      PearsonResult ret = operation.execute(inputFeatures, inputFields);
      // end process

      monitor.setTask(Text.text("Encoding result"));
      monitor.progress(90.0f);

      Map<String, Object> resultMap = new HashMap<String, Object>();
      resultMap.put(PearsonCorrelationProcessFactory.RESULT.key, ret);
      monitor.complete(); // same as 100.0f

      return resultMap;
    } catch (Exception eek) {
      monitor.exceptionOccurred(eek);
      return null;
    } finally {
      monitor.dispose();
    }
  }
Exemple #3
0
  /**
   * Executes the import operation using the parameters that have been specified. Features will be
   * added to the working tree, and a new working tree will be constructed. Either {@code all} or
   * {@code table}, but not both, must be set prior to the import process.
   *
   * @return RevTree the new working tree
   */
  @SuppressWarnings("deprecation")
  @Override
  public RevTree call() {

    // check preconditions and get the actual list of type names to import
    final String[] typeNames = checkPreconditions();

    ProgressListener progressListener = getProgressListener();
    progressListener.started();

    // use a local variable not to alter the command's state
    boolean overwrite = this.overwrite;
    if (alter) {
      overwrite = false;
    }

    final WorkingTree workTree = getWorkTree();

    final boolean destPathProvided = destPath != null;
    if (destPathProvided && overwrite) {
      // we delete the previous tree to honor the overwrite setting, but then turn it
      // to false. Otherwise, each table imported will overwrite the previous ones and
      // only the last one will be imported.
      try {
        workTree.delete(destPath);
      } catch (Exception e) {
        throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
      }
      overwrite = false;
    }

    int tableCount = 0;

    for (String typeName : typeNames) {
      {
        tableCount++;
        String tableName = String.format("%-16s", typeName);
        if (typeName.length() > 16) {
          tableName = tableName.substring(0, 13) + "...";
        }
        progressListener.setDescription(
            "Importing " + tableName + " (" + tableCount + "/" + typeNames.length + ")... ");
      }

      FeatureSource featureSource = getFeatureSource(typeName);
      SimpleFeatureType featureType = (SimpleFeatureType) featureSource.getSchema();

      final String fidPrefix = featureType.getTypeName() + ".";

      String path;
      if (destPath == null) {
        path = featureType.getTypeName();
      } else {
        NodeRef.checkValidPath(destPath);
        path = destPath;
        featureType = createForceFeatureType(featureType, path);
      }
      featureSource =
          new ForceTypeAndFidFeatureSource<FeatureType, Feature>(
              featureSource, featureType, fidPrefix);

      ProgressListener taskProgress = subProgress(100.f / typeNames.length);
      if (overwrite) {
        try {
          workTree.delete(path);
          workTree.createTypeTree(path, featureType);
        } catch (Exception e) {
          throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
        }
      }

      if (alter) {
        // first we modify the feature type and the existing features, if needed
        workTree.updateTypeTree(path, featureType);
        Iterator<Feature> transformedIterator = transformFeatures(featureType, path);
        try {
          final Integer collectionSize = collectionSize(featureSource);
          workTree.insert(path, transformedIterator, taskProgress, null, collectionSize);
        } catch (Exception e) {
          throw new GeoToolsOpException(StatusCode.UNABLE_TO_INSERT);
        }
      }
      try {
        insert(workTree, path, featureSource, taskProgress);
      } catch (Exception e) {
        throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
      }
    }

    progressListener.progress(100.f);
    progressListener.complete();
    return workTree.getTree();
  }