Index: lams_tool_chat/build.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/build.properties,v diff -u -r1.14 -r1.15 --- lams_tool_chat/build.properties 3 Mar 2008 04:05:55 -0000 1.14 +++ lams_tool_chat/build.properties 27 Oct 2008 03:31:23 -0000 1.15 @@ -11,7 +11,7 @@ package=org/lamsfoundation/lams/tool/chat package.name=org.lamsfoundation.lams.tool.chat weblib=lib -tool.version=20080229 +tool.version=20081027 # Minimum compatible version min.server.version.number=2.0.3 Index: lams_tool_chat/conf/hibernate/mappings/org/lamsfoundation/lams/tool/chat/model/ChatCondition.hbm.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/conf/hibernate/mappings/org/lamsfoundation/lams/tool/chat/model/ChatCondition.hbm.xml,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/conf/hibernate/mappings/org/lamsfoundation/lams/tool/chat/model/ChatCondition.hbm.xml 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file Index: lams_tool_chat/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/conf/language/lams/ApplicationResources.properties,v diff -u -r1.14 -r1.15 --- lams_tool_chat/conf/language/lams/ApplicationResources.properties 27 Aug 2008 00:15:43 -0000 1.14 +++ lams_tool_chat/conf/language/lams/ApplicationResources.properties 27 Oct 2008 03:31:23 -0000 1.15 @@ -19,6 +19,7 @@ button.basic =Basic button.advanced =Advanced button.upload =Upload +button.conditions=Conditions label.authoring.basic.title =Title: label.authoring.basic.content =Content: instructions.type.online =Online @@ -103,5 +104,27 @@ monitor.summary.td.notebookInstructions =Notebook instructions monitor.summary.td.filteredWords =Filtered words +label.authoring.heading.conditions =Conditions +label.authoring.conditions.add.condition =Add condition +label.authoring.conditions.list.title =Conditions +label.authoring.conditions.order =Order +label.authoring.conditions.empty.condition.list =There are no conditions +label.authoring.conditions.condition.name =Name +label.authoring.edit.conditions.button =Edit conditions +label.authoring.up =Up +label.authoring.down =Down +label.authoring.edit =Edit +error.condition.name.blank =Condition name can not be blank. +error.condition.duplicated.name =Duplicated name. Please choose unique one. +error.condition =Error creating condition. + +output.desc.text.search.output.definition.chat=Messages contain certain words +text.search.output.definition.chat.default.condition =Messages contain word "LAMS" + +textsearch.heading =Messages that... +textsearch.all.words =have all these words: +textsearch.phrase =have this exact wording or phrase: +textsearch.any.words =have one or more of these words: +textsearch.excluded.words =have none of these unwanted words: #======= End labels: Exported 96 labels for en AU ===== Index: lams_tool_chat/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/conf/language/lams/ApplicationResources_en_AU.properties,v diff -u -r1.12 -r1.13 --- lams_tool_chat/conf/language/lams/ApplicationResources_en_AU.properties 27 Aug 2008 00:15:43 -0000 1.12 +++ lams_tool_chat/conf/language/lams/ApplicationResources_en_AU.properties 27 Oct 2008 03:31:23 -0000 1.13 @@ -19,6 +19,7 @@ button.basic =Basic button.advanced =Advanced button.upload =Upload +button.conditions=Conditions label.authoring.basic.title =Title: label.authoring.basic.content =Content: instructions.type.online =Online @@ -103,5 +104,27 @@ monitor.summary.td.notebookInstructions =Notebook instructions monitor.summary.td.filteredWords =Filtered words +label.authoring.heading.conditions =Conditions +label.authoring.conditions.add.condition =Add condition +label.authoring.conditions.list.title =Conditions +label.authoring.conditions.order =Order +label.authoring.conditions.empty.condition.list =There are no conditions +label.authoring.conditions.condition.name =Name +label.authoring.edit.conditions.button =Edit conditions +label.authoring.up =Up +label.authoring.down =Down +label.authoring.edit =Edit +error.condition.name.blank =Condition name can not be blank. +error.condition.duplicated.name =Duplicated name. Please choose unique one. +error.condition =Error creating condition. + +output.desc.text.search.output.definition.chat =Messages contain certain words +text.search.output.definition.chat.default.condition =Messages contain word "LAMS" + +textsearch.heading =Messages that... +textsearch.all.words =have all these words: +textsearch.phrase =have this exact wording or phrase: +textsearch.any.words =have one or more of these words: +textsearch.excluded.words =have none of these unwanted words: #======= End labels: Exported 96 labels for en AU ===== Index: lams_tool_chat/conf/xdoclet/struts-actions.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/conf/xdoclet/struts-actions.xml,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/conf/xdoclet/struts-actions.xml 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: lams_tool_chat/db/model/chat_tool.clay =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/db/model/chat_tool.clay,v diff -u -r1.3 -r1.4 --- lams_tool_chat/db/model/chat_tool.clay 8 Jun 2006 01:41:24 -0000 1.3 +++ lams_tool_chat/db/model/chat_tool.clay 27 Oct 2008 03:31:23 -0000 1.4 @@ -1,26 +1,74 @@ - - - - + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
- - + + - - +
+ - - + + - + @@ -29,11 +77,11 @@ - - + + - + @@ -42,25 +90,25 @@ - - + + - - + + - - + + - + @@ -69,17 +117,17 @@ - - + + - - + + - + @@ -89,40 +137,40 @@ - - + + - - + + - - + + - - + +
- - +
+ - - + + - + @@ -131,23 +179,23 @@ - - + + - - + + - - + + - + @@ -156,60 +204,60 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + @@ -218,41 +266,41 @@ - - + + - - + + - - + + - - + +
- - +
+ - - + + - + @@ -261,11 +309,11 @@ - - + + - + @@ -274,11 +322,11 @@ - - + + - + @@ -287,11 +335,11 @@ - - + + - + @@ -300,83 +348,83 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
- - +
+ - - + + - + @@ -385,23 +433,23 @@ - - + + - - + + - - + + - + @@ -410,11 +458,11 @@ - - + + - + @@ -423,18 +471,18 @@ - - + + - - + + - + @@ -443,48 +491,48 @@ - - + + - - + + - - + + - - + + - - + +
- - +
+ - - + + - + @@ -493,11 +541,11 @@ - - + + - + @@ -506,39 +554,39 @@ - - + + - - + + - - + + - - + + - - + + - + @@ -548,27 +596,27 @@ - - + + - - + + - - + + - - + + Index: lams_tool_chat/db/sql/create_lams_tool_chat.sql =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/db/sql/create_lams_tool_chat.sql,v diff -u -r1.15 -r1.16 --- lams_tool_chat/db/sql/create_lams_tool_chat.sql 29 Feb 2008 03:46:49 -0000 1.15 +++ lams_tool_chat/db/sql/create_lams_tool_chat.sql 27 Oct 2008 03:31:23 -0000 1.16 @@ -7,11 +7,24 @@ drop table if exists tl_lachat11_message; drop table if exists tl_lachat11_session; drop table if exists tl_lachat11_user; +drop table if exists tl_lachat11_conditions; + create table tl_lachat11_attachment (uid bigint not null auto_increment, file_version_id bigint, file_type varchar(255), file_name varchar(255), file_uuid bigint, create_date datetime, chat_uid bigint, primary key (uid))type=innodb; create table tl_lachat11_chat (uid bigint not null auto_increment, create_date datetime, update_date datetime, create_by bigint, title varchar(255), instructions text, run_offline bit, lock_on_finished bit, reflect_on_activity bit, reflect_instructions text, online_instructions text, offline_instructions text, content_in_use bit, define_later bit, tool_content_id bigint, filtering_enabled bit, filter_keywords text, primary key (uid))type=innodb; create table tl_lachat11_message (uid bigint not null auto_increment, chat_session_uid bigint not null, from_user_uid bigint, to_user_uid bigint, type varchar(255), body text, send_date datetime, hidden bit, primary key (uid))type=innodb; create table tl_lachat11_session (uid bigint not null auto_increment, session_end_date datetime, session_start_date datetime, status integer, session_id bigint, session_name varchar(250), chat_uid bigint, jabber_room varchar(250), room_created bit, primary key (uid))type=innodb; create table tl_lachat11_user (uid bigint not null auto_increment, user_id bigint, last_name varchar(255), login_name varchar(255), first_name varchar(255), jabber_id varchar(255), finishedActivity bit, jabber_nickname varchar(255), chat_session_uid bigint, primary key (uid))type=innodb; + +CREATE TABLE tl_lachat11_conditions ( + condition_id BIGINT(20) NOT NULL + , content_uid BIGINT(20) + , PRIMARY KEY (condition_id) + , CONSTRAINT ChatConditionInheritance FOREIGN KEY (condition_id) + REFERENCES lams_branch_condition(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT ChatConditionToChat FOREIGN KEY (content_uid) + REFERENCES tl_lachat11_chat(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + alter table tl_lachat11_attachment add index FK9ED6CB2E1A3926E3 (chat_uid), add constraint FK9ED6CB2E1A3926E3 foreign key (chat_uid) references tl_lachat11_chat (uid); alter table tl_lachat11_message add index FKCC08C1DC2AF61E05 (to_user_uid), add constraint FKCC08C1DC2AF61E05 foreign key (to_user_uid) references tl_lachat11_user (uid); alter table tl_lachat11_message add index FKCC08C1DC9C8469FC (chat_session_uid), add constraint FKCC08C1DC9C8469FC foreign key (chat_session_uid) references tl_lachat11_session (uid); Index: lams_tool_chat/db/sql/drop_lams_tool_chat.sql =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/db/sql/drop_lams_tool_chat.sql,v diff -u -r1.2 -r1.3 --- lams_tool_chat/db/sql/drop_lams_tool_chat.sql 20 Apr 2006 03:27:43 -0000 1.2 +++ lams_tool_chat/db/sql/drop_lams_tool_chat.sql 27 Oct 2008 03:31:23 -0000 1.3 @@ -5,6 +5,7 @@ DROP TABLE IF EXISTS tl_lachat11_attachment; DROP TABLE IF EXISTS tl_lachat11_session; DROP TABLE IF EXISTS tl_lachat11_chat; +DROP TABLE IF EXISTS tl_lachat11_conditions; SET FOREIGN_KEY_CHECKS=1; Index: lams_tool_chat/db/sql/tool_insert.sql =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/db/sql/tool_insert.sql,v diff -u -r1.8 -r1.9 --- lams_tool_chat/db/sql/tool_insert.sql 22 Mar 2007 05:21:29 -0000 1.8 +++ lams_tool_chat/db/sql/tool_insert.sql 27 Oct 2008 03:31:23 -0000 1.9 @@ -28,7 +28,8 @@ classpath_addition, context_file, create_date_time, -modified_date_time +modified_date_time, +supports_outputs ) VALUES ( @@ -58,5 +59,6 @@ 'lams-tool-lachat11.jar', '/org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml', NOW(), -NOW() +NOW(), +1 ) Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml,v diff -u -r1.8 -r1.9 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml 29 Aug 2006 04:35:57 -0000 1.8 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/chatApplicationContext.xml 27 Oct 2008 03:31:23 -0000 1.9 @@ -10,22 +10,35 @@ + + + + org.lamsfoundation.lams.tool.chat.ApplicationResources + + + + + org/lamsfoundation/lams/learningdesign/BranchCondition.hbm.xml org/lamsfoundation/lams/tool/chat/model/Chat.hbm.xml org/lamsfoundation/lams/tool/chat/model/ChatSession.hbm.xml org/lamsfoundation/lams/tool/chat/model/ChatUser.hbm.xml org/lamsfoundation/lams/tool/chat/model/ChatMessage.hbm.xml org/lamsfoundation/lams/tool/chat/model/ChatAttachment.hbm.xml + org/lamsfoundation/lams/tool/chat/model/ChatCondition.hbm.xml + + + @@ -41,6 +54,7 @@ + Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatDAO.java,v diff -u -r1.6 -r1.7 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatDAO.java 17 Sep 2006 06:20:53 -0000 1.6 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatDAO.java 27 Oct 2008 03:31:23 -0000 1.7 @@ -28,15 +28,16 @@ import org.lamsfoundation.lams.tool.chat.model.Chat; /** - * DAO for accessing the Chat objects - interface defining - * methods to be implemented by the Hibernate or other implementation. + * DAO for accessing the Chat objects - interface defining methods to be implemented by the Hibernate or other + * implementation. */ -public interface IChatDAO extends IBaseDAO{ +public interface IChatDAO extends IBaseDAO { - Chat getByContentId(Long toolContentId); + Chat getByContentId(Long toolContentId); - void saveOrUpdate(Chat toContent); + void saveOrUpdate(Chat toContent); - void deleteInstructionFile(Long toolContentId, Long uuid, Long versionId, String type); - + void deleteInstructionFile(Long toolContentId, Long uuid, Long versionId, String type); + + void releaseFromCache(Object o); } \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatMessageDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatMessageDAO.java,v diff -u -r1.4 -r1.5 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatMessageDAO.java 17 Sep 2006 06:20:53 -0000 1.4 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/IChatMessageDAO.java 27 Oct 2008 03:31:23 -0000 1.5 @@ -34,20 +34,22 @@ import org.lamsfoundation.lams.tool.chat.model.ChatUser; /** - * DAO for accessing the ChatMessage objects - interface defining - * methods to be implemented by the Hibernate or other implementation. + * DAO for accessing the ChatMessage objects - interface defining methods to be implemented by the Hibernate or other + * implementation. */ public interface IChatMessageDAO extends IBaseDAO { - void saveOrUpdate(ChatMessage chatMessage); + void saveOrUpdate(ChatMessage chatMessage); - List getForUser(ChatUser chatUser); + List getForUser(ChatUser chatUser); - ChatMessage getByUID(Long uid); + ChatMessage getByUID(Long uid); - List getLatest(ChatSession chatSession, int max); - - Map getCountBySession(Long chatUID); - - Map getCountByFromUser(Long sessionUID); -} + List getLatest(ChatSession chatSession, int max); + + Map getCountBySession(Long chatUID); + + Map getCountByFromUser(Long sessionUID); + + List getSentByUser(Long userUid); +} \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatDAO.java,v diff -u -r1.6 -r1.7 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatDAO.java 17 Sep 2006 06:20:53 -0000 1.6 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatDAO.java 27 Oct 2008 03:31:23 -0000 1.7 @@ -38,41 +38,42 @@ */ public class ChatDAO extends BaseDAO implements IChatDAO { - private static final String FIND_FORUM_BY_CONTENTID = "from Chat chat where chat.toolContentId=?"; + private static final String FIND_FORUM_BY_CONTENTID = "from Chat chat where chat.toolContentId=?"; - private static final String FIND_INSTRUCTION_FILE = "from " - + ChatAttachment.class.getName() - + " as i where tool_content_id=? and i.file_uuid=? and i.file_version_id=? and i.file_type=?"; + private static final String FIND_INSTRUCTION_FILE = "from " + ChatAttachment.class.getName() + + " as i where tool_content_id=? and i.file_uuid=? and i.file_version_id=? and i.file_type=?"; - public Chat getByContentId(Long toolContentId) { - List list = getHibernateTemplate().find(FIND_FORUM_BY_CONTENTID, - toolContentId); - if (list != null && list.size() > 0) - return (Chat) list.get(0); - else - return null; + public Chat getByContentId(Long toolContentId) { + List list = getHibernateTemplate().find(ChatDAO.FIND_FORUM_BY_CONTENTID, toolContentId); + if (list != null && list.size() > 0) { + return (Chat) list.get(0); + } else { + return null; } + } - public void saveOrUpdate(Chat chat) { - this.getHibernateTemplate().saveOrUpdate(chat); - this.getHibernateTemplate().flush(); + public void saveOrUpdate(Chat chat) { + this.getHibernateTemplate().saveOrUpdate(chat); + this.getHibernateTemplate().flush(); + } + + public void deleteInstructionFile(Long toolContentId, Long uuid, Long versionId, String type) { + HibernateTemplate templ = this.getHibernateTemplate(); + if (toolContentId != null && uuid != null && versionId != null) { + List list = getSession().createQuery(ChatDAO.FIND_INSTRUCTION_FILE).setLong(0, toolContentId.longValue()) + .setLong(1, uuid.longValue()).setLong(2, versionId.longValue()).setString(3, type).list(); + if (list != null && list.size() > 0) { + ChatAttachment file = (ChatAttachment) list.get(0); + this.getSession().setFlushMode(FlushMode.AUTO); + templ.delete(file); + templ.flush(); + } } - public void deleteInstructionFile(Long toolContentId, Long uuid, - Long versionId, String type) { - HibernateTemplate templ = this.getHibernateTemplate(); - if (toolContentId != null && uuid != null && versionId != null) { - List list = getSession().createQuery(FIND_INSTRUCTION_FILE) - .setLong(0, toolContentId.longValue()).setLong(1, - uuid.longValue()).setLong(2, versionId.longValue()) - .setString(3, type).list(); - if (list != null && list.size() > 0) { - ChatAttachment file = (ChatAttachment) list.get(0); - this.getSession().setFlushMode(FlushMode.AUTO); - templ.delete(file); - templ.flush(); - } - } + } - } + public void releaseFromCache(Object o) { + getSession().evict(o); + + } } Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatMessageDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatMessageDAO.java,v diff -u -r1.5 -r1.6 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatMessageDAO.java 17 Sep 2006 06:20:53 -0000 1.5 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dao/hibernate/ChatMessageDAO.java 27 Oct 2008 03:31:23 -0000 1.6 @@ -40,91 +40,92 @@ public class ChatMessageDAO extends BaseDAO implements IChatMessageDAO { - // public static final String SQL_QUERY_FIND_USER_MESSAGE_HISTORY = "from " - // + ChatMessage.class.getName() + " as f where " - // + "f.chatSession=? and (f.type='groupchat' or " - // + "(f.type='chat' and (f.fromUser.userId=? or f.toUser.userId=?)))"; + // public static final String SQL_QUERY_FIND_USER_MESSAGE_HISTORY = "from " + // + ChatMessage.class.getName() + " as f where " + // + "f.chatSession=? and (f.type='groupchat' or " + // + "(f.type='chat' and (f.fromUser.userId=? or f.toUser.userId=?)))"; - public static final String SQL_QUERY_FIND_USER_MESSAGE_HISTORY = "from " - + ChatMessage.class.getName() - + " as f where " - + "f.chatSession.uid=? and f.hidden='false' and (f.type='groupchat' or (f.type='chat' and (f.fromUser.uid=? or f.toUser.uid=?)))"; + public static final String SQL_QUERY_FIND_USER_MESSAGE_HISTORY = "from " + + ChatMessage.class.getName() + + " as f where " + + "f.chatSession.uid=? and f.hidden='false' and (f.type='groupchat' or (f.type='chat' and (f.fromUser.uid=? or f.toUser.uid=?)))"; - public static final String SQL_QUERY_FIND_MESSAGE_BY_UID = "from " - + ChatMessage.class.getName() + " where uid=?"; + public static final String SQL_QUERY_FIND_MESSAGE_BY_UID = "from " + ChatMessage.class.getName() + " where uid=?"; - public static final String SQL_QUERY_FIND_MESSAGE_BY_SESSION_ORDER_BY_DATE_ASC = "from " - + ChatMessage.class.getName() - + " as f where f.chatSession=? order by f.sendDate desc"; + public static final String SQL_QUERY_FIND_MESSAGE_BY_SESSION_ORDER_BY_DATE_ASC = "from " + + ChatMessage.class.getName() + " as f where f.chatSession=? order by f.sendDate desc"; - public static final String SQL_QUERY_FIND_MESSAGE_COUNT_BY_FROM_USER = "select f.fromUser.uid, count(*) from " - + ChatMessage.class.getName() - + " as f where f.chatSession.uid=? group by f.fromUser"; + public static final String SQL_QUERY_FIND_MESSAGE_COUNT_BY_FROM_USER = "select f.fromUser.uid, count(*) from " + + ChatMessage.class.getName() + " as f where f.chatSession.uid=? group by f.fromUser"; - public static final String SQL_QUERY_FIND_MESSAGE_COUNT_BY_SESSION = "select f.chatSession.uid, count(*) from " - + ChatMessage.class.getName() - + " as f where f.chatSession.chat.uid=? group by f.chatSession"; + public static final String SQL_QUERY_FIND_MESSAGE_COUNT_BY_SESSION = "select f.chatSession.uid, count(*) from " + + ChatMessage.class.getName() + " as f where f.chatSession.chat.uid=? group by f.chatSession"; - public void saveOrUpdate(ChatMessage chatMessage) { - this.getHibernateTemplate().saveOrUpdate(chatMessage); - this.getHibernateTemplate().flush(); - } + public static final String SQL_QUERY_FIND_MESSAGES_SENT_BY_USER = "FROM " + ChatMessage.class.getName() + + " AS f WHERE f.fromUser.uid=?"; - public List getForUser(ChatUser chatUser) { - return this.getHibernateTemplate().find( - SQL_QUERY_FIND_USER_MESSAGE_HISTORY, - new Object[] { chatUser.getChatSession().getUid(), - chatUser.getUid(), chatUser.getUid() }); - } + public void saveOrUpdate(ChatMessage chatMessage) { + this.getHibernateTemplate().saveOrUpdate(chatMessage); + this.getHibernateTemplate().flush(); + } - public ChatMessage getByUID(Long uid) { - // TODO Auto-generated method stub - List list = this.getHibernateTemplate().find( - SQL_QUERY_FIND_MESSAGE_BY_UID, new Object[] { uid }); + public List getForUser(ChatUser chatUser) { + return this.getHibernateTemplate().find(ChatMessageDAO.SQL_QUERY_FIND_USER_MESSAGE_HISTORY, + new Object[] { chatUser.getChatSession().getUid(), chatUser.getUid(), chatUser.getUid() }); + } - if (list != null && list.size() > 0) - return (ChatMessage) list.get(0); - else - return null; + public ChatMessage getByUID(Long uid) { + // TODO Auto-generated method stub + List list = this.getHibernateTemplate() + .find(ChatMessageDAO.SQL_QUERY_FIND_MESSAGE_BY_UID, new Object[] { uid }); + if (list != null && list.size() > 0) { + return (ChatMessage) list.get(0); + } else { + return null; } - public List getLatest(ChatSession chatSession, int max) { - try { - Query query = this.getSession().createQuery( - SQL_QUERY_FIND_MESSAGE_BY_SESSION_ORDER_BY_DATE_ASC); - query.setLong(0, chatSession.getUid()); - query.setMaxResults(max); - return query.list(); - } catch (HibernateException he) { - logger.error("getLatest: hibernate exception"); - return null; - } + } + + public List getLatest(ChatSession chatSession, int max) { + try { + Query query = this.getSession().createQuery( + ChatMessageDAO.SQL_QUERY_FIND_MESSAGE_BY_SESSION_ORDER_BY_DATE_ASC); + query.setLong(0, chatSession.getUid()); + query.setMaxResults(max); + return query.list(); + } catch (HibernateException he) { + logger.error("getLatest: hibernate exception"); + return null; } + } - public Map getCountBySession(Long chatUID) { - List list = this.getHibernateTemplate().find( - SQL_QUERY_FIND_MESSAGE_COUNT_BY_SESSION, - new Object[] { chatUID }); + public Map getCountBySession(Long chatUID) { + List list = this.getHibernateTemplate().find(ChatMessageDAO.SQL_QUERY_FIND_MESSAGE_COUNT_BY_SESSION, + new Object[] { chatUID }); - Map resultMap = new HashMap(); - for (Iterator iter = list.iterator(); iter.hasNext();) { - Object[] row = (Object[]) iter.next(); - resultMap.put((Long) row[0], (Integer) row[1]); - } - return resultMap; + Map resultMap = new HashMap(); + for (Iterator iter = list.iterator(); iter.hasNext();) { + Object[] row = (Object[]) iter.next(); + resultMap.put((Long) row[0], (Integer) row[1]); } - - public Map getCountByFromUser(Long sessionUID) { - List list = this.getHibernateTemplate().find( - SQL_QUERY_FIND_MESSAGE_COUNT_BY_FROM_USER, - new Object[] { sessionUID }); + return resultMap; + } - Map resultMap = new HashMap(); - for (Iterator iter = list.iterator(); iter.hasNext();) { - Object[] row = (Object[]) iter.next(); - resultMap.put((Long) row[0], (Integer) row[1]); - } - return resultMap; + public Map getCountByFromUser(Long sessionUID) { + List list = this.getHibernateTemplate().find(ChatMessageDAO.SQL_QUERY_FIND_MESSAGE_COUNT_BY_FROM_USER, + new Object[] { sessionUID }); + + Map resultMap = new HashMap(); + for (Iterator iter = list.iterator(); iter.hasNext();) { + Object[] row = (Object[]) iter.next(); + resultMap.put((Long) row[0], (Integer) row[1]); } + return resultMap; + } + + public List getSentByUser(Long userUid) { + return this.getHibernateTemplate().find(ChatMessageDAO.SQL_QUERY_FIND_MESSAGES_SENT_BY_USER, + new Object[] { userUid }); + } } Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dbupdates/patch20081027_updateFrom21.sql =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dbupdates/patch20081027_updateFrom21.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/dbupdates/patch20081027_updateFrom21.sql 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,12 @@ +-- SQL statements to update from LAMS 2.1/2.1.1 +CREATE TABLE tl_lachat11_conditions ( + condition_id BIGINT(20) NOT NULL + , content_uid BIGINT(20) + , PRIMARY KEY (condition_id) + , CONSTRAINT ChatConditionInheritance FOREIGN KEY (condition_id) + REFERENCES lams_branch_condition(condition_id) ON DELETE CASCADE ON UPDATE CASCADE + , CONSTRAINT ChatConditionToChat FOREIGN KEY (content_uid) + REFERENCES tl_lachat11_chat(uid) ON DELETE CASCADE ON UPDATE CASCADE +)TYPE=InnoDB; + +UPDATE lams_tool SET supports_outputs=1 WHERE tool_signature='lachat11'; \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java,v diff -u -r1.11 -r1.12 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java 1 Nov 2006 23:46:48 -0000 1.11 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java 27 Oct 2008 03:31:23 -0000 1.12 @@ -28,9 +28,11 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.chat.service.ChatService; /** @@ -39,418 +41,440 @@ public class Chat implements java.io.Serializable, Cloneable { - /** - * - */ - private static final long serialVersionUID = 579733009969321015L; + /** + * + */ + private static final long serialVersionUID = 579733009969321015L; - static Logger log = Logger.getLogger(ChatService.class.getName()); + static Logger log = Logger.getLogger(ChatService.class.getName()); - // Fields - /** - * - */ - private Long uid; + // Fields + /** + * + */ + private Long uid; - private Date createDate; + private Date createDate; - private Date updateDate; + private Date updateDate; - private Long createBy; + private Long createBy; - private String title; + private String title; - private String instructions; + private String instructions; - private boolean runOffline; + private boolean runOffline; - private boolean lockOnFinished; - - private boolean reflectOnActivity; - - private String reflectInstructions; + private boolean lockOnFinished; - private boolean filteringEnabled; + private boolean reflectOnActivity; - private String filterKeywords; + private String reflectInstructions; - private String onlineInstructions; + private boolean filteringEnabled; - private String offlineInstructions; + private String filterKeywords; - private boolean contentInUse; + private String onlineInstructions; - private boolean defineLater; + private String offlineInstructions; - private Long toolContentId; + private boolean contentInUse; - private Set chatAttachments; + private boolean defineLater; - private Set chatSessions; - - //*********** NON Persisit fields - private IToolContentHandler toolContentHandler; + private Long toolContentId; - // Constructors + private Set chatAttachments; - /** default constructor */ - public Chat() { - } + private Set chatSessions; + private Set conditions = new TreeSet(new TextSearchConditionComparator()); - /** full constructor */ - public Chat(Date createDate, Date updateDate, Long createBy, String title, - String instructions, boolean runOffline, boolean lockOnFinished, - boolean filteringEnabled, String filterKeywords, - String onlineInstructions, String offlineInstructions, - boolean contentInUse, boolean defineLater, Long toolContentId, - Set chatAttachments, Set chatSessions) { - this.createDate = createDate; - this.updateDate = updateDate; - this.createBy = createBy; - this.title = title; - this.instructions = instructions; - this.runOffline = runOffline; - this.lockOnFinished = lockOnFinished; - this.filteringEnabled = filteringEnabled; - this.filterKeywords = filterKeywords; - this.onlineInstructions = onlineInstructions; - this.offlineInstructions = offlineInstructions; - this.contentInUse = contentInUse; - this.defineLater = defineLater; - this.toolContentId = toolContentId; - this.chatAttachments = chatAttachments; - this.chatSessions = chatSessions; - } + // *********** NON Persisit fields + private IToolContentHandler toolContentHandler; - // Property accessors - /** - * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" - * - */ + // Constructors - public Long getUid() { - return this.uid; - } + /** default constructor */ + public Chat() { + } - public void setUid(Long uid) { - this.uid = uid; - } + /** full constructor */ + public Chat(Date createDate, Date updateDate, Long createBy, String title, String instructions, boolean runOffline, + boolean lockOnFinished, boolean filteringEnabled, String filterKeywords, String onlineInstructions, + String offlineInstructions, boolean contentInUse, boolean defineLater, Long toolContentId, + Set chatAttachments, Set chatSessions) { + this.createDate = createDate; + this.updateDate = updateDate; + this.createBy = createBy; + this.title = title; + this.instructions = instructions; + this.runOffline = runOffline; + this.lockOnFinished = lockOnFinished; + this.filteringEnabled = filteringEnabled; + this.filterKeywords = filterKeywords; + this.onlineInstructions = onlineInstructions; + this.offlineInstructions = offlineInstructions; + this.contentInUse = contentInUse; + this.defineLater = defineLater; + this.toolContentId = toolContentId; + this.chatAttachments = chatAttachments; + this.chatSessions = chatSessions; + } - /** - * @hibernate.property column="create_date" - * - */ + // Property accessors + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * + */ - public Date getCreateDate() { - return this.createDate; - } + public Long getUid() { + return uid; + } - public void setCreateDate(Date createDate) { - this.createDate = createDate; - } + public void setUid(Long uid) { + this.uid = uid; + } - /** - * @hibernate.property column="update_date" - * - */ + /** + * @hibernate.property column="create_date" + * + */ - public Date getUpdateDate() { - return this.updateDate; - } + public Date getCreateDate() { + return createDate; + } - public void setUpdateDate(Date updateDate) { - this.updateDate = updateDate; - } + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } - /** - * @hibernate.property column="create_by" length="20" - * - */ + /** + * @hibernate.property column="update_date" + * + */ - public Long getCreateBy() { - return this.createBy; - } + public Date getUpdateDate() { + return updateDate; + } - public void setCreateBy(Long createBy) { - this.createBy = createBy; - } + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } - /** - * @hibernate.property column="title" length="255" - * - */ + /** + * @hibernate.property column="create_by" length="20" + * + */ - public String getTitle() { - return this.title; - } + public Long getCreateBy() { + return createBy; + } - public void setTitle(String title) { - this.title = title; - } + public void setCreateBy(Long createBy) { + this.createBy = createBy; + } - /** - * @hibernate.property column="instructions" length="65535" - * - */ + /** + * @hibernate.property column="title" length="255" + * + */ - public String getInstructions() { - return this.instructions; - } + public String getTitle() { + return title; + } - public void setInstructions(String instructions) { - this.instructions = instructions; - } + public void setTitle(String title) { + this.title = title; + } - /** - * @hibernate.property column="run_offline" length="1" - * - */ + /** + * @hibernate.property column="instructions" length="65535" + * + */ - public boolean isRunOffline() { - return this.runOffline; - } + public String getInstructions() { + return instructions; + } - public void setRunOffline(boolean runOffline) { - this.runOffline = runOffline; - } + public void setInstructions(String instructions) { + this.instructions = instructions; + } - /** - * @hibernate.property column="lock_on_finished" length="1" - * - */ + /** + * @hibernate.property column="run_offline" length="1" + * + */ - public boolean isLockOnFinished() { - return this.lockOnFinished; - } + public boolean isRunOffline() { + return runOffline; + } - public void setLockOnFinished(boolean lockOnFinished) { - this.lockOnFinished = lockOnFinished; - } - - /** - * @hibernate.property column="reflect_on_activity" length="1" - */ - public boolean isReflectOnActivity() { - return reflectOnActivity; - } + public void setRunOffline(boolean runOffline) { + this.runOffline = runOffline; + } - public void setReflectOnActivity(boolean reflectOnActivity) { - this.reflectOnActivity = reflectOnActivity; - } - - /** - * @hibernate.property column="reflect_instructions" length="65535" - */ - public String getReflectInstructions() { - return reflectInstructions; - } + /** + * @hibernate.property column="lock_on_finished" length="1" + * + */ - public void setReflectInstructions(String reflectInstructions) { - this.reflectInstructions = reflectInstructions; - } - - /** - * @hibernate.property column="online_instructions" length="65535" - * - */ + public boolean isLockOnFinished() { + return lockOnFinished; + } - public String getOnlineInstructions() { - return this.onlineInstructions; - } + public void setLockOnFinished(boolean lockOnFinished) { + this.lockOnFinished = lockOnFinished; + } - public void setOnlineInstructions(String onlineInstructions) { - this.onlineInstructions = onlineInstructions; - } + /** + * @hibernate.property column="reflect_on_activity" length="1" + */ + public boolean isReflectOnActivity() { + return reflectOnActivity; + } - /** - * @hibernate.property column="offline_instructions" length="65535" - * - */ + public void setReflectOnActivity(boolean reflectOnActivity) { + this.reflectOnActivity = reflectOnActivity; + } - public String getOfflineInstructions() { - return this.offlineInstructions; - } + /** + * @hibernate.property column="reflect_instructions" length="65535" + */ + public String getReflectInstructions() { + return reflectInstructions; + } - public void setOfflineInstructions(String offlineInstructions) { - this.offlineInstructions = offlineInstructions; - } + public void setReflectInstructions(String reflectInstructions) { + this.reflectInstructions = reflectInstructions; + } - /** - * @hibernate.property column="content_in_use" length="1" - * - */ + /** + * @hibernate.property column="online_instructions" length="65535" + * + */ - public boolean isContentInUse() { - return this.contentInUse; - } + public String getOnlineInstructions() { + return onlineInstructions; + } - public void setContentInUse(boolean contentInUse) { - this.contentInUse = contentInUse; - } + public void setOnlineInstructions(String onlineInstructions) { + this.onlineInstructions = onlineInstructions; + } - /** - * @hibernate.property column="define_later" length="1" - * - */ + /** + * @hibernate.property column="offline_instructions" length="65535" + * + */ - public boolean isDefineLater() { - return this.defineLater; - } + public String getOfflineInstructions() { + return offlineInstructions; + } - public void setDefineLater(boolean defineLater) { - this.defineLater = defineLater; - } + public void setOfflineInstructions(String offlineInstructions) { + this.offlineInstructions = offlineInstructions; + } - /** - * @hibernate.property column="tool_content_id" length="20" - * - */ + /** + * @hibernate.property column="content_in_use" length="1" + * + */ - public Long getToolContentId() { - return this.toolContentId; - } + public boolean isContentInUse() { + return contentInUse; + } - public void setToolContentId(Long toolContentId) { - this.toolContentId = toolContentId; - } + public void setContentInUse(boolean contentInUse) { + this.contentInUse = contentInUse; + } - /** - * @hibernate.set lazy="false" inverse="false" cascade="all-delete-orphan" - * @hibernate.collection-key column="chat_uid" - * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.chat.model.ChatAttachment" - * - */ + /** + * @hibernate.property column="define_later" length="1" + * + */ - public Set getChatAttachments() { - return this.chatAttachments; - } + public boolean isDefineLater() { + return defineLater; + } - public void setChatAttachments(Set chatAttachments) { - this.chatAttachments = chatAttachments; - } + public void setDefineLater(boolean defineLater) { + this.defineLater = defineLater; + } - /** - * @hibernate.set lazy="true" inverse="true" cascade="none" - * @hibernate.collection-key column="chat_uid" - * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.chat.model.ChatSession" - * - */ + /** + * @hibernate.property column="tool_content_id" length="20" + * + */ - public Set getChatSessions() { - return this.chatSessions; - } + public Long getToolContentId() { + return toolContentId; + } - public void setChatSessions(Set chatSessions) { - this.chatSessions = chatSessions; - } + public void setToolContentId(Long toolContentId) { + this.toolContentId = toolContentId; + } - /** - * @hibernate.property column="filtering_enabled" length="1" - */ - public boolean isFilteringEnabled() { - return filteringEnabled; - } + /** + * @hibernate.set lazy="false" inverse="false" cascade="all-delete-orphan" + * @hibernate.collection-key column="chat_uid" + * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.chat.model.ChatAttachment" + * + */ - public void setFilteringEnabled(boolean filteringEnabled) { - this.filteringEnabled = filteringEnabled; - } + public Set getChatAttachments() { + return chatAttachments; + } - /** - * @hibernate.property column="filter_keywords" length="65535" - */ - public String getFilterKeywords() { - return filterKeywords; - } + public void setChatAttachments(Set chatAttachments) { + this.chatAttachments = chatAttachments; + } - public void setFilterKeywords(String filterKeywords) { - this.filterKeywords = filterKeywords; - } + /** + * @hibernate.set lazy="true" inverse="true" cascade="none" + * @hibernate.collection-key column="chat_uid" + * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.chat.model.ChatSession" + * + */ - /** - * toString - * - * @return String - */ - public String toString() { - StringBuffer buffer = new StringBuffer(); + public Set getChatSessions() { + return chatSessions; + } - buffer.append(getClass().getName()).append("@").append( - Integer.toHexString(hashCode())).append(" ["); - buffer.append("title").append("='").append(getTitle()).append("' "); - buffer.append("instructions").append("='").append(getInstructions()) - .append("' "); - buffer.append("toolContentId").append("='").append(getToolContentId()) - .append("' "); - buffer.append("]"); + public void setChatSessions(Set chatSessions) { + this.chatSessions = chatSessions; + } - return buffer.toString(); - } + /** + * @hibernate.property column="filtering_enabled" length="1" + */ + public boolean isFilteringEnabled() { + return filteringEnabled; + } - public boolean equals(Object other) { - if ((this == other)) - return true; - if ((other == null)) - return false; - if (!(other instanceof Chat)) - return false; - Chat castOther = (Chat) other; + public void setFilteringEnabled(boolean filteringEnabled) { + this.filteringEnabled = filteringEnabled; + } - return ((this.getUid() == castOther.getUid()) || (this.getUid() != null - && castOther.getUid() != null && this.getUid().equals( - castOther.getUid()))); - } + /** + * @hibernate.property column="filter_keywords" length="65535" + */ + public String getFilterKeywords() { + return filterKeywords; + } - public int hashCode() { - int result = 17; - result = 37 * result - + (getUid() == null ? 0 : this.getUid().hashCode()); - return result; - } + public void setFilterKeywords(String filterKeywords) { + this.filterKeywords = filterKeywords; + } - public static Chat newInstance(Chat fromContent, Long toContentId, - IToolContentHandler chatToolContentHandler) { - Chat toContent = new Chat(); - fromContent.toolContentHandler = chatToolContentHandler; - toContent = (Chat) fromContent.clone(); - toContent.setToolContentId(toContentId); - toContent.setCreateDate(new Date()); - return toContent; + /** + * toString + * + * @return String + */ + @Override + public String toString() { + StringBuffer buffer = new StringBuffer(); + + buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" ["); + buffer.append("title").append("='").append(getTitle()).append("' "); + buffer.append("instructions").append("='").append(getInstructions()).append("' "); + buffer.append("toolContentId").append("='").append(getToolContentId()).append("' "); + buffer.append("]"); + + return buffer.toString(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; } + if (other == null) { + return false; + } + if (!(other instanceof Chat)) { + return false; + } + Chat castOther = (Chat) other; - protected Object clone() { + return this.getUid() == castOther.getUid() || this.getUid() != null && castOther.getUid() != null + && this.getUid().equals(castOther.getUid()); + } - Chat chat = null; - try { - chat = (Chat) super.clone(); - chat.setUid(null); + @Override + public int hashCode() { + int result = 17; + result = 37 * result + (getUid() == null ? 0 : this.getUid().hashCode()); + return result; + } - if (chatAttachments != null) { - // create a copy of the attachments but do not duplicate node in repository - Iterator iter = chatAttachments.iterator(); - Set set = new HashSet(); - while (iter.hasNext()) { - ChatAttachment originalFile = (ChatAttachment) iter.next(); - ChatAttachment newFile = (ChatAttachment) originalFile - .clone(); - - set.add(newFile); - } - chat.chatAttachments = set; - } - // create an empty set for the chatSession - chat.chatSessions = new HashSet(); + public static Chat newInstance(Chat fromContent, Long toContentId, IToolContentHandler chatToolContentHandler) { + Chat toContent = new Chat(); + fromContent.toolContentHandler = chatToolContentHandler; + toContent = (Chat) fromContent.clone(); + toContent.setToolContentId(toContentId); + toContent.setCreateDate(new Date()); + return toContent; + } - } catch (CloneNotSupportedException cnse) { - log.error("Error cloning " + Chat.class); + @Override + protected Object clone() { + + Chat chat = null; + try { + chat = (Chat) super.clone(); + chat.setUid(null); + + if (chatAttachments != null) { + // create a copy of the attachments but do not duplicate node in repository + Iterator iter = chatAttachments.iterator(); + Set set = new HashSet(); + while (iter.hasNext()) { + ChatAttachment originalFile = (ChatAttachment) iter.next(); + ChatAttachment newFile = (ChatAttachment) originalFile.clone(); + + set.add(newFile); } - return chat; - } + chat.chatAttachments = set; + } + // create an empty set for the chatSession + chat.chatSessions = new HashSet(); - public IToolContentHandler getToolContentHandler() { - return toolContentHandler; - } + if (conditions != null) { + Set set = new TreeSet(new TextSearchConditionComparator()); + for (ChatCondition condition : conditions) { + set.add((ChatCondition) condition.clone()); + } + chat.setConditions(set); + } - public void setToolContentHandler(IToolContentHandler toolContentHandler) { - this.toolContentHandler = toolContentHandler; + } catch (CloneNotSupportedException cnse) { + Chat.log.error("Error cloning " + Chat.class); } + return chat; + } + + public IToolContentHandler getToolContentHandler() { + return toolContentHandler; + } + + public void setToolContentHandler(IToolContentHandler toolContentHandler) { + this.toolContentHandler = toolContentHandler; + } + + /** + * @hibernate.set lazy="true" cascade="all" + * sort="org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator" + * @hibernate.collection-key column="content_uid" + * @hibernate.collection-one-to-many class="org.lamsfoundation.lams.tool.chat.model.ChatCondition" + * + */ + public Set getConditions() { + return conditions; + } + + public void setConditions(Set conditions) { + this.conditions = conditions; + } } Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/ChatCondition.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/ChatCondition.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/ChatCondition.java 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,115 @@ +package org.lamsfoundation.lams.tool.chat.model; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.lamsfoundation.lams.learningdesign.BranchCondition; +import org.lamsfoundation.lams.learningdesign.LearningDesign; +import org.lamsfoundation.lams.learningdesign.TextSearchCondition; +import org.lamsfoundation.lams.learningdesign.dto.BranchConditionDTO; +import org.lamsfoundation.lams.tool.OutputType; +import org.lamsfoundation.lams.tool.ToolOutput; +import org.lamsfoundation.lams.tool.ToolOutputFormatException; +import org.lamsfoundation.lams.tool.ToolOutputValue; + +/** + * A text search condition with a set of messages on which the search should be performed. + * + * + * @author Marcin Cieslak + * + */ +public class ChatCondition extends TextSearchCondition { + + public ChatCondition() { + super(); + } + + public ChatCondition(BranchConditionDTO conditionDTO) { + super(conditionDTO); + } + + public ChatCondition(Long conditionId, Integer conditionUIID, Integer orderId, String name, String displayName, + String allWords, String phrase, String anyWords, String excludedWords) { + super(conditionId, conditionUIID, orderId, name, displayName, BranchCondition.OUTPUT_TYPE_COMPLEX, null, null, + null, allWords, phrase, anyWords, excludedWords); + } + + @Override + public Object clone() { + return new ChatCondition(null, null, orderId, name, displayName, allWords, phrase, anyWords, excludedWords); + } + + @Override + public ChatCondition clone(int uiidOffset) { + Integer newConditionUIID = LearningDesign.addOffset(conditionUIID, uiidOffset); + return new ChatCondition(null, newConditionUIID, orderId, name, displayName, allWords, phrase, anyWords, + excludedWords); + } + + @Override + public boolean isMet(ToolOutput output) throws ToolOutputFormatException { + boolean result = false; + if (output != null) { + ToolOutputValue value = output.getValue(); + if (value != null) { + if (OutputType.OUTPUT_COMPLEX.equals(value.getType())) { + // the condition "knows" it's an array of strings - user's messages + String[] messages = (String[]) value.getValue(); + parseConditionStrings(); + + if (messages == null) { + result = getAllWordsCondition() == null && getAnyWordsCondition() == null + && getPhraseCondition() == null; + } else { + /* + * We want to check if each messages doesn't contain excluded words and at least one message + * contains the desired (all, any, phrase) words. That is why we check all, any and phrase + * conditions using the "matches" method, but we check excluded words manually. + */ + List excludedWordsCopy = getExcludedWordsCondition(); + setExcludedWordsCondition(null); + for (String message : messages) { + if (!result) { + result = matches(message); + } + if (matchExcludedWordsOnly(excludedWordsCopy, message)) { + result = false; + break; + } + } + } + + } else { + throw new ToolOutputFormatException("Chat tool produced a non-complex tool output."); + } + } + } + return result; + } + + /** + * It filters the given text in order to find any of the unwanted words. + * + * @param excludedWords + * words to search for + * @param textToMatch + * string to be filtered + * @return true if at least one of the words from the list is found in the text + */ + private boolean matchExcludedWordsOnly(List excludedWords, String textToMatch) { + if (textToMatch == null || excludedWords == null) { + return false; + } + StringBuilder stringPattern = new StringBuilder(); + for (String excludedWord : excludedWords) { + stringPattern.append("(?:").append(TextSearchCondition.WORD_DELIMITER_REGEX).append( + Pattern.quote(excludedWord)).append(TextSearchCondition.WORD_DELIMITER_REGEX).append(")|"); + } + stringPattern.deleteCharAt(stringPattern.length() - 1); + Pattern regexPattern = Pattern.compile(stringPattern.toString(), TextSearchCondition.PATTERN_MATCHING_OPTIONS); + Matcher matcher = regexPattern.matcher(textToMatch); + return matcher.find(); + } +} \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatOutputFactory.java 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,162 @@ +/**************************************************************** + * 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: ChatOutputFactory.java,v 1.1 2008/10/27 03:31:23 marcin Exp $ */ +package org.lamsfoundation.lams.tool.chat.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.lamsfoundation.lams.learningdesign.BranchCondition; +import org.lamsfoundation.lams.tool.OutputFactory; +import org.lamsfoundation.lams.tool.ToolOutput; +import org.lamsfoundation.lams.tool.ToolOutputDefinition; +import org.lamsfoundation.lams.tool.chat.model.Chat; +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; +import org.lamsfoundation.lams.tool.chat.model.ChatMessage; +import org.lamsfoundation.lams.tool.chat.model.ChatUser; +import org.lamsfoundation.lams.tool.chat.util.ChatConstants; +import org.lamsfoundation.lams.tool.exception.ToolException; + +/** + * Output factory for Chat tool. Currently it provides only one type of output - all messages that a user sent. + * + * @author Marcin Cieslak + */ +public class ChatOutputFactory extends OutputFactory { + + /** + * {@inheritDoc} + */ + @Override + public SortedMap getToolOutputDefinitions(Object toolContentObject) + throws ToolException { + SortedMap definitionMap = new TreeMap(); + if (toolContentObject != null) { + ToolOutputDefinition chatMessagesDefinition = buildComplexOutputDefinition(ChatConstants.TEXT_SEARCH_DEFINITION_NAME); + Chat chat = (Chat) toolContentObject; + // adding all existing conditions + chatMessagesDefinition.setDefaultConditions(new ArrayList(chat.getConditions())); + // if no conditions were created in the tool instance, a default condition is added; the condition is + // persisted in ChatService. + if (chatMessagesDefinition.getDefaultConditions().isEmpty()) { + String name = buildConditionName(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, chat.getToolContentId() + .toString()); + // Default condition checks if messages contain word "LAMS" + ChatCondition defaultCondition = new ChatCondition(null, null, 1, name, getI18NText( + ChatConstants.TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY, false), "LAMS", null, null, null); + chat.getConditions().add(defaultCondition); + chatMessagesDefinition.getDefaultConditions().add(defaultCondition); + } + chatMessagesDefinition.setShowConditionNameOnly(true); + definitionMap.put(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, chatMessagesDefinition); + } + + return definitionMap; + } + + /** + * Follows {@link ChatService#getToolOutput(List, Long, Long)}. + * + */ + public SortedMap getToolOutput(List names, IChatService chatService, + Long toolSessionId, Long learnerId) { + + TreeMap outputs = new TreeMap(); + // cached tool output for all text search conditions + ToolOutput chatMessagesOutput = null; + if (names == null) { + // output will be set for all the existing conditions + Chat chat = chatService.getSessionBySessionId(toolSessionId).getChat(); + Set conditions = chat.getConditions(); + for (ChatCondition condition : conditions) { + String name = condition.getName(); + if (isTextSearchConditionName(name) && chatMessagesOutput != null) { + outputs.put(name, chatMessagesOutput); + } else { + ToolOutput output = getToolOutput(name, chatService, toolSessionId, learnerId); + if (output != null) { + outputs.put(name, output); + if (isTextSearchConditionName(name)) { + chatMessagesOutput = output; + } + } + } + } + } else { + for (String name : names) { + if (isTextSearchConditionName(name) && chatMessagesOutput != null) { + outputs.put(name, chatMessagesOutput); + } else { + ToolOutput output = getToolOutput(name, chatService, toolSessionId, learnerId); + if (output != null) { + outputs.put(name, output); + if (isTextSearchConditionName(name)) { + chatMessagesOutput = output; + } + } + } + } + } + return outputs; + + } + + public ToolOutput getToolOutput(String name, IChatService chatService, Long toolSessionId, Long learnerId) { + if (isTextSearchConditionName(ChatConstants.TEXT_SEARCH_DEFINITION_NAME)) { + // entry is loaded from DB + Chat chat = chatService.getSessionBySessionId(toolSessionId).getChat(); + + ChatUser user = chatService.getUserByUserIdAndSessionId(learnerId, toolSessionId); + List messages = chatService.getMessagesSentByUser(user.getUid()); + + String[] textMessages = null; + if (messages != null) { + textMessages = new String[messages.size()]; + int messageIndex = 0; + for (ChatMessage message : messages) { + textMessages[messageIndex++] = message.getBody(); + } + } + + return new ToolOutput(name, getI18NText(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, true), textMessages, + false); + } + return null; + } + + @Override + protected String[] splitConditionName(String conditionName) { + return super.splitConditionName(conditionName); + } + + protected String buildConditionName(String uniquePart) { + return super.buildConditionName(ChatConstants.TEXT_SEARCH_DEFINITION_NAME, uniquePart); + } + + private boolean isTextSearchConditionName(String name) { + return name != null && name.startsWith(ChatConstants.TEXT_SEARCH_DEFINITION_NAME); + } +} \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java,v diff -u -r1.46 -r1.47 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java 15 Oct 2008 04:13:09 -0000 1.46 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/ChatService.java 27 Oct 2008 03:31:23 -0000 1.47 @@ -27,15 +27,16 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Random; import java.util.Set; import java.util.SortedMap; -import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -83,6 +84,7 @@ import org.lamsfoundation.lams.tool.chat.dto.ChatMessageDTO; import org.lamsfoundation.lams.tool.chat.model.Chat; import org.lamsfoundation.lams.tool.chat.model.ChatAttachment; +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; import org.lamsfoundation.lams.tool.chat.model.ChatMessage; import org.lamsfoundation.lams.tool.chat.model.ChatSession; import org.lamsfoundation.lams.tool.chat.model.ChatUser; @@ -143,6 +145,10 @@ private ICoreNotebookService coreNotebookService; + private ChatOutputFactory chatOutputFactory; + + private Random generator = new Random(); + // private IdentifierGenerator idGenerator; @@ -156,8 +162,8 @@ /* Methods from ToolSessionManager */ public void createToolSession(Long toolSessionId, String toolSessionName, Long toolContentId) throws ToolException { - if (logger.isDebugEnabled()) { - logger.debug("entering method createToolSession:" + " toolSessionId = " + toolSessionId + if (ChatService.logger.isDebugEnabled()) { + ChatService.logger.debug("entering method createToolSession:" + " toolSessionId = " + toolSessionId + " toolSessionName = " + toolSessionName + " toolContentId = " + toolContentId); } @@ -240,7 +246,7 @@ * java.lang.Long) */ public SortedMap getToolOutput(List names, Long toolSessionId, Long learnerId) { - return new TreeMap(); + return getChatOutputFactory().getToolOutput(names, this, toolSessionId, learnerId); } /** @@ -250,16 +256,16 @@ * java.lang.Long) */ public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { - return null; + return getChatOutputFactory().getToolOutput(name, this, toolSessionId, learnerId); } /* Methods from ToolContentManager */ public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException { - if (logger.isDebugEnabled()) { - logger.debug("entering method copyToolContent:" + " fromContentId=" + fromContentId + " toContentId=" - + toContentId); + if (ChatService.logger.isDebugEnabled()) { + ChatService.logger.debug("entering method copyToolContent:" + " fromContentId=" + fromContentId + + " toContentId=" + toContentId); } if (toContentId == null) { @@ -306,17 +312,19 @@ * Export the XML fragment for the tool's content, along with any files needed for the content. * * @throws DataMissingException - * if no tool content matches the toolSessionId + * if no tool content matches the toolSessionId * @throws ToolException - * if any other error occurs + * if any other error occurs */ public void exportToolContent(Long toolContentId, String rootPath) throws DataMissingException, ToolException { Chat chat = chatDAO.getByContentId(toolContentId); - if (chat == null) + if (chat == null) { chat = getDefaultContent(); - if (chat == null) + } + if (chat == null) { throw new DataMissingException("Unable to find default content for the chat tool"); + } // set ResourceToolContentHandler as null to avoid copy file node in // repository again. @@ -340,7 +348,7 @@ * Import the XML fragment for the tool's content, along with any files needed for the content. * * @throws ToolException - * if any other error occurs + * if any other error occurs */ public void importToolContent(Long toolContentId, Integer newUserUid, String toolContentPath, String fromVersion, String toVersion) throws ToolException { @@ -350,9 +358,10 @@ Object toolPOJO = exportContentService.importToolContent(toolContentPath, chatToolContentHandler, fromVersion, toVersion); - if (!(toolPOJO instanceof Chat)) + if (!(toolPOJO instanceof Chat)) { throw new ImportToolContentException("Import Chat tool content failed. Deserialized object is " + toolPOJO); + } Chat chat = (Chat) toolPOJO; // reset it to new toolContentId @@ -374,7 +383,19 @@ * @return SortedMap of ToolOutputDefinitions with the key being the name of each definition */ public SortedMap getToolOutputDefinitions(Long toolContentId) throws ToolException { - return new TreeMap(); + Chat chat = getChatDAO().getByContentId(toolContentId); + + if (chat == null) { + chat = getDefaultContent(); + } + // If there are no user added conditions, the default condition will be added in the output factory. It also + // needs to be persisted. + boolean defaultConditionToBeAdded = chat.getConditions().isEmpty(); + SortedMap map = getChatOutputFactory().getToolOutputDefinitions(chat); + if (defaultConditionToBeAdded && !chat.getConditions().isEmpty()) { + saveOrUpdateChat(chat); + } + return map; } /* IChatService Methods */ @@ -383,7 +404,7 @@ toolContentId = new Long(toolService.getToolDefaultContentIdBySignature(toolSignature)); if (toolContentId == null) { String error = "Could not retrieve default content id for this tool"; - logger.error(error); + ChatService.logger.error(error); throw new ChatException(error); } return toolContentId; @@ -394,7 +415,7 @@ Chat defaultContent = getChatByContentId(defaultContentID); if (defaultContent == null) { String error = "Could not retrieve default content record for this tool"; - logger.error(error); + ChatService.logger.error(error); throw new ChatException(error); } return defaultContent; @@ -404,7 +425,7 @@ if (newContentID == null) { String error = "Cannot copy the Chat tools default content: + " + "newContentID is null"; - logger.error(error); + ChatService.logger.error(error); throw new ChatException(error); } @@ -417,25 +438,25 @@ } public Chat getChatByContentId(Long toolContentID) { - Chat chat = (Chat) chatDAO.getByContentId(toolContentID); + Chat chat = chatDAO.getByContentId(toolContentID); if (chat == null) { - logger.debug("Could not find the content with toolContentID:" + toolContentID); + ChatService.logger.debug("Could not find the content with toolContentID:" + toolContentID); } return chat; } public ChatSession getSessionBySessionId(Long toolSessionId) { ChatSession chatSession = chatSessionDAO.getBySessionId(toolSessionId); if (chatSession == null) { - logger.debug("Could not find the chat session with toolSessionID:" + toolSessionId); + ChatService.logger.debug("Could not find the chat session with toolSessionID:" + toolSessionId); } return chatSession; } public ChatSession getSessionByJabberRoom(String jabberRoom) { ChatSession chatSession = chatSessionDAO.getByJabberRoom(jabberRoom); if (chatSession == null) { - logger.debug("Could not find the chat session with jabberRoom:" + jabberRoom); + ChatService.logger.debug("Could not find the chat session with jabberRoom:" + jabberRoom); } return chatSession; } @@ -464,9 +485,17 @@ return chatMessageDAO.getForUser(chatUser); } + /** + * {@inheritDoc} + */ + public List getMessagesSentByUser(Long userUid) { + return chatMessageDAO.getSentByUser(userUid); + } + public ChatAttachment uploadFileToContent(Long toolContentId, FormFile file, String type) { - if (file == null || StringUtils.isEmpty(file.getFileName())) + if (file == null || StringUtils.isEmpty(file.getFileName())) { throw new ChatException("Could not find upload file: " + file); + } NodeKey nodeKey = processFile(file, type); @@ -515,7 +544,7 @@ ChatUser chatUser = new ChatUser(user, chatSession); String jabberId = XMPPUtil.createId(user); if (jabberId == null) { - logger.error("Unable to create jabber id for user: " + user.getUserID()); + ChatService.logger.error("Unable to create jabber id for user: " + user.getUserID()); throw new RuntimeException(); } chatUser.setJabberId(jabberId); @@ -570,7 +599,7 @@ // format is room@domain/nick int index = to.getNodeValue().lastIndexOf("/"); if (index == -1) { - logger.debug("processIncomingMessages: malformed 'to' attribute :" + to.getNodeValue()); + ChatService.logger.debug("processIncomingMessages: malformed 'to' attribute :" + to.getNodeValue()); return; // somethings wrong, ignore packet } jabberRoom = to.getNodeValue().substring(0, index); @@ -580,7 +609,7 @@ // format is room@domain jabberRoom = to.getNodeValue(); } else { - logger.debug("processIncomingMessages: unknown type: " + type.getNodeValue()); + ChatService.logger.debug("processIncomingMessages: unknown type: " + type.getNodeValue()); return; } @@ -592,7 +621,7 @@ // setting from field int index = from.getNodeValue().lastIndexOf("@"); if (index == -1) { - logger.debug("processIncomingMessages: malformed 'from' attribute :" + from.getNodeValue()); + ChatService.logger.debug("processIncomingMessages: malformed 'from' attribute :" + from.getNodeValue()); return; // somethings wrong, ignore packet } String JidUsername = from.getNodeValue().substring(0, index); @@ -601,7 +630,7 @@ try { userId = new Long(JidUsername); } catch (NumberFormatException e) { - logger.debug("processIncomingMessages: malformed JID username: " + JidUsername); + ChatService.logger.debug("processIncomingMessages: malformed JID username: " + JidUsername); return; } ChatUser fromUser = getUserByUserIdAndSessionId(userId, chatSession.getSessionId()); @@ -627,16 +656,15 @@ Node to = nnm.getNamedItem("to"); if (from == null || to == null) { // somethings wrong, return empty list - logger.debug("malformed presence xml: no from or to attributes present"); + ChatService.logger.debug("malformed presence xml: no from or to attributes present"); return null; } /* * // Note: Removed xmlns check due to problems with firefox 3 // checking presence packet for correct values - * Node xElem = presence.getFirstChild(); if (xElem == null) { - * logger.debug("malformed presence xml: no x element present"); } nnm = xElem.getAttributes(); Node xmlns = - * nnm.getNamedItem("xmlns"); if (xmlns == null || !xmlns.getNodeValue().equals( - * "http://jabber.org/protocol/muc")) { logger - * .debug("malformed presence xml: xmlns attribute for x element not available or incorrect"); return null; } + * Node xElem = presence.getFirstChild(); if (xElem == null) { logger.debug("malformed presence xml: no x + * element present"); } nnm = xElem.getAttributes(); Node xmlns = nnm.getNamedItem("xmlns"); if (xmlns == null || + * !xmlns.getNodeValue().equals( "http://jabber.org/protocol/muc")) { logger .debug("malformed presence xml: + * xmlns attribute for x element not available or incorrect"); return null; } */ // get the Chat User @@ -646,7 +674,7 @@ ChatUser chatUser = getUserByJabberIDAndJabberRoom(jabberID, jabberRoom); List chatMessageList = getMessagesForUser(chatUser); - logger.debug("MESSAGE COUNT" + chatMessageList.size()); + ChatService.logger.debug("MESSAGE COUNT" + chatMessageList.size()); List xmlMessageList = new ArrayList(); try { @@ -680,7 +708,7 @@ } } catch (ParserConfigurationException e) { e.printStackTrace(); - logger.debug("parser configuration exception"); + ChatService.logger.debug("parser configuration exception"); return null; } return xmlMessageList; @@ -895,7 +923,7 @@ } public void setChatAttachmentDAO(IChatAttachmentDAO attachmentDAO) { - this.chatAttachmentDAO = attachmentDAO; + chatAttachmentDAO = attachmentDAO; } public IChatDAO getChatDAO() { @@ -919,7 +947,7 @@ } public void setChatSessionDAO(IChatSessionDAO sessionDAO) { - this.chatSessionDAO = sessionDAO; + chatSessionDAO = sessionDAO; } public ILamsToolService getToolService() { @@ -935,15 +963,15 @@ } public void setChatUserDAO(IChatUserDAO userDAO) { - this.chatUserDAO = userDAO; + chatUserDAO = userDAO; } public IChatMessageDAO getChatMessageDAO() { return chatMessageDAO; } public void setChatMessageDAO(IChatMessageDAO messageDAO) { - this.chatMessageDAO = messageDAO; + chatMessageDAO = messageDAO; } public ILearnerService getLearnerService() { @@ -1032,7 +1060,7 @@ ToolContentImport102Manager.CONTENT_REUSABLE); chat.setLockOnFinished(isReusable != null ? !isReusable.booleanValue() : true); } catch (WDDXProcessorConversionException e) { - logger.error("Unable to content for activity " + chat.getTitle() + ChatService.logger.error("Unable to content for activity " + chat.getTitle() + "properly due to a WDDXProcessorConversionException.", e); throw new ToolException( "Invalid import data format for activity " @@ -1062,5 +1090,41 @@ chat.setReflectInstructions(description); } + public ChatOutputFactory getChatOutputFactory() { + return chatOutputFactory; + } + + public void setChatOutputFactory(ChatOutputFactory notebookOutputFactory) { + chatOutputFactory = notebookOutputFactory; + } + + public String createConditionName(Collection existingConditions) { + String uniqueNumber = null; + do { + uniqueNumber = String.valueOf(Math.abs(generator.nextInt())); + for (ChatCondition condition : existingConditions) { + String[] splitedName = getChatOutputFactory().splitConditionName(condition.getName()); + if (uniqueNumber.equals(splitedName[1])) { + uniqueNumber = null; + } + } + } while (uniqueNumber == null); + return getChatOutputFactory().buildConditionName(uniqueNumber); + } + + public void deleteCondition(ChatCondition condition) { + if (condition != null && condition.getConditionId() != null) { + chatDAO.delete(condition); + } + } + + public void releaseConditionsFromCache(Chat chat) { + if (chat.getConditions() != null) { + for (ChatCondition condition : chat.getConditions()) { + getChatDAO().releaseFromCache(condition); + } + } + } + // ========================================================================================= } Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/IChatService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/IChatService.java,v diff -u -r1.16 -r1.17 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/IChatService.java 15 Oct 2008 04:13:09 -0000 1.16 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/service/IChatService.java 27 Oct 2008 03:31:23 -0000 1.17 @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.tool.chat.service; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -32,6 +33,7 @@ import org.lamsfoundation.lams.tool.chat.dto.ChatMessageDTO; import org.lamsfoundation.lams.tool.chat.model.Chat; import org.lamsfoundation.lams.tool.chat.model.ChatAttachment; +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; import org.lamsfoundation.lams.tool.chat.model.ChatMessage; import org.lamsfoundation.lams.tool.chat.model.ChatSession; import org.lamsfoundation.lams.tool.chat.model.ChatUser; @@ -244,4 +246,19 @@ public NotebookEntry getEntry(Long id, Integer idType, String signature, Integer userID); public void updateEntry(NotebookEntry notebookEntry); + + public String createConditionName(Collection existingConditions); + + public void deleteCondition(ChatCondition condition); + + /** + * Gets all messages sent by the given user. + * + * @param userUid + * UID of the user + * @return list of his/hers messages + */ + public List getMessagesSentByUser(Long userUid); + + void releaseConditionsFromCache(Chat chat); } \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatConstants.java,v diff -u -r1.12 -r1.13 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatConstants.java 1 Nov 2006 02:53:01 -0000 1.12 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatConstants.java 27 Oct 2008 03:31:23 -0000 1.13 @@ -24,29 +24,40 @@ package org.lamsfoundation.lams.tool.chat.util; - public interface ChatConstants { - public static final String TOOL_SIGNATURE = "lachat11"; - - // Chat session status - public static final Integer SESSION_NOT_STARTED = new Integer(0); - public static final Integer SESSION_IN_PROGRESS = new Integer(1); - public static final Integer SESSION_COMPLETED = new Integer(2); - - public static final String AUTHORING_DEFAULT_TAB = "1"; - public static final String ATTACHMENT_LIST = "attachmentList"; - public static final String DELETED_ATTACHMENT_LIST = "deletedAttachmentList"; - public static final String AUTH_SESSION_ID_COUNTER = "authoringSessionIdCounter"; - public static final String AUTH_SESSION_ID = "authoringSessionId"; - - public static final int MONITORING_SUMMARY_MAX_MESSAGES = 5; - - // Attribute names - public static final String ATTR_MESSAGE = "message"; - public static final String ATTR_SESSION_MAP = "sessionMap"; - - // Parameter names - public static final String PARAM_PARENT_PAGE = "parentPage"; - - static final String FILTER_REPLACE_TEXT = "***"; -} + public static final String TOOL_SIGNATURE = "lachat11"; + + // Chat session status + public static final Integer SESSION_NOT_STARTED = new Integer(0); + public static final Integer SESSION_IN_PROGRESS = new Integer(1); + public static final Integer SESSION_COMPLETED = new Integer(2); + + public static final String AUTHORING_DEFAULT_TAB = "1"; + public static final String ATTACHMENT_LIST = "attachmentList"; + public static final String DELETED_ATTACHMENT_LIST = "deletedAttachmentList"; + public static final String AUTH_SESSION_ID_COUNTER = "authoringSessionIdCounter"; + public static final String AUTH_SESSION_ID = "authoringSessionId"; + + public static final int MONITORING_SUMMARY_MAX_MESSAGES = 5; + + // Attribute names + public static final String ATTR_MESSAGE = "message"; + public static final String ATTR_SESSION_MAP = "sessionMap"; + + // Parameter names + public static final String PARAM_PARENT_PAGE = "parentPage"; + + static final String FILTER_REPLACE_TEXT = "***"; + + public static final String ATTR_SESSION_MAP_ID = "sessionMapID"; + public static final String ATTR_CONDITION_SET = "conditionList"; + + public static final String PARAM_ORDER_ID = "orderId"; + public static final String ATTR_DELETED_CONDITION_LIST = "deletedConditionList"; + public static final String TEXT_SEARCH_DEFINITION_NAME = "text.search.output.definition.chat"; + public static final String TEXT_SEARCH_DEFAULT_CONDITION_DISPLAY_NAME_KEY = "text.search.output.definition.chat.default.condition"; + public static final String SUCCESS = "success"; + 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"; +} \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java,v diff -u -r1.27 -r1.28 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java 5 May 2008 05:26:56 -0000 1.27 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringAction.java 27 Oct 2008 03:31:23 -0000 1.28 @@ -24,12 +24,15 @@ package org.lamsfoundation.lams.tool.chat.web.actions; +import java.util.ArrayList; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -43,9 +46,11 @@ import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.authoring.web.AuthoringConstants; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.lamsfoundation.lams.tool.chat.model.Chat; import org.lamsfoundation.lams.tool.chat.model.ChatAttachment; +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; import org.lamsfoundation.lams.tool.chat.service.ChatServiceProxy; import org.lamsfoundation.lams.tool.chat.service.IChatService; import org.lamsfoundation.lams.tool.chat.util.ChatConstants; @@ -60,420 +65,439 @@ * @author * @version * - * @struts.action path="/authoring" name="authoringForm" parameter="dispatch" - * scope="request" validate="false" + * @struts.action path="/authoring" name="authoringForm" parameter="dispatch" scope="request" validate="false" * * @struts.action-forward name="success" path="tiles:/authoring/main" * @struts.action-forward name="message_page" path="tiles:/generic/message" */ public class AuthoringAction extends LamsDispatchAction { - private static Logger logger = Logger.getLogger(AuthoringAction.class); + private static Logger logger = Logger.getLogger(AuthoringAction.class); - public IChatService chatService; + public IChatService chatService; - // Authoring SessionMap key names - private static final String KEY_TOOL_CONTENT_ID = "toolContentID"; + // Authoring SessionMap key names + private static final String KEY_TOOL_CONTENT_ID = "toolContentID"; - private static final String KEY_CONTENT_FOLDER_ID = "contentFolderID"; + private static final String KEY_CONTENT_FOLDER_ID = "contentFolderID"; - private static final String KEY_MODE = "mode"; + private static final String KEY_MODE = "mode"; - private static final String KEY_ONLINE_FILES = "onlineFiles"; + private static final String KEY_ONLINE_FILES = "onlineFiles"; - private static final String KEY_OFFLINE_FILES = "offlineFiles"; + private static final String KEY_OFFLINE_FILES = "offlineFiles"; - private static final String KEY_UNSAVED_ONLINE_FILES = "unsavedOnlineFiles"; + private static final String KEY_UNSAVED_ONLINE_FILES = "unsavedOnlineFiles"; - private static final String KEY_UNSAVED_OFFLINE_FILES = "unsavedOfflineFiles"; + private static final String KEY_UNSAVED_OFFLINE_FILES = "unsavedOfflineFiles"; - private static final String KEY_DELETED_FILES = "deletedFiles"; + private static final String KEY_DELETED_FILES = "deletedFiles"; - /** - * Default method when no dispatch parameter is specified. It is expected - * that the parameter toolContentID will be passed in. This - * will be used to retrieve content for this tool. - * - */ - protected ActionForward unspecified(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { + /** + * Default method when no dispatch parameter is specified. It is expected that the parameter + * toolContentID will be passed in. This will be used to retrieve content for this tool. + * + */ + @Override + protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { - // Extract toolContentID from parameters. - Long toolContentID = new Long(WebUtil.readLongParam(request, - AttributeNames.PARAM_TOOL_CONTENT_ID)); + // Extract toolContentID from parameters. + Long toolContentID = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); - String contentFolderID = WebUtil.readStrParam(request, - AttributeNames.PARAM_CONTENT_FOLDER_ID); + String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); - ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", - true); + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, "mode", true); - // set up chatService - if (chatService == null) { - chatService = ChatServiceProxy.getChatService(this.getServlet() - .getServletContext()); - } + // set up chatService + if (chatService == null) { + chatService = ChatServiceProxy.getChatService(this.getServlet().getServletContext()); + } - // retrieving Chat with given toolContentID - Chat chat = chatService.getChatByContentId(toolContentID); - if (chat == null) { - chat = chatService.copyDefaultContent(toolContentID); - chat.setCreateDate(new Date()); - chatService.saveOrUpdateChat(chat); - // TODO NOTE: this causes DB orphans when LD not saved. - } + // retrieving Chat with given toolContentID + Chat chat = chatService.getChatByContentId(toolContentID); + if (chat == null) { + chat = chatService.copyDefaultContent(toolContentID); + chat.setCreateDate(new Date()); + chatService.saveOrUpdateChat(chat); + // TODO NOTE: this causes DB orphans when LD not saved. + } - if (mode != null && mode.isTeacher()) { - // Set the defineLater flag so that learners cannot use content - // while we - // are editing. This flag is released when updateContent is called. - chat.setDefineLater(true); - chatService.saveOrUpdateChat(chat); - } + if (mode != null && mode.isTeacher()) { + // Set the defineLater flag so that learners cannot use content + // while we + // are editing. This flag is released when updateContent is called. + chat.setDefineLater(true); + chatService.saveOrUpdateChat(chat); + } - // Set up the authForm. - AuthoringForm authForm = (AuthoringForm) form; - updateAuthForm(authForm, chat); + // Set up the authForm. + AuthoringForm authForm = (AuthoringForm) form; + updateAuthForm(authForm, chat); - // Set up sessionMap - SessionMap map = createSessionMap(chat, - getAccessMode(request), contentFolderID, toolContentID); - authForm.setSessionMapID(map.getSessionID()); + // Set up sessionMap + SessionMap map = createSessionMap(chat, getAccessMode(request), contentFolderID, toolContentID); + authForm.setSessionMapID(map.getSessionID()); - // add the sessionMap to HTTPSession. - request.getSession().setAttribute(map.getSessionID(), map); - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + // add the sessionMap to HTTPSession. + request.getSession().setAttribute(map.getSessionID(), map); + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - return mapping.findForward("success"); - } + return mapping.findForward("success"); + } - public ActionForward updateContent(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - // TODO need error checking. + public ActionForward updateContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + // TODO need error checking. - // get authForm and session map. - AuthoringForm authForm = (AuthoringForm) form; - SessionMap map = getSessionMap(request, authForm); + // get authForm and session map. + AuthoringForm authForm = (AuthoringForm) form; + SessionMap map = getSessionMap(request, authForm); - // get chat content. - Chat chat = chatService.getChatByContentId((Long) map - .get(KEY_TOOL_CONTENT_ID)); + // get chat content. + Chat chat = chatService.getChatByContentId((Long) map.get(AuthoringAction.KEY_TOOL_CONTENT_ID)); - // update chat content using form inputs. - ToolAccessMode mode = (ToolAccessMode) map.get(KEY_MODE); - updateChat(chat, authForm, mode); + // update chat content using form inputs. + ToolAccessMode mode = (ToolAccessMode) map.get(AuthoringAction.KEY_MODE); + updateChat(chat, authForm, mode); - // remove attachments marked for deletion. - Set attachments = chat.getChatAttachments(); - if (attachments == null) { - attachments = new HashSet(); - } + // remove attachments marked for deletion. + Set attachments = chat.getChatAttachments(); + if (attachments == null) { + attachments = new HashSet(); + } - for (ChatAttachment att : getAttList(KEY_DELETED_FILES, map)) { - // leave in repository but remove from db - attachments.remove(att); - } + for (ChatAttachment att : getAttList(AuthoringAction.KEY_DELETED_FILES, map)) { + // leave in repository but remove from db + attachments.remove(att); + } - // add unsaved attachments - attachments.addAll(getAttList(KEY_UNSAVED_ONLINE_FILES, map)); - attachments.addAll(getAttList(KEY_UNSAVED_OFFLINE_FILES, map)); + // add unsaved attachments + attachments.addAll(getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map)); + attachments.addAll(getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map)); - // set attachments in case it didn't exist - chat.setChatAttachments(attachments); + // set attachments in case it didn't exist + chat.setChatAttachments(attachments); + chatService.releaseConditionsFromCache(chat); - // set the update date - chat.setUpdateDate(new Date()); + Set conditions = chat.getConditions(); + if (conditions == null) { + conditions = new TreeSet(new TextSearchConditionComparator()); + } + SortedSet conditionSet = (SortedSet) map.get(ChatConstants.ATTR_CONDITION_SET); + conditions.addAll(conditionSet); - // releasing defineLater flag so that learner can start using the tool. - chat.setDefineLater(false); + List deletedConditionList = (List) map + .get(ChatConstants.ATTR_DELETED_CONDITION_LIST); + if (deletedConditionList != null) { + for (ChatCondition condition : deletedConditionList) { + // remove from db, leave in repository + conditions.remove(condition); + chatService.deleteCondition(condition); + } + } - chatService.saveOrUpdateChat(chat); + // set attachments in case it didn't exist + chat.setConditions(conditionSet); + // set the update date + chat.setUpdateDate(new Date()); - request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, - Boolean.TRUE); + // releasing defineLater flag so that learner can start using the tool. + chat.setDefineLater(false); - // add the sessionMapID to form - authForm.setSessionMapID(map.getSessionID()); + chatService.saveOrUpdateChat(chat); - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG, Boolean.TRUE); - return mapping.findForward("success"); - } + // add the sessionMapID to form + authForm.setSessionMapID(map.getSessionID()); - public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return uploadFile(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_ONLINE, request); - } + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return uploadFile(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_OFFLINE, request); - } + return mapping.findForward("success"); + } - public ActionForward deleteOnline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_ONLINE, request); - } + public ActionForward uploadOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return uploadFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); + } - public ActionForward deleteOffline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_OFFLINE, request); - } + public ActionForward uploadOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return uploadFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); + } - public ActionForward removeUnsavedOnline(ActionMapping mapping, - ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return removeUnsaved(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_ONLINE, request); - } + public ActionForward deleteOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return deleteFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); + } - public ActionForward removeUnsavedOffline(ActionMapping mapping, - ActionForm form, HttpServletRequest request, - HttpServletResponse response) { - return removeUnsaved(mapping, (AuthoringForm) form, - IToolContentHandler.TYPE_OFFLINE, request); - } + public ActionForward deleteOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return deleteFile(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); + } - /* ========== Private Methods ********** */ + public ActionForward removeUnsavedOnline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return removeUnsaved(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_ONLINE, request); + } - private ActionForward uploadFile(ActionMapping mapping, - AuthoringForm authForm, String type, HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + public ActionForward removeUnsavedOffline(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return removeUnsaved(mapping, (AuthoringForm) form, IToolContentHandler.TYPE_OFFLINE, request); + } - FormFile file; - List unsavedFiles; - List savedFiles; - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - file = (FormFile) authForm.getOfflineFile(); - unsavedFiles = getAttList(KEY_UNSAVED_OFFLINE_FILES, map); + /* ========== Private Methods ********** */ - savedFiles = getAttList(KEY_OFFLINE_FILES, map); - } else { - file = (FormFile) authForm.getOnlineFile(); - unsavedFiles = getAttList(KEY_UNSAVED_ONLINE_FILES, map); + private ActionForward uploadFile(ActionMapping mapping, AuthoringForm authForm, String type, + HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - savedFiles = getAttList(KEY_ONLINE_FILES, map); - } + FormFile file; + List unsavedFiles; + List savedFiles; + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + file = authForm.getOfflineFile(); + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); - ActionMessages errors = new ActionMessages(); - FileValidatorUtil.validateFileSize(file, true, errors); - if (!errors.isEmpty()) { - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - this.saveErrors(request, errors); - return mapping.findForward("success"); - } + savedFiles = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); + } else { + file = authForm.getOnlineFile(); + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map); - if (file.getFileName().length() != 0) { - // upload file to repository - ChatAttachment newAtt = chatService.uploadFileToContent((Long) map - .get(KEY_TOOL_CONTENT_ID), file, type); + savedFiles = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); + } - // Add attachment to unsavedFiles - // check to see if file with same name exists - ChatAttachment currAtt; - Iterator iter = savedFiles.iterator(); - while (iter.hasNext()) { - currAtt = (ChatAttachment) iter.next(); - if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName()) - && StringUtils.equals(currAtt.getFileType(), newAtt.getFileType())) { - // move from this this list to deleted list. - getAttList(KEY_DELETED_FILES, map).add(currAtt); - iter.remove(); - break; - } - } - unsavedFiles.add(newAtt); - - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); - } - return mapping.findForward("success"); + ActionMessages errors = new ActionMessages(); + FileValidatorUtil.validateFileSize(file, true, errors); + if (!errors.isEmpty()) { + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + this.saveErrors(request, errors); + return mapping.findForward("success"); } - private ActionForward deleteFile(ActionMapping mapping, - AuthoringForm authForm, String type, HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + if (file.getFileName().length() != 0) { + // upload file to repository + ChatAttachment newAtt = chatService.uploadFileToContent( + (Long) map.get(AuthoringAction.KEY_TOOL_CONTENT_ID), file, type); - List fileList; - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - fileList = getAttList(KEY_OFFLINE_FILES, map); - } else { - fileList = getAttList(KEY_ONLINE_FILES, map); + // Add attachment to unsavedFiles + // check to see if file with same name exists + ChatAttachment currAtt; + Iterator iter = savedFiles.iterator(); + while (iter.hasNext()) { + currAtt = (ChatAttachment) iter.next(); + if (StringUtils.equals(currAtt.getFileName(), newAtt.getFileName()) + && StringUtils.equals(currAtt.getFileType(), newAtt.getFileType())) { + // move from this this list to deleted list. + getAttList(AuthoringAction.KEY_DELETED_FILES, map).add(currAtt); + iter.remove(); + break; } + } + unsavedFiles.add(newAtt); - Iterator iter = fileList.iterator(); + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); + } + return mapping.findForward("success"); + } - while (iter.hasNext()) { - ChatAttachment att = (ChatAttachment) iter.next(); + private ActionForward deleteFile(ActionMapping mapping, AuthoringForm authForm, String type, + HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { - // move to delete file list, deleted at next updateContent - getAttList(KEY_DELETED_FILES, map).add(att); + List fileList; + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + fileList = getAttList(AuthoringAction.KEY_OFFLINE_FILES, map); + } else { + fileList = getAttList(AuthoringAction.KEY_ONLINE_FILES, map); + } - // remove from this list - iter.remove(); - break; - } - } + Iterator iter = fileList.iterator(); - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); + while (iter.hasNext()) { + ChatAttachment att = (ChatAttachment) iter.next(); - return mapping.findForward("success"); + if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { + // move to delete file list, deleted at next updateContent + getAttList(AuthoringAction.KEY_DELETED_FILES, map).add(att); + + // remove from this list + iter.remove(); + break; + } } - private ActionForward removeUnsaved(ActionMapping mapping, - AuthoringForm authForm, String type, HttpServletRequest request) { - SessionMap map = getSessionMap(request, authForm); + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); - List unsavedFiles; + return mapping.findForward("success"); + } - if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { - unsavedFiles = getAttList(KEY_UNSAVED_OFFLINE_FILES, map); - } else { - unsavedFiles = getAttList(KEY_UNSAVED_ONLINE_FILES, map); - } + private ActionForward removeUnsaved(ActionMapping mapping, AuthoringForm authForm, String type, + HttpServletRequest request) { + SessionMap map = getSessionMap(request, authForm); - Iterator iter = unsavedFiles.iterator(); - while (iter.hasNext()) { - ChatAttachment att = (ChatAttachment) iter.next(); + List unsavedFiles; - if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { - // delete from repository and list - chatService.deleteFromRepository(att.getFileUuid(), att - .getFileVersionId()); - iter.remove(); - break; - } - } + if (StringUtils.equals(IToolContentHandler.TYPE_OFFLINE, type)) { + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, map); + } else { + unsavedFiles = getAttList(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, map); + } - request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); - request.setAttribute("unsavedChanges", new Boolean(true)); + Iterator iter = unsavedFiles.iterator(); + while (iter.hasNext()) { + ChatAttachment att = (ChatAttachment) iter.next(); - return mapping.findForward("success"); + if (att.getFileUuid().equals(authForm.getDeleteFileUuid())) { + // delete from repository and list + chatService.deleteFromRepository(att.getFileUuid(), att.getFileVersionId()); + iter.remove(); + break; + } } - /** - * Updates Chat content using AuthoringForm inputs. - * - * @param authForm - * @param mode - * @return - */ - private void updateChat(Chat chat, AuthoringForm authForm, - ToolAccessMode mode) { - chat.setTitle(authForm.getTitle()); - chat.setInstructions(authForm.getInstructions()); - if (mode.isAuthor()) { // Teacher cannot modify following - chat.setOfflineInstructions(authForm.getOfflineInstruction()); - chat.setOnlineInstructions(authForm.getOnlineInstruction()); - chat.setLockOnFinished(authForm.isLockOnFinished()); - chat.setReflectOnActivity(authForm.isReflectOnActivity()); - chat.setReflectInstructions(authForm.getReflectInstructions()); - chat.setFilteringEnabled(authForm.isFilteringEnabled()); - chat.setFilterKeywords(authForm.getFilterKeywords()); - } - } + request.setAttribute(ChatConstants.ATTR_SESSION_MAP, map); + request.setAttribute("unsavedChanges", new Boolean(true)); - /** - * Updates AuthoringForm using Chat content. - * - * @param chat - * @param authForm - * @return - */ - private void updateAuthForm(AuthoringForm authForm, Chat chat) { - authForm.setTitle(chat.getTitle()); - authForm.setInstructions(chat.getInstructions()); - authForm.setOnlineInstruction(chat.getOnlineInstructions()); - authForm.setOfflineInstruction(chat.getOfflineInstructions()); - authForm.setLockOnFinished(chat.isLockOnFinished()); - authForm.setReflectOnActivity(chat.isReflectOnActivity()); - authForm.setReflectInstructions(chat.getReflectInstructions()); - authForm.setFilteringEnabled(chat.isFilteringEnabled()); - authForm.setFilterKeywords(chat.getFilterKeywords()); + return mapping.findForward("success"); + } + + /** + * Updates Chat content using AuthoringForm inputs. + * + * @param authForm + * @param mode + * @return + */ + private void updateChat(Chat chat, AuthoringForm authForm, ToolAccessMode mode) { + chat.setTitle(authForm.getTitle()); + chat.setInstructions(authForm.getInstructions()); + if (mode.isAuthor()) { // Teacher cannot modify following + chat.setOfflineInstructions(authForm.getOfflineInstruction()); + chat.setOnlineInstructions(authForm.getOnlineInstruction()); + chat.setLockOnFinished(authForm.isLockOnFinished()); + chat.setReflectOnActivity(authForm.isReflectOnActivity()); + chat.setReflectInstructions(authForm.getReflectInstructions()); + chat.setFilteringEnabled(authForm.isFilteringEnabled()); + chat.setFilterKeywords(authForm.getFilterKeywords()); } + } - /** - * Updates SessionMap using Chat content. - * - * @param chat - * @param mode - */ - private SessionMap createSessionMap(Chat chat, - ToolAccessMode mode, String contentFolderID, Long toolContentID) { + /** + * Updates AuthoringForm using Chat content. + * + * @param chat + * @param authForm + * @return + */ + private void updateAuthForm(AuthoringForm authForm, Chat chat) { + authForm.setTitle(chat.getTitle()); + authForm.setInstructions(chat.getInstructions()); + authForm.setOnlineInstruction(chat.getOnlineInstructions()); + authForm.setOfflineInstruction(chat.getOfflineInstructions()); + authForm.setLockOnFinished(chat.isLockOnFinished()); + authForm.setReflectOnActivity(chat.isReflectOnActivity()); + authForm.setReflectInstructions(chat.getReflectInstructions()); + authForm.setFilteringEnabled(chat.isFilteringEnabled()); + authForm.setFilterKeywords(chat.getFilterKeywords()); + } - SessionMap map = new SessionMap(); + /** + * Updates SessionMap using Chat content. + * + * @param chat + * @param mode + */ + private SessionMap createSessionMap(Chat chat, ToolAccessMode mode, String contentFolderID, + Long toolContentID) { - map.put(KEY_MODE, mode); - map.put(KEY_CONTENT_FOLDER_ID, contentFolderID); - map.put(KEY_TOOL_CONTENT_ID, toolContentID); - map.put(KEY_ONLINE_FILES, new LinkedList()); - map.put(KEY_OFFLINE_FILES, new LinkedList()); - map.put(KEY_UNSAVED_ONLINE_FILES, new LinkedList()); - map.put(KEY_UNSAVED_OFFLINE_FILES, new LinkedList()); - map.put(KEY_DELETED_FILES, new LinkedList()); + SessionMap map = new SessionMap(); - Iterator iter = chat.getChatAttachments().iterator(); - while (iter.hasNext()) { - ChatAttachment attachment = (ChatAttachment) iter.next(); - String type = attachment.getFileType(); - if (type.equals(IToolContentHandler.TYPE_OFFLINE)) { - getAttList(KEY_OFFLINE_FILES, map).add(attachment); - } - if (type.equals(IToolContentHandler.TYPE_ONLINE)) { - getAttList(KEY_ONLINE_FILES, map).add(attachment); - } - } + map.put(AuthoringAction.KEY_MODE, mode); + map.put(AuthoringAction.KEY_CONTENT_FOLDER_ID, contentFolderID); + map.put(AuthoringAction.KEY_TOOL_CONTENT_ID, toolContentID); + map.put(AuthoringAction.KEY_ONLINE_FILES, new LinkedList()); + map.put(AuthoringAction.KEY_OFFLINE_FILES, new LinkedList()); + map.put(AuthoringAction.KEY_UNSAVED_ONLINE_FILES, new LinkedList()); + map.put(AuthoringAction.KEY_UNSAVED_OFFLINE_FILES, new LinkedList()); + map.put(AuthoringAction.KEY_DELETED_FILES, new LinkedList()); - return map; + Iterator iter = chat.getChatAttachments().iterator(); + while (iter.hasNext()) { + ChatAttachment attachment = (ChatAttachment) iter.next(); + String type = attachment.getFileType(); + if (type.equals(IToolContentHandler.TYPE_OFFLINE)) { + getAttList(AuthoringAction.KEY_OFFLINE_FILES, map).add(attachment); + } + if (type.equals(IToolContentHandler.TYPE_ONLINE)) { + getAttList(AuthoringAction.KEY_ONLINE_FILES, map).add(attachment); + } } + SortedSet set = new TreeSet(new TextSearchConditionComparator()); - /** - * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR - * mode. - * - * @param request - * @return - */ - private ToolAccessMode getAccessMode(HttpServletRequest request) { - ToolAccessMode mode; - String modeStr = request.getParameter(AttributeNames.ATTR_MODE); - if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER - .toString())) - mode = ToolAccessMode.TEACHER; - else - mode = ToolAccessMode.AUTHOR; - return mode; + if (chat.getConditions() != null) { + set.addAll(chat.getConditions()); } + map.put(ChatConstants.ATTR_CONDITION_SET, set); + return map; + } - /** - * Retrieves a List of attachments from the map using the key. - * - * @param key - * @param map - * @return - */ - private List getAttList(String key, - SessionMap map) { - List list = (List) map.get(key); - return list; + /** + * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode. + * + * @param request + * @return + */ + private ToolAccessMode getAccessMode(HttpServletRequest request) { + ToolAccessMode mode; + String modeStr = request.getParameter(AttributeNames.ATTR_MODE); + if (StringUtils.equalsIgnoreCase(modeStr, ToolAccessMode.TEACHER.toString())) { + mode = ToolAccessMode.TEACHER; + } else { + mode = ToolAccessMode.AUTHOR; } + return mode; + } - /** - * Retrieve the SessionMap from the HttpSession. - * - * @param request - * @param authForm - * @return - */ - private SessionMap getSessionMap( - HttpServletRequest request, AuthoringForm authForm) { - return (SessionMap) request.getSession().getAttribute( - authForm.getSessionMapID()); + /** + * Retrieves a List of attachments from the map using the key. + * + * @param key + * @param map + * @return + */ + private List getAttList(String key, SessionMap map) { + List list = (List) map.get(key); + return list; + } + + /** + * Retrieve the SessionMap from the HttpSession. + * + * @param request + * @param authForm + * @return + */ + private SessionMap getSessionMap(HttpServletRequest request, AuthoringForm authForm) { + return (SessionMap) request.getSession().getAttribute(authForm.getSessionMapID()); + } + + /** + * List save deleted taskList items, which could be persisted or non-persisted items. + * + * @param request + * @return + */ + private List getDeletedChatConditionList(SessionMap sessionMap) { + List list = (List) sessionMap.get(ChatConstants.ATTR_DELETED_CONDITION_LIST); + if (list == null) { + list = new ArrayList(); + sessionMap.put(ChatConstants.ATTR_DELETED_CONDITION_LIST, list); } + return list; + + } } \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringChatConditionAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringChatConditionAction.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/actions/AuthoringChatConditionAction.java 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,411 @@ +/**************************************************************** + * 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 + * **************************************************************** + */ + +package org.lamsfoundation.lams.tool.chat.web.actions; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionErrors; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionMessage; +import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; +import org.lamsfoundation.lams.tool.chat.service.ChatServiceProxy; +import org.lamsfoundation.lams.tool.chat.service.IChatService; +import org.lamsfoundation.lams.tool.chat.util.ChatConstants; +import org.lamsfoundation.lams.tool.chat.util.ChatException; +import org.lamsfoundation.lams.tool.chat.web.forms.AuthoringForm; +import org.lamsfoundation.lams.tool.chat.web.forms.ChatConditionForm; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.SessionMap; + +/** + * Auxiliary action in author mode. It contains operations with ChatCondition. The rest of operations are located in + * AuthoringAction action. + * + * @author Marcin Cieslak + * @see org.lamsfoundation.lams.tool.notebook.web.action.AuthoringAction + * + */ +public class AuthoringChatConditionAction extends Action { + public IChatService chatService; + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + String param = mapping.getParameter(); + + if (param.equals("newConditionInit")) { + return newConditionInit(mapping, form, request, response); + } + if (param.equals("editCondition")) { + return editCondition(mapping, form, request, response); + } + if (param.equals("saveOrUpdateCondition")) { + return saveOrUpdateCondition(mapping, form, request, response); + } + if (param.equals("removeCondition")) { + return removeCondition(mapping, form, request, response); + } + if (param.equals("upCondition")) { + return upCondition(mapping, form, request, response); + } + if (param.equals("downCondition")) { + return downCondition(mapping, form, request, response); + } + + return null; + } + + /** + * Display empty page for new taskList item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward newConditionInit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = WebUtil.readStrParam(request, ChatConstants.ATTR_SESSION_MAP_ID); + ((ChatConditionForm) form).setSessionMapID(sessionMapID); + ((ChatConditionForm) form).setOrderId(-1); + return mapping.findForward("addcondition"); + } + + /** + * Display edit page for existed taskList item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward editCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + ChatConditionForm notebookConditionForm = (ChatConditionForm) form; + String sessionMapID = notebookConditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(ChatConstants.PARAM_ORDER_ID), -1); + ChatCondition condition = null; + if (orderId != -1) { + SortedSet conditionSet = getChatConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + condition = conditionList.get(orderId); + if (condition != null) { + populateConditionToForm(orderId, condition, (ChatConditionForm) form, request); + } + } + return condition == null ? null : mapping.findForward("addcondition"); + } + + /** + * This method will get necessary information from taskList item form and save or update into + * HttpSession ChatItemList. Notice, this save is not persist them into database, just save + * HttpSession temporarily. Only they will be persist when the entire authoring page is being + * persisted. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + */ + private ActionForward saveOrUpdateCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + ChatConditionForm conditionForm = (ChatConditionForm) form; + ActionErrors errors = validateChatCondition(conditionForm, request); + + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("addcondition"); + } + + try { + extractFormToChatCondition(request, conditionForm); + } catch (Exception e) { + // any upload exception will display as normal error message rather then throw exception directly + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ChatConstants.ERROR_MSG_CONDITION, e + .getMessage())); + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("addcondition"); + } + } + // set session map ID so that itemlist.jsp can get sessionMAP + request.setAttribute(ChatConstants.ATTR_SESSION_MAP_ID, conditionForm.getSessionMapID()); + // return null to close this window + return mapping.findForward(ChatConstants.SUCCESS); + } + + /** + * Remove taskList item from HttpSession list and update page display. As authoring rule, all persist only happen + * when user submit whole page. So this remove is just impact HttpSession values. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward removeCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, ChatConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(ChatConstants.PARAM_ORDER_ID), -1); + if (orderId != -1) { + SortedSet conditionSet = getChatConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + ChatCondition condition = conditionList.remove(orderId); + for (ChatCondition otherCondition : conditionSet) { + if (otherCondition.getOrderId() > orderId) { + otherCondition.setOrderId(otherCondition.getOrderId() - 1); + } + } + conditionSet.clear(); + conditionSet.addAll(conditionList); + // add to delList + List delList = getDeletedChatConditionList(sessionMap); + delList.add(condition); + } + + request.setAttribute(ChatConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(ChatConstants.SUCCESS); + } + + /** + * Move up current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward upCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return switchItem(mapping, request, true); + } + + /** + * Move down current item. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + */ + private ActionForward downCondition(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + return switchItem(mapping, request, false); + } + + private ActionForward switchItem(ActionMapping mapping, HttpServletRequest request, boolean up) { + // get back sessionMAP + String sessionMapID = WebUtil.readStrParam(request, ChatConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + + int orderId = NumberUtils.stringToInt(request.getParameter(ChatConstants.PARAM_ORDER_ID), -1); + if (orderId != -1) { + SortedSet conditionSet = getChatConditionSet(sessionMap); + List conditionList = new ArrayList(conditionSet); + // get current and the target item, and switch their sequnece + ChatCondition condition = conditionList.get(orderId); + ChatCondition repCondition; + if (up) { + repCondition = conditionList.get(--orderId); + } else { + repCondition = conditionList.get(++orderId); + } + int upSeqId = repCondition.getOrderId(); + repCondition.setOrderId(condition.getOrderId()); + condition.setOrderId(upSeqId); + + // put back list, it will be sorted again + conditionSet.clear(); + conditionSet.addAll(conditionList); + } + + request.setAttribute(ChatConstants.ATTR_SESSION_MAP_ID, sessionMapID); + return mapping.findForward(ChatConstants.SUCCESS); + } + + // ************************************************************************************* + // Private methods for internal needs + // ************************************************************************************* + + /** + * List save current taskList items. + * + * @param request + * @return + */ + private SortedSet getChatConditionSet(SessionMap sessionMap) { + SortedSet set = (SortedSet) sessionMap.get(ChatConstants.ATTR_CONDITION_SET); + if (set == null) { + set = new TreeSet(new TextSearchConditionComparator()); + sessionMap.put(ChatConstants.ATTR_CONDITION_SET, set); + } + return set; + } + + /** + * List save deleted taskList items, which could be persisted or non-persisted items. + * + * @param request + * @return + */ + private List getDeletedChatConditionList(SessionMap sessionMap) { + return getListFromSession(sessionMap, ChatConstants.ATTR_DELETED_CONDITION_LIST); + } + + /** + * Get java.util.List from HttpSession by given name. + * + * @param request + * @param name + * @return + */ + private List getListFromSession(SessionMap sessionMap, String name) { + List list = (List) sessionMap.get(name); + if (list == null) { + list = new ArrayList(); + sessionMap.put(name, list); + } + return list; + } + + /** + * This method will populate taskList item information to its form for edit use. + * + * @param orderId + * @param condition + * @param form + * @param request + */ + private void populateConditionToForm(int orderId, ChatCondition condition, ChatConditionForm form, + HttpServletRequest request) { + form.populateForm(condition); + if (orderId >= 0) { + form.setOrderId(orderId + 1); + } + } + + /** + * Extract form content to taskListContent. + * + * @param request + * @param form + * @throws ChatException + */ + private void extractFormToChatCondition(HttpServletRequest request, ChatConditionForm form) throws Exception { + + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID()); + // check whether it is "edit(old item)" or "add(new item)" + SortedSet conditionSet = getChatConditionSet(sessionMap); + int orderId = form.getOrderId(); + ChatCondition condition = null; + + if (orderId == -1) { // add + String properConditionName = getChatService().createConditionName(conditionSet); + condition = form.extractCondition(); + condition.setName(properConditionName); + int maxSeq = 1; + if (conditionSet != null && conditionSet.size() > 0) { + ChatCondition last = conditionSet.last(); + maxSeq = last.getOrderId() + 1; + } + condition.setOrderId(maxSeq); + conditionSet.add(condition); + } else { // edit + List conditionList = new ArrayList(conditionSet); + condition = conditionList.get(orderId - 1); + form.extractCondition(condition); + } + } + + /** + * Validate taskListCondition + * + * @param conditionForm + * @return + */ + private ActionErrors validateChatCondition(ChatConditionForm conditionForm, HttpServletRequest request) { + ActionErrors errors = new ActionErrors(); + + String formConditionName = conditionForm.getDisplayName(); + if (StringUtils.isBlank(formConditionName)) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(ChatConstants.ERROR_MSG_NAME_BLANK)); + } else { + + Integer formConditionSequenceId = conditionForm.getOrderId(); + + String sessionMapID = conditionForm.getSessionMapID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SortedSet conditionList = getChatConditionSet(sessionMap); + for (ChatCondition condition : conditionList) { + if (formConditionName.equals(condition.getName()) + && !formConditionSequenceId.equals(new Integer(condition.getOrderId() - 1).toString())) { + errors.add(ActionMessages.GLOBAL_MESSAGE, + new ActionMessage(ChatConstants.ERROR_MSG_NAME_DUPLICATED)); + break; + } + } + } + return errors; + } + + private ActionMessages validate(AuthoringForm taskListForm, ActionMapping mapping, HttpServletRequest request) { + return new ActionMessages(); + } + + private IChatService getChatService() { + if (chatService == null) { + chatService = ChatServiceProxy.getChatService(this.getServlet().getServletContext()); + } + return chatService; + } +} \ No newline at end of file Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/ChatConditionForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/ChatConditionForm.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/web/forms/ChatConditionForm.java 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,61 @@ +package org.lamsfoundation.lams.tool.chat.web.forms; + +import org.lamsfoundation.lams.tool.chat.model.ChatCondition; +import org.lamsfoundation.lams.web.TextSearchActionForm; + +/** + * A text search form with additional parameters for Chat needs. + * + * @author Marcin Cieslak + * @struts.form name="chatConditionForm" + */ +public class ChatConditionForm extends TextSearchActionForm { + + private Integer orderId; + private String displayName; + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String name) { + displayName = name; + } + + public ChatConditionForm() { + } + + public void populateForm(ChatCondition condition) { + super.populateForm(condition); + setOrderId(condition.getOrderId()); + setDisplayName(condition.getDisplayName()); + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + /** + * Fills a new ChatCondition with data contained in this form. Note that some cruicial data is missing, so the + * condition is NOT complete. + * + * @return created condition + */ + public ChatCondition extractCondition() { + return new ChatCondition(null, null, getOrderId(), null, getDisplayName(), getAllWords(), getPhrase(), + getAnyWords(), getExcludedWords()); + } + + public void extractCondition(ChatCondition condition) { + condition.setOrderId(getOrderId()); + condition.setDisplayName(getDisplayName()); + condition.setAllWords(getAllWords()); + condition.setPhrase(getPhrase()); + condition.setAnyWords(getAnyWords()); + condition.setExcludedWords(getExcludedWords()); + } +} \ No newline at end of file Index: lams_tool_chat/web/WEB-INF/lams.tld =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/WEB-INF/Attic/lams.tld,v diff -u -r1.21 -r1.22 --- lams_tool_chat/web/WEB-INF/lams.tld 25 Jul 2008 07:49:38 -0000 1.21 +++ lams_tool_chat/web/WEB-INF/lams.tld 27 Oct 2008 03:31:23 -0000 1.22 @@ -466,6 +466,10 @@ ImgButtonWrapper /WEB-INF/tags/ImgButtonWrapper.tag + + + TextSearch + /WEB-INF/tags/TextSearch.tag textarea Index: lams_tool_chat/web/WEB-INF/struts/struts-config.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/WEB-INF/struts/Attic/struts-config.xml,v diff -u -r1.10 -r1.11 --- lams_tool_chat/web/WEB-INF/struts/struts-config.xml 17 Sep 2006 06:20:53 -0000 1.10 +++ lams_tool_chat/web/WEB-INF/struts/struts-config.xml 27 Oct 2008 03:31:23 -0000 1.11 @@ -22,6 +22,10 @@ type="org.lamsfoundation.lams.tool.chat.web.forms.AuthoringForm" /> + @@ -133,7 +137,46 @@ /> - + + + + + + + + + + + + + + + + + + + Index: lams_tool_chat/web/WEB-INF/tags/TextSearch.tag =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/WEB-INF/tags/TextSearch.tag,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/WEB-INF/tags/TextSearch.tag 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,136 @@ +<% +/**************************************************************** + * 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 + * **************************************************************** + */ + + /** + * TextSearch.tag + * Author: Marcin Cieslak + * Description: Displays form for creating text search conditions. + */ + + %> +<%@ tag body-content="scriptless" %> +<%@ taglib uri="tags-core" prefix="c" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="tags-html" prefix="html" %> +<%@ taglib uri="tags-lams" prefix="lams" %> + +<%-- Required attributes --%> +<%@ attribute name="sessionMapID" required="true" rtexprvalue="true" %> +<%@ attribute name="wrapInFormTag" required="true" rtexprvalue="true" %> + +<%-- Optional attributes --%> +<%@ attribute name="action" required="false" rtexprvalue="true" %> +<%@ attribute name="formID" required="false" rtexprvalue="true" %> +<%@ attribute name="headingLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="allWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="phraseLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="anyWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="excludedWordsLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="saveButtonLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="cancelButtonLabelKey" required="false" rtexprvalue="true" %> +<%@ attribute name="cancelAction" required="false" rtexprvalue="true" %> + +<%-- Default value for message key --%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

+
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + + \ No newline at end of file Index: lams_tool_chat/web/common/messages.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/common/messages.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/common/messages.jsp 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,20 @@ +<%-- Error Messages --%> + +
+ +    +   
+
+
+
+ +<%-- Success Messages --%> + +
+ +    +   
+
+
+
\ No newline at end of file Index: lams_tool_chat/web/images/cross.gif =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/images/cross.gif,v diff -u Binary files differ Index: lams_tool_chat/web/images/down.gif =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/images/down.gif,v diff -u Binary files differ Index: lams_tool_chat/web/images/down_disabled.gif =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/images/down_disabled.gif,v diff -u Binary files differ Index: lams_tool_chat/web/images/up.gif =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/images/up.gif,v diff -u Binary files differ Index: lams_tool_chat/web/images/up_disabled.gif =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/images/up_disabled.gif,v diff -u Binary files differ Index: lams_tool_chat/web/pages/authoring/addCondition.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/authoring/addCondition.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/authoring/addCondition.jsp 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,45 @@ + +<%@ include file="/common/taglibs.jsp"%> + + + + <%@ include file="/common/taglibs.jsp"%> + + + + + + <fmt:message key="activity.title" /> + + + + + + + + <%@ include file="/common/messages.jsp"%> + + +

+ +

+ +
+ +
+
+ +
+ <%-- Text search form fields are being included --%> + +
+ + + + + + +
Index: lams_tool_chat/web/pages/authoring/authoring.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/authoring/authoring.jsp,v diff -u -r1.14 -r1.15 --- lams_tool_chat/web/pages/authoring/authoring.jsp 14 Dec 2006 00:53:18 -0000 1.14 +++ lams_tool_chat/web/pages/authoring/authoring.jsp 27 Oct 2008 03:31:23 -0000 1.15 @@ -20,6 +20,7 @@ + @@ -55,6 +56,8 @@ + + + + + + + + +
+

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +
+ ${status.index + 1} + + ${condition.displayName} + + + " + onclick="upCondition(${status.index},'${sessionMapID}')"> + + "> + + + + + + "> + + + " + onclick="downCondition(${status.index},'${sessionMapID}')"> + + + " + onclick="editCondition(${status.index},'${sessionMapID}')" /> + + " + onclick="deleteCondition(${status.index},'${sessionMapID}')" /> +
+
+ +<%-- This script will works when a new resoruce Condition submit in order to refresh "TaskList List" panel. --%> + Index: lams_tool_chat/web/pages/authoring/conditions.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/authoring/conditions.jsp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/web/pages/authoring/conditions.jsp 27 Oct 2008 03:31:23 -0000 1.1 @@ -0,0 +1,110 @@ +<%@ include file="/common/taglibs.jsp"%> + + + + + +
+ + <%@ include file="/pages/authoring/conditionList.jsp"%> +
+ +

+ ');" class="button-add-item"> + +

+ + +

+ +

Index: lams_tool_chat/web/pages/authoring/headItems.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/web/pages/authoring/headItems.jsp,v diff -u -r1.2 -r1.3 --- lams_tool_chat/web/pages/authoring/headItems.jsp 30 Aug 2006 07:35:17 -0000 1.2 +++ lams_tool_chat/web/pages/authoring/headItems.jsp 27 Oct 2008 03:31:23 -0000 1.3 @@ -1,9 +1,10 @@ <%@ include file="/common/taglibs.jsp"%> - + + + - + + \ No newline at end of file