1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.Way;
|
---|
7 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
8 | import org.openstreetmap.josm.data.validation.Test;
|
---|
9 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
10 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
11 | import org.openstreetmap.josm.io.Capabilities;
|
---|
12 | import 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 | */
|
---|
19 | public 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(TestError.builder(this, Severity.ERROR, MAX_WAY_NODES_ERROR)
|
---|
53 | .message(message)
|
---|
54 | .primitives(w)
|
---|
55 | .build());
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|