Index: lams_common/src/java/org/lamsfoundation/lams/notebook/service/CoreNotebookService.java =================================================================== diff -u -r9aad33f52b06632e7a8ed3705a7708338bcc00f8 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_common/src/java/org/lamsfoundation/lams/notebook/service/CoreNotebookService.java (.../CoreNotebookService.java) (revision 9aad33f52b06632e7a8ed3705a7708338bcc00f8) +++ lams_common/src/java/org/lamsfoundation/lams/notebook/service/CoreNotebookService.java (.../CoreNotebookService.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -118,19 +118,23 @@ * notebook entries (the Strings) are needed. * * Finally, as it will be returning the notebook entry as a separate field in select clause, set up the sql -> java - * object translation using ".addScalar("notebookEntry", Hibernate.STRING)". + * object translation using ".addScalar("notebookEntry", Hibernate.STRING)" if includeDateModified = false or + * .addScalar("notebookEntry", Hibernate.STRING).addScalar("notebookCreateDate", Hibernate.DATE).addScalar("notebookModifiedDate", Hibernate.DATE) + * if includeDates = true. * * @param sessionIdString * Session identifier, usually the toolSessionId * @param toolSignature * Tool's string signature (without any quotes) e.g. lantbk11 * @param userIdString * User identifier field string e.g. + * @param includeDates + * if true, SQL should also return the date modified as well as the notebook entry * @return String[] { partial select string, join clause } * */ @Override - public String[] getNotebookEntrySQLStrings(String sessionIdString, String toolSignature, String userIdString) { + public String[] getNotebookEntrySQLStrings(String sessionIdString, String toolSignature, String userIdString, boolean includeDates) { StringBuilder buf = new StringBuilder(" LEFT JOIN lams_notebook_entry entry ON entry.external_id="); buf.append(sessionIdString); buf.append(" AND entry.external_id_type="); @@ -139,10 +143,19 @@ buf.append(toolSignature); buf.append("\" AND entry.user_id="); buf.append(userIdString); - return new String[] { ", entry.entry notebookEntry ", buf.toString() }; + String[] retValue = new String[2]; + retValue[0] = includeDates ? ", entry.entry notebookEntry, entry.create_date notebookCreateDate, entry.last_modified notebookModifiedDate " : ", entry.entry notebookEntry "; + retValue[1] = buf.toString(); + return retValue; } + @Override + public String[] getNotebookEntrySQLStrings(String sessionIdString, String toolSignature, String userIdString) { + return getNotebookEntrySQLStrings(sessionIdString, toolSignature, userIdString, false); + } + + @Override public List getEntry(Long id, Integer idType, String signature) { return notebookEntryDAO.get(id, idType, signature); } Index: lams_common/src/java/org/lamsfoundation/lams/notebook/service/ICoreNotebookService.java =================================================================== diff -u -r9aad33f52b06632e7a8ed3705a7708338bcc00f8 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_common/src/java/org/lamsfoundation/lams/notebook/service/ICoreNotebookService.java (.../ICoreNotebookService.java) (revision 9aad33f52b06632e7a8ed3705a7708338bcc00f8) +++ lams_common/src/java/org/lamsfoundation/lams/notebook/service/ICoreNotebookService.java (.../ICoreNotebookService.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -41,6 +41,7 @@ List getEntry(Long id, Integer idType, String signature, Integer userID); String[] getNotebookEntrySQLStrings(String sessionIdString, String toolSignature, String userIdString); + String[] getNotebookEntrySQLStrings(String sessionIdString, String toolSignature, String userIdString, boolean includeDates); List getEntry(Long id, Integer idType, String signature); Index: lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java =================================================================== diff -u -racc8d2acf5b6b0002e0c8129947040a779ab4077 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java (.../DateUtil.java) (revision acc8d2acf5b6b0002e0c8129947040a779ab4077) +++ lams_common/src/java/org/lamsfoundation/lams/util/DateUtil.java (.../DateUtil.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.util; import java.sql.Timestamp; +import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -45,6 +46,7 @@ public static final String WDDX_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; public static final String LAMS_FLASH_FORMAT = "dd/M/yyyy h:mm a"; + private static final DateFormat JSON_DATE_OUTPUT_FORMATTER = new SimpleDateFormat("d MMMM yyyy h:mm:ss a"); /** * Convert your local time to Universal Time Coordinator. @@ -182,4 +184,12 @@ return convertFromString(dateString, LAMS_FLASH_FORMAT); } + + /** + * Convert a date to a String for sending to the client via JSON. + */ + public static String convertToStringForJSON(Date date) { + return JSON_DATE_OUTPUT_FORMATTER.format(date); + } + } Index: lams_tool_notebook/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rdd54a263f740bfa28f0079c04053ff4350ce5aff -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision dd54a263f740bfa28f0079c04053ff4350ce5aff) +++ lams_tool_notebook/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -111,6 +111,10 @@ event.teacher.comment.subject =Teacher has left a comment for your notebook entry. event.teacher.comment.body =Comment: label.click.to.edit =Click to edit - - +label.notebook.entries=Notebook Entries +label.user.name=Username +label.comment=Comment +label.no.entry=No Entry +label.yes=Yes +label.no=No #======= End labels: Exported 105 labels for en AU ===== Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/INotebookUserDAO.java =================================================================== diff -u -r9e446244a7245a4e8893e4673a801c56e4a35334 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/INotebookUserDAO.java (.../INotebookUserDAO.java) (revision 9e446244a7245a4e8893e4673a801c56e4a35334) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/INotebookUserDAO.java (.../INotebookUserDAO.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -24,7 +24,11 @@ package org.lamsfoundation.lams.tool.notebook.dao; +import java.util.List; + import org.lamsfoundation.lams.dao.IBaseDAO; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; +import org.lamsfoundation.lams.tool.notebook.dto.StatisticDTO; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; /** @@ -57,4 +61,15 @@ * @return */ NotebookUser getByUID(Long uid); + + /** Will return List<[NotebookUser, String, Date, Date]> + * where the String is the notebook entry, the first date is the create date and the second date is the modified date. + * No notebook entries needed? Will return in their place. + */ + List getUsersForTablesorter(final Long sessionId, int page, int size, int sorting, String searchString, + ICoreNotebookService coreNotebookService); + int getCountUsersBySession(final Long sessionId, String searchString); + + /** Get the statistics for monitoring */ + List getStatisticsBySession(final Long contentId) ; } \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/hibernate/NotebookUserDAO.java =================================================================== diff -u -r9e446244a7245a4e8893e4673a801c56e4a35334 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/hibernate/NotebookUserDAO.java (.../NotebookUserDAO.java) (revision 9e446244a7245a4e8893e4673a801c56e4a35334) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dao/hibernate/NotebookUserDAO.java (.../NotebookUserDAO.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -26,9 +26,17 @@ import java.util.List; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Hibernate; +import org.hibernate.SQLQuery; +import org.hibernate.transform.Transformers; import org.lamsfoundation.lams.dao.hibernate.BaseDAO; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; import org.lamsfoundation.lams.tool.notebook.dao.INotebookUserDAO; +import org.lamsfoundation.lams.tool.notebook.dto.StatisticDTO; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; +import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; /** * DAO for accessing the NotebookUser objects - Hibernate specific code. @@ -85,4 +93,121 @@ return (NotebookUser) list.get(0); } + + @SuppressWarnings("unchecked") + /** Will return List<[NotebookUser, String, Date, Date]> + * where the String is the notebook entry, the first date is the create date and the second date is the modified date. + * No notebook entries needed? Will return in their place. + */ + public List getUsersForTablesorter(final Long sessionId, int page, int size, int sorting, String searchString, + ICoreNotebookService coreNotebookService) { + String sortingOrder; + switch (sorting) { + case NotebookConstants.SORT_BY_USERNAME_ASC: + sortingOrder = "user.last_name ASC, user.first_name ASC"; + break; + case NotebookConstants.SORT_BY_USERNAME_DESC: + sortingOrder = "user.last_name DESC, user.first_name DESC"; + break; + case NotebookConstants.SORT_BY_DATE_ASC: + sortingOrder = "notebookCreateDate ASC"; + break; + case NotebookConstants.SORT_BY_DATE_DESC: + sortingOrder = "notebookCreateDate DESC"; + break; + case NotebookConstants.SORT_BY_COMMENT_ASC: + sortingOrder = "user.teachers_comment ASC"; + break; + case NotebookConstants.SORT_BY_COMMENT_DESC: + sortingOrder = "user.teachers_comment DESC"; + break; + default: + sortingOrder = "user.last_name, user.first_name"; + } + + String[] notebookEntryStrings = coreNotebookService.getNotebookEntrySQLStrings(sessionId.toString(),NotebookConstants.TOOL_SIGNATURE,"user.user_id",true ); + + // Basic select for the user records + StringBuilder queryText = new StringBuilder(); + queryText.append("SELECT user.* "); + queryText.append(notebookEntryStrings[0]); + queryText.append(" FROM tl_lantbk11_user user "); + queryText.append(" JOIN tl_lantbk11_session session ON user.notebook_session_uid = session.uid and session.session_id = :sessionId"); + queryText.append(notebookEntryStrings[1]); + + // If filtering by name add a name based where clause + buildNameSearch(searchString, queryText); + + // Now specify the sort based on the switch statement above. + queryText.append(" ORDER BY " + sortingOrder); + + SQLQuery query = getSession().createSQLQuery(queryText.toString()); + query.addEntity("user", NotebookUser.class) + .addScalar("notebookEntry", Hibernate.STRING) + .addScalar("notebookCreateDate", Hibernate.TIMESTAMP) + .addScalar("notebookModifiedDate", Hibernate.TIMESTAMP) + .setLong("sessionId", sessionId.longValue()) + .setFirstResult(page * size) + .setMaxResults(size); + return query.list(); + } + + private void buildNameSearch(String searchString, StringBuilder sqlBuilder) { + if (!StringUtils.isBlank(searchString)) { + String[] tokens = searchString.trim().split("\\s+"); + for (String token : tokens) { + String escToken = StringEscapeUtils.escapeSql(token); + sqlBuilder.append(" WHERE (user.first_name LIKE '%").append(escToken) + .append("%' OR user.last_name LIKE '%").append(escToken) + .append("%' OR user.login_name LIKE '%").append(escToken).append("%') "); + } + } + } + + @SuppressWarnings("rawtypes") + public int getCountUsersBySession(final Long sessionId, String searchString) { + + StringBuilder queryText = new StringBuilder("SELECT count(*) FROM tl_lantbk11_user user "); + queryText.append(" JOIN tl_lantbk11_session session ON user.notebook_session_uid = session.uid and session.session_id = :sessionId"); + buildNameSearch(searchString, queryText); + + List list = getSession().createSQLQuery(queryText.toString()).setLong("sessionId", sessionId.longValue()).list(); + if (list == null || list.size() == 0) { + return 0; + } + return ((Number) list.get(0)).intValue(); + } + + @SuppressWarnings("rawtypes") + public int getStatistics(final Long sessionId, String searchString) { + + StringBuilder queryText = new StringBuilder("SELECT count(*) FROM tl_lantbk11_user user "); + queryText.append(" JOIN tl_lantbk11_session session ON user.notebook_session_uid = session.uid and session.session_id = :sessionId"); + buildNameSearch(searchString, queryText); + + List list = getSession().createSQLQuery(queryText.toString()).setLong("sessionId", sessionId.longValue()).list(); + if (list == null || list.size() == 0) { + return 0; + } + return ((Number) list.get(0)).intValue(); + } + + private static final String GET_STATISTICS = "SELECT session.session_id sessionId, session.session_name sessionName, " + + " COUNT(user.uid) numLearners, SUM(user.finishedActivity) numLearnersFinished " + + " FROM tl_lantbk11_notebook notebook, tl_lantbk11_session session, tl_lantbk11_user user " + + " WHERE notebook.tool_content_id = :contentId and notebook.uid = session.notebook_uid AND user.notebook_session_uid = session.uid " + + " GROUP BY session.session_id"; + + @SuppressWarnings("unchecked") + public List getStatisticsBySession(final Long contentId) { + SQLQuery query = getSession().createSQLQuery(GET_STATISTICS); + query.addScalar("sessionId", Hibernate.LONG) + .addScalar("sessionName", Hibernate.STRING) + .addScalar("numLearners", Hibernate.INTEGER) + .addScalar("numLearnersFinished", Hibernate.INTEGER) + .setLong("contentId", contentId) + .setResultTransformer(Transformers.aliasToBean(StatisticDTO.class)); + return query.list(); + } + } Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/NotebookSessionsDTO.java =================================================================== diff -u --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/NotebookSessionsDTO.java (revision 0) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/NotebookSessionsDTO.java (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -0,0 +1,158 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ + +package org.lamsfoundation.lams.tool.notebook.dto; + +/** Contains just the basic information for a notebook and it's sessions. It does not contain any user information. Used for the paging version of monitoring */ + +import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; + +import org.lamsfoundation.lams.tool.notebook.model.Notebook; +import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; + +public class NotebookSessionsDTO { + + public Long toolContentId; + + public String title; + + public String instructions; + + public boolean contentInUse; + + public boolean allowRichEditor; + + public boolean lockOnFinish; + + public Date submissionDeadline; + + public Map sessions; + + public Long currentTab; + + /* Constructors */ + @SuppressWarnings("rawtypes") + public NotebookSessionsDTO(Notebook notebook) { + toolContentId = notebook.getToolContentId(); + title = notebook.getTitle(); + instructions = notebook.getInstructions(); + contentInUse = notebook.isContentInUse(); + allowRichEditor = notebook.isAllowRichEditor(); + lockOnFinish = notebook.isLockOnFinished(); + + sessions = new TreeMap(); + for (Iterator iter = notebook.getNotebookSessions().iterator(); iter.hasNext();) { + NotebookSession session = (NotebookSession) iter.next(); + sessions.put(session.getSessionId(), session.getSessionName()); + } + } + + /* Getters / Setters */ + public String getInstructions() { + return instructions; + } + + public void setInstructions(String instructions) { + this.instructions = instructions; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Long getToolContentId() { + return toolContentId; + } + + public void setToolContentId(Long toolContentID) { + this.toolContentId = toolContentID; + } + + public Boolean getContentInUse() { + return contentInUse; + } + + public void setContentInUse(Boolean contentInUse) { + this.contentInUse = contentInUse; + } + + public boolean isAllowRichEditor() { + return allowRichEditor; + } + + public void setAllowRichEditor(boolean allowRichEditor) { + this.allowRichEditor = allowRichEditor; + } + + public boolean isLockOnFinish() { + return lockOnFinish; + } + + public void setLockOnFinish(boolean lockOnFinish) { + this.lockOnFinish = lockOnFinish; + } + + /** + * @return the submissionDeadline + */ + public Date getSubmissionDeadline() { + return submissionDeadline; + } + + /** + * @param submissionDeadline + * the submissionDeadline to set + */ + public void setSubmissionDeadline(Date submissionDeadline) { + this.submissionDeadline = submissionDeadline; + } + + public Long getCurrentTab() { + return currentTab; + } + + public void setCurrentTab(Long currentTab) { + this.currentTab = currentTab; + } + + public void setContentInUse(boolean contentInUse) { + this.contentInUse = contentInUse; + } + + public void setSessions(Map sessions) { + this.sessions = sessions; + } + + public Map getSessions() { + return sessions; + } +} \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/StatisticDTO.java =================================================================== diff -u --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/StatisticDTO.java (revision 0) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/dto/StatisticDTO.java (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -0,0 +1,75 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ + +package org.lamsfoundation.lams.tool.notebook.dto; + +public class StatisticDTO { + + public Long sessionId; + + public String sessionName; + + public int numLearners; + + public int numLearnersFinished; + + /* Constructors */ + public StatisticDTO() { + } + + /* Getters / Setters */ + public Long getSessionId() { + return sessionId; + } + + public void setSessionId(Long sessionId) { + this.sessionId = sessionId; + } + + public String getSessionName() { + return sessionName; + } + + public void setSessionName(String sessionName) { + this.sessionName = sessionName; + } + + public int getNumLearners() { + return numLearners; + } + + public void setNumLearners(int numLearners) { + this.numLearners = numLearners; + } + + public int getNumLearnersFinished() { + return numLearnersFinished; + } + + public void setNumLearnersFinished(int numLearnersFinished) { + this.numLearnersFinished = numLearnersFinished; + } + +} \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java =================================================================== diff -u -r61e93f3e13e9e2c7cade09a54b751e4be730cf01 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java (.../INotebookService.java) (revision 61e93f3e13e9e2c7cade09a54b751e4be730cf01) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/INotebookService.java (.../INotebookService.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -25,8 +25,11 @@ package org.lamsfoundation.lams.tool.notebook.service; import java.util.Collection; +import java.util.List; import org.lamsfoundation.lams.notebook.model.NotebookEntry; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; +import org.lamsfoundation.lams.tool.notebook.dto.StatisticDTO; import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookCondition; import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; @@ -165,4 +168,13 @@ */ String getLearnerContentFolder(Long toolSessionId, Long userId); + /** Will return List<[NotebookUser, String, Date, Date]> + * where the String is the notebook entry, the first date is the create date and the second date is the modified date. + */ + List getUsersForTablesorter(final Long sessionId, int page, int size, int sorting, String searchString); + int getCountUsersBySession(final Long sessionId, String searchString); + + /** Get the statistics for monitoring */ + List getStatisticsBySession(final Long contentId) ; + } \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java =================================================================== diff -u -r9aad33f52b06632e7a8ed3705a7708338bcc00f8 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (.../NotebookService.java) (revision 9aad33f52b06632e7a8ed3705a7708338bcc00f8) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/service/NotebookService.java (.../NotebookService.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -57,6 +57,7 @@ import org.lamsfoundation.lams.tool.notebook.dao.INotebookDAO; import org.lamsfoundation.lams.tool.notebook.dao.INotebookSessionDAO; import org.lamsfoundation.lams.tool.notebook.dao.INotebookUserDAO; +import org.lamsfoundation.lams.tool.notebook.dto.StatisticDTO; import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookCondition; import org.lamsfoundation.lams.tool.notebook.model.NotebookSession; @@ -468,7 +469,19 @@ private String getLocalisedMessage(String key, Object[] args) { return messageService.getMessage(key, args); } + + public List getUsersForTablesorter(final Long sessionId, int page, int size, int sorting, String searchString) { + return notebookUserDAO.getUsersForTablesorter(sessionId, page, size, sorting, searchString, coreNotebookService); + } + + public int getCountUsersBySession(final Long sessionId, String searchString) { + return notebookUserDAO.getCountUsersBySession(sessionId, searchString); + } + public List getStatisticsBySession(final Long contentId) { + return notebookUserDAO.getStatisticsBySession(contentId); + } + /* ===============Methods implemented from ToolContentImport102Manager =============== */ /** @@ -680,5 +693,7 @@ // nb.setConditions(conditions); } + + } \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/util/NotebookConstants.java =================================================================== diff -u -r5fd25049d526080b60f6753a3d4603fb18913202 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/util/NotebookConstants.java (.../NotebookConstants.java) (revision 5fd25049d526080b60f6753a3d4603fb18913202) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/util/NotebookConstants.java (.../NotebookConstants.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -60,8 +60,24 @@ public static final String ERROR_MSG_CONDITION = "error.condition"; public static final String ERROR_MSG_NAME_BLANK = "error.condition.name.blank"; public static final String ERROR_MSG_NAME_DUPLICATED = "error.condition.duplicated.name"; + public static final String PARAM_ENTRY = "entry"; + public static final String PARAM_NAME = "userName"; + public static final String PARAM_MODIFIED_DATE = "lastEdited"; + public static final String PARAM_COMMENT = "comment"; + public static final String PARAM_COMMENT_SORT = "commentsort"; // used to trigger sorting on comments // for submission deadline public static final String ATTR_SUBMISSION_DEADLINE = "submissionDeadline"; public static final String ATTR_IS_SUBMISSION_DEADLINE_PASSED = "isSubmissionDeadlinePassed"; + + // monitor sorting + public static final int SORT_BY_NO = 1; + public static final int SORT_BY_USERNAME_ASC = 2; + public static final int SORT_BY_USERNAME_DESC = 3; + public static final int SORT_BY_DATE_ASC = 4; + public static final int SORT_BY_DATE_DESC = 5; + public static final int SORT_BY_COMMENT_ASC = 6; + public static final int SORT_BY_COMMENT_DESC = 7; + public static final String ASC = "asc"; + public static final String DESC = "desc"; } \ No newline at end of file Index: lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java =================================================================== diff -u -r61e93f3e13e9e2c7cade09a54b751e4be730cf01 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 61e93f3e13e9e2c7cade09a54b751e4be730cf01) +++ lams_tool_notebook/src/java/org/lamsfoundation/lams/tool/notebook/web/actions/MonitoringAction.java (.../MonitoringAction.java) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -24,7 +24,7 @@ package org.lamsfoundation.lams.tool.notebook.web.actions; -import java.util.ArrayList; +import java.io.IOException; import java.util.Date; import java.util.List; import java.util.TimeZone; @@ -33,38 +33,42 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.lamsfoundation.lams.events.IEventNotificationService; -import org.lamsfoundation.lams.notebook.model.NotebookEntry; -import org.lamsfoundation.lams.tool.notebook.dto.NotebookDTO; -import org.lamsfoundation.lams.tool.notebook.dto.NotebookEntryDTO; -import org.lamsfoundation.lams.tool.notebook.dto.NotebookSessionDTO; -import org.lamsfoundation.lams.tool.notebook.dto.NotebookUserDTO; +import org.apache.tomcat.util.json.JSONArray; +import org.apache.tomcat.util.json.JSONException; +import org.apache.tomcat.util.json.JSONObject; +import org.lamsfoundation.lams.tool.notebook.dto.NotebookSessionsDTO; import org.lamsfoundation.lams.tool.notebook.model.Notebook; import org.lamsfoundation.lams.tool.notebook.model.NotebookUser; import org.lamsfoundation.lams.tool.notebook.service.INotebookService; import org.lamsfoundation.lams.tool.notebook.service.NotebookServiceProxy; import org.lamsfoundation.lams.tool.notebook.util.NotebookConstants; -import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.DateUtil; +import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; /** * @struts.action path="/monitoring" parameter="dispatch" scope="request" name="monitoringForm" validate="false" * * @struts.action-forward name="success" path="tiles:/monitoring/main" + * + * @struts.action-forward name="statistic" path="/pages/monitoring/statisticpart.jsp" */ public class MonitoringAction extends LamsDispatchAction { private static Logger log = Logger.getLogger(MonitoringAction.class); + private static String noEntryText = null; // access via getNoEntryText() public INotebookService notebookService; @@ -84,21 +88,10 @@ boolean isGroupedActivity = notebookService.isGroupedActivity(toolContentID); request.setAttribute("isGroupedActivity", isGroupedActivity); - NotebookDTO notebookDTO = new NotebookDTO(notebook); + NotebookSessionsDTO notebookDTO = new NotebookSessionsDTO(notebook); Long currentTab = WebUtil.readLongParam(request, AttributeNames.PARAM_CURRENT_TAB, true); - notebookDTO.setCurrentTab(currentTab); + notebookDTO.setCurrentTab(currentTab != null ? currentTab : 1); - // add the notebookEntry for each user in each session - for (NotebookSessionDTO session : notebookDTO.getSessionDTOs()) { - for (NotebookUserDTO user : session.getUserDTOs()) { - NotebookEntry entry = notebookService.getEntry(user.getEntryUID()); - if (entry != null) { - NotebookEntryDTO entryDTO = new NotebookEntryDTO(entry); - user.setEntryDTO(entryDTO); - } - } - } - request.setAttribute("notebookDTO", notebookDTO); Date submissionDeadline = notebook.getSubmissionDeadline(); @@ -113,6 +106,78 @@ return mapping.findForward("success"); } + public ActionForward getUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException { + + setupService(); + Long toolSessionId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID)); + + // TODO fix modified date - sorts on creation date at the moment due to database. + boolean hasSearch = WebUtil.readBooleanParam(request, "_search", false); + String searchString = hasSearch ? request.getParameter(NotebookConstants.PARAM_NAME) : null; + int page = WebUtil.readIntParam(request, "page"); + int size = WebUtil.readIntParam(request, "rows"); + int sorting = NotebookConstants.SORT_BY_NO; + String sidx = request.getParameter("sidx"); + String sord = request.getParameter("sord"); + if ( sidx != null ) { + if ( sidx.equals(NotebookConstants.PARAM_NAME) ) + sorting = sord != null && sord.equals(NotebookConstants.ASC) ? NotebookConstants.SORT_BY_USERNAME_ASC : NotebookConstants.SORT_BY_USERNAME_DESC; + else if ( sidx.equals(NotebookConstants.PARAM_MODIFIED_DATE) ) + sorting = sord != null && sord.equals(NotebookConstants.ASC) ? NotebookConstants.SORT_BY_DATE_ASC : NotebookConstants.SORT_BY_DATE_DESC; + else if ( sidx.equals(NotebookConstants.PARAM_COMMENT_SORT) ) + sorting = sord != null && sord.equals(NotebookConstants.ASC) ? NotebookConstants.SORT_BY_COMMENT_ASC : NotebookConstants.SORT_BY_COMMENT_DESC; + } + + JSONObject responsedata = new JSONObject(); + int totalRows = notebookService.getCountUsersBySession(toolSessionId, searchString); + responsedata.put("total_rows", totalRows); + responsedata.put("page", page); + responsedata.put("total", Math.ceil((float)totalRows/size)); + + JSONArray rows = new JSONArray(); + // our code expects the first page to be 0 but jqgrid uses 1 for the first page. + List users = notebookService.getUsersForTablesorter(toolSessionId, page > 0 ? page-1 : 0, size, sorting, searchString); + + String noEntry = getNoEntryText(); + + int id = 1; + for (Object[] userAndReflection : users) { + + JSONObject responseRow = new JSONObject(); + + NotebookUser user = (NotebookUser) userAndReflection[0]; + responseRow.put("id", id++); + responseRow.put(NotebookConstants.PARAM_USER_UID, user.getUid()); + responseRow.put(NotebookConstants.PARAM_NAME, StringEscapeUtils.escapeHtml(user.getLastName() + " " + user.getFirstName())); + if ( userAndReflection.length > 1 && userAndReflection[1] != null) { + responseRow.put(NotebookConstants.PARAM_ENTRY, userAndReflection[1]); + } + if ( user.getTeachersComment() != null && user.getTeachersComment().length() > 0 ) { + responseRow.put(NotebookConstants.PARAM_COMMENT, user.getTeachersComment()); + } + + Date modifiedDate = null; + if ( userAndReflection.length > 3 && userAndReflection[3] != null) { + modifiedDate = (Date) userAndReflection[3]; + } else if ( userAndReflection.length > 2 && userAndReflection[2] != null) { + modifiedDate = (Date) userAndReflection[2]; + } + if ( modifiedDate != null ) { + responseRow.put(NotebookConstants.PARAM_MODIFIED_DATE, + DateUtil.convertToStringForJSON(modifiedDate)); + } else { + responseRow.put(NotebookConstants.PARAM_MODIFIED_DATE,noEntry); + } + rows.put(responseRow); + } + responsedata.put("rows", rows); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(responsedata.toString()); + return null; + + } + /** * Updates a user's mark or feedback for an entire lesson * @@ -180,6 +245,21 @@ return null; } + /** Get the statistics for monitoring */ + public ActionForward getStatistics(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + setupService(); + Long contentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); + + boolean isGroupedActivity = notebookService.isGroupedActivity(contentID); + request.setAttribute("isGroupedActivity", isGroupedActivity); + + request.setAttribute("statisticList", notebookService.getStatisticsBySession(contentID)); + + return mapping.findForward("statistic"); + } + /** * set up notebookService */ @@ -188,4 +268,13 @@ notebookService = NotebookServiceProxy.getNotebookService(this.getServlet().getServletContext()); } } + + private String getNoEntryText() { + if ( noEntryText == null ) { + WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + noEntryText = ((MessageService) wac.getBean("notebookMessageService")).getMessage("label.no.entry"); + } + return noEntryText; + } } Index: lams_tool_notebook/web/pages/learning/mobile/notebook.jsp =================================================================== diff -u -rd8a839e69eb14d39808c89c26c669667b197b477 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/web/pages/learning/mobile/notebook.jsp (.../notebook.jsp) (revision d8a839e69eb14d39808c89c26c669667b197b477) +++ lams_tool_notebook/web/pages/learning/mobile/notebook.jsp (.../notebook.jsp) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -94,7 +94,7 @@

- +

Index: lams_tool_notebook/web/pages/learning/notebook.jsp =================================================================== diff -u -r53e23abd7b5e540202e095e1563d7cca7783382a -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/web/pages/learning/notebook.jsp (.../notebook.jsp) (revision 53e23abd7b5e540202e095e1563d7cca7783382a) +++ lams_tool_notebook/web/pages/learning/notebook.jsp (.../notebook.jsp) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -104,7 +104,7 @@

- +

Index: lams_tool_notebook/web/pages/monitoring/monitoring.jsp =================================================================== diff -u -rbe07c35c372d904a65581d98660e73f3b13b69db -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/web/pages/monitoring/monitoring.jsp (.../monitoring.jsp) (revision be07c35c372d904a65581d98660e73f3b13b69db) +++ lams_tool_notebook/web/pages/monitoring/monitoring.jsp (.../monitoring.jsp) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -2,19 +2,39 @@ <%@ page import="org.lamsfoundation.lams.tool.notebook.util.NotebookConstants"%>
- + + Index: lams_tool_notebook/web/pages/monitoring/statisticpart.jsp =================================================================== diff -u --- lams_tool_notebook/web/pages/monitoring/statisticpart.jsp (revision 0) +++ lams_tool_notebook/web/pages/monitoring/statisticpart.jsp (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -0,0 +1,32 @@ +<%-- This is for AJAX call to refresh statistic page --%> +<%@ include file="/common/taglibs.jsp"%> + + + + + + + + +

+
+ + + + + + + + + + +
+ + + +
+ + + +
+
Index: lams_tool_notebook/web/pages/monitoring/statistics.jsp =================================================================== diff -u -r5fd25049d526080b60f6753a3d4603fb18913202 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/web/pages/monitoring/statistics.jsp (.../statistics.jsp) (revision 5fd25049d526080b60f6753a3d4603fb18913202) +++ lams_tool_notebook/web/pages/monitoring/statistics.jsp (.../statistics.jsp) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -1,33 +1,4 @@ <%@ include file="/common/taglibs.jsp"%> - - - - - - - -
-

- ${session.sessionName} -

-
- - - - - - - - - - -
- heading.totalLearnersInGroup - - ${session.numberOfLearners} -
- heading.totalFinishedLearnersInGroup - - ${session.numberOfFinishedLearners} -
-
+
+ <%@ include file="statisticpart.jsp"%> +
Index: lams_tool_notebook/web/pages/monitoring/summary.jsp =================================================================== diff -u -r313f8d6b66048cd3257c069e73343bc92ff2cb02 -r6f7031f1ac1eb389133a9c306cc6ea178eb88573 --- lams_tool_notebook/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 313f8d6b66048cd3257c069e73343bc92ff2cb02) +++ lams_tool_notebook/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 6f7031f1ac1eb389133a9c306cc6ea178eb88573) @@ -6,7 +6,7 @@