- Timestamp:
- 2009-12-04T15:53:55+01:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r2512 r2569 36 36 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 37 37 import org.openstreetmap.josm.gui.io.UploadDialog; 38 import org.openstreetmap.josm.gui.io.UploadStrategySpecification; 38 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 39 40 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 168 169 return; 169 170 Main.worker.execute( 170 createUploadTask( 171 new UploadPrimitivesTask( 172 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 171 173 layer, 172 174 apiData.getPrimitives(), … … 552 554 } 553 555 554 public UploadPrimitivesTask createUploadTask(OsmDataLayer layer, Collection<OsmPrimitive> toUpload, Changeset changeset, boolean closeChangesetAfterUpload) {555 return new UploadPrimitivesTask(layer, toUpload, changeset, closeChangesetAfterUpload);556 }557 558 556 /** 559 557 * The task for uploading a collection of primitives … … 569 567 private boolean closeChangesetAfterUpload; 570 568 private HashSet<OsmPrimitive> processedPrimitives; 569 private UploadStrategySpecification strategy; 571 570 572 571 /** 573 * 572 * Creates the task 573 * @param strategy the upload strategy 574 574 * @param layer the OSM data layer for which data is uploaded 575 575 * @param toUpload the collection of primitives to upload … … 577 577 * @param closeChangesetAfterUpload true, if the changeset is to be closed after uploading 578 578 */ 579 private UploadPrimitivesTask( OsmDataLayer layer, Collection <OsmPrimitive> toUpload, Changeset changeset, boolean closeChangesetAfterUpload) {579 private UploadPrimitivesTask(UploadStrategySpecification strategy, OsmDataLayer layer, Collection <OsmPrimitive> toUpload, Changeset changeset, boolean closeChangesetAfterUpload) { 580 580 super(tr("Uploading data for layer ''{0}''", layer.getName()),false /* don't ignore exceptions */); 581 581 this.toUpload = toUpload; 582 582 this.layer = layer; 583 583 this.changeset = changeset; 584 this.strategy = strategy; 584 585 this.closeChangesetAfterUpload = closeChangesetAfterUpload; 585 586 this.processedPrimitives = new HashSet<OsmPrimitive>(); … … 628 629 try { 629 630 getProgressMonitor().subTask(tr("Uploading {0} objects ...", toUpload.size())); 630 writer.uploadOsm( layer.data.getVersion(), toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false));631 writer.uploadOsm(strategy, toUpload, changeset, getProgressMonitor().createSubTaskMonitor(1, false)); 631 632 processedPrimitives.addAll(writer.getProcessedPrimitives()); 632 633 // if we get here we've successfully uploaded the data. Exit the loop. -
trunk/src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java
r2512 r2569 73 73 // value 74 74 System.out.println( 75 tr("Warning: automatically truncating value of tag ''{0}'' on deleted primitive{1}",75 tr("Warning: automatically truncating value of tag ''{0}'' on deleted object {1}", 76 76 e.getKey(), 77 77 Long.toString(osmPrimitive.getId()) … … 82 82 } 83 83 JOptionPane.showMessageDialog(Main.parent, 84 tr("Length of value for tag ''{0}'' on primitive{1} exceeds the max. allowed length {2}. Values length is {3}.",84 tr("Length of value for tag ''{0}'' on object {1} exceeds the max. allowed length {2}. Values length is {3}.", 85 85 e.getKey(), Long.toString(osmPrimitive.getId()), 255, e.getValue().length() 86 86 ), -
trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java
r2512 r2569 68 68 super.executeCommand(); 69 69 70 // replace the list of nodes of 'my' wayby the list of merged71 // nodes70 // replace the list of members of 'my' relation by the list of merged 71 // members 72 72 // 73 73 my.setMembers(mergedMembers); … … 87 87 public void undoCommand() { 88 88 if (! Main.map.mapView.hasLayer(layer)) { 89 logger.warning(tr("Can' t undo command ''{0}'' because layer ''{1}'' is not present any more",89 logger.warning(tr("Can''t undo command ''{0}'' because layer ''{1}'' is not present any more", 90 90 this.toString(), 91 91 layer.toString() -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java
r2512 r2569 15 15 import java.util.HashMap; 16 16 import java.util.Observable; 17 import java.util.logging.Logger;18 17 19 18 import javax.swing.AbstractListModel; … … 120 119 return entries.get(MERGED_ENTRIES); 121 120 } 121 122 122 protected ArrayList<T> getMyEntries() { 123 123 return entries.get(MY_ENTRIES); 124 124 } 125 125 126 protected ArrayList<T> getTheirEntries() { 126 127 return entries.get(THEIR_ENTRIES); -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java
r2512 r2569 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.ArrayList; 6 7 import java.util.logging.Logger; 7 8 … … 16 17 * The model for merging two lists of relation members 17 18 * 18 *19 19 */ 20 20 public class RelationMemberListMergeModel extends ListMergeModel<RelationMember>{ … … 24 24 @Override 25 25 public boolean isEqualEntry(RelationMember e1, RelationMember e2) { 26 boolean ret = e1.getRole().equals(e2.getRole()); 27 if (!e1.getMember().isNew() ) { 28 ret = ret && (e1.getMember().getId() == e2.getMember().getId()); 29 } else { 30 ret = ret && (e1 == e2); 31 } 32 return ret; 26 return e1.equals(e2); 33 27 } 34 28 … … 119 113 if (! isFrozen()) 120 114 throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Can't build resolution command")); 121 return new RelationMemberConflictResolverCommand(my, their, getMergedEntries()); 115 ArrayList<RelationMember> entries = getMergedEntries(); 116 return new RelationMemberConflictResolverCommand(my, their, entries); 122 117 } 123 118 } -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r2512 r2569 298 298 public void cancel() { 299 299 switch(model.getMode()) { 300 301 300 case EDITING_DATA: cancelWhenInEditingModel(); break; 301 case UPLOADING_AND_SAVING: cancelSafeAndUploadTask(); break; 302 302 } 303 303 } … … 333 333 Mode mode = (Mode)evt.getNewValue(); 334 334 switch(mode) { 335 336 335 case EDITING_DATA: setEnabled(true); break; 336 case UPLOADING_AND_SAVING: setEnabled(false); break; 337 337 } 338 338 } … … 367 367 SaveLayersModel.Mode mode = (SaveLayersModel.Mode)evt.getNewValue(); 368 368 switch(mode) { 369 370 369 case EDITING_DATA: setEnabled(true); break; 370 case UPLOADING_AND_SAVING: setEnabled(false); break; 371 371 } 372 372 } … … 408 408 409 409 currentTask = new UploadLayerTask( 410 UploadDialog.getUploadDialog().getUploadStrategySpecification(), 410 411 layerInfo.getLayer(), 411 412 monitor, -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r2512 r2569 2 2 package org.openstreetmap.josm.gui.io; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; … … 50 51 import org.openstreetmap.josm.data.osm.Changeset; 51 52 import org.openstreetmap.josm.data.osm.OsmPrimitive; 53 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 52 54 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 53 55 import org.openstreetmap.josm.gui.SideButton; … … 58 60 import org.openstreetmap.josm.gui.tagging.TagModel; 59 61 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 60 import org.openstreetmap.josm.io.OsmApi;61 62 import org.openstreetmap.josm.tools.GBC; 62 63 import org.openstreetmap.josm.tools.ImageProvider; … … 192 193 JComponent.WHEN_IN_FOCUSED_WINDOW 193 194 ); 194 pnl.add(new SideButton(new ContextSensitiveHelpAction( "/Dialogs/UploadDialog")));195 HelpUtil.setHelpContext(getRootPane(), "/Dialogs/UploadDialog");195 pnl.add(new SideButton(new ContextSensitiveHelpAction(ht("/Dialogs/UploadDialog")))); 196 HelpUtil.setHelpContext(getRootPane(),ht("/Dialogs/UploadDialog")); 196 197 return pnl; 197 198 } … … 293 294 pnlLists.add(spDelete, gcList); 294 295 } 296 pnlChangesetSelection.setNumUploadedObjects(add.size() + update.size() + delete.size()); 295 297 } 296 298 … … 320 322 cs.put("comment", getUploadComment()); 321 323 return cs; 324 } 325 326 /** 327 * Replies the {@see UploadStrategySpecification} the user entered in the dialog. 328 * 329 * @return the {@see UploadStrategySpecification} the user entered in the dialog. 330 */ 331 public UploadStrategySpecification getUploadStrategySpecification() { 332 return pnlChangesetSelection.getUploadStrategySpecification(); 322 333 } 323 334 … … 487 498 488 499 protected void warnIllegalUploadComment() { 489 JOptionPane.showMessageDialog(500 HelpAwareOptionPane.showOptionDialog( 490 501 UploadDialog.this, 491 502 tr("Please enter a comment for this upload changeset (min. 3 characters)"), 492 503 tr("Illegal upload comment"), 493 JOptionPane.ERROR_MESSAGE 504 JOptionPane.ERROR_MESSAGE, 505 ht("/Dialog/UploadDialog#IllegalUploadComment") 494 506 495 507 ); 496 508 } 509 510 protected void warnIllegalChunkSize() { 511 HelpAwareOptionPane.showOptionDialog( 512 UploadDialog.this, 513 tr("Please enter a valid chunk size first"), 514 tr("Illegal chunk size"), 515 JOptionPane.ERROR_MESSAGE, 516 ht("/Dialog/UploadDialog#IllegalChunkSize") 517 ); 518 } 519 520 497 521 public void actionPerformed(ActionEvent e) { 498 522 if (getUploadComment().trim().length() < 3) { … … 502 526 return; 503 527 } 528 UploadStrategySpecification strategy = getUploadStrategySpecification(); 529 if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)) { 530 if (strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) { 531 warnIllegalChunkSize(); 532 southTabbedPane.setSelectedIndex(0); 533 pnlChangesetSelection.initEditingOfChunkSize(); 534 return; 535 } 536 } 504 537 setCanceled(false); 505 538 setVisible(false); 506 507 539 } 508 540 } … … 607 639 private OpenChangesetModel model; 608 640 private HistoryComboBox cmt; 609 private JCheckBox cbUseAtomicUpload;641 private UploadStrategySelectionPanel pnlUploadStrategy; 610 642 611 643 /** … … 615 647 * @return the panel 616 648 */ 617 protected JPanel buildAtomicUploadControlPanel() { 618 JPanel pnl = new JPanel(); 619 pnl.setLayout(new GridBagLayout()); 620 GridBagConstraints gc = new GridBagConstraints(); 621 gc.fill = GridBagConstraints.HORIZONTAL; 622 gc.weightx = 1.0; 623 gc.anchor = GridBagConstraints.FIRST_LINE_START; 624 pnl.add(cbUseAtomicUpload = new JCheckBox(tr("Upload all changes in one request")), gc); 625 cbUseAtomicUpload.setToolTipText(tr("Enable to upload all changes in one request, disable to use one request per changed primitive")); 626 boolean useAtomicUpload = Main.pref.getBoolean("osm-server.atomic-upload", true); 627 cbUseAtomicUpload.setSelected(useAtomicUpload); 628 cbUseAtomicUpload.setEnabled(OsmApi.getOsmApi().hasSupportForDiffUploads()); 629 return pnl; 649 protected JPanel buildUploadStrategySelectionPanel() { 650 pnlUploadStrategy = new UploadStrategySelectionPanel(); 651 pnlUploadStrategy.initFromPreferences(); 652 return pnlUploadStrategy; 630 653 } 631 654 … … 678 701 gc.weightx = 1.0; 679 702 gc.anchor = GridBagConstraints.FIRST_LINE_START; 680 add(build AtomicUploadControlPanel(), gc);703 add(buildUploadStrategySelectionPanel(), gc); 681 704 682 705 // -- changeset command … … 764 787 cmt.addCurrentItemToHistory(); 765 788 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 766 Main.pref.put("osm-server.atomic-upload", cbUseAtomicUpload.isSelected());789 pnlUploadStrategy.saveToPreferences(); 767 790 } 768 791 … … 819 842 } 820 843 844 public void initEditingOfChunkSize() { 845 pnlUploadStrategy.initEditingOfChunkSize(); 846 } 847 821 848 protected void refreshGUI() { 822 849 rbExisting.setEnabled(model.getSize() > 0); … … 848 875 return new Changeset(); 849 876 return cs; 877 } 878 879 /** 880 * Replies the {@see UploadStrategySpecification} the user entered in the dialog. 881 * 882 * @return the {@see UploadStrategySpecification} the user entered in the dialog. 883 */ 884 public UploadStrategySpecification getUploadStrategySpecification() { 885 return pnlUploadStrategy.getUploadStrategySpecification(); 850 886 } 851 887 … … 932 968 public boolean isCloseAfterUpload() { 933 969 return cbCloseAfterUpload.isSelected(); 970 } 971 972 public void setNumUploadedObjects(int numUploadedObjects) { 973 pnlUploadStrategy.setNumUploadedObjects(numUploadedObjects); 934 974 } 935 975 -
trunk/src/org/openstreetmap/josm/gui/io/UploadLayerTask.java
r2512 r2569 44 44 private Collection<OsmPrimitive> toUpload; 45 45 private HashSet<OsmPrimitive> processedPrimitives; 46 private UploadStrategySpecification strategy; 46 47 47 48 /** 48 * 49 * Creates the upload task 50 * 51 * @param strategy the upload strategy specification 49 52 * @param layer the layer. Must not be null. 50 53 * @param monitor a progress monitor. If monitor is null, uses {@see NullProgressMonitor#INSTANCE} … … 52 55 * @param closeChangesetAfterUpload true, if the changeset should be closed after the upload 53 56 * @throws IllegalArgumentException thrown, if layer is null 57 * @throws IllegalArgumentException thrown if strategy is null 54 58 */ 55 public UploadLayerTask( OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset, boolean closeChangesetAfterUpload) {59 public UploadLayerTask(UploadStrategySpecification strategy, OsmDataLayer layer, ProgressMonitor monitor, Changeset changeset, boolean closeChangesetAfterUpload) { 56 60 if (layer == null) 57 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", layer)); 61 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "layer")); 62 if (strategy == null) 63 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "strategy")); 58 64 if (monitor == null) { 59 65 monitor = NullProgressMonitor.INSTANCE; … … 62 68 this.monitor = monitor; 63 69 this.changeset = changeset; 70 this.strategy = strategy; 64 71 this.closeChangesetAfterUpload = closeChangesetAfterUpload; 65 72 processedPrimitives = new HashSet<OsmPrimitive>(); … … 103 110 @Override 104 111 public void run() { 105 monitor. subTask(tr("Preparing primitives to upload ..."));112 monitor.indeterminateSubTask(tr("Preparing primitives to upload ...")); 106 113 APIDataSet ds = new APIDataSet(layer.data); 107 114 try { … … 120 127 ProgressMonitor m = monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 121 128 if (isCancelled()) return; 122 writer.uploadOsm( layer.data.getVersion(), toUpload, changeset, m);129 writer.uploadOsm(strategy, toUpload, changeset, m); 123 130 processedPrimitives.addAll(writer.getProcessedPrimitives()); 124 131 break; -
trunk/src/org/openstreetmap/josm/io/ChangesetClosedException.java
r2512 r2569 12 12 import java.util.regex.Pattern; 13 13 14 /** 15 * A ChangesetClosedException is thrown if the server replies with a HTTP 16 * return code 409 (Conflict) with the error header {@see #ERROR_HEADER_PATTERN}. 17 * 18 * Depending on the context the exception is thrown in we have to react differently. 19 * <ul> 20 * <li>if it is thrown when we try to update a changeset, the changeset was most 21 * likely closed before, either explicitly by the user or because of a timeout</li> 22 * <li>if it is thrown when we try to upload data to the changeset, the changeset 23 * was most likely closed because we reached the servers capability limit for the size 24 * of a changeset.</li> 25 * </ul> 26 */ 14 27 public class ChangesetClosedException extends OsmTransferException { 28 /** the error header pattern for in case of HTTP response 409 indicating 29 * that a changeset was closed 30 */ 31 final static public String ERROR_HEADER_PATTERN = "The changeset (\\d+) was closed at (.*)"; 32 33 static enum Source { 34 /** 35 * The exception was thrown when a changeset was updated. This most likely means 36 * that the changeset was closed before. 37 */ 38 UPDATE_CHANGESET, 39 /** 40 * The exception was thrown when data was uploaded to the changeset. This most 41 * likely means that the servers capability limits for a changeset have been 42 * exceeded. 43 */ 44 UPLOAD_DATA, 45 /** 46 * Unspecified source 47 */ 48 UNSPECIFIED 49 } 50 51 /** 52 * Replies true if <code>errorHeader</code> matches with {@see #ERROR_HEADER_PATTERN} 53 * 54 * @param errorHeader the error header 55 * @return true if <code>errorHeader</code> matches with {@see #ERROR_HEADER_PATTERN} 56 */ 57 static public boolean errorHeaderMatchesPattern(String errorHeader) { 58 if (errorHeader == null) 59 return false; 60 Pattern p = Pattern.compile(ERROR_HEADER_PATTERN); 61 Matcher m = p.matcher(errorHeader); 62 return m.matches(); 63 } 15 64 16 65 /** the changeset id */ … … 18 67 /** the date on which the changeset was closed */ 19 68 private Date closedOn; 69 /** the source */ 70 private Source source; 20 71 21 72 protected void parseErrorHeader(String errorHeader) { 22 String pattern = "The changeset (\\d+) was closed at (.*)"; 23 Pattern p = Pattern.compile(pattern); 73 Pattern p = Pattern.compile(ERROR_HEADER_PATTERN); 24 74 Matcher m = p.matcher(errorHeader); 25 75 if (m.matches()) { … … 39 89 } 40 90 91 /** 92 * Creates the exception with the given <code>errorHeader</code> 93 * 94 * @param errorHeader the error header 95 */ 41 96 public ChangesetClosedException(String errorHeader) { 42 97 super(errorHeader); 43 98 parseErrorHeader(errorHeader); 99 this.source = Source.UNSPECIFIED; 44 100 } 45 101 102 /** 103 * Creates the exception with the given error header and the given 104 * source. 105 * 106 * @param errorHeader the error header 107 * @param source the source for the exception 108 */ 109 public ChangesetClosedException(String errorHeader, Source source) { 110 super(errorHeader); 111 parseErrorHeader(errorHeader); 112 this.source = source == null ? Source.UNSPECIFIED : source; 113 } 114 115 /** 116 * Replies the id of the changeset which was closed 117 * 118 * @return the id of the changeset which was closed 119 */ 46 120 public long getChangesetId() { 47 121 return changesetId; 48 122 } 49 123 124 /** 125 * Replies the date the changeset was closed 126 * 127 * @return the date the changeset was closed. May be null if the date isn't known. 128 */ 50 129 public Date getClosedOn() { 51 130 return closedOn; 52 131 } 132 133 /** 134 * Replies the source where the exception was thrown 135 * 136 * @return the source 137 */ 138 public Source getSource() { 139 return source; 140 } 53 141 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2512 r2569 145 145 146 146 /** 147 * Returns true if the negotiated version supports diff uploads.148 * @return true if the negotiated version supports diff uploads149 */150 public boolean hasSupportForDiffUploads() {151 return ((version != null) && (version.compareTo("0.6")>=0));152 }153 154 /**155 147 * Initializes this component by negotiating a protocol version with the server. 156 148 * … … 168 160 if (capabilities.supportsVersion("0.6")) { 169 161 version = "0.6"; 170 } else if (capabilities.supportsVersion("0.5")) {171 version = "0.5";172 162 } else { 173 163 System.err.println(tr("This version of JOSM is incompatible with the configured server.")); 174 System.err.println(tr("It supports protocol version s 0.5 and0.6, while the server says it supports {0} to {1}.",164 System.err.println(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.", 175 165 capabilities.get("version", "minimum"), capabilities.get("version", "maximum"))); 176 166 initialized = false; … … 256 246 257 247 /** 258 * Modifies an OSM primitive on the server. For protocols greater than 0.5, 259 * the OsmPrimitive object passed in is modified by giving it the server-assigned 260 * version. 261 * 262 * @param osm the primitive. Must not be null 248 * Modifies an OSM primitive on the server. 249 * 250 * @param osm the primitive. Must not be null. 251 * @param monitor the progress monitor 263 252 * @throws OsmTransferException if something goes wrong 264 253 */ … … 268 257 ensureValidChangeset(); 269 258 initialize(monitor); 270 if (version.equals("0.5")) { 271 // legacy mode does not return the new object version. 272 sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true),monitor); 273 } else { 274 // normal mode (0.6 and up) returns new object version. 275 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 276 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim())); 277 } 259 // normal mode (0.6 and up) returns new object version. 260 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor); 261 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim())); 278 262 } catch(NumberFormatException e) { 279 263 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret)); … … 359 343 ); 360 344 } catch(OsmApiException e) { 361 if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT )362 throw new ChangesetClosedException(e.getErrorHeader() );345 if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT && ChangesetClosedException.errorHeaderMatchesPattern(e.getErrorHeader())) 346 throw new ChangesetClosedException(e.getErrorHeader(), ChangesetClosedException.Source.UPDATE_CHANGESET); 363 347 throw e; 364 348 } finally { … … 569 553 case HttpURLConnection.HTTP_GONE: 570 554 throw new OsmApiPrimitiveGoneException(errorHeader, errorBody); 555 case HttpURLConnection.HTTP_CONFLICT: 556 if (ChangesetClosedException.errorHeaderMatchesPattern(errorHeader)) 557 throw new ChangesetClosedException(errorBody, ChangesetClosedException.Source.UPLOAD_DATA); 558 else 559 throw new OsmApiException(retCode, errorHeader, errorBody); 571 560 default: 572 561 throw new OsmApiException(retCode, errorHeader, errorBody); … … 642 631 this.changeset = changeset; 643 632 } 644 645 633 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2512 r2569 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; 9 import java.util.Iterator; 8 10 import java.util.LinkedList; 11 import java.util.List; 9 12 import java.util.logging.Logger; 10 13 11 import org.openstreetmap.josm.Main;12 14 import org.openstreetmap.josm.data.osm.Changeset; 13 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm.gui.io.UploadStrategySpecification; 15 18 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 16 19 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 36 39 37 40 private OsmApi api = OsmApi.getOsmApi(); 41 private boolean canceled = false; 38 42 39 43 private static final int MSECS_PER_SECOND = 1000; … … 42 46 43 47 long uploadStartTime; 48 44 49 45 50 public String timeLeft(int progress, int list_size) { … … 125 130 126 131 /** 132 * Upload all changes in one diff upload 133 * 134 * @param primitives the collection of primitives to upload 135 * @param progressMonitor the progress monitor 136 * @param chunkSize the size of the individual upload chunks. > 0 required. 137 * @throws IllegalArgumentException thrown if chunkSize <= 0 138 * @throws OsmTransferException thrown if an exception occurs 139 */ 140 protected void uploadChangesInChunks(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize) throws OsmTransferException, IllegalArgumentException { 141 if (chunkSize <=0) 142 throw new IllegalArgumentException(tr("Value >0 expected for parameter ''{0}'', got {1}", "chunkSize", chunkSize)); 143 try { 144 progressMonitor.beginTask(tr("Starting to upload in chunks...")); 145 List<OsmPrimitive> chunk = new ArrayList<OsmPrimitive>(chunkSize); 146 Iterator<OsmPrimitive> it = primitives.iterator(); 147 int numChunks = (int)Math.ceil((double)primitives.size() / (double)chunkSize); 148 int i= 0; 149 while(it.hasNext()) { 150 i++; 151 progressMonitor.setCustomText(tr("({0}/{1}) Uploading {2} objects...", i,numChunks,chunkSize)); 152 if (canceled) return; 153 int j = 0; 154 chunk.clear(); 155 while(it.hasNext() && j < chunkSize) { 156 if (canceled) return; 157 j++; 158 chunk.add(it.next()); 159 } 160 processed.addAll(api.uploadDiff(chunk, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 161 } 162 } catch(OsmTransferException e) { 163 throw e; 164 } catch(Exception e) { 165 throw new OsmTransferException(e); 166 } finally { 167 progressMonitor.finishTask(); 168 } 169 } 170 171 /** 127 172 * Send the dataset to the server. 128 173 * 129 * @param apiVersion version of the data set174 * @param strategy the upload strategy. Must not be null. 130 175 * @param primitives list of objects to send 131 176 * @param changeset the changeset the data is uploaded to. Must not be null. 132 177 * @param monitor the progress monitor. If null, assumes {@see NullProgressMonitor#INSTANCE} 133 178 * @throws IllegalArgumentException thrown if changeset is null 179 * @throws IllegalArgumentException thrown if strategy is null 134 180 * @throws OsmTransferException thrown if something goes wrong 135 181 */ 136 public void uploadOsm( String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {182 public void uploadOsm(UploadStrategySpecification strategy, Collection<OsmPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException { 137 183 if (changeset == null) 138 184 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "changeset")); … … 143 189 api.initialize(monitor); 144 190 // check whether we can use diff upload 145 //146 boolean canUseDiffUpload = api.hasSupportForDiffUploads();147 if (apiVersion == null) {148 System.out.println(tr("WARNING: no API version defined for data to upload. Falling back to version 0.6"));149 apiVersion = "0.6";150 }151 boolean useDiffUpload = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);152 if (useDiffUpload && ! canUseDiffUpload) {153 System.out.println(tr("WARNING: preference ''{0}'' or API version ''{1}'' of dataset requires to use diff uploads, but API is not able to handle them. Ignoring diff upload.", "osm-server.atomic-upload", apiVersion));154 useDiffUpload = false;155 }156 191 if (changeset.getId() == 0) { 157 192 api.openChangeset(changeset,monitor.createSubTaskMonitor(0, false)); … … 160 195 } 161 196 api.setChangeset(changeset); 162 if (useDiffUpload) { 197 switch(strategy.getStrategy()) { 198 case SINGLE_REQUEST_STRATEGY: 163 199 uploadChangesAsDiffUpload(primitives,monitor.createSubTaskMonitor(0,false)); 164 } else { 200 break; 201 case INDIVIDUAL_OBJECTS_STRATEGY: 165 202 uploadChangesIndividually(primitives,monitor.createSubTaskMonitor(0,false)); 203 break; 204 case CHUNKED_DATASET_STRATEGY: 205 uploadChangesInChunks(primitives,monitor.createSubTaskMonitor(0,false), strategy.getChunkSize()); 206 break; 166 207 } 167 208 } catch(OsmTransferException e) { … … 186 227 187 228 public void cancel() { 229 this.canceled = true; 188 230 if (api != null) { 189 231 api.cancel(); -
trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java
r2498 r2569 32 32 import org.openstreetmap.josm.data.osm.Way; 33 33 import org.openstreetmap.josm.data.projection.Mercator; 34 import org.openstreetmap.josm.gui.io.UploadStrategySpecification; 34 35 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 35 36 … … 124 125 OsmServerWriter writer = new OsmServerWriter(); 125 126 Changeset cs = new Changeset(); 126 writer.uploadOsm( "0.6", primitives,cs,NullProgressMonitor.INSTANCE);127 writer.uploadOsm(UploadStrategySpecification.createSingleRequestUploadStrategy(), primitives,cs,NullProgressMonitor.INSTANCE); 127 128 OsmApi.getOsmApi().closeChangeset(cs, NullProgressMonitor.INSTANCE); 128 129 } -
trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java
r2498 r2569 33 33 import org.openstreetmap.josm.data.osm.Way; 34 34 import org.openstreetmap.josm.data.projection.Mercator; 35 import org.openstreetmap.josm.gui.io.UploadStrategySpecification; 35 36 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 36 37 … … 128 129 OsmServerWriter writer = new OsmServerWriter(); 129 130 Changeset cs = new Changeset(); 130 writer.uploadOsm( "0.6", primitives, cs, NullProgressMonitor.INSTANCE);131 writer.uploadOsm(UploadStrategySpecification.createSingleRequestUploadStrategy(), primitives, cs, NullProgressMonitor.INSTANCE); 131 132 OsmApi.getOsmApi().closeChangeset(cs, NullProgressMonitor.INSTANCE); 132 133 }
Note:
See TracChangeset
for help on using the changeset viewer.