use of de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder in project StreetComplete by westnordost.
the class AOsmElementQuestTypeTest method verify.
protected final void verify(StringMapEntryChange... expectedChanges) {
StringMapChangesBuilder cb = new StringMapChangesBuilder(tags);
createQuestType().applyAnswerTo(bundle, cb);
List<StringMapEntryChange> changes = cb.create().getChanges();
for (StringMapEntryChange expectedChange : expectedChanges) {
assertTrue(changes.contains(expectedChange));
}
}
use of de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder in project StreetComplete by westnordost.
the class AddCyclewayTest method testCyclewayLeftAndRightDontHaveToBeSpecified2.
public void testCyclewayLeftAndRightDontHaveToBeSpecified2() {
bundle.putString(AddCyclewayForm.CYCLEWAY_RIGHT, Cycleway.LANE.name());
StringMapChangesBuilder cb = new StringMapChangesBuilder(tags);
createQuestType().applyAnswerTo(bundle, cb);
// success if no exception thrown
}
use of de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder in project StreetComplete by westnordost.
the class AddCyclewayTest method testCyclewayLeftAndRightDontHaveToBeSpecified1.
public void testCyclewayLeftAndRightDontHaveToBeSpecified1() {
bundle.putString(AddCyclewayForm.CYCLEWAY_LEFT, Cycleway.LANE.name());
StringMapChangesBuilder cb = new StringMapChangesBuilder(tags);
createQuestType().applyAnswerTo(bundle, cb);
// success if no exception thrown
}
use of de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder in project StreetComplete by westnordost.
the class QuestController method solveOsmQuest.
private boolean solveOsmQuest(long questId, Bundle answer, String source) {
// race condition: another thread (i.e. quest download thread) may have removed the
// element already (#282). So in this case, just ignore
OsmQuest q = osmQuestDB.get(questId);
if (q == null)
return false;
Element element = osmElementDB.get(q.getElementType(), q.getElementId());
if (element == null)
return false;
StringMapChanges changes;
try {
StringMapChangesBuilder changesBuilder = new StringMapChangesBuilder(element.getTags());
q.getOsmElementQuestType().applyAnswerTo(answer, changesBuilder);
changes = changesBuilder.create();
} catch (IllegalArgumentException e) {
// if applying the changes results in an error (=a conflict), the data the quest(ion)
// was based on is not valid anymore -> like with other conflicts, silently drop the
// user's change (#289) and the quest
osmQuestDB.delete(questId);
return false;
}
if (!changes.isEmpty()) {
q.setChanges(changes, source);
q.setStatus(QuestStatus.ANSWERED);
osmQuestDB.update(q);
openChangesetsDao.setLastQuestSolvedTimeToNow();
return true;
} else {
throw new RuntimeException("OsmQuest " + questId + " (" + q.getType().getClass().getSimpleName() + ") has been answered by the user but the changeset is empty!");
}
}
Aggregations