Пример #1
0
  private JSONArray getPublishableLayers(final JSONArray selectedLayers, final User user)
      throws ActionException {
    if (selectedLayers == null || user == null) {
      throw new ActionParamsException("Could not get selected layers");
    }
    final JSONArray filteredList = new JSONArray();
    log.debug("Selected layers:", selectedLayers);

    String userUuid = user.getUuid();
    try {
      for (int i = 0; i < selectedLayers.length(); ++i) {
        JSONObject layer = selectedLayers.getJSONObject(i);
        String layerId = layer.getString("id");
        if (layerId.startsWith(PREFIX_MYPLACES)) {
          // check publish right for published myplaces layer
          if (hasRightToPublishMyPlaceLayer(layerId, userUuid, user.getScreenname())) {
            filteredList.put(layer);
          }
        } else if (layerId.startsWith(PREFIX_BASELAYER)) {
          // check publish right for base layer
          if (hasRightToPublishBaseLayer(layerId, user)) {
            filteredList.put(layer);
          }
        }
        // check publish right for normal layer
        else if (hasRightToPublishLayer(layerId, user)) {
          filteredList.put(layer);
        }
      }
    } catch (Exception e) {
      log.error(e, "Error parsing myplaces layers from published layers", selectedLayers);
    }
    log.debug("Filtered layers:", filteredList);
    return filteredList;
  }
  /**
   * Process of the job
   *
   * <p>Worker calls this when starts the job.
   */
  public String run() {

    log.debug(PROCESS_STARTED + " " + getKey());
    setResourceSending();

    // if different SRS, create transforms for geometries
    if (!this.session.getLocation().getSrs().equals(this.layer.getSRSName())) {
      this.transformService =
          this.session.getLocation().getTransformForService(this.layer.getCrs(), true);
      this.transformClient =
          this.session.getLocation().getTransformForClient(this.layer.getCrs(), true);
    }

    // check that the job isn't canceled
    if (!goNext()) {
      log.debug("[fe] Cancelled");
      return STATUS_CANCELED;
    }
    // run job specific tasks
    boolean completed = runRequestedJob();
    if (!completed) {
      log.debug("[fe] Cancelled");
      return STATUS_CANCELED;
    }
    log.debug("[fe] " + PROCESS_ENDED + " " + getKey());
    return "success";
  }
Пример #3
0
  @Override
  public void type(
      Resource type,
      List<Pair<Resource, XSDDatatype>> simpleProperties,
      List<Pair<Resource, Object>> linkProperties,
      List<Pair<Resource, String>> geometryProperties)
      throws IOException {
    requestResponse.setFeatureIri(type);

    log.debug("[fe] registering (generic) output type for " + type);

    /*
     * List<String> layerSelectedProperties = layer
     * .getSelectedFeatureParams(session.getLanguage());
     */
    selectedProperties.add(0, "__fid");
    log.debug("- Property:" + "__fid" + " as 0");
    for (Pair<Resource, XSDDatatype> prop : simpleProperties) {

      log.debug("- Property:" + prop.getKey() + " as " + selectedProperties.size());
      selectedPropertiesIndex.put(prop.getKey(), selectedProperties.size());
      selectedProperties.add(prop.getKey().getLocalPart());
    }
    selectedProperties.add("__centerX");
    log.debug("- Property:" + "__centerX" + " as " + selectedProperties.size());
    selectedProperties.add("__centerY");
    log.debug("- Property:" + "__centerY" + " as " + selectedProperties.size());
  }
  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);
    }
  }
