Exemplo n.º 1
0
 public List<Island> getIslandsByArea(
     Double longitude, Double latitude, Double distance, Integer maxResults) {
   Point center = new Point(latitude, longitude);
   GeocellQuery query = new GeocellQuery();
   List<Island> islands = null;
   islands =
       GeocellManager.proximitySearch(
           center, maxResults, distance, Island.class, query, getPersistenceManager());
   return islands;
 }
Exemplo n.º 2
0
  /**
   * Performs a query over all objects of type <T>
   *
   * @param <T> any object that extends LocationCapable
   * @param terms Array of string search terms
   * @param location a Point to use as the center of the query
   * @param maxResults maximum number of results returned
   * @param maxDistance maximum distance to search in meters
   * @param t instance of T
   * @return list of <T> matching the search terms
   */
  @SuppressWarnings("unchecked")
  public static <T extends TDPersistable> Set<T> searchGeoItems(
      String[] terms, Point location, int maxResults, int maxDistance, T t) {
    final List<Object> paramList;
    String queryS = "";
    String paramS = "";
    final GeocellQuery baseQuery;

    if (null != terms) {
      paramList = new ArrayList<Object>();

      for (int i = 0; i < terms.length; i++) {
        if (i > 0) {
          queryS += " && searchTerms.contains(s" + i + ")";
        } else {
          queryS += "searchTerms.contains(s" + i + ")";
        }

        paramList.add(terms[i].toLowerCase());

        if (paramS.length() > 0) {
          paramS += ", String s" + i;
        } else {
          paramS += "String s" + i;
        }
      }
      Logger.getLogger(TAG).info("Creating query with params: " + paramList);
      baseQuery = new GeocellQuery(queryS, paramS, paramList);
    } else {
      Logger.getLogger(TAG).info("Creating query without params.");
      baseQuery = new GeocellQuery("", "", new ArrayList<Object>());
    }

    try {
      Logger.getLogger(TAG).info("Sending query to GeocellManager.");
      return new HashSet<T>(
          (Collection<? extends T>)
              GeocellManager.proximityFetch(
                  location,
                  maxResults,
                  maxDistance,
                  t,
                  baseQuery,
                  PMF.get().getPersistenceManager()));
    } catch (Exception e) {
      Logger.getLogger(TAG).info("GeocellManager failed: " + e.getMessage());
      e.printStackTrace();
    }

    return null;
  }
Exemplo n.º 3
0
  @Override
  public List<RetailerDTO> displayRetailersWithinDistance(
      Double latitude, Double longitude, Double distance) {

    com.beoui.geocell.model.Point centerPoint =
        new com.beoui.geocell.model.Point(latitude, longitude);

    List<Object> params = new ArrayList<Object>();
    params.add("RETAILER");
    // GeocellQuery baseQuery = new GeocellQuery("lastName == lastNameParam", "String
    // lastNameParam", params);
    GeocellQuery baseQuery =
        new GeocellQuery("category== categoryParam", "String categoryParam", params);
    List<Retailer> objects = null;
    try {
      objects =
          GeocellManager.proximityFetch(
              centerPoint,
              GSTCloudServerConstants.maxSearchResults,
              distance,
              Retailer.class,
              baseQuery,
              pm);
      // Assert.assertTrue(objects.size() > 0);
    } catch (Exception e) {

      e.printStackTrace();
    }

    // List<Retailer> Retailerlist = (List<Retailers>) pm.newQuery(query).execute();

    List<RetailerDTO> tempList = new ArrayList<RetailerDTO>();

    int rowCount = objects.size();
    for (int ctr = 0; ctr < rowCount; ctr++) {
      Retailer temp = objects.get(ctr);
      tempList.add(
          new RetailerDTO(
              temp.getCategory(),
              temp.getName(),
              temp.getAddress(),
              temp.getLatitude(),
              temp.getLongitude(),
              true));
    }

    return tempList;
  }
