/**
   * Parses AGGREGATE results for Oskari front
   *
   * @param response WPS vec:aggregate execute results
   * @param analysisLayer analysis layer params (field/columns info)
   * @return JSON.toSting() eg. aggregate WPS results
   *     **********************************************************************
   */
  public String parseAggregateResults(String response, AnalysisLayer analysisLayer) {

    try {

      // convert xml/text String to JSON

      final JSONObject json = XML.toJSONObject(response); // all
      // Add field name
      final AggregateMethodParams aggreParams =
          (AggregateMethodParams) analysisLayer.getAnalysisMethodParams();
      String fieldName = aggreParams.getAggreField1();
      if (analysisLayer.getInputAnalysisId() != null) {
        fieldName =
            analysisDataService.SwitchField2OriginalField(
                fieldName, analysisLayer.getInputAnalysisId());
      }
      json.put("fieldName", fieldName);
      return json.toString();

    } catch (JSONException e) {
      log.error(e, "XML to JSON failed", response);
    }

    return "{}";
  }
  public AnalysisLayer parseSwitch2UnionLayer(
      AnalysisLayer analysisLayer, String layerJSON, String filter, String baseUrl)
      throws ServiceException {
    // Switch to UNION method
    layerJSON = layerJSON.replace("\"method\":\"aggregate\"", "\"method\":\"union\"");

    AnalysisLayer al2 = this.parseAnalysisLayer(layerJSON, filter, baseUrl);
    al2.setResult(analysisLayer.getResult());
    return al2;
  }
  /**
   * Reform the featureset after WPS response for WFS-T (fix prefixes, propertynames, etc)
   *
   * @param featureSet
   * @param analysisLayer
   * @return
   */
  public String harmonizeElementNames(String featureSet, final AnalysisLayer analysisLayer) {

    try {

      final AnalysisMethodParams params = analysisLayer.getAnalysisMethodParams();
      String[] enames = params.getTypeName().split(":");
      String ename = enames[0];
      if (enames.length > 1) ename = enames[1];
      String extraFrom = "gml:" + ename + "_";

      // Mixed perfixes to feature: prefix etc
      featureSet = featureSet.replace(extraFrom, ANALYSIS_WFST_PREFIX);

      extraFrom = ANALYSIS_GML_PREFIX + ename;
      String extraTo = ANALYSIS_WFST_PREFIX + ename;
      featureSet = featureSet.replace(extraFrom, extraTo);
      String[] geoms = params.getGeom().split(":");
      String geom = geoms[0];
      if (geoms.length > 1) geom = geoms[1];
      extraFrom = ANALYSIS_GML_PREFIX + geom + ">";
      featureSet = featureSet.replace(extraFrom, ANALYSIS_WFST_GEOMETRY);
      featureSet = featureSet.replace(ANALYSIS_WPS_UNION_GEOM, ANALYSIS_WFST_GEOMETRY);
      featureSet =
          featureSet.replace(
              ANALYSIS_GML_PREFIX + ANALYSIS_WPS_ELEMENT_LOCALNAME,
              ANALYSIS_WFST_PREFIX + ANALYSIS_WPS_ELEMENT_LOCALNAME);
      featureSet = featureSet.replace(" NaN", "");
      featureSet = featureSet.replace("srsDimension=\"3\"", "srsDimension=\"2\"");

    } catch (Exception e) {
      log.debug("Harmonizing element names failed: ", e);
    }
    return featureSet;
  }
  /**
   * Setup extra data for analysis layer when input is myplaces
   *
   * @param analysisLayer analysis input layer data
   * @param json wps analysis parameters
   * @return false, if no id found
   */
  private boolean prepareAnalysis4Myplaces(AnalysisLayer analysisLayer, JSONObject json) {

    try {

      String sid = this.getAnalysisInputId(json);
      if (sid != null) {

        analysisLayer.setId(ConversionHelper.getInt(myplacesBaseLayerId, 0));
        analysisLayer.setInputType(ANALYSIS_INPUT_TYPE_GS_VECTOR);
        analysisLayer.setInputCategoryId(sid);
        return true;
      }
    } catch (Exception e) {

    }
    return false;
  }
 public String mergeAggregateResults2FeatureSet(String featureSet, AnalysisLayer analysisLayer) {
   try {
     // Add aggregate results to FeatureCollection ( only to one feature)
     featureSet =
         transformationService.addPropertiesTo1stFeature(featureSet, analysisLayer.getResult());
   } catch (ServiceException e) {
     log.debug("Feature property insert to FeatureCollection failed: ", e);
   }
   return featureSet;
 }
  /**
   * Fix the geometry property name for WFST transform Geometry property name in WPS method result
   * is not the same as in input featurecollections
   *
   * @param analysisLayer
   */
  private void fixGeometryPropertyName(AnalysisLayer analysisLayer) {

    try {

      AnalysisMethodParams params = analysisLayer.getAnalysisMethodParams();
      if (params.getMethod().equals(AnalysisParser.SPATIAL_JOIN_STATISTICS)) {
        params.setGeom("z_" + ((SpatialJoinStatisticsMethodParams) params).getGeom2());
      }

    } catch (Exception e) {
      log.warn("WPS geometry property name fix failed ", e);
    }
  }
  /**
   * Get WFS service field names
   *
   * @param analysisLayer analysis input layer data
   * @return field names
   */
  private JSONArray getWfsFields(AnalysisLayer analysisLayer) {
    JSONArray fields = new JSONArray();
    try {
      Map<String, String> map = analysisLayer.getFieldtypeMap();
      if (map != null) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
          fields.put(entry.getKey());
        }
      }

    } catch (Exception e) {

    }
    return fields;
  }
  /**
   * Use gs_vector input type, when wfs input layer is in the same server as WPS service
   *
   * @param wps_params
   * @param analysisLayer
   */
  private void setWpsInputLayerType(String wps_params, AnalysisLayer analysisLayer) {

    try {

      if (!wps_params.equals("{}")) {
        JSONObject json = JSONHelper.createJSONObject(wps_params);
        if (json.has(WPS_INPUT_TYPE)) {
          if (json.getString(WPS_INPUT_TYPE).equals(ANALYSIS_INPUT_TYPE_GS_VECTOR))
            analysisLayer.setInputType(ANALYSIS_INPUT_TYPE_GS_VECTOR);
        }
      }
    } catch (Exception e) {

    }
  }
  /**
   * Set analysis field types
   *
   * @param analysisLayer analysis input layer data
   * @param json wps analysis parameters
   * @return false, if no id found
   */
  private boolean prepareFieldtypeMap(AnalysisLayer analysisLayer, JSONObject json) {

    try {
      if (json.has(JSON_KEY_FIELDTYPES)) {
        JSONObject ftypes = json.getJSONObject(JSON_KEY_FIELDTYPES);
        Iterator<?> keys = ftypes.keys();

        while (keys.hasNext()) {
          String key = (String) keys.next();
          final String value = ftypes.getString(key);
          analysisLayer.getFieldtypeMap().put(key, value);
        }
      }

    } catch (Exception e) {

    }
    return false;
  }
  /**
   * Handles action_route CreateAnalysisLayer
   *
   * @param params Ajax request parameters
   *     **********************************************************************
   */
  public void handleAction(ActionParameters params) throws ActionException {

    if (params.getUser().isGuest()) {
      throw new ActionDeniedException("Session expired");
    }

    final String analyse = params.getRequiredParam(PARAM_ANALYSE, ERROR_ANALYSE_PARAMETER_MISSING);
    JSONObject analyseJson = JSONHelper.createJSONObject(analyse);
    if (analyseJson == null) {
      // json corrupted/parsing failed
      throw new ActionParamsException(ERROR_ANALYSE_PARAMETER_MISSING);
    }

    // filter conf data
    final String filter1 = params.getHttpParam(PARAM_FILTER1);
    final String filter2 = params.getHttpParam(PARAM_FILTER2);

    // Get baseProxyUrl
    final String baseUrl = getBaseProxyUrl(params);

    // User
    String uuid = params.getUser().getUuid();
    // note! analysisLayer is replaced in aggregate handling!!
    AnalysisLayer analysisLayer = getAnalysisLayer(analyseJson, filter1, filter2, baseUrl, uuid);
    Analysis analysis = null;

    if (analysisLayer.getMethod().equals(AnalysisParser.LAYER_UNION)) {
      // no WPS for merge analysis
      analysis = analysisDataService.mergeAnalysisData(analysisLayer, analyse, params.getUser());
    } else {
      // Generate WPS XML
      String featureSet = executeWPSprocess(analysisLayer);
      if (analysisLayer.getMethod().equals(AnalysisParser.UNION)
          || analysisLayer.getMethod().equals(AnalysisParser.INTERSECT)
          || analysisLayer.getMethod().equals(AnalysisParser.SPATIAL_JOIN)) {
        // Harmonize namespaces and element names
        featureSet = analysisParser.harmonizeElementNames(featureSet, analysisLayer);
      }

      // Add data to analysis db  - we must create still an union in aggregate case
      if (analysisLayer.getMethod().equals(AnalysisParser.AGGREGATE)) {
        // No store to analysis db for aggregate - set results in to the
        // response
        // Save analysis results - use union of input data
        analysisLayer.setWpsLayerId(-1);
        final String aggregateResult =
            this.localiseAggregateResult(
                analysisParser.parseAggregateResults(featureSet, analysisLayer), analyseJson);
        log.debug("\nAggregate results:\n", aggregateResult, "\n");
        /*
        Aggregate results:
         {"fi_url_1":{"Count":4},"tmp_id":{"Sum":45301,"Median":12232,"Count":4,"Standar
        d deviation":3186.3551571505645,"Maximum":14592,"Average":11325.25,"Minimum":624
        5},"fi_url_3":{"Count":4},"postinumero":{"Count":4},"fi_url_2":{"Count":4},"fi_s
        posti_1":{"Count":4},"kuntakoodi":{"Count":4},"fi_osoite":{"Count":4},"fi_nimi":
        {"Count":4},"kto_tarkennus":{"Count":4}}
                         */
        analysisLayer.setResult(aggregateResult);

        // Get geometry for aggretage features
        try {
          // Just return result as JSON and don't save analysis to DB
          if (!params.getHttpParam(PARAM_SAVE_BLN, true)) {
            // NOTE!! Replacing the analysisLayer!
            // Get response as geojson when no db store
            analysisLayer =
                getAggregateLayer(analyse, filter1, filter2, baseUrl, analysisLayer, JSONFORMAT);
            featureSet = wpsService.requestFeatureSet(analysisLayer);
            // Just return result as JSON and don't save analysis to DB
            // Get geometry as geojson for hilighting features of aggregate result
            JSONObject geojson = JSONHelper.createJSONObject(featureSet);
            JSONObject jsaggregate = JSONHelper.createJSONObject(aggregateResult);
            JSONObject results = new JSONObject();
            JSONHelper.putValue(results, JSON_KEY_GEOJSON, geojson);
            JSONHelper.putValue(results, JSON_KEY_AGGREGATE_RESULT, jsaggregate);
            ResponseHelper.writeResponse(params, results);
            return;
          }
          // NOTE!! Replacing the analysisLayer!  - response is gml
          analysisLayer =
              getAggregateLayer(analyse, filter1, filter2, baseUrl, analysisLayer, null);
          featureSet = wpsService.requestFeatureSet(analysisLayer);
          // Harmonize namespaces and element names
          featureSet = analysisParser.harmonizeElementNames(featureSet, analysisLayer);
          featureSet =
              analysisParser.mergeAggregateResults2FeatureSet(
                  featureSet,
                  analysisLayer,
                  this.getRowOrder(analyseJson),
                  this.getColumnOrder(analyseJson));
          // Redefine column types
          analysisLayer.setFieldtypeMap(
              this.getAggregateFieldTypes(this.getColumnOrder(analyseJson)));
        } catch (ServiceException e) {
          throw new ActionException(ERROR_UNABLE_TO_GET_FEATURES_FOR_UNION, e);
        }
      }
      // Add extra TypeNames (depends on wps method)
      analysisParser.fixTypeNames(analysisLayer);

      // Fix geometry property name for WFST (could be any, depends on Wps method )
      fixGeometryPropertyName(analysisLayer);

      analysis =
          analysisDataService.storeAnalysisData(
              featureSet, analysisLayer, analyse, params.getUser());
    }

    if (analysis == null) {
      this.MyError(ERROR_UNABLE_TO_STORE_ANALYSIS_DATA, params, null);
      return;
    }

    analysisLayer.setWpsLayerId(analysis.getId()); // aka. analysis_id
    // Analysis field mapping
    analysisLayer.setLocaleFields(analysis);
    analysisLayer.setNativeFields(analysis);

    // copy permissions from source layer to new analysis
    final Resource sourceResource =
        getSourcePermission(analysisParser.getSourceLayerId(analyseJson), params.getUser());
    if (sourceResource != null) {
      final Resource analysisResource = new Resource();
      analysisResource.setType(AnalysisLayer.TYPE);
      analysisResource.setMapping("analysis", Long.toString(analysis.getId()));
      for (Permission p : sourceResource.getPermissions()) {
        // check if user has role matching permission?
        if (p.isOfType(Permissions.PERMISSION_TYPE_PUBLISH)
            || p.isOfType(Permissions.PERMISSION_TYPE_VIEW_PUBLISHED)) {
          analysisResource.addPermission(p.clonePermission());
        }
      }
      log.debug(
          "Trying to save permissions for analysis",
          analysisResource,
          analysisResource.getPermissions());
      permissionsService.saveResourcePermissions(analysisResource);
    } else {
      log.warn("Couldn't get source permissions for analysis, result will have none");
    }

    // Get analysisLayer JSON for response to front
    final JSONObject analysisLayerJSON = AnalysisHelper.getlayerJSON(analysis);

    // Additional param for new layer creation when merging layers:
    // - Notify client to remove merged layers since they are removed from backend
    JSONArray mlayers = new JSONArray();
    if (analysisLayer.getMergeAnalysisLayers() != null) {
      for (String lay : analysisLayer.getMergeAnalysisLayers()) {
        mlayers.put(lay);
      }
    }
    JSONHelper.putValue(analysisLayerJSON, "mergeLayers", mlayers);

    Set<String> permissionsList = permissionsService.getPublishPermissions(AnalysisLayer.TYPE);
    Set<String> downloadPermissionsList =
        permissionsService.getDownloadPermissions(AnalysisLayer.TYPE);
    Set<String> editAccessList = null;
    String permissionKey = "analysis+" + analysis.getId();
    JSONObject permissions =
        OskariLayerWorker.getPermissions(
            params.getUser(),
            permissionKey,
            permissionsList,
            downloadPermissionsList,
            editAccessList);
    JSONHelper.putValue(analysisLayerJSON, "permissions", permissions);

    ResponseHelper.writeResponse(params, analysisLayerJSON);
  }
  /**
   * Get GeoServer WPS execute responses
   *
   * @param analysisLayer analysis method parameters
   * @return one or more Wps execute responses
   * @throws ServiceException
   */
  private String requestFeatureSets(AnalysisLayer analysisLayer) throws ServiceException {

    String featureSet = null;
    Boolean doRequest = true;
    if (analysisLayer.getMethod().equals(AnalysisParser.AGGREGATE)) {
      StringBuilder sb = new StringBuilder();
      // Loop aggregate attribute fields
      // Temp save  aggregate function setup
      List<String> aggre_funcs =
          ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams()).getAggreFunctions();
      List<String> aggre_text_funcs = new ArrayList<String>();
      aggre_text_funcs.add("Count");
      for (String field : analysisLayer.getFields()) {
        ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams()).setAggreField1(field);
        if (analysisLayer.getFieldtypeMap().containsKey(field)) {
          if (analysisLayer.getFieldtypeMap().get(field).equals("numeric")) {
            ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams())
                .setAggreFunctions(aggre_funcs);
            if (aggre_funcs.size() == 0) doRequest = false;
          } else {
            ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams())
                .setAggreFunctions(aggre_text_funcs);
            doRequest = true;
          }
        }
        sb.append("<fieldResult>");
        sb.append("<field>" + field + "</field>");
        if (doRequest) sb.append(wpsService.requestFeatureSet(analysisLayer));
        if (analysisLayer.isNodataCount()) {
          // Special aggregate process for NoDataCount - use count method with specific filter
          ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams())
              .setAggreFunctions(aggre_text_funcs);
          ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams()).setDoNoDataCount(true);
          sb.append("<fieldNoDataCount>");
          String nodataresponse = wpsService.requestFeatureSet(analysisLayer);
          // Wps wps input features fails, if no nodata feature fields (exception) --> skip
          // Could be another wps exception as well
          if (nodataresponse.indexOf("ows:Exception") == -1) sb.append(nodataresponse);
          sb.append("</fieldNoDataCount>");
          ((AggregateMethodParams) analysisLayer.getAnalysisMethodParams()).setDoNoDataCount(false);
        }
        sb.append("</fieldResult>");
      }

      featureSet = sb.toString();
    } else if (analysisLayer.getMethod().equals(AnalysisParser.DIFFERENCE)) {
      // Get feature set via WFS 2.0 GetFeature
      // WFS join select is not available in wfs 1.1.0
      featureSet = wpsService.requestWFS2FeatureSet(analysisLayer);

    } else {
      featureSet = wpsService.requestFeatureSet(analysisLayer);
    }
    return featureSet;
  }
