diff --git a/dependencies.gradle b/dependencies.gradle index bcc7fd161..4daaa427b 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,7 +1,7 @@ project.ext.versions = [ checkstyle: '8.18', jacoco: '0.8.7', - atlas: '6.5.7', + atlas: '6.6.2', commons:'2.6', atlas_generator: '5.3.6', atlas_checkstyle: '5.6.9', diff --git a/docs/maproulette_upload.md b/docs/maproulette_upload.md index 93821604b..a753ae3bd 100644 --- a/docs/maproulette_upload.md +++ b/docs/maproulette_upload.md @@ -24,6 +24,8 @@ Each Challenge is added to the project provided in the MapRoulette connection ur * **undiscoverableChallenges** (optional) - Check names listed here are made into undiscoverable challenges. If you define this, leave discoverableChallenges undefined. Supply a comma-delimited list for cherry-picking undiscoverable challenges (in which case all other checks are converted to discoverable challenges), or an empty string to make all challenges undiscoverable, or do not define. If undefined, checks in discoverableChallenges are made discoverable, but if discoverableChallenges is null, all challenges are made undiscoverable. * **discoverableChallenges** (optional) - Check names listed here are made into discoverable challenges. If you define this, leave undiscoverableChallenges undefined. Supply a comma-delimited list for cherry-picking discoverable challenges (in which case all other checks are converted to undiscoverable challenges), or an empty string to make all challenges discoverable, or do not define. If undefined, see undiscoverableChallenges. * **discoverableProject** (optional) - Whether the project is discoverable (enabled) in MapRoulette. +* **purgeIncompleteTasks** (optional) - Whether challenges should be purged of all incomplete tasks before uploading new tasks (true/false, default: false). +* **countryDisplayNames** (optional) - Whether ISO country codes should be converted to display names for challenge titles (true/false, default: true). ## Example The following command will upload EdgeCrossingEdge & SinkIsland checks to the `checks_example_project` Project on maproulette.org. diff --git a/src/main/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommand.java b/src/main/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommand.java index a5987aaf8..c8a04536a 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommand.java +++ b/src/main/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommand.java @@ -84,6 +84,9 @@ public class MapRouletteUploadCommand extends MapRouletteCommand private static final Switch PURGE_CHALLENGES = new Switch<>("purgeIncompleteTasks", "true/false whether challenges should be purged of all incomplete tasks before uploading new tasks.", Boolean::parseBoolean, Optionality.OPTIONAL, "false"); + private static final Switch COUNTRY_DISPLAY_NAMES = new Switch<>("countryDisplayNames", + "true/false whether ISO country codes should be converted to display names for challenge titles (defaults to true).", + Boolean::parseBoolean, Optionality.OPTIONAL, "true"); private static final String PARAMETER_CHALLENGE = "challenge"; private static final Logger logger = LoggerFactory.getLogger(MapRouletteUploadCommand.class); @@ -123,7 +126,7 @@ public SwitchList switches() return super.switches().with(INPUT_DIRECTORY, OUTPUT_PATH, CONFIG_LOCATION, COUNTRIES, CHECKS, CHECKIN_COMMENT_PREFIX, CHECKIN_COMMENT, DISCOVERABLE_CHALLENGES, UNDISCOVERABLE_CHALLENGES, DISCOVERABLE_PROJECT, INCLUDE_FIX_SUGGESTIONS, - PURGE_CHALLENGES); + PURGE_CHALLENGES, COUNTRY_DISPLAY_NAMES); } @Override @@ -146,6 +149,7 @@ protected void execute(final CommandMap commandMap, final Optional> undiscoverableChallenges = (Optional>) commandMap .getOption(UNDISCOVERABLE_CHALLENGES); this.validateChallengeDiscoverability(discoverableChallenges, undiscoverableChallenges); + final boolean useDisplayNames = (boolean) commandMap.get(COUNTRY_DISPLAY_NAMES); ((File) commandMap.get(INPUT_DIRECTORY)).listFilesRecursively().forEach(logFile -> { @@ -184,8 +188,9 @@ protected void execute(final CommandMap commandMap, final Challenge challengeObject = countryToChallengeMap .computeIfAbsent(countryCode, ignore -> this.getChallenge(checkName, instructions, - countryCode, checkinCommentPrefix, - checkinComment, discoverableChallenges, + countryCode, useDisplayNames, + checkinCommentPrefix, checkinComment, + discoverableChallenges, undiscoverableChallenges)); // by default, do NOT purge incomplete tasks from challenges challengeObject.setPurge((boolean) commandMap @@ -228,16 +233,19 @@ protected void execute(final CommandMap commandMap, * the full configuration, which contains challenge parameters for checkName. * @param countryCode * the CheckFlag iso3 country code + * @param useDisplayNames + * convert iso code to display name or not * @param checkinCommentPrefix * the MapRoulette checkinComment prefix * @param checkinComment * the MapRoulette checkinComment * @return the check's challenge parameters, stored as a Challenge object. */ + @SuppressWarnings("squid:S107") private Challenge getChallenge(final String checkName, final Configuration fallbackConfiguration, final String countryCode, - final String checkinCommentPrefix, final String checkinComment, - final Optional> discoverableChallenges, + final boolean useDisplayNames, final String checkinCommentPrefix, + final String checkinComment, final Optional> discoverableChallenges, final Optional> undiscoverableChallenges) { final Map challengeMap = fallbackConfiguration @@ -246,7 +254,8 @@ private Challenge getChallenge(final String checkName, .registerTypeAdapter(Challenge.class, new ChallengeDeserializer()).create(); final Challenge result = gson.fromJson(gson.toJson(challengeMap), Challenge.class); // Prepend the challenge name with the full country name if one exists - final String challengeName = String.join(" - ", this.getCountryDisplayName(countryCode), + final String challengeName = String.join(" - ", + useDisplayNames ? this.getCountryDisplayName(countryCode) : countryCode, result.getName().isEmpty() ? checkName : result.getName()); result.setName(challengeName); // Set check-in comment to checkinComment if provided, otherwise, set as #prefix: [ISO - diff --git a/src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java b/src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java index 9a1fcca01..fd6f5859c 100644 --- a/src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java +++ b/src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java @@ -50,6 +50,22 @@ public void testCheckFilter() Arrays.asList("SomeCheck")); } + @Test + public void testCountryDisplayNamesFalse() + { + final String[] additionalArguments = { "-countryDisplayNames=false" }; + final TestMapRouletteConnection connection = this.run(additionalArguments); + final Set projects = connection.uploadedProjects(); + final List challengeNames = projects.stream().flatMap(project -> connection + .challengesForProject(project).stream().map(Challenge::getName)).sorted() + .collect(Collectors.toList()); + + Assert.assertEquals("CAN - SomeOtherCheck", challengeNames.get(0)); + Assert.assertEquals("MEX,BLZ - AnotherCheck", challengeNames.get(1)); + Assert.assertEquals("URY - SomeCheck", challengeNames.get(2)); + Assert.assertEquals("USA - SomeCheck", challengeNames.get(3)); + } + @Test public void testCountryFilter() {