예제 #1
0
 /**
  * Creates a new Geotag entry for the given attachment and track. NOTE: I'm basically ignoring
  * errors here for now. Note that DataAccessExceptions do NOT actually propagate up the call stack
  * from here. They are caught and logged, but do NOT stop or undo the creation of the attachment.
  *
  * @param fileName
  * @param track
  * @throws DataAccessException
  */
 public void createGeotag(String fileName, GpsTrack track) throws DataAccessException {
   try {
     Attachment attachment = new AttachmentDao().findByFileName(fileName);
     Geotag tag = new Geotag(track.getCenter());
     tag.setAttachmentId(attachment.getAttachmentId());
     tag.setMapId(attachment.getAttachmentId());
     new GeotagDao().create(tag);
   } catch (Exception e) {
     log.error("Unable to create geotag for attachment.", e);
   }
 }
예제 #2
0
  /**
   * Creates a GPX-formatted file attachment for the given entry.
   *
   * @param user
   * @param entryId
   * @param fileName
   * @param activityId
   * @param track
   * @param track
   */
  public void createAttachment(
      User user, int entryId, String fileName, String title, String activityId, GpsTrack track)
      throws DataAccessException, IOException {
    Attachment a = new Attachment();
    a.setUserName(user.getUserName());
    a.setUserId(user.getUserId());
    a.setEntryId(entryId);
    a.setFileType("map");
    a.setFileName(fileName);
    a.setActivityId(activityId);
    a.setTitle(title);

    GpxFormatter formatter = new GpxFormatter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<GpsTrack> tracks = new ArrayList<GpsTrack>();
    tracks.add(track);

    formatter.format(tracks, baos);
    log.debug(new String(baos.toByteArray()));
    a.setBytes(baos.toByteArray());

    new AttachmentDao().create(a);
  }