コード例 #1
0
ファイル: Postgres.java プロジェクト: n-/baleen
  /** Get the table name with the schema and prefix if one is set */
  public String getTableName(String table) {
    String ret = table;

    if (!Strings.isNullOrEmpty(prefix)) {
      ret = prefix + ret;
    }

    if (!Strings.isNullOrEmpty(schema)) {
      ret = schema + "." + ret;
    }

    return ret;
  }
コード例 #2
0
ファイル: Postgres.java プロジェクト: n-/baleen
  /** Add CRS (assumed to be EPSG:4326) to a GeoJSON string if it doesn't already exist */
  public static String addCrsToGeoJSON(String geoJson) throws BaleenException {
    if (Strings.isNullOrEmpty(geoJson)) {
      return geoJson;
    }

    try {
      Map<String, Object> geoJsonObj = MAPPER.readValue(geoJson, MAP_LIKE_TYPE);
      if (geoJsonObj.get("crs") == null) {
        Map<String, Object> crs = new HashMap<>();
        crs.put("type", "name");

        Map<String, Object> srid = new HashMap<>();
        srid.put("name", "EPSG:4326");
        crs.put("properties", srid);

        geoJsonObj.put("crs", crs);

        return MAPPER.writeValueAsString(geoJsonObj);
      } else {
        return geoJson;
      }
    } catch (Exception e) {
      throw new BaleenException("Unable to parse GeoJSON", e);
    }
  }
コード例 #3
0
  @Override
  public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
    long totalHits = response.getHits().totalHits();
    List<T> results = new ArrayList<T>();
    for (SearchHit hit : response.getHits()) {
      if (hit != null) {
        T result = null;
        if (!Strings.isNullOrEmpty(hit.sourceAsString())) {
          result = mapEntity(hit.sourceAsString(), clazz);
        } else {
          result = mapEntity(hit.getFields().values(), clazz);
        }
        setPersistentEntityId(result, hit.getId(), clazz);
        results.add(result);
      }
    }
    List<FacetResult> facets = new ArrayList<FacetResult>();
    if (response.getFacets() != null) {
      for (Facet facet : response.getFacets()) {
        FacetResult facetResult = DefaultFacetMapper.parse(facet);
        if (facetResult != null) {
          facets.add(facetResult);
        }
      }
    }

    return new FacetedPageImpl<T>(results, pageable, totalHits, facets);
  }