Ejemplo n.º 1
0
  public JSONObject toJSON(boolean includeReviews) {
    JSONObject json = new JSONObject();
    try {
      if (categories.size() > 0) {
        JSONArray jarray = new JSONArray();
        for (String str : categories) {
          jarray.put(str);
        }
        json.put("categories", jarray);
      }
      if (pid != null && pid.length() > 0) json.put("pid", pid);
      if (getName() != null) json.put("name", getName());

      if (getAccreditations() != null && getAccreditations().length() > 0)
        json.put("accreditations", getAccreditations());
      if (getBrands() != null && getBrands().length() > 0) json.put("brands", getBrands());
      if (getPayment_types_accepted() != null && getPayment_types_accepted().length() > 0)
        json.put("payment", getPayment_types_accepted());
      if (getAka() != null && getAka().length() > 0) json.put("aka", getAka());
      if (getAvg_rating() != null && getAvg_rating().length() > 0)
        json.put("avg_rating", getAvg_rating());
      if (getBiz_since() != null && getBiz_since().length() > 0)
        json.put("in_biz_since", getBiz_since());
      if (getLanguages() != null && getLanguages().length() > 0)
        json.put("languages", getLanguages());

      if (getWhereId() != null) json.put("whereid", getWhereId());
      if (getAddress() != null) {
        Address addy = getAddress();
        json.put("location", addy.toJSON());
      }

      if (getLatlng() != null) {
        json.put("lat", getLatlng()[0]);
        json.put("long", getLatlng()[1]);
      }

      if (hours != null && hours.length() > 0) json.put("hours", hours);
      if (YPurl != null) json.put("ypurl", YPurl);
      if (biz_url != null && biz_url.length() > 0) json.put("biz_url", biz_url);

      if (includeReviews)
        if (reviews.size() > 0) {
          JSONArray jarray = new JSONArray();
          for (JSONObject jobj : reviews) {
            jarray.put(jobj);
          }
          json.put("reviews", jarray);
        }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return json;
  }
Ejemplo n.º 2
0
  /**
   * Convert a localeze record to a place object
   *
   * @param record - input localeze record
   * @return place
   */
  public Place toPlace(String record) {
    String[] bits = record.split("\\|");
    if (bits == null) {
      throw new RuntimeException("bits is null");
    }
    if (bits.length < 47) {
      throw new RuntimeException("bits.length (" + bits.length + ") < 47");
    }
    // new place
    Place place = new Place();
    place.setSource(Place.Source.LOCALEZE);
    place.setNativeId(bits[0].trim());
    place.setShortname(bits[3]);
    place.setName(bits[4]);

    // calc whereid
    String whereIDtoWrite;
    long pid = Long.parseLong(place.getNativeId());

    if (mappedExistingIDs.containsKey(pid)) {
      // this pid already exists, pull whereid from .map
      whereIDtoWrite = new Long(mappedExistingIDs.get(pid)).toString();
    } else {
      // increment and get max, use as new whereid
      whereIDtoWrite = new Long(++startId_).toString();
    }

    place.setWhereId(whereIDtoWrite);

    // address
    Address addr = new Address();
    String street1 = new String();
    for (int i = 6; i < 10; i++) {
      street1 += bits[i] + " ";
    }
    street1 = street1.replaceAll("\\s+", " ").trim();
    addr.setAddress1(street1);
    String street2 = new String();
    for (int i = 10; i < 13; i++) {
      street2 += bits[i] + " ";
    }
    street2 = street2.replaceAll("\\s+", " ").trim();
    addr.setAddress2(street2);
    addr.setNeighborhood(bits[13].trim());
    addr.setCity(bits[14].trim());
    addr.setState(bits[15].trim());

    boolean stringIsBlank = (bits[17].isEmpty()) || (bits[17] == null);
    addr.setZip(stringIsBlank ? bits[16].trim() : bits[16].trim() + "-" + bits[17].trim());

    place.setAddress(addr);

    // geo
    double lat = Double.parseDouble(bits[45].trim());
    double lng = Double.parseDouble(bits[46].trim());
    place.setLatlng(new double[] {lat, lng});
    String geohash = GeoHashUtils.encode(lat, lng);
    place.setGeohash(geohash);

    // phone
    place.setPhone(bits[34].trim() + bits[35].trim() + bits[36].trim());

    return place;
  }