Search in sources :

Example 1 with StringMapChanges

use of de.westnordost.streetcomplete.data.osm.changes.StringMapChanges in project StreetComplete by westnordost.

the class OsmQuestChangesUploadTest method createAnsweredQuestWithNonAppliableChange.

private static OsmQuest createAnsweredQuestWithNonAppliableChange() {
    StringMapEntryChange nonPossibleChange = new StringMapEntryDelete("somekey", "value");
    StringMapChanges changes = new StringMapChanges(Collections.singletonList(nonPossibleChange));
    return createAnsweredQuest(changes);
}
Also used : StringMapEntryDelete(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryDelete) StringMapEntryChange(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryChange) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)

Example 2 with StringMapChanges

use of de.westnordost.streetcomplete.data.osm.changes.StringMapChanges in project StreetComplete by westnordost.

the class AOsmQuestDao method createNonFinalContentValuesFrom.

@Override
protected ContentValues createNonFinalContentValuesFrom(OsmQuest quest) {
    ContentValues values = new ContentValues();
    values.put(Columns.QUEST_STATUS, quest.getStatus().name());
    values.put(Columns.LAST_UPDATE, new Date().getTime());
    StringMapChanges changes = quest.getChanges();
    values.put(Columns.TAG_CHANGES, changes != null ? serializer.toBytes(changes) : null);
    values.put(Columns.CHANGES_SOURCE, quest.getChangesSource());
    return values;
}
Also used : ContentValues(android.content.ContentValues) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Date(java.util.Date)

Example 3 with StringMapChanges

use of de.westnordost.streetcomplete.data.osm.changes.StringMapChanges 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)

Example 4 with StringMapChanges

use of de.westnordost.streetcomplete.data.osm.changes.StringMapChanges in project StreetComplete by westnordost.

the class AOsmQuestDao method createObjectFrom.

@Override
protected OsmQuest createObjectFrom(Cursor cursor) {
    int colQuestId = cursor.getColumnIndexOrThrow(Columns.QUEST_ID), colElementId = cursor.getColumnIndexOrThrow(Columns.ELEMENT_ID), colElementType = cursor.getColumnIndexOrThrow(Columns.ELEMENT_TYPE), colQuestStatus = cursor.getColumnIndexOrThrow(Columns.QUEST_STATUS), colQuestType = cursor.getColumnIndexOrThrow(Columns.QUEST_TYPE), colChanges = cursor.getColumnIndexOrThrow(Columns.TAG_CHANGES), colChangesSource = cursor.getColumnIndexOrThrow(Columns.CHANGES_SOURCE), colLastChange = cursor.getColumnIndexOrThrow(Columns.LAST_UPDATE);
    long questId = cursor.getLong(colQuestId);
    long elementId = cursor.getLong(colElementId);
    Element.Type elementType = Element.Type.valueOf(cursor.getString(colElementType));
    QuestStatus questStatus = QuestStatus.valueOf(cursor.getString(colQuestStatus));
    String questTypeName = cursor.getString(colQuestType);
    OsmElementQuestType questType = (OsmElementQuestType) questTypeRegistry.getByName(questTypeName);
    if (questType == null) {
        throw new IllegalArgumentException("The quest type " + questTypeName + " does not exist!");
    }
    StringMapChanges changes = null;
    if (!cursor.isNull(colChanges)) {
        changes = serializer.toObject(cursor.getBlob(colChanges), StringMapChanges.class);
    }
    String changesSource = null;
    if (!cursor.isNull(colChangesSource)) {
        changesSource = cursor.getString(colChangesSource);
    }
    ElementGeometry geometry = ElementGeometryDao.createObjectFrom(serializer, cursor);
    Date lastChange = new Date(cursor.getLong(colLastChange));
    return new OsmQuest(questId, questType, elementType, elementId, questStatus, changes, changesSource, lastChange, geometry);
}
Also used : OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date)

Example 5 with StringMapChanges

use of de.westnordost.streetcomplete.data.osm.changes.StringMapChanges in project StreetComplete by westnordost.

the class AOsmQuestChangesUpload method changesApplied.

private Element changesApplied(Element element, OsmQuest quest) {
    // The element can be null if it has been deleted in the meantime (outside this app usually)
    if (element == null) {
        Log.d(TAG, "Dropping quest " + getQuestStringForLog(quest) + " because the associated element has already been deleted");
        return null;
    }
    Element copy = copyElement(element, element.getVersion());
    StringMapChanges changes = quest.getChanges();
    if (changes.hasConflictsTo(copy.getTags())) {
        Log.d(TAG, "Dropping quest " + getQuestStringForLog(quest) + " because there has been a conflict while applying the changes");
        return null;
    }
    changes.applyTo(copy.getTags());
    return copy;
}
Also used : StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element)

Aggregations

StringMapChanges (de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)7 Element (de.westnordost.osmapi.map.data.Element)3 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)3 StringMapEntryChange (de.westnordost.streetcomplete.data.osm.changes.StringMapEntryChange)3 StringMapEntryAdd (de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd)2 StringMapEntryDelete (de.westnordost.streetcomplete.data.osm.changes.StringMapEntryDelete)2 Date (java.util.Date)2 ContentValues (android.content.ContentValues)1 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)1 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)1 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)1 StringMapChangesBuilder (de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder)1 StringMapEntryModify (de.westnordost.streetcomplete.data.osm.changes.StringMapEntryModify)1 ArrayList (java.util.ArrayList)1