Exemplo n.º 4
0
  /**
   * Searches for all geo-aware items near a {@link Point}.
   *
   * @param <T> type of item to search for.
   * @param location {@link Point} as the center of the search
   * @param maxResults maximum number of results
   * @param maxDistance maximum distance to search in meters
   * @param t instance of the type T
   * @return {@link List} of items of type T
   */
  @SuppressWarnings("unchecked")
  public static <T extends TDPersistable> List<T> searchGeoItems(
      Point location, int maxResults, int maxDistance, T t) {
    final GeocellQuery baseQuery = new GeocellQuery("", "", new ArrayList<Object>());

    try {
      return (List<T>)
          GeocellManager.proximityFetch(
              location, maxResults, maxDistance, t, baseQuery, PMF.get().getPersistenceManager());
    } catch (Exception e) {
      e.printStackTrace();
      // TODO: handle exception properly
    }

    return null;
  }
  /**
   * Actualiza la posición del surfero. En caso de que el surfero entre o salga de una playa se
   * actualizara el estado de estas playas.
   *
   * @param surfer
   * @param latitude
   * @param longitude
   */
  public static Session updateSurferLocation(Surfer surfer, double latitude, double longitude) {
    EntityManager em = entityManager();
    Session session = null;

    if (!em.contains(surfer)) {
      throw new IllegalStateException("El surfero debe ser una untidad gestionada");
      // Si no es gestionada no se reflejan los cambios!, asi que gestionala!
      // TODO esto podria cambiarse por un assert, improved production performance
    }

    // Location as a Point
    Point location = new Point(latitude, longitude);

    // Generate Geocells
    List<String> cells = GeocellManager.generateGeoCell(location);

    // Save instance
    surfer.setLatitude(latitude);
    surfer.setLongitude(longitude);
    surfer.setGeoCellsData(cells);

    // Se busca si la posicion forma parte de una playa
    Spot spot = SpotService.findSpotByLocation(latitude, longitude);
    Session actual = findActiveSession(surfer);

    // Esta el surfer en una playa?
    if (SessionService.hasActiveSession(surfer)) {
      // Ha salido o cambiado de playa el surfer?
      if (spot == null || spot.getId() != actual.getSpotId()) {
        SessionService.endSession(surfer);
      }
    }

    // Ha cambiado o entrado en una nueva playa?
    if (spot != null && (actual == null || spot.getId() != actual.getSpotId())) {
      session = SessionService.beginSession(surfer, spot);
    }

    return session;
  }
Exemplo n.º 6
0
 @Override
 public void create(Island island) {
   island.setCells(
       GeocellManager.generateGeoCell(new Point(island.getLatitude(), island.getLongitude())));
   super.create(island);
 }
Exemplo n.º 7
0
  /**
   * Filters dishes based on a center latitude/longitude pair, distance, number of results, and a
   * list of {@link Tag}s. <br>
   * FIXME: {@link HashSet}s do not hold order. As such, the supplied {@link Comparator} cannot be
   * relied upon. This needs to be fixed.
   *
   * @param maxResults number of results to return
   * @param tagKeys {@link List} of {@link Tag} {@link Key}s to filter by
   * @param maxDistance maximum distance in meters
   * @param lat latitude of center of search
   * @param lng longitude of center of search
   * @param offset number of results to ignore for paging through results
   * @param comparator comparator to use to override the natural sorting of results
   * @return {@link List} of {@link Dish}es
   * @deprecated You can't sort a {@link Set}!
   */
  @Deprecated
  public static Set<Dish> filterDishes(
      int maxResults,
      Set<Key> tagKeys,
      double maxDistance,
      double lat,
      double lng,
      int offset,
      Comparator<Dish> comparator) {
    String queryS = "";
    List<Object> paramList = new ArrayList<Object>();
    String paramS = "";
    List<Dish> result = new ArrayList<Dish>();
    maxResults += offset;

    Key[] tagKeyArray = tagKeys.toArray(new Key[tagKeys.size()]);

    for (int i = 0; i < tagKeyArray.length; i++) {
      if (i > 0) {
        queryS += " && tags.contains(k" + i + ")";
      } else {
        queryS += "tags.contains(k" + i + ")";
      }

      paramList.add(tagKeyArray[i]);

      if (paramS.length() > 0) {
        paramS += ", " + Key.class.getName() + " k" + i;
      } else {
        paramS += Key.class.getName() + " k" + i;
      }
    }

    GeocellQuery baseQuery = null;

    if (paramList.size() > 0) {
      baseQuery = new GeocellQuery(queryS, paramS, paramList);
    } else {
      baseQuery = new GeocellQuery("", "", paramList);
    }

    result =
        GeocellManager.proximityFetch(
            new Point(lat, lng),
            maxResults,
            maxDistance,
            new Dish(),
            baseQuery,
            PMF.get().getPersistenceManager());

    // Check within offset, if not return empty set
    if (offset >= result.size()) return new HashSet<Dish>();

    //		Logger.getLogger(TAG).info("BEFORE SORT: " + result);

    // Run Dish sort
    //		if (null != comparator)
    //			Collections.sort(result, comparator);

    //		Logger.getLogger(TAG).info("AFTER SORT: " + result);

    // Get the section of the list desired
    if (offset > 0 && result.size() > 0) {
      result = result.subList(offset, result.size());
    }

    // Return the dishes
    return new HashSet<Dish>(result);
  }
