001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.validation.tests; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import org.openstreetmap.josm.data.osm.Way; 007import org.openstreetmap.josm.data.validation.Severity; 008import org.openstreetmap.josm.data.validation.Test; 009import org.openstreetmap.josm.data.validation.TestError; 010import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 011import org.openstreetmap.josm.io.Capabilities; 012import org.openstreetmap.josm.io.OsmApi; 013 014/** 015 * Performs validation tests against OSM API capabilities. This class does not test length 016 * of key/values (limited to 255 characters) because it's done by {@code TagChecker}. 017 * @since 7574 018 */ 019public class ApiCapabilitiesTest extends Test { 020 021 private static final int MAX_WAY_NODES_ERROR = 3401; 022 023 private long maxNodes = -1; 024 025 /** 026 * Constructs a new {@code ApiCapabilitiesTest}. 027 */ 028 public ApiCapabilitiesTest() { 029 super(tr("API Capabilities"), tr("Checks for errors against API capabilities")); 030 } 031 032 @Override 033 public void initialize() throws Exception { 034 super.initialize(); 035 OsmApi api = OsmApi.getOsmApi(); 036 api.initialize(NullProgressMonitor.INSTANCE); 037 Capabilities capabilities = api.getCapabilities(); 038 if (capabilities != null) { 039 maxNodes = capabilities.getMaxWayNodes(); 040 } 041 } 042 043 @Override 044 public void visit(Way w) { 045 if (maxNodes > 1 && w.getNodesCount() > maxNodes) { 046 String message; 047 if (w.isClosed()) { 048 message = tr("Way contains more than {0} nodes. It should be replaced by a multipolygon", maxNodes); 049 } else { 050 message = tr("Way contains more than {0} nodes. It should be split or simplified", maxNodes); 051 } 052 errors.add(new TestError(this, Severity.ERROR, message, MAX_WAY_NODES_ERROR, w)); 053 } 054 } 055}