Example #1
0
 private static Date parseDate(final String date) {
   final String strippedDate = PATTERN_TIMEZONE.matcher(date).replaceAll("$1$20");
   try {
     return ISO8601DATEFORMAT.parse(strippedDate);
   } catch (final ParseException e) {
     Log.e("OkapiClient.parseDate", e);
   }
   return null;
 }
Example #2
0
  public static LogResult postLog(
      final Geocache cache,
      final LogType logType,
      final Calendar date,
      final String log,
      final String logPassword,
      final OCApiConnector connector) {
    final Parameters params = new Parameters("cache_code", cache.getGeocode());
    params.add("logtype", logType.oc_type);
    params.add("comment", log);
    params.add("comment_format", "plaintext");
    params.add("when", LOG_DATE_FORMAT.format(date.getTime()));
    if (logType.equals(LogType.NEEDS_MAINTENANCE)) {
      params.add("needs_maintenance", "true");
    }
    if (logPassword != null) {
      params.add("password", logPassword);
    }

    final ObjectNode data = request(connector, OkapiService.SERVICE_SUBMIT_LOG, params).data;

    if (data == null) {
      return new LogResult(StatusCode.LOG_POST_ERROR, "");
    }

    try {
      if (data.get("success").asBoolean()) {
        return new LogResult(StatusCode.NO_ERROR, data.get("log_uuid").asText());
      }

      return new LogResult(StatusCode.LOG_POST_ERROR, "");
    } catch (final NullPointerException e) {
      Log.e("OkapiClient.postLog", e);
    }
    return new LogResult(StatusCode.LOG_POST_ERROR, "");
  }
Example #3
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;
  }
Example #4
0
    @Override
    public final void endElement(final String uri, final String localName, final String qName)
        throws SAXException {
      try {
        if (localName.equalsIgnoreCase("geolutin_id")) {
          trackable.setGeocode(content);
        }
        if (localName.equalsIgnoreCase("nom")) {
          trackable.setName(content);
        }
        if (localName.equalsIgnoreCase("description")) {
          trackable.setDetails(content);
          isMultiline = false;
        }
        if (localName.equalsIgnoreCase("esprit_nom")) {
          if (isInApparition) {
            logEntryBuilder.setAuthor(content);
          } else {
            trackable.setOwner(content);
          }
        }
        if (StringUtils.isNotBlank(content) && localName.equalsIgnoreCase("date_naissance")) {
          final Date date = DATE_FORMAT.parse(content);
          trackable.setReleased(date);
        }
        if (StringUtils.isNotBlank(content) && localName.equalsIgnoreCase("distance_parcourue")) {
          trackable.setDistance(Float.parseFloat(content));
        }
        if (localName.equalsIgnoreCase("date_apparition_disparition")) {
          logEntryBuilder.setDate(DATE_FORMAT.parse(content).getTime());
        }
        if (localName.equalsIgnoreCase("commentaires")) {
          logEntryBuilder.setLog(content);
        }
        if (localName.equalsIgnoreCase("type")) {
          logEntryBuilder.setLogType(getLogType(content));
        }

        if (localName.equalsIgnoreCase("geolutin")) {
          trackable.setLogs(logsEntries);

          // manage spotted field
          if (!logsEntries.isEmpty()) {
            // retrieve the first logEntry
            final LogEntry lastLog = logsEntries.get(0);
            if (lastLog.getType() == LogType.PLACED_IT) {
              // it's in a cache
              trackable.setSpottedType(Trackable.SPOTTED_CACHE);
              trackable.setSpottedName(lastLog.cacheName);
            } else if (lastLog.getType() == LogType.RETRIEVED_IT) {
              trackable.setSpottedName(lastLog.author);
              // it's in someone hands
              trackable.setSpottedType(Trackable.SPOTTED_USER);
              trackable.setSpottedName(lastLog.author);
            } else {
              Log.e("GeolutinsHandler.endElement unknown logtype:" + lastLog.getType());
            }
          }
        }
        if (localName.equalsIgnoreCase("apparition_disparition")) {
          isInApparition = false;
          logsEntries.add(logEntryBuilder.build());
        }
      } catch (final ParseException | NumberFormatException e) {
        Log.e("Parsing GeoLutins", e);
      }
    }