Skip to content

Commit

Permalink
MapRouletteUploadCommand Challenge Country Name Parameter (#655)
Browse files Browse the repository at this point in the history
* ISO display switch; bump atlas

* suppress warning
  • Loading branch information
Bentleysb authored Feb 15, 2022
1 parent 7d7d155 commit 55e66d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 2 additions & 0 deletions docs/maproulette_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class MapRouletteUploadCommand extends MapRouletteCommand
private static final Switch<Boolean> 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<Boolean> 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);
Expand Down Expand Up @@ -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
Expand All @@ -146,6 +149,7 @@ protected void execute(final CommandMap commandMap,
final Optional<List<String>> undiscoverableChallenges = (Optional<List<String>>) 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 ->
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<List<String>> discoverableChallenges,
final boolean useDisplayNames, final String checkinCommentPrefix,
final String checkinComment, final Optional<List<String>> discoverableChallenges,
final Optional<List<String>> undiscoverableChallenges)
{
final Map<String, String> challengeMap = fallbackConfiguration
Expand All @@ -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 -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> projects = connection.uploadedProjects();
final List<String> 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()
{
Expand Down

0 comments on commit 55e66d1

Please sign in to comment.