Search in sources :

Example 1 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteManager method saveNoteNoTransactionMgmt.

/**
 * Method saving a note and the associated foreign collection (comments) without transaction management.
 * <p/>
 * Do not call the DAO directly to save a note, use this method.
 *
 * @param note The note to save.
 * @return The saved note.
 * @see #saveNote(Note)
 */
private Note saveNoteNoTransactionMgmt(Note note) {
    commentDao.deleteByNoteIdAndUpdated(note.getId(), false);
    noteDao.createOrUpdate(note);
    if (note.getComments() != null) {
        for (Comment comment : note.getComments()) {
            commentDao.createOrUpdate(comment);
        }
    }
    bus.post(new NoteSavedEvent(note));
    return note;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) PleaseApplyNewComment(io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment) NoteSavedEvent(io.jawg.osmcontributor.model.events.NoteSavedEvent)

Example 2 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteManager method createComment.

/**
 * Create a Comment with the given parameters without modifying the Note.
 *
 * @param note    The Note associated with the comment.
 * @param action  The action of the comment.
 * @param comment The comment of the comment.
 * @return The created comment.
 */
public Comment createComment(Note note, String action, String comment) {
    Comment newComment = new Comment();
    newComment.setText(comment);
    switch(action) {
        case NoteActivity.CLOSE:
            newComment.setAction(Comment.ACTION_CLOSE);
            break;
        case NoteActivity.COMMENT:
            newComment.setAction(Comment.ACTION_COMMENT);
            break;
        case NoteActivity.REOPEN:
            newComment.setAction(Comment.ACTION_REOPEN);
            break;
        default:
            newComment.setAction(Comment.ACTION_OPEN);
            break;
    }
    newComment.setNote(note);
    return newComment;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) PleaseApplyNewComment(io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment)

Example 3 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class NoteDetailFragment method setNote.

private void setNote(Note note) {
    this.note = note;
    List<Comment> comments = new ArrayList<>();
    comments.addAll(note.getComments());
    if (!comments.isEmpty()) {
        for (Comment c : comments) {
            if (c.getAction().equals("opened")) {
                textViewCommentText.setText(c.getText());
            }
        }
    }
    textViewNoteStatus.setText("Note (" + note.getStatus() + ")");
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) ArrayList(java.util.ArrayList)

Example 4 with Comment

use of io.jawg.osmcontributor.model.entities.Comment in project osm-contributor by jawg.

the class CommentMapper method convertFromComment.

public List<CommentDto> convertFromComment(Collection<Comment> comments) {
    List<CommentDto> result = new ArrayList<>();
    for (Comment comment : comments) {
        CommentDto commentDto = new CommentDto();
        commentDto.setText(comment.getText());
        commentDto.setAction(comment.getAction());
        result.add(commentDto);
    }
    return result;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) ArrayList(java.util.ArrayList) CommentDto(io.jawg.osmcontributor.rest.dtos.osm.CommentDto)

Example 5 with Comment

use of io.jawg.osmcontributor.model.entities.Comment 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;
}
Also used : Comment(io.jawg.osmcontributor.model.entities.Comment) Note(io.jawg.osmcontributor.model.entities.Note) ArrayList(java.util.ArrayList) CommentDto(io.jawg.osmcontributor.rest.dtos.osm.CommentDto) ParseException(java.text.ParseException) NoteDto(io.jawg.osmcontributor.rest.dtos.osm.NoteDto) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Aggregations

Comment (io.jawg.osmcontributor.model.entities.Comment)9 ArrayList (java.util.ArrayList)5 Note (io.jawg.osmcontributor.model.entities.Note)4 DateTime (org.joda.time.DateTime)3 CommentDto (io.jawg.osmcontributor.rest.dtos.osm.CommentDto)2 PleaseApplyNewComment (io.jawg.osmcontributor.ui.events.map.PleaseApplyNewComment)2 NoteManager (io.jawg.osmcontributor.ui.managers.NoteManager)2 Test (org.junit.Test)2 LayoutInflater (android.view.LayoutInflater)1 NoteSavedEvent (io.jawg.osmcontributor.model.events.NoteSavedEvent)1 NoteDto (io.jawg.osmcontributor.rest.dtos.osm.NoteDto)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1