Changeset 2040 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-09-03T18:51:04+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r2037 r2040 145 145 146 146 /** 147 * Returns true if the negotiated version supports changesets.148 * @return true if the negotiated version supports changesets.149 */ 150 public boolean has ChangesetSupport() {147 * Returns true if the negotiated version supports diff uploads. 148 * @return true if the negotiated version supports diff uploads 149 */ 150 public boolean hasSupportForDiffUploads() { 151 151 return ((version != null) && (version.compareTo("0.6")>=0)); 152 152 } … … 280 280 281 281 /** 282 * Creates a new changeset on the server to use for subsequent calls. 283 * @param comment the "commit comment" for the new changeset 282 * Creates the changeset to be used for subsequent uploads. 283 * 284 * If changesetProcessingType is {@see ChangesetProcessingType#USE_NEW} creates a new changeset based 285 * on <code>changeset</code>. Otherwise uses the changeset given by {@see OsmApi#getCurrentChangeset()}. 286 * If this changeset is null or has an id of value 0, a new changeset is created too. 287 * 288 * @param changeset the changeset to be used for uploading if <code>changesetProcessingType</code> is 289 * {@see ChangesetProcessingType#USE_NEW} 290 * @param changesetProcessingType how to handel changesets; set to {@see ChangesetProcessingType#USE_NEW} if null 291 * @param progressMonitor the progress monitor 284 292 * @throws OsmTransferException signifying a non-200 return code, or connection errors 285 293 */ 286 public void createChangeset(String comment, ProgressMonitor progressMonitor) throws OsmTransferException { 287 progressMonitor.beginTask((tr("Opening changeset..."))); 294 public void createChangeset(Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 295 if (changesetProcessingType == null) { 296 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE; 297 } 288 298 try { 289 changeset = new Changeset(); 290 Properties sysProp = System.getProperties(); 291 Object ua = sysProp.get("http.agent"); 292 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 293 changeset.put("comment", comment); 294 createPrimitive(changeset, progressMonitor); 299 progressMonitor.beginTask((tr("Creating changeset..."))); 300 if (changesetProcessingType.isUseNew()) { 301 Properties sysProp = System.getProperties(); 302 Object ua = sysProp.get("http.agent"); 303 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 304 createPrimitive(changeset, progressMonitor); 305 this.changeset = changeset; 306 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId()))); 307 } else { 308 if (this.changeset == null || this.changeset.getId() == 0) { 309 progressMonitor.setCustomText((tr("No currently open changeset. Opening a new changeset..."))); 310 System.out.println(tr("Warning: could not reuse an existing changeset as requested. Opening a new one.")); 311 Properties sysProp = System.getProperties(); 312 Object ua = sysProp.get("http.agent"); 313 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 314 createPrimitive(changeset, progressMonitor); 315 this.changeset = changeset; 316 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",this.changeset.getId()))); 317 } else { 318 progressMonitor.setCustomText((tr("Reusing existing changeset {0}", this.changeset.getId()))); 319 } 320 } 295 321 } finally { 296 322 progressMonitor.finishTask(); … … 301 327 * Closes a changeset on the server. 302 328 * 329 * @param changesetProcessingType how changesets are currently handled 330 * @param progressMonitor the progress monitor 331 * 303 332 * @throws OsmTransferException if something goes wrong. 304 333 */ 305 public void stopChangeset(ProgressMonitor progressMonitor) throws OsmTransferException { 306 progressMonitor.beginTask(tr("Closing changeset {0}...", changeset.getId())); 334 public void stopChangeset(ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 335 if (changesetProcessingType == null) { 336 changesetProcessingType = ChangesetProcessingType.USE_NEW_AND_CLOSE; 337 } 307 338 try { 339 progressMonitor.beginTask(tr("Closing changeset...")); 308 340 initialize(progressMonitor); 309 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor); 310 changeset = null; 341 if (changesetProcessingType.isCloseAfterUpload()) { 342 progressMonitor.setCustomText(tr("Closing changeset {0}...", changeset.getId())); 343 if (this.changeset != null && this.changeset.getId() > 0) { 344 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, progressMonitor); 345 changeset = null; 346 } 347 } else { 348 progressMonitor.setCustomText(tr("Leaving changeset {0} open...", changeset.getId())); 349 } 311 350 } finally { 312 351 progressMonitor.finishTask(); -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r2037 r2040 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.actions.UploadAction; 14 import org.openstreetmap.josm.data.osm.Changeset; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 81 82 * 82 83 * @param primitives the collection of primitives to upload 84 * @param changeset the changeset to be used if <code>changesetProcessingType</code> indicates that 85 * a new changeset should be opened 86 * @param changesetProcessingType how we handle changesets 83 87 * @param progressMonitor the progress monitor 84 88 * @throws OsmTransferException thrown if an exception occurs 85 89 */ 86 protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 90 protected void uploadChangesIndividually(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 87 91 try { 88 92 progressMonitor.setTicksCount(primitives.size()); 89 api.createChangeset( getChangesetComment(),progressMonitor.createSubTaskMonitor(0, false));93 api.createChangeset(changeset, changesetProcessingType,progressMonitor.createSubTaskMonitor(0, false)); 90 94 uploadStartTime = System.currentTimeMillis(); 91 95 for (OsmPrimitive osm : primitives) { … … 121 125 122 126 if (api.getCurrentChangeset() != null && api.getCurrentChangeset().getId() > 0) { 123 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 127 api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false)); 124 128 } 125 129 } catch(Exception e) { … … 138 142 * @throws OsmTransferException thrown if an exception occurs 139 143 */ 140 protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 144 protected void uploadChangesAsDiffUpload(Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 141 145 // upload everything in one changeset 142 146 // 143 147 try { 144 api.createChangeset( getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false));148 api.createChangeset(changeset, changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false)); 145 149 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 146 150 } catch(OsmTransferException e) { … … 150 154 } finally { 151 155 try { 152 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 156 api.stopChangeset(changesetProcessingType, progressMonitor.createSubTaskMonitor(0, false)); 153 157 } catch (Exception ee) { 154 158 OsmChangesetCloseException closeException = new OsmChangesetCloseException(ee); … … 165 169 * @param primitives list of objects to send 166 170 */ 167 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 171 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, Changeset changeset, ChangesetProcessingType changesetProcessingType, ProgressMonitor progressMonitor) throws OsmTransferException { 168 172 processed = new LinkedList<OsmPrimitive>(); 169 173 … … 171 175 172 176 try { 173 // check whether we can use changeset177 // check whether we can use diff upload 174 178 // 175 boolean ca nUseChangeset= api.hasChangesetSupport();176 boolean use Changeset= Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0);177 if (use Changeset&& ! canUseChangeset) {178 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoringchangesets.", "osm-server.atomic-upload", apiVersion));179 use Changeset= false;180 } 181 182 if (use Changeset) {179 boolean casUseDiffUploads = api.hasSupportForDiffUploads(); 180 boolean useDiffUpload = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 181 if (useDiffUpload && ! casUseDiffUploads) { 182 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)); 183 useDiffUpload = false; 184 } 185 186 if (useDiffUpload) { 183 187 progressMonitor.beginTask(tr("Starting to upload in one request ...")); 184 uploadChangesAsDiffUpload(primitives, progressMonitor); 188 uploadChangesAsDiffUpload(primitives,changeset, changesetProcessingType, progressMonitor); 185 189 } else { 186 190 progressMonitor.beginTask(tr("Starting to upload with one request per primitive ...")); 187 uploadChangesIndividually(primitives, progressMonitor); 191 uploadChangesIndividually(primitives,changeset,changesetProcessingType, progressMonitor); 188 192 } 189 193 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.