/** * Retries to recover the upload operation from an exception which was thrown because an uploaded * primitive was already deleted on the server. * * @param e the exception throw by the API * @param monitor a progress monitor * @throws OsmTransferException thrown if we can't recover from the exception */ protected void recoverFromGoneOnServer(OsmApiPrimitiveGoneException e, ProgressMonitor monitor) throws OsmTransferException { if (!e.isKnownPrimitive()) throw e; OsmPrimitive p = layer.data.getPrimitiveById(e.getPrimitiveId(), e.getPrimitiveType()); if (p == null) throw e; if (p.isDeleted()) { // we tried to delete an already deleted primitive. // System.out.println( tr( "Warning: object ''{0}'' is already deleted on the server. Skipping this object and retrying to upload.", p.getDisplayName(DefaultNameFormatter.getInstance()))); monitor.appendLogMessage( tr( "Object ''{0}'' is already deleted. Skipping object in upload.", p.getDisplayName(DefaultNameFormatter.getInstance()))); processedPrimitives.addAll(writer.getProcessedPrimitives()); processedPrimitives.add(p); toUpload.removeProcessed(processedPrimitives); return; } // exception was thrown because we tried to *update* an already deleted // primitive. We can't resolve this automatically. Re-throw exception, // a conflict is going to be created later. throw e; }
protected boolean recoverFromChangesetFullException() { if (toUpload.getSize() - processedPrimitives.size() == 0) { strategy.setPolicy(MaxChangesetSizeExceededPolicy.ABORT); return false; } if (strategy.getPolicy() == null || strategy.getPolicy().equals(MaxChangesetSizeExceededPolicy.ABORT)) { MaxChangesetSizeExceededPolicy policy = askMaxChangesetSizeExceedsPolicy(); strategy.setPolicy(policy); } switch (strategy.getPolicy()) { case ABORT: // don't continue - finish() will send the user back to map editing // return false; case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG: // don't continue - finish() will send the user back to the upload dialog // return false; case AUTOMATICALLY_OPEN_NEW_CHANGESETS: // prepare the state of the task for a next iteration in uploading. // openNewChangeset(); toUpload.removeProcessed(processedPrimitives); return true; } // should not happen return false; }
/** * Retries to recover the upload operation from an exception which was thrown because an uploaded * primitive was already deleted on the server. * * @param e the exception throw by the API * @param monitor a progress monitor * @throws OsmTransferException if we can't recover from the exception */ protected void recoverFromGoneOnServer(OsmApiPrimitiveGoneException e, ProgressMonitor monitor) throws OsmTransferException { if (!e.isKnownPrimitive()) throw e; OsmPrimitive p = layer.data.getPrimitiveById(e.getPrimitiveId(), e.getPrimitiveType()); if (p == null) throw e; if (p.isDeleted()) { // we tried to delete an already deleted primitive. final String msg; final String displayName = p.getDisplayName(DefaultNameFormatter.getInstance()); if (p instanceof Node) { msg = tr("Node ''{0}'' is already deleted. Skipping object in upload.", displayName); } else if (p instanceof Way) { msg = tr("Way ''{0}'' is already deleted. Skipping object in upload.", displayName); } else if (p instanceof Relation) { msg = tr("Relation ''{0}'' is already deleted. Skipping object in upload.", displayName); } else { msg = tr("Object ''{0}'' is already deleted. Skipping object in upload.", displayName); } monitor.appendLogMessage(msg); Main.warn(msg); processedPrimitives.addAll(writer.getProcessedPrimitives()); processedPrimitives.add(p); toUpload.removeProcessed(processedPrimitives); return; } // exception was thrown because we tried to *update* an already deleted // primitive. We can't resolve this automatically. Re-throw exception, // a conflict is going to be created later. throw e; }
@Override protected void finish() { // depending on the success of the upload operation and on the policy for // multi changeset uploads this will sent the user back to the appropriate // place in JOSM, either // - to an error dialog // - to the Upload Dialog // - to map editing GuiHelper.runInEDT( () -> { // if the changeset is still open after this upload we want it to be selected on the next // upload ChangesetCache.getInstance().update(changeset); if (changeset != null && changeset.isOpen()) { UploadDialog.getUploadDialog().setSelectedChangesetForNextUpload(changeset); } if (uploadCanceled) return; if (lastException == null) { new Notification("<h3>" + tr("Upload successful!") + "</h3>") .setIcon(ImageProvider.get("misc", "check_large")) .show(); return; } if (lastException instanceof ChangesetClosedException) { ChangesetClosedException e = (ChangesetClosedException) lastException; if (e.getSource().equals(ChangesetClosedException.Source.UPDATE_CHANGESET)) { handleFailedUpload(lastException); return; } if (strategy.getPolicy() == null) /* do nothing if unknown policy */ return; if (e.getSource().equals(ChangesetClosedException.Source.UPLOAD_DATA)) { switch (strategy.getPolicy()) { case ABORT: break; /* do nothing - we return to map editing */ case AUTOMATICALLY_OPEN_NEW_CHANGESETS: break; /* do nothing - we return to map editing */ case FILL_ONE_CHANGESET_AND_RETURN_TO_UPLOAD_DIALOG: // return to the upload dialog // toUpload.removeProcessed(processedPrimitives); UploadDialog.getUploadDialog().setUploadedPrimitives(toUpload); UploadDialog.getUploadDialog().setVisible(true); break; } } else { handleFailedUpload(lastException); } } else { handleFailedUpload(lastException); } }); }