Пример #5
0
  public void handleAction(final FlowModel flowModel) throws OgcFlowException {

    WFSLayer wfsLayer = findWFSLayer(flowModel);
    log.debug("Drawing image for wfs layer '" + wfsLayer.getName(locale) + "'");
    List<Future<WFSResponseCapsule>> futures = new ArrayList<Future<WFSResponseCapsule>>();
    /* Create workers */
    log.debug("We have " + wfsLayer.getSelectedFeatureTypes().size() + " selected feature types");
    for (SelectedFeatureType sft : wfsLayer.getSelectedFeatureTypes()) {
      FeatureType ft = sft.getFeatureType();
      log.debug("Processing featuretype '", ft.getTitle(locale), "'...");

      /* Create filter */
      String geomName = ft.getBboxParameterName();
      FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());

      GetFeaturesWorker worker =
          new GetFeaturesWorker(sft, getExtendedMapViewBbox(ff, geomName, flowModel), false);
      Future<WFSResponseCapsule> future = WfsExecutorService.schedule(worker);
      futures.add(future);
    }

    /* collect results */
    FeatureCollection<SimpleFeatureType, SimpleFeature> features =
        WfsExecutorService.collectFeaturesFromFutures(futures);
    String[] bbox = getBbox(flowModel);
    Double bboxMinX = Double.parseDouble(bbox[0]);
    Double bboxMinY = Double.parseDouble(bbox[1]);
    Double bboxMaxX = Double.parseDouble(bbox[2]);
    Double bboxMaxY = Double.parseDouble(bbox[3]);

    MapContext mapContext = buildMapContext();
    ReferencedEnvelope bounds =
        new ReferencedEnvelope(
            bboxMaxX, bboxMinX, bboxMaxY, bboxMinY, mapContext.getCoordinateReferenceSystem());

    /* Add all found features */
    if (features != null && features.size() > 0) {
      log.debug("Parsing found " + features.size() + " features.");
      String styleString = wfsLayer.getStyle();

      // TODO: sld styles should be stored in the database
      if (styleString == null || "".equals(styleString)) {
        styleString =
            SLDStore.getSLD(
                wfsLayer
                    .getWmsName()); // MapLayerServiceNoDbImpl.getSldStyle(wfsLayer.getWmsName());
      }

      Style style = SLD.styles(createSLDStyle(styleString))[0];
      mapContext.addLayer(features, style);
    } else {
      log.debug("Parsing found no features.");
    }

    BufferedImage image = renderImageFromFeatures(flowModel, mapContext, bounds);
    /*image.getGraphics().setColor(new Color(1f, 0, 0));
    image.getGraphics().drawRect(1, 1, image.getWidth()-1, image.getHeight()-1);*/
    flowModel.put("image", image);
  }
 public List<Keyword> findKeywordsMatching(final String name) {
   if (name == null) {
     return Collections.emptyList();
   }
   log.debug("Finding keywords matching:", name);
   final List<Keyword> keyword =
       queryForList(getNameSpace() + ".find-by-name", name.toLowerCase());
   log.debug("Found keywords:", keyword);
   return keyword;
 }
 public List<Keyword> findKeywordsMatching(final String name, final String lang) {
   if (name == null) {
     return Collections.emptyList();
   }
   log.debug("Finding keywords matching:", name);
   final Keyword param = new Keyword();
   param.setValue(name.toLowerCase());
   param.setLang(lang);
   final List<Keyword> keyword = queryForList(getNameSpace() + ".find-by-name-and-lang", param);
   log.debug("Found keywords:", keyword);
   return keyword;
 }
