Search in sources :

Example 6 with UserCommentVO

use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.

the class EventInstanceModel method setComments.

@JsonSetter
public void setComments(List<UserCommentModel> commentModels) {
    List<UserCommentVO> comments = this.data.getEventComments();
    if (comments == null) {
        comments = new ArrayList<UserCommentVO>();
        this.data.setEventComments(comments);
    }
    for (UserCommentModel model : commentModels) {
        comments.add(model.getDataAsComment());
    }
}
Also used : UserCommentModel(com.serotonin.m2m2.web.mvc.rest.v1.model.comment.UserCommentModel) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO) JsonSetter(com.fasterxml.jackson.annotation.JsonSetter)

Example 7 with UserCommentVO

use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.

the class EventInstanceModel method getComments.

@JsonGetter
public List<UserCommentModel> getComments() {
    List<UserCommentModel> commentModels = new ArrayList<UserCommentModel>();
    List<UserCommentVO> comments = this.data.getEventComments();
    if (comments == null)
        return null;
    for (UserCommentVO comment : comments) {
        commentModels.add(new UserCommentModel(comment));
    }
    return commentModels;
}
Also used : UserCommentModel(com.serotonin.m2m2.web.mvc.rest.v1.model.comment.UserCommentModel) ArrayList(java.util.ArrayList) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO) JsonGetter(com.fasterxml.jackson.annotation.JsonGetter)

Example 8 with UserCommentVO

use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-modules-public by infiniteautomation.

the class ReportDao method getReportInstanceEvents.

public List<EventInstance> getReportInstanceEvents(int instanceId) {
    // Get the events.
    final List<EventInstance> events = query(EVENT_SELECT, new Object[] { instanceId }, new EventDao.EventInstanceRowMapper());
    // Add in the comments.
    ejt.query(EVENT_COMMENT_SELECT, new Object[] { instanceId, UserCommentVO.TYPE_EVENT }, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            // Create the comment
            UserCommentVO c = new UserCommentVO();
            c.setUsername(rs.getString(1));
            c.setTs(rs.getLong(3));
            c.setComment(rs.getString(4));
            // Find the event and add the comment
            int eventId = rs.getInt(2);
            for (EventInstance event : events) {
                if (event.getId() == eventId) {
                    if (event.getEventComments() == null)
                        event.setEventComments(new ArrayList<UserCommentVO>());
                    event.addEventComment(c);
                }
            }
        }
    });
    // Done
    return events;
}
Also used : EventInstance(com.serotonin.m2m2.rt.event.EventInstance) EventDao(com.serotonin.m2m2.db.dao.EventDao) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO)

Example 9 with UserCommentVO

use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-core-public by infiniteautomation.

the class BaseDwr method addUserComment.

/**
 * Logs a user comment after validation.
 *
 * @param eventId
 * @param comment
 * @return
 */
@DwrPermission(user = true)
public UserCommentVO addUserComment(int typeId, int referenceId, String comment) {
    if (StringUtils.isBlank(comment))
        return null;
    User user = Common.getHttpUser();
    UserCommentVO c = new UserCommentVO();
    c.setXid(UserCommentDao.instance.generateUniqueXid());
    c.setComment(comment);
    c.setTs(Common.timer.currentTimeMillis());
    c.setUserId(user.getId());
    c.setUsername(user.getUsername());
    c.setReferenceId(referenceId);
    if (typeId == UserCommentVO.TYPE_EVENT) {
        c.setCommentType(UserCommentVO.TYPE_EVENT);
        EventDao.instance.insertEventComment(c);
    } else if (typeId == UserCommentVO.TYPE_POINT) {
        c.setCommentType(UserCommentVO.TYPE_POINT);
        UserCommentDao.instance.save(c);
    } else
        throw new ShouldNeverHappenException("Invalid comment type: " + typeId);
    return c;
}
Also used : User(com.serotonin.m2m2.vo.User) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 10 with UserCommentVO

use of com.serotonin.m2m2.vo.comment.UserCommentVO in project ma-core-public by infiniteautomation.

the class EventInstanceVO method getCommentsHTML.

/**
 * Construct the comments html
 * @return
 */
public String getCommentsHTML() {
    StringBuilder builder = new StringBuilder("");
    if (eventComments != null) {
        builder.append("</br>");
        for (UserCommentVO comment : this.eventComments) {
            builder.append("<span class='copyTitle'>");
            builder.append("<img style='padding-right: 5px' src='/images/comment.png' title='").append(Common.translate("notes.note")).append("'/>");
            builder.append(DeltamationCommon.formatDate(comment.getTs())).append(" ");
            builder.append(Common.translate("notes.by")).append(" ");
            if (comment.getUsername() == null)
                builder.append(Common.translate("common.deleted"));
            else
                builder.append(comment.getUsername());
            builder.append("</span></br>");
            builder.append(comment.getComment()).append("</br>");
        }
    }
    return builder.toString();
}
Also used : UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO)

Aggregations

UserCommentVO (com.serotonin.m2m2.vo.comment.UserCommentVO)11 UserCommentModel (com.serotonin.m2m2.web.mvc.rest.v1.model.comment.UserCommentModel)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 User (com.serotonin.m2m2.vo.User)3 JsonGetter (com.fasterxml.jackson.annotation.JsonGetter)1 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonSetter (com.fasterxml.jackson.annotation.JsonSetter)1 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 EventDao (com.serotonin.m2m2.db.dao.EventDao)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)1 DataPointEventType (com.serotonin.m2m2.rt.event.type.DataPointEventType)1 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)1 EventType (com.serotonin.m2m2.rt.event.type.EventType)1 MissingEventType (com.serotonin.m2m2.rt.event.type.MissingEventType)1 PublisherEventType (com.serotonin.m2m2.rt.event.type.PublisherEventType)1 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)1