use of io.jawg.osmcontributor.rest.dtos.osm.NoteDto in project osm-contributor by jawg.
the class NoteMapper method convertNoteToNoteDto.
/**
* @param note the note to convert
* @return the converted NoteDto
*/
public NoteDto convertNoteToNoteDto(Note note) {
NoteDto noteDto = new NoteDto();
noteDto.setLat(note.getLatitude());
noteDto.setLon(note.getLongitude());
noteDto.setId(note.getBackendId());
noteDto.setStatus(note.getStatus());
noteDto.setCommentDtoList(commentMapper.convertFromComment(note.getComments()));
return noteDto;
}
use of io.jawg.osmcontributor.rest.dtos.osm.NoteDto in project osm-contributor by jawg.
the class OSMSyncNoteManager method syncDownloadNotesInBox.
/**
* {@inheritDoc}
*/
@Override
public List<Note> syncDownloadNotesInBox(final Box box) {
Timber.d("Requesting osm for notes download");
String strBox = box.getWest() + "," + box.getSouth() + "," + box.getEast() + "," + box.getNorth();
Call<OsmDto> osmDtoCall = osmRestClient.getNotes(strBox);
try {
Response<OsmDto> response = osmDtoCall.execute();
if (response.isSuccessful()) {
OsmDto osmDto = response.body();
if (osmDto != null) {
List<NoteDto> noteDtos = osmDto.getNoteDtoList();
if (noteDtos != null && !noteDtos.isEmpty()) {
Timber.d("Updating %d note(s)", noteDtos.size());
bus.post(new SyncDownloadRetrofitErrorEvent());
return noteMapper.convertNoteDtosToNotes(noteDtos);
}
}
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
return null;
}
use of io.jawg.osmcontributor.rest.dtos.osm.NoteDto 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;
}
use of io.jawg.osmcontributor.rest.dtos.osm.NoteDto in project osm-contributor by jawg.
the class NoteMapper method convertNoteDtosToNotes.
public List<Note> convertNoteDtosToNotes(List<NoteDto> dtos) {
List<Note> result = new ArrayList<>();
if (dtos != null) {
for (NoteDto dto : dtos) {
Note note = new Note();
note.setLatitude(dto.getLat());
note.setLongitude(dto.getLon());
note.setBackendId(dto.getId());
note.setUpdated(false);
note.setStatus(dto.getStatus());
DateTime dt = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
try {
Date date = simpleDateFormat.parse(dto.getDate_created());
dt = new DateTime(date);
} catch (ParseException ex) {
System.out.println("Exception " + ex);
}
note.setCreatedDate(dt);
ArrayList<Comment> comments = new ArrayList<>(dto.getCommentDtoList().size());
for (CommentDto commentDto : dto.getCommentDtoList()) {
Comment comment = new Comment();
comment.setNote(note);
comment.setUpdated(false);
comment.setAction(commentDto.getAction());
comment.setText(commentDto.getText());
try {
Date date = simpleDateFormat.parse(commentDto.getDate());
dt = new DateTime(date);
} catch (ParseException ex) {
System.out.println("Exception " + ex);
}
comment.setCreatedDate(dt);
comments.add(comment);
}
note.setComments(comments);
result.add(note);
}
}
return result;
}
Aggregations