source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/ApiCapabilitiesTest.java@ 7574

Last change on this file since 7574 was 7574, checked in by Don-vip, 10 years ago

fix #10452 - new validator test to warn users about ways that exceed the 2000 nodes API limit before upload attempt

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.openstreetmap.josm.data.osm.Way;
7import org.openstreetmap.josm.data.validation.Severity;
8import org.openstreetmap.josm.data.validation.Test;
9import org.openstreetmap.josm.data.validation.TestError;
10import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
11import org.openstreetmap.josm.io.Capabilities;
12import org.openstreetmap.josm.io.OsmApi;
13
14/**
15 * Performs validation tests against OSM API capabilities. This class does not test length
16 * of key/values (limited to 255 characters) because it's done by {@code TagChecker}.
17 * @since 7574
18 */
19public class ApiCapabilitiesTest extends Test {
20
21 private static final int MAX_WAY_NODES_ERROR = 3401;
22
23 private long maxNodes = -1;
24
25 /**
26 * Constructs a new {@code ApiCapabilitiesTest}.
27 */
28 public ApiCapabilitiesTest() {
29 super(tr("API Capabilities"), tr("Checks for errors against API capabilities"));
30 }
31
32 @Override
33 public void initialize() throws Exception {
34 super.initialize();
35 OsmApi api = OsmApi.getOsmApi();
36 api.initialize(NullProgressMonitor.INSTANCE);
37 Capabilities capabilities = api.getCapabilities();
38 if (capabilities != null) {
39 maxNodes = capabilities.getMaxWayNodes();
40 }
41 }
42
43 @Override
44 public void visit(Way w) {
45 if (maxNodes > 1 && w.getNodesCount() > maxNodes) {
46 String message;
47 if (w.isClosed()) {
48 message = tr("Way contains more than {0} nodes. It should be replaced by a multipolygon", maxNodes);
49 } else {
50 message = tr("Way contains more than {0} nodes. It should be split or simplified", maxNodes);
51 }
52 errors.add(new TestError(this, Severity.ERROR, message, MAX_WAY_NODES_ERROR, w));
53 }
54 }
55}
Note: See TracBrowser for help on using the repository browser.