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

Last change on this file since 3122 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
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;
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 @SuppressWarnings("unused")
53 static private final Logger logger = Logger.getLogger(OsmApi.class.getName());
54 /** max number of retries to send a request in case of HTTP 500 errors or timeouts */
55 static public final int DEFAULT_MAX_NUM_RETRIES = 5;
56
57 /** the collection of instantiated OSM APIs */
58 private static HashMap<String, OsmApi> instances = new HashMap<String, OsmApi>();
59
60 /**
61 * replies the {@see OsmApi} for a given server URL
62 *
63 * @param serverUrl the server URL
64 * @return the OsmApi
65 * @throws IllegalArgumentException thrown, if serverUrl is null
66 *
67 */
68 static public OsmApi getOsmApi(String serverUrl) {
69 OsmApi api = instances.get(serverUrl);
70 if (api == null) {
71 api = new OsmApi(serverUrl);
72 instances.put(serverUrl,api);
73 }
74 return api;
75 }
76 /**
77 * replies the {@see OsmApi} for the URL given by the preference <code>osm-server.url</code>
78 *
79 * @return the OsmApi
80 * @exception IllegalStateException thrown, if the preference <code>osm-server.url</code> is not set
81 *
82 */
83 static public OsmApi getOsmApi() {
84 String serverUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
85 if (serverUrl == null)
86 throw new IllegalStateException(tr("Preference ''{0}'' missing. Cannot initialize OsmApi.", "osm-server.url"));
87 return getOsmApi(serverUrl);
88 }
89
90 /** the server URL */
91 private String serverUrl;
92
93 /**
94 * Object describing current changeset
95 */
96 private Changeset changeset;
97
98 /**
99 * API version used for server communications
100 */
101 private String version = null;
102
103 /** the api capabilities */
104 private Capabilities capabilities = new Capabilities();
105
106 /**
107 * true if successfully initialized
108 */
109 private boolean initialized = false;
110
111 private StringWriter swriter = new StringWriter();
112 private OsmWriter osmWriter = new OsmWriter(new PrintWriter(swriter), true, null);
113
114 /**
115 * A parser for the "capabilities" response XML
116 */
117 private class CapabilitiesParser extends DefaultHandler {
118 @Override
119 public void startDocument() throws SAXException {
120 capabilities.clear();
121 }
122
123 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
124 for (int i=0; i< qName.length(); i++) {
125 capabilities.put(qName, atts.getQName(i), atts.getValue(i));
126 }
127 }
128 }
129
130 /**
131 * creates an OSM api for a specific server URL
132 *
133 * @param serverUrl the server URL. Must not be null
134 * @exception IllegalArgumentException thrown, if serverUrl is null
135 */
136 protected OsmApi(String serverUrl) {
137 CheckParameterUtil.ensureParameterNotNull(serverUrl, "serverUrl");
138 this.serverUrl = serverUrl;
139 }
140
141 /**
142 * Returns the OSM protocol version we use to talk to the server.
143 * @return protocol version, or null if not yet negotiated.
144 */
145 public String getVersion() {
146 return version;
147 }
148
149 /**
150 * Initializes this component by negotiating a protocol version with the server.
151 *
152 * @exception OsmApiInitializationException thrown, if an exception occurs
153 */
154 public void initialize(ProgressMonitor monitor) throws OsmApiInitializationException, OsmTransferCancelledException {
155 if (initialized)
156 return;
157 cancel = false;
158 try {
159 String s = sendRequest("GET", "capabilities", null,monitor, false);
160 InputSource inputSource = new InputSource(new StringReader(s));
161 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
162 if (capabilities.supportsVersion("0.6")) {
163 version = "0.6";
164 } else {
165 System.err.println(tr("This version of JOSM is incompatible with the configured server."));
166 System.err.println(tr("It supports protocol version 0.6, while the server says it supports {0} to {1}.",
167 capabilities.get("version", "minimum"), capabilities.get("version", "maximum")));
168 initialized = false;
169 }
170 System.out.println(tr("Communications with {0} established using protocol version {1}.",
171 serverUrl,
172 version));
173 osmWriter.setVersion(version);
174 initialized = true;
175 } catch(IOException e) {
176 initialized = false;
177 throw new OsmApiInitializationException(e);
178 } catch(SAXException e) {
179 initialized = false;
180 throw new OsmApiInitializationException(e);
181 } catch(ParserConfigurationException e) {
182 initialized = false;
183 throw new OsmApiInitializationException(e);
184 } catch(OsmTransferCancelledException e){
185 throw e;
186 } catch(OsmTransferException e) {
187 initialized = false;
188 throw new OsmApiInitializationException(e);
189 }
190 }
191
192 /**
193 * Makes an XML string from an OSM primitive. Uses the OsmWriter class.
194 * @param o the OSM primitive
195 * @param addBody true to generate the full XML, false to only generate the encapsulating tag
196 * @return XML string
197 */
198 private String toXml(OsmPrimitive o, boolean addBody) {
199 swriter.getBuffer().setLength(0);
200 osmWriter.setWithBody(addBody);
201 osmWriter.setChangeset(changeset);
202 osmWriter.header();
203 o.visit(osmWriter);
204 osmWriter.footer();
205 osmWriter.out.flush();
206 return swriter.toString();
207 }
208
209 /**
210 * Makes an XML string from an OSM primitive. Uses the OsmWriter class.
211 * @param o the OSM primitive
212 * @param addBody true to generate the full XML, false to only generate the encapsulating tag
213 * @return XML string
214 */
215 private String toXml(Changeset s) {
216 swriter.getBuffer().setLength(0);
217 osmWriter.header();
218 s.visit(osmWriter);
219 osmWriter.footer();
220 osmWriter.out.flush();
221 return swriter.toString();
222 }
223
224 /**
225 * Returns the base URL for API requests, including the negotiated version number.
226 * @return base URL string
227 */
228 public String getBaseUrl() {
229 StringBuffer rv = new StringBuffer(serverUrl);
230 if (version != null) {
231 rv.append("/");
232 rv.append(version);
233 }
234 rv.append("/");
235 // this works around a ruby (or lighttpd) bug where two consecutive slashes in
236 // an URL will cause a "404 not found" response.
237 int p; while ((p = rv.indexOf("//", 6)) > -1) { rv.delete(p, p + 1); }
238 return rv.toString();
239 }
240
241 /**
242 * Creates an OSM primitive on the server. The OsmPrimitive object passed in
243 * is modified by giving it the server-assigned id.
244 *
245 * @param osm the primitive
246 * @throws OsmTransferException if something goes wrong
247 */
248 public void createPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
249 String ret = "";
250 try {
251 ensureValidChangeset();
252 initialize(monitor);
253 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/create", toXml(osm, true),monitor);
254 osm.setOsmId(Long.parseLong(ret.trim()), 1);
255 osm.setChangesetId(getChangeset().getId());
256 } catch(NumberFormatException e){
257 throw new OsmTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret));
258 }
259 }
260
261 /**
262 * Modifies an OSM primitive on the server.
263 *
264 * @param osm the primitive. Must not be null.
265 * @param monitor the progress monitor
266 * @throws OsmTransferException if something goes wrong
267 */
268 public void modifyPrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
269 String ret = null;
270 try {
271 ensureValidChangeset();
272 initialize(monitor);
273 // normal mode (0.6 and up) returns new object version.
274 ret = sendRequest("PUT", OsmPrimitiveType.from(osm).getAPIName()+"/" + osm.getId(), toXml(osm, true), monitor);
275 osm.setOsmId(osm.getId(), Integer.parseInt(ret.trim()));
276 osm.setChangesetId(getChangeset().getId());
277 } catch(NumberFormatException e) {
278 throw new OsmTransferException(tr("Unexpected format of new version of modified primitive ''{0}''. Got ''{1}''.", osm.getId(), ret));
279 }
280 }
281
282 /**
283 * Deletes an OSM primitive on the server.
284 * @param osm the primitive
285 * @throws OsmTransferException if something goes wrong
286 */
287 public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
288 ensureValidChangeset();
289 initialize(monitor);
290 // can't use a the individual DELETE method in the 0.6 API. Java doesn't allow
291 // submitting a DELETE request with content, the 0.6 API requires it, however. Falling back
292 // to diff upload.
293 //
294 uploadDiff(Collections.singleton(osm), monitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
295 }
296
297 /**
298 * Creates a new changeset based on the keys in <code>changeset</code>. If this
299 * method succeeds, changeset.getId() replies the id the server assigned to the new
300 * changeset
301 *
302 * The changeset must not be null, but its key/value-pairs may be empty.
303 *
304 * @param changeset the changeset toe be created. Must not be null.
305 * @param progressMonitor the progress monitor
306 * @throws OsmTransferException signifying a non-200 return code, or connection errors
307 * @throws IllegalArgumentException thrown if changeset is null
308 */
309 public void openChangeset(Changeset changeset, ProgressMonitor progressMonitor) throws OsmTransferException {
310 CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
311 try {
312 progressMonitor.beginTask((tr("Creating changeset...")));
313 initialize(progressMonitor);
314 String ret = "";
315 try {
316 ret = sendRequest("PUT", "changeset/create", toXml(changeset),progressMonitor);
317 changeset.setId(Integer.parseInt(ret.trim()));
318 changeset.setOpen(true);
319 } catch(NumberFormatException e){
320 throw new OsmTransferException(tr("Unexpected format of ID replied by the server. Got ''{0}''.", ret));
321 }
322 progressMonitor.setCustomText((tr("Successfully opened changeset {0}",changeset.getId())));
323 } finally {
324 progressMonitor.finishTask();
325 }
326 }
327
328 /**
329 * Updates a changeset with the keys in <code>changesetUpdate</code>. The changeset must not
330 * be null and id > 0 must be true.
331 *
332 * @param changeset the changeset to update. Must not be null.
333 * @param monitor the progress monitor. If null, uses the {@see NullProgressMonitor#INSTANCE}.
334 *
335 * @throws OsmTransferException if something goes wrong.
336 * @throws IllegalArgumentException if changeset is null
337 * @throws IllegalArgumentException if changeset.getId() <= 0
338 *
339 */
340 public void updateChangeset(Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
341 CheckParameterUtil.ensureParameterNotNull(changeset, "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 CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
382 if (monitor == null) {
383 monitor = NullProgressMonitor.INSTANCE;
384 }
385 if (changeset.getId() <= 0)
386 throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId()));
387 try {
388 monitor.beginTask(tr("Closing changeset..."));
389 initialize(monitor);
390 sendRequest("PUT", "changeset" + "/" + changeset.getId() + "/close", null, monitor);
391 changeset.setOpen(false);
392 } finally {
393 monitor.finishTask();
394 }
395 }
396
397 /**
398 * Uploads a list of changes in "diff" form to the server.
399 *
400 * @param list the list of changed OSM Primitives
401 * @param monitor the progress monitor
402 * @return list of processed primitives
403 * @throws OsmTransferException if something is wrong
404 */
405 public Collection<OsmPrimitive> uploadDiff(Collection<OsmPrimitive> list, ProgressMonitor monitor) throws OsmTransferException {
406 try {
407 monitor.beginTask("", list.size() * 2);
408 if (changeset == null)
409 throw new OsmTransferException(tr("No changeset present for diff upload."));
410
411 initialize(monitor);
412
413 // prepare upload request
414 //
415 OsmChangeBuilder changeBuilder = new OsmChangeBuilder(changeset);
416 monitor.subTask(tr("Preparing upload request..."));
417 changeBuilder.start();
418 changeBuilder.append(list);
419 changeBuilder.finish();
420 String diffUploadRequest = changeBuilder.getDocument();
421
422 // Upload to the server
423 //
424 monitor.indeterminateSubTask(
425 trn("Uploading {0} object...", "Uploading {0} objects...", list.size(), 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.