public void handleAction(final ActionParameters params) throws ActionException {
    log.debug("in handle action");

    final String term = params.getHttpParam(PARAM_TERM);
    if (term == null || term.equals("")) {
      throw new ActionParamsException("Search string was null");
    }

    final String error = SearchWorker.checkLegalSearch(term);

    if (!SearchWorker.STR_TRUE.equals(error)) {
      // write error message key
      ResponseHelper.writeResponse(params, error);
    } else {
      final Locale locale = params.getLocale();
      final SearchCriteria sc = new SearchCriteria();

      final String geographical_names = params.getHttpParam(PARAM_GEO_NAMES);
      final String addresses = params.getHttpParam(PARAM_ADDRESSES);
      final String epsg = params.getHttpParam(PARAM_EPSG_KEY);

      sc.setSearchString(term);
      sc.setSRS(epsg); // eg. EPSG:3067
      sc.setLocale(locale.getLanguage());

      sc.addParam(PARAM_REGION, params.getHttpParam(PARAM_REGION, ""));
      sc.addParam(PARAM_COUNTRY, params.getHttpParam(PARAM_COUNTRY, ""));
      sc.addParam(PARAM_FILTER, params.getHttpParam(PARAM_FILTER, "false"));
      sc.addParam(PARAM_NORMAL, params.getHttpParam(PARAM_NORMAL, "false"));
      sc.addParam(PARAM_LON, params.getHttpParam(PARAM_LON, ""));
      sc.addParam(PARAM_LAT, params.getHttpParam(PARAM_LAT, ""));
      sc.addParam(PARAM_ADDRESSES, params.getHttpParam(PARAM_ADDRESSES));
      sc.addParam(PARAM_LOCATION_TYPE, params.getHttpParam(PARAM_LOCATION_TYPE, ""));
      sc.addParam(PARAM_NAME_LANG, params.getHttpParam(PARAM_NAME_LANG, ""));
      sc.addParam(PARAM_NEAREST, params.getHttpParam(PARAM_NEAREST, ""));

      if (isFuzzy(sc)) {
        sc.addParam(PARAM_FUZZY, "true");
      }

      for (String channelId : channels) {
        if (geographical_names != null
            && geographical_names.equals("true")
            && channelId.equals(ELFGEOLOCATOR_CHANNEL)) {
          log.debug("adding channel: ELFGEOLOCATOR_CHANNEL");
          sc.addChannel(channelId);
        }
        if (addresses != null
            && addresses.equals("true")
            && channelId.equals(ELFADDRESSLOCATOR_CHANNEL)) {
          log.debug("adding channel: ELFADDRESSLOCATOR_CHANNEL");
          sc.addChannel(channelId);
        }
      }

      final JSONObject result = SearchWorker.doSearch(sc);
      ResponseHelper.writeResponse(params, result);
    }
  }
  /**
   * Parses WPS Proxy url via Oskari action route
   *
   * @param params Action parameters
   * @return String baseurl for Geoserver WPS reference WFS data input
   *     **********************************************************************
   */
  public String getBaseProxyUrl(ActionParameters params) {
    String baseurl = GEOSERVER_PROXY_BASE_URL;
    if (baseurl == null) {
      try {
        final URL url = new URL(params.getRequest().getRequestURL().toString());
        baseurl = url.getProtocol() + "://" + url.getHost() + ":" + url.getPort();
      } catch (Exception ignored) {
      }
    }

    final String baseAjaxUrl =
        PropertyUtil.get(params.getLocale(), GetAppSetupHandler.PROPERTY_AJAXURL);
    baseurl = baseurl + baseAjaxUrl + PARAMS_PROXY;
    log.debug("Analysis baseURL:", baseurl);
    return baseurl;
  }
