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