Commit 0f7fa139 authored by Florian Schäfer's avatar Florian Schäfer

Add some more comments, use constants for tag keys

parent 2bd335f6
......@@ -48,8 +48,14 @@ public abstract class ApiQuery<T> {
return url.toString();
}
/**
* @return a (preferably short) name that identifies the API for which the query is designed.
*/
public abstract String getApiName();
/**
* @return for each call a new instance of a {@link HttpClient} ready to execute the query
*/
public abstract HttpClient getHttpClient();
public final T deserialize(final InputStream stream) throws IOException {
......
......@@ -112,6 +112,14 @@ public final class ApiQueryClient {
return response.getContent();
}
/**
* Wraps the given exception given as parameter into a new {@link IOException}.
* That new exception has a message already translated via {@link I18n#tr(String, Object...)}.
* The exception given as parameter is used as cause for the newly created exception.
* @param exception the exception that should be wrapped
* @param apiName the name of the API, reading from which caused the exception to occur
* @return the new exception that wraps the one given as parameter
*/
private static IOException wrapReadDecodeJsonExceptions(final IOException exception, final String apiName) {
final IOException wrapper;
if (exception instanceof JsonParseException || exception instanceof JsonMappingException) {
......
......@@ -12,8 +12,6 @@ import org.wikipedia.data.WikipediaSite;
public final class OsmPrimitiveUtil {
private static final Pattern WIKIPEDIA_PATTERN = Pattern.compile("(.+):(.+)");
public static final String TAG_NAME_WIKIPEDIA = "wikipedia";
private static final String TAG_NAME_WIKIDATA = "wikidata";
private OsmPrimitiveUtil() {
// Private constructor to avoid instantiation
......@@ -28,7 +26,7 @@ public final class OsmPrimitiveUtil {
* or if the Wikipedia language does not exist or is closed
*/
public static Optional<Pair<IWikipediaSite, String>> getWikipediaValue(final OsmPrimitive primitive) {
final String tagValue = primitive.get(TAG_NAME_WIKIPEDIA);
final String tagValue = primitive.get(OsmTagConstants.Key.WIKIPEDIA);
if (tagValue != null) {
final Matcher matcher = WIKIPEDIA_PATTERN.matcher(tagValue);
if (matcher.matches()) {
......@@ -46,7 +44,7 @@ public final class OsmPrimitiveUtil {
}
public static Optional<String> getWikidataValue(final OsmPrimitive primitive) {
final String wikidataValue = primitive.get(TAG_NAME_WIKIDATA);
final String wikidataValue = primitive.get(OsmTagConstants.Key.WIKIDATA);
return Optional.ofNullable(RegexUtil.isValidQId(wikidataValue) ? wikidataValue : null);
}
}
......@@ -3,6 +3,7 @@ package org.wikipedia.tools;
public class OsmTagConstants {
public static class Key {
public static final String WIKIDATA = "wikidata";
public static final String WIKIPEDIA = "wikipedia";
public static final String BRAND_WIKIDATA = "brand:wikidata";
private Key() {
......
......@@ -72,7 +72,7 @@ public abstract class BatchProcessedTagTest<T extends BatchProcessedTagTest.Test
}
}
static abstract class TestCompanion {
abstract static class TestCompanion {
private final OsmPrimitive primitive;
TestCompanion(final OsmPrimitive primitive) {
......
......@@ -24,6 +24,7 @@ import org.wikipedia.api.wikipedia_action.json.QueryResult;
import org.wikipedia.data.IWikipediaSite;
import org.wikipedia.tools.ListUtil;
import org.wikipedia.tools.OsmPrimitiveUtil;
import org.wikipedia.tools.OsmTagConstants;
public class WikipediaRedirect extends BatchProcessedTagTest<WikipediaRedirect.TestCompanion> {
......@@ -41,7 +42,7 @@ public class WikipediaRedirect extends BatchProcessedTagTest<WikipediaRedirect.T
@Override
protected TestCompanion prepareTestCompanion(OsmPrimitive primitive) {
final String plainWikipediaValue = primitive.get(OsmPrimitiveUtil.TAG_NAME_WIKIPEDIA);
final String plainWikipediaValue = primitive.get(OsmTagConstants.Key.WIKIPEDIA);
final Optional<Pair<IWikipediaSite, String>> companion = OsmPrimitiveUtil.getWikipediaValue(primitive);
if (plainWikipediaValue != null && !companion.isPresent()) {
errors.add(
......@@ -120,7 +121,7 @@ public class WikipediaRedirect extends BatchProcessedTagTest<WikipediaRedirect.T
if (optionPaneResult == JOptionPane.YES_OPTION) {
return new ChangePropertyCommand(
entry.getValue(),
OsmPrimitiveUtil.TAG_NAME_WIKIPEDIA,
OsmTagConstants.Key.WIKIPEDIA,
site.getLanguageCode() + ':' + redirectedTitle
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment