Search in sources :

Example 6 with OsmQuest

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

the class OsmQuestChangesUploadTest method testUploadNormally.

public void testUploadNormally() {
    OsmQuest quest = createAnsweredQuestWithAppliableChange();
    Element element = createElement();
    OsmQuestDao questDb = mock(OsmQuestDao.class);
    MapDataDao mapDataDao = mock(MapDataDao.class);
    QuestStatisticsDao statisticsDao = mock(QuestStatisticsDao.class);
    MergedElementDao elementDb = mock(MergedElementDao.class);
    OsmQuestUnlocker osmQuestUnlocker = mock(OsmQuestUnlocker.class);
    OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null, statisticsDao, null, null, null, null, osmQuestUnlocker);
    assertTrue(u.uploadQuestChange(1, quest, element, false, false));
    assertEquals(QuestStatus.CLOSED, quest.getStatus());
    verify(statisticsDao).addOne("TestQuestType");
}
Also used : OsmQuestUnlocker(de.westnordost.streetcomplete.data.osm.OsmQuestUnlocker) Element(de.westnordost.osmapi.map.data.Element) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) MapDataDao(de.westnordost.osmapi.map.MapDataDao) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatisticsDao(de.westnordost.streetcomplete.data.statistics.QuestStatisticsDao) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Example 7 with OsmQuest

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

the class QuestController method retrieve.

/**
 * Retrieve the given quest from local database asynchronously, including the element / note.
 */
public void retrieve(final QuestGroup group, final long questId) {
    workerHandler.post(() -> {
        if (group == QuestGroup.OSM) {
            // race condition: another thread may have removed the element already (#288)
            OsmQuest osmQuest = osmQuestDB.get(questId);
            if (osmQuest == null)
                return;
            Element element = osmElementDB.get(osmQuest.getElementType(), osmQuest.getElementId());
            if (element == null)
                return;
            relay.onQuestSelected(osmQuest, group, element);
        } else if (group == QuestGroup.OSM_NOTE) {
            OsmNoteQuest osmNoteQuest = osmNoteQuestDB.get(questId);
            if (osmNoteQuest == null)
                return;
            relay.onQuestSelected(osmNoteQuest, group, null);
        }
    });
}
Also used : Element(de.westnordost.osmapi.map.data.Element) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) OsmNoteQuest(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuest)

Example 8 with OsmQuest

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

the class OsmQuestDownload method getPreviousQuestsIdsByElementKey.

private Map<OsmElementKey, Long> getPreviousQuestsIdsByElementKey(OsmElementQuestType questType, BoundingBox bbox) {
    String questTypeName = questType.getClass().getSimpleName();
    Map<OsmElementKey, Long> result = new HashMap<>();
    for (OsmQuest quest : osmQuestDB.getAll(bbox, null, questTypeName, null, null)) {
        result.put(new OsmElementKey(quest.getElementType(), quest.getElementId()), quest.getId());
    }
    return result;
}
Also used : HashMap(java.util.HashMap) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) OsmElementKey(de.westnordost.streetcomplete.data.osm.persist.OsmElementKey)

Example 9 with OsmQuest

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

the class OsmQuestDao method getNextNewAt.

public OsmQuest getNextNewAt(long questId, final List<String> questTypesNames) {
    OsmQuest quest = get(questId);
    if (quest == null)
        return null;
    WhereSelectionBuilder qb = new WhereSelectionBuilder();
    addQuestStatus(QuestStatus.NEW, qb);
    addElementType(quest.getElementType(), qb);
    addElementId(quest.getElementId(), qb);
    addQuestTypes(questTypesNames, qb);
    List<OsmQuest> allNext = getAllThings(getMergedViewName(), null, qb, this::createObjectFrom);
    Collections.sort(allNext, (o1, o2) -> {
        String o1Name = o1.getType().getClass().getSimpleName();
        String o2Name = o2.getType().getClass().getSimpleName();
        return questTypesNames.indexOf(o1Name) - questTypesNames.indexOf(o2Name);
    });
    return allNext.isEmpty() ? null : allNext.get(0);
}
Also used : OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) WhereSelectionBuilder(de.westnordost.streetcomplete.data.WhereSelectionBuilder)

Example 10 with OsmQuest

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

the class OsmQuestDaoTest method testDeleteReverted.

public void testDeleteReverted() {
    ElementGeometry geom = new ElementGeometry(new OsmLatLon(5, 5));
    OsmQuest quest1 = createNewQuest(new TestQuestType(), 1, Element.Type.NODE, geom);
    quest1.setStatus(QuestStatus.CLOSED);
    OsmQuest quest2 = createNewQuest(new TestQuestType2(), 1, Element.Type.NODE, geom);
    quest2.setStatus(QuestStatus.REVERT);
    OsmQuest quest3 = createNewQuest(new TestQuestType2(), 2, Element.Type.NODE, geom);
    quest3.setStatus(QuestStatus.REVERT);
    OsmQuest quest4 = createNewQuest(new TestQuestType2(), 1, Element.Type.WAY, geom);
    quest4.setStatus(QuestStatus.REVERT);
    addToDaos(quest1, quest2);
    assertEquals(1, dao.deleteAllReverted(Element.Type.NODE, 1));
}
Also used : ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) TestQuestType(de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType) TestQuestType2(de.westnordost.streetcomplete.data.osm.persist.test.TestQuestType2)

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