Ejemplo n.º 3
0
  private JSONObject getPrintJSON(ActionParameters params) throws ActionException {
    final JSONObject jsonprint = new JSONObject();
    try {
      final HttpServletRequest httpRequest = params.getRequest();

      // copy parameters
      JSONObject jsparamdata = new JSONObject();
      for (Object key : httpRequest.getParameterMap().keySet()) {
        String keyStr = (String) key;
        // not geojson, tiles, tabledata param ..
        if (!EXTRA_PARAMS.contains(keyStr)) {
          jsparamdata.put(keyStr, params.getHttpParam(keyStr));
        }
      }
      jsonprint.put(KEY_MAPLINK, jsparamdata);

      // Table data
      final JSONObject jsTableData = this.populateTableData(params);
      if (jsTableData != null) jsonprint.put(KEY_PRINTOUT, jsTableData);

      // construct state
      final JSONObject jsonstatedata = new JSONObject();

      final String[] coords = CoordinateParamHandler.parseParam(params.getHttpParam(PARM_COORD));
      if (coords.length == 2) {
        try {
          final double east = ConversionHelper.getDouble(coords[0], -1);
          final double north = ConversionHelper.getDouble(coords[1], -1);
          if (east == -1 || north == -1) {
            throw new IllegalArgumentException(
                "Coordinates not set: " + params.getHttpParam(PARM_COORD));
          }
          jsonstatedata.put(ViewModifier.KEY_EAST, east);
          jsonstatedata.put(ViewModifier.KEY_NORTH, north);
        } catch (Exception ex) {
          throw new ActionException("Could not set coordinates from URL param.", ex);
        }
      }
      jsonstatedata.put(
          ViewModifier.KEY_ZOOM, ConversionHelper.getInt(params.getHttpParam(PARM_ZOOMLEVEL), 10));

      final String[] layers = params.getHttpParam(PARM_MAPLAYERS).split(",");
      final JSONArray configLayers = new JSONArray();
      final JSONArray selectedlayers = new JSONArray();

      // final String referer =
      // RequestHelper.getDomainFromReferer(params.getHttpHeader("Referer"));
      for (String layerString : layers) {
        final String[] layerProps = layerString.split(" ");
        final JSONObject layer =
            LayersParamHandler.getLayerJson(layerProps, "paikkatietoikkuna.fi");
        if (layer != null) {
          selectedlayers.put(layer);
          configLayers.put(layer);
        }
      }

      // GeoJson graphics layers to selected layers
      final String geojs64 = params.getHttpParam(PARM_GEOJSON, "");

      JSONArray geojs = null;
      if (!geojs64.isEmpty()) {
        // decoding geojson
        byte[] decoded = Base64.decodeBase64(geojs64.getBytes());

        geojs = new JSONArray(new String(decoded));

        JSONArray jslays = getGeojsonLayers(geojs);
        for (int i = 0; i < jslays.length(); i++) {
          selectedlayers.put(jslays.getJSONObject(i));
        }
      }
      jsonstatedata.put(ViewModifier.KEY_SELECTEDLAYERS, selectedlayers);
      jsonprint.put(ViewModifier.KEY_STATE, jsonstatedata);

      // printservice uses direct urls to myplaces instead of servletfilter/actionroute proxy
      final boolean useDirectURLForMyplaces = true;
      // populate layer details
      final JSONArray fullLayersConfigJson =
          MapfullHandler.getFullLayerConfig(
              configLayers,
              params.getUser(),
              params.getLocale().getLanguage(),
              PRINT_VIEW,
              ViewTypes.PRINT,
              Collections.EMPTY_SET,
              useDirectURLForMyplaces);

      // GeoJson graphics layers + styles
      if (geojs != null) {
        // Add geojson geometry and styles to layers section
        for (int i = 0; i < geojs.length(); i++) {
          fullLayersConfigJson.put(geojs.getJSONObject(i));
        }
      }

      // Add tiles, (statslayer, wfs)
      //      if (fullLayersConfigJson.toString().contains(VALUE_STATSLAYER)) {
      // Tiles in params ?
      if (!params.getHttpParam(PARM_TILES, "").isEmpty()) {

        JSONArray tiles = getTilesJSON(params);
        addTiles2Layers(fullLayersConfigJson, tiles);
      }
      //    }

      jsonprint.put(KEY_LAYERS, fullLayersConfigJson);

    } catch (Exception e) {
      throw new ActionException("Failed to create image", e);
    }

    return jsonprint;
  }