Пример #8
0
  /**
   * Constructor for image of certain layer and style
   *
   * @param layer
   * @param styleName
   */
  public WFSImage(WFSLayerStore layer, String client, String styleName, String highlightStyleName) {
    if (layer == null || styleName == null) {
      log.error("Failed to construct image (undefined params)");
      return;
    }

    // check if tile buffer is given
    String tileBufferKey;
    if (styleName.startsWith(PREFIX_CUSTOM_STYLE)) {
      tileBufferKey = PREFIX_CUSTOM_STYLE;
    } else {
      tileBufferKey = styleName;
    }
    if (layer.getTileBuffer() != null && layer.getTileBuffer().containsKey(tileBufferKey)) {
      bufferSize = layer.getTileBuffer().get(tileBufferKey);
    }
    log.debug(tileBufferKey, "=", bufferSize);

    // TODO: possibility to change the custom style store key to sessionID (it is hard without
    // connection to get client)
    if (styleName.startsWith(PREFIX_CUSTOM_STYLE) && client != null) {
      try {
        this.customStyle = WFSCustomStyleStore.create(client, layer.getLayerId());
        if (this.customStyle == null) {
          this.style = null;
          log.error("WFSCustomStyleStore not created", client, layer.getLayerId());
          return;
        }
        this.customStyle.setGeometry(
            layer.getGMLGeometryProperty().replaceAll("^[^_]*:", "")); // set the geometry name
        log.debug(this.customStyle.getGeometry());

        if (highlightStyleName == null) {
          this.style = createCustomSLDStyle();
        } else {
          isHighlight = true;
          this.style = createCustomSLDStyle();
        }
      } catch (Exception e) {
        this.style = null;
        log.error(e, "JSON parsing failed for WFSCustomStyleStore");
        return;
      }
    } else if (highlightStyleName == null) {
      this.style = getSLDStyle(layer, styleName);
    } else {
      isHighlight = true;
      this.style = getSLDStyle(layer, highlightStyleName);
    }
  }
  public JSONObject getWMSFeatureInfo(final GFIRequestParams params) {

    final Map<String, String> headers = new HashMap<String, String>();
    headers.put(
        "User-Agent",
        "Mozilla/5.0 "
            + "(Windows; U; Windows NT 6.0; pl; rv:1.9.1.2) "
            + "Gecko/20090729 Firefox/3.5.2");
    headers.put("Referer", "/");
    headers.put("Cookie", "_ptifiut_");

    String gfiResponse;
    try {
      final String url = params.getGFIUrl();
      log.debug("Calling GFI url:", url);
      gfiResponse = IOHelper.getURL(url, headers);
      log.debug("Got GFI response:", gfiResponse);
    } catch (IOException e) {
      log.error(e, "Couldn't call GFI URL with params:", params);
      return null;
    }
    if (gfiResponse != null && !gfiResponse.isEmpty()) {
      final JSONObject response = new JSONObject();
      try {
        response.put(GetGeoPointDataService.TYPE, params.getLayer().getType());
        response.put(GetGeoPointDataService.LAYER_ID, params.getLayer().getId());
        final String xslt = params.getLayer().getXslt();
        if (xslt == null || xslt.isEmpty()) {
          response.put(
              GetGeoPointDataService.PRESENTATION_TYPE,
              GetGeoPointDataService.PRESENTATION_TYPE_TEXT);
          response.put(GetGeoPointDataService.CONTENT, gfiResponse);
        } else {
          final String transformedResult = transformResponse(xslt, gfiResponse);
          JSONObject respObj = new JSONObject(transformedResult);
          response.put(
              GetGeoPointDataService.PRESENTATION_TYPE,
              GetGeoPointDataService.PRESENTATION_TYPE_JSON);
          response.put(GetGeoPointDataService.CONTENT, respObj);
        }
      } catch (JSONException je) {
        log.error(je, "Couldn't construct GFI response from:", gfiResponse, "- params:", params);
        return null;
      }
      return response;
    }
    return null;
  }
