Search in sources :

Example 1 with StringMapChangesBuilder

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));
    }
}
Also used : StringMapEntryChange(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryChange) StringMapChangesBuilder(de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder)

Example 2 with StringMapChangesBuilder

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
}
Also used : StringMapChangesBuilder(de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder)

Example 3 with StringMapChangesBuilder

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
}
Also used : StringMapChangesBuilder(de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder)

Example 4 with StringMapChangesBuilder

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!");
    }
}
Also used : StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element) StringMapChangesBuilder(de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Aggregations

StringMapChangesBuilder (de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder)4 Element (de.westnordost.osmapi.map.data.Element)1 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)1 StringMapChanges (de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)1 StringMapEntryChange (de.westnordost.streetcomplete.data.osm.changes.StringMapEntryChange)1