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