Search in sources :

Example 1 with OpenChangesetKey

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetKey in project StreetComplete by westnordost.

the class OsmQuestChangesUploadTest method doTestHandleChangesetConflict.

private void doTestHandleChangesetConflict(ChangesetsDao changesetsDao, long userId, long firstChangesetId, long secondChangesetId) {
    OsmQuest quest = createAnsweredQuestWithAppliableChange();
    Element element = createElement();
    MergedElementDao elementDb = mock(MergedElementDao.class);
    OsmQuestDao questDb = mock(OsmQuestDao.class);
    DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
    OpenChangesetsDao manageChangesetsDb = mock(OpenChangesetsDao.class);
    MapDataDao mapDataDao = createMapDataDaoThatReportsConflictOnUploadAndNodeDeleted();
    when(mapDataDao.openChangeset(any(Map.class))).thenReturn(secondChangesetId);
    SharedPreferences prefs = createPreferencesForUser(userId);
    OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null, null, manageChangesetsDb, changesetsDao, downloadedTilesDao, prefs, null);
    assertFalse(u.uploadQuestChange(firstChangesetId, quest, element, false, false));
    verify(manageChangesetsDb).replace(new OpenChangesetKey("TestQuestType", "test case"), secondChangesetId);
    verify(questDb).delete(quest.getId());
    verify(elementDb).delete(Element.Type.NODE, A_NODE_ID);
    verify(downloadedTilesDao).remove(any(Point.class));
}
Also used : OpenChangesetsDao(de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao) SharedPreferences(android.content.SharedPreferences) OpenChangesetKey(de.westnordost.streetcomplete.data.changesets.OpenChangesetKey) Element(de.westnordost.osmapi.map.data.Element) OsmQuestDao(de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao) MapDataDao(de.westnordost.osmapi.map.MapDataDao) Point(android.graphics.Point) OsmQuest(de.westnordost.streetcomplete.data.osm.OsmQuest) DownloadedTilesDao(de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao) HashMap(java.util.HashMap) Map(java.util.Map) MergedElementDao(de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)

Example 2 with OpenChangesetKey

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetKey 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 OpenChangesetKey

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetKey in project StreetComplete by westnordost.

the class AOsmQuestChangesUpload method getChangesetIdOrCreate.

private long getChangesetIdOrCreate(OsmElementQuestType questType, String source) {
    String questTypeName = questType.getClass().getSimpleName();
    OpenChangesetKey key = new OpenChangesetKey(questTypeName, source);
    Long cachedChangesetId = changesetIdsCache.get(key);
    if (cachedChangesetId != null)
        return cachedChangesetId;
    OpenChangesetInfo changesetInfo = openChangesetsDB.get(key);
    long result;
    if (changesetInfo != null && changesetInfo.changesetId != null) {
        result = changesetInfo.changesetId;
    } else {
        result = createChangeset(questType, source);
    }
    changesetIdsCache.put(key, result);
    return result;
}
Also used : OpenChangesetKey(de.westnordost.streetcomplete.data.changesets.OpenChangesetKey) OpenChangesetInfo(de.westnordost.streetcomplete.data.changesets.OpenChangesetInfo)

Example 4 with OpenChangesetKey

use of de.westnordost.streetcomplete.data.changesets.OpenChangesetKey in project StreetComplete by westnordost.

the class AOsmQuestChangesUpload method createChangeset.

private long createChangeset(OsmElementQuestType questType, String source) {
    OpenChangesetKey key = new OpenChangesetKey(questType.getClass().getSimpleName(), source);
    long changesetId = osmDao.openChangeset(createChangesetTags(questType, source));
    openChangesetsDB.replace(key, changesetId);
    return changesetId;
}
Also used : OpenChangesetKey(de.westnordost.streetcomplete.data.changesets.OpenChangesetKey)

Aggregations

OpenChangesetKey (de.westnordost.streetcomplete.data.changesets.OpenChangesetKey)4 SharedPreferences (android.content.SharedPreferences)1 Point (android.graphics.Point)1 MapDataDao (de.westnordost.osmapi.map.MapDataDao)1 Element (de.westnordost.osmapi.map.data.Element)1 OpenChangesetInfo (de.westnordost.streetcomplete.data.changesets.OpenChangesetInfo)1 OpenChangesetsDao (de.westnordost.streetcomplete.data.changesets.OpenChangesetsDao)1 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)1 OsmQuest (de.westnordost.streetcomplete.data.osm.OsmQuest)1 MergedElementDao (de.westnordost.streetcomplete.data.osm.persist.MergedElementDao)1 OsmQuestDao (de.westnordost.streetcomplete.data.osm.persist.OsmQuestDao)1 DownloadedTilesDao (de.westnordost.streetcomplete.data.tiles.DownloadedTilesDao)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1