use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.
the class AOsmQuestChangesUpload method upload.
public synchronized void upload(AtomicBoolean cancelState) {
int commits = 0, obsolete = 0;
changesetIdsCache = new HashMap<>();
unlockedQuests = new ArrayList<>();
for (OsmQuest quest : questDB.getAll(null, QuestStatus.ANSWERED)) {
// break so that the unreferenced stuff is deleted still
if (cancelState.get())
break;
Element element = elementDB.get(quest.getElementType(), quest.getElementId());
long changesetId = getChangesetIdOrCreate(quest.getOsmElementQuestType(), quest.getChangesSource());
if (uploadQuestChange(changesetId, quest, element, false, false)) {
commits++;
} else {
obsolete++;
}
}
cleanUp();
String logMsg = "Committed " + commits + " changes";
if (obsolete > 0) {
logMsg += " but dropped " + obsolete + " changes because there were conflicts";
}
Log.i(TAG, logMsg);
if (!unlockedQuests.isEmpty()) {
int unlockedQuestsCount = unlockedQuests.size();
if (visibleQuestListener != null) {
visibleQuestListener.onQuestsCreated(unlockedQuests, QuestGroup.OSM);
}
Log.i(TAG, "Unlocked " + unlockedQuestsCount + " new quests");
}
closeOpenChangesets();
if (commits > 0) {
// changesets are closed delayed after X minutes of inactivity
ChangesetAutoCloserJob.scheduleJob();
}
}
use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.
the class ElementGeometryDaoTest method testDeleteUnreferenced.
public void testDeleteUnreferenced() {
Element.Type type = Element.Type.WAY;
long id = 0;
ElementGeometry geometry = createSimpleGeometry();
dao.put(type, id, geometry);
assertEquals(1, dao.deleteUnreferenced());
dao.put(type, id, geometry);
new OsmQuestDao(dbHelper, serializer, null).add(new OsmQuest(Mockito.mock(OsmElementQuestType.class), type, id, geometry));
assertEquals(0, dao.deleteUnreferenced());
}
use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.
the class OsmQuestDaoTest method testGetAllByElementTypeAndId.
public void testGetAllByElementTypeAndId() {
OsmQuest quest1 = createNewQuest(11, Element.Type.NODE);
OsmQuest quest2 = createNewQuest(12, Element.Type.WAY);
addToDaos(quest1, quest2);
assertEquals(1, dao.getAll(null, null, null, Element.Type.NODE, null).size());
assertEquals(1, dao.getAll(null, null, null, Element.Type.WAY, 12L).size());
}
use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.
the class OsmQuestDaoTest method testDeleteAllClosed.
public void testDeleteAllClosed() {
OsmQuest quest1 = createNewQuest(1, Element.Type.NODE);
quest1.setStatus(QuestStatus.CLOSED);
OsmQuest quest2 = createNewQuest(2, Element.Type.NODE);
quest2.setStatus(QuestStatus.REVERT);
OsmQuest quest3 = createNewQuest(3, Element.Type.NODE);
addToDaos(quest1, quest2, quest3);
assertEquals(2, dao.deleteAllClosed(System.currentTimeMillis() + 10000L));
}
use of de.westnordost.streetcomplete.data.osm.OsmQuest in project StreetComplete by westnordost.
the class OsmQuestDaoTest method testAddGetWithChanges.
public void testAddGetWithChanges() {
List<StringMapEntryChange> changes = new ArrayList<>();
changes.add(new StringMapEntryAdd("a key", "a value"));
changes.add(new StringMapEntryDelete("delete this", "key"));
changes.add(new StringMapEntryModify("modify", "this", "to that"));
OsmQuest quest = createNewQuest(11, Element.Type.NODE);
quest.setChanges(new StringMapChanges(changes), "bla");
addToDaos(quest);
assertEquals(1, (long) quest.getId());
OsmQuest dbQuest = dao.get(1);
checkEqual(quest, dbQuest);
}
Aggregations