Changeset 35078 in osm for applications/editors/josm/plugins/reverter/src
- Timestamp:
- 2019-08-11T02:08:18+02:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/reverter/src/reverter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java
r34999 r35078 14 14 import java.util.Iterator; 15 15 import java.util.List; 16 import java.util.Map.Entry; 16 17 17 18 import org.openstreetmap.josm.command.Command; … … 222 223 trn("Downloading history for {0} object", "Downloading history for {0} objects", num, num)), num + 1); 223 224 try { 225 HashMap<Long,Integer> nodeList = new HashMap<>(), 226 wayList = new HashMap<>(), 227 relationList = new HashMap<>(); 228 224 229 for (HashSet<HistoryOsmPrimitive> collection : Arrays.asList(updated, deleted)) { 225 230 for (HistoryOsmPrimitive entry : collection) { … … 228 233 if (earliestVersion == null || earliestVersion <= 1) 229 234 throw new OsmTransferException(tr("Unexpected data in changeset #{1}", String.valueOf(changesetId))); 230 readObjectVersion(rdr, id, earliestVersion - 1, progressMonitor); 231 if (progressMonitor.isCanceled()) return; 235 switch (id.getType()) { 236 case NODE: nodeList.put(id.getUniqueId(), earliestVersion - 1); break; 237 case WAY: wayList.put(id.getUniqueId(), earliestVersion - 1); break; 238 case RELATION: relationList.put(id.getUniqueId(), earliestVersion - 1); break; 239 default: throw new AssertionError(); 240 } 232 241 } 233 242 } 243 Logging.info("New fetcher is started"); 244 rdr.readMultiObjects(OsmPrimitiveType.NODE, nodeList, progressMonitor); 245 rdr.readMultiObjects(OsmPrimitiveType.WAY, wayList, progressMonitor); 246 rdr.readMultiObjects(OsmPrimitiveType.RELATION, relationList, progressMonitor); 247 if (progressMonitor.isCanceled()) return; 248 // If multi-read failed, retry with regular read 249 for (Entry<Long,Integer> entry : nodeList.entrySet()) { 250 if (progressMonitor.isCanceled()) return; 251 readObjectVersion(rdr, new SimplePrimitiveId(entry.getKey(),OsmPrimitiveType.NODE), entry.getValue(), progressMonitor); 252 } 253 for (Entry<Long,Integer> entry : wayList.entrySet()) { 254 if (progressMonitor.isCanceled()) return; 255 readObjectVersion(rdr, new SimplePrimitiveId(entry.getKey(),OsmPrimitiveType.WAY), entry.getValue(), progressMonitor); 256 } 257 for (Entry<Long,Integer> entry : relationList.entrySet()) { 258 if (progressMonitor.isCanceled()) return; 259 readObjectVersion(rdr, new SimplePrimitiveId(entry.getKey(),OsmPrimitiveType.RELATION), entry.getValue(), progressMonitor); 260 } 261 if (progressMonitor.isCanceled()) return; 234 262 nds = rdr.parseOsm(progressMonitor.createSubTaskMonitor(1, true)); 235 263 for (OsmPrimitive p : nds.allPrimitives()) { -
applications/editors/josm/plugins/reverter/src/reverter/MultiOsmReader.java
r34960 r35078 5 5 import java.io.InputStreamReader; 6 6 7 import javax.xml.stream.XMLStreamException; 8 9 import org.openstreetmap.josm.data.osm.Node; 10 import org.openstreetmap.josm.data.osm.Relation; 11 import org.openstreetmap.josm.data.osm.Way; 7 12 import org.openstreetmap.josm.io.IllegalDataException; 8 13 import org.openstreetmap.josm.io.OsmReader; … … 33 38 prepareDataSet(); 34 39 } 40 41 public ParseCallback callback; 42 43 @Override 44 protected Node parseNode() throws XMLStreamException { 45 Node node = super.parseNode(); 46 if (callback != null) { 47 callback.primitiveParsed(node.getPrimitiveId()); 48 } 49 return node; 50 } 51 @Override 52 protected Way parseWay() throws XMLStreamException { 53 Way way = super.parseWay(); 54 if (callback != null) { 55 callback.primitiveParsed(way.getPrimitiveId()); 56 } 57 return way; 58 } 59 @Override 60 protected Relation parseRelation() throws XMLStreamException { 61 Relation relation = super.parseRelation(); 62 if (callback != null) { 63 callback.primitiveParsed(relation.getPrimitiveId()); 64 } 65 return relation; 66 } 35 67 } -
applications/editors/josm/plugins/reverter/src/reverter/OsmServerMultiObjectReader.java
r34917 r35078 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.List; 10 import java.util.Map; 11 import java.util.Map.Entry; 8 12 9 13 import org.openstreetmap.josm.data.osm.DataSet; 10 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 15 import org.openstreetmap.josm.data.osm.PrimitiveId; 16 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 12 17 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 18 import org.openstreetmap.josm.io.IllegalDataException; 14 19 import org.openstreetmap.josm.io.OsmServerReader; 15 20 import org.openstreetmap.josm.io.OsmTransferException; 21 import org.openstreetmap.josm.tools.Logging; 16 22 17 23 public class OsmServerMultiObjectReader extends OsmServerReader { … … 38 44 } 39 45 } 46 private List<String> makeQueryStrings(OsmPrimitiveType type, Map<Long,Integer> list) { 47 List<String> result = new ArrayList<>((list.size()+maxQueryIds-1)/maxQueryIds); 48 StringBuilder sb = new StringBuilder(); 49 int cnt=0; 50 for (Entry<Long,Integer> entry : list.entrySet()) { 51 if (cnt == 0) { 52 sb.append(type.getAPIName()); 53 sb.append("s?"); 54 sb.append(type.getAPIName()); 55 sb.append("s="); 56 } else { 57 sb.append(","); 58 } 59 sb.append(entry.getKey()); 60 sb.append("v"); 61 sb.append(entry.getValue()); 62 cnt++; 63 if (cnt >=maxQueryIds) { 64 result.add(sb.toString()); 65 sb.setLength(0); 66 cnt = 0; 67 } 68 } 69 if (cnt>0) { 70 result.add(sb.toString()); 71 } 72 return result; 73 } 74 75 protected static final int maxQueryIds = 128; 76 public void readMultiObjects(OsmPrimitiveType type, Map<Long,Integer> list, ProgressMonitor progressMonitor) { 77 for (String query : makeQueryStrings(type,list)) { 78 if (progressMonitor.isCanceled()) { 79 return; 80 } 81 rdr.callback = new ParseCallback() { 82 @Override 83 public void primitiveParsed(PrimitiveId id) { 84 if (id.getType() == type && list.remove(id.getUniqueId()) != null) { 85 progressMonitor.worked(1); 86 } 87 } 88 }; 89 try (InputStream in = getInputStream(query, NullProgressMonitor.INSTANCE)) { 90 rdr.addData(in); 91 } catch (IOException | IllegalDataException | OsmTransferException e) { 92 Logging.error(e); 93 } finally { 94 rdr.callback = null; 95 } 96 } 97 } 98 40 99 41 100 /**
Note:
See TracChangeset
for help on using the changeset viewer.