Package org.openstreetmap.josm.gui.io
Class UploadPrimitivesTask
- java.lang.Object
-
- org.openstreetmap.josm.gui.PleaseWaitRunnable
-
- org.openstreetmap.josm.gui.io.AbstractUploadTask
-
- org.openstreetmap.josm.gui.io.UploadPrimitivesTask
-
- All Implemented Interfaces:
java.lang.Runnable
,ProgressMonitor.CancelListener
- Direct Known Subclasses:
AsynchronousUploadPrimitivesTask
public class UploadPrimitivesTask extends AbstractUploadTask
The task for uploading a collection of primitives.- Since:
- 2599
-
-
Field Summary
Fields Modifier and Type Field Description private Changeset
changeset
private java.lang.Exception
lastException
private OsmDataLayer
layer
private int
numObjectsToUpload
Initial number of objects to be uploadedprivate java.util.Set<IPrimitive>
processedPrimitives
private UploadStrategySpecification
strategy
private APIDataSet
toUpload
The objects to upload.private boolean
uploadCanceled
private OsmServerWriter
writer
-
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
-
-
Constructor Summary
Constructors Constructor Description UploadPrimitivesTask(UploadStrategySpecification strategy, OsmDataLayer layer, APIDataSet toUpload, Changeset changeset)
Creates the task
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cancel()
User pressed cancel button.protected void
cleanupAfterUpload()
private void
closeChangeset()
Closes the changeset on the server and locally.private void
closeChangesetIfRequired()
protected void
finish()
Depending on the success of the upload operation and on the policy for multi changeset uploads this will send the user back to the appropriate place in JOSM, either: to an error dialog, to the Upload Dialog, or to map editing.protected boolean
handleChangesetFullResponse()
Handles a server changeset full response.protected MaxChangesetSizeExceededPolicy
promptUserForPolicy()
Prompt the user about how to proceed.protected void
realRun()
Called in the worker thread to do the actual work.protected void
recoverFromGoneOnServer(OsmApiPrimitiveGoneException e, ProgressMonitor monitor)
Retries to recover the upload operation from an exception which was thrown because an uploaded primitive was already deleted on the server.-
Methods inherited from class org.openstreetmap.josm.gui.io.AbstractUploadTask
handleFailedUpload, handleGone, handlePreconditionFailed, handleUploadConflict, handleUploadConflictForClosedChangeset, handleUploadConflictForKnownConflict, handleUploadConflictForUnknownConflict, handleUploadPreconditionFailedConflict, synchronizeDataSet, synchronizePrimitive
-
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, canRunInBackground, getProgressMonitor, operationCanceled, run
-
-
-
-
Field Detail
-
uploadCanceled
private boolean uploadCanceled
-
lastException
private java.lang.Exception lastException
-
toUpload
private final APIDataSet toUpload
The objects to upload. Successfully uploaded objects are removed.
-
writer
private OsmServerWriter writer
-
layer
private final OsmDataLayer layer
-
processedPrimitives
private final java.util.Set<IPrimitive> processedPrimitives
-
strategy
private final UploadStrategySpecification strategy
-
numObjectsToUpload
private final int numObjectsToUpload
Initial number of objects to be uploaded
-
-
Constructor Detail
-
UploadPrimitivesTask
public UploadPrimitivesTask(UploadStrategySpecification strategy, OsmDataLayer layer, APIDataSet toUpload, Changeset changeset)
Creates the task- Parameters:
strategy
- the upload strategy. Must not be null.layer
- the OSM data layer for which data is uploaded. Must not be null.toUpload
- the collection of primitives to upload. Set to the empty collection if null.changeset
- the changeset to use for uploading. Must not be null. changeset.getId() can be 0 in which case the upload task creates a new changeset- Throws:
java.lang.IllegalArgumentException
- if layer is nulljava.lang.IllegalArgumentException
- if toUpload is nulljava.lang.IllegalArgumentException
- if strategy is nulljava.lang.IllegalArgumentException
- if changeset is null
-
-
Method Detail
-
promptUserForPolicy
protected MaxChangesetSizeExceededPolicy promptUserForPolicy()
Prompt the user about how to proceed.- Returns:
- the policy selected by the user
-
handleChangesetFullResponse
protected boolean handleChangesetFullResponse() throws OsmTransferException
Handles a server changeset full response.Handles a server changeset full response by either aborting or opening a new changeset, if the user requested it so.
- Returns:
- true if the upload process should continue with the new changeset, false if the upload should be interrupted
- Throws:
OsmTransferException
- "if something goes wrong."
-
recoverFromGoneOnServer
protected void recoverFromGoneOnServer(OsmApiPrimitiveGoneException e, ProgressMonitor monitor) throws OsmTransferException
Retries to recover the upload operation from an exception which was thrown because an uploaded primitive was already deleted on the server.- Parameters:
e
- the exception throw by the APImonitor
- a progress monitor- Throws:
OsmTransferException
- if we can't recover from the exception
-
cleanupAfterUpload
protected void cleanupAfterUpload()
-
realRun
protected void realRun()
Description copied from class:PleaseWaitRunnable
Called in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.- Specified by:
realRun
in classPleaseWaitRunnable
-
closeChangeset
private void closeChangeset() throws OsmTransferException
Closes the changeset on the server and locally.- Throws:
OsmTransferException
- "if something goes wrong."
-
closeChangesetIfRequired
private void closeChangesetIfRequired() throws OsmTransferException
- Throws:
OsmTransferException
-
finish
protected void finish()
Depending on the success of the upload operation and on the policy for multi changeset uploads this will send the user back to the appropriate place in JOSM, either:- to an error dialog,
- to the Upload Dialog, or
- to map editing.
- Specified by:
finish
in classPleaseWaitRunnable
-
cancel
protected void cancel()
Description copied from class:PleaseWaitRunnable
User pressed cancel button.- Specified by:
cancel
in classPleaseWaitRunnable
-
-