Changeset 11618 in josm


Ignore:
Timestamp:
2017-02-25T19:59:42+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #11077 - Changeset with 50k/10k objects is not auto-closed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r11535 r11618  
    4040/**
    4141 * The task for uploading a collection of primitives.
    42  *
     42 * @since 2599
    4343 */
    4444public class UploadPrimitivesTask extends AbstractUploadTask {
     
    133133        case 0: return MaxChangesetSizeExceededPolicy.AUTOMATICALLY_OPEN_NEW_CHANGESETS;
    134134        case 1: return MaxChangesetSizeExceededPolicy.FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG;
    135         case 2: return MaxChangesetSizeExceededPolicy.ABORT;
    136         case JOptionPane.CLOSED_OPTION: return MaxChangesetSizeExceededPolicy.ABORT;
    137         }
    138         // should not happen
    139         return null;
    140     }
    141 
     135        case 2:
     136        case JOptionPane.CLOSED_OPTION:
     137        default: return MaxChangesetSizeExceededPolicy.ABORT;
     138        }
     139    }
     140
     141    /**
     142     * Opens a new changeset.
     143     */
    142144    protected void openNewChangeset() {
    143145        // make sure the current changeset is removed from the upload dialog.
    144         //
    145146        ChangesetCache.getInstance().update(changeset);
    146147        Changeset newChangeSet = new Changeset();
     
    149150    }
    150151
    151     protected boolean recoverFromChangesetFullException() {
     152    protected boolean recoverFromChangesetFullException() throws OsmTransferException {
    152153        if (toUpload.getSize() - processedPrimitives.size() == 0) {
    153154            strategy.setPolicy(MaxChangesetSizeExceededPolicy.ABORT);
     
    155156        }
    156157        if (strategy.getPolicy() == null || strategy.getPolicy().equals(MaxChangesetSizeExceededPolicy.ABORT)) {
    157             MaxChangesetSizeExceededPolicy policy = askMaxChangesetSizeExceedsPolicy();
    158             strategy.setPolicy(policy);
     158            strategy.setPolicy(askMaxChangesetSizeExceedsPolicy());
    159159        }
    160160        switch(strategy.getPolicy()) {
    161         case ABORT:
    162             // don't continue - finish() will send the user back to map editing
    163             //
    164             return false;
    165         case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
    166             // don't continue - finish() will send the user back to the upload dialog
    167             //
    168             return false;
    169161        case AUTOMATICALLY_OPEN_NEW_CHANGESETS:
    170162            // prepare the state of the task for a next iteration in uploading.
    171             //
     163            closeChangesetIfRequired();
    172164            openNewChangeset();
    173165            toUpload.removeProcessed(processedPrimitives);
    174166            return true;
    175         }
    176         // should not happen
    177         return false;
     167        case ABORT:
     168        case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG:
     169        default:
     170            // don't continue - finish() will send the user back to map editing or upload dialog
     171            return false;
     172        }
    178173    }
    179174
     
    250245
    251246                    // if we get here we've successfully uploaded the data. Exit the loop.
    252                     //
    253247                    break;
    254248                } catch (OsmTransferCanceledException e) {
     
    258252                } catch (OsmApiPrimitiveGoneException e) {
    259253                    // try to recover from  410 Gone
    260                     //
    261254                    recoverFromGoneOnServer(e, getProgressMonitor());
    262255                } catch (ChangesetClosedException e) {
     
    264257                        processedPrimitives.addAll(writer.getProcessedPrimitives()); // OsmPrimitive in => OsmPrimitive out
    265258                    }
    266                     changeset.setOpen(false);
    267259                    switch(e.getSource()) {
    268                     case UNSPECIFIED:
    269                         throw e;
    270                     case UPDATE_CHANGESET:
    271                         // The changeset was closed when we tried to update it. Probably, our
    272                         // local list of open changesets got out of sync with the server state.
    273                         // The user will have to select another open changeset.
    274                         // Rethrow exception - this will be handled later.
    275                         //
    276                         throw e;
    277260                    case UPLOAD_DATA:
    278261                        // Most likely the changeset is full. Try to recover and continue
    279262                        // with a new changeset, but let the user decide first (see
    280263                        // recoverFromChangesetFullException)
    281                         //
    282264                        if (recoverFromChangesetFullException()) {
    283265                            continue;
     
    285267                        lastException = e;
    286268                        break uploadloop;
     269                    case UNSPECIFIED:
     270                    case UPDATE_CHANGESET:
     271                    default:
     272                        // The changeset was closed when we tried to update it. Probably, our
     273                        // local list of open changesets got out of sync with the server state.
     274                        // The user will have to select another open changeset.
     275                        // Rethrow exception - this will be handled later.
     276                        changeset.setOpen(false);
     277                        throw e;
    287278                    }
    288279                } finally {
     
    296287            }
    297288            // if required close the changeset
    298             //
    299             if (strategy.isCloseChangesetAfterUpload() && changeset != null && !changeset.isNew() && changeset.isOpen()) {
    300                 OsmApi.getOsmApi().closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
    301             }
     289            closeChangesetIfRequired();
    302290        } catch (OsmTransferException e) {
    303291            if (uploadCanceled) {
     
    309297        if (uploadCanceled && processedPrimitives.isEmpty()) return;
    310298        cleanupAfterUpload();
     299    }
     300
     301    private void closeChangesetIfRequired() throws OsmTransferException {
     302        if (strategy.isCloseChangesetAfterUpload() && changeset != null && !changeset.isNew() && changeset.isOpen()) {
     303            OsmApi.getOsmApi().closeChangeset(changeset, progressMonitor.createSubTaskMonitor(0, false));
     304        }
    311305    }
    312306
Note: See TracChangeset for help on using the changeset viewer.