Search in sources :

Example 1 with SyncUploadNoteRetrofitErrorEvent

use of io.jawg.osmcontributor.rest.events.error.SyncUploadNoteRetrofitErrorEvent in project osm-contributor by jawg.

the class OSMSyncNoteManager method remoteAddComment.

/**
 * {@inheritDoc}
 */
public Note remoteAddComment(final Comment comment) {
    Call<OsmDto> osmDtoCall;
    switch(comment.getAction()) {
        case Comment.ACTION_CLOSE:
            osmDtoCall = osmRestClient.closeNote(comment.getNote().getBackendId(), comment.getText(), "");
            break;
        case Comment.ACTION_REOPEN:
            osmDtoCall = osmRestClient.reopenNote(comment.getNote().getBackendId(), comment.getText(), "");
            break;
        case Comment.ACTION_OPEN:
            osmDtoCall = osmRestClient.addNote(comment.getNote().getLatitude(), comment.getNote().getLongitude(), comment.getText(), "");
            break;
        default:
            osmDtoCall = osmRestClient.addComment(comment.getNote().getBackendId(), comment.getText(), "");
            break;
    }
    try {
        Response<OsmDto> response = osmDtoCall.execute();
        if (response.isSuccessful()) {
            OsmDto osmDto = response.body();
            if (osmDto != null) {
                NoteDto noteDto = osmDto.getNoteDtoList().get(0);
                Note note = noteMapper.convertNoteDtoToNote(noteDto);
                note.setUpdated(false);
                note.setId(comment.getNote().getId());
                return note;
            }
        } else if (response.code() == 409) {
            bus.post(new SyncConflictingNoteErrorEvent(comment.getNote()));
        }
    } catch (IOException e) {
        Timber.e(e, "Retrofit error, couldn't create comment !");
    }
    bus.post(new SyncUploadNoteRetrofitErrorEvent(comment.getNote().getId()));
    return null;
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) SyncConflictingNoteErrorEvent(io.jawg.osmcontributor.rest.events.error.SyncConflictingNoteErrorEvent) Note(io.jawg.osmcontributor.model.entities.Note) SyncUploadNoteRetrofitErrorEvent(io.jawg.osmcontributor.rest.events.error.SyncUploadNoteRetrofitErrorEvent) IOException(java.io.IOException) NoteDto(io.jawg.osmcontributor.rest.dtos.osm.NoteDto)

Aggregations

Note (io.jawg.osmcontributor.model.entities.Note)1 NoteDto (io.jawg.osmcontributor.rest.dtos.osm.NoteDto)1 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)1 SyncConflictingNoteErrorEvent (io.jawg.osmcontributor.rest.events.error.SyncConflictingNoteErrorEvent)1 SyncUploadNoteRetrofitErrorEvent (io.jawg.osmcontributor.rest.events.error.SyncUploadNoteRetrofitErrorEvent)1 IOException (java.io.IOException)1