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);
}
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;
}
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!");
}
}
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);
}
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;
}
Aggregations