Ticket #23738: 23738-4.patch
| File 23738-4.patch, 8.3 KB (added by , 22 months ago) |
|---|
-
src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java
84 84 85 85 /** 86 86 * Prompt the user about how to proceed. 87 * @param source the source of the changeset exception 87 88 * 88 89 * @return the policy selected by the user 89 90 */ 90 protected MaxChangesetSizeExceededPolicy promptUserForPolicy( ) {91 protected MaxChangesetSizeExceededPolicy promptUserForPolicy(ChangesetClosedException.Source source) { 91 92 ButtonSpec[] specs = { 92 93 new ButtonSpec( 93 94 tr("Continue uploading"), … … 109 110 ) 110 111 }; 111 112 int numObjectsToUploadLeft = toUpload.getSize() - processedPrimitives.size(); 112 String msg1 = tr("The server reported that the current changeset was closed.<br>" 113 + "This is most likely because the changesets size exceeded the max. size<br>" 114 + "of {0} objects on the server ''{1}''.", 115 OsmApi.getOsmApi().getCapabilities().getMaxChangesetSize(), 116 OsmApi.getOsmApi().getBaseUrl() 117 ); 113 final String msg1; 114 if (source == ChangesetClosedException.Source.PREPARE_FURTHER_UPLOAD) { 115 msg1 = tr("The current changeset is full.<br>" 116 + "This is because the changesets size reached the max. size<br>" 117 + "of {0} objects on the server ''{1}''.", 118 OsmApi.getOsmApi().getCapabilities().getMaxChangesetSize(), 119 OsmApi.getOsmApi().getBaseUrl() 120 ); 121 } else { 122 msg1 = tr("The server reported that the current changeset was closed.<br>" 123 + "This is most likely because the changesets size exceeded the max. size<br>" 124 + "of {0} objects on the server ''{1}''.", 125 OsmApi.getOsmApi().getCapabilities().getMaxChangesetSize(), 126 OsmApi.getOsmApi().getBaseUrl() 127 ); 128 } 118 129 String msg2 = trn( 119 130 "There is {0} object left to upload.", 120 131 "There are {0} objects left to upload.", … … 150 161 } 151 162 152 163 /** 153 * Handles a server changeset full response .164 * Handles a server changeset full response and the case that JOSM detects that a changeset is full while preparing an upload. 154 165 * <p> 155 * Handles a server changeset full responseby either aborting or opening a new changeset, if the166 * Handles a full changeset by either aborting or opening a new changeset, if the 156 167 * user requested it so. 168 * @param source the source of the changeset exception 157 169 * 158 170 * @return true if the upload process should continue with the new changeset, false if the 159 171 * upload should be interrupted 160 172 * @throws OsmTransferException "if something goes wrong." 161 173 */ 162 protected boolean handleChangesetFullResponse( ) throws OsmTransferException {174 protected boolean handleChangesetFullResponse(ChangesetClosedException.Source source) throws OsmTransferException { 163 175 if (processedPrimitives.size() == toUpload.getSize()) { 164 176 strategy.setPolicy(MaxChangesetSizeExceededPolicy.ABORT); 165 177 return false; 166 178 } 167 179 if (strategy.getPolicy() == null || strategy.getPolicy() == MaxChangesetSizeExceededPolicy.ABORT) { 168 strategy.setPolicy(promptUserForPolicy());180 GuiHelper.runInEDTAndWait(() -> strategy.setPolicy(promptUserForPolicy(source))); 169 181 } 170 182 switch (strategy.getPolicy()) { 171 183 case AUTOMATICALLY_OPEN_NEW_CHANGESETS: … … 282 294 } 283 295 switch (e.getSource()) { 284 296 case UPLOAD_DATA: 297 case PREPARE_FURTHER_UPLOAD: 285 298 // Most likely the changeset is full. Try to recover and continue 286 299 // with a new changeset, but let the user decide first. 287 if (handleChangesetFullResponse( )) {300 if (handleChangesetFullResponse(e.getSource())) { 288 301 continue; 289 302 } 290 303 lastException = e; … … 392 405 if (strategy.getPolicy() == null) 393 406 /* do nothing if unknown policy */ 394 407 return; 395 if (e.getSource() == ChangesetClosedException.Source.UPLOAD_DATA) { 408 if (e.getSource() == ChangesetClosedException.Source.UPLOAD_DATA 409 || e.getSource() == ChangesetClosedException.Source.PREPARE_FURTHER_UPLOAD) { 396 410 switch (strategy.getPolicy()) { 397 411 case ABORT: 398 412 break; /* do nothing - we return to map editing */ -
src/org/openstreetmap/josm/io/ChangesetClosedException.java
42 42 /** 43 43 * The exception was thrown when data was uploaded to the changeset. This most 44 44 * likely means that the servers capability limits for a changeset have been 45 * exceeded. 45 * exceeded. In this case the changeset itself is not closed, just the connection. 46 46 */ 47 47 UPLOAD_DATA, 48 48 /** 49 * The exception was thrown when the servers capability limits for a 50 * changeset would be exceeded and further data should be uploaded. 51 * It is assumed that the server would reject any further upload. 52 */ 53 PREPARE_FURTHER_UPLOAD, 54 /** 49 55 * The exception was thrown when we tried to close a changeset. Probably the changeset 50 56 * already timed out on the server. 51 57 * @since 18283 -
src/org/openstreetmap/josm/io/OsmServerWriter.java
165 165 if (canceled) return; 166 166 int j = 0; 167 167 chunk.clear(); 168 while (it.hasNext() && j < chunkSize && processed.size() + j < maxChunkSize) { 168 final int oldChangesCount = api.getChangeset().getChangesCount(); 169 while (it.hasNext() && j < chunkSize && oldChangesCount + j < maxChunkSize) { 169 170 j++; 170 171 chunk.add(it.next()); 171 172 } 172 progressMonitor.setCustomText( 173 trn("({0}/{1}) Uploading {2} object...", 174 "({0}/{1}) Uploading {2} objects...", 175 chunk.size(), i, numChunks, chunk.size())); 176 processed.addAll(api.uploadDiff(chunk, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 177 // see #23738: server will close CS if maximum changeset size was reached 178 if (processed.size() >= maxChunkSize) { 179 throw new ChangesetClosedException(api.getChangeset().getId(), Instant.now(), Source.UPLOAD_DATA); 173 if (!chunk.isEmpty()) { 174 progressMonitor.setCustomText( 175 trn("({0}/{1}) Uploading {2} object...", 176 "({0}/{1}) Uploading {2} objects...", 177 chunk.size(), i, numChunks, chunk.size())); 178 processed.addAll(api.uploadDiff(chunk, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 180 179 } 180 // see #23738: server will close the connection when a changeset is too large 181 if (it.hasNext() && oldChangesCount + processed.size() >= maxChunkSize) { 182 throw new ChangesetClosedException(api.getChangeset().getId(), Instant.now(), Source.PREPARE_FURTHER_UPLOAD); 183 } 181 184 } 182 185 } finally { 183 186 progressMonitor.finishTask();
