Search in sources :

Example 1 with OsmConflictException

use of de.westnordost.osmapi.common.errors.OsmConflictException in project StreetComplete by westnordost.

the class AOsmQuestChangesUpload method closeOpenChangesets.

public synchronized void closeOpenChangesets() {
    long timePassed = System.currentTimeMillis() - openChangesetsDB.getLastQuestSolvedTime();
    if (timePassed < OpenChangesetsDao.CLOSE_CHANGESETS_AFTER_INACTIVITY_OF)
        return;
    for (OpenChangesetInfo info : openChangesetsDB.getAll()) {
        try {
            osmDao.closeChangeset(info.changesetId);
            Log.i(TAG, "Closed changeset #" + info.changesetId + ".");
        } catch (OsmConflictException e) {
            Log.w(TAG, "Couldn't close changeset #" + info.changesetId + " because it has already been closed.");
        } finally {
            // done!
            openChangesetsDB.delete(info.key);
        }
    }
}
Also used : OsmConflictException(de.westnordost.osmapi.common.errors.OsmConflictException) OpenChangesetInfo(de.westnordost.streetcomplete.data.changesets.OpenChangesetInfo)

Example 2 with OsmConflictException

use of de.westnordost.osmapi.common.errors.OsmConflictException in project StreetComplete by westnordost.

the class OsmNoteQuestChangesUpload method uploadNoteChanges.

Note uploadNoteChanges(OsmNoteQuest quest) {
    String text = quest.getComment();
    try {
        text += AttachPhotoUtils.uploadAndGetAttachedPhotosText(imageUploader, quest.getImagePaths());
        Note newNote = osmDao.comment(quest.getNote().id, text);
        /* Unlike OSM quests, note quests are never deleted when the user contributed to it
			   but must remain in the database with the status CLOSED as long as they are not
			   solved. The reason is because as long as a note is unsolved, the problem at that
			   position persists and thus it should still block other quests to be created.
			   (Reminder: Note quests block other quests)
			  */
        // so, not this: questDB.delete(quest.getId());
        quest.setStatus(QuestStatus.CLOSED);
        quest.setNote(newNote);
        questDB.update(quest);
        noteDB.put(newNote);
        AttachPhotoUtils.deleteImages(quest.getImagePaths());
        return newNote;
    } catch (OsmConflictException e) {
        // someone else already closed the note -> our contribution is probably worthless. Delete
        questDB.delete(quest.getId());
        noteDB.delete(quest.getNote().id);
        AttachPhotoUtils.deleteImages(quest.getImagePaths());
        Log.i(TAG, "Dropped the comment " + getNoteQuestStringForLog(quest) + " because the note has already been closed");
        return null;
    }
}
Also used : OsmConflictException(de.westnordost.osmapi.common.errors.OsmConflictException) Note(de.westnordost.osmapi.notes.Note)

Example 3 with OsmConflictException

use of de.westnordost.osmapi.common.errors.OsmConflictException in project StreetComplete by westnordost.

the class AOsmQuestChangesUpload method uploadQuestChange.

boolean uploadQuestChange(long changesetId, OsmQuest quest, Element element, boolean alreadyHandlingElementConflict, boolean alreadyHandlingChangesetConflict) {
    Element elementWithChangesApplied = changesApplied(element, quest);
    if (elementWithChangesApplied == null) {
        deleteConflictingQuest(quest);
        return false;
    }
    int[] newVersion = { element.getVersion() };
    try {
        osmDao.uploadChanges(changesetId, Collections.singleton(elementWithChangesApplied), diffElement -> {
            if (diffElement.clientId == elementWithChangesApplied.getId()) {
                newVersion[0] = diffElement.serverVersion;
            /* It is not necessary (yet) to handle updating the element's id because
					   StreetComplete does not add or delete elements */
            }
        });
    } catch (OsmConflictException e) {
        return handleConflict(changesetId, quest, element, alreadyHandlingElementConflict, alreadyHandlingChangesetConflict, e);
    }
    Element updatedElement = copyElement(elementWithChangesApplied, newVersion[0]);
    closeQuest(quest);
    // save with new version when persisting to DB
    elementDB.put(updatedElement);
    statisticsDB.addOne(quest.getType().getClass().getSimpleName());
    unlockedQuests.addAll(questUnlocker.unlockNewQuests(updatedElement));
    return true;
}
Also used : OsmConflictException(de.westnordost.osmapi.common.errors.OsmConflictException) Element(de.westnordost.osmapi.map.data.Element)

Aggregations

OsmConflictException (de.westnordost.osmapi.common.errors.OsmConflictException)3 Element (de.westnordost.osmapi.map.data.Element)1 Note (de.westnordost.osmapi.notes.Note)1 OpenChangesetInfo (de.westnordost.streetcomplete.data.changesets.OpenChangesetInfo)1