Search in sources :

Example 1 with OsmElementQuestType

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

the class OsmQuestDownloadTest method testIgnoreBlacklistedPositionsAndInvalidGeometry.

public void testIgnoreBlacklistedPositionsAndInvalidGeometry() {
    LatLon blacklistPos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry blacklistElement = new ElementWithGeometry();
    blacklistElement.element = new OsmNode(0, 0, blacklistPos, null);
    blacklistElement.geometry = new ElementGeometry(blacklistPos);
    ElementWithGeometry invalidGeometryElement = new ElementWithGeometry();
    invalidGeometryElement.element = new OsmNode(0, 0, new OsmLatLon(1.0, 1.0), null);
    invalidGeometryElement.geometry = null;
    OsmElementQuestType questType = new ListBackedQuestType(Arrays.asList(blacklistElement, invalidGeometryElement));
    setUpOsmQuestDaoMockWithNoPreviousElements();
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    dl.download(questType, new BoundingBox(0, 0, 1, 1), Collections.singleton(blacklistPos));
    verify(listener, times(0)).onQuestsCreated(any(Collection.class), any(QuestGroup.class));
}
Also used : VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 2 with OsmElementQuestType

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

the class AOsmQuestChangesUpload method handleChangesetConflict.

private boolean handleChangesetConflict(OsmQuest quest, Element element, boolean alreadyHandlingElementConflict) {
    OsmElementQuestType questType = quest.getOsmElementQuestType();
    long changesetId = createChangeset(questType, quest.getChangesSource());
    OpenChangesetKey key = new OpenChangesetKey(questType.getClass().getSimpleName(), quest.getChangesSource());
    changesetIdsCache.put(key, changesetId);
    return uploadQuestChange(changesetId, quest, element, alreadyHandlingElementConflict, true);
}
Also used : OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) OpenChangesetKey(de.westnordost.streetcomplete.data.changesets.OpenChangesetKey)

Example 3 with OsmElementQuestType

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

the class QuestDownload method downloadQuestTypes.

private void downloadQuestTypes(BoundingBox bbox, List<QuestType> questTypes, Set<LatLon> notesPositions) {
    for (QuestType questType : questTypes) {
        if (cancelState.get())
            break;
        if (maxQuestTypes != null && downloadedQuestTypes >= maxQuestTypes)
            break;
        if (questType instanceof OsmElementQuestType) {
            OsmQuestDownload questDownload = questDownloadProvider.get();
            questDownload.setQuestListener(questListener);
            if (questDownload.download((OsmElementQuestType) questType, bbox, notesPositions)) {
                downloadedTilesDao.put(tiles, questType.getClass().getSimpleName());
            }
            downloadedQuestTypes++;
            dispatchProgress();
        }
    }
}
Also used : OsmNoteQuestType(de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) QuestType(de.westnordost.streetcomplete.data.QuestType) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) OsmQuestDownload(de.westnordost.streetcomplete.data.osm.download.OsmQuestDownload)

Example 4 with OsmElementQuestType

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

the class OsmQuestDownloadTest method testDeleteObsoleteQuests.

public void testDeleteObsoleteQuests() {
    LatLon pos = new OsmLatLon(3.0, 4.0);
    ElementWithGeometry node4 = new ElementWithGeometry();
    node4.element = new OsmNode(4, 0, pos, null);
    node4.geometry = new ElementGeometry(pos);
    // questType mock will only "find" the Node #4
    OsmElementQuestType questType = new ListBackedQuestType(Collections.singletonList(node4));
    // in the quest database mock, there are quests for node 4 and node 5
    List<OsmQuest> quests = new ArrayList<>();
    quests.add(new OsmQuest(12L, questType, Element.Type.NODE, 4, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    quests.add(new OsmQuest(13L, questType, Element.Type.NODE, 5, QuestStatus.NEW, null, null, new Date(), new ElementGeometry(pos)));
    when(osmQuestDao.getAll(any(BoundingBox.class), any(QuestStatus.class), anyString(), any(Element.Type.class), anyLong())).thenReturn(quests);
    doAnswer(invocation -> {
        Collection<Long> deletedQuests = (Collection<Long>) (invocation.getArguments()[0]);
        assertEquals(1, deletedQuests.size());
        assertEquals(13L, (long) deletedQuests.iterator().next());
        return 1;
    }).when(osmQuestDao).deleteAll(any(Collection.class));
    OsmQuestDownload dl = new OsmQuestDownload(geometryDb, elementDb, osmQuestDao, countryBoundariesFuture);
    VisibleQuestListener listener = mock(VisibleQuestListener.class);
    dl.setQuestListener(listener);
    // -> we expect that quest with node #5 is removed
    dl.download(questType, new BoundingBox(0, 0, 1, 1), null);
    verify(osmQuestDao).deleteAll(any(Collection.class));
    verify(listener).onQuestsRemoved(any(Collection.class), any(QuestGroup.class));
}
Also used : OsmNode(de.westnordost.osmapi.map.data.OsmNode) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) ArrayList(java.util.ArrayList) QuestGroup(de.westnordost.streetcomplete.data.QuestGroup) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date) VisibleQuestListener(de.westnordost.streetcomplete.data.VisibleQuestListener) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) Matchers.anyLong(org.mockito.Matchers.anyLong) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) Collection(java.util.Collection) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 5 with OsmElementQuestType

use of de.westnordost.streetcomplete.data.osm.OsmElementQuestType 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);
}
Also used : OsmElementQuestType(de.westnordost.streetcomplete.data.osm.OsmElementQuestType) StringMapChanges(de.westnordost.streetcomplete.data.osm.changes.StringMapChanges) Element(de.westnordost.osmapi.map.data.Element) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) QuestStatus(de.westnordost.streetcomplete.data.QuestStatus) Date(java.util.Date)

Aggregations

OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)5 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)3 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)2 LatLon (de.westnordost.osmapi.map.data.LatLon)2 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)2 OsmNode (de.westnordost.osmapi.map.data.OsmNode)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 QuestStatus (de.westnordost.streetcomplete.data.QuestStatus)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)2 Collection (java.util.Collection)2 Date (java.util.Date)2 Element (de.westnordost.osmapi.map.data.Element)1 QuestType (de.westnordost.streetcomplete.data.QuestType)1 OpenChangesetKey (de.westnordost.streetcomplete.data.changesets.OpenChangesetKey)1 StringMapChanges (de.westnordost.streetcomplete.data.osm.changes.StringMapChanges)1 OsmQuestDownload (de.westnordost.streetcomplete.data.osm.download.OsmQuestDownload)1 OsmNoteQuestType (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType)1 ArrayList (java.util.ArrayList)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1