Skip to content

Commit 55e66d1

Browse files
authored
MapRouletteUploadCommand Challenge Country Name Parameter (#655)
* ISO display switch; bump atlas * suppress warning
1 parent 7d7d155 commit 55e66d1

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project.ext.versions = [
22
checkstyle: '8.18',
33
jacoco: '0.8.7',
4-
atlas: '6.5.7',
4+
atlas: '6.6.2',
55
commons:'2.6',
66
atlas_generator: '5.3.6',
77
atlas_checkstyle: '5.6.9',

docs/maproulette_upload.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Each Challenge is added to the project provided in the MapRoulette connection ur
2424
* **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.
2525
* **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.
2626
* **discoverableProject** (optional) - Whether the project is discoverable (enabled) in MapRoulette.
27+
* **purgeIncompleteTasks** (optional) - Whether challenges should be purged of all incomplete tasks before uploading new tasks (true/false, default: false).
28+
* **countryDisplayNames** (optional) - Whether ISO country codes should be converted to display names for challenge titles (true/false, default: true).
2729
## Example
2830

2931
The following command will upload EdgeCrossingEdge & SinkIsland checks to the `checks_example_project` Project on maproulette.org.

src/main/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommand.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public class MapRouletteUploadCommand extends MapRouletteCommand
8484
private static final Switch<Boolean> PURGE_CHALLENGES = new Switch<>("purgeIncompleteTasks",
8585
"true/false whether challenges should be purged of all incomplete tasks before uploading new tasks.",
8686
Boolean::parseBoolean, Optionality.OPTIONAL, "false");
87+
private static final Switch<Boolean> COUNTRY_DISPLAY_NAMES = new Switch<>("countryDisplayNames",
88+
"true/false whether ISO country codes should be converted to display names for challenge titles (defaults to true).",
89+
Boolean::parseBoolean, Optionality.OPTIONAL, "true");
8790

8891
private static final String PARAMETER_CHALLENGE = "challenge";
8992
private static final Logger logger = LoggerFactory.getLogger(MapRouletteUploadCommand.class);
@@ -123,7 +126,7 @@ public SwitchList switches()
123126
return super.switches().with(INPUT_DIRECTORY, OUTPUT_PATH, CONFIG_LOCATION, COUNTRIES,
124127
CHECKS, CHECKIN_COMMENT_PREFIX, CHECKIN_COMMENT, DISCOVERABLE_CHALLENGES,
125128
UNDISCOVERABLE_CHALLENGES, DISCOVERABLE_PROJECT, INCLUDE_FIX_SUGGESTIONS,
126-
PURGE_CHALLENGES);
129+
PURGE_CHALLENGES, COUNTRY_DISPLAY_NAMES);
127130
}
128131

129132
@Override
@@ -146,6 +149,7 @@ protected void execute(final CommandMap commandMap,
146149
final Optional<List<String>> undiscoverableChallenges = (Optional<List<String>>) commandMap
147150
.getOption(UNDISCOVERABLE_CHALLENGES);
148151
this.validateChallengeDiscoverability(discoverableChallenges, undiscoverableChallenges);
152+
final boolean useDisplayNames = (boolean) commandMap.get(COUNTRY_DISPLAY_NAMES);
149153

150154
((File) commandMap.get(INPUT_DIRECTORY)).listFilesRecursively().forEach(logFile ->
151155
{
@@ -184,8 +188,9 @@ protected void execute(final CommandMap commandMap,
184188
final Challenge challengeObject = countryToChallengeMap
185189
.computeIfAbsent(countryCode,
186190
ignore -> this.getChallenge(checkName, instructions,
187-
countryCode, checkinCommentPrefix,
188-
checkinComment, discoverableChallenges,
191+
countryCode, useDisplayNames,
192+
checkinCommentPrefix, checkinComment,
193+
discoverableChallenges,
189194
undiscoverableChallenges));
190195
// by default, do NOT purge incomplete tasks from challenges
191196
challengeObject.setPurge((boolean) commandMap
@@ -228,16 +233,19 @@ protected void execute(final CommandMap commandMap,
228233
* the full configuration, which contains challenge parameters for checkName.
229234
* @param countryCode
230235
* the CheckFlag iso3 country code
236+
* @param useDisplayNames
237+
* convert iso code to display name or not
231238
* @param checkinCommentPrefix
232239
* the MapRoulette checkinComment prefix
233240
* @param checkinComment
234241
* the MapRoulette checkinComment
235242
* @return the check's challenge parameters, stored as a Challenge object.
236243
*/
244+
@SuppressWarnings("squid:S107")
237245
private Challenge getChallenge(final String checkName,
238246
final Configuration fallbackConfiguration, final String countryCode,
239-
final String checkinCommentPrefix, final String checkinComment,
240-
final Optional<List<String>> discoverableChallenges,
247+
final boolean useDisplayNames, final String checkinCommentPrefix,
248+
final String checkinComment, final Optional<List<String>> discoverableChallenges,
241249
final Optional<List<String>> undiscoverableChallenges)
242250
{
243251
final Map<String, String> challengeMap = fallbackConfiguration
@@ -246,7 +254,8 @@ private Challenge getChallenge(final String checkName,
246254
.registerTypeAdapter(Challenge.class, new ChallengeDeserializer()).create();
247255
final Challenge result = gson.fromJson(gson.toJson(challengeMap), Challenge.class);
248256
// Prepend the challenge name with the full country name if one exists
249-
final String challengeName = String.join(" - ", this.getCountryDisplayName(countryCode),
257+
final String challengeName = String.join(" - ",
258+
useDisplayNames ? this.getCountryDisplayName(countryCode) : countryCode,
250259
result.getName().isEmpty() ? checkName : result.getName());
251260
result.setName(challengeName);
252261
// Set check-in comment to checkinComment if provided, otherwise, set as #prefix: [ISO -

src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ public void testCheckFilter()
5050
Arrays.asList("SomeCheck"));
5151
}
5252

53+
@Test
54+
public void testCountryDisplayNamesFalse()
55+
{
56+
final String[] additionalArguments = { "-countryDisplayNames=false" };
57+
final TestMapRouletteConnection connection = this.run(additionalArguments);
58+
final Set<Project> projects = connection.uploadedProjects();
59+
final List<String> challengeNames = projects.stream().flatMap(project -> connection
60+
.challengesForProject(project).stream().map(Challenge::getName)).sorted()
61+
.collect(Collectors.toList());
62+
63+
Assert.assertEquals("CAN - SomeOtherCheck", challengeNames.get(0));
64+
Assert.assertEquals("MEX,BLZ - AnotherCheck", challengeNames.get(1));
65+
Assert.assertEquals("URY - SomeCheck", challengeNames.get(2));
66+
Assert.assertEquals("USA - SomeCheck", challengeNames.get(3));
67+
}
68+
5369
@Test
5470
public void testCountryFilter()
5571
{

0 commit comments

Comments
 (0)