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

Last change on this file since 2986 was 2852, checked in by mjulius, 14 years ago

fix messages for io

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