Changeset 10006 in josm for trunk/src/org
- Timestamp:
- 2016-03-18T00:41:42+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r9371 r10006 180 180 } 181 181 182 /** 183 * Returns the changeset for this history primitive. 184 * @return the changeset for this history primitive 185 */ 182 186 public Changeset getChangeset() { 183 187 return changeset; 184 188 } 185 189 190 /** 191 * Sets the changeset for this history primitive. 192 * @param changeset the changeset for this history primitive 193 */ 186 194 public void setChangeset(Changeset changeset) { 187 195 this.changeset = changeset; -
trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java
r9078 r10006 7 7 import java.awt.Component; 8 8 import java.io.IOException; 9 import java. text.MessageFormat;9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 11 import java.util.HashSet; 12 import java.util.List; 12 13 import java.util.Set; 13 14 14 15 import org.openstreetmap.josm.data.osm.Changeset; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;17 17 import org.openstreetmap.josm.data.osm.PrimitiveId; 18 import org.openstreetmap.josm.data.osm.SimplePrimitiveId;19 18 import org.openstreetmap.josm.data.osm.history.History; 20 19 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; … … 22 21 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 23 22 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 23 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 24 24 import org.openstreetmap.josm.io.ChangesetQuery; 25 25 import org.openstreetmap.josm.io.OsmServerChangesetReader; … … 30 30 31 31 /** 32 * Loads the object history of an collection of objects from the 33 * server. 32 * Loads the object history of a collection of objects from the server. 34 33 * 35 34 * It provides a fluent API for configuration. … … 38 37 * 39 38 * <pre> 40 * HistoryLoadTask task 41 * .add( 1, OsmPrimitiveType.NODE)42 * .add( 1233, OsmPrimitiveType.WAY)43 * .add( 37234, OsmPrimitveType.RELATION)39 * HistoryLoadTask task = new HistoryLoadTask() 40 * .add(node) 41 * .add(way) 42 * .add(relation) 44 43 * .add(aHistoryItem); 45 44 * 46 45 * Main.worker.execute(task); 47 *48 46 * </pre> 49 47 */ … … 52 50 private boolean canceled; 53 51 private Exception lastException; 54 private final Set<PrimitiveId> toLoad ;52 private final Set<PrimitiveId> toLoad = new HashSet<>(); 55 53 private HistoryDataSet loadedData; 56 54 private OsmServerHistoryReader reader; … … 61 59 public HistoryLoadTask() { 62 60 super(tr("Load history"), true); 63 toLoad = new HashSet<>();64 61 } 65 62 … … 75 72 super(parent, tr("Load history"), true); 76 73 CheckParameterUtil.ensureParameterNotNull(parent, "parent"); 77 toLoad = new HashSet<>();78 }79 80 /**81 * Adds an object whose history is to be loaded.82 *83 * @param id the object id84 * @param type the object type85 * @return this task86 */87 public HistoryLoadTask add(long id, OsmPrimitiveType type) {88 if (id <= 0)89 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got {1}.", "id", id));90 CheckParameterUtil.ensureParameterNotNull(type, "type");91 SimplePrimitiveId pid = new SimplePrimitiveId(id, type);92 toLoad.add(pid);93 return this;94 74 } 95 75 … … 115 95 public HistoryLoadTask add(HistoryOsmPrimitive primitive) { 116 96 CheckParameterUtil.ensureParameterNotNull(primitive, "primitive"); 117 toLoad.add(primitive.getPrimitiveId()); 118 return this; 97 return add(primitive.getPrimitiveId()); 119 98 } 120 99 … … 128 107 public HistoryLoadTask add(History history) { 129 108 CheckParameterUtil.ensureParameterNotNull(history, "history"); 130 toLoad.add(history.getPrimitiveId()); 131 return this; 109 return add(history.getPrimitiveId()); 132 110 } 133 111 … … 142 120 public HistoryLoadTask add(OsmPrimitive primitive) { 143 121 CheckParameterUtil.ensureValidPrimitiveId(primitive, "primitive"); 144 toLoad.add(primitive.getPrimitiveId()); 145 return this; 122 return add(primitive.getPrimitiveId()); 146 123 } 147 124 … … 194 171 break; 195 172 } 196 String msg = ""; 197 switch(pid.getType()) { 198 case NODE: msg = marktr("Loading history for node {0}"); break; 199 case WAY: msg = marktr("Loading history for way {0}"); break; 200 case RELATION: msg = marktr("Loading history for relation {0}"); break; 201 } 202 progressMonitor.indeterminateSubTask(tr(msg, 203 Long.toString(pid.getUniqueId()))); 173 String msg = getLoadingMessage(pid); 174 progressMonitor.indeterminateSubTask(tr(msg, Long.toString(pid.getUniqueId()))); 204 175 reader = null; 205 HistoryDataSet ds = null;176 HistoryDataSet ds; 206 177 try { 207 178 reader = new OsmServerHistoryReader(pid.getType(), pid.getUniqueId()); 208 ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false)); 209 // load corresponding changesets (mostly for changeset comment) 210 for (final Changeset i : new OsmServerChangesetReader().queryChangesets( 211 new ChangesetQuery().forChangesetIds(ds.getChangesetIds()), progressMonitor.createSubTaskMonitor(1, false))) { 212 ds.putChangeset(i); 213 } 179 ds = loadHistory(reader, progressMonitor); 214 180 } catch (OsmTransferException e) { 215 181 if (canceled) … … 225 191 } 226 192 193 protected static HistoryDataSet loadHistory(OsmServerHistoryReader reader, ProgressMonitor progressMonitor) throws OsmTransferException { 194 HistoryDataSet ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false)); 195 // load corresponding changesets (mostly for changeset comment) 196 OsmServerChangesetReader changesetReader = new OsmServerChangesetReader(); 197 List<Long> changesetIds = new ArrayList<>(ds.getChangesetIds()); 198 199 // query changesets 100 by 100 (OSM API limit) 200 int n = ChangesetQuery.MAX_CHANGESETS_NUMBER; 201 for (int i = 0; i < changesetIds.size(); i += n) { 202 for (Changeset c : changesetReader.queryChangesets( 203 new ChangesetQuery().forChangesetIds(changesetIds.subList(i, Math.min(i + n, changesetIds.size()))), 204 progressMonitor.createSubTaskMonitor(1, false))) { 205 ds.putChangeset(c); 206 } 207 } 208 209 return ds; 210 } 211 212 protected static String getLoadingMessage(PrimitiveId pid) { 213 switch (pid.getType()) { 214 case NODE: 215 return marktr("Loading history for node {0}"); 216 case WAY: 217 return marktr("Loading history for way {0}"); 218 case RELATION: 219 return marktr("Loading history for relation {0}"); 220 default: 221 return ""; 222 } 223 } 224 225 /** 226 * Determines if this task has ben canceled. 227 * @return {@code true} if this task has ben canceled 228 */ 227 229 public boolean isCanceled() { 228 230 return canceled; 229 231 } 230 232 233 /** 234 * Returns the last exception that occured during loading, if any. 235 * @return the last exception that occured during loading, or {@code null} 236 */ 231 237 public Exception getLastException() { 232 238 return lastException; -
trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java
r8840 r10006 16 16 import java.util.Map.Entry; 17 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.data.Bounds; 19 20 import org.openstreetmap.josm.data.coor.LatLon; … … 23 24 24 25 public class ChangesetQuery { 26 27 /** 28 * Maximum number of changesets returned by the OSM API call "/changesets?" 29 */ 30 public static int MAX_CHANGESETS_NUMBER = 100; 25 31 26 32 /** … … 234 240 public ChangesetQuery forChangesetIds(Collection<Long> changesetIds) { 235 241 CheckParameterUtil.ensureParameterNotNull(changesetIds, "changesetIds"); 242 if (changesetIds.size() > MAX_CHANGESETS_NUMBER) { 243 Main.warn("Changeset query built with more than " + MAX_CHANGESETS_NUMBER + " changeset ids (" + changesetIds.size() + ")"); 244 } 236 245 this.changesetIds = changesetIds; 237 246 return this; -
trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
r8540 r10006 73 73 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) { 74 74 if (in == null) 75 return null;75 return Collections.emptyList(); 76 76 monitor.indeterminateSubTask(tr("Downloading changesets ...")); 77 77 result = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
Note:
See TracChangeset
for help on using the changeset viewer.