Пример #10
0
  /**
   * 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;
  }
Пример #11
0
 public static JSONArray getStartupSequence(final View view) throws ViewException {
   final JSONArray startupSequence = new JSONArray();
   final List<Bundle> bundles = view.getBundles();
   log.debug("Got", bundles.size(), "states for view", view.getId());
   for (Bundle s : bundles) {
     final String startup = s.getStartup();
     final String name = s.getName();
     if (startup != null) {
       try {
         startupSequence.put(new JSONObject(startup));
       } catch (JSONException jsonex) {
         log.error(
             jsonex,
             "Malformed JSON in startup sequence fragment for bundle:",
             name,
             "- JSON:",
             startup);
       }
     } else {
       throw new ViewException(
           "Could not get startup sequence fragment for bundle '" + name + "'");
     }
   }
   return startupSequence;
 }
Пример #12
0
  public SimpleFeatureBuilder getAndSetFeatureBuilder(Resource type) {

    SimpleFeatureBuilder sfb = responseBuilders.get(type);
    if (sfb == null) {

      SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
      ftb.setName(type.getLocalPart());
      ftb.setNamespaceURI(type.getNs());

      // add a geometry property

      ftb.setCRS(crs); // set crs first
      ftb.add("geometry", Geometry.class, crs); // then add
      // geometry

      SimpleFeatureType schema = ftb.buildFeatureType();

      sfb = new SimpleFeatureBuilder(schema);

      responseBuilders.put(type, sfb);

      log.debug("[fe] creating featurebuilder for : " + type);
    }
    return sfb;
  }
Пример #13
0
  /**
   * Merge href sub features to main features
   *
   * @param jlist addtional features to where local hrefs point
   * @param res href property resourse
   */
  public void merge(List<JSONObject> jlist, Resource res) {
    // Get index of resource
    Integer keyInd = selectedPropertiesIndex.get(res);
    if (keyInd == null) return;

    try {
      // Loop features
      for (List lis : list) {
        // Href key
        Object val = lis.get(keyInd);
        if (val instanceof List) {
          ArrayList<String> vallist = (ArrayList<String>) val;
          List<Map<String, Object>> hrefFeas = new ArrayList<Map<String, Object>>();
          for (String lval : vallist) {
            if (lval == null) continue;
            lval = lval.replace("#", "");
            for (JSONObject js : jlist) {
              if (JSONHelper.getStringFromJSON(js, "id", "").equals(lval)) {
                hrefFeas.add(JSONHelper.getObjectAsMap(js));
                break;
              }
            }
          }
          // Replace refs with objects
          if (hrefFeas.size() > 0) lis.set(keyInd, hrefFeas);
        }
      }

    } catch (Exception ee) {
      log.debug("Local href subfeature merge failed:", ee);
    }
  }
Пример #14
0
  /**
   * Creates SLD style
   *
   * @param layer
   * @param styleName
   * @return style
   */
  private Style getSLDStyle(WFSLayerStore layer, String styleName) {
    Style style = null;
    log.debug("Trying to get style with name:", styleName);
    if (layer.getStyles().containsKey(styleName)) {
      style = createSLDStyle(layer.getStyles().get(styleName).getSLDStyle());
    } else if (STYLE_HIGHLIGHT.equals(styleName)) {
      style = createSLDStyle(layer.getSelectionSLDStyle());
    } else if (layer.getStyles().containsKey(STYLE_DEFAULT)) {
      style = createSLDStyle(layer.getStyles().get(STYLE_DEFAULT).getSLDStyle());
    }

    // if styles couldn't be parsed, use defaults
    if (style == null) {
      log.info("Layer style not customized or parsing failed. Using defaults.");
      if (STYLE_HIGHLIGHT.equals(styleName)) {
        // style = createDefaultHighlightSLDStyle(layer.getGMLGeometryProperty());
        // TODO: check if we really always want to use without namespace
        style = createDefaultHighlightSLDStyle(layer.getGMLGeometryPropertyNoNamespace());
      } else {
        style =
            createSLDStyle(
                WFSImage.class.getResourceAsStream(DEFAULT_SLD)); // getClass() (non-static)
      }
    }
    if (style == null) {
      // something is seriously wrong, even default styles can't be parsed
      log.error("Failed to get SLD style (even default failed)!!");
    }

    return style;
  }
 public Keyword findExactKeyword(final String name, final String language) {
   if (name == null) {
     return null;
   }
   log.debug("Finding keyword template by name:", name);
   final Keyword param = new Keyword();
   param.setValue(name.toLowerCase());
   param.setLang(language);
   final List<Keyword> keywords =
       queryForList(getNameSpace() + ".find-exact-by-name-and-lang", param);
   Keyword keyword = null;
   if (keywords.size() > 0) {
     keyword = keywords.get(0);
   }
   log.debug("Found keyword:", keyword);
   return keyword;
 }
 /** Send image parsing error */
 protected void imageParsingFailed(final String message) {
   log.debug("Image parsing failed");
   Map<String, Object> output = new HashMap<String, Object>();
   output.put(OUTPUT_LAYER_ID, this.layerId);
   output.put(OUTPUT_ONCE, true);
   output.put(OUTPUT_MESSAGE, message);
   this.service.addResults(session.getClient(), ResultProcessor.CHANNEL_ERROR, output);
 }
