Changeset 7531 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-09-13T00:40:11+02:00 (10 years ago)
Author:
bastiK
Message:

applied #10503 - Note download code (patch by ToeBee)

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadAction.java

    r7509 r7531  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
     13import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
    1314import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    1415import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     
    5455                Main.worker.submit(new PostDownloadHandler(task, future));
    5556            }
     57
     58            //TODO: This eventually needs to be a checkbox in the UI
     59            //For now I'm adding it as a hidden feature since this is still a work in progress
     60            if (Main.pref.getBoolean("osm.notes.enableDownload", false)) {
     61                DownloadNotesTask task = new DownloadNotesTask();
     62                Future<?> future = task.download(false, area, null);
     63                Main.worker.submit(new PostDownloadHandler(task, future));
     64            }
    5665        }
    5766    }
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r7434 r7531  
    2323import org.openstreetmap.josm.Main;
    2424import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
     25import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesTask;
    2526import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeCompressedTask;
    2627import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask;
     
    5960        addDownloadTaskClass(DownloadOsmTask.class);
    6061        addDownloadTaskClass(DownloadGpsTask.class);
     62        addDownloadTaskClass(DownloadNotesTask.class);
    6163        addDownloadTaskClass(DownloadOsmChangeTask.class);
    6264        addDownloadTaskClass(DownloadOsmUrlTask.class);
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r7033 r7531  
    66import java.io.IOException;
    77import java.io.InputStream;
    8 
     8import java.util.List;
     9
     10import org.openstreetmap.josm.Main;
    911import org.openstreetmap.josm.data.Bounds;
    1012import org.openstreetmap.josm.data.gpx.GpxData;
     13import org.openstreetmap.josm.data.notes.Note;
    1114import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    154157        }
    155158    }
     159
     160    @Override
     161    public List<Note> parseNotes(Integer noteLimit, Integer daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException {
     162        progressMonitor.beginTask("Downloading notes");
     163        noteLimit = checkNoteLimit(noteLimit);
     164        daysClosed = checkDaysClosed(daysClosed);
     165        String url = new StringBuilder()
     166        .append("notes?limit=")
     167        .append(noteLimit)
     168        .append("&closed=")
     169        .append(daysClosed)
     170        .append("&bbox=")
     171        .append(lon1)
     172        .append(",").append(lat1)
     173        .append(",").append(lon2)
     174        .append(",").append(lat2)
     175        .toString();
     176        try {
     177            InputStream is = getInputStream(url, progressMonitor.createSubTaskMonitor(1, false));
     178            NoteReader reader = new NoteReader(is);
     179            return reader.parse();
     180        } catch (IOException e) {
     181            throw new OsmTransferException(e);
     182        } catch (SAXException e) {
     183            throw new OsmTransferException(e);
     184        } finally {
     185            progressMonitor.finishTask();
     186        }
     187    }
     188
     189    private Integer checkNoteLimit(Integer limit) {
     190        if (limit == null) {
     191            limit = Main.pref.getInteger("osm.notes.downloadLimit", 1000);
     192        }
     193        if (limit > 10000) {
     194            Main.error("Requested note limit is over API hard limit of 10000. Reducing to 10000.");
     195            limit = 10000;
     196        }
     197        if (limit < 1) {
     198            Main.error("Requested note limit is less than 1. Setting to 1.");
     199            limit = 1;
     200        }
     201        Main.debug("returning note limit: " + limit);
     202        return limit;
     203    }
     204
     205    private Integer checkDaysClosed(Integer days) {
     206        if (days == null) {
     207            days = Main.pref.getInteger("osm.notes.daysClosed", 1);
     208        }
     209        if (days < -1) {
     210            Main.error("Requested days closed must be greater than -1");
     211            days = -1;
     212        }
     213        Main.debug("returning days closed: " + days);
     214        return days;
     215    }
     216
    156217}
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r7509 r7531  
    66import java.io.IOException;
    77import java.io.InputStream;
     8import java.util.ArrayList;
     9import java.util.List;
    810
    911import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
    1012import org.openstreetmap.josm.data.gpx.GpxData;
     13import org.openstreetmap.josm.data.notes.Note;
    1114import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    106109    }
    107110
     111    @Override
     112    public List<Note> parseRawNotes(final ProgressMonitor progressMonitor) throws OsmTransferException {
     113        return doParse(new NoteParser(progressMonitor, Compression.NONE), progressMonitor);
     114    }
     115
     116    @Override
     117    public List<Note> parseRawNotesBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException {
     118        return doParse(new NoteParser(progressMonitor, Compression.BZIP2), progressMonitor);
     119    }
     120
    108121    protected class OsmParser extends Parser<DataSet> {
    109122        protected OsmParser(ProgressMonitor progressMonitor, Compression compression) {
     
    154167        }
    155168    }
     169
     170    protected class NoteParser extends Parser<List<Note>> {
     171
     172        public NoteParser(ProgressMonitor progressMonitor, Compression compression) {
     173            super(progressMonitor, compression);
     174        }
     175
     176        @Override
     177        public List<Note> parse() throws OsmTransferException, IllegalDataException, IOException, SAXException {
     178            in = getInputStream(url, progressMonitor.createSubTaskMonitor(1, true));
     179            if (in == null) {
     180                return new ArrayList<Note>();
     181            }
     182            progressMonitor.subTask(tr("Downloading OSM notes..."));
     183            NoteReader reader = new NoteReader(compression.getUncompressedInputStream(in));
     184            return reader.parse();
     185        }
     186    }
    156187}
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r7434 r7531  
    2020import org.openstreetmap.josm.Main;
    2121import org.openstreetmap.josm.data.gpx.GpxData;
     22import org.openstreetmap.josm.data.notes.Note;
    2223import org.openstreetmap.josm.data.osm.DataSet;
    2324import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    349350        return gpxParsedProperly;
    350351    }
     352
     353    /**
     354     * Downloads notes from the API, given API limit parameters
     355     *
     356     * @param noteLimit How many notes to download. Defaults to 1000 if not specified. API has a hard limit of 10000
     357     * @param daysClosed Return notes closed this many days in the past. -1 means all notes, ever. 0 means only unresolved notes.
     358     * @param progressMonitor Progress monitor for user feedback
     359     * @return List of notes returned by the API
     360     * @throws OsmTransferException if any errors happen
     361     */
     362    public List<Note> parseNotes(Integer noteLimit, Integer daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException {
     363        return null;
     364    }
     365
     366    /**
     367     * Downloads notes from a given raw URL. The URL is assumed to be complete and no API limits are added
     368     *
     369     * @param progressMonitor
     370     * @return A list of notes parsed from the URL
     371     * @throws OsmTransferException
     372     */
     373    public List<Note> parseRawNotes(final ProgressMonitor progressMonitor) throws OsmTransferException {
     374        return null;
     375    }
     376
     377    /**
     378     * Download notes from a URL that contains a bzip2 compressed notes dump file
     379     * @param progressMonitor
     380     * @return A list of notes parsed from the URL
     381     * @throws OsmTransferException
     382     */
     383    public List<Note> parseRawNotesBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException {
     384        return null;
     385    }
    351386}
Note: See TracChangeset for help on using the changeset viewer.