Exemplo n.º 8
0
  /**
   * Performs a query over all objects of type <T> along with filters
   *
   * @param <T> any object that extends LocationCapable
   * @param terms Array of string search terms
   * @param location a Point to use as the center of the query
   * @param maxResults maximum number of results returned
   * @param maxDistance maximum distance to search in meters
   * @param t instance of T
   * @param pm PersistentManager to be used to create new queries
   * @param tagKeys a list of {@link Key} objects representing the tags to filter by
   * @return list of <T> matching the search terms
   */
  @SuppressWarnings("unchecked")
  public static <T extends TDPersistable> List<T> searchGeoItemsWithFilter(
      String[] terms,
      Point location,
      int maxResults,
      double maxDistance,
      T t,
      int offset,
      List<Key> tagKeys,
      Comparator<T> comparator) {
    final List<Object> paramList;
    String queryS = "";
    String paramS = "";
    final GeocellQuery baseQuery;

    maxResults += offset;

    paramList = new ArrayList<Object>();
    boolean paramsAdded = false;
    if (tagKeys.size() > 0) {
      for (int i = 0; i < tagKeys.size(); i++) {
        if (i > 0) {
          queryS += " && tags.contains(k" + i + ")";
        } else {
          queryS += "tags.contains(k" + i + ")";
        }

        paramList.add(tagKeys.get(i));

        if (paramS.length() > 0) {
          paramS += ", " + Key.class.getName() + " k" + i;
        } else {
          paramS += Key.class.getName() + " k" + i;
        }
      }
      paramsAdded = true;
    }

    if (null != terms) {

      for (int i = 0; i < terms.length; i++) {
        if (i > 0 || paramsAdded) {
          queryS += " && searchTerms.contains(s" + i + ")";
        } else {
          queryS += "searchTerms.contains(s" + i + ")";
        }

        paramList.add(terms[i].toLowerCase());

        if (paramS.length() > 0 || paramsAdded) {
          paramS += ", String s" + i;
        } else {
          paramS += "String s" + i;
        }
      }

      paramsAdded = true;
    }

    if (paramsAdded) {
      baseQuery = new GeocellQuery(queryS, paramS, paramList);
    } else {
      baseQuery = new GeocellQuery("", "", paramList);
    }
    List<T> result = new ArrayList<T>();
    try {
      result =
          (List<T>)
              GeocellManager.proximityFetch(
                  location,
                  maxResults,
                  maxDistance,
                  t,
                  baseQuery,
                  PMF.get().getPersistenceManager());
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (comparator != null) {
      Collections.sort(result, comparator);
    }

    if (offset >= result.size()) {
      return new ArrayList<T>();
    } else if (offset > 0 && result.size() > 0) {
      // skip the first _offset_ results
      return result.subList(offset, result.size());
    } else {
      return result;
    }
  }