Пример #17
0
  @Override
  public void handleAction(ActionParameters params) throws ActionException {
    String jsessionid = params.getRequest().getSession().getId();

    // remove cache
    log.debug("deleting session:", jsessionid);
    WFSLayerPermissionsStore.destroy(jsessionid);
  }
  public boolean runHighlightJob() {
    if (!this.sendHighlight) {
      // highlight job with a flag for not sending images, what is going on in here?
      return true;
    }
    if (!this.requestHandler(null)) {
      return false;
    }
    this.featuresHandler();
    if (!goNext()) {
      return false;
    }
    // Send geometries, if requested as well
    if (this.session.isGeomRequest()) {
      this.sendWFSFeatureGeometries(
          this.geomValuesList, ResultProcessor.CHANNEL_FEATURE_GEOMETRIES);
    }
    log.debug("highlight image handling", this.features.size());
    // IMAGE HANDLING
    log.debug("sending");
    Location location = this.session.getLocation();
    if (this.image == null) {
      this.image =
          new WFSImage(
              this.layer,
              this.session.getClient(),
              this.session.getLayers().get(this.layerId).getStyleName(),
              JobType.HIGHLIGHT.toString());
    }
    BufferedImage bufferedImage =
        this.image.draw(this.session.getMapSize(), location, this.features);
    if (bufferedImage == null) {
      this.imageParsingFailed();
      throw new RuntimeException("Image parsing failed!");
    }

    Double[] bbox = location.getBboxArray();

    // cache (non-persistant)
    setImageCache(
        bufferedImage, JobType.HIGHLIGHT.toString() + "_" + this.session.getSession(), bbox, false);

    String url = createImageURL(JobType.HIGHLIGHT.toString(), bbox);
    this.sendWFSImage(url, bufferedImage, bbox, false, false);
    return true;
  }
  @Override
  public void init(StatisticalDatasource source) {
    layers = source.getLayers();

    config = new PxwebConfig(source.getConfigJSON(), source.getId());
    indicatorsParser = new PxwebIndicatorsParser(config);

    LOG.debug("pxweb layer mappings: ", layers);
  }
Пример #20
0
  public List<SimpleFeature> getAndSetListSimpleFeature(Resource type) {

    List<SimpleFeature> list = responseFeatures.get(type);
    if (list == null) {
      list = new LinkedList<SimpleFeature>();
      responseFeatures.put(type, list);
      log.debug("[fe] creating featureList for : " + type);
    }
    return list;
  }
Пример #21
0
 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;
 }
  /**
   * Sends list of features
   *
   * @param features
   * @param channel
   */
  protected void sendWFSFeatures(List<List<Object>> features, String channel) {
    if (features == null || features.size() == 0) {
      log.debug("No features to Send");
      return;
    }

    log.debug("#### Sending " + features.size() + "  FEATURES");

    Map<String, Object> output = new HashMap<String, Object>();
    output.put(OUTPUT_LAYER_ID, this.layerId);
    output.put(OUTPUT_FEATURES, features);
    if (channel.equals(ResultProcessor.CHANNEL_MAP_CLICK)
        || channel.equals(ResultProcessor.CHANNEL_FILTER)) {
      output.put(OUTPUT_KEEP_PREVIOUS, this.session.isKeepPrevious());
    }

    log.debug("Sending", features.size(), "features");
    this.service.addResults(this.session.getClient(), channel, output);
  }
 public List<Keyword> findSiblings(final Long id, final String language) {
   if (id == null) {
     return null;
   }
   final Keyword param = new Keyword();
   param.setId(id);
   param.setLang(language);
   final List<Keyword> synonyms =
       queryForList(getNameSpace() + ".find-siblings-by-id-and-lang", param);
   log.debug("Found " + synonyms.size() + " synonyms");
   return synonyms;
 }
