Search in sources :

Example 26 with OsmQuest

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();
    }
}
Also used : Element(de.westnordost.osmapi.map.data.Element) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) Point(android.graphics.Point)

Example 27 with OsmQuest

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

Example 28 with OsmQuest

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

Example 29 with OsmQuest

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

Example 30 with OsmQuest

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);
}
Also used : StringMapEntryDelete(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryDelete) StringMapEntryModify(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryModify) StringMapEntryChange(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryChange) StringMapEntryAdd(de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) ArrayList(java.util.ArrayList) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest)

Aggregations

OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)31 Element (de.westnordost.osmapi.map.data.Element)11 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)9 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)7 Point (android.graphics.Point)6 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)6 MergedElementDao (de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)5 TestQuestType (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType)5 ArrayList (java.util.ArrayList)5 TestQuestType2 (de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)4 DownloadedTilesDao (de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao)4 MapDataDao (de.westnordost.osmapi.map.MapDataDao)3 OpenChangesetsDao (de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)3 StringMapChanges (de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)3 HashMap (java.util.HashMap)3 SharedPreferences (android.content.SharedPreferences)2 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)2 ElementGeometryDao (de.westnordost.streetcomplete.data.osm.persist.ElementGeometryDao)2