示例#12
0
  /**
   * Parses method parameters to WPS execute xml syntax definition
   *
   * @param layerJSON method parameters and layer info from the front
   * @param baseUrl Url for Geoserver WPS reference input (input FeatureCollection)
   * @return AnalysisLayer parameters for WPS execution
   *     **********************************************************************
   */
  public AnalysisLayer parseAnalysisLayer(String layerJSON, String filter, String baseUrl)
      throws ServiceException {
    AnalysisLayer analysisLayer = new AnalysisLayer();

    JSONObject json = JSONHelper.createJSONObject(layerJSON);
    WFSLayerConfiguration lc = null;

    // analysis input data type - default is WFS layer
    analysisLayer.setInputType(ANALYSIS_INPUT_TYPE_WFS);
    // analysis rendering url
    analysisLayer.setWpsUrl(analysisRenderingUrl);
    // analysis element name
    analysisLayer.setWpsName(analysisRenderingElement);

    analysisLayer.setInputAnalysisId(null);
    int id = 0;
    try {
      // Analysis input property types
      this.prepareFieldtypeMap(analysisLayer, json);

      String sid = json.getString(JSON_KEY_LAYERID);

      // Input is wfs layer or analaysis layer or my places
      if (sid.indexOf(LAYER_PREFIX) == 0) {
        // Analysislayer is input
        if (!this.prepareAnalysis4Analysis(analysisLayer, json))
          throw new ServiceException("AnalysisInAnalysis parameters are invalid");
        id = analysisLayer.getId();
      } else if (sid.indexOf(MYPLACES_LAYER_PREFIX) == 0) {
        // myplaces is input
        if (!this.prepareAnalysis4Myplaces(analysisLayer, json))
          throw new ServiceException("AnalysisInMyPlaces parameters are invalid");
        id = analysisLayer.getId();
      } else {
        // Wfs layer id
        id = ConversionHelper.getInt(sid, -1);
      }
    } catch (JSONException e) {
      throw new ServiceException("AnalysisInAnalysis parameters are invalid");
    }
    // --- WFS layer is analysis input
    analysisLayer.setId(id);

    // Get wfs layer configuration
    lc = layerConfigurationService.findConfiguration(id);

    final OskariLayer wfsLayer = mapLayerService.find(id);
    log.debug("got wfs layer", wfsLayer);
    analysisLayer.setMinScale(wfsLayer.getMinScale());
    analysisLayer.setMaxScale(wfsLayer.getMaxScale());

    // Set WFS input type, other than analysis_ and myplaces_- default is REFERENCE
    this.setWpsInputLayerType(lc.getWps_params(), analysisLayer);

    // Extract parameters for analysis methods from layer

    String name = json.optString("name");
    if (name.isEmpty()) {
      throw new ServiceException("Analysis name missing.");
    } else {
      analysisLayer.setName(name);
    }

    JSONArray fields_in = json.optJSONArray("fields");
    List<String> fields = new ArrayList<String>();

    if (fields_in == null) {
      throw new ServiceException("Fields missing.");
    } else {
      // Add fields of WFS service, if empty and all fields mode on
      if (fields_in.length() == 0) fields_in = this.getWfsFields(analysisLayer);
      // Remove internal fields
      try {
        for (int i = 0; i < fields_in.length(); i++) {
          if (!HIDDEN_FIELDS.contains(fields_in.getString(i))) fields.add(fields_in.getString(i));
        }
      } catch (JSONException e) {
        throw new ServiceException("Method fields parameters missing.");
      }
      analysisLayer.setFields(fields);
    }

    String style = json.optString("style");
    if (style.isEmpty()) {
      throw new ServiceException("Style missing.");
    } else {
      analysisLayer.setStyle(style);
    }

    Integer opacity = json.optInt("opacity");
    if (opacity == 0) opacity = DEFAULT_OPACITY;
    analysisLayer.setOpacity(opacity);

    String analysisMethod = json.optString("method"); // "union_geom"; test
    analysisLayer.setMethod(analysisMethod);

    analysisLayer.setAggreFunctions(null);
    analysisLayer.setMergeAnalysisLayers(null);

    // ------------------LAYER_UNION -----------------------
    if (LAYER_UNION.equals(analysisMethod)) {
      JSONObject params;
      try {
        params = json.getJSONObject(JSON_KEY_METHODPARAMS);
      } catch (JSONException e) {
        throw new ServiceException("Method parameters missing.");
      }
      JSONArray sids = params.optJSONArray(JSON_KEY_LAYERS);
      // Loop merge layers - get analysis ids
      List<Long> ids = new ArrayList<Long>();
      List<String> mergelays = new ArrayList<String>();
      if (sids == null) {
        throw new ServiceException("merge layers missing");
      } else {
        try {
          for (int i = 0; i < sids.length(); i++) {
            Long aid = this.getAnalysisId(sids.getString(i));
            if (aid > 0) {
              ids.add(aid);
              mergelays.add(sids.getString(i));
            }
          }
        } catch (JSONException e) {
          throw new ServiceException("Merge layers missing.");
        }
        // Merge analysis Ids
        analysisLayer.setMergeAnalysisIds(ids);
        // Merge analysis Layers
        analysisLayer.setMergeAnalysisLayers(mergelays);
      }
    }
    // ------------------ BUFFER -----------------------
    else if (BUFFER.equals(analysisMethod)) {
      // when analysisMethod == vec:BufferFeatureCollection

      // Set params for WPS execute

      BufferMethodParams method = this.parseBufferParams(lc, json, baseUrl);

      method.setWps_reference_type(analysisLayer.getInputType());
      analysisLayer.setAnalysisMethodParams(method);

      // WFS filter
      analysisLayer
          .getAnalysisMethodParams()
          .setFilter(
              this.parseFilter(
                  lc,
                  filter,
                  analysisLayer.getInputAnalysisId(),
                  analysisLayer.getInputCategoryId()));
      // WFS Query properties
      analysisLayer
          .getAnalysisMethodParams()
          .setProperties(
              this.parseProperties(
                  analysisLayer.getFields(),
                  lc.getFeatureNamespace(),
                  lc.getGMLGeometryProperty()));
      // ------------------ INTERSECT -----------------------
    } else if (INTERSECT.equals(analysisMethod)) {
      JSONObject params;
      try {
        params = json.getJSONObject(JSON_KEY_METHODPARAMS);
      } catch (JSONException e) {
        throw new ServiceException("Method parameters missing.");
      }
      WFSLayerConfiguration lc2 = null;
      int id2 = 0;
      String sid = "";
      try {
        sid = params.getString(JSON_KEY_LAYERID);
        // Input is wfs layer or analaysis layer
        if (sid.indexOf(LAYER_PREFIX) == 0) {
          // Analysislayer is input
          // eg. analyse_216_340
          id2 = ConversionHelper.getInt(analysisBaseLayerId, 0);

        } else if (sid.indexOf(MYPLACES_LAYER_PREFIX) == 0) {
          // Myplaces is input
          id2 = ConversionHelper.getInt(myplacesBaseLayerId, 0);

        } else {
          // Wfs layer id
          id2 = ConversionHelper.getInt(sid, -1);
        }
      } catch (JSONException e) {
        throw new ServiceException("AnalysisInAnalysis parameters are invalid");
      }

      // Get wfs layer configuration for union input 2
      lc2 = layerConfigurationService.findConfiguration(id2);

      // Set params for WPS execute

      IntersectMethodParams method = this.parseIntersectParams(lc, lc2, json, baseUrl);

      method.setWps_reference_type(analysisLayer.getInputType());
      if (sid.indexOf(LAYER_PREFIX) == 0 || sid.indexOf(MYPLACES_LAYER_PREFIX) == 0) {
        method.setWps_reference_type2(ANALYSIS_INPUT_TYPE_GS_VECTOR);
      } else {
        method.setWps_reference_type2(ANALYSIS_INPUT_TYPE_WFS);
      }
      // Set WFS input type, other than analysis_ and myplaces_- default is REFERENCE
      this.setWpsInputLayerType(lc.getWps_params(), analysisLayer);

      // WFS filter

      method.setFilter(
          this.parseFilter(
              lc, filter, analysisLayer.getInputAnalysisId(), analysisLayer.getInputCategoryId()));

      if (sid.indexOf(MYPLACES_LAYER_PREFIX) == 0) {
        method.setFilter2(this.parseFilter(lc2, null, null, this.getAnalysisInputId(params)));
      } else {
        method.setFilter2(this.parseFilter(lc2, null, this.getAnalysisInputId(params), null));
      }
      // WFS Query properties
      method.setProperties(
          this.parseProperties(
              analysisLayer.getFields(), lc.getFeatureNamespace(), lc.getGMLGeometryProperty()));

      analysisLayer.setAnalysisMethodParams(method);
      // ------------------ AGGREGATE -----------------------
    } else if (AGGREGATE.equals(analysisMethod)) {

      // 1 to n aggregate wps tasks
      String aggre_field = null;
      try {

        aggre_field = json.getJSONObject(JSON_KEY_METHODPARAMS).optString(JSON_KEY_AGGRE_ATTRIBUTE);
        if (analysisLayer.getInputType().equals(ANALYSIS_INPUT_TYPE_GS_VECTOR)) {
          if (analysisLayer.getInputAnalysisId() != null) {
            aggre_field =
                analysisDataService.SwitchField2AnalysisField(
                    aggre_field, analysisLayer.getInputAnalysisId());
          }
        }
        JSONArray aggre_func_in =
            json.getJSONObject(JSON_KEY_METHODPARAMS).optJSONArray(JSON_KEY_FUNCTIONS);
        List<String> aggre_funcs = new ArrayList<String>();
        if (aggre_func_in == null) {
          throw new ServiceException("Aggregate functions missing.");
        } else {
          try {
            for (int i = 0; i < aggre_func_in.length(); i++) {
              aggre_funcs.add(aggre_func_in.getString(i));
            }
          } catch (JSONException e) {
            throw new ServiceException("Aggregate functions missing.");
          }
          analysisLayer.setAggreFunctions(aggre_funcs);
        }

      } catch (JSONException e) {
        throw new ServiceException("Method parameters missing.");
      }

      // Set params for WPS execute
      if (aggre_field == null) throw new ServiceException("Aggregate field parameter missing.");
      AggregateMethodParams method =
          this.parseAggregateParams(
              lc, json, baseUrl, aggre_field, analysisLayer.getAggreFunctions());

      method.setWps_reference_type(analysisLayer.getInputType());
      analysisLayer.setAnalysisMethodParams(method);
      // WFS filter

      analysisLayer
          .getAnalysisMethodParams()
          .setFilter(
              this.parseFilter(
                  lc,
                  filter,
                  analysisLayer.getInputAnalysisId(),
                  analysisLayer.getInputCategoryId()));
      // ------------------ UNION -----------------------
    } else if (UNION.equals(analysisMethod)) {
      JSONObject params;
      try {
        params = json.getJSONObject(JSON_KEY_METHODPARAMS);
      } catch (JSONException e) {
        throw new ServiceException("Method parameters missing.");
      }

      // Set params for WPS execute

      UnionMethodParams method = this.parseUnionParams(lc, json, baseUrl);
      method.setWps_reference_type(analysisLayer.getInputType());

      // WFS filter

      method.setFilter(
          this.parseFilter(
              lc, filter, analysisLayer.getInputAnalysisId(), analysisLayer.getInputCategoryId()));

      analysisLayer.setAnalysisMethodParams(method);

    } else {
      throw new ServiceException("Method parameters missing.");
    }

    return analysisLayer;
  }