Skip to content

Commit

Permalink
Handle invalid serialized CheckFlags: solves osmlab#415 (osmlab#435)
Browse files Browse the repository at this point in the history
* update waterAreaCheck and CheckFlagDeserializer

* fix javadoc warning

* add null check test

Co-authored-by: Sean Coulter <[email protected]>
  • Loading branch information
seancoulter and Sean Coulter authored Dec 2, 2020
1 parent bffa74e commit b8e8502
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public Task getMapRouletteTask()
*
* @param includeFixSuggestions
* true if we want to upload fix suggestions, false if not
* @return @return a {@link Task}
* @return a {@link Task}
*/
public Task getMapRouletteTask(final boolean includeFixSuggestions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public CheckFlag deserialize(final JsonElement json, final Type typeOfT,
final JsonDeserializationContext context)
{
final JsonObject full = json.getAsJsonObject();
if (full.get("type") == null)
{
// Consumers of this deserializer will have to handle this null result. Indicates the
// serialized flag is not a FeatureCollection, so it might not have flagged objects
return null;
}
final JsonObject properties = full.get(PROPERTIES).getAsJsonObject();
final String checkName = properties.get(GENERATOR).getAsString();
// Split the instructions using the new line character and remove the prepended instruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ protected void execute(final CommandMap commandMap,
{
final CheckFlag flagRecoveredFromLine = new CheckFlagDeserializer()
.deserialize(new JsonParser().parse(line), null, null);
if (flagRecoveredFromLine == null)
{
// an issue deserializing the flag
return;
}
final CheckFlag uploadFlag = OpenStreetMapCheckFlagConverter
.openStreetMapify(flagRecoveredFromLine)
.orElse(flagRecoveredFromLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private CheckFlag checkForMissingWaterway(final CheckFlag flag, final Area area,
returnFlag.addInstruction(this.getLocalizedInstruction(
FALLBACK_INSTRUCTIONS.indexOf(INSTRUCTION_MISSING_WATERWAY),
area.getOsmIdentifier()));
returnFlag.addObject(area);
}
return returnFlag;
}
Expand Down Expand Up @@ -228,6 +229,10 @@ private CheckFlag checkForNoExitingWays(final CheckFlag flag, final Polygon area
{
returnFlag = new CheckFlag(this.getTaskIdentifier(area));
}
if (returnFlag.getFlaggedObjects().isEmpty())
{
returnFlag.addObject(area);
}
returnFlag.addInstruction(this.getLocalizedInstruction(
FALLBACK_INSTRUCTIONS.indexOf(INSTRUCTION_NO_EXITING_WATERWAY),
area.getOsmIdentifier()));
Expand Down Expand Up @@ -277,6 +282,11 @@ && matchesFilter(this.waterwayCrossingIgnore, area)
{
returnFlag = new CheckFlag(this.getTaskIdentifier(area));
}
// At this point, the flag should hold the area or nothing
if (returnFlag.getFlaggedObjects().isEmpty())
{
returnFlag.addObject(area);
}
returnFlag.addPoints(possibleAreaIntersections.stream()
.filter(pair -> !this.alreadyFlagged(pair.getRight())).map(Pair::getLeft)
.map(Segment::middle).collect(Collectors.toList()));
Expand Down Expand Up @@ -304,6 +314,12 @@ && matchesFilter(this.waterwayCrossingIgnore, area)
{
returnFlag = new CheckFlag(this.getTaskIdentifier(area));
}
// At this point, the flag should hold any one of: the area, the area and some other
// area(s), or nothing. So we just check for the last case
if (returnFlag.getFlaggedObjects().isEmpty())
{
returnFlag.addObject(area);
}
returnFlag.addInstruction(this.getLocalizedInstruction(
FALLBACK_INSTRUCTIONS.indexOf(INSTRUCTION_WATERWAY_INTERSECTION),
area.getOsmIdentifier(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void writeFiles()
unzippedProcessor.process(this.setup.getTwoCountryFlag());
unzippedProcessor.process(this.setup.getAnotherBasicFlag());
unzippedProcessor.process(this.setup.getFlagSameCheck());
unzippedProcessor.process(this.setup.getFlagNoObjects());
unzippedProcessor.process(new ShutdownEvent());

// Create a zipped file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MapRouletteUploadCommandTestRule extends CoreTestRule
private static final String IDENTIFIER_2 = "2";
private static final String IDENTIFIER_3 = "3";
private static final String IDENTIFIER_4 = "4";
private static final String IDENTIFIER_5 = "5";
private static final String CHALLENGE_1 = "SomeCheck";
private static final String CHALLENGE_2 = "SomeOtherCheck";
private static final String CHALLENGE_3 = "AnotherCheck";
Expand All @@ -41,6 +42,11 @@ public CheckFlagEvent getAnotherBasicFlag()
return this.getBasicFlag(IDENTIFIER_2, this.basicAtlas.point(2L), CHALLENGE_2);
}

public CheckFlagEvent getFlagNoObjects()
{
return this.getBasicFlag(IDENTIFIER_5, null, CHALLENGE_1);
}

public CheckFlagEvent getFlagSameCheck()
{
return this.getBasicFlag(IDENTIFIER_4, this.basicAtlas.point(4L), CHALLENGE_1);
Expand Down

0 comments on commit b8e8502

Please sign in to comment.