Exemplo n.º 1
0
  public static void testOCCacheWithWaypoints() {
    final String geoCode = "OCDDD2";
    removeCacheCompletely(geoCode);
    Geocache cache = OkapiClient.getCache(geoCode);
    assertThat(cache).as("Cache from OKAPI").isNotNull();
    // cache should be stored to DB (to listID 0) when loaded above
    cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
    assert cache != null;
    assertThat(cache).isNotNull();
    assertThat(cache.getWaypoints()).hasSize(3);

    // load again
    cache.refreshSynchronous(null);
    assertThat(cache.getWaypoints()).hasSize(3);
  }
Exemplo n.º 2
0
  /**
   * This method constructs a <code>Point</code> for displaying in Locus
   *
   * @param cache
   * @param withWaypoints whether to give waypoints to Locus or not
   * @param withCacheDetails whether to give cache details (description, hint) to Locus or not
   *     should be false for all if more then 200 Caches are transferred
   * @return null, when the <code>Point</code> could not be constructed
   */
  private static Point getCachePoint(
      Geocache cache, boolean withWaypoints, boolean withCacheDetails) {
    if (cache == null || cache.getCoords() == null) {
      return null;
    }

    // create one simple point with location
    final Location loc = new Location("cgeo");
    loc.setLatitude(cache.getCoords().getLatitude());
    loc.setLongitude(cache.getCoords().getLongitude());

    final Point p = new Point(cache.getName(), loc);
    final PointGeocachingData pg = new PointGeocachingData();
    p.setGeocachingData(pg);

    // set data in Locus' cache
    pg.cacheID = cache.getGeocode();
    pg.available = !cache.isDisabled();
    pg.archived = cache.isArchived();
    pg.premiumOnly = cache.isPremiumMembersOnly();
    pg.name = cache.getName();
    pg.placedBy = cache.getOwnerDisplayName();
    final Date hiddenDate = cache.getHiddenDate();
    if (hiddenDate != null) {
      pg.hidden = ISO8601DATE.format(hiddenDate);
    }
    int locusId = toLocusType(cache.getType());
    if (locusId != NO_LOCUS_ID) {
      pg.type = locusId;
    }
    locusId = toLocusSize(cache.getSize());
    if (locusId != NO_LOCUS_ID) {
      pg.container = locusId;
    }
    if (cache.getDifficulty() > 0) {
      pg.difficulty = cache.getDifficulty();
    }
    if (cache.getTerrain() > 0) {
      pg.terrain = cache.getTerrain();
    }
    pg.found = cache.isFound();

    if (withWaypoints && cache.hasWaypoints()) {
      pg.waypoints = new ArrayList<>();
      for (Waypoint waypoint : cache.getWaypoints()) {
        if (waypoint == null || waypoint.getCoords() == null) {
          continue;
        }
        PointGeocachingDataWaypoint wp = new PointGeocachingDataWaypoint();
        wp.code = waypoint.getGeocode();
        wp.name = waypoint.getName();
        String locusWpId = toLocusWaypoint(waypoint.getWaypointType());
        if (locusWpId != null) {
          wp.type = locusWpId;
        }
        wp.lat = waypoint.getCoords().getLatitude();
        wp.lon = waypoint.getCoords().getLongitude();
        pg.waypoints.add(wp);
      }
    }

    // Other properties of caches. When there are many caches to be displayed
    // in Locus, using these properties can lead to Exceptions in Locus.
    // Should not be used if caches count > 200

    if (withCacheDetails) {
      pg.shortDescription = cache.getShortDescription();
      pg.longDescription = cache.getDescription();
      pg.encodedHints = cache.getHint();
    }

    return p;
  }