source: josm/trunk/src/org/openstreetmap/josm/io/OsmApi.java@ 2832

Last change on this file since 2832 was 2825, checked in by Gubaer, 14 years ago

fixed #4328: No visible error message when trying to upload to a closed changeset

File size: 27.3 KB
Line 
1//License: GPL. See README for details.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.BufferedReader;
7import java.io.BufferedWriter;
8import java.io.IOException;
9import java.io.InputStream;
10import java.io.InputStreamReader;
11import java.io.OutputStream;
12import java.io.OutputStreamWriter;
13import java.io.PrintWriter;
14import java.io.StringReader;
15import java.io.StringWriter;
16import java.net.ConnectException;
17import java.net.HttpURLConnection;
18import java.net.SocketTimeoutException;
19import java.net.URL;
20import java.net.UnknownHostException;
21import java.util.Collection;
22import java.util.Collections;
23import java.util.HashMap;
24import java.util.logging.Logger;
25
26import javax.xml.parsers.ParserConfigurationException;
27import javax.xml.parsers.SAXParserFactory;
28
29import org.openstreetmap.josm.Main;
30import org.openstreetmap.josm.data.osm.Changeset;
31import org.openstreetmap.josm.data.osm.OsmPrimitive;
32import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
33import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
34import org.openstreetmap.josm.gui.progress.ProgressMonitor;
35import org.xml.sax.Attributes;
36import org.xml.sax.InputSource;
37import org.xml.sax.SAXException;
38import org.xml.sax.helpers.DefaultHandler;
39
40/**
41 * Class that encapsulates the communications with the OSM API.
42 *
43 * All interaction with the server-side OSM API should go through this class.
44 *
45 * It is conceivable to extract this into an interface later and create various
46 * classes implementing the interface, to be able to talk to various kinds of servers.
47 *
48 */
49public class OsmApi extends OsmConnection {
50 static private final Logger logger = Logger.getLogger(OsmApi.class.getName());
51 /** max number of retries to send a request in case of HTTP 500 errors or timeouts */
52 static public final int DEFAULT_MAX_NUM_RETRIES = 5;
53
54 /** the collection of instantiated OSM APIs */
55 private static HashMap<String, OsmApi> instances = new HashMap<String, OsmApi>();
56
57 /**
58 * replies the {@see OsmApi} for a given server URL
59 *
60 * @param serverUrl the server URL
61 * @return the OsmApi
62 * @throws IllegalArgumentException thrown, if serverUrl is null
63 *
64 */
65 static public OsmApi getOsmApi(String serverUrl) {
66 OsmApi api = instances.get(serverUrl);
67 if (api == null) {
68 api = new OsmApi(serverUrl);
69 instances.put(serverUrl,api);
70 }
71 return api;
72 }
73 /**
74 * replies the {@see OsmApi} for the URL given by the preference <code>osm-server.url</code>
75 *
76 * @return the OsmApi
77 * @exception IllegalStateException thrown, if the preference <code>osm-server.url</code> is not set
78 *
79 */
80 static public OsmApi getOsmApi() {
81 String serverUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
82 if (serverUrl == null)
83 throw new IllegalStateException(tr("Preference ''{0}'' missing. Cannot initialize OsmApi.", "osm-server.url"));
84 return getOsmApi(serverUrl);
85 }
86
87 /** the server URL */
88 private String serverUrl;
89
90 /**
91 * Object describing current changeset
92 */
93 private Changeset changeset;
94
95 /**
96 * API version used for server communications
97 */
98 private String version = null;
99
100 /** the api capabilities */
101 private Capabilities capabilities = new Capabilities();
102
103 /**
104 * true if successfully initialized
105 */
106 private boolean initialized = false;
107
108 private StringWriter swriter = new StringWriter();
109 private OsmWriter osmWriter = new OsmWriter(new PrintWriter(swriter), true, null);
110
111 /**
112 * A parser for the "capabilities" response XML
113 */
114 private class CapabilitiesParser extends DefaultHandler {
115 @Override
116 public void startDocument() throws SAXException {
117 capabilities.clear();
118 }
119
120 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
121 for (int i=0; i< qName.length(); i++) {
122 capabilities.put(qName, atts.getQName(i), atts.getValue(i));
123 }
124 }
125 }
126
127 /**
128 * creates an OSM api for a specific server URL
129 *
130 * @param serverUrl the server URL. Must not be null
131 * @exception IllegalArgumentException thrown, if serverUrl is null
132 */
133 protected OsmApi(String serverUrl) {
134 if (serverUrl == null)
135 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "serverUrl"));
136 this.serverUrl = serverUrl;
137 }
138
139 /**
140 * Returns the OSM protocol version we use to talk to the server.
141 * @return protocol version, or null if not yet negotiated.
142 */
143 public String getVersion() {
144 return version;
145 }
146
147 /**
148 * Initializes this component by negotiating a protocol version with the server.
149 *
150 * @exception OsmApiInitializationException thrown, if an exception occurs
151 */
152 public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCancelledException {
153 if (initialized)
154 return;
155 cancel = false;
156 try {
157 String s = sendRequest("GET", "capabilities", null,monitor, false);
158 InputSource inputSource = new InputSource(new StringReader(s));
159 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
160 if (capabilities.supportsVersion("0.6")) {
161 version = "0.6";
162 } else {
163 System.err.println(tr("This version of JOSM is incompatible with the configured server."));
164 System.err.println(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.",
165 capabilities.get("version", "minimum"), capabilities.get("version", "maximum")));
166 initialized = false;
167 }
168 System.out.println(tr("Communications with {0} established using protocol version {1}.",
169 serverUrl,
170 version));
171 osmWriter.setVersion(version);
172 initialized = true;
173 } catch(IOException e) {
174 initialized = false;
175 throw new OsmApiInitializationException(e);
176 } catch(SAXException e) {
177 initialized = false;
178 throw new OsmApiInitializationException(e);
179 } catch(ParserConfigurationException e) {
180 initialized = false;
181 throw new OsmApiInitializationException(e);
182 } catch(OsmTransferCancelledException e){
183 throw e;
184 } catch(OsmTransferException e) {
185 initialized = false;
186 throw new OsmApiInitializationException(e);
187 }
188 }
189
190 /**
191 * Makes an XML string from an OSM primitive. Uses the OsmWriter class.
192 * @param o the OSM primitive
193 * @param addBody true to generate the full XML, false to only generate the encapsulating tag
194 * @return XML string
195 */
196 private String toXml(OsmPrimitive o, boolean addBody) {
197 swriter.getBuffer().setLength(0);
198 osmWriter.setWithBody(addBody);
199 osmWriter.setChangeset(changeset);
200 osmWriter.header();
201 o.visit(osmWriter);
202 osmWriter.footer();
203 osmWriter.out.flush();
204 return swriter.toString();
205 }
206
207 /**
208 * Makes an XML string from an OSM primitive. Uses the OsmWriter class.
209 * @param o the OSM primitive
210 * @param addBody true to generate the full XML, false to only generate the encapsulating tag
211 * @return XML string
212 */
213 private String toXml(Changeset s) {
214 swriter.getBuffer().setLength(0);
215 osmWriter.header();
216 s.visit(osmWriter);
217 osmWriter.footer();
218 osmWriter.out.flush();
219 return swriter.toString();
220 }
221
222 /**
223 * Returns the base URL for API requests, including the negotiated version number.
224 * @return base URL string
225 */
226 public String getBaseUrl() {
227 StringBuffer rv = new StringBuffer(serverUrl);
228 if (version != null) {
229 rv.append("/");
230 rv.append(version);
231 }
232 rv.append("/");
233 // this works around a ruby (or lighttpd) bug where two consecutive slashes in
234 // an URL will cause a "404 not found" response.
235 int p; while ((p = rv.indexOf("//", 6)) > -1) { rv.delete(p, p + 1); }
236 return rv.toString();
237 }
238
239 /**
240 * Creates an OSM primitive on the server. The OsmPrimitive object passed in
241 * is modified by giving it the server-assigned id.
242 *
243 * @param osm the primitive
244 * @throws OsmTransferException if something goes wrong
245 */
246 public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
247 String ret = "";
248 try {
249 ensureValidChangeset();
250 initialize(monitor);
251 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor);
252 osm.setOsmId(Long.parseLong(ret.trim()), 1);
253 osm.setChangesetId(getChangeset().getId());
254 } catch(NumberFormatException e){
255 throw new OsmTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret));
256 }
257 }
258
259 /**
260 * Modifies an OSM primitive on the server.
261 *
262 * @param osm the primitive. Must not be null.
263 * @param monitor the progress monitor
264 * @throws OsmTransferException if something goes wrong
265 */
266 public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
267 String ret = null;
268 try {
269 ensureValidChangeset();
270 initialize(monitor);
271 // normal mode (0.6 and up) returns new object version.
272 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor);
273 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim()));
274 osm.setChangesetId(getChangeset().getId());
275 } catch(NumberFormatException e) {
276 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret));
277 }
278 }
279
280 /**
281 * Deletes an OSM primitive on the server.
282 * @param osm the primitive
283 * @throws OsmTransferException if something goes wrong
284 */
285 public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
286 ensureValidChangeset();
287 initialize(monitor);
288 // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow
289 // submitting a DELETE request with content, the 0.6 API requires it, however. Falling back
290 // to diff upload.
291 //
292 uploadDiff(Collections.singleton(osm), monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
293 }
294
295 /**
296 * Creates a new changeset based on the keys in <code>changeset</code>. If this
297 * method succeeds, changeset.getId() replies the id the server assigned to the new
298 * changeset
299 *
300 * The changeset must not be null, but its key/value-pairs may be empty.
301 *
302 * @param changeset the changeset toe be created. Must not be null.
303 * @param progressMonitor the progress monitor
304 * @throws OsmTransferException signifying a non-200 return code, or connection errors
305 * @throws IllegalArgumentException thrown if changeset is null
306 */
307 public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException {
308 if (changeset == null)
309 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "changeset"));
310 try {
311 progressMonitor.beginTask((tr("Creating changeset...")));
312 initialize(progressMonitor);
313 String ret = "";
314 try {
315 ret = sendRequest("PUT", "changeset/create", toXml(changeset),progressMonitor);
316 changeset.setId(Integer.parseInt(ret.trim()));
317 changeset.setOpen(true);
318 } catch(NumberFormatException e){
319 throw new OsmTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret));
320 }
321 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId())));
322 } finally {
323 progressMonitor.finishTask();
324 }
325 }
326
327 /**
328 * Updates a changeset with the keys in <code>changesetUpdate</code>. The changeset must not
329 * be null and id > 0 must be true.
330 *
331 * @param changeset the changeset to update. Must not be null.
332 * @param monitor the progress monitor. If null, uses the {@see NullProgressMonitor#INSTANCE}.
333 *
334 * @throws OsmTransferException if something goes wrong.
335 * @throws IllegalArgumentException if changeset is null
336 * @throws IllegalArgumentException if changeset.getId() <= 0
337 *
338 */
339 public void updateChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
340 if (changeset == null)
341 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "changeset"));
342 if (monitor == null) {
343 monitor = NullProgressMonitor.INSTANCE;
344 }
345 if (changeset.getId() <= 0)
346 throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
347 try {
348 monitor.beginTask(tr("Updating changeset..."));
349 initialize(monitor);
350 monitor.setCustomText(tr("Updating changeset {0}...", changeset.getId()));
351 sendRequest(
352 "PUT",
353 "changeset/" + changeset.getId(),
354 toXml(changeset),
355 monitor
356 );
357 } catch(ChangesetClosedException e) {
358 e.setSource(ChangesetClosedException.Source.UPDATE_CHANGESET);
359 throw e;
360 } catch(OsmApiException e) {
361 if (e.getResponseCode() == HttpURLConnection.HTTP_CONFLICT && ChangesetClosedException.errorHeaderMatchesPattern(e.getErrorHeader()))
362 throw new ChangesetClosedException(e.getErrorHeader(), ChangesetClosedException.Source.UPDATE_CHANGESET);
363 throw e;
364 } finally {
365 monitor.finishTask();
366 }
367 }
368
369 /**
370 * Closes a changeset on the server. Sets changeset.setOpen(false) if this operation
371 * succeeds.
372 *
373 * @param changeset the changeset to be closed. Must not be null. changeset.getId() > 0 required.
374 * @param monitor the progress monitor. If null, uses {@see NullProgressMonitor#INSTANCE}
375 *
376 * @throws OsmTransferException if something goes wrong.
377 * @throws IllegalArgumentException thrown if changeset is null
378 * @throws IllegalArgumentException thrown if changeset.getId() <= 0
379 */
380 public void closeChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
381 if (changeset == null)
382 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "changeset"));
383 if (monitor == null) {
384 monitor = NullProgressMonitor.INSTANCE;
385 }
386 if (changeset.getId() <= 0)
387 throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
388 try {
389 monitor.beginTask(tr("Closing changeset..."));
390 initialize(monitor);
391 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, monitor);
392 changeset.setOpen(false);
393 } finally {
394 monitor.finishTask();
395 }
396 }
397
398 /**
399 * Uploads a list of changes in "diff" form to the server.
400 *
401 * @param list the list of changed OSM Primitives
402 * @param monitor the progress monitor
403 * @return list of processed primitives
404 * @throws OsmTransferException if something is wrong
405 */
406 public Collection<OsmPrimitive> uploadDiff(Collection<OsmPrimitive> list, ProgressMonitor monitor) throws OsmTransferException {
407 try {
408 monitor.beginTask("", list.size() * 2);
409 if (changeset == null)
410 throw new OsmTransferException(tr("No changeset present for diff upload."));
411
412 initialize(monitor);
413
414 // prepare upload request
415 //
416 OsmChangeBuilder changeBuilder = new OsmChangeBuilder(changeset);
417 monitor.subTask(tr("Preparing upload request..."));
418 changeBuilder.start();
419 changeBuilder.append(list);
420 changeBuilder.finish();
421 String diffUploadRequest = changeBuilder.getDocument();
422
423 // Upload to the server
424 //
425 monitor.indeterminateSubTask(tr("Uploading {0} objects...", list.size()));
426 String diffUploadResponse = sendRequest("POST", "changeset/" + changeset.getId() + "/upload", diffUploadRequest,monitor);
427
428 // Process the response from the server
429 //
430 DiffResultProcessor reader = new DiffResultProcessor(list);
431 reader.parse(diffUploadResponse, monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
432 return reader.postProcess(
433 getChangeset(),
434 monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)
435 );
436 } catch(OsmTransferException e) {
437 throw e;
438 } catch(OsmDataParsingException e) {
439 throw new OsmTransferException(e);
440 } finally {
441 monitor.finishTask();
442 }
443 }
444
445 private void sleepAndListen(int retry, ProgressMonitor monitor) throws OsmTransferCancelledException {
446 System.out.print(tr("Waiting 10 seconds ... "));
447 for(int i=0; i < 10; i++) {
448 if (monitor != null) {
449 monitor.setCustomText(tr("Starting retry {0} of {1} in {2} seconds ...", getMaxRetries() - retry,getMaxRetries(), 10-i));
450 }
451 if (cancel)
452 throw new OsmTransferCancelledException();
453 try {
454 Thread.sleep(1000);
455 } catch (InterruptedException ex) {}
456 }
457 System.out.println(tr("OK - trying again."));
458 }
459
460 /**
461 * Replies the max. number of retries in case of 5XX errors on the server
462 *
463 * @return the max number of retries
464 */
465 protected int getMaxRetries() {
466 int ret = Main.pref.getInteger("osm-server.max-num-retries", DEFAULT_MAX_NUM_RETRIES);
467 return Math.max(ret,0);
468 }
469
470 protected boolean isUsingOAuth() {
471 String authMethod = Main.pref.get("osm-server.auth-method", "basic");
472 return authMethod.equals("oauth");
473 }
474
475 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor) throws OsmTransferException {
476 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, true);
477 }
478
479 /**
480 * Generic method for sending requests to the OSM API.
481 *
482 * This method will automatically re-try any requests that are answered with a 5xx
483 * error code, or that resulted in a timeout exception from the TCP layer.
484 *
485 * @param requestMethod The http method used when talking with the server.
486 * @param urlSuffix The suffix to add at the server url, not including the version number,
487 * but including any object ids (e.g. "/way/1234/history").
488 * @param requestBody the body of the HTTP request, if any.
489 * @param monitor the progress monitor
490 * @param doAuthenticate set to true, if the request sent to the server shall include authentication
491 * credentials;
492 *
493 * @return the body of the HTTP response, if and only if the response code was "200 OK".
494 * @exception OsmTransferException if the HTTP return code was not 200 (and retries have
495 * been exhausted), or rewrapping a Java exception.
496 */
497 private String sendRequest(String requestMethod, String urlSuffix,String requestBody, ProgressMonitor monitor, boolean doAuthenticate) throws OsmTransferException {
498 StringBuffer responseBody = new StringBuffer();
499 int retries = getMaxRetries();
500
501 while(true) { // the retry loop
502 try {
503 URL url = new URL(new URL(getBaseUrl()), urlSuffix);
504 System.out.print(requestMethod + " " + url + "... ");
505 activeConnection = (HttpURLConnection)url.openConnection();
506 activeConnection.setConnectTimeout(15000);
507 activeConnection.setRequestMethod(requestMethod);
508 if (doAuthenticate) {
509 addAuth(activeConnection);
510 }
511
512 if (requestMethod.equals("PUT") || requestMethod.equals("POST") || requestMethod.equals("DELETE")) {
513 activeConnection.setDoOutput(true);
514 activeConnection.setRequestProperty("Content-type", "text/xml");
515 OutputStream out = activeConnection.getOutputStream();
516
517 // It seems that certain bits of the Ruby API are very unhappy upon
518 // receipt of a PUT/POST message without a Content-length header,
519 // even if the request has no payload.
520 // Since Java will not generate a Content-length header unless
521 // we use the output stream, we create an output stream for PUT/POST
522 // even if there is no payload.
523 if (requestBody != null) {
524 BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
525 bwr.write(requestBody);
526 bwr.flush();
527 }
528 out.close();
529 }
530
531 activeConnection.connect();
532 System.out.println(activeConnection.getResponseMessage());
533 int retCode = activeConnection.getResponseCode();
534
535 if (retCode >= 500) {
536 if (retries-- > 0) {
537 sleepAndListen(retries, monitor);
538 System.out.println(tr("Starting retry {0} of {1}.", getMaxRetries() - retries,getMaxRetries()));
539 continue;
540 }
541 }
542
543 // populate return fields.
544 responseBody.setLength(0);
545
546 // If the API returned an error code like 403 forbidden, getInputStream
547 // will fail with an IOException.
548 InputStream i = null;
549 try {
550 i = activeConnection.getInputStream();
551 } catch (IOException ioe) {
552 i = activeConnection.getErrorStream();
553 }
554 if (i != null) {
555 // the input stream can be null if both the input and the error stream
556 // are null. Seems to be the case if the OSM server replies a 401
557 // Unauthorized, see #3887.
558 //
559 BufferedReader in = new BufferedReader(new InputStreamReader(i));
560 String s;
561 while((s = in.readLine()) != null) {
562 responseBody.append(s);
563 responseBody.append("\n");
564 }
565 }
566 String errorHeader = null;
567 // Look for a detailed error message from the server
568 if (activeConnection.getHeaderField("Error") != null) {
569 errorHeader = activeConnection.getHeaderField("Error");
570 System.err.println("Error header: " + errorHeader);
571 } else if (retCode != 200 && responseBody.length()>0) {
572 System.err.println("Error body: " + responseBody);
573 }
574 activeConnection.disconnect();
575
576 errorHeader = errorHeader == null? null : errorHeader.trim();
577 String errorBody = responseBody.length() == 0? null : responseBody.toString().trim();
578 switch(retCode) {
579 case HttpURLConnection.HTTP_OK:
580 return responseBody.toString();
581 case HttpURLConnection.HTTP_GONE:
582 throw new OsmApiPrimitiveGoneException(errorHeader, errorBody);
583 case HttpURLConnection.HTTP_CONFLICT:
584 if (ChangesetClosedException.errorHeaderMatchesPattern(errorHeader))
585 throw new ChangesetClosedException(errorBody, ChangesetClosedException.Source.UPLOAD_DATA);
586 else
587 throw new OsmApiException(retCode, errorHeader, errorBody);
588 case HttpURLConnection.HTTP_FORBIDDEN:
589 OsmApiException e = new OsmApiException(retCode, errorHeader, errorBody);
590 e.setAccessedUrl(activeConnection.getURL().toString());
591 throw e;
592 default:
593 throw new OsmApiException(retCode, errorHeader, errorBody);
594 }
595 } catch (UnknownHostException e) {
596 throw new OsmTransferException(e);
597 } catch (SocketTimeoutException e) {
598 if (retries-- > 0) {
599 continue;
600 }
601 throw new OsmTransferException(e);
602 } catch (ConnectException e) {
603 if (retries-- > 0) {
604 continue;
605 }
606 throw new OsmTransferException(e);
607 } catch(IOException e){
608 throw new OsmTransferException(e);
609 } catch(OsmTransferCancelledException e){
610 throw e;
611 } catch(OsmTransferException e) {
612 throw e;
613 }
614 }
615 }
616
617 /**
618 * returns the API capabilities; null, if the API is not initialized yet
619 *
620 * @return the API capabilities
621 */
622 public Capabilities getCapabilities() {
623 return capabilities;
624 }
625
626 /**
627 * Ensures that the current changeset can be used for uploading data
628 *
629 * @throws OsmTransferException thrown if the current changeset can't be used for
630 * uploading data
631 */
632 protected void ensureValidChangeset() throws OsmTransferException {
633 if (changeset == null)
634 throw new OsmTransferException(tr("Current changeset is null. Cannot upload data."));
635 if (changeset.getId() <= 0)
636 throw new OsmTransferException(tr("ID of current changeset > 0 required. Current ID is {0}.", changeset.getId()));
637 }
638 /**
639 * Replies the changeset data uploads are currently directed to
640 *
641 * @return the changeset data uploads are currently directed to
642 */
643 public Changeset getChangeset() {
644 return changeset;
645 }
646
647 /**
648 * Sets the changesets to which further data uploads are directed. The changeset
649 * can be null. If it isn't null it must have been created, i.e. id > 0 is required. Furthermore,
650 * it must be open.
651 *
652 * @param changeset the changeset
653 * @throws IllegalArgumentException thrown if changeset.getId() <= 0
654 * @throws IllegalArgumentException thrown if !changeset.isOpen()
655 */
656 public void setChangeset(Changeset changeset) {
657 if (changeset == null) {
658 this.changeset = null;
659 return;
660 }
661 if (changeset.getId() <= 0)
662 throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
663 if (!changeset.isOpen())
664 throw new IllegalArgumentException(tr("Open changeset expected. Got closed changeset with id {0}.", changeset.getId()));
665 this.changeset = changeset;
666 }
667}
Note: See TracBrowser for help on using the repository browser.