Search in sources :

Example 1 with ActivityStreamComment

use of org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment in project entando-core by entando.

the class SocialActivityStreamDAO method getActionCommentRecords.

@Override
public List<ActivityStreamComment> getActionCommentRecords(int id) {
    List<ActivityStreamComment> comments = new ArrayList<>();
    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet result = null;
    try {
        conn = this.getConnection();
        stat = conn.prepareStatement(GET_ACTION_COMMENT_RECORDS);
        stat.setInt(1, id);
        result = stat.executeQuery();
        while (result.next()) {
            ActivityStreamComment comment = new ActivityStreamComment();
            comment.setId(result.getInt(1));
            comment.setUsername(result.getString(2));
            comment.setCommentText(result.getString(3));
            Timestamp timestamp = result.getTimestamp(4);
            comment.setCommentDate(new Date(timestamp.getTime()));
            comments.add(comment);
        }
    } catch (Throwable t) {
        logger.error("Error while loading activity stream comment records", t);
        throw new RuntimeException("Error while loading activity stream comment records", t);
    } finally {
        closeDaoResources(result, stat, conn);
    }
    return comments;
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Date(java.util.Date) ActivityStreamComment(org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment)

Example 2 with ActivityStreamComment

use of org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment in project entando-core by entando.

the class SocialActivityStreamManager method getActionCommentRecords.

@Override
@CachePut(value = ICacheInfoManager.DEFAULT_CACHE_NAME, key = "'ActivityStreamCommentRecords_id_'.concat(#id)")
@CacheableInfo(groups = "'ActivityStreamCommentRecords_cacheGroup'")
public List<ActivityStreamComment> getActionCommentRecords(int id) throws ApsSystemException {
    List<ActivityStreamComment> infos = null;
    try {
        infos = this.getSocialActivityStreamDAO().getActionCommentRecords(id);
        if (null != infos) {
            for (int i = 0; i < infos.size(); i++) {
                ActivityStreamComment comment = infos.get(i);
                String username = comment.getUsername();
                IUserProfile profile = this.getUserProfileManager().getProfile(username);
                String displayName = (null != profile) ? profile.getDisplayName() : username;
                comment.setDisplayName(displayName);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error extracting activity stream like records for stream with id {}", id, t);
        throw new ApsSystemException("Error extracting activity stream like records", t);
    }
    return infos;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ActivityStreamComment(org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment) CacheableInfo(org.entando.entando.aps.system.services.cache.CacheableInfo) CachePut(org.springframework.cache.annotation.CachePut)

Example 3 with ActivityStreamComment

use of org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment in project entando-core by entando.

the class TestSocialActivityStreamDAO method testAddDeleteCommentRecord.

public void testAddDeleteCommentRecord() throws Throwable {
    ActionLogRecord record1 = this._helper.createActionRecord(1, "username1", "actionName1", "namespace1", DateConverter.parseDate("01/01/2009 00:00", "dd/MM/yyyy HH:mm"), "params1");
    ActionLogRecord record2 = this._helper.createActionRecord(2, "username2", "actionName2", "namespace2", DateConverter.parseDate("01/02/2009 00:00", "dd/MM/yyyy HH:mm"), "params2");
    this._actionLoggerDAO.addActionRecord(record1);
    this._actionLoggerDAO.addActionRecord(record2);
    ActionLogRecord addedRecord1 = this._actionLoggerDAO.getActionRecord(record1.getId());
    this.compareActionRecords(record1, addedRecord1);
    ActionLogRecord addedRecord2 = this._actionLoggerDAO.getActionRecord(record2.getId());
    this.compareActionRecords(record2, addedRecord2);
    this._socialActivityStreamDAO.addActionCommentRecord(100, addedRecord1.getId(), "admin", "test comment 1");
    synchronized (this) {
        this.wait(1000);
    }
    this._socialActivityStreamDAO.addActionCommentRecord(101, addedRecord1.getId(), "admin", "test comment 2");
    List<ActivityStreamComment> actionCommentRecords = this._socialActivityStreamDAO.getActionCommentRecords(addedRecord1.getId());
    assertEquals(2, actionCommentRecords.size());
    assertEquals(100, actionCommentRecords.get(0).getId());
    assertEquals(101, actionCommentRecords.get(1).getId());
    this._socialActivityStreamDAO.deleteActionCommentRecord(100);
    actionCommentRecords = this._socialActivityStreamDAO.getActionCommentRecords(addedRecord1.getId());
    assertEquals(1, actionCommentRecords.size());
    assertEquals("test comment 2", actionCommentRecords.get(0).getCommentText());
}
Also used : ActionLogRecord(org.entando.entando.aps.system.services.actionlog.model.ActionLogRecord) ActivityStreamComment(org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment)

Aggregations

ActivityStreamComment (org.entando.entando.apsadmin.system.services.activitystream.model.ActivityStreamComment)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ActionLogRecord (org.entando.entando.aps.system.services.actionlog.model.ActionLogRecord)1 CacheableInfo (org.entando.entando.aps.system.services.cache.CacheableInfo)1 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)1 CachePut (org.springframework.cache.annotation.CachePut)1