Пример #24
0
 /**
  * Compares 2 JSONArrays for equality.
  *
  * @param jsonArray1
  * @param jsonArray2
  * @return
  */
 public static boolean isEqual(JSONArray jsonArray1, JSONArray jsonArray2) {
   if (jsonArray1.length() != jsonArray2.length()) {
     return false;
   }
   if (jsonArray1.length() == 0) {
     return true;
   }
   for (int i = 0; i < jsonArray1.length(); ++i) {
     try {
       final Object value1 = jsonArray1.get(i);
       final Object value2 = jsonArray2.get(i);
       if (value1 instanceof JSONObject && value2 instanceof JSONObject) {
         if (!isEqual((JSONObject) value1, (JSONObject) value2)) {
           log.debug(
               "Array content was JSONObjects but they were not equal:", value1, "!=", value2);
           return false;
         }
       } else if (value1 instanceof JSONArray && value2 instanceof JSONArray) {
         if (!isEqual((JSONArray) value1, (JSONArray) value2)) {
           log.debug(
               "Array content was JSONArrays but they were not equal:", value1, "!=", value2);
           return false;
         }
       } else if (value1 == null && value2 != null) {
         log.debug("Array1 had <null>, but Array2 had a value:", value2);
         return false;
       } else if (value1 != null && value2 == null) {
         log.debug("Array1 had value", value1, ", but Array2 had <null>");
         return false;
       } else if (value1 != null && value2 != null && !value1.equals(value2)) {
         log.debug("Array values didn't match:", value1, value2);
         return false;
       }
     } catch (Exception ex) {
       log.warn(ex, "Error comparing JSONArrays");
       return false;
     }
   }
   return true;
 }
  /**
   * Sends list of feature geometries
   *
   * @param geometries
   * @param channel
   */
  protected void sendWFSFeatureGeometries(List<List<Object>> geometries, String channel) {
    if (geometries == null || geometries.size() == 0) {
      log.warn("Failed to send feature geometries");
      return;
    }
    Map<String, Object> output = new HashMap<String, Object>();
    output.put(OUTPUT_LAYER_ID, this.layerId);
    output.put(OUTPUT_GEOMETRIES, geometries);
    output.put(OUTPUT_KEEP_PREVIOUS, this.session.isKeepPrevious());

    log.debug("Sending", geometries.size(), "geometries");
    this.service.addResults(this.session.getClient(), channel, output);
  }
Пример #26
0
 /**
  * Creates default highlight sld style by replacing geomtype
  *
  * @return sld
  */
 public Style createDefaultHighlightSLDStyle(String geom_type) {
   log.debug("Creating default highlight SLD for:", geom_type);
   InputStream resource = WFSImage.class.getResourceAsStream(HIGHLIGHT_SLD);
   try {
     String xml = IOHelper.readString(resource, "ISO-8859-1");
     xml = xml.replaceAll(GEOM_TYPE_PLACEHOLDER, geom_type);
     return createSLDStyle(xml);
   } catch (Exception e) {
     log.error(e, "Failed to get Default highlight SLD Style - geom type ", geom_type);
     log.error(resource);
   }
   return null;
 }
  public boolean runMapClickJob() {

    if (!this.requestHandler(null)) {
      // success, just no hits
      this.sendWFSFeatures(EMPTY_LIST, ResultProcessor.CHANNEL_MAP_CLICK);
      return true;
    }
    this.featuresHandler();
    if (!goNext()) {
      return false;
    }

    // features
    if (this.sendFeatures) {
      log.debug("Feature values list", this.featureValuesList);
      this.sendWFSFeatures(this.featureValuesList, ResultProcessor.CHANNEL_MAP_CLICK);
    } else {
      log.debug("No feature data!");
      this.sendWFSFeatures(EMPTY_LIST, ResultProcessor.CHANNEL_MAP_CLICK);
    }
    return true;
  }
