Changeset 16205 in josm


Ignore:
Timestamp:
2020-03-27T15:39:19+01:00 (4 years ago)
Author:
GerdP
Message:

see #18982, #10783: allow to collect missing primitives instead of stopping on first error when loading history data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java

    r16123 r16205  
    77import java.awt.Component;
    88import java.io.IOException;
     9import java.net.HttpURLConnection;
    910import java.util.ArrayList;
    1011import java.util.Collection;
    11 import java.util.HashSet;
     12import java.util.LinkedHashSet;
    1213import java.util.List;
    1314import java.util.Objects;
     
    2425import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2526import org.openstreetmap.josm.io.ChangesetQuery;
     27import org.openstreetmap.josm.io.OsmApiException;
    2628import org.openstreetmap.josm.io.OsmServerChangesetReader;
    2729import org.openstreetmap.josm.io.OsmServerHistoryReader;
     
    5153    private boolean canceled;
    5254    private Exception lastException;
    53     private final Set<PrimitiveId> toLoad = new HashSet<>();
     55    private final Set<PrimitiveId> toLoad = new LinkedHashSet<>();
    5456    private HistoryDataSet loadedData;
    5557    private OsmServerHistoryReader reader;
    5658    private boolean getChangesetData = true;
     59    private boolean collectMissing;
     60    private final Set<PrimitiveId> missingPrimitives = new LinkedHashSet<>();
    5761
    5862    /**
     
    194198        progressMonitor.indeterminateSubTask(tr(msg, Long.toString(pid.getUniqueId())));
    195199        reader = null;
    196         HistoryDataSet ds;
     200        HistoryDataSet ds = null;
    197201        try {
    198202            reader = new OsmServerHistoryReader(pid.getType(), pid.getUniqueId());
     
    202206                ds = reader.parseHistory(progressMonitor.createSubTaskMonitor(1, false));
    203207            }
     208        } catch (OsmApiException e) {
     209            if (canceled)
     210                return;
     211            if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND && collectMissing) {
     212                missingPrimitives.add(pid);
     213            } else {
     214                throw e;
     215            }
    204216        } catch (OsmTransferException e) {
    205217            if (canceled)
     
    207219            throw e;
    208220        }
    209         loadedData.mergeInto(ds);
     221        if (ds != null) {
     222            loadedData.mergeInto(ds);
     223        }
    210224    }
    211225
     
    267281        getChangesetData = b;
    268282    }
     283
     284    /**
     285     * Determine if missing primitives should be collected. By default they are not collected
     286     * and the first missing object terminates the task.
     287     * @param b true means collect missing data and continue.
     288     * @since 16205
     289     */
     290    public void setCollectMissing(boolean b) {
     291        collectMissing = b;
     292    }
     293
     294    /**
     295     * replies the set of ids of all primitives for which a fetch request to the
     296     * server was submitted but which are not available from the server (the server
     297     * replied a return code of 404)
     298     * @since 16205
     299     *
     300     * @return the set of ids of missing primitives
     301     */
     302    public Set<PrimitiveId> getMissingPrimitives() {
     303        return missingPrimitives;
     304    }
     305
    269306}
Note: See TracChangeset for help on using the changeset viewer.