001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005import static org.openstreetmap.josm.tools.I18n.trn; 006 007import java.io.IOException; 008import java.io.InputStream; 009import java.net.HttpURLConnection; 010import java.util.ArrayList; 011import java.util.Collection; 012import java.util.Collections; 013import java.util.HashSet; 014import java.util.Iterator; 015import java.util.LinkedHashSet; 016import java.util.List; 017import java.util.Set; 018import java.util.concurrent.Callable; 019import java.util.concurrent.CompletionService; 020import java.util.concurrent.ExecutionException; 021import java.util.concurrent.ExecutorCompletionService; 022import java.util.concurrent.ExecutorService; 023import java.util.concurrent.Executors; 024import java.util.concurrent.Future; 025 026import org.openstreetmap.josm.data.osm.DataSet; 027import org.openstreetmap.josm.data.osm.DataSetMerger; 028import org.openstreetmap.josm.data.osm.Node; 029import org.openstreetmap.josm.data.osm.OsmPrimitive; 030import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 031import org.openstreetmap.josm.data.osm.PrimitiveId; 032import org.openstreetmap.josm.data.osm.Relation; 033import org.openstreetmap.josm.data.osm.RelationMember; 034import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 035import org.openstreetmap.josm.data.osm.Way; 036import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 037import org.openstreetmap.josm.gui.progress.ProgressMonitor; 038import org.openstreetmap.josm.spi.preferences.Config; 039import org.openstreetmap.josm.tools.Logging; 040import org.openstreetmap.josm.tools.Utils; 041 042/** 043 * Retrieves a set of {@link OsmPrimitive}s from an OSM server using the so called 044 * Multi Fetch API. 045 * 046 * Usage: 047 * <pre> 048 * MultiFetchServerObjectReader reader = MultiFetchServerObjectReader() 049 * .append(2345,2334,4444) 050 * .append(new Node(72343)); 051 * reader.parseOsm(); 052 * if (!reader.getMissingPrimitives().isEmpty()) { 053 * Logging.info("There are missing primitives: " + reader.getMissingPrimitives()); 054 * } 055 * if (!reader.getSkippedWays().isEmpty()) { 056 * Logging.info("There are skipped ways: " + reader.getMissingPrimitives()); 057 * } 058 * </pre> 059 */ 060public class MultiFetchServerObjectReader extends OsmServerReader { 061 /** 062 * the max. number of primitives retrieved in one step. Assuming IDs with 10 digits, 063 * this leads to a max. request URL of ~ 1900 Bytes ((10 digits + 1 Separator) * 170), 064 * which should be safe according to the 065 * <a href="http://www.boutell.com/newfaq/misc/urllength.html">WWW FAQ</a>. 066 */ 067 private static final int MAX_IDS_PER_REQUEST = 170; 068 069 private final Set<Long> nodes; 070 private final Set<Long> ways; 071 private final Set<Long> relations; 072 private Set<PrimitiveId> missingPrimitives; 073 private final DataSet outputDataSet; 074 075 /** 076 * Constructs a {@code MultiFetchServerObjectReader}. 077 */ 078 protected MultiFetchServerObjectReader() { 079 nodes = new LinkedHashSet<>(); 080 ways = new LinkedHashSet<>(); 081 relations = new LinkedHashSet<>(); 082 this.outputDataSet = new DataSet(); 083 this.missingPrimitives = new LinkedHashSet<>(); 084 } 085 086 /** 087 * Creates a new instance of {@link MultiFetchServerObjectReader} or {@link MultiFetchOverpassObjectReader} 088 * depending on the {@link OverpassDownloadReader#FOR_MULTI_FETCH preference}. 089 * 090 * @return a new instance 091 * @since 9241 092 */ 093 public static MultiFetchServerObjectReader create() { 094 return create(OverpassDownloadReader.FOR_MULTI_FETCH.get()); 095 } 096 097 /** 098 * Creates a new instance of {@link MultiFetchServerObjectReader} or {@link MultiFetchOverpassObjectReader} 099 * depending on the {@code fromMirror} parameter. 100 * 101 * @param fromMirror {@code false} for {@link MultiFetchServerObjectReader}, {@code true} for {@link MultiFetchOverpassObjectReader} 102 * @return a new instance 103 * @since 15520 (changed visibility) 104 */ 105 public static MultiFetchServerObjectReader create(final boolean fromMirror) { 106 if (fromMirror) { 107 return new MultiFetchOverpassObjectReader(); 108 } else { 109 return new MultiFetchServerObjectReader(); 110 } 111 } 112 113 /** 114 * Remembers an {@link OsmPrimitive}'s id. The id will 115 * later be fetched as part of a Multi Get request. 116 * 117 * Ignore the id if it represents a new primitives. 118 * 119 * @param id the id 120 */ 121 protected void remember(PrimitiveId id) { 122 if (id.isNew()) return; 123 switch(id.getType()) { 124 case NODE: nodes.add(id.getUniqueId()); break; 125 case WAY: ways.add(id.getUniqueId()); break; 126 case RELATION: relations.add(id.getUniqueId()); break; 127 default: throw new AssertionError(); 128 } 129 } 130 131 /** 132 * appends a {@link OsmPrimitive} id to the list of ids which will be fetched from the server. 133 * 134 * @param ds the {@link DataSet} to which the primitive belongs 135 * @param id the primitive id 136 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 137 * {@link OsmPrimitiveType#RELATION RELATION} 138 * @return this 139 */ 140 public MultiFetchServerObjectReader append(DataSet ds, long id, OsmPrimitiveType type) { 141 OsmPrimitive p = ds.getPrimitiveById(id, type); 142 switch(type) { 143 case NODE: 144 return appendNode((Node) p); 145 case WAY: 146 return appendWay((Way) p); 147 case RELATION: 148 return appendRelation((Relation) p); 149 default: 150 return this; 151 } 152 } 153 154 /** 155 * appends a {@link Node} id to the list of ids which will be fetched from the server. 156 * 157 * @param node the node (ignored, if null) 158 * @return this 159 */ 160 public MultiFetchServerObjectReader appendNode(Node node) { 161 if (node == null) return this; 162 remember(node.getPrimitiveId()); 163 return this; 164 } 165 166 /** 167 * appends a {@link Way} id and the list of ids of nodes the way refers to the list of ids which will be fetched from the server. 168 * 169 * @param way the way (ignored, if null) 170 * @return this 171 */ 172 public MultiFetchServerObjectReader appendWay(Way way) { 173 if (way == null) return this; 174 if (way.isNew()) return this; 175 for (Node node: !recursesDown() ? way.getNodes() : Collections.<Node>emptyList()) { 176 if (!node.isNew()) { 177 remember(node.getPrimitiveId()); 178 } 179 } 180 remember(way.getPrimitiveId()); 181 return this; 182 } 183 184 /** 185 * appends a {@link Relation} id to the list of ids which will be fetched from the server. 186 * 187 * @param relation the relation (ignored, if null) 188 * @return this 189 */ 190 protected MultiFetchServerObjectReader appendRelation(Relation relation) { 191 if (relation == null) return this; 192 if (relation.isNew()) return this; 193 remember(relation.getPrimitiveId()); 194 for (RelationMember member : !recursesDown() ? relation.getMembers() : Collections.<RelationMember>emptyList()) { 195 // avoid infinite recursion in case of cyclic dependencies in relations 196 if (OsmPrimitiveType.from(member.getMember()) == OsmPrimitiveType.RELATION 197 && relations.contains(member.getMember().getId())) { 198 continue; 199 } 200 if (!member.getMember().isIncomplete()) { 201 append(member.getMember()); 202 } 203 } 204 return this; 205 } 206 207 /** 208 * appends an {@link OsmPrimitive} to the list of ids which will be fetched from the server. 209 * @param primitive the primitive 210 * @return this 211 */ 212 public MultiFetchServerObjectReader append(OsmPrimitive primitive) { 213 if (primitive instanceof Node) { 214 return appendNode((Node) primitive); 215 } else if (primitive instanceof Way) { 216 return appendWay((Way) primitive); 217 } else if (primitive instanceof Relation) { 218 return appendRelation((Relation) primitive); 219 } 220 return this; 221 } 222 223 /** 224 * appends a list of {@link OsmPrimitive} to the list of ids which will be fetched from the server. 225 * 226 * @param primitives the list of primitives (ignored, if null) 227 * @return this 228 * 229 * @see #append(OsmPrimitive) 230 */ 231 public MultiFetchServerObjectReader append(Collection<? extends OsmPrimitive> primitives) { 232 if (primitives == null) return this; 233 for (OsmPrimitive primitive : primitives) { 234 append(primitive); 235 } 236 return this; 237 } 238 239 /** 240 * extracts a subset of max {@link #MAX_IDS_PER_REQUEST} ids from <code>ids</code> and 241 * replies the subset. The extracted subset is removed from <code>ids</code>. 242 * 243 * @param ids a set of ids 244 * @return the subset of ids 245 */ 246 protected Set<Long> extractIdPackage(Set<Long> ids) { 247 Set<Long> pkg = new HashSet<>(); 248 if (ids.isEmpty()) 249 return pkg; 250 if (ids.size() > MAX_IDS_PER_REQUEST) { 251 Iterator<Long> it = ids.iterator(); 252 for (int i = 0; i < MAX_IDS_PER_REQUEST; i++) { 253 pkg.add(it.next()); 254 } 255 ids.removeAll(pkg); 256 } else { 257 pkg.addAll(ids); 258 ids.clear(); 259 } 260 return pkg; 261 } 262 263 /** 264 * builds the Multi Get request string for a set of ids and a given {@link OsmPrimitiveType}. 265 * 266 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 267 * {@link OsmPrimitiveType#RELATION RELATION} 268 * @param idPackage the package of ids 269 * @return the request string 270 */ 271 protected String buildRequestString(final OsmPrimitiveType type, Set<Long> idPackage) { 272 return type.getAPIName() + "s?" + type.getAPIName() + "s=" + Utils.join(",", idPackage); 273 } 274 275 protected void rememberNodesOfIncompleteWaysToLoad(DataSet from) { 276 for (Way w: from.getWays()) { 277 if (w.hasIncompleteNodes()) { 278 for (Node n: w.getNodes()) { 279 if (n.isIncomplete()) { 280 nodes.add(n.getId()); 281 } 282 } 283 } 284 } 285 } 286 287 /** 288 * merges the dataset <code>from</code> to {@link #outputDataSet}. 289 * 290 * @param from the other dataset 291 */ 292 protected void merge(DataSet from) { 293 final DataSetMerger visitor = new DataSetMerger(outputDataSet, from); 294 visitor.merge(); 295 } 296 297 /** 298 * fetches a set of ids of a given {@link OsmPrimitiveType} from the server 299 * 300 * @param ids the set of ids 301 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 302 * {@link OsmPrimitiveType#RELATION RELATION} 303 * @param progressMonitor progress monitor 304 * @throws OsmTransferException if an error occurs while communicating with the API server 305 */ 306 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException { 307 String msg; 308 final String baseUrl = getBaseUrl(); 309 switch (type) { 310 // CHECKSTYLE.OFF: SingleSpaceSeparator 311 case NODE: msg = tr("Fetching a package of nodes from ''{0}''", baseUrl); break; 312 case WAY: msg = tr("Fetching a package of ways from ''{0}''", baseUrl); break; 313 case RELATION: msg = tr("Fetching a package of relations from ''{0}''", baseUrl); break; 314 // CHECKSTYLE.ON: SingleSpaceSeparator 315 default: throw new AssertionError(); 316 } 317 progressMonitor.setTicksCount(ids.size()); 318 progressMonitor.setTicks(0); 319 // The complete set containing all primitives to fetch 320 Set<Long> toFetch = new HashSet<>(ids); 321 // Build a list of fetchers that will download smaller sets containing only MAX_IDS_PER_REQUEST (200) primitives each. 322 // we will run up to MAX_DOWNLOAD_THREADS concurrent fetchers. 323 int threadsNumber = Config.getPref().getInt("osm.download.threads", OsmApi.MAX_DOWNLOAD_THREADS); 324 threadsNumber = Utils.clamp(threadsNumber, 1, OsmApi.MAX_DOWNLOAD_THREADS); 325 final ExecutorService exec = Executors.newFixedThreadPool( 326 threadsNumber, Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY)); 327 CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec); 328 List<Future<FetchResult>> jobs = new ArrayList<>(); 329 while (!toFetch.isEmpty()) { 330 jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor))); 331 } 332 // Run the fetchers 333 for (int i = 0; i < jobs.size() && !isCanceled(); i++) { 334 progressMonitor.subTask(msg + "... " + progressMonitor.getTicks() + '/' + progressMonitor.getTicksCount()); 335 try { 336 FetchResult result = ecs.take().get(); 337 if (result.rc404 != null) { 338 List<Long> toSplit = new ArrayList<>(result.rc404); 339 int n = toSplit.size() / 2; 340 jobs.add(ecs.submit(new Fetcher(type, new HashSet<>(toSplit.subList(0, n)), progressMonitor))); 341 jobs.add(ecs.submit(new Fetcher(type, new HashSet<>(toSplit.subList(n, toSplit.size())), progressMonitor))); 342 } 343 if (result.missingPrimitives != null) { 344 missingPrimitives.addAll(result.missingPrimitives); 345 } 346 if (result.dataSet != null && !isCanceled()) { 347 rememberNodesOfIncompleteWaysToLoad(result.dataSet); 348 merge(result.dataSet); 349 } 350 } catch (InterruptedException | ExecutionException e) { 351 Logging.error(e); 352 } 353 } 354 exec.shutdown(); 355 // Cancel requests if the user chose to 356 if (isCanceled()) { 357 for (Future<FetchResult> job : jobs) { 358 job.cancel(true); 359 } 360 } 361 } 362 363 /** 364 * invokes one or more Multi Gets to fetch the {@link OsmPrimitive}s and replies 365 * the dataset of retrieved primitives. Note that the dataset includes non visible primitives too! 366 * In contrast to a simple Get for a node, a way, or a relation, a Multi Get always replies 367 * the latest version of the primitive (if any), even if the primitive is not visible (i.e. if 368 * visible==false). 369 * 370 * Invoke {@link #getMissingPrimitives()} to get a list of primitives which have not been 371 * found on the server (the server response code was 404) 372 * 373 * @return the parsed data 374 * @throws OsmTransferException if an error occurs while communicating with the API server 375 * @see #getMissingPrimitives() 376 * 377 */ 378 @Override 379 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 380 int n = nodes.size() + ways.size() + relations.size(); 381 progressMonitor.beginTask(trn("Downloading {0} object from ''{1}''", 382 "Downloading {0} objects from ''{1}''", n, n, OsmApi.getOsmApi().getBaseUrl())); 383 try { 384 missingPrimitives = new HashSet<>(); 385 if (isCanceled()) return null; 386 fetchPrimitives(ways, OsmPrimitiveType.WAY, progressMonitor); 387 if (isCanceled()) return null; 388 fetchPrimitives(nodes, OsmPrimitiveType.NODE, progressMonitor); 389 if (isCanceled()) return null; 390 fetchPrimitives(relations, OsmPrimitiveType.RELATION, progressMonitor); 391 if (outputDataSet != null) { 392 outputDataSet.deleteInvisible(); 393 } 394 return outputDataSet; 395 } finally { 396 progressMonitor.finishTask(); 397 } 398 } 399 400 /** 401 * replies the set of ids of all primitives for which a fetch request to the 402 * server was submitted but which are not available from the server (the server 403 * replied a return code of 404) 404 * 405 * @return the set of ids of missing primitives 406 */ 407 public Set<PrimitiveId> getMissingPrimitives() { 408 return missingPrimitives; 409 } 410 411 /** 412 * Whether this reader fetches nodes when loading ways, or members when loading relations. 413 * 414 * @return {@code true} if the reader recurses down 415 */ 416 protected boolean recursesDown() { 417 return false; 418 } 419 420 /** 421 * The class holding the results given by {@link Fetcher}. 422 * It is only a wrapper of the resulting {@link DataSet} and the collection of {@link PrimitiveId} that could not have been loaded. 423 */ 424 protected static class FetchResult { 425 426 /** 427 * The resulting data set 428 */ 429 public final DataSet dataSet; 430 431 /** 432 * The collection of primitive ids that could not have been loaded 433 */ 434 public final Set<PrimitiveId> missingPrimitives; 435 436 private Set<Long> rc404; 437 438 /** 439 * Constructs a {@code FetchResult} 440 * @param dataSet The resulting data set 441 * @param missingPrimitives The collection of primitive ids that could not have been loaded 442 */ 443 public FetchResult(DataSet dataSet, Set<PrimitiveId> missingPrimitives) { 444 this.dataSet = dataSet; 445 this.missingPrimitives = missingPrimitives; 446 } 447 } 448 449 /** 450 * The class that actually download data from OSM API. 451 * Several instances of this class are used by {@link MultiFetchServerObjectReader} (one per set of primitives to fetch). 452 * The inheritance of {@link OsmServerReader} is only explained by the need to have a distinct OSM connection by {@code Fetcher} instance. 453 * @see FetchResult 454 */ 455 protected class Fetcher extends OsmServerReader implements Callable<FetchResult> { 456 457 private final Set<Long> pkg; 458 private final OsmPrimitiveType type; 459 private final ProgressMonitor progressMonitor; 460 461 /** 462 * Constructs a {@code Fetcher} 463 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 464 * {@link OsmPrimitiveType#RELATION RELATION} 465 * @param idsPackage The set of primitives ids to fetch 466 * @param progressMonitor The progress monitor 467 */ 468 public Fetcher(OsmPrimitiveType type, Set<Long> idsPackage, ProgressMonitor progressMonitor) { 469 this.pkg = idsPackage; 470 this.type = type; 471 this.progressMonitor = progressMonitor; 472 } 473 474 @Override 475 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 476 // This method is implemented because of the OsmServerReader inheritance, but not used, 477 // as the main target of this class is the call() method. 478 return fetch(progressMonitor).dataSet; 479 } 480 481 @Override 482 public FetchResult call() throws Exception { 483 return fetch(progressMonitor); 484 } 485 486 /** 487 * fetches the requested primitives and updates the specified progress monitor. 488 * @param progressMonitor the progress monitor 489 * @return the {@link FetchResult} of this operation 490 * @throws OsmTransferException if an error occurs while communicating with the API server 491 */ 492 protected FetchResult fetch(ProgressMonitor progressMonitor) throws OsmTransferException { 493 try { 494 return multiGetIdPackage(type, pkg, progressMonitor); 495 } catch (OsmApiException e) { 496 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 497 if (pkg.size() > 4) { 498 FetchResult res = new FetchResult(null, null); 499 res.rc404 = pkg; 500 return res; 501 } 502 Logging.info(tr("Server replied with response code 404, retrying with an individual request for each object.")); 503 return singleGetIdPackage(type, pkg, progressMonitor); 504 } else { 505 throw e; 506 } 507 } 508 } 509 510 @Override 511 protected String getBaseUrl() { 512 return MultiFetchServerObjectReader.this.getBaseUrl(); 513 } 514 515 /** 516 * invokes a Multi Get for a set of ids and a given {@link OsmPrimitiveType}. 517 * The retrieved primitives are merged to {@link #outputDataSet}. 518 * 519 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 520 * {@link OsmPrimitiveType#RELATION RELATION} 521 * @param pkg the package of ids 522 * @param progressMonitor progress monitor 523 * @return the {@link FetchResult} of this operation 524 * @throws OsmTransferException if an error occurs while communicating with the API server 525 */ 526 protected FetchResult multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) 527 throws OsmTransferException { 528 String request = buildRequestString(type, pkg); 529 FetchResult result = null; 530 try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) { 531 if (in == null) return null; 532 progressMonitor.subTask(tr("Downloading OSM data...")); 533 try { 534 result = new FetchResult(OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(pkg.size(), false)), null); 535 } catch (IllegalDataException e) { 536 throw new OsmTransferException(e); 537 } 538 } catch (IOException ex) { 539 Logging.warn(ex); 540 } 541 return result; 542 } 543 544 /** 545 * invokes a Multi Get for a single id and a given {@link OsmPrimitiveType}. 546 * The retrieved primitive is merged to {@link #outputDataSet}. 547 * 548 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 549 * {@link OsmPrimitiveType#RELATION RELATION} 550 * @param id the id 551 * @param progressMonitor progress monitor 552 * @return the {@link DataSet} resulting of this operation 553 * @throws OsmTransferException if an error occurs while communicating with the API server 554 */ 555 protected DataSet singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor) throws OsmTransferException { 556 String request = buildRequestString(type, Collections.singleton(id)); 557 DataSet result = null; 558 try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) { 559 if (in == null) return null; 560 progressMonitor.subTask(tr("Downloading OSM data...")); 561 try { 562 result = OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 563 } catch (IllegalDataException e) { 564 throw new OsmTransferException(e); 565 } 566 } catch (IOException ex) { 567 Logging.warn(ex); 568 } 569 return result; 570 } 571 572 /** 573 * invokes a sequence of Multi Gets for individual ids in a set of ids and a given {@link OsmPrimitiveType}. 574 * The retrieved primitives are merged to {@link #outputDataSet}. 575 * 576 * This method is used if one of the ids in pkg doesn't exist (the server replies with return code 404). 577 * If the set is fetched with this method it is possible to find out which of the ids doesn't exist. 578 * Unfortunately, the server does not provide an error header or an error body for a 404 reply. 579 * 580 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 581 * {@link OsmPrimitiveType#RELATION RELATION} 582 * @param pkg the set of ids 583 * @param progressMonitor progress monitor 584 * @return the {@link FetchResult} of this operation 585 * @throws OsmTransferException if an error occurs while communicating with the API server 586 */ 587 protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) 588 throws OsmTransferException { 589 FetchResult result = new FetchResult(new DataSet(), new HashSet<PrimitiveId>()); 590 String baseUrl = OsmApi.getOsmApi().getBaseUrl(); 591 for (long id : pkg) { 592 try { 593 String msg; 594 switch (type) { 595 // CHECKSTYLE.OFF: SingleSpaceSeparator 596 case NODE: msg = tr("Fetching node with id {0} from ''{1}''", id, baseUrl); break; 597 case WAY: msg = tr("Fetching way with id {0} from ''{1}''", id, baseUrl); break; 598 case RELATION: msg = tr("Fetching relation with id {0} from ''{1}''", id, baseUrl); break; 599 // CHECKSTYLE.ON: SingleSpaceSeparator 600 default: throw new AssertionError(); 601 } 602 progressMonitor.setCustomText(msg); 603 result.dataSet.mergeFrom(singleGetId(type, id, progressMonitor)); 604 } catch (OsmApiException e) { 605 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 606 Logging.info(tr("Server replied with response code 404 for id {0}. Skipping.", Long.toString(id))); 607 result.missingPrimitives.add(new SimplePrimitiveId(id, type)); 608 } else { 609 throw e; 610 } 611 } 612 } 613 return result; 614 } 615 } 616}