Пример #28
0
  private View getBaseView(final JSONObject publisherInput, final User user)
      throws ActionException {

    if (user.isGuest()) {
      throw new ActionDeniedException("Trying to publish map, but couldn't determine user");
    }

    // not editing, use template view
    if (PUBLISHED_VIEW_TEMPLATE_ID == -1) {
      log.error("Publish template id not configured (property: view.template.publish)!");
      throw new ActionParamsException("Trying to publish map, but template isn't configured");
    }
    log.debug("Using template to create a new view");
    // Get publisher defaults
    View templateView = viewService.getViewWithConf(PUBLISHED_VIEW_TEMPLATE_ID);
    if (templateView == null) {
      log.error("Could not get template View with id:", PUBLISHED_VIEW_TEMPLATE_ID);
      throw new ActionParamsException("Could not get template View");
    }

    // clone a blank view based on template (so template doesn't get updated!!)
    final View view = templateView.cloneBasicInfo();
    final long viewId = publisherInput.optLong("id", -1);
    if (viewId != -1) {
      // check loaded view against user if we are updating a view
      log.debug("Loading view for editing:", viewId);
      final View existingView = viewService.getViewWithConf(viewId);
      if (user.getId() != existingView.getCreator()) {
        throw new ActionDeniedException("No permissions to update view with id:" + viewId);
      }
      // setup ids for updating a view
      view.setId(existingView.getId());
      view.setSupplementId(existingView.getSupplementId());
      view.setUuid(existingView.getUuid());
      view.setOldId(existingView.getOldId());
    }

    return view;
  }
Пример #29
0
 /**
  * Compares 2 JSONObjects for equality. Ignores property order and only matches on defined
  * properties and property values.
  *
  * @param jsonObject1
  * @param jsonObject2
  * @return
  */
 public static boolean isEqual(final JSONObject jsonObject1, final JSONObject jsonObject2) {
   if (jsonObject1 == null || JSONObject.getNames(jsonObject1) == null) {
     // if object 1 is null or empty -> object 2 should also be null or empty
     return (jsonObject2 == null || JSONObject.getNames(jsonObject2) == null);
   } else if (jsonObject2 == null || JSONObject.getNames(jsonObject2) == null) {
     return false;
   }
   final List<String> objectProperties1 = Arrays.asList(JSONObject.getNames(jsonObject1));
   Collections.sort(objectProperties1);
   final List<String> objectProperties2 = Arrays.asList(JSONObject.getNames(jsonObject2));
   Collections.sort(objectProperties2);
   // compare sorted propertynames
   if (!objectProperties1.equals(objectProperties2)) {
     log.debug(
         "Object:\n", objectProperties1, "didn't have same properties as:\n", objectProperties2);
     return false;
   }
   try {
     for (String key : objectProperties1) {
       final Object value1 = jsonObject1.get(key);
       final Object value2 = jsonObject2.get(key);
       if (value1 instanceof JSONObject) {
         if (!(value2 instanceof JSONObject)) {
           log.debug(value1, "was a JSONObject unlike", value2);
           return false;
         } else if (!isEqual((JSONObject) value1, (JSONObject) value2)) {
           log.debug("JSONObject recursion was not equal");
           return false;
         }
       } else if (value1 instanceof JSONArray) {
         if (!(value2 instanceof JSONArray)) {
           log.debug(value1, "was a JSONArray unlike", value2);
           return false;
         }
         if (!isEqual((JSONArray) value1, (JSONArray) value2)) {
           log.debug("JSONArrays were not equal");
           return false;
         }
       } else if (value1 == null) {
         if (value2 != null) {
           log.debug("value1 was <null>, but value2 was:" + value2);
           return false;
         }
       } else if (!value1.equals(value2)) {
         log.debug("Values were not equal:", value1, "!=", value2);
         return false;
       }
     }
   } catch (Exception ex) {
     log.warn(ex, "Error comparing JSONObjects");
     return false;
   }
   return true;
 }
Пример #30
0
  @Override
  public void end() throws IOException {

    for (Resource type : responseFeatures.keySet()) {
      List<SimpleFeature> sfc = getAndSetListSimpleFeature(type);

      SimpleFeatureCollection fc = DataUtilities.collection(sfc);

      responseCollections.put(type, fc);

      log.debug("[fe] type: " + type + " / fc: { len: " + fc.size() + "}");
    }
  }