+ * @param wiki
+ */
+ public void delete(Wiki wiki) {
+ this.getHibernateTemplate().delete(wiki);
+ }
+
+ public Wiki getByContentId(Long contentID) {
+ List list = getHibernateTemplate().find(FIND_FORUM_BY_CONTENTID,contentID);
+ if(list != null && list.size() > 0)
+ return (Wiki) list.get(0);
+ else
+ return null;
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiException.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiException.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiException.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,58 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+
+/**
+ * User: conradb
+ * Date: 14/06/2005
+ * Time: 12:33:12
+ */
+public class WikiException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7408922611270822369L;
+
+ public WikiException(String message) {
+ super(message);
+ }
+
+ public WikiException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public WikiException() {
+ super();
+
+ }
+
+ public WikiException(Throwable cause) {
+ super(cause);
+
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageDao.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageDao.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageDao.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,130 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.List;
+
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * @author conradb
+ */
+public class WikiMessageDao extends HibernateDaoSupport {
+ private static final String SQL_QUERY_FIND_ROOT_TOPICS = "from " + Message.class.getName() +" m "
+ + " where parent_uid is null and m.toolSession.sessionId=?";
+
+ private static final String SQL_QUERY_FIND_TOPICS_FROM_AUTHOR = "from " + Message.class.getName()
+ + " where is_authored = true and wiki_uid=? order by create_date";
+
+ private static final String SQL_QUERY_FIND_CHILDREN = "from " + Message.class.getName()
+ + " where parent=?";
+
+ private static final String SQL_QUERY_BY_USER_SESSION = "from " + Message.class.getName() + " m "
+ + " where m.createdBy.uid = ? and m.toolSession.sessionId=?";
+
+ private static final String SQL_QUERY_BY_SESSION = "from " + Message.class.getName() + " m "
+ + " where m.toolSession.sessionId=?";
+
+ private static final String SQL_QUERY_TOPICS_NUMBER_BY_USER_SESSION = "select count(*) from " + Message.class.getName() + " m "
+ + " where m.createdBy.userId=? and m.toolSession.sessionId=? and m.isAuthored = false";
+
+
+ public void saveOrUpdate(Message message) {
+ message.updateModificationData();
+
+ this.getHibernateTemplate().saveOrUpdate(message);
+ }
+
+ public void update(Message message) {
+ this.getHibernateTemplate().saveOrUpdate(message);
+ }
+
+ public Message getById(Long messageId) {
+ return (Message) getHibernateTemplate().get(Message.class,messageId);
+ }
+ /**
+ * Get all root (first level) topics in a special Session.
+ * @param sessionId
+ * @return
+ */
+ public List getRootTopics(Long sessionId) {
+ return this.getHibernateTemplate().find(SQL_QUERY_FIND_ROOT_TOPICS, sessionId);
+ }
+ /**
+ * Get all message posted by author role in a special wiki.
+ * @param wikiUid
+ * @return
+ */
+ public List getTopicsFromAuthor(Long wikiUid) {
+ return this.getHibernateTemplate().find(SQL_QUERY_FIND_TOPICS_FROM_AUTHOR, wikiUid);
+ }
+
+ public void delete(Long uid) {
+ Message msg = getById(uid);
+ if(msg != null){
+ this.getHibernateTemplate().delete(msg);
+ }
+ }
+ /**
+ * Get all children message from the given parent topic ID.
+ * @param parentId
+ * @return
+ */
+ public List getChildrenTopics(Long parentId) {
+ return this.getHibernateTemplate().find(SQL_QUERY_FIND_CHILDREN, parentId);
+ }
+ /**
+ * Get all messages according to special user and session.
+ * @param userUid
+ * @param sessionId
+ * @return
+ */
+ public List getByUserAndSession(Long userUid, Long sessionId) {
+ return this.getHibernateTemplate().find(SQL_QUERY_BY_USER_SESSION, new Object[]{userUid,sessionId});
+ }
+ /**
+ * Get all messages according to special session.
+ * @param sessionId
+ * @return
+ */
+ public List getBySession(Long sessionId) {
+ return this.getHibernateTemplate().find(SQL_QUERY_BY_SESSION, sessionId);
+ }
+ /**
+ * Return how many post from this user and session. DOES NOT include posts from author.
+ * @param userID
+ * @param sessionId
+ * @return
+ */
+ public int getTopicsNum(Long userID, Long sessionId) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_TOPICS_NUMBER_BY_USER_SESSION,new Object[]{userID,sessionId});
+ if(list != null && list.size() > 0)
+ return ((Number)list.get(0)).intValue();
+ else
+ return 0;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageSeqDao.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageSeqDao.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiMessageSeqDao.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,60 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.List;
+
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+public class WikiMessageSeqDao extends HibernateDaoSupport {
+ private static final String SQL_QUERY_FIND_TOPIC_THREAD = "from " + MessageSeq.class.getName()
+ + " where root_message_uid = ?";
+ private static final String SQL_QUERY_FIND_TOPIC_ID = "from " + MessageSeq.class.getName()
+ + " where message_uid = ?";
+
+ public List getTopicThread(Long rootTopicId) {
+ return this.getHibernateTemplate().find(SQL_QUERY_FIND_TOPIC_THREAD,rootTopicId);
+ }
+
+ public MessageSeq getByTopicId(Long messageId) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_FIND_TOPIC_ID,messageId);
+ if(list == null || list.isEmpty())
+ return null;
+ return (MessageSeq) list.get(0);
+ }
+
+ public void save(MessageSeq msgSeq) {
+ this.getHibernateTemplate().save(msgSeq);
+ }
+
+ public void deleteByTopicId(Long topicUid) {
+ MessageSeq seq = getByTopicId(topicUid);
+ if(seq != null)
+ this.getHibernateTemplate().delete(seq);
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.hbm.xml
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.hbm.xml (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.hbm.xml (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,81 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.Date;
+
+/**
+ *
+ * @hibernate.class table="tl_lawiki10_report"
+ *
+ */
+public class WikiReport {
+
+ private Long uid;
+ private Float mark;
+ private String comment;
+ private Date dateMarksReleased;
+ /**
+ * @hibernate.id column="uid" generator-class="native"
+ */
+ public Long getUid() {
+ return uid;
+ }
+ public void setUid(Long uid) {
+ this.uid = uid;
+ }
+ /**
+ * @hibernate.property column="comment" type="text"
+ * @return
+ */
+ public String getComment() {
+ return comment;
+ }
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+ /**
+ * @hibernate.property column="release_date"
+ * @return
+ */
+ public Date getDateMarksReleased() {
+ return dateMarksReleased;
+ }
+ public void setDateMarksReleased(Date dateMarksReleased) {
+ this.dateMarksReleased = dateMarksReleased;
+ }
+ /**
+ * @hibernate.property column="mark"
+ * @return
+ */
+ public Float getMark() {
+ return mark;
+ }
+ public void setMark(Float mark) {
+ this.mark = mark;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReportDAO.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReportDAO.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiReportDAO.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,6 @@
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+
+public class WikiReportDAO extends BaseDAOHibernate {
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.hbm.xml
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.hbm.xml (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.hbm.xml (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,176 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @hibernate.class table="tl_lawiki10_tool_session"
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ */
+public class WikiToolSession implements Cloneable{
+
+ private static Logger log = Logger.getLogger(WikiToolSession.class);
+
+ private Long uid;
+ private Long sessionId;
+ private String sessionName;
+ private Wiki wiki;
+ private Date sessionStartDate;
+ private Date sessionEndDate;
+ private boolean markReleased;
+ //content topics copyed (1) or not (0)
+ private int status;
+
+ //optimistic lock
+ private int version;
+// **********************************************************
+ // Function method for WikiToolSession
+// **********************************************************
+ public Object clone(){
+
+ WikiToolSession session = null;
+ try{
+ session = (WikiToolSession) super.clone();
+
+ } catch (CloneNotSupportedException e) {
+ log.error("When clone " + WikiToolSession.class + " failed");
+ }
+ return session;
+ }
+
+
+// **********************************************************
+ // Get/Set methods
+// **********************************************************
+ /**
+ * @hibernate.id generator-class="native" type="java.lang.Long" column="uid"
+ * @return Returns the learnerID.
+ */
+ public Long getUid() {
+ return uid;
+ }
+ public void setUid(Long uuid) {
+ this.uid = uuid;
+ }
+
+ /**
+ * @hibernate.property column="session_end_date"
+ * @return
+ */
+ public Date getSessionEndDate() {
+ return sessionEndDate;
+ }
+ public void setSessionEndDate(Date sessionEndDate) {
+ this.sessionEndDate = sessionEndDate;
+ }
+ /**
+ * @hibernate.property column="session_start_date"
+ *
+ * @return
+ */
+ public Date getSessionStartDate() {
+ return sessionStartDate;
+ }
+ public void setSessionStartDate(Date sessionStartDate) {
+ this.sessionStartDate = sessionStartDate;
+ }
+ /**
+ * @hibernate.property
+ * @return
+ */
+ public int getStatus() {
+ return status;
+ }
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ /**
+ * @hibernate.many-to-one column="wiki_uid"
+ * cascade="none"
+ * @return
+ */
+ public Wiki getWiki() {
+ return wiki;
+ }
+ public void setWiki(Wiki wiki) {
+ this.wiki = wiki;
+ }
+ /**
+ * @hibernate.property column="session_id"
+ * @return
+ */
+ public Long getSessionId() {
+ return sessionId;
+ }
+ public void setSessionId(Long sessionId) {
+ this.sessionId = sessionId;
+ }
+
+ /**
+ * @hibernate.property column="session_name" length="250"
+ * @return Returns the session name
+ */
+ public String getSessionName() {
+ return sessionName;
+ }
+
+ /**
+ *
+ * @param sessionName The session name to set.
+ */
+ public void setSessionName(String sessionName) {
+ this.sessionName = sessionName;
+ }
+
+ /**
+ * @hibernate.property column="mark_released"
+ * @return Returns the mark released flag
+ */
+ public boolean isMarkReleased() {
+ return markReleased;
+ }
+ public void setMarkReleased(boolean markReleased) {
+ this.markReleased = markReleased;
+ }
+
+ /**
+ * @hibernate.version column="version"
+ */
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSessionDao.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSessionDao.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSessionDao.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.List;
+
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+public class WikiToolSessionDao extends HibernateDaoSupport {
+
+ private static final String SQL_QUERY_FIND_BY_SESSION_ID = "from " + WikiToolSession.class.getName() + " where session_id=?";
+ private static final String SQL_QUERY_FIND_BY_CONTENT_ID = "select s from " + Wiki.class.getName()+ " as f, " +
+ WikiToolSession.class.getName() + " as s" +
+ " where f.contentId=? and s.wiki.uid=f.uid";
+
+ public WikiToolSession getBySessionId(Long sessionId) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_FIND_BY_SESSION_ID,sessionId);
+ if(list == null || list.isEmpty())
+ return null;
+ return (WikiToolSession) list.get(0);
+ }
+
+ public void saveOrUpdate(WikiToolSession session){
+ this.getHibernateTemplate().saveOrUpdate(session);
+ }
+
+ public List getByContentId(Long contentID) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_FIND_BY_CONTENT_ID,contentID);
+ return list;
+ }
+
+ public void delete(Long sessionId) {
+ WikiToolSession session = getBySessionId(sessionId);
+ this.getHibernateTemplate().delete(session);
+ }
+
+ public void delete(WikiToolSession session){
+ this.getHibernateTemplate().delete(session);
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.hbm.xml
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.hbm.xml (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.hbm.xml (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,89 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,196 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.io.Serializable;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+/**
+ *
+ * @hibernate.class table="tl_lawiki10_wiki_user"
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ * @serialData -7043502180037866257L
+ */
+public class WikiUser implements Serializable,Cloneable{
+
+ private static final long serialVersionUID = -7043502180037866257L;
+ private static Logger log = Logger.getLogger(WikiUser.class);
+
+ private Long uid;
+ private Long userId;
+ private String firstName;
+ private String lastName;
+ private String loginName;
+ private boolean sessionFinished;
+
+ private WikiToolSession session;
+
+ public WikiUser(){
+ }
+
+ public WikiUser(UserDTO user, WikiToolSession session) {
+ this.userId = new Long(user.getUserID().intValue());
+ this.firstName = user.getFirstName();
+ this.lastName = user.getLastName();
+ this.loginName = user.getLogin();
+ this.session = session;
+ this.sessionFinished = false;
+ }
+
+
+// **********************************************************
+ // Function method for WikiUser
+// **********************************************************
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ public Object clone() {
+
+ Object obj = null;
+ try {
+ obj = super.clone();
+ } catch (CloneNotSupportedException e) {
+ log.error("When clone " + WikiUser.class + " failed");
+ }
+ return obj;
+ }
+
+
+// **********************************************************
+ // Get/Set methods
+// **********************************************************
+ /**
+ * @hibernate.id generator-class="native" type="java.lang.Long" column="uid"
+ * @return Returns the uid.
+ */
+ public Long getUid() {
+ return uid;
+ }
+ /**
+ * @param uid The uid to set.
+ */
+ public void setUid(Long userID) {
+ this.uid = userID;
+ }
+
+ /**
+ * @hibernate.property column="user_id" length="20"
+ * @return Returns the userId.
+ */
+ public Long getUserId() {
+ return userId;
+ }
+ /**
+ * @param userId
+ * The userId to set.
+ */
+ public void setUserId(Long userID) {
+ this.userId = userID;
+ }
+
+ /**
+ * @hibernate.property length="255" column="last_name"
+ * @return
+ */
+ public String getLastName() {
+ return lastName;
+ }
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ /**
+ * @hibernate.property length="255" column="first_name"
+ * @return
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ /**
+ * @hibernate.many-to-one column="session_id"
+ * cascade="none"
+ * @return
+ */
+ public WikiToolSession getSession() {
+ return session;
+ }
+
+ public void setSession(WikiToolSession session) {
+ this.session = session;
+ }
+
+ /**
+ * @hibernate.property column="login_name"
+ * @return
+ */
+ public String getLoginName() {
+ return loginName;
+ }
+
+ public void setLoginName(String loginName) {
+ this.loginName = loginName;
+ }
+ /**
+ * @hibernate.property column="session_finished"
+ * @return
+ */
+ public boolean isSessionFinished() {
+ return sessionFinished;
+ }
+
+ public void setSessionFinished(boolean sessionFinished) {
+ this.sessionFinished = sessionFinished;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof WikiUser))
+ return false;
+
+ final WikiUser user = (WikiUser) obj;
+
+ return new EqualsBuilder().append(this.uid, user.uid).append(this.firstName, user.firstName)
+ .append(this.lastName,user.lastName).append(this.loginName, user.loginName).isEquals();
+
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder().append(uid).append(firstName)
+ .append(lastName).append(loginName)
+ .toHashCode();
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUserDao.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUserDao.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/persistence/WikiUserDao.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,80 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.persistence;
+
+import java.util.List;
+
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+public class WikiUserDao extends HibernateDaoSupport{
+
+ private static final String SQL_QUERY_FIND_BY_USER_ID_SESSION_ID = "from " + WikiUser.class.getName() + " as f"
+ + " where user_id=? and f.session.sessionId=?";
+
+ private static final String SQL_QUERY_FIND_BY_USER_ID = "from " + WikiUser.class.getName() + " as f"
+ + " where user_id=? and session_id is null";
+
+ private static final String SQL_QUERY_FIND_BY_SESSION_ID = "from " +
+ WikiUser.class.getName() + " as f " +
+ " where f.session.sessionId=?";
+
+
+ public List getBySessionId(Long sessionID) {
+ return this.getHibernateTemplate().find(SQL_QUERY_FIND_BY_SESSION_ID, sessionID);
+ }
+
+ public void save(WikiUser wikiUser){
+ this.getHibernateTemplate().save(wikiUser);
+ }
+ public WikiUser getByUserIdAndSessionId(Long userId, Long sessionId) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_FIND_BY_USER_ID_SESSION_ID
+ , new Object[]{userId,sessionId});
+
+ if(list == null || list.isEmpty())
+ return null;
+
+ return (WikiUser) list.get(0);
+ }
+
+ public WikiUser getByUserId(Long userId) {
+ List list = this.getHibernateTemplate().find(SQL_QUERY_FIND_BY_USER_ID, userId);
+
+ if(list == null || list.isEmpty())
+ return null;
+
+ return (WikiUser) list.get(0);
+ }
+ public WikiUser getByUid(Long userUid) {
+
+ return (WikiUser) this.getHibernateTemplate().get(WikiUser.class,userUid);
+ }
+
+ public void delete(WikiUser user) {
+ this.getHibernateTemplate().delete(user);
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/IWikiService.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/IWikiService.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/IWikiService.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,314 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.service;
+
+import java.util.List;
+
+import org.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.dto.UserDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiReport;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.persistence.PersistenceException;
+import org.lamsfoundation.lams.util.audit.IAuditService;
+
+/**
+ * User: conradb
+ * Date: 8/06/2005
+ * Time: 14:49:59
+ */
+public interface IWikiService {
+ //************************************************************************************
+ // Wiki Method
+ //************************************************************************************
+ /**
+ * Create a Wiki instance according to the default content.
+ * Note, this new insstance won't save into database until called persist method.
+ *
+ * @param contentID
+ * @return
+ */
+ public Wiki getDefaultContent(Long contentID);
+ /**
+ * Update wiki by given Wiki. If wiki does not exist, the create a new wiki.
+ * @param wiki
+ * @return
+ * @throws PersistenceException
+ */
+ public Wiki updateWiki(Wiki wiki) throws PersistenceException;
+ /**
+ * Upload instruction file
+ * @param file
+ * @param type
+ * @return
+ * @throws PersistenceException
+ */
+ public Attachment uploadInstructionFile(FormFile file, String type) throws PersistenceException;
+ /**
+ * Get wiki by wiki UID
+ * @param wikiUid
+ * @return
+ * @throws PersistenceException
+ */
+ public Wiki getWiki(Long wikiUid) throws PersistenceException;
+ /**
+ * Get wiki by wiki ID(not record UID)
+ * @param contentID
+ * @return
+ * @throws PersistenceException
+ */
+ public Wiki getWikiByContentId(Long contentID) throws PersistenceException;
+
+ /**
+ * Delete authoring page instruction files.
+ * @param attachmentId
+ * @throws PersistenceException
+ */
+ public void deleteWikiAttachment(Long attachmentId) throws PersistenceException;
+
+ //************************************************************************************
+ //Topic Method
+ //************************************************************************************
+ /**
+ * Create a root topic.
+ * @param wikiId
+ * @param sessionId
+ * @param message
+ * @return
+ * @throws PersistenceException
+ */
+ public Message createRootTopic(Long wikiId, Long sessionId, Message message) throws PersistenceException ;
+ /**
+ * Update a topic by give Message instance.
+ * @param message
+ * @return
+ * @throws PersistenceException
+ */
+ public Message updateTopic(Message message) throws PersistenceException;
+ /**
+ * Hide a message by given Message instance
+ * @param message
+ * @return
+ * @throws PersistenceException
+ */
+ public Message updateMessageHideFlag(Long messageId, boolean hideFlag) throws PersistenceException;
+ /**
+ * Reply a topic.
+ * @param parentId
+ * @param sessionId ToolSessionID
+ * @param message
+ * @return
+ * @throws PersistenceException
+ */
+ public Message replyTopic(Long parentId, Long sessionId, Message message) throws PersistenceException;
+
+ /**
+ * Delete the topic by given topic ID. The function will delete all children topics under this topic.
+ * @param topicId
+ * @throws PersistenceException
+ */
+ public void deleteTopic(Long topicId) throws PersistenceException;
+ /**
+ * Upload message attachment file into repository.
+ * This method only upload the given file into system repository. It does not execute any database operation.
+ *
+ * @param file
+ * @return Attachment
+ * A new instance of attachment has uploaded file VersionID and UUID information.
+ * @throws PersistenceException
+ */
+ public Attachment uploadAttachment(FormFile file) throws PersistenceException;
+
+ /**
+ * Delete file from repository.
+ * @param uuID
+ * @param versionID
+ * @throws PersistenceException
+ */
+ public void deleteFromRepository(Long uuID, Long versionID) throws PersistenceException;
+
+ //************************************************************************************
+ //*********************Get topic methods **********************
+ //************************************************************************************
+ /**
+ * Get topic and its children list by given root topic ID.
+ * Note that the return type is DTO.
+ *
+ * @param rootTopicId
+ * @return
+ * List of MessageDTO
+ */
+ public List getTopicThread(Long rootTopicId);
+ /**
+ * Get root topics by a given sessionID value. Simultanousely, it gets back topics, which author
+ * posted in authoring page for this wiki, which is related with the given sessionID value.
+ *
+ * This method will used by user to display initial topic page for a wiki.
+ *
+ * Note that the return type is DTO.
+ * @param sessionId
+ * @return
+ * List of MessageDTO
+ */
+ public List getRootTopics(Long sessionId);
+ /**
+ * Get topics posted by author role. Note that the return type is DTO.
+ * @return
+ * List of MessageDTO
+ */
+ public List getAuthoredTopics(Long wikiId);
+ /**
+ * This method will look up root topic ID by any level topicID.
+ * @param topicId
+ * @return
+ */
+ public Long getRootTopicId(Long topicId);
+ /**
+ * Get message by given message UID
+ * @param messageUid
+ * @return
+ * Message
+ * @throws PersistenceException
+ */
+ public Message getMessage(Long messageUid) throws PersistenceException;
+ /**
+ * Get message list posted by given user.
+ * Note that the return type is DTO.
+ * @param userId
+ * @return
+ */
+ public List getMessagesByUserUid(Long userId, Long sessionId);
+ /**
+ * Get how many post of this user post in a special session. DOES NOT include posts from author.
+ * @param userID
+ * @param sessionId
+ * @return
+ */
+ public int getTopicsNum(Long userID, Long sessionId);
+
+ //************************************************************************************
+ // Session Method
+ //************************************************************************************
+ /**
+ * Get Wiki tool session by Session ID (not record UID).
+ * @param sessionId
+ * @return
+ */
+ public WikiToolSession getSessionBySessionId(Long sessionId);
+
+ /**
+ * Get session list according to content ID.
+ * @param contentID
+ * @return List
+ */
+ public List getSessionsByContentId(Long contentID);
+ /**
+ * Get all message according to the given session ID.
+ * @param sessionID
+ * @return
+ */
+ public List getAllTopicsFromSession(Long sessionID);
+ //************************************************************************************
+ // User Method
+ //************************************************************************************
+ /**
+ * Create a new user in database.
+ * @param wikiUser
+ */
+ public void createUser(WikiUser wikiUser);
+ /**
+ * Get user by user ID (not record UID).
+ * @param userId
+ * @return
+ */
+ public WikiUser getUserByUserAndSession(Long userId,Long sessionId);
+ /**
+ * Get user list by given session ID.
+ * @param sessionID
+ * @return
+ */
+ public List getUsersBySessionId(Long sessionID);
+ /**
+ * Get user by uid
+ * @param userUid
+ * @return
+ */
+ public WikiUser getUser(Long userUid);
+ /**
+ * Get user by user ID
+ * @param userId
+ * @return
+ */
+ public WikiUser getUserByID(Long userId);
+ /**
+ * Update wiki message report.
+ * @param report
+ */
+ public void updateReport(WikiReport report);
+ //************************************************************************************
+ // Report Method
+ //************************************************************************************
+
+ //************************************************************************************
+ // Miscellaneous Method
+ //************************************************************************************
+ public void releaseMarksForSession(Long sessionID);
+
+ /** The topic updates (for monitoring) are done in the web layer, so need the audit service to log the updates */
+ public IAuditService getAuditService( );
+ /**
+ * Mark user completing a session.
+ * @param currentUser
+ */
+ public void finishUserSession(WikiUser currentUser);
+ /**
+ * Create refection entry into notebook tool.
+ * @param sessionId
+ * @param notebook_tool
+ * @param tool_signature
+ * @param userId
+ * @param entryText
+ */
+ public Long createNotebookEntry(Long sessionId, Integer notebookToolType, String toolSignature, Integer userId, String entryText);
+ /**
+ * Get reflection entry from notebook tool.
+ * @param sessionId
+ * @param idType
+ * @param signature
+ * @param userID
+ * @return
+ */
+ public NotebookEntry getEntry(Long sessionId, Integer idType, String signature, Integer userID);
+
+ /**
+ * @param notebookEntry
+ */
+ public void updateEntry(NotebookEntry notebookEntry);
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiOutputFactory.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiOutputFactory.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiOutputFactory.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,83 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.tool.wiki.service;
+
+import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.lamsfoundation.lams.tool.OutputFactory;
+import org.lamsfoundation.lams.tool.ToolOutput;
+import org.lamsfoundation.lams.tool.ToolOutputDefinition;
+import org.lamsfoundation.lams.tool.exception.ToolException;
+
+/**
+ * Creates the output definitions for wiki. Eventually there will be a definition
+ * that outputs some or all of the wiki queries, but for now there are just a couple of
+ * simple definitions so that we can try various features of the tool output based
+ * branching.
+ */
+public class WikiOutputFactory extends OutputFactory {
+
+ /** The number of posts the learner has made in one wiki activity. */
+ protected final static String OUTPUT_NAME_LEARNER_NUM_POSTS = "learner.number.of.posts";
+
+ /**
+ * @see org.lamsfoundation.lams.tool.OutputDefinitionFactory#getToolOutputDefinitions(java.lang.Object)
+ */
+ public SortedMap getToolOutputDefinitions(
+ Object toolContentObject) throws ToolException {
+ TreeMap definitionMap = new TreeMap();
+
+ ToolOutputDefinition definition = buildRangeDefinition(OUTPUT_NAME_LEARNER_NUM_POSTS, new Long(0), null);
+ definitionMap.put(OUTPUT_NAME_LEARNER_NUM_POSTS, definition);
+
+ return definitionMap;
+ }
+
+ public SortedMap getToolOutput(List names, IWikiService wikiService,
+ Long toolSessionId, Long learnerId) {
+
+ TreeMap map = new TreeMap();
+ if ( names == null || names.contains(OUTPUT_NAME_LEARNER_NUM_POSTS)) {
+ map.put(OUTPUT_NAME_LEARNER_NUM_POSTS,getNumPosts(wikiService, learnerId, toolSessionId));
+ }
+ return map;
+
+ }
+
+ public ToolOutput getToolOutput(String name, IWikiService wikiService, Long toolSessionId, Long learnerId) {
+
+ if ( name != null && name.equals(OUTPUT_NAME_LEARNER_NUM_POSTS)) {
+ return getNumPosts(wikiService, learnerId, toolSessionId);
+ }
+ return null;
+
+ }
+
+ private ToolOutput getNumPosts(IWikiService wikiService, Long learnerId, Long toolSessionId) {
+ int num = wikiService.getTopicsNum(learnerId, toolSessionId);
+ return new ToolOutput(OUTPUT_NAME_LEARNER_NUM_POSTS, "", new Long(num));
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiService.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiService.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiService.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,1140 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.service;
+
+import static org.lamsfoundation.lams.tool.wiki.util.WikiConstants.OLD_FORUM_STYLE;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.Vector;
+import java.util.Map.Entry;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.contentrepository.AccessDeniedException;
+import org.lamsfoundation.lams.contentrepository.ICredentials;
+import org.lamsfoundation.lams.contentrepository.ITicket;
+import org.lamsfoundation.lams.contentrepository.InvalidParameterException;
+import org.lamsfoundation.lams.contentrepository.LoginException;
+import org.lamsfoundation.lams.contentrepository.NodeKey;
+import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException;
+import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException;
+import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler;
+import org.lamsfoundation.lams.contentrepository.service.IRepositoryService;
+import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials;
+import org.lamsfoundation.lams.learning.service.ILearnerService;
+import org.lamsfoundation.lams.learningdesign.service.ExportToolContentException;
+import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService;
+import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException;
+import org.lamsfoundation.lams.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.notebook.service.ICoreNotebookService;
+import org.lamsfoundation.lams.tool.ToolContentImport102Manager;
+import org.lamsfoundation.lams.tool.ToolContentManager;
+import org.lamsfoundation.lams.tool.ToolOutput;
+import org.lamsfoundation.lams.tool.ToolOutputDefinition;
+import org.lamsfoundation.lams.tool.ToolSessionExportOutputData;
+import org.lamsfoundation.lams.tool.ToolSessionManager;
+import org.lamsfoundation.lams.tool.exception.DataMissingException;
+import org.lamsfoundation.lams.tool.exception.SessionDataExistsException;
+import org.lamsfoundation.lams.tool.exception.ToolException;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiAttachmentDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiException;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiReport;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiReportDAO;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSessionDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUserDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiMessageDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.MessageSeq;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiMessageSeqDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.PersistenceException;
+import org.lamsfoundation.lams.tool.wiki.util.DateComparator;
+import org.lamsfoundation.lams.tool.wiki.util.WikiConstants;
+import org.lamsfoundation.lams.tool.wiki.util.WikiToolContentHandler;
+import org.lamsfoundation.lams.tool.wiki.util.TopicComparator;
+import org.lamsfoundation.lams.tool.service.ILamsToolService;
+import org.lamsfoundation.lams.usermanagement.User;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.usermanagement.service.IUserManagementService;
+import org.lamsfoundation.lams.util.MessageService;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.util.audit.IAuditService;
+import org.lamsfoundation.lams.util.wddx.WDDXProcessor;
+import org.lamsfoundation.lams.util.wddx.WDDXProcessorConversionException;
+
+/**
+ *
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ */
+public class WikiService implements IWikiService,ToolContentManager,ToolSessionManager,ToolContentImport102Manager {
+ private static final Logger log = Logger.getLogger(WikiService.class);
+ //DAO variables
+ private WikiDao wikiDao;
+ private WikiAttachmentDao wikiAttachmentDao;
+ private WikiMessageDao wikiMessageDao;
+ private WikiMessageSeqDao wikiMessageSeqDao;
+ private WikiUserDao wikiUserDao;
+ private WikiToolSessionDao wikiToolSessionDao;
+ private WikiReportDAO wikiReportDAO;
+ //system level handler and service
+ private ILamsToolService toolService;
+ private WikiToolContentHandler wikiToolContentHandler;
+ private IRepositoryService repositoryService;
+ private ILearnerService learnerService;
+ private IAuditService auditService;
+ private MessageService messageService;
+ private IExportToolContentService exportContentService;
+ private IUserManagementService userManagementService;
+ private ICoreNotebookService coreNotebookService;
+ private WikiOutputFactory wikiOutputFactory;
+
+ //---------------------------------------------------------------------
+ // Inversion of Control Methods - Method injection
+ //---------------------------------------------------------------------
+ public void setAuditService(IAuditService auditService) {
+ this.auditService = auditService;
+ }
+
+ public IAuditService getAuditService( ) {
+ return auditService;
+ }
+
+ public void setMessageService(MessageService messageService) {
+ this.messageService = messageService;
+ }
+
+ public WikiOutputFactory getWikiOutputFactory() {
+ return wikiOutputFactory;
+ }
+
+ public void setWikiOutputFactory(
+ WikiOutputFactory wikiOutputFactory) {
+ this.wikiOutputFactory = wikiOutputFactory;
+ }
+
+ public Wiki updateWiki(Wiki wiki) throws PersistenceException {
+ wikiDao.saveOrUpdate(wiki);
+ return wiki;
+ }
+
+ public Wiki getWiki(Long wikiUid) throws PersistenceException {
+ return (Wiki) wikiDao.getById(wikiUid);
+ }
+
+ public Wiki getWikiByContentId(Long contentID) throws PersistenceException {
+ return (Wiki) wikiDao.getByContentId(contentID);
+ }
+
+ public void deleteWikiAttachment(Long attachmentId) throws PersistenceException {
+ Attachment attachment = (Attachment) wikiAttachmentDao.getById(attachmentId);
+ wikiAttachmentDao.delete(attachment);
+ }
+
+ public Message createRootTopic(Long wikiId, Long sessionId, Message message) throws PersistenceException {
+ return createRootTopic(wikiId, getSessionBySessionId(sessionId), message);
+ }
+
+ public Message createRootTopic(Long wikiId, WikiToolSession session, Message message) throws PersistenceException {
+ //get Wiki and WikiToolSesion
+ if(message.getWiki() == null){
+ Wiki wiki = wikiDao.getById(wikiId);
+ message.setWiki(wiki);
+ }
+ //if topic created by author, session will be null.
+ if(session != null){
+ message.setToolSession(session);
+ }
+
+ if(message.getUid() == null){
+ //update message sequence
+ MessageSeq msgSeq = new MessageSeq();
+ msgSeq.setMessage(message);
+ msgSeq.setMessageLevel((short) 0);
+ //set itself as root
+ msgSeq.setRootMessage(message);
+ wikiMessageSeqDao.save(msgSeq);
+ }
+
+ // if this message had any cloned objects, they also need to be changed.
+ // this will only happen if an authored topic is changed via monitoring
+ if ( message.getSessionClones().size() > 0 ) {
+ Iterator iter = message.getSessionClones().iterator();
+ while ( iter.hasNext() ) {
+ Message clone = (Message) iter.next();
+ message.updateClone(clone);
+ }
+ }
+
+ //create message in database
+ wikiMessageDao.saveOrUpdate(message);
+
+ return message;
+ }
+
+ public Message updateTopic(Message message) throws PersistenceException {
+
+ //update message
+ wikiMessageDao.saveOrUpdate(message);
+
+ //udate root message's lastReply date if this message
+ //if this message is root message, then actually, it will update itself lastReplayDate
+ MessageSeq msgSeq = wikiMessageSeqDao.getByTopicId(message.getUid());
+ Message root = msgSeq.getRootMessage();
+ //update reply date
+ wikiMessageDao.saveOrUpdate(root);
+
+ return message;
+ }
+
+ public void updateReport(WikiReport report) {
+ wikiReportDAO.saveObject(report);
+ }
+ public Message updateMessageHideFlag(Long messageId, boolean hideFlag) {
+
+ Message message = getMessage(messageId);
+ if ( message !=null ) {
+ Long userId = 0L;
+ String loginName = "Default";
+ if(message.getCreatedBy() == null){
+ userId = message.getCreatedBy().getUserId();
+ loginName = message.getCreatedBy().getLoginName();
+ }
+ if ( hideFlag ) {
+ auditService.logHideEntry(WikiConstants.TOOL_SIGNATURE, userId,
+ loginName, message.toString());
+ } else {
+ auditService.logShowEntry(WikiConstants.TOOL_SIGNATURE,userId,
+ loginName, message.toString());
+ }
+
+ message.setHideFlag(hideFlag);
+
+ // update message
+ wikiMessageDao.update(message);
+ }
+ return message;
+ }
+
+ public Message getMessage(Long messageUid) throws PersistenceException {
+ return (Message) wikiMessageDao.getById(messageUid);
+ }
+
+ public void deleteTopic(Long topicUid) throws PersistenceException {
+ List children = wikiMessageDao.getChildrenTopics(topicUid);
+ //cascade delete children topic by recursive
+ if(children != null){
+ Iterator iter = children.iterator();
+ while(iter.hasNext()){
+ Message msg = (Message) iter.next();
+ this.deleteTopic(msg.getUid());
+ }
+ }
+ wikiMessageSeqDao.deleteByTopicId(topicUid);
+ wikiMessageDao.delete(topicUid);
+ }
+
+ public Message replyTopic(Long parentId,Long sessionId, Message replyMessage) throws PersistenceException {
+ //set parent
+ Message parent = this.getMessage(parentId);
+ replyMessage.setParent(parent);
+ replyMessage.setWiki(parent.getWiki());
+ //parent sessionID maybe empty if created by author role. So given sessionId is exactly value.
+ WikiToolSession session = getSessionBySessionId(sessionId);
+ replyMessage.setToolSession(session);
+ wikiMessageDao.saveOrUpdate(replyMessage);
+
+ //get root topic and create record in MessageSeq table
+ MessageSeq parentSeq = wikiMessageSeqDao.getByTopicId(parent.getUid());
+ if(parentSeq == null){
+ log.error("Message Sequence table is broken becuase topic " + parent +" can not get Sequence Record");
+ }
+ Message root = parentSeq.getRootMessage();
+ MessageSeq msgSeq = new MessageSeq();
+ msgSeq.setMessage(replyMessage);
+ msgSeq.setMessageLevel((short) (parentSeq.getMessageLevel() + 1));
+ msgSeq.setRootMessage(root);
+ wikiMessageSeqDao.save(msgSeq);
+
+ //update last reply date for root message
+ root.setLastReplyDate(new Date());
+ //update reply message number for root
+ root.setReplyNumber(root.getReplyNumber()+1);
+ wikiMessageDao.saveOrUpdate(root);
+
+ return replyMessage;
+ }
+
+ public Attachment uploadInstructionFile(FormFile uploadFile, String fileType) throws PersistenceException{
+ if(uploadFile == null || StringUtils.isEmpty(uploadFile.getFileName()))
+ throw new WikiException("Could not find upload file: " + uploadFile);
+
+ //upload file to repository
+ NodeKey nodeKey = processFile(uploadFile,fileType);
+
+ //create new attachement
+ Attachment file = new Attachment();
+ file.setFileType(fileType);
+ file.setFileUuid(nodeKey.getUuid());
+ file.setFileVersionId(nodeKey.getVersion());
+ file.setFileName(uploadFile.getFileName());
+
+ return file;
+
+ }
+
+ /**
+ * This method deletes the content with the given uuid and
+ * versionID from the content repository
+ *
+ * @param uuid
+ * The uuid of the node to be deleted
+ * @param versionID
+ * The version_id of the node to be deleted.
+ * @throws SubmitFilesException
+ */
+ public void deleteFromRepository(Long uuid, Long versionID)
+ throws WikiException {
+ ITicket ticket = getRepositoryLoginTicket();
+ try {
+ repositoryService.deleteVersion(ticket, uuid,versionID);
+ } catch (Exception e) {
+ throw new WikiException(
+ "Exception occured while deleting files from"
+ + " the repository " + e.getMessage());
+ }
+ }
+
+
+ public Attachment uploadAttachment(FormFile uploadFile) throws PersistenceException {
+ if(uploadFile == null || StringUtils.isEmpty(uploadFile.getFileName()))
+ throw new WikiException("Could not find upload file: " + uploadFile);
+
+ NodeKey nodeKey = processFile(uploadFile,IToolContentHandler.TYPE_ONLINE);
+ Attachment file = new Attachment();
+ file.setFileType(IToolContentHandler.TYPE_ONLINE);
+ file.setFileUuid(nodeKey.getUuid());
+ file.setFileVersionId(nodeKey.getVersion());
+ file.setFileName(uploadFile.getFileName());
+
+ return file;
+ }
+ public List getTopicThread(Long rootTopicId){
+
+ List unsortedThread = wikiMessageSeqDao.getTopicThread(rootTopicId);
+ Iterator iter = unsortedThread.iterator();
+ MessageSeq msgSeq;
+ SortedMap map = new TreeMap(new TopicComparator());
+ while(iter.hasNext()){
+ msgSeq = (MessageSeq) iter.next();
+ map.put(msgSeq,msgSeq.getMessage());
+ }
+ return getSortedMessageDTO(map);
+ }
+
+
+ public List getRootTopics(Long sessionId){
+ List topicsBySession = wikiMessageDao.getRootTopics(sessionId);
+ WikiToolSession session = getSessionBySessionId(sessionId);
+ if(session == null || session.getWiki() == null){
+ log.error("Failed on getting session by given sessionID:" + sessionId);
+ throw new WikiException("Failed on getting session by given sessionID:" + sessionId);
+ }
+
+ //sorted by last post date
+ Message msg;
+ SortedMap map = new TreeMap(new DateComparator());
+ Iterator iter = topicsBySession.iterator();
+ while(iter.hasNext()){
+ msg = (Message) iter.next();
+ if(OLD_FORUM_STYLE)
+ map.put(msg.getCreated(),msg);
+ else
+ map.put(msg.getLastReplyDate(),msg);
+ }
+ return MessageDTO.getMessageDTO(new ArrayList(map.values()));
+
+ }
+
+ public int getTopicsNum(Long userID, Long sessionId) {
+ return wikiMessageDao.getTopicsNum(userID,sessionId);
+ }
+
+ public WikiUser getUserByID(Long userId) {
+ return wikiUserDao.getByUserId(userId);
+ }
+
+ public WikiUser getUserByUserAndSession(Long userId,Long sessionId) {
+ return wikiUserDao.getByUserIdAndSessionId(userId,sessionId);
+ }
+
+ public void createUser(WikiUser wikiUser) {
+ wikiUserDao.save(wikiUser);
+ }
+ public WikiToolSession getSessionBySessionId(Long sessionId) {
+ return wikiToolSessionDao.getBySessionId(sessionId);
+ }
+
+ public Long getRootTopicId(Long topicId) {
+ MessageSeq seq = wikiMessageSeqDao.getByTopicId(topicId);
+ if(seq == null ||seq.getRootMessage() == null){
+ log.error("A sequence information can not be found for topic ID:" + topicId);
+ return null;
+ }
+ return seq.getRootMessage().getUid();
+ }
+
+ public List getAuthoredTopics(Long wikiUid) {
+ List list = wikiMessageDao.getTopicsFromAuthor(wikiUid);
+
+ TreeMap map = new TreeMap(new DateComparator());
+ // get all the topics skipping ones with a tool session (we may be editing in monitor) and sort by create date
+ Iterator iter = list.iterator();
+ while(iter.hasNext()){
+ Message topic = (Message) iter.next();
+ if ( topic.getToolSession() == null )
+ map.put(topic.getCreated(),topic);
+ }
+ return MessageDTO.getMessageDTO(new ArrayList(map.values()));
+ }
+
+
+ public Long getToolDefaultContentIdBySignature(String toolSignature)
+ {
+ Long contentId = null;
+ contentId=new Long(toolService.getToolDefaultContentIdBySignature(toolSignature));
+ if (contentId == null)
+ {
+ String error="Could not retrieve default content id for this tool";
+ log.error(error);
+ throw new WikiException(error);
+ }
+ return contentId;
+ }
+
+ public List getSessionsByContentId(Long contentID) {
+ return wikiToolSessionDao.getByContentId(contentID);
+ }
+
+ public List getUsersBySessionId(Long sessionID) {
+ return wikiUserDao.getBySessionId(sessionID);
+ }
+
+ public List getMessagesByUserUid(Long userId,Long sessionId) {
+ List list = wikiMessageDao.getByUserAndSession(userId,sessionId);
+
+ return MessageDTO.getMessageDTO(list);
+ }
+
+ public WikiUser getUser(Long userUid) {
+ return wikiUserDao.getByUid(userUid);
+ }
+
+ public void releaseMarksForSession(Long sessionID) {
+ //udate release mark date for each message.
+ List list = wikiMessageDao.getBySession(sessionID);
+ Iterator iter = list.iterator();
+ while(iter.hasNext()){
+ Message msg = (Message) iter.next();
+ WikiReport report = msg.getReport();
+ if(report != null)
+ report.setDateMarksReleased(new Date());
+ wikiMessageDao.saveOrUpdate(msg);
+ }
+ //update session to set MarkRelease flag.
+ WikiToolSession session = wikiToolSessionDao.getBySessionId(sessionID);
+ session.setMarkReleased(true);
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ }
+
+ public void finishUserSession(WikiUser currentUser) {
+ currentUser.setSessionFinished(true);
+ wikiUserDao.save(currentUser);
+ }
+
+ //***************************************************************************************************************
+ // Private methods
+ //***************************************************************************************************************
+ /**
+ * @param map
+ * @return
+ */
+ private List getSortedMessageDTO(SortedMap map) {
+ Iterator iter;
+ MessageSeq msgSeq;
+ List msgDtoList = new ArrayList();
+ iter =map.entrySet().iterator();
+ while(iter.hasNext()){
+ Map.Entry entry = (Entry) iter.next();
+ msgSeq = (MessageSeq) entry.getKey();
+ MessageDTO dto = MessageDTO.getMessageDTO((Message) entry.getValue());
+ dto.setLevel(msgSeq.getMessageLevel());
+ msgDtoList.add(dto);
+ }
+ return msgDtoList;
+ }
+ /**
+ * Process an uploaded file.
+ *
+ * @param wikiForm
+ * @throws FileNotFoundException
+ * @throws IOException
+ * @throws RepositoryCheckedException
+ * @throws InvalidParameterException
+ */
+ private NodeKey processFile(FormFile file, String fileType){
+ NodeKey node = null;
+ if (file!= null && !StringUtils.isEmpty(file.getFileName())) {
+ String fileName = file.getFileName();
+ try {
+ node = getWikiToolContentHandler().uploadFile(file.getInputStream(), fileName,
+ file.getContentType(), fileType);
+ } catch (InvalidParameterException e) {
+ throw new WikiException("FileNotFoundException occured while trying to upload File" + e.getMessage());
+ } catch (FileNotFoundException e) {
+ throw new WikiException("FileNotFoundException occured while trying to upload File" + e.getMessage());
+ } catch (RepositoryCheckedException e) {
+ throw new WikiException("FileNotFoundException occured while trying to upload File" + e.getMessage());
+ } catch (IOException e) {
+ throw new WikiException("FileNotFoundException occured while trying to upload File" + e.getMessage());
+ }
+ }
+ return node;
+ }
+ /**
+ * This method verifies the credentials of the SubmitFiles Tool and gives it
+ * the Ticket to login and access the Content Repository.
+ *
+ * A valid ticket is needed in order to access the content from the
+ * repository. This method would be called evertime the tool needs to
+ * upload/download files from the content repository.
+ *
+ * @return ITicket The ticket for repostory access
+ * @throws SubmitFilesException
+ */
+ private ITicket getRepositoryLoginTicket() throws WikiException {
+ ICredentials credentials = new SimpleCredentials(
+ wikiToolContentHandler.getRepositoryUser(),
+ wikiToolContentHandler.getRepositoryId());
+ try {
+ ITicket ticket = repositoryService.login(credentials,
+ wikiToolContentHandler.getRepositoryWorkspaceName());
+ return ticket;
+ } catch (AccessDeniedException ae) {
+ throw new WikiException("Access Denied to repository."
+ + ae.getMessage());
+ } catch (WorkspaceNotFoundException we) {
+ throw new WikiException("Workspace not found."
+ + we.getMessage());
+ } catch (LoginException e) {
+ throw new WikiException("Login failed." + e.getMessage());
+ }
+ }
+ private Wiki getDefaultWiki(){
+ Long defaultWikiId = getToolDefaultContentIdBySignature(WikiConstants.TOOL_SIGNATURE);
+ Wiki defaultWiki = getWikiByContentId(defaultWikiId);
+ if(defaultWiki == null)
+ {
+ String error="Could not retrieve default content record for this tool";
+ log.error(error);
+ throw new WikiException(error);
+ }
+
+ return defaultWiki;
+
+ }
+
+ public Long createNotebookEntry(Long sessionId, Integer notebookToolType, String toolSignature, Integer userId, String entryText) {
+ return coreNotebookService.createNotebookEntry(sessionId, notebookToolType, toolSignature, userId, "", entryText);
+ }
+ public NotebookEntry getEntry(Long sessionId, Integer idType, String signature, Integer userID){
+ List list = coreNotebookService.getEntry(sessionId, idType, signature, userID);
+ if (list == null || list.isEmpty()) {
+ return null;
+ } else {
+ return list.get(0);
+ }
+ }
+
+ /**
+ * @param notebookEntry
+ */
+ public void updateEntry(NotebookEntry notebookEntry) {
+ coreNotebookService.updateEntry(notebookEntry);
+ }
+ //***************************************************************************************************************
+ // ToolContentManager and ToolSessionManager methods
+ //***************************************************************************************************************
+ public void copyToolContent(Long fromContentId, Long toContentId) throws ToolException {
+ if (toContentId == null)
+ throw new ToolException(
+ "Failed to create the WikiFiles tool seession");
+
+ Wiki fromContent = null;
+ if ( fromContentId != null ) {
+ fromContent = wikiDao.getByContentId(fromContentId);
+ }
+ if ( fromContent == null ) {
+ fromContent = getDefaultWiki();
+ }
+
+ Wiki toContent = Wiki.newInstance(fromContent,toContentId,wikiToolContentHandler);
+ wikiDao.saveOrUpdate(toContent);
+
+ //save topics in this wiki, only save the author created topic!!! and reset its reply number to zero.
+ Set topics = toContent.getMessages();
+ if(topics != null){
+ Iterator iter = topics.iterator();
+ while(iter.hasNext()){
+ Message msg = (Message) iter.next();
+ //set this message wiki Uid as toContent
+ if(!msg.getIsAuthored())
+ continue;
+ msg.setReplyNumber(0);
+ msg.setCreated(new Date());
+ msg.setUpdated(new Date());
+ msg.setLastReplyDate(new Date());
+ msg.setHideFlag(false);
+ msg.setWiki(toContent);
+ createRootTopic(toContent.getUid(),(WikiToolSession) null,msg);
+ }
+ }
+
+ }
+
+ public void setAsDefineLater(Long toolContentId, boolean value) throws DataMissingException, ToolException {
+ Wiki wiki = wikiDao.getByContentId(toolContentId);
+ if(wiki == null){
+ throw new ToolException("No found tool content by given content ID:" + toolContentId);
+ }
+ wiki.setDefineLater(value);
+ wiki.setContentInUse(false);
+ }
+
+ public void setAsRunOffline(Long toolContentId, boolean value) throws DataMissingException, ToolException {
+ Wiki wiki = wikiDao.getByContentId(toolContentId);
+ if(wiki == null){
+ throw new ToolException("No found tool content by given content ID:" + toolContentId);
+ }
+ wiki.setRunOffline(value);
+
+ }
+
+ public void removeToolContent(Long toolContentId, boolean removeSessionData) throws SessionDataExistsException, ToolException {
+ Wiki wiki = wikiDao.getByContentId(toolContentId);
+ if(removeSessionData){
+ List list = wikiToolSessionDao.getByContentId(toolContentId);
+ Iterator iter = list.iterator();
+ while(iter.hasNext()){
+ WikiToolSession session = (WikiToolSession) iter.next();
+ wikiToolSessionDao.delete(session);
+ }
+ }
+ wikiDao.delete(wiki);
+ }
+
+
+ /**
+ * 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
+ * @throws ToolException if any other error occurs
+ */
+
+ public void exportToolContent(Long toolContentId, String rootPath) throws DataMissingException, ToolException {
+ Wiki toolContentObj = wikiDao.getByContentId(toolContentId);
+ if(toolContentObj == null)
+ toolContentObj = getDefaultWiki();
+ if(toolContentObj == null)
+ throw new DataMissingException("Unable to find default content for the wiki tool");
+
+ //set ResourceToolContentHandler as null to avoid copy file node in repository again.
+ toolContentObj = Wiki.newInstance(toolContentObj,toolContentId,null);
+ toolContentObj.setToolContentHandler(null);
+ toolContentObj.setCreatedBy(null);
+ Set items = toolContentObj.getMessages();
+ Set authorItems = new HashSet();
+ for(Message item:items){
+ if(item.getIsAuthored()){
+ authorItems.add(item);
+ item.setCreatedBy(null);
+ item.setModifiedBy(null);
+ item.setToolSession(null);
+ item.setWiki(null);
+ item.setToolContentHandler(null);
+ item.setReport(null);
+ item.setReplyNumber(0);
+ item.setParent(null);
+ item.setSessionClones(null);
+ }
+ }
+ toolContentObj.setMessages(authorItems);
+ try {
+ exportContentService.registerFileClassForExport(Attachment.class.getName(),"fileUuid","fileVersionId");
+ exportContentService.exportToolContent( toolContentId, toolContentObj,wikiToolContentHandler, rootPath);
+ } catch (ExportToolContentException e) {
+ throw new ToolException(e);
+ }
+ }
+
+ /**
+ * Import the XML fragment for the tool's content, along with any files needed
+ * for the content.
+ * @throws ToolException if any other error occurs
+ */
+ public void importToolContent(Long toolContentId, Integer newUserUid, String toolContentPath ,String fromVersion,String toVersion)
+ throws ToolException {
+
+
+ try {
+ exportContentService.registerFileClassForImport(Attachment.class.getName()
+ ,"fileUuid","fileVersionId","fileName","fileType",null,null);
+
+ Object toolPOJO = exportContentService.importToolContent(toolContentPath,wikiToolContentHandler,fromVersion,toVersion);
+ if(!(toolPOJO instanceof Wiki))
+ throw new ImportToolContentException("Import Wiki tool content failed. Deserialized object is " + toolPOJO);
+ Wiki toolContentObj = (Wiki) toolPOJO;
+
+// reset it to new toolContentId
+ toolContentObj.setContentId(toolContentId);
+ WikiUser user = wikiUserDao.getByUserId(new Long(newUserUid.longValue()));
+ if(user == null){
+ user = new WikiUser();
+ UserDTO sysUser = ((User)userManagementService.findById(User.class,newUserUid)).getUserDTO();
+ user.setFirstName(sysUser.getFirstName());
+ user.setLastName(sysUser.getLastName());
+ user.setLoginName(sysUser.getLogin());
+ user.setUserId(new Long(newUserUid.longValue()));
+ this.createUser(user);
+ }
+ toolContentObj.setCreatedBy(user);
+ //save wiki first
+ wikiDao.saveOrUpdate(toolContentObj);
+
+ //save all authoring message one by one.
+ //reset all resourceItem createBy user
+ Set items = toolContentObj.getMessages();
+ for(Message item:items){
+ item.setCreatedBy(user);
+ item.setIsAuthored(true);
+ item.setWiki(toolContentObj);
+ item.setSessionClones(new HashSet());
+ createRootTopic(toolContentObj.getUid(),(WikiToolSession) null,item);
+ }
+ } catch (ImportToolContentException e) {
+ throw new ToolException(e);
+ }
+ }
+
+ /** Get the definitions for possible output for an activity, based on the toolContentId. These may be definitions that are always
+ * available for the tool (e.g. number of marks for Multiple Choice) or a custom definition created for a particular activity
+ * such as the answer to the third question contains the word Koala and hence the need for the toolContentId
+ * @return SortedMap of ToolOutputDefinitions with the key being the name of each definition
+ */
+ public SortedMap getToolOutputDefinitions(Long toolContentId) throws ToolException {
+ Wiki wiki = getWiki(toolContentId);
+ if ( wiki == null ) {
+ wiki = getDefaultWiki();
+ }
+ return getWikiOutputFactory().getToolOutputDefinitions(wiki);
+ }
+
+
+ /** @see org.lamsfoundation.lams.tool.ToolSessionManager#createToolSession(java.lang.Long, java.lang.String, java.lang.Long) */
+ public void createToolSession(Long toolSessionId, String toolSessionName, Long toolContentId) throws ToolException {
+ WikiToolSession session = new WikiToolSession();
+ session.setSessionId(toolSessionId);
+ session.setSessionName(toolSessionName);
+ Wiki wiki = wikiDao.getByContentId(toolContentId);
+ session.setWiki(wiki);
+
+// also clone author created topic from this wiki tool content!!!
+// this can avoid topic record information conflict when multiple sessions are against same tool content
+// for example, the reply number maybe various for different sessions.
+ log.debug("Clone tool content [" + wiki.getContentId() +"] topics for session [" + session.getSessionId() + "]");
+ Set contentTopics = wiki.getMessages();
+ if(contentTopics != null && contentTopics.size() > 0){
+ for(Message msg : contentTopics){
+ if(msg.getIsAuthored() && msg.getToolSession() == null){
+ Message newMsg = Message.newInstance(msg, wikiToolContentHandler);
+ msg.getSessionClones().add(newMsg);
+ createRootTopic(wiki.getContentId(), session, newMsg);
+ }
+ }
+ }
+ session.setStatus(WikiConstants.STATUS_CONTENT_COPYED);
+
+ wikiToolSessionDao.saveOrUpdate(session);
+ log.debug("tool session ["+session.getSessionId()+"] created.");
+ }
+
+ public String leaveToolSession(Long toolSessionId, Long learnerId) throws DataMissingException, ToolException {
+ if(toolSessionId == null){
+ log.error("Fail to leave tool Session based on null tool session id.");
+ throw new ToolException("Fail to remove tool Session based on null tool session id.");
+ }
+ if(learnerId == null){
+ log.error("Fail to leave tool Session based on null learner.");
+ throw new ToolException("Fail to remove tool Session based on null learner.");
+ }
+
+ WikiToolSession session = wikiToolSessionDao.getBySessionId(toolSessionId);
+ if(session != null){
+ wikiToolSessionDao.saveOrUpdate(session);
+ }else{
+ log.error("Fail to leave tool Session.Could not find submit file " +
+ "session by given session id: "+toolSessionId);
+ throw new DataMissingException("Fail to leave tool Session." +
+ "Could not find submit file session by given session id: "+toolSessionId);
+ }
+ return learnerService.completeToolSession(toolSessionId,learnerId);
+ }
+ public ToolSessionExportOutputData exportToolSession(Long toolSessionId) throws DataMissingException, ToolException {
+ return null;
+ }
+
+ public ToolSessionExportOutputData exportToolSession(List toolSessionIds) throws DataMissingException, ToolException {
+ return null;
+ }
+
+
+ public void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException {
+ wikiToolSessionDao.delete(toolSessionId);
+ }
+
+ /**
+ * Get the tool output for the given tool output names.
+ * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.util.List, java.lang.Long, java.lang.Long)
+ */
+ public SortedMap getToolOutput(List names,
+ Long toolSessionId, Long learnerId) {
+
+ return wikiOutputFactory.getToolOutput(names, this, toolSessionId, learnerId);
+
+ }
+
+ /**
+ * Get the tool output for the given tool output name.
+ * @see org.lamsfoundation.lams.tool.ToolSessionManager#getToolOutput(java.lang.String, java.lang.Long, java.lang.Long)
+ */
+ public ToolOutput getToolOutput(String name, Long toolSessionId,
+ Long learnerId) {
+ return wikiOutputFactory.getToolOutput(name, this, toolSessionId, learnerId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.tool.sbmt.service.ISubmitFilesService#getDefaultContent(java.lang.Long)
+ */
+ public Wiki getDefaultContent(Long contentID) {
+ if (contentID == null)
+ {
+ String error="Could not retrieve default content id for Wiki tool";
+ log.error(error);
+ throw new WikiException(error);
+ }
+
+ Wiki defaultContent = getDefaultWiki();
+ //get default content by given ID.
+ Wiki content = new Wiki();
+ content = Wiki.newInstance(defaultContent,contentID,wikiToolContentHandler);
+
+ Set topics = content.getMessages();
+ if(topics != null){
+ Iterator iter = topics.iterator();
+ while(iter.hasNext()){
+ Message msg = (Message) iter.next();
+ //clear message wiki so that they can be saved when persistent happens
+ msg.setWiki(null);
+ }
+ }
+
+ return content;
+ }
+ public List getAllTopicsFromSession(Long sessionID) {
+ return MessageDTO.getMessageDTO(wikiMessageDao.getBySession(sessionID));
+ }
+ /* ===============Methods implemented from ToolContentImport102Manager =============== */
+
+
+ /**
+ * Import the data for a 1.0.2 Wiki
+ */
+ public void import102ToolContent(Long toolContentId, UserDTO user, Hashtable importValues)
+ {
+ Date now = new Date();
+ Wiki toolContentObj = new Wiki();
+
+ try {
+
+ toolContentObj.setTitle((String)importValues.get(ToolContentImport102Manager.CONTENT_TITLE));
+
+ toolContentObj.setAllowAnonym(Boolean.FALSE);
+ toolContentObj.setAllowEdit(Boolean.TRUE); // this is the default value
+ toolContentObj.setAllowNewTopic(Boolean.TRUE);
+ //toolContentObj.setAllowRichEditor(Boolean.FALSE);
+ toolContentObj.setAllowUpload(Boolean.TRUE); // this is the default value
+ toolContentObj.setContentId(toolContentId);
+ toolContentObj.setContentInUse(Boolean.FALSE);
+ toolContentObj.setCreated(now);
+ toolContentObj.setDefineLater(Boolean.FALSE);
+ toolContentObj.setInstructions(WebUtil.convertNewlines((String)importValues.get(ToolContentImport102Manager.CONTENT_BODY)));
+ toolContentObj.setLimitedChar(5000); // this is the default value
+ toolContentObj.setReflectOnActivity(Boolean.FALSE);
+ toolContentObj.setReflectInstructions(null);
+
+ // lockOnFinsh = ! isReusable
+ Boolean bool = WDDXProcessor.convertToBoolean(importValues, ToolContentImport102Manager.CONTENT_REUSABLE);
+ toolContentObj.setLockWhenFinished(bool != null ? ! bool.booleanValue() : false);
+ toolContentObj.setMaximumReply(0);
+ toolContentObj.setMinimumReply(0);
+ toolContentObj.setOfflineInstructions(null);
+ toolContentObj.setOnlineInstructions(null);
+ toolContentObj.setRunOffline(Boolean.FALSE);
+ toolContentObj.setUpdated(now);
+
+ // unused entries from 1.0.2
+ // isNewTopicAllowed - not actually used in 1.0.2
+ // durationInDays - no equivalent in 2.0
+ // isPostingModerated - no equivalent in 2.0
+ // isPostingNotified - no equivalent in 2.0
+ // contentShowUser - no equivalent in 2.0
+ // isHTML - no equivalent in 2.0
+ // terminationType=moderator - no equivalent in 2.0
+
+ WikiUser wikiUser = new WikiUser();
+ wikiUser.setUserId(new Long(user.getUserID().longValue()));
+ wikiUser.setFirstName(user.getFirstName());
+ wikiUser.setLastName(user.getLastName());
+ wikiUser.setLoginName(user.getLogin());
+ createUser(wikiUser);
+ toolContentObj.setCreatedBy(wikiUser);
+
+ // leave as empty, no need to set them to anything.
+ //toolContentObj.setAttachments(attachments);
+ wikiDao.saveOrUpdate(toolContentObj);
+
+ // topics in the XML file are ordered using the "number" field, not in their order in the vector.
+ TreeMap messageMaps = new TreeMap();
+ Vector topics = (Vector) importValues.get(ToolContentImport102Manager.CONTENT_MB_TOPICS);
+ Date msgDate = null;
+ if ( topics != null ) {
+ Iterator iter = topics.iterator();
+ while ( iter.hasNext() ) {
+ Hashtable messageMap = (Hashtable) iter.next();
+ Integer order = WDDXProcessor.convertToInteger(messageMap, ToolContentImport102Manager.CONTENT_MB_TOPIC_NUMBER);
+ messageMaps.put(order, messageMap);
+ }
+
+ iter = messageMaps.values().iterator();
+ while ( iter.hasNext() ) {
+
+ Map messageMap = (Map) iter.next();
+
+ Message message = new Message();
+ message.setIsAuthored(true);
+
+ // topics are ordered by date, so I need to try to assign each entry a different date. Won't work if this is too quick.
+ if ( msgDate != null ) {
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {}
+ }
+ msgDate = new Date();
+
+ message.setCreated(msgDate);
+ message.setCreatedBy(wikiUser);
+ message.setUpdated(msgDate);
+ message.setLastReplyDate(msgDate);
+ message.setSubject((String)messageMap.get(ToolContentImport102Manager.CONTENT_TITLE));
+ message.setBody(WebUtil.convertNewlines((String)messageMap.get(ToolContentImport102Manager.CONTENT_MB_TOPIC_MESSAGE)));
+ // ignore the old subject field - it wasn't updated by the old interface.
+ message.setHideFlag(Boolean.FALSE);
+ message.setIsAnonymous(Boolean.FALSE);
+
+ createRootTopic(toolContentObj.getUid(),(WikiToolSession) null,message);
+
+ }
+ }
+
+ } catch (WDDXProcessorConversionException e) {
+ log.error("Unable to content for activity "+toolContentObj.getTitle()+"properly due to a WDDXProcessorConversionException.",e);
+ throw new ToolException("Invalid import data format for activity "+toolContentObj.getTitle()+"- WDDX caused an exception. Some data from the design will have been lost. See log for more details.");
+ }
+
+
+
+ }
+
+ /** Set the description, throws away the title value as this is not supported in 2.0 */
+ public void setReflectiveData(Long toolContentId, String title, String description)
+ throws ToolException, DataMissingException {
+
+ Wiki toolContentObj = getWikiByContentId(toolContentId);
+ if ( toolContentObj == null ) {
+ throw new DataMissingException("Unable to set reflective data titled "+title
+ +" on activity toolContentId "+toolContentId
+ +" as the tool content does not exist.");
+ }
+
+ toolContentObj.setReflectOnActivity(Boolean.TRUE);
+ toolContentObj.setReflectInstructions(description);
+ }
+
+ //***************************************************************************************************************
+ // Get / Set methods
+ //***************************************************************************************************************
+ public ILamsToolService getToolService() {
+ return toolService;
+ }
+
+ public void setToolService(ILamsToolService toolService) {
+ this.toolService = toolService;
+ }
+
+ public WikiAttachmentDao getWikiAttachmentDao() {
+ return wikiAttachmentDao;
+ }
+
+ public void setWikiAttachmentDao(WikiAttachmentDao wikiAttachmentDao) {
+ this.wikiAttachmentDao = wikiAttachmentDao;
+ }
+
+ public WikiDao getWikiDao() {
+ return wikiDao;
+ }
+
+ public void setWikiDao(WikiDao wikiDao) {
+ this.wikiDao = wikiDao;
+ }
+
+ public WikiMessageDao getWikiMessageDao() {
+ return wikiMessageDao;
+ }
+
+ public void setWikiMessageDao(WikiMessageDao wikiMessageDao) {
+ this.wikiMessageDao = wikiMessageDao;
+ }
+
+
+ public WikiMessageSeqDao getWikiMessageSeqDao() {
+ return wikiMessageSeqDao;
+ }
+
+ public void setWikiMessageSeqDao(WikiMessageSeqDao wikiMessageSeqDao) {
+ this.wikiMessageSeqDao = wikiMessageSeqDao;
+ }
+
+ public WikiToolSessionDao getWikiToolSessionDao() {
+ return wikiToolSessionDao;
+ }
+
+ public void setWikiToolSessionDao(WikiToolSessionDao wikiToolSessionDao) {
+ this.wikiToolSessionDao = wikiToolSessionDao;
+ }
+
+ public WikiUserDao getWikiUserDao() {
+ return wikiUserDao;
+ }
+
+ public void setWikiUserDao(WikiUserDao wikiUserDao) {
+ this.wikiUserDao = wikiUserDao;
+ }
+
+ public IRepositoryService getRepositoryService() {
+ return repositoryService;
+ }
+
+ public void setRepositoryService(IRepositoryService repositoryService) {
+ this.repositoryService = repositoryService;
+ }
+ public WikiToolContentHandler getWikiToolContentHandler() {
+ return wikiToolContentHandler;
+ }
+
+ public void setWikiToolContentHandler(WikiToolContentHandler toolContentHandler) {
+ this.wikiToolContentHandler = toolContentHandler;
+ }
+
+ public ILearnerService getLearnerService() {
+ return learnerService;
+ }
+
+ public void setLearnerService(ILearnerService learnerService) {
+ this.learnerService = learnerService;
+ }
+
+ public IExportToolContentService getExportContentService() {
+ return exportContentService;
+ }
+
+ public void setExportContentService(IExportToolContentService exportContentService) {
+ this.exportContentService = exportContentService;
+ }
+ public IUserManagementService getUserManagementService() {
+ return userManagementService;
+ }
+
+
+ public void setUserManagementService(IUserManagementService userManagementService) {
+ this.userManagementService = userManagementService;
+ }
+
+ public WikiReportDAO getWikiReportDAO() {
+ return wikiReportDAO;
+ }
+
+ public void setWikiReportDAO(WikiReportDAO wikiReportDAO) {
+ this.wikiReportDAO = wikiReportDAO;
+ }
+
+ public ICoreNotebookService getCoreNotebookService() {
+ return coreNotebookService;
+ }
+
+ public void setCoreNotebookService(ICoreNotebookService coreNotebookService) {
+ this.coreNotebookService = coreNotebookService;
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiServiceProxy.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiServiceProxy.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/service/WikiServiceProxy.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,53 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.service;
+
+import javax.servlet.ServletContext;
+
+import org.lamsfoundation.lams.tool.ToolSessionManager;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class WikiServiceProxy {
+ public static final IWikiService getWikiService(ServletContext servletContext){
+ return (IWikiService) getService(servletContext);
+ }
+
+ public static ToolSessionManager getToolSessionManager(ServletContext servletContext) {
+ return (ToolSessionManager) getService(servletContext);
+ }
+
+ /**
+ * @param servletContext
+ * @return
+ */
+ private static Object getService(ServletContext servletContext) {
+ WebApplicationContext context = WebApplicationContextUtils
+ .getRequiredWebApplicationContext(servletContext);
+ return context.getBean("wikiService");
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/DateComparator.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/DateComparator.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/DateComparator.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.util;
+
+import java.util.Comparator;
+import java.util.Date;
+import static org.lamsfoundation.lams.tool.wiki.util.WikiConstants.OLD_FORUM_STYLE;
+public class DateComparator implements Comparator {
+
+ public int compare(Date arg0, Date arg1) {
+ if(OLD_FORUM_STYLE)
+ return (arg0.getTime() - arg1.getTime()) > 0 ?1:-1;
+ else
+ return (arg0.getTime() - arg1.getTime()) > 0 ?-1:1;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/TopicComparator.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/TopicComparator.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/TopicComparator.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,107 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.util;
+
+import java.util.Comparator;
+
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.persistence.MessageSeq;
+import static org.lamsfoundation.lams.tool.wiki.util.WikiConstants.OLD_FORUM_STYLE;
+
+/**
+ * This class implementaion java.util.Comparator interface. It can sort meesage according to
+ * message post date and message level.
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ */
+public class TopicComparator implements Comparator {
+ private static final Logger log = Logger.getLogger(TopicComparator.class);
+
+ public int compare(MessageSeq msgSeq1, MessageSeq msgSeq2) {
+ Message msg1 = msgSeq1.getMessage();
+ Message msg2 = msgSeq2.getMessage();
+
+ short level1,level2;
+ level1 = msgSeq1.getMessageLevel();
+ level2 = msgSeq2.getMessageLevel();
+ Message parent1,parent2;
+ //choose the smaller level value
+ short lessLevel = level1>level2? level2:level1;
+ for(int compareLevel=0;compareLevel <= lessLevel;compareLevel++){
+ //init value, loop from current message
+ parent1 = msg1;
+ parent2 = msg2;
+ level1 = msgSeq1.getMessageLevel();
+ level2 = msgSeq2.getMessageLevel();
+ while(level1 > compareLevel){
+ //get parent until assigned level
+ if(parent1 == null){
+ log.error("Message "+ parent1 +" level "+ level1 +" has null parent");
+ return 0;
+ }
+ parent1 = parent1.getParent();
+ level1--;
+ }
+ while(level2 > compareLevel){
+ //get parent until assigned level
+ if(parent2 == null){
+ log.error("Message "+ parent2 +" level "+ level2 +" has null parent");
+ return 0;
+ }
+ parent2 = parent2.getParent();
+ level2--;
+ }
+ //this comparation will handle different branch node
+ if(parent1 != parent2){
+ //compare last modified date, the latest is at beginning
+ if(OLD_FORUM_STYLE)
+ return parent1.getUpdated().before(parent2.getUpdated())?-1:1;
+ else
+ return parent1.getUpdated().before(parent2.getUpdated())?1:-1;
+ }
+ //this comparation will handle same branch node
+ //the direct parent level, their parent(or themselves) are still equal
+ if(compareLevel==lessLevel){
+ if(msgSeq1.getMessageLevel() != msgSeq2.getMessageLevel())
+ return msgSeq1.getMessageLevel() -msgSeq2.getMessageLevel();
+ else{
+ if(OLD_FORUM_STYLE)
+ return msg1.getUpdated().before(msg2.getUpdated())?-1:1;
+ else
+ return msg1.getUpdated().before(msg2.getUpdated())?1:-1;
+ }
+ }
+
+ }
+ if(OLD_FORUM_STYLE)
+ return msg1.getUpdated().before(msg2.getUpdated())?-1:1;
+ else
+ return msg1.getUpdated().before(msg2.getUpdated())?1:-1;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiConstants.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiConstants.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiConstants.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,125 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.util;
+
+/**
+ * User: conradb
+ * Date: 14/06/2005
+ * Time: 10:33:00
+ */
+public interface WikiConstants {
+ public static final String TOOL_SIGNATURE = "lawiki10";
+ public static final String TOOL_CONTENT_HANDLER_NAME = "wikiToolContentHandler";
+
+
+ //See LDEV652
+ // For old style (Fiona's description): The oldest topic is at the top, does not depends the reply date etc.
+ // For new style (Ernie's early desc): Most current popular wiki used style: latest topics
+ // should be at the top, reply date will descide the order etc.
+ public static final boolean OLD_FORUM_STYLE = true;
+
+ public static final int STATUS_CONTENT_COPYED = 1;
+ public static final int SESSION_STATUS_FINISHED = 1;
+
+ public final static int MAX_FILE_SIZE = 250 * 1000;
+ public final static String FORUM_SERVICE = "wikiService";
+
+ public final static String CONTENT_HANDLER = "toolContentHandler";
+
+ public static final String AUTHORING_DTO = "authoring";
+ public static final String AUTHORING_TOPICS_LIST = "topicList";
+ public static final String AUTHORING_TOPICS_INDEX = "topicIndex";
+ public static final String AUTHORING_TOPIC_THREAD = "topicThread";
+ public static final String AUTHORING_TOPIC = "topic";
+
+ public static final String DEFAULT_TITLE = "Wiki";
+ //TODO:hard code!!! need to read from config
+ public static final String TOOL_URL_BASE = "/lams/tool/lawiki10/";
+ public static final String FORUM_ID = "wiki_id";
+
+ public static final String ATTR_ALLOW_EDIT = "allowEdit";
+ public static final String ATTR_ALLOW_UPLOAD = "allowUpload";
+ public static final String ATTR_ALLOW_NEW_TOPICS = "allowNewTopics";
+ public static final String ATTR_ALLOW_RICH_EDITOR = "allowRichEditor";
+ public static final String ATTR_LIMITED_CHARS = "limitedChars";
+
+ public static final String ONLINE_ATTACHMENT = "online_att";
+ public static final String OFFLINE_ATTACHMENT = "offline_att";
+
+ public static final String ATTACHMENT_LIST = "attachmentList";
+ public static final String DELETED_ATTACHMENT_LIST = "deletedAttachmentList";
+
+ public static final String TOPIC_DELETED_ATTACHMENT_LIST = "topicDeletedAttachmentList";
+
+ public static final String DELETED_AUTHORING_TOPICS_LIST = "deletedAuthoringTopicList";
+
+ public static final String USER_UID = "userID";
+
+ public static final String ATTR_FINISHED_LOCK = "finishedLock";
+
+ public static final String ATTR_USER_FINISHED = "userFinished";
+
+ // used in monitoring
+ public static final String TITLE = "title";
+ public static final String INSTRUCTIONS = "instructions";
+ public static final String PAGE_EDITABLE = "isPageEditable";
+
+ public static final String ATTR_ROOT_TOPIC_UID = "rootUid";
+
+ public static final String ATTR_FORUM_TITLE = "title";
+ public static final String ATTR_FORUM_INSTRCUTION = "instruction";
+
+ public static final String ATTR_TOOL_CONTENT_TOPICS = "ToolContentTopicList";
+ public static final String ATTR_TOPIC = "topic";
+ public static final String ATTR_USER= "user";
+ public static final String ATTR_USER_UID= "userUid";
+ public static final String ATTR_REPORT = "report";
+ public static final String ATTR_FILE_TYPE_FLAG = "fileTypeFlag";
+
+ public static final String PARAM_UPDATE_MODE = "updateMode";
+
+ public static final String ATTR_NO_MORE_POSTS = "noMorePosts";
+
+ public static final String ATTR_SESSION_MAP_ID = "sessionMapID";
+
+ public static final String ATTR_PARENT_TOPIC_ID = "parentID";
+
+ // used when replying message LDEV-1305
+ public static final String ATTR_ORIGINAL_MESSAGE = "originalMessage";
+
+ public static final String ATTR_TOPIC_ID = "topicID";
+ public static final String ATTR_REFLECTION_ON = "reflectOn";
+ public static final String ATTR_REFLECTION_INSTRUCTION = "reflectInstructions";
+ public static final String ATTR_REFLECTION_ENTRY = "reflectEntry";
+
+ public static final String MARK_UPDATE_FROM_SESSION = "listAllMarks";
+ public static final String MARK_UPDATE_FROM_USER = "listMarks";
+ public static final String MARK_UPDATE_FROM_FORUM = "viewWiki";
+
+
+
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiToolContentHandler.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiToolContentHandler.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiToolContentHandler.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,69 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.util;
+
+import org.lamsfoundation.lams.contentrepository.client.ToolContentHandler;
+
+/**
+ * Simple client for accessing the content repository.
+ *
+ * @author Fiona Malikoff
+ */
+public class WikiToolContentHandler extends ToolContentHandler {
+
+ private static String repositoryWorkspaceName = "wikiworkspace";
+ private static String repositoryUser = "wiki";
+ private static char[] repositoryId = {'l','a','m','s','-','f','o','r','u','m'};
+
+ /**
+ *
+ */
+ public WikiToolContentHandler() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryWorkspaceName()
+ */
+ public String getRepositoryWorkspaceName() {
+ return repositoryWorkspaceName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryUser()
+ */
+ public String getRepositoryUser() {
+ return repositoryUser;
+ }
+
+ /* (non-Javadoc)
+ * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryId()
+ */
+ public char[] getRepositoryId() {
+ return repositoryId;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiWebUtils.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiWebUtils.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/util/WikiWebUtils.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,76 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.util;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang.StringUtils;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiException;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+
+
+/**
+ * Contains helper methods used by the Action Servlets
+ *
+ * @author Anthony Sukkar
+ *
+ */
+public class WikiWebUtils {
+
+ public static boolean isWikiEditable(Wiki wiki) {
+ if ( (wiki.isDefineLater() == true) && (wiki.isContentInUse()==true) )
+ {
+ throw new WikiException("An exception has occurred: There is a bug in this tool, conflicting flags are set");
+ //return false;
+ }
+ else if ( (wiki.isDefineLater() == true) && (wiki.isContentInUse() == false))
+ return true;
+ else if ( (wiki.isDefineLater() == false) && (wiki.isContentInUse() == false))
+ return true;
+ else // (content.isContentInUse()==true && content.isDefineLater() == false)
+ return false;
+ }
+
+ /**
+ * Get ToolAccessMode from HttpRequest parameters. Default value is AUTHOR mode.
+ * @param request
+ * @return
+ */
+ public static ToolAccessMode getAccessMode(HttpServletRequest request) {
+ ToolAccessMode mode = null;
+ String modeStr = request.getParameter(AttributeNames.ATTR_MODE);
+ if(StringUtils.equalsIgnoreCase(modeStr,ToolAccessMode.TEACHER.toString()))
+ mode = ToolAccessMode.TEACHER;
+ else if (StringUtils.equalsIgnoreCase(modeStr,ToolAccessMode.AUTHOR.toString()))
+ mode = ToolAccessMode.AUTHOR;
+ else if (StringUtils.equalsIgnoreCase(modeStr,ToolAccessMode.LEARNER.toString()))
+ mode = ToolAccessMode.LEARNER;
+
+ return mode;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/AuthoringAction.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/AuthoringAction.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/AuthoringAction.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,959 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.web.actions;
+
+import static org.lamsfoundation.lams.tool.wiki.util.WikiConstants.OLD_FORUM_STYLE;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.Action;
+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.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.authoring.web.AuthoringConstants;
+import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.persistence.PersistenceException;
+import org.lamsfoundation.lams.tool.wiki.service.IWikiService;
+import org.lamsfoundation.lams.tool.wiki.util.DateComparator;
+import org.lamsfoundation.lams.tool.wiki.util.WikiConstants;
+import org.lamsfoundation.lams.tool.wiki.util.WikiWebUtils;
+import org.lamsfoundation.lams.tool.wiki.web.forms.WikiForm;
+import org.lamsfoundation.lams.tool.wiki.web.forms.MessageForm;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.FileValidatorUtil;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.lamsfoundation.lams.web.util.SessionMap;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * @author Steve.Ni
+ * @version $Revision$
+ */
+public class AuthoringAction extends Action {
+ private static Logger log = Logger.getLogger(AuthoringAction.class);
+ private IWikiService wikiService;
+
+ public ActionForward execute(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, PersistenceException {
+
+ String param = mapping.getParameter();
+ //-----------------------Wiki Author function ---------------------------
+ if (param.equals("initPage")) {
+ request.setAttribute(AttributeNames.ATTR_MODE,ToolAccessMode.AUTHOR);
+ return initPage(mapping, form, request, response);
+ }
+
+ // ***************** Monitoring define later screen ********************
+ if (param.equals("defineLater")){
+ //update define later flag to true
+ request.setAttribute(AttributeNames.ATTR_MODE,ToolAccessMode.TEACHER);
+ wikiService = getWikiManager();
+ Long contentId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+ Wiki wiki = wikiService.getWikiByContentId(contentId);
+
+ boolean isWikiEditable = WikiWebUtils.isWikiEditable(wiki);
+ if(!isWikiEditable){
+ request.setAttribute(WikiConstants.PAGE_EDITABLE, new Boolean(isWikiEditable));
+ return mapping.findForward("forbidden");
+ }
+
+ if(!wiki.isContentInUse()){
+ wiki.setDefineLater(true);
+ wikiService.updateWiki(wiki);
+ }
+
+ return initPage(mapping, form, request, response);
+ }
+ if (param.equals("updateContent")) {
+ return updateContent(mapping, form, request, response);
+ }
+ if (param.equals("uploadOnlineFile")) {
+ return uploadOnline(mapping, form, request, response);
+ }
+ if (param.equals("uploadOfflineFile")) {
+ return uploadOffline(mapping, form, request, response);
+ }
+ if (param.equals("deleteOnlineFile")) {
+ return deleteOnlineFile(mapping, form, request, response);
+ }
+ if (param.equals("deleteOfflineFile")) {
+ return deleteOfflineFile(mapping, form, request, response);
+ }
+ //-----------------------Topic function ---------------------------
+ if (param.equals("newTopic")) {
+ return newTopic(mapping, form, request, response);
+ }
+ if (param.equals("createTopic")) {
+ return createTopic(mapping, form, request, response);
+ }
+ if (param.equals("editTopic")) {
+ return editTopic(mapping, form, request, response);
+ }
+ if (param.equals("updateTopic")) {
+ return updateTopic(mapping, form, request, response);
+ }
+ if (param.equals("viewTopic")) {
+ return viewTopic(mapping, form, request, response);
+ }
+ if (param.equals("deleteTopic")) {
+ return deleteTopic(mapping, form, request, response);
+ }
+ if (param.equals("deleteAttachment")) {
+ return deleteAttachment(mapping, form, request, response);
+ }
+ return mapping.findForward("error");
+ }
+ //******************************************************************************************************************
+ // Wiki Author functions
+ //******************************************************************************************************************
+
+ /**
+ * This page will display initial submit tool content. Or just a blank page if the toolContentID does not
+ * exist before.
+ *
+ * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
+ * org.apache.struts.action.ActionForm,
+ * javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected ActionForward initPage(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ //initial Session Map
+ SessionMap sessionMap = new SessionMap();
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+
+ Long contentId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+ String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ WikiForm wikiForm = (WikiForm)form;
+ wikiForm.setSessionMapID(sessionMap.getSessionID());
+ wikiForm.setContentFolderID(contentFolderID);
+ sessionMap.put(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID);
+
+ //get back the topic list and display them on page
+ wikiService = getWikiManager();
+
+ List topics = null;
+ Wiki wiki = null;
+ try {
+ wiki = wikiService.getWikiByContentId(contentId);
+ //if wiki does not exist, try to use default content instead.
+ if(wiki == null){
+ wiki = wikiService.getDefaultContent(contentId);
+ if(wiki.getMessages() != null){
+ TreeMap map = new TreeMap(new DateComparator());
+ //sorted by create date
+ Iterator iter = wiki.getMessages().iterator();
+ while(iter.hasNext()){
+ Message topic = (Message) iter.next();
+ //contentFolderID != -1 means it is sysadmin: LDEV-906
+ if(topic.getCreatedBy() == null && !StringUtils.equals(contentFolderID,"-1")){
+ //get login user (author)
+ HttpSession ss = SessionManager.getSession();
+ //get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ WikiUser fuser = new WikiUser(user,null);
+ topic.setCreatedBy(fuser);
+ }
+ map.put(topic.getCreated(),topic);
+ }
+ topics = MessageDTO.getMessageDTO(new ArrayList(map.values()));
+ }else
+ topics = null;
+ }else{
+ topics = wikiService.getAuthoredTopics(wiki.getUid());
+ //failure tolerance: if current contentID is defaultID, the createBy will be null.
+ //contentFolderID != -1 means it is sysadmin: LDEV-906
+ if(!StringUtils.equals(contentFolderID,"-1"))
+ for (MessageDTO messageDTO : topics) {
+ if(StringUtils.isBlank(messageDTO.getAuthor())){
+ //get login user (author)
+ HttpSession ss = SessionManager.getSession();
+ //get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ WikiUser fuser = new WikiUser(user,null);
+ messageDTO.setAuthor(fuser.getFirstName()+" "+fuser.getLastName());
+ }
+ }
+ }
+ //initialize attachmentList
+ List attachmentList = getAttachmentList(sessionMap);
+ attachmentList.addAll(wiki.getAttachments());
+
+ //tear down PO to normal object using clone() method
+ wikiForm.setWiki((Wiki) wiki.clone());
+ } catch (Exception e) {
+ log.error(e);
+ return mapping.findForward("error");
+ }
+
+ //set back STRUTS component value
+ //init it to avoid null exception in following handling
+ if(topics == null)
+ topics = new ArrayList();
+
+ sessionMap.put(WikiConstants.AUTHORING_TOPICS_LIST, topics);
+ return mapping.findForward("success");
+ }
+ /**
+ * Update all content for wiki. These contents contain
+ *
+ *
Wiki authoring infomation, e.g. online/offline instruction, title, advacnce options, etc.
+ *
Uploaded offline/online instruction files
+ *
Topics author created
+ *
Topics' attachment file
+ *
Author user information
+ *
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward updateContent(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+
+ ToolAccessMode mode = getAccessMode(request);
+ WikiForm wikiForm = (WikiForm)(form);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(wikiForm.getSessionMapID());
+ //validation
+ ActionMessages errors = validate(wikiForm, mapping, request);
+ if(!errors.isEmpty()){
+ saveErrors(request, errors);
+ if(mode.isAuthor())
+ return mapping.findForward("author");
+ else
+ return mapping.findForward("monitor");
+ }
+
+ Wiki wiki = wikiForm.getWiki();
+ //get back tool content ID
+ wiki.setContentId(wikiForm.getToolContentID());
+ try {
+ wikiService = getWikiManager();
+
+ //*******************************Handle user*******************
+ String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ WikiUser wikiUser = null;
+ //check whether it is sysadmin:LDEV-906
+ if(!StringUtils.equals(contentFolderID,"-1" )){
+ //try to get form system session
+ HttpSession ss = SessionManager.getSession();
+ //get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ wikiUser = wikiService.getUserByID(new Long(user.getUserID().intValue()));
+ if(wikiUser == null){
+ wikiUser = new WikiUser(user,null);
+ wikiService.createUser(wikiUser);
+ }
+ }
+ //**********************************Get Wiki PO*********************
+ Wiki wikiPO = wikiService.getWikiByContentId(wikiForm.getToolContentID());
+ if(wikiPO == null){
+ //new Wiki, create it.
+ wikiPO = wiki;
+ wikiPO.setContentId(wikiForm.getToolContentID());
+ }else{
+ if(mode.isAuthor()){
+ Long uid = wikiPO.getUid();
+ PropertyUtils.copyProperties(wikiPO,wiki);
+ //get back UID
+ wikiPO.setUid(uid);
+ }else{
+// if it is Teacher, then just update basic tab content (definelater)
+ wikiPO.setInstructions(wiki.getInstructions());
+ wikiPO.setTitle(wiki.getTitle());
+// change define later status
+ wikiPO.setDefineLater(false);
+ }
+ }
+ wikiPO.setCreatedBy(wikiUser);
+
+ //**********************************Handle Attachement*********************
+ //merge attachment info
+ Set attPOSet = wikiPO.getAttachments();
+ if(attPOSet == null)
+ attPOSet = new HashSet();
+ List attachmentList = getAttachmentList(sessionMap);
+ List deleteAttachmentList = getDeletedAttachmentList(sessionMap);
+ Iterator iter = attachmentList.iterator();
+ while(iter.hasNext()){
+ Attachment newAtt = (Attachment) iter.next();
+ attPOSet.add(newAtt);
+ }
+ attachmentList.clear();
+
+ iter = deleteAttachmentList.iterator();
+ while(iter.hasNext()){
+ Attachment delAtt = (Attachment) iter.next();
+ iter.remove();
+ //it is an existed att, then delete it from current attachmentPO
+ if(delAtt.getUid() != null){
+ Iterator attIter = attPOSet.iterator();
+ while(attIter.hasNext()){
+ Attachment att = (Attachment) attIter.next();
+ if(delAtt.getUid().equals(att.getUid())){
+ attIter.remove();
+ break;
+ }
+ }
+ wikiService.deleteWikiAttachment(delAtt.getUid());
+ }//end remove from persist value
+ }
+
+ //copy back
+ wikiPO.setAttachments(attPOSet);
+ wiki = wikiService.updateWiki(wikiPO);
+
+ //********************************Handle topic*******************
+ //delete message attachment
+ List topicDeleteAttachmentList = getTopicDeletedAttachmentList(sessionMap);
+ iter = topicDeleteAttachmentList.iterator();
+ while(iter.hasNext()){
+ Attachment delAtt = (Attachment) iter.next();
+ iter.remove();
+ }
+
+ //Handle message
+ List topics = getTopicList(sessionMap);
+ iter = topics.iterator();
+ while(iter.hasNext()){
+ MessageDTO dto = (MessageDTO) iter.next();
+ if(dto.getMessage() != null){
+ //This flushs user UID info to message if this user is a new user.
+ dto.getMessage().setCreatedBy(wikiUser);
+ dto.getMessage().setModifiedBy(wikiUser);
+ wikiService.createRootTopic(wiki.getUid(),null,dto.getMessage());
+ }
+ }
+ //delete them from database.
+ List delTopics = getDeletedTopicList(sessionMap);
+ iter = delTopics.iterator();
+ while(iter.hasNext()){
+ MessageDTO dto = (MessageDTO) iter.next();
+ iter.remove();
+ if(dto.getMessage() != null && dto.getMessage().getUid() != null)
+ wikiService.deleteTopic(dto.getMessage().getUid());
+ }
+
+ //initialize attachmentList again
+ attachmentList = getAttachmentList(sessionMap);
+ attachmentList.addAll(wiki.getAttachments());
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+
+ request.setAttribute(AuthoringConstants.LAMS_AUTHORING_SUCCESS_FLAG,Boolean.TRUE);
+ if(mode.isAuthor())
+ return mapping.findForward("author");
+ else
+ return mapping.findForward("monitor");
+ }
+
+ /**
+ * Handle upload online instruction files request.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward uploadOnline(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return uploadFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request);
+ }
+ /**
+ * Handle upload offline instruction files request.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward uploadOffline(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return uploadFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request);
+ }
+ /**
+ * Common method to upload online or offline instruction files request.
+ * @param mapping
+ * @param form
+ * @param type
+ * @param request
+ * @return
+ */
+ private ActionForward uploadFile(ActionMapping mapping, ActionForm form,
+ String type,HttpServletRequest request) {
+
+ WikiForm wikiForm = (WikiForm) form;
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(wikiForm.getSessionMapID());
+
+ FormFile file;
+ if(StringUtils.equals(IToolContentHandler.TYPE_OFFLINE,type))
+ file = (FormFile) wikiForm.getOfflineFile();
+ else
+ file = (FormFile) wikiForm.getOnlineFile();
+
+ if(file == null || StringUtils.isBlank(file.getFileName()))
+ return mapping.findForward("success");
+
+ ActionMessages errors = new ActionMessages();
+ FileValidatorUtil.validateFileSize(file, true, errors );
+ if(!errors.isEmpty()){
+ this.saveErrors(request, errors);
+ return mapping.findForward("success");
+ }
+
+ wikiService = getWikiManager();
+ //upload to repository
+ Attachment att = wikiService.uploadInstructionFile(file, type);
+
+ //handle session value
+ List attachmentList = getAttachmentList(sessionMap);
+ List deleteAttachmentList = getDeletedAttachmentList(sessionMap);
+ //first check exist attachment and delete old one (if exist) to deletedAttachmentList
+ Iterator iter = attachmentList.iterator();
+ Attachment existAtt;
+ while(iter.hasNext()){
+ existAtt = (Attachment) iter.next();
+ if(StringUtils.equals(existAtt.getFileName(),att.getFileName())){
+ //if there is same name attachment, delete old one
+ deleteAttachmentList.add(existAtt);
+ iter.remove();
+ break;
+ }
+ }
+ //add to attachmentList
+ attachmentList.add(att);
+
+ return mapping.findForward("success");
+
+ }
+
+
+ /**
+ * Delete offline instruction file from current Wiki authoring page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward deleteOfflineFile(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return deleteFile(mapping, form,request, response, IToolContentHandler.TYPE_OFFLINE);
+ }
+ /**
+ * Delete online instruction file from current Wiki authoring page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward deleteOnlineFile(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ return deleteFile(mapping, form,request, response, IToolContentHandler.TYPE_ONLINE);
+ }
+
+ /**
+ * @param request
+ * @param response
+ * @param form
+ * @param type
+ * @return
+ */
+ private ActionForward deleteFile(ActionMapping mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response, String type){
+ Long versionID = new Long(WebUtil.readLongParam(request,"versionID"));
+ Long uuID = new Long(WebUtil.readLongParam(request,"uuID"));
+ //get sessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ //handle session value
+ List attachmentList = getAttachmentList(sessionMap);
+ List deleteAttachmentList = getDeletedAttachmentList(sessionMap);
+ //first check exist attachment and delete old one (if exist) to deletedAttachmentList
+ Iterator iter = attachmentList.iterator();
+ Attachment existAtt;
+ while(iter.hasNext()){
+ existAtt = (Attachment) iter.next();
+ if(existAtt.getFileUuid().equals(uuID) && existAtt.getFileVersionId().equals(versionID)){
+ //if there is same name attachment, delete old one
+ deleteAttachmentList.add(existAtt);
+ iter.remove();
+ }
+
+ }
+
+ request.setAttribute(WikiConstants.ATTR_FILE_TYPE_FLAG, type);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMapID);
+ return mapping.findForward("success");
+ }
+
+ //******************************************************************************************************************
+ // Topic functions
+ //******************************************************************************************************************
+ /**
+ * Display emtpy topic page for user input topic information. This page will contain all topics list which
+ * this author posted before.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward newTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID );
+ ((MessageForm)form).setSessionMapID(sessionMapID);
+
+ return mapping.findForward("success");
+ }
+ /**
+ * Create a topic in memory. This topic will be saved when user save entire authoring page.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ * @throws PersistenceException
+ */
+ public ActionForward createTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException, PersistenceException {
+ MessageForm messageForm = (MessageForm) form;
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(messageForm.getSessionMapID());
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, messageForm.getSessionMapID());
+
+ List topics = getTopicList(sessionMap);
+ //get login user (author)
+ HttpSession ss = SessionManager.getSession();
+ //get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+
+ //get message info from web page
+ Message message = messageForm.getMessage();
+ //init some basic variables for first time create
+ message.setIsAuthored(true);
+ message.setCreated(new Date());
+ message.setUpdated(new Date());
+ message.setLastReplyDate(new Date());
+
+ //check whether this user exist or not
+ WikiUser wikiUser = wikiService.getUserByID(new Long(user.getUserID().intValue()));
+ String contentFolderID = (String) sessionMap.get(AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ //check whether it is sysadmin:LDEV-906
+ if(wikiUser == null && !StringUtils.equals(contentFolderID,"-1" )){
+ //if user not exist, create new one in database
+ wikiUser = new WikiUser(user,null);
+ }
+ message.setCreatedBy(wikiUser);
+ //same person with create at first time
+ message.setModifiedBy(wikiUser);
+
+ //set attachment of this topic
+ Set attSet = null;
+ if(messageForm.getAttachmentFile() != null
+ && !StringUtils.isEmpty(messageForm.getAttachmentFile().getFileName())){
+ wikiService = getWikiManager();
+ Attachment att = wikiService.uploadAttachment(messageForm.getAttachmentFile());
+ //only allow one attachment, so replace whatever
+ attSet = new HashSet();
+ attSet.add(att);
+ }
+ message.setAttachments(attSet);
+
+ //save the new message into HttpSession
+ if(OLD_FORUM_STYLE)
+ topics.add(MessageDTO.getMessageDTO(message));
+ else
+ topics.add(0,MessageDTO.getMessageDTO(message));
+
+
+ return mapping.findForward("success");
+ }
+ /**
+ * Diplay a special topic information. Only display author created root message content, even this topic already
+ * has some reply messages from learner in some cases.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws PersistenceException {
+
+ //get SessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID );
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMapID);
+
+ List topics = getTopicList(sessionMap);
+ String topicIndex = (String) request.getParameter(WikiConstants.AUTHORING_TOPICS_INDEX);
+ int topicIdx = NumberUtils.stringToInt(topicIndex,-1);
+
+ //if topicIndex is empty, try to get it from Request Attribute again.
+ //This may be caused by reresh this page, back from edit page etc.
+ if(topicIdx == -1){
+ topicIndex = (String) request.getAttribute(WikiConstants.AUTHORING_TOPICS_INDEX);
+ topicIdx = NumberUtils.stringToInt(topicIndex,-1);
+ }
+
+ if(topicIdx != -1){
+ MessageDTO topic = (MessageDTO) topics.get(topicIdx);
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_INDEX,topicIndex);
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC,topic);
+ }
+
+ return mapping.findForward("success");
+
+ }
+ /**
+ * Delete a topic form current topic list. But database record will be deleted only when user save whole authoring
+ * page.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward deleteTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws PersistenceException {
+ //get SessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID );
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID,sessionMapID);
+ List topics = getTopicList(sessionMap);
+ String topicIndex = (String) request.getParameter(WikiConstants.AUTHORING_TOPICS_INDEX);
+ int topicIdx = NumberUtils.stringToInt(topicIndex,-1);
+
+ if(topicIdx != -1){
+ Object obj = topics.remove(topicIdx);
+ List delList = getDeletedTopicList(sessionMap);
+ delList.add(obj);
+ }
+
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Display a HTML FORM which contains subject, body and attachment information from a special topic. This page
+ * is ready for user update this topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward editTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws PersistenceException {
+
+// get SessionMAP
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID );
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ MessageForm msgForm = (MessageForm)form;
+ msgForm.setSessionMapID(sessionMapID);
+
+ List topics = getTopicList(sessionMap);
+ String topicIndex = (String) request.getParameter(WikiConstants.AUTHORING_TOPICS_INDEX);
+ int topicIdx = NumberUtils.stringToInt(topicIndex,-1);
+ if(topicIdx != -1){
+ MessageDTO topic = (MessageDTO) topics.get(topicIdx);
+ if (topic != null) {
+ //check whehter the edit topic and the current user are same person, if not, forbidden to edit topic
+ if(topic.getMessage() != null && topic.getMessage().getCreatedBy() != null){
+ //get login user (author)
+ HttpSession ss = SessionManager.getSession();
+ //get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ Long topicAuthorId = topic.getMessage().getCreatedBy().getUserId();
+ if(!(new Long(user.getUserID().intValue()).equals(topicAuthorId)))
+ return mapping.findForward("forbiden");
+ }
+ //update message to HTML Form to echo back to web page: for subject, body display
+ msgForm.setMessage(topic.getMessage());
+ }
+ //echo back to web page: for attachment display
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC,topic);
+ }
+
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_INDEX,topicIndex);
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Submit user updated inforamion in a topic to memory. This update will be submit to database only when user
+ * save whole authoring page.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward updateTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) throws PersistenceException {
+ MessageForm messageForm = (MessageForm) form;
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(messageForm.getSessionMapID());
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, messageForm.getSessionMapID());
+
+ //get value from HttpSession
+ List topics = getTopicList(sessionMap);
+ //get param from HttpServletRequest
+ String topicIndex = (String) request.getParameter(WikiConstants.AUTHORING_TOPICS_INDEX);
+ int topicIdx = NumberUtils.stringToInt(topicIndex,-1);
+
+ if(topicIdx != -1){
+ Message message = messageForm.getMessage();
+
+ MessageDTO newMsg = (MessageDTO) topics.get(topicIdx);
+ if(newMsg.getMessage()== null)
+ newMsg.setMessage(new Message());
+
+ newMsg.getMessage().setSubject(message.getSubject());
+ newMsg.getMessage().setBody(message.getBody());
+ newMsg.getMessage().setUpdated(new Date());
+ //update attachment
+ if(messageForm.getAttachmentFile() != null
+ && !StringUtils.isEmpty(messageForm.getAttachmentFile().getFileName())){
+ wikiService = getWikiManager();
+ Attachment att = wikiService.uploadAttachment(messageForm.getAttachmentFile());
+ //only allow one attachment, so replace whatever
+ Set attSet = attSet = new HashSet();
+ attSet.add(att);
+ newMsg.setHasAttachment(true);
+ newMsg.getMessage().setAttachments(attSet);
+ }else if(!messageForm.isHasAttachment()){
+ Set att = newMsg.getMessage().getAttachments();
+ if(att != null && att.size() > 0){
+ List delTopicAtt = getTopicDeletedAttachmentList(sessionMap);
+ delTopicAtt.add(att.iterator().next());
+ }
+ newMsg.setHasAttachment(false);
+ newMsg.getMessage().setAttachments(null);
+ }
+ }
+
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_INDEX,topicIndex);
+ return mapping.findForward("success");
+ }
+ /**
+ * Remove message attachment.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
+ request.setAttribute("itemAttachment", null);
+ return mapping.findForward("success");
+ }
+
+ //******************************************************************************************************************
+ // Private method for internal functions
+ //******************************************************************************************************************
+ private IWikiService getWikiManager() {
+ if ( wikiService == null ) {
+ WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
+ wikiService = (IWikiService) wac.getBean(WikiConstants.FORUM_SERVICE);
+ }
+ return wikiService;
+ }
+ /**
+ * @param request
+ * @return
+ */
+ private List getAttachmentList(SessionMap sessionMap) {
+ return getListFromSession(sessionMap,WikiConstants.ATTACHMENT_LIST);
+ }
+ /**
+ * @param request
+ * @return
+ */
+ private List getDeletedAttachmentList(SessionMap sessionMap) {
+ return getListFromSession(sessionMap,WikiConstants.DELETED_ATTACHMENT_LIST);
+ }
+ /**
+ * @param request
+ * @return
+ */
+ private List getTopicList(SessionMap sessionMap) {
+ return getListFromSession(sessionMap,WikiConstants.AUTHORING_TOPICS_LIST);
+ }
+ /**
+ * @param request
+ * @return
+ */
+ private List getTopicDeletedAttachmentList(SessionMap sessionMap) {
+ return getListFromSession(sessionMap,WikiConstants.DELETED_ATTACHMENT_LIST);
+ }
+ /**
+ * @param request
+ * @return
+ */
+ private List getDeletedTopicList(SessionMap sessionMap) {
+ return getListFromSession(sessionMap,WikiConstants.DELETED_AUTHORING_TOPICS_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;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Wiki validation method from STRUCT interface.
+ *
+ */
+ public ActionMessages validate( WikiForm form,ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
+ ActionMessages errors = new ActionMessages();
+
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(form.getSessionMapID());
+ ActionMessage ae;
+ try {
+ String modeStr = request.getParameter(AttributeNames.ATTR_MODE);
+// if (StringUtils.isBlank(form.getWiki().getTitle())) {
+// ActionMessage error = new ActionMessage("error.title.empty");
+// errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+// }
+ boolean allowNewTopic = form.getWiki().isAllowNewTopic();
+// define it later mode(TEACHER): need read out AllowNewTopic flag rather than get from HTML form
+ //becuase defineLater does not include this field
+ if(StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())){
+ wikiService = getWikiManager();
+ Wiki wikiPO = wikiService.getWikiByContentId(form.getToolContentID());
+ if(wikiPO != null)
+ allowNewTopic = wikiPO.isAllowNewTopic();
+ else{
+ //failure tolerance
+ log.error("ERROR: Can not found Wiki by toolContentID:"+ form.getToolContentID());
+ allowNewTopic = true;
+ }
+ }
+ if(!allowNewTopic){
+ List topics = getTopicList(sessionMap);
+ if(topics.size() == 0){
+ ActionMessage error = new ActionMessage("error.must.have.topic");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ }
+ }
+ //define it later mode(TEACHER) skip below validation.
+ if(StringUtils.equals(modeStr, ToolAccessMode.TEACHER.toString())){
+ return errors;
+ }
+ /*if(!form.getWiki().isAllowRichEditor() && form.getWiki().isLimitedInput()){
+ if(form.getWiki().getLimitedChar() <=0){
+ ActionMessage error = new ActionMessage("error.limit.char.less.zero");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ }
+ }*/
+ if(!form.getWiki().isAllowNewTopic()){
+ if(form.getWiki().getMaximumReply() !=0
+ && (form.getWiki().getMaximumReply() < form.getWiki().getMinimumReply())){
+ ActionMessage error = new ActionMessage("error.min.less.max");
+ errors.add(ActionMessages.GLOBAL_MESSAGE, error);
+ }
+ }
+
+ } catch (Exception e) {
+ log.error(e.toString());
+ }
+ return errors;
+ }
+ private float convertToMeg( int numBytes ) {
+ return numBytes != 0 ? numBytes / 1024 / 1024 : 0;
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ClearSessionAction.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ClearSessionAction.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ClearSessionAction.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $Id$ */
+package org.lamsfoundation.lams.tool.wiki.web.actions;
+
+import javax.servlet.http.HttpSession;
+
+import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+
+/**
+ * This class give a chance to clear HttpSession when user save/close authoring page.
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ */
+public class ClearSessionAction extends LamsAuthoringFinishAction {
+
+ @Override
+ public void clearSession(String customiseSessionID,HttpSession session, ToolAccessMode mode) {
+ if(mode.isAuthor()){
+ session.removeAttribute(customiseSessionID);
+ }
+ }
+
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ExportServlet.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ExportServlet.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/ExportServlet.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,278 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.web.actions;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiException;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.service.WikiServiceProxy;
+import org.lamsfoundation.lams.tool.wiki.service.IWikiService;
+import org.lamsfoundation.lams.tool.wiki.util.WikiConstants;
+import org.lamsfoundation.lams.tool.wiki.util.WikiToolContentHandler;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.FileUtil;
+import org.lamsfoundation.lams.web.servlet.AbstractExportPortfolioServlet;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.lamsfoundation.lams.web.util.SessionMap;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class ExportServlet extends AbstractExportPortfolioServlet {
+ private static final long serialVersionUID = -4529093489007108143L;
+ private static Logger logger = Logger.getLogger(ExportServlet.class);
+ private final String FILENAME = "wiki_main.html";
+ WikiToolContentHandler handler;
+
+
+ private class StringComparator implements Comparator{
+ public int compare(String o1, String o2) {
+ if(o1 != null && o2 != null){
+ return o1.compareTo(o2);
+ }else if(o1 != null)
+ return 1;
+ else
+ return -1;
+ }
+ }
+
+ protected String doOfflineExport(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies) {
+ if (toolContentID == null && toolSessionID == null) {
+ logger.error("Tool content Id or and session Id are null. Unable to activity title");
+ } else {
+ IWikiService wikiService = WikiServiceProxy.getWikiService(getServletContext());
+ Wiki wiki = null;
+ if ( toolContentID != null ) {
+ wiki = wikiService.getWikiByContentId(toolContentID);
+ } else {
+ WikiToolSession session = wikiService.getSessionBySessionId(toolSessionID);
+ if ( session != null )
+ wiki = session.getWiki();
+ }
+ if ( wiki != null ) {
+ activityTitle = wiki.getTitle();
+ }
+ }
+ return super.doOfflineExport(request, response, directoryName, cookies);
+ }
+
+ public String doExport(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies)
+ {
+
+// initial sessionMap
+ SessionMap sessionMap = new SessionMap();
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+
+ if (StringUtils.equals(mode,ToolAccessMode.LEARNER.toString())){
+ sessionMap.put(AttributeNames.PARAM_MODE, ToolAccessMode.LEARNER);
+ learner(request,response,directoryName,cookies,sessionMap);
+ }else if (StringUtils.equals(mode,ToolAccessMode.TEACHER.toString())){
+ sessionMap.put(AttributeNames.PARAM_MODE, ToolAccessMode.TEACHER);
+ teacher(request,response,directoryName,cookies,sessionMap);
+ }
+
+ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
+ writeResponseToFile(basePath+"/jsps/export/exportportfolio.jsp?sessionMapID="+sessionMap.getSessionID()
+ ,directoryName,FILENAME,cookies);
+
+ return FILENAME;
+ }
+ public void learner(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies, HashMap sessionMap)
+ {
+
+ IWikiService wikiService = WikiServiceProxy.getWikiService(getServletContext());
+
+ if (userID == null || toolSessionID == null)
+ {
+ String error = "Tool session Id or user Id is null. Unable to continue";
+ logger.error(error);
+ throw new WikiException(error);
+ }
+
+ WikiUser learner = wikiService.getUserByUserAndSession(userID,toolSessionID);
+
+ if (learner == null)
+ {
+ String error="The user with user id " + userID + " does not exist in this session or session may not exist.";
+ logger.error(error);
+ throw new WikiException(error);
+ }
+
+ // get root topic list and its children topics
+ List msgDtoList = getSessionTopicList(toolSessionID, directoryName, wikiService);
+ //set author flag, to decide if display mark of topics.Only author allow see his own mark.
+ setAuthorMark(msgDtoList);
+
+ WikiToolSession session = wikiService.getSessionBySessionId(toolSessionID);
+
+ //put all message into Map. Key is session name, value is list of all topics in this session.
+ Map sessionTopicMap = new TreeMap();
+ sessionTopicMap.put(session.getSessionName(), msgDtoList);
+
+ sessionMap.put(WikiConstants.ATTR_TOOL_CONTENT_TOPICS, sessionTopicMap);
+
+ //set wiki title
+ sessionMap.put(WikiConstants.ATTR_FORUM_TITLE, session.getWiki().getTitle());
+
+ }
+
+
+ public void teacher(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies, HashMap sessionMap)
+ {
+ IWikiService wikiService = WikiServiceProxy.getWikiService(getServletContext());
+
+ //check if toolContentId exists in db or not
+ if (toolContentID==null)
+ {
+ String error="Tool Content Id is missing. Unable to continue";
+ logger.error(error);
+ throw new WikiException(error);
+ }
+
+ Wiki content = wikiService.getWikiByContentId(toolContentID);
+
+ if (content == null)
+ {
+ String error="Data is missing from the database. Unable to Continue";
+ logger.error(error);
+ throw new WikiException(error);
+ }
+ //return FileDetailsDTO list according to the given sessionID
+ List sessionList = wikiService.getSessionsByContentId(toolContentID);
+ Iterator iter = sessionList.iterator();
+ //put all message into Map. Key is session name, value is list of all topics in this session.
+ Map> topicsByUser = new TreeMap>(this.new StringComparator());
+ while(iter.hasNext()){
+ WikiToolSession session = (WikiToolSession) iter.next();
+ List sessionMsgDTO = getSessionTopicList(session.getSessionId(), directoryName, wikiService);
+ topicsByUser.put(session.getSessionName(),sessionMsgDTO);
+ }
+ sessionMap.put(WikiConstants.ATTR_TOOL_CONTENT_TOPICS,topicsByUser);
+
+// set wiki title
+ sessionMap.put(WikiConstants.ATTR_FORUM_TITLE, content.getTitle());
+ }
+
+ /**
+ * Get all topics with their children message for a special ToolSessionID.
+ * @param toolSessionID
+ * @param directoryName
+ * @param wikiService
+ * @return
+ */
+ private List getSessionTopicList(Long toolSessionID, String directoryName, IWikiService wikiService) {
+ List rootTopics = wikiService.getRootTopics(toolSessionID);
+ List msgDtoList = new ArrayList();
+ for(MessageDTO msgDto : rootTopics){
+ List topics = wikiService.getTopicThread(msgDto.getMessage().getUid());
+ //check attachement, if it has, save it into local directory.
+ for(MessageDTO topic:topics){
+ if(topic.getHasAttachment()){
+ Iterator iter = topic.getMessage().getAttachments().iterator();
+ while(iter.hasNext()){
+ Attachment att = (Attachment) iter.next();
+ topic.setAttachmentName(att.getFileName());
+ int idx= 1;
+ String userName = topic.getAuthor();
+ String localDir;
+ while(true){
+ localDir = FileUtil.getFullPath(directoryName,userName + "/" + idx);
+ File local = new File(localDir);
+ if(!local.exists()){
+ local.mkdirs();
+ break;
+ }
+ idx++;
+ }
+ topic.setAttachmentLocalUrl(userName + "/" + idx + "/" + att.getFileUuid() + '.' + FileUtil.getFileExtension(att.getFileName()));
+ try {
+ handler = getToolContentHandler();
+ handler.saveFile(att.getFileUuid(), FileUtil.getFullPath(directoryName, topic.getAttachmentLocalUrl()));
+ } catch (Exception e) {
+ logger.error("Export wiki topic attachment failed: " + e.toString());
+ }
+ }
+ }
+ }
+ msgDtoList.addAll(topics);
+ }
+ return msgDtoList;
+ }
+ private WikiToolContentHandler getToolContentHandler() {
+ if ( handler == null ) {
+ WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
+ handler = (WikiToolContentHandler) wac.getBean(WikiConstants.TOOL_CONTENT_HANDLER_NAME);
+ }
+ return handler;
+ }
+
+ /**
+ * If this topic is created by current login user, then set Author mark
+ * true.
+ *
+ * @param msgDtoList
+ */
+ private void setAuthorMark(List msgDtoList) {
+ // set current user to web page, so that can display "edit" button
+ // correct. Only author alow to edit.
+ HttpSession ss = SessionManager.getSession();
+ // get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+
+ Long currUserId = new Long(user.getUserID().intValue());
+ Iterator iter = msgDtoList.iterator();
+ while (iter.hasNext()) {
+ MessageDTO dto = (MessageDTO) iter.next();
+ if (dto.getMessage().getCreatedBy() != null
+ && currUserId.equals(dto.getMessage().getCreatedBy()
+ .getUserId()))
+ dto.setAuthor(true);
+ else
+ dto.setAuthor(false);
+ }
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/LearningAction.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/LearningAction.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/LearningAction.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,885 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.web.actions;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.Action;
+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.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.ToolSessionManager;
+import org.lamsfoundation.lams.tool.exception.DataMissingException;
+import org.lamsfoundation.lams.tool.exception.ToolException;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiException;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.persistence.PersistenceException;
+import org.lamsfoundation.lams.tool.wiki.service.WikiServiceProxy;
+import org.lamsfoundation.lams.tool.wiki.service.IWikiService;
+import org.lamsfoundation.lams.tool.wiki.util.WikiConstants;
+import org.lamsfoundation.lams.tool.wiki.web.forms.MessageForm;
+import org.lamsfoundation.lams.tool.wiki.web.forms.ReflectionForm;
+import org.lamsfoundation.lams.usermanagement.dto.UserDTO;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.session.SessionManager;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.lamsfoundation.lams.web.util.SessionMap;
+import org.springframework.orm.ObjectOptimisticLockingFailureException;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * User: conradb Date: 24/06/2005 Time: 10:54:09
+ */
+public class LearningAction extends Action {
+ private static Logger log = Logger.getLogger(LearningAction.class);
+
+ private static final boolean MODE_OPTIONAL = false;
+
+ private IWikiService wikiService;
+
+ public final ActionForward execute(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ String param = mapping.getParameter();
+ // --------------Wiki Level ------------------
+ if (param.equals("viewWiki")) {
+ return viewForm(mapping, form, request, response);
+ }
+ if (param.equals("finish")) {
+ return finish(mapping, form, request, response);
+ }
+
+ // --------------Topic Level ------------------
+ if (param.equals("viewTopic")) {
+ return viewTopic(mapping, form, request, response);
+ }
+ if (param.equals("newTopic")) {
+ return newTopic(mapping, form, request, response);
+ }
+ if (param.equals("createTopic")) {
+ return createTopic(mapping, form, request, response);
+ }
+ if (param.equals("newReplyTopic")) {
+ return newReplyTopic(mapping, form, request, response);
+ }
+ if (param.equals("replyTopic")) {
+ return replyTopic(mapping, form, request, response);
+ }
+ if (param.equals("editTopic")) {
+ return editTopic(mapping, form, request, response);
+ }
+ if (param.equals("updateTopic")) {
+ return updateTopic(mapping, form, request, response);
+ }
+ if (param.equals("deleteAttachment")) {
+ return deleteAttachment(mapping, form, request, response);
+ }
+ if (param.equals("updateMessageHideFlag")) {
+ return updateMessageHideFlag(mapping, form, request, response);
+ }
+
+ //================ Reflection =======================
+ if (param.equals("newReflection")) {
+ return newReflection(mapping, form, request, response);
+ }
+ if (param.equals("submitReflection")) {
+ return submitReflection(mapping, form, request, response);
+ }
+
+
+ return mapping.findForward("error");
+ }
+
+
+
+ // ==========================================================================================
+ // Wiki level methods
+ // ==========================================================================================
+ /**
+ * Display root topics of a wiki. This page will be the initial page of
+ * Learner page.
+ * @throws Exception
+ *
+ */
+ private ActionForward viewForm(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+ //initial Session Map
+ String sessionMapID = request.getParameter(WikiConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap;
+ //refresh wiki page, not initial enter
+ if(sessionMapID != null){
+ sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ }else{
+ sessionMap = new SessionMap();
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+ }
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID());
+
+ // set the mode into http session
+ ToolAccessMode mode = null;
+ try {
+ mode = WebUtil.readToolAccessModeParam(request,AttributeNames.PARAM_MODE, MODE_OPTIONAL);
+ } catch (Exception exp) {
+ }
+ if (mode == null) {
+ //set it as default mode
+ mode = ToolAccessMode.LEARNER;
+ }
+
+ // get sessionId from HttpServletRequest
+ Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ // Try to get WikiID according to sessionId
+ wikiService = getWikiManager();
+ WikiToolSession session = wikiService.getSessionBySessionId(sessionId);
+
+ if (session == null || session.getWiki() == null) {
+ log.error("Failed on getting session by given sessionID:" + sessionId);
+ throw new Exception("Failed on getting session by given sessionID:" + sessionId);
+ }
+
+ Wiki wiki = session.getWiki();
+ //lock on finish
+ WikiUser wikiUser = getCurrentUser(request,sessionId);
+ boolean lock = wiki.getLockWhenFinished() && wikiUser.isSessionFinished();
+
+ //add define later support
+ if(wiki.isDefineLater()){
+ return mapping.findForward("defineLater");
+ }
+
+ //add run offline support
+ if(wiki.getRunOffline()){
+ return mapping.findForward("runOffline");
+ }
+
+ //set contentInUse flag to true!
+ if ( ! wiki.isContentInUse() ) {
+ wiki.setContentInUse(true);
+ wiki.setDefineLater(false);
+ wikiService.updateWiki(wiki);
+ }
+
+ //set some option flag to HttpSession
+ // if allowRichEditor = true then don't restrict the number of chars
+ // if isLimitedInput = false then don't restrict the number of chars
+ // Indicate don't restrict number of chars by allowNumber = 0
+ Long wikiId = wiki.getUid();
+ //Boolean allowRichEditor = new Boolean(wiki.isAllowRichEditor());
+ Boolean allowRichEditor = new Boolean(true);
+ //int allowNumber = wiki.isLimitedInput() || wiki.isAllowRichEditor() ? wiki.getLimitedChar() : 0;
+ int allowNumber = wiki.getLimitedChar();
+
+ // get notebook entry
+ String entryText = new String();
+ NotebookEntry notebookEntry = wikiService.getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL,
+ WikiConstants.TOOL_SIGNATURE, wikiUser.getUserId().intValue());
+
+ if (notebookEntry != null) {
+ entryText = notebookEntry.getEntry();
+ }
+
+ sessionMap.put(WikiConstants.FORUM_ID, wikiId);
+ sessionMap.put(AttributeNames.ATTR_MODE, mode);
+ sessionMap.put(WikiConstants.ATTR_FINISHED_LOCK, new Boolean(lock));
+ sessionMap.put(WikiConstants.ATTR_USER_FINISHED, wikiUser.isSessionFinished());
+ sessionMap.put(WikiConstants.ATTR_ALLOW_EDIT, wiki.isAllowEdit());
+ sessionMap.put(WikiConstants.ATTR_ALLOW_UPLOAD,wiki.isAllowUpload());
+ sessionMap.put(WikiConstants.ATTR_ALLOW_NEW_TOPICS,wiki.isAllowNewTopic());
+ sessionMap.put(WikiConstants.ATTR_ALLOW_RICH_EDITOR,allowRichEditor);
+ sessionMap.put(WikiConstants.ATTR_LIMITED_CHARS,new Integer(allowNumber));
+ sessionMap.put(WikiConstants.ATTR_REFLECTION_ON,wiki.isReflectOnActivity());
+ sessionMap.put(WikiConstants.ATTR_REFLECTION_INSTRUCTION,wiki.getReflectInstructions());
+ sessionMap.put(WikiConstants.ATTR_REFLECTION_ENTRY, entryText);
+ sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId);
+ sessionMap.put(WikiConstants.ATTR_FORUM_TITLE,wiki.getTitle());
+ sessionMap.put(WikiConstants.ATTR_FORUM_INSTRCUTION,wiki.getInstructions());
+
+ // get all root topic to display on init page
+ List rootTopics = wikiService.getRootTopics(sessionId);
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_LIST, rootTopics);
+
+ return mapping.findForward("success");
+ }
+
+
+ /**
+ * Learner click "finish" button in wiki page, this method will turn on
+ * session status flag for this learner.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward finish(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+
+ ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE);
+ Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ wikiService = getWikiManager();
+
+ if (mode == ToolAccessMode.LEARNER || mode==ToolAccessMode.AUTHOR) {
+ if(!validateBeforeFinish(request, sessionMapID))
+ return mapping.getInputForward();
+
+ String nextActivityUrl;
+ try {
+// get session from shared session.
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ Long userID = new Long(user.getUserID().longValue());
+
+ //finish current session for user
+ wikiService.finishUserSession(getCurrentUser(request, sessionId));
+ ToolSessionManager sessionMgrService = WikiServiceProxy.getToolSessionManager(getServlet().getServletContext());
+ nextActivityUrl = sessionMgrService.leaveToolSession(sessionId,userID);
+ response.sendRedirect(nextActivityUrl);
+ } catch (DataMissingException e) {
+ throw new WikiException(e);
+ } catch (ToolException e) {
+ throw new WikiException(e);
+ } catch (IOException e) {
+ throw new WikiException(e);
+ }
+ return null;
+
+ }
+ // get all root topic to display on init page
+ List rootTopics = wikiService.getRootTopics(sessionId);
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_LIST, rootTopics);
+
+ return mapping.getInputForward();
+ }
+
+
+
+ /**
+ * Submit reflection form input database.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward submitReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+ ReflectionForm refForm = (ReflectionForm) form;
+ Integer userId = refForm.getUserID();
+
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ // check for existing notebook entry
+ NotebookEntry entry = wikiService.getEntry(sessionId,
+ CoreNotebookConstants.NOTEBOOK_TOOL,
+ WikiConstants.TOOL_SIGNATURE, userId);
+
+ if (entry == null) {
+ // create new entry
+ wikiService.createNotebookEntry(sessionId,
+ CoreNotebookConstants.NOTEBOOK_TOOL,
+ WikiConstants.TOOL_SIGNATURE, userId, refForm
+ .getEntryText());
+ } else {
+ // update existing entry
+ entry.setEntry(refForm.getEntryText());
+ entry.setLastModified(new Date());
+ wikiService.updateEntry(entry);
+ }
+
+ return finish(mapping, form, request, response);
+ }
+
+ /**
+ * Display empty reflection form.
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward newReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ //get session value
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID);
+ if(!validateBeforeFinish(request, sessionMapID))
+ return mapping.getInputForward();
+
+ ReflectionForm refForm = (ReflectionForm) form;
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+
+ refForm.setUserID(user.getUserID());
+ refForm.setSessionMapID(sessionMapID);
+
+ // get the existing reflection entry
+ IWikiService submitFilesService = getWikiManager();
+
+ SessionMap map = (SessionMap)request.getSession().getAttribute(sessionMapID);
+ Long toolSessionID = (Long)map.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+ NotebookEntry entry = submitFilesService.getEntry(toolSessionID, CoreNotebookConstants.NOTEBOOK_TOOL, WikiConstants.TOOL_SIGNATURE, user.getUserID());
+
+ if (entry != null) {
+ refForm.setEntryText(entry.getEntry());
+ }
+
+ return mapping.findForward("success");
+ }
+ // ==========================================================================================
+ // Topic level methods
+ // ==========================================================================================
+
+ /**
+ * Display read-only page for a special topic. Topic will arrange by Tree
+ * structure.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+ Long rootTopicId = WebUtil.readLongParam(request, WikiConstants.ATTR_TOPIC_ID);
+ wikiService = getWikiManager();
+ // get root topic list
+ List msgDtoList = wikiService.getTopicThread(rootTopicId);
+ updateMesssageFlag(msgDtoList);
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
+
+ String sessionMapID = WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ sessionMap.put(WikiConstants.ATTR_ROOT_TOPIC_UID, rootTopicId);
+
+ //transfer SessionMapID as well
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMapID);
+
+ return mapping.findForward("success");
+
+ }
+
+
+ /**
+ * Display empty page for a new topic in wiki
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward newTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ //transfer SessionMapID as well
+ ((MessageForm)form).setSessionMapID(WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID));
+
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Create a new root topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws ServletException
+ * @throws PersistenceException
+ */
+ public ActionForward createTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException, PersistenceException {
+
+ MessageForm messageForm = (MessageForm) form;
+ SessionMap sessionMap = getSessionMap(request, messageForm);
+ Long wikiId = (Long) sessionMap.get(WikiConstants.FORUM_ID);
+ Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ Message message = messageForm.getMessage();
+ message.setIsAuthored(false);
+ message.setCreated(new Date());
+ message.setUpdated(new Date());
+ message.setLastReplyDate(new Date());
+ WikiUser wikiUser = getCurrentUser(request,sessionId);
+ message.setCreatedBy(wikiUser);
+ message.setModifiedBy(wikiUser);
+ setAttachment(messageForm, message);
+
+ // save message into database
+ wikiService = getWikiManager();
+ wikiService.createRootTopic(wikiId, sessionId, message);
+
+ // echo back current root topic to fourm init page
+ List rootTopics = wikiService.getRootTopics(sessionId);
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_LIST, rootTopics);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID,messageForm.getSessionMapID());
+
+ return mapping.findForward("success");
+ }
+
+
+ /**
+ * Display replay topic page. Message form subject will include parent
+ * topics same subject.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward newReplyTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ String sessionMapID = request.getParameter(WikiConstants.ATTR_SESSION_MAP_ID);
+
+ MessageForm msgForm = (MessageForm) form;
+ msgForm.setSessionMapID(sessionMapID);
+
+ Long parentId = WebUtil.readLongParam(request, WikiConstants.ATTR_PARENT_TOPIC_ID);
+ // get parent topic, it can decide default subject of reply.
+ MessageDTO topic = getTopic(parentId);
+
+ if (topic != null && topic.getMessage() != null) {
+ String reTitle = topic.getMessage().getSubject();
+
+ MessageDTO originalMessage = MessageDTO.getMessageDTO(topic.getMessage());
+
+ request.setAttribute(WikiConstants.ATTR_ORIGINAL_MESSAGE, originalMessage);
+
+ // echo back current topic subject to web page
+ if(reTitle != null && !reTitle.trim().startsWith("Re:"))
+ msgForm.getMessage().setSubject("Re:" + reTitle);
+ else
+ msgForm.getMessage().setSubject(reTitle);
+ }
+ SessionMap sessionMap = getSessionMap(request, msgForm);
+ sessionMap.put(WikiConstants.ATTR_PARENT_TOPIC_ID, parentId);
+
+
+ return mapping.findForward("success");
+ }
+
+
+ /**
+ * Create a replayed topic for a parent topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward replyTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+
+ MessageForm messageForm = (MessageForm) form;
+ SessionMap sessionMap = getSessionMap(request, messageForm);
+ Long parentId = (Long) sessionMap.get(WikiConstants.ATTR_PARENT_TOPIC_ID);
+ Long sessionId =(Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ Message message = messageForm.getMessage();
+ message.setIsAuthored(false);
+ message.setCreated(new Date());
+ message.setUpdated(new Date());
+ message.setLastReplyDate(new Date());
+ WikiUser wikiUser = getCurrentUser(request,sessionId);
+ message.setCreatedBy(wikiUser);
+ message.setModifiedBy(wikiUser);
+ setAttachment(messageForm, message);
+
+
+ // save message into database
+ wikiService = getWikiManager();
+ wikiService.replyTopic(parentId, sessionId, message);
+
+ // echo back this topic thread into page
+ Long rootTopicId = wikiService.getRootTopicId(parentId);
+ List msgDtoList = wikiService.getTopicThread(rootTopicId);
+ updateMesssageFlag(msgDtoList);
+
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID,messageForm.getSessionMapID());
+
+ //check whether allow more posts for this user
+ WikiToolSession session = wikiService.getSessionBySessionId(sessionId);
+ Wiki wiki = session.getWiki();
+ if(wiki != null){
+ if(!wiki.isAllowNewTopic()){
+ int posts = wikiService.getTopicsNum(wikiUser.getUserId(), sessionId);
+ if(wiki.getMaximumReply() != 0 && (posts >= wiki.getMaximumReply()))
+ sessionMap.put(WikiConstants.ATTR_NO_MORE_POSTS, Boolean.TRUE);
+ }
+ }
+ sessionMap.remove(WikiConstants.ATTR_ORIGINAL_MESSAGE);
+
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Display a editable form for a special topic in order to update it.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward editTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response)
+ throws PersistenceException {
+ Long topicId = WebUtil.readLongParam(request, WikiConstants.ATTR_TOPIC_ID);
+
+ MessageDTO topic = getTopic(topicId);
+
+ // echo current topic content to web page
+ MessageForm msgForm = (MessageForm) form;
+ if (topic != null) {
+ msgForm.setMessage(topic.getMessage());
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC, topic);
+ }
+
+ //cache this topicID, using in Update topic
+ SessionMap sessionMap = getSessionMap(request, msgForm);
+ sessionMap.put(WikiConstants.ATTR_TOPIC_ID, topicId);
+
+ return mapping.findForward("success");
+ }
+ /**
+ * Delete attachment from topic. This method only reset attachment information in memory. The finally update
+ * will happen in updateTopic method. So topic can keep this attachment if user choose "Cancel" edit
+ * topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ //only reset not attachment flag.
+ MessageDTO dto = new MessageDTO();
+ dto.setHasAttachment(false);
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC, dto);
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(WebUtil.readStrParam(request, WikiConstants.ATTR_SESSION_MAP_ID));
+ request.setAttribute(WikiConstants.ATTR_ALLOW_UPLOAD, sessionMap.get(WikiConstants.ATTR_ALLOW_UPLOAD));
+
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Update a topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ * @throws PersistenceException
+ */
+ public ActionForward updateTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response)
+ throws PersistenceException {
+
+ wikiService = getWikiManager();
+
+ MessageForm messageForm = (MessageForm) form;
+ SessionMap sessionMap = getSessionMap(request, messageForm);
+ Long topicId = (Long) sessionMap.get(WikiConstants.ATTR_TOPIC_ID);
+ Message message = messageForm.getMessage();
+
+ boolean makeAuditEntry = ToolAccessMode.TEACHER.equals((ToolAccessMode)sessionMap.get(AttributeNames.ATTR_MODE));
+ String oldMessageString = null;
+
+ // get PO from database and sync with Form
+ Message messagePO = wikiService.getMessage(topicId);
+ if ( makeAuditEntry ) {
+ oldMessageString = messagePO.toString();
+ }
+ messagePO.setSubject(message.getSubject());
+ messagePO.setBody(message.getBody());
+ messagePO.setUpdated(new Date());
+ messagePO.setModifiedBy(getCurrentUser(request,(Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID)));
+ setAttachment(messageForm, messagePO);
+
+ if ( makeAuditEntry ) {
+ Long userId = 0L;
+ String loginName = "Default";
+ if(message.getCreatedBy() != null){
+ userId = message.getCreatedBy().getUserId();
+ loginName = message.getCreatedBy().getLoginName();
+ }
+ wikiService.getAuditService().logChange(WikiConstants.TOOL_SIGNATURE,
+ userId,loginName,
+ oldMessageString, messagePO.toString());
+ }
+
+ // save message into database
+ // if we are in monitoring then we are probably editing some else's entry so log the change.
+ wikiService.updateTopic(messagePO);
+
+ // echo back this topic thread into page
+ Long rootTopicId = wikiService.getRootTopicId(topicId);
+ List msgDtoList = wikiService.getTopicThread(rootTopicId);
+ updateMesssageFlag(msgDtoList);
+
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID,messageForm.getSessionMapID());
+
+ return mapping.findForward("success");
+ }
+
+
+ /**
+ * Sets the visibility of a message by updating the hide flag for a message
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ public ActionForward updateMessageHideFlag(ActionMapping mapping,
+ ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ Long msgId = new Long(WebUtil.readLongParam(request,WikiConstants.ATTR_TOPIC_ID));
+ Boolean hideFlag = new Boolean(WebUtil.readBooleanParam(request, "hideFlag"));
+ wikiService = getWikiManager();
+
+ // TODO Skipping permissions for now, currently having issues with default learning designs not having an create_by field
+// Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
+ // check if the user has permission to hide posts.
+// WikiToolSession toolSession = wikiService
+// .getSessionBySessionId(sessionId);
+//
+// Wiki wiki = toolSession.getWiki();
+// WikiUser currentUser = getCurrentUser(request,sessionId);
+// WikiUser wikiCreatedBy = wiki.getCreatedBy();
+
+ // we should be looking at whether a user is a teacher and more specifically staff
+// if (currentUser.getUserId().equals(wikiCreatedBy.getUserId())) {
+ wikiService.updateMessageHideFlag(msgId, hideFlag.booleanValue());
+// } else {
+// log.info(currentUser + "does not have permission to hide/show postings in wiki: " + wiki.getUid());
+// log.info("Wiki created by :" + wikiCreatedBy.getUid() + ", Current User is: " + currentUser.getUid());
+// }
+
+
+ // echo back this topic thread into page
+ Long rootTopicId = wikiService.getRootTopicId(msgId);
+ List msgDtoList = wikiService.getTopicThread(rootTopicId);
+ updateMesssageFlag(msgDtoList);
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID,WebUtil.readStrParam(request,WikiConstants.ATTR_SESSION_MAP_ID));
+
+ return mapping.findForward("success");
+ }
+
+ // ==========================================================================================
+ // Utility methods
+ // ==========================================================================================
+ /**
+ * Validation method to check whether user posts meet minimum number.
+ */
+ private boolean validateBeforeFinish(HttpServletRequest request, String sessionMapID) {
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
+ Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ WikiToolSession session = wikiService.getSessionBySessionId(sessionId);
+ Wiki wiki = session.getWiki();
+ // get session from shared session.
+ HttpSession ss = SessionManager.getSession();
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ Long userID = new Long(user.getUserID().longValue());
+ if(!wiki.getRunOffline() && !wiki.isAllowNewTopic()){
+ int postNum = wikiService.getTopicsNum(userID,sessionId);
+ if(postNum < wiki.getMinimumReply()){
+ //create error
+ ActionMessages errors = new ActionMessages();
+ errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.less.mini.post",(wiki.getMinimumReply() - postNum)));
+ saveErrors(request, errors);
+
+ // get all root topic to display on init page
+ List rootTopics = wikiService.getRootTopics(sessionId);
+ request.setAttribute(WikiConstants.AUTHORING_TOPICS_LIST, rootTopics);
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMapID );
+ return false;
+ }
+ }
+ return true;
+ }
+ /**
+ * This method will set flag in message DTO:
+ *
If this topic is created by current login user, then set Author mark
+ * true.
+ *
+ * @param msgDtoList
+ */
+ private void updateMesssageFlag(List msgDtoList) {
+ // set current user to web page, so that can display "edit" button
+ // correct. Only author alow to edit.
+ HttpSession ss = SessionManager.getSession();
+ // get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+
+ Long currUserId = new Long(user.getUserID().intValue());
+ Iterator iter = msgDtoList.iterator();
+ while (iter.hasNext()) {
+ MessageDTO dto = (MessageDTO) iter.next();
+ if (dto.getMessage().getCreatedBy() != null
+ && currUserId.equals(dto.getMessage().getCreatedBy()
+ .getUserId()))
+ dto.setAuthor(true);
+ else
+ dto.setAuthor(false);
+ }
+ }
+
+ /**
+ * @param topicId
+ * @return
+ */
+ private MessageDTO getTopic(Long topicId) {
+ // get Topic content according to TopicID
+ wikiService = getWikiManager();
+ MessageDTO topic = MessageDTO.getMessageDTO(wikiService.getMessage(topicId));
+ return topic;
+ }
+
+ /**
+ * Get login user information from system level session. Check it whether it
+ * exists in database or not, and save it if it does not exists. Return an
+ * instance of PO of WikiUser.
+ *
+ * @param request
+ * @param sessionId
+ * @return Current user instance
+ */
+ private WikiUser getCurrentUser(HttpServletRequest request, Long sessionId) {
+ // get login user (author)
+ HttpSession ss = SessionManager.getSession();
+ // get back login user DTO
+ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
+ WikiUser wikiUser = wikiService.getUserByUserAndSession(new Long(
+ user.getUserID().intValue()), sessionId);
+ if (wikiUser == null) {
+ // if user not exist, create new one in database
+ WikiToolSession session = wikiService
+ .getSessionBySessionId(sessionId);
+ wikiUser = new WikiUser(user, session);
+ wikiService.createUser(wikiUser);
+ }
+ return wikiUser;
+ }
+
+ /**
+ * Get Wiki Service.
+ *
+ * @return
+ */
+ private IWikiService getWikiManager() {
+ if (wikiService == null) {
+ WebApplicationContext wac = WebApplicationContextUtils
+ .getRequiredWebApplicationContext(getServlet()
+ .getServletContext());
+ wikiService = (IWikiService) wac
+ .getBean(WikiConstants.FORUM_SERVICE);
+ }
+ return wikiService;
+ }
+
+ /**
+ * @param messageForm
+ * @param message
+ */
+ private void setAttachment(MessageForm messageForm, Message message) {
+ if (messageForm.getAttachmentFile() != null
+ && !StringUtils.isBlank(messageForm.getAttachmentFile().getFileName())) {
+ wikiService = getWikiManager();
+ Attachment att = wikiService.uploadAttachment(messageForm
+ .getAttachmentFile());
+ Set attSet = message.getAttachments();
+ if(attSet == null)
+ attSet = new HashSet();
+ // only allow one attachment, so replace whatever
+ attSet.clear();
+ attSet.add(att);
+ message.setAttachments(attSet);
+ }else if(!messageForm.isHasAttachment()){
+ //user already called deleteAttachment in AJAX call
+ if(message.getAttachments() != null){
+ Set atts = message.getAttachments();
+ atts.clear();
+ message.setAttachments(atts);
+ }else
+ message.setAttachments(null);
+ }
+ }
+
+ private SessionMap getSessionMap(HttpServletRequest request, MessageForm messageForm) {
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(messageForm.getSessionMapID());
+ return sessionMap;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/MonitoringAction.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/MonitoringAction.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/actions/MonitoringAction.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,855 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.web.actions;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+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.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+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.notebook.model.NotebookEntry;
+import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.dto.SessionDTO;
+import org.lamsfoundation.lams.tool.wiki.dto.UserDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiReport;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.service.IWikiService;
+import org.lamsfoundation.lams.tool.wiki.util.WikiConstants;
+import org.lamsfoundation.lams.tool.wiki.util.WikiWebUtils;
+import org.lamsfoundation.lams.tool.wiki.web.forms.WikiForm;
+import org.lamsfoundation.lams.tool.wiki.web.forms.MarkForm;
+import org.lamsfoundation.lams.util.MessageService;
+import org.lamsfoundation.lams.util.WebUtil;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+import org.lamsfoundation.lams.web.util.SessionMap;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+public class MonitoringAction extends Action {
+
+ private static Logger log = Logger.getLogger(MonitoringAction.class);
+
+ private IWikiService wikiService;
+
+ private class SessionDTOComparator implements Comparator{
+ public int compare(SessionDTO o1, SessionDTO o2) {
+ if(o1 != null && o2 != null){
+ return o1.getSessionName().compareTo(o2.getSessionName());
+ }else if(o1 != null)
+ return 1;
+ else
+ return -1;
+ }
+ }
+
+ private class WikiUserComparator implements Comparator{
+ public int compare(WikiUser o1, WikiUser o2) {
+ if(o1 != null && o2 != null){
+ return o1.getLoginName().compareTo(o2.getLoginName());
+ }else if(o1 != null)
+ return 1;
+ else
+ return -1;
+ }
+ }
+ private class UserDTOComparator implements Comparator{
+ public int compare(UserDTO o1, UserDTO o2) {
+ if(o1 != null && o2 != null){
+ return o1.getLoginName().compareTo(o2.getLoginName());
+ }else if(o1 != null)
+ return 1;
+ else
+ return -1;
+ }
+ }
+ /**
+ * Action method entry.
+ */
+ public final ActionForward execute(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ String param = mapping.getParameter();
+
+ if (param.equals("init")) {
+ return init(mapping, form, request, response);
+ }
+ //refresh statistic page by Ajax call.
+ if (param.equals("statistic")) {
+ return statistic(mapping, form, request, response);
+ }
+ // ***************** Marks Functions ********************
+ if (param.equals("viewAllMarks")) {
+ return viewAllMarks(mapping, form, request, response);
+ }
+ if (param.equals("downloadMarks")) {
+ return downloadMarks(mapping, form, request, response);
+ }
+ if (param.equals("viewUserMark")) {
+ return viewUserMark(mapping, form, request, response);
+ }
+ if (param.equals("editMark")) {
+ return editMark(mapping, form, request, response);
+ }
+ if (param.equals("updateMark")) {
+ return updateMark(mapping, form, request, response);
+ }
+
+ if(param.equals("releaseMark"))
+ return releaseMark(mapping, form, request, response);
+
+ // ***************** Miscellaneous ********************
+ if (param.equals("viewTopic")) {
+ return viewTopic(mapping, form, request, response);
+ }
+ if (param.equals("viewTopicTree")) {
+ return viewTopicTree(mapping, form, request, response);
+ }
+
+ if (param.equals("viewReflection")) {
+ return viewReflection(mapping, form, request, response);
+ }
+
+ return mapping.findForward("error");
+ }
+
+
+
+ /**
+ * The initial method for monitoring
+ */
+ private ActionForward init(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+ // perform the actions for all the tabs.
+ doTabs(mapping, form, request, response);
+
+ return mapping.findForward("load");
+ }
+
+ private ActionForward doTabs(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
+ this.summary(mapping, form, request, response);
+ this.viewInstructions(mapping, form, request, response);
+ this.viewActivity(mapping, form, request, response);
+ this.statistic(mapping, form, request, response);
+ return mapping.findForward("load");
+ }
+
+ /**
+ * The initial method for monitoring. List all users according to given
+ * Content ID.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward summary(ActionMapping mapping,
+ ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+ Long toolContentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+
+ wikiService = getWikiService();
+ List sessionsList = wikiService.getSessionsByContentId(toolContentID);
+
+ Map sessionUsersMap = new TreeMap(this.new SessionDTOComparator());
+ // build a map with all users in the submitFilesSessionList
+ Iterator it = sessionsList.iterator();
+ while (it.hasNext()) {
+ SessionDTO sessionDto = new SessionDTO();
+ WikiToolSession fts = (WikiToolSession) it.next();
+ boolean hasReflection = fts.getWiki().isReflectOnActivity();
+
+ sessionDto.setSessionID(fts.getSessionId());
+ sessionDto.setSessionName(fts.getSessionName());
+ List userList = wikiService.getUsersBySessionId(fts.getSessionId());
+
+ //sort and create DTO list
+ Set dtoList = new TreeSet(this.new UserDTOComparator());
+ Iterator iter = userList.iterator();
+ while(iter.hasNext()){
+ WikiUser user = (WikiUser) iter.next();
+ UserDTO userDTO = new UserDTO(user);
+ userDTO.setHasRefection(hasReflection);
+ dtoList.add(userDTO);
+ //userDTO.setNoOfPosts(noOfPosts)
+ }
+ sessionUsersMap.put(sessionDto, dtoList);
+ }
+
+ // request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,sessionID);
+ request.setAttribute("sessionUserMap", sessionUsersMap);
+ return mapping.findForward("success");
+
+ }
+
+ /**
+ * Download marks for all users in a speical session.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward downloadMarks(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ Long sessionID = new Long(WebUtil.readLongParam(request,
+ AttributeNames.PARAM_TOOL_SESSION_ID));
+ wikiService = getWikiService();
+ List topicList = wikiService.getAllTopicsFromSession(sessionID);
+ // construct Excel file format and download
+ ActionMessages errors = new ActionMessages();
+ try {
+ // create an empty excel file
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet("Marks");
+ sheet.setColumnWidth((short) 0, (short) 5000);
+ HSSFRow row = null;
+ HSSFCell cell;
+ Iterator iter = getTopicsSortedByAuthor(topicList).values().iterator();
+ Iterator dtoIter;
+ boolean first = true;
+ int idx = 0;
+ int fileCount = 0;
+ while (iter.hasNext()) {
+ List list = (List) iter.next();
+ dtoIter = list.iterator();
+ first = true;
+
+ while (dtoIter.hasNext()) {
+ MessageDTO dto = (MessageDTO) dtoIter.next();
+ if (first) {
+ first = false;
+ row = sheet.createRow(0);
+ cell = row.createCell((short) idx);
+ cell.setCellValue("Subject");
+ sheet.setColumnWidth((short) idx, (short) 8000);
+ ++idx;
+
+ cell = row.createCell((short) idx);
+ cell.setCellValue("Author");
+ sheet.setColumnWidth((short) idx, (short) 8000);
+ ++idx;
+
+ cell = row.createCell((short) idx);
+ cell.setCellValue("Date");
+ sheet.setColumnWidth((short) idx, (short) 8000);
+ ++idx;
+
+ cell = row.createCell((short) idx);
+ cell.setCellValue("Marks");
+ sheet.setColumnWidth((short) idx, (short) 8000);
+ ++idx;
+
+ cell = row.createCell((short) idx);
+ cell.setCellValue("Comments");
+ sheet.setColumnWidth((short) idx, (short) 8000);
+ ++idx;
+ }
+ ++fileCount;
+ idx = 0;
+ row = sheet.createRow(fileCount);
+ cell = row.createCell((short) idx++);
+ cell.setCellValue(dto.getMessage().getSubject());
+
+ cell = row.createCell((short) idx++);
+ cell.setCellValue(dto.getAuthor());
+
+ cell = row.createCell((short) idx++);
+ cell.setCellValue(DateFormat.getInstance().format(
+ dto.getMessage().getCreated()));
+
+ cell = row.createCell((short) idx++);
+
+ if (dto.getMessage() != null
+ && dto.getMessage().getReport() != null
+ && dto.getMessage().getReport().getMark() != null)
+ cell.setCellValue(dto.getMessage().getReport()
+ .getMark().doubleValue());
+ else
+ cell.setCellValue("");
+
+ cell = row.createCell((short) idx++);
+ if (dto.getMessage() != null
+ && dto.getMessage().getReport() != null)
+ cell.setCellValue(dto.getMessage().getReport()
+ .getComment());
+ else
+ cell.setCellValue("");
+ }
+ }
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ wb.write(bos);
+ // construct download file response header
+ String fileName = "marks" + sessionID + ".xls";
+ String mineType = "application/vnd.ms-excel";
+ String header = "attachment; filename=\"" + fileName + "\";";
+ response.setContentType(mineType);
+ response.setHeader("Content-Disposition", header);
+
+ byte[] data = bos.toByteArray();
+ response.getOutputStream().write(data, 0, data.length);
+ response.getOutputStream().flush();
+ } catch (IOException e) {
+ log.error(e);
+ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
+ "monitoring.download.error", e.toString()));
+ }
+
+ if (!errors.isEmpty()) {
+ saveErrors(request, errors);
+ request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID,
+ sessionID);
+ return mapping.getInputForward();
+ }
+
+ return null;
+ }
+
+ /**
+ * View activity for content.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewActivity(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ Long toolContentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+ //set back tool content ID
+ String contentFolderID = WebUtil.readStrParam(request,AttributeNames.PARAM_CONTENT_FOLDER_ID);
+ request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID);
+
+ wikiService = getWikiService();
+ Wiki wiki = wikiService.getWikiByContentId(toolContentID);
+ // if can not find out wiki, echo back error message
+ if (wiki == null) {
+ ActionErrors errors = new ActionErrors();
+ errors.add("activity.globel", new ActionMessage(
+ "error.fail.get.wiki"));
+ this.addErrors(request, errors);
+ return mapping.getInputForward();
+ }
+ String title = wiki.getTitle();
+ String instruction = wiki.getInstructions();
+
+ boolean isWikiEditable = WikiWebUtils.isWikiEditable(wiki);
+ request.setAttribute(WikiConstants.PAGE_EDITABLE, new Boolean(isWikiEditable));
+ request.setAttribute(AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentID);
+ request.setAttribute("title", title);
+ request.setAttribute("instruction", instruction);
+ return mapping.findForward("success");
+ }
+
+ /**
+ * View instruction inforamtion for a content.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewInstructions(ActionMapping mapping,
+ ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+ Long toolContentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+
+ wikiService = getWikiService();
+ Wiki wiki = wikiService.getWikiByContentId(toolContentID);
+ // if can not find out wiki, echo back error message
+ if (wiki == null) {
+ ActionErrors errors = new ActionErrors();
+ errors.add("instruction.globel", new ActionMessage(
+ "error.fail.get.wiki"));
+ this.addErrors(request, errors);
+ return mapping.getInputForward();
+ }
+
+ WikiForm wikiForm = new WikiForm();
+ wikiForm.setWiki(wiki);
+
+ request.setAttribute("wikiBean", wikiForm);
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Show statisitc page for a session.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward statistic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ Long toolContentID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_CONTENT_ID));
+
+ wikiService = getWikiService();
+ Map sessionTopicsMap = new TreeMap>(this.new SessionDTOComparator());
+ Map sessionAvaMarkMap = new HashMap();
+ Map sessionTotalMsgMap = new HashMap();
+
+ List sessList = wikiService.getSessionsByContentId(toolContentID);
+ Iterator sessIter = sessList.iterator();
+ while (sessIter.hasNext()) {
+ WikiToolSession session = (WikiToolSession) sessIter.next();
+ List topicList = wikiService.getRootTopics(session.getSessionId());
+ Iterator iter = topicList.iterator();
+ int totalMsg = 0;
+ int msgNum;
+ float totalMsgMarkSum = 0;
+ float msgMarkSum = 0;
+ for (; iter.hasNext();) {
+ MessageDTO msgDto = (MessageDTO) iter.next();
+ // get all message under this topic
+ List topicThread = wikiService.getTopicThread(msgDto
+ .getMessage().getUid());
+ // loop all message under this topic
+ msgMarkSum = 0;
+ Iterator threadIter = topicThread.iterator();
+ for (msgNum = 0; threadIter.hasNext(); msgNum++) {
+ MessageDTO dto = (MessageDTO) threadIter.next();
+ if (dto.getMark() != null)
+ msgMarkSum += dto.getMark().floatValue();
+ }
+ // summary to total mark
+ totalMsgMarkSum += msgMarkSum;
+ // set average mark to topic message DTO for display use
+ msgDto.setMark(getAverageFormat(msgMarkSum / (float) msgNum));
+ totalMsg += msgNum;
+ }
+
+ float averMark = totalMsg == 0 ? 0
+ : (totalMsgMarkSum / (float) totalMsg);
+
+ SessionDTO sessionDto = new SessionDTO();
+ sessionDto.setSessionID(session.getSessionId());
+ sessionDto.setSessionName(session.getSessionName());
+
+ sessionTopicsMap.put(sessionDto, topicList);
+ sessionAvaMarkMap.put(session.getSessionId(),
+ getAverageFormat(averMark));
+ sessionTotalMsgMap.put(session.getSessionId(),
+ new Integer(totalMsg));
+ }
+ request.setAttribute("topicList", sessionTopicsMap);
+ request.setAttribute("markAverage", sessionAvaMarkMap);
+ request.setAttribute("totalMessage", sessionTotalMsgMap);
+ return mapping.findForward("success");
+ }
+
+ /**
+ * View all messages under one topic.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewTopicTree(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+ Long rootTopicId = WebUtil.readLongParam(request, WikiConstants.ATTR_TOPIC_ID);
+ wikiService = getWikiService();
+ // get root topic list
+ List msgDtoList = wikiService.getTopicThread(rootTopicId);
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC_THREAD, msgDtoList);
+
+ return mapping.findForward("success");
+ }
+
+ private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ Long uid = WebUtil.readLongParam(request, WikiConstants.ATTR_USER_UID);
+ Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);
+
+ WikiUser user = wikiService.getUser(uid);
+ NotebookEntry notebookEntry = wikiService.getEntry(sessionID,
+ CoreNotebookConstants.NOTEBOOK_TOOL,
+ WikiConstants.TOOL_SIGNATURE, user.getUserId().intValue());
+
+ WikiToolSession session = wikiService.getSessionBySessionId(sessionID);
+
+ UserDTO userDTO = new UserDTO(user);
+ if(notebookEntry == null){
+ userDTO.setFinishReflection(false);
+ userDTO.setReflect(null);
+ }else{
+ userDTO.setFinishReflection(true);
+ userDTO.setReflect(notebookEntry.getEntry());
+ }
+ userDTO.setReflectInstrctions(session.getWiki().getReflectInstructions());
+
+ request.setAttribute("userDTO", userDTO);
+ return mapping.findForward("success");
+ }
+ /**
+ * View topic subject, content and attachement.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewTopic(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+
+ Long msgUid = new Long(WebUtil.readLongParam(request,
+ WikiConstants.ATTR_TOPIC_ID));
+
+ wikiService = getWikiService();
+ Message topic = wikiService.getMessage(msgUid);
+
+ request.setAttribute(WikiConstants.AUTHORING_TOPIC, MessageDTO
+ .getMessageDTO(topic));
+ return mapping.findForward("success");
+ }
+
+
+
+ private ActionForward releaseMark(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
+ //get service then update report table
+ wikiService = getWikiService();
+ Long sessionID =new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID));
+ wikiService.releaseMarksForSession(sessionID);
+ try {
+ PrintWriter out = response.getWriter();
+ WikiToolSession session = wikiService.getSessionBySessionId(sessionID);
+ String sessionName = "";
+ if(session != null)
+ sessionName = session.getSessionName();
+ out.write(getMessageService().getMessage("msg.mark.released",new String[]{sessionName}));
+ out.flush();
+ } catch (IOException e) {
+ }
+
+ return null;
+ }
+
+ // ==========================================================================================
+ // View and update marks methods
+ // ==========================================================================================
+
+ /**
+ * View all user marks for a special Session ID
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewAllMarks(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ //only one param for session scope marks
+ Long sessionID = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID));
+
+ //create sessionMap
+ SessionMap sessionMap = new SessionMap();
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+ sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionID);
+ sessionMap.put(WikiConstants.PARAM_UPDATE_MODE, WikiConstants.MARK_UPDATE_FROM_SESSION);
+
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID());
+
+ //get tool session scope topics
+ wikiService = getWikiService();
+ List topicList = wikiService.getAllTopicsFromSession(sessionID);
+
+ Map topicsByUser = getTopicsSortedByAuthor(topicList);
+ request.setAttribute(WikiConstants.ATTR_REPORT, topicsByUser);
+ return mapping.findForward("success");
+ }
+ /**
+ * View a special user's mark
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward viewUserMark(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ Long userUid = new Long(WebUtil.readLongParam(request,WikiConstants.USER_UID));
+ Long sessionId = new Long(WebUtil.readLongParam(request,AttributeNames.PARAM_TOOL_SESSION_ID));
+
+ //create sessionMap
+ SessionMap sessionMap = new SessionMap();
+ request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
+
+ sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId);
+ sessionMap.put(WikiConstants.PARAM_UPDATE_MODE, WikiConstants.MARK_UPDATE_FROM_USER);
+
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID());
+ //get this user's all topics
+ wikiService = getWikiService();
+ List messageList = wikiService.getMessagesByUserUid(userUid, sessionId);
+ WikiUser user = wikiService.getUser(userUid);
+
+ // each back to web page
+ Map> report = new TreeMap(this.new WikiUserComparator());
+ report.put(user,messageList);
+ request.setAttribute(WikiConstants.ATTR_REPORT, report);
+
+ return mapping.findForward("success");
+ }
+
+
+ /**
+ * Edit a special user's mark.
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward editMark(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ MarkForm markForm = (MarkForm) form;
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID());
+ String updateMode = (String) sessionMap.get(WikiConstants.PARAM_UPDATE_MODE);
+ //view wiki mode
+ if(StringUtils.isBlank(updateMode)){
+ sessionMap.put(WikiConstants.PARAM_UPDATE_MODE, WikiConstants.MARK_UPDATE_FROM_FORUM);
+ sessionMap.put(WikiConstants.ATTR_ROOT_TOPIC_UID,markForm.getTopicID());
+ }
+
+ // get Message and User from database
+ wikiService = getWikiService();
+ Message msg = wikiService.getMessage(markForm.getTopicID());
+ WikiUser user = msg.getCreatedBy();
+
+ // echo back to web page
+ if (msg.getReport() != null) {
+ if (msg.getReport().getMark() != null)
+ markForm.setMark(msg.getReport().getMark().toString());
+ else
+ markForm.setMark("");
+ markForm.setComment(msg.getReport().getComment());
+ }
+
+ // each back to web page
+ request.setAttribute(WikiConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg));
+ request.setAttribute(WikiConstants.ATTR_USER, user);
+
+ return mapping.findForward("success");
+ }
+
+ /**
+ * Update mark for a special user
+ *
+ * @param mapping
+ * @param form
+ * @param request
+ * @param response
+ * @return
+ */
+ private ActionForward updateMark(ActionMapping mapping, ActionForm form,
+ HttpServletRequest request, HttpServletResponse response) {
+ MarkForm markForm = (MarkForm) form;
+
+ request.setAttribute(WikiConstants.ATTR_SESSION_MAP_ID, markForm.getSessionMapID());
+ String mark = markForm.getMark();
+ ActionMessages errors = new ActionMessages();
+ if (StringUtils.isBlank(mark)) {
+ ActionMessage error = new ActionMessage("error.valueReqd");
+ errors.add("report.mark", error);
+ }else if(!NumberUtils.isNumber(mark)){
+ ActionMessage error = new ActionMessage("error.mark.needNumber");
+ errors.add("report.mark", error);
+ }else {
+ try{
+ Float.parseFloat(mark);
+ }catch(Exception e){
+ ActionMessage error = new ActionMessage("error.mark.invalid.number");
+ errors.add("report.mark", error);
+ }
+ }
+
+ wikiService = getWikiService();
+ // echo back to web page
+ Message msg = wikiService.getMessage(markForm.getTopicID());
+ WikiUser user = msg.getCreatedBy();
+
+ request.setAttribute(WikiConstants.ATTR_USER, user);
+ if(!errors.isEmpty()){
+ // each back to web page
+ request.setAttribute(WikiConstants.ATTR_TOPIC, MessageDTO.getMessageDTO(msg));
+ saveErrors(request, errors);
+ return mapping.getInputForward();
+ }
+
+ //update message report
+
+ wikiService = getWikiService();
+ WikiReport report = msg.getReport();
+ if (report == null) {
+ report = new WikiReport();
+ msg.setReport(report);
+ }
+
+ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(markForm.getSessionMapID());
+ Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID);
+ String updateMode = (String) sessionMap.get(WikiConstants.PARAM_UPDATE_MODE);
+
+ //only session has been released mark, the data of mark release will have value.
+ WikiToolSession toolSession = wikiService.getSessionBySessionId(sessionId);
+ if(toolSession.isMarkReleased())
+ report.setDateMarksReleased(new Date());
+
+ report.setMark(new Float(Float.parseFloat(mark)));
+ report.setComment(markForm.getComment());
+ wikiService.updateTopic(msg);
+
+ //echo back to topic list page: it depends which screen is come from: view special user mark, or view all user marks.
+ if(StringUtils.equals(updateMode, WikiConstants.MARK_UPDATE_FROM_SESSION)){
+ List topicList = wikiService.getAllTopicsFromSession(sessionId);
+ Map topicsByUser = getTopicsSortedByAuthor(topicList);
+ request.setAttribute(WikiConstants.ATTR_REPORT, topicsByUser);
+ //listMark or listAllMark.
+ return mapping.findForward("success");
+ }else if(StringUtils.equals(updateMode, WikiConstants.MARK_UPDATE_FROM_USER)){
+ List messageList = wikiService.getMessagesByUserUid(user.getUid(), sessionId);
+ Map> topicMap = new TreeMap(this.new WikiUserComparator());
+ topicMap.put(user,messageList);
+ request.setAttribute(WikiConstants.ATTR_REPORT, topicMap);
+ //listMark or listAllMark.
+ return mapping.findForward("success");
+ }else{ //mark from view wiki
+ return mapping.findForward("viewTopic");
+ }
+
+ }
+
+ // ==========================================================================================
+ // Utility methods
+ // ==========================================================================================
+
+ /**
+ * Get Wiki Service.
+ *
+ * @return
+ */
+ private IWikiService getWikiService() {
+ if (wikiService == null) {
+ WebApplicationContext wac = WebApplicationContextUtils
+ .getRequiredWebApplicationContext(getServlet()
+ .getServletContext());
+ wikiService = (IWikiService) wac
+ .getBean(WikiConstants.FORUM_SERVICE);
+ }
+ return wikiService;
+ }
+
+ /**
+ * @param topicList
+ * @return
+ */
+ private Map getTopicsSortedByAuthor(List topicList) {
+ Map> topicsByUser = new TreeMap(this.new WikiUserComparator());
+ Iterator iter = topicList.iterator();
+ wikiService = getWikiService();
+ while (iter.hasNext()) {
+ MessageDTO dto = (MessageDTO) iter.next();
+ if(dto.getMessage().getIsAuthored())
+ continue;
+ dto.getMessage().getReport();
+ WikiUser user = (WikiUser) dto.getMessage().getCreatedBy().clone();
+ List list = (List) topicsByUser.get(user);
+ if (list == null) {
+ list = new ArrayList();
+ topicsByUser.put(user, list);
+ }
+ list.add(dto);
+ }
+ return topicsByUser;
+ }
+
+ /**
+ * Get formatted average mark.
+ *
+ * @param aver
+ * @return
+ */
+ private Float getAverageFormat(float aver) {
+ try {
+ NumberFormat format = NumberFormat.getInstance();
+ format.setMaximumFractionDigits(1);
+ return format.parse(format.format(aver)).floatValue();
+ } catch (Exception e) {
+ return new Float(0);
+ }
+ }
+ /**
+ * Return ResourceService bean.
+ */
+ private MessageService getMessageService() {
+ WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext());
+ return (MessageService) wac.getBean("wikiMessageService");
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MarkForm.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MarkForm.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MarkForm.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,68 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.web.forms;
+
+import org.apache.struts.action.ActionForm;
+/**
+ * @struts.form name="markForm"
+ * @author Steve.Ni
+ *
+ * @version $Revision$
+ */
+public class MarkForm extends ActionForm{
+ private static final long serialVersionUID = -4967675292027554366L;
+
+ private String mark;
+ private String comment;
+
+ private Long topicID;
+ private String sessionMapID;
+
+ public String getComment() {
+ return comment;
+ }
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+ public String getMark() {
+ return mark;
+ }
+ public void setMark(String mark) {
+ this.mark = mark;
+ }
+ public String getSessionMapID() {
+ return sessionMapID;
+ }
+ public void setSessionMapID(String sessionMapID) {
+ this.sessionMapID = sessionMapID;
+ }
+ public Long getTopicID() {
+ return topicID;
+ }
+ public void setTopicID(Long topicID) {
+ this.topicID = topicID;
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MessageForm.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MessageForm.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/MessageForm.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,175 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.web.forms;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.poi.util.StringUtil;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.upload.FormFile;
+import org.apache.struts.validator.ValidatorForm;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.util.FileUtil;
+import org.lamsfoundation.lams.util.FileValidatorUtil;
+
+/**
+ *
+ * Message Form.
+ * @struts.form name="messageForm"
+ *
+ * User: conradb
+ * Date: 10/06/2005
+ * Time: 15:44:47
+ */
+public class MessageForm extends ValidatorForm {
+ private static final long serialVersionUID = -9054365604649146734L;
+ private static Logger logger = Logger.getLogger(MessageForm.class.getName());
+
+ protected Message message;
+ protected String sessionMapID;
+ protected Long wikiId;
+ protected Long parentId;
+ protected Long topicId;
+
+ private boolean hasAttachment;
+ //attachment file name
+ private String attachmentName;
+ //Message attachment file
+ private FormFile attachmentFile;
+
+ public MessageForm() {
+ message = new Message();
+ }
+ /**
+ * MessageForm validation method from STRUCT interface.
+ *
+ */
+ public ActionErrors validate(ActionMapping mapping,
+ javax.servlet.http.HttpServletRequest request) {
+ ActionErrors errors = new ActionErrors();
+ try{
+ if (StringUtils.isBlank(message.getSubject())) {
+ ActionMessage error = new ActionMessage("error.wikiTitle.required");
+ errors.add("message.subject", error);
+ }
+ if (StringUtils.isBlank(message.getBody())) {
+ ActionMessage error = new ActionMessage("error.pageContent.required");
+ errors.add("message.body", error);
+ }
+
+
+// validate item size
+ boolean largeFile = true;
+ if(request.getRequestURI().indexOf("/learning/") != -1){
+ if(this.getAttachmentFile() != null && FileUtil.isExecutableFile(this.getAttachmentFile().getFileName())){
+ ActionMessage error = new ActionMessage("error.attachment.executable");
+ errors.add("message.attachment", error);
+ }
+ largeFile = false;
+ }
+
+ FileValidatorUtil.validateFileSize(this.getAttachmentFile(), largeFile,"message.attachment", errors );
+
+ } catch (Exception e) {
+ logger.error("", e);
+ }
+ return errors;
+ }
+
+ //-------------------------get/set methods----------------
+ public void setMessage(Message message) {
+ this.message = message;
+ if(message != null){
+ if(message.getAttachments() != null
+ && message.getAttachments().size() > 0){
+ hasAttachment = true;
+ attachmentName = ((Attachment)message.getAttachments().iterator().next()).getFileName();
+ }else{
+ hasAttachment = false;
+ attachmentName = null;
+ }
+ }
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public void setWikiId(Long wikiId) {
+ this.wikiId = wikiId;
+ }
+
+ public Long getWikiId() {
+ return this.wikiId;
+ }
+
+ public void setParentId(Long parentId) {
+ this.parentId = parentId;
+ }
+
+ public Long getParentId() {
+ return this.parentId;
+ }
+
+ public void setTopicId(Long topicId) {
+ this.topicId = topicId;
+ }
+
+ public Long getTopicId() {
+ return this.topicId;
+ }
+
+
+ public String getAttachmentName() {
+ return attachmentName;
+ }
+
+ public void setAttachmentName(String attachmentName) {
+ this.attachmentName = attachmentName;
+ }
+
+ public FormFile getAttachmentFile() {
+ return attachmentFile;
+ }
+
+ public void setAttachmentFile(FormFile attachmentFile) {
+ this.attachmentFile = attachmentFile;
+ }
+ public String getSessionMapID() {
+ return sessionMapID;
+ }
+ public void setSessionMapID(String sessionMapID) {
+ this.sessionMapID = sessionMapID;
+ }
+ public boolean isHasAttachment() {
+ return hasAttachment;
+ }
+ public void setHasAttachment(boolean hasAttachment) {
+ this.hasAttachment = hasAttachment;
+ }
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/ReflectionForm.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/ReflectionForm.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/ReflectionForm.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,73 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.web.forms;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.validator.ValidatorForm;
+
+/**
+ *
+ * Reflection Form.
+ * @struts.form name="reflectionForm"
+ *
+ */
+public class ReflectionForm extends ValidatorForm {
+ private static final long serialVersionUID = -9054365604649146735L;
+ private static Logger logger = Logger.getLogger(ReflectionForm.class.getName());
+
+ private Integer userID;
+ private String sessionMapID;
+ private String entryText;
+
+ public String getEntryText() {
+ return entryText;
+ }
+
+ public void setEntryText(String entryText) {
+ this.entryText = entryText;
+ }
+
+ public Integer getUserID() {
+ return userID;
+ }
+
+ public void setUserID(Integer userUid) {
+ this.userID = userUid;
+ }
+
+ public String getSessionMapID() {
+ return sessionMapID;
+ }
+
+ public void setSessionMapID(String sessionMapID) {
+ this.sessionMapID = sessionMapID;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/WikiForm.java
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/WikiForm.java (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/web/forms/WikiForm.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,188 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+package org.lamsfoundation.lams.tool.wiki.web.forms;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.upload.FormFile;
+import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler;
+import org.lamsfoundation.lams.tool.ToolAccessMode;
+import org.lamsfoundation.lams.tool.wiki.persistence.Attachment;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.util.UploadFileUtil;
+import org.lamsfoundation.lams.web.util.AttributeNames;
+
+/**
+ *
+ * Message Form.
+ * @struts.form name="wikiForm"
+ *
+ * User: conradb
+ * Date: 10/06/2005
+ * Time: 15:44:36
+ */
+public class WikiForm extends ActionForm {
+ private static final long serialVersionUID = -6054354910960460120L;
+ private static Logger logger = Logger.getLogger(WikiForm.class.getName());
+
+ //Wiki fields
+ private Long toolContentID;
+ private String currentTab;
+ private String sessionMapID;
+ private String contentFolderID;
+
+ private FormFile offlineFile;
+ private FormFile onlineFile;
+ private List onlineFileList;
+ private List offlineFileList;
+
+ private Wiki wiki;
+
+ /**
+ * Empty construction method
+ */
+ public WikiForm() {
+
+ this.toolContentID = new Long(0);
+ this.wiki = new Wiki();
+ this.wiki.setTitle("");
+ this.currentTab = "";
+ }
+ /**
+ * Initialize this form by given Wiki instance.
+ * @param wiki
+ */
+ public void setWiki(Wiki wiki) {
+ this.wiki = wiki;
+ //set Form special varaible from given wiki
+ if(wiki != null){
+ this.toolContentID = wiki.getContentId();
+ onlineFileList = new ArrayList();
+ offlineFileList = new ArrayList();
+ Set fileSet = wiki.getAttachments();
+ if(fileSet != null){
+ Iterator iter = fileSet.iterator();
+ while(iter.hasNext()){
+ Attachment file = (Attachment) iter.next();
+ if(StringUtils.equalsIgnoreCase(file.getFileType(),IToolContentHandler.TYPE_OFFLINE))
+ offlineFileList.add(file);
+ else
+ onlineFileList.add(file);
+ }
+ }
+ }else{
+ logger.error("Initial WikiForm failed by null value of Wiki.");
+ }
+
+ }
+
+ public void reset(ActionMapping mapping, HttpServletRequest request){
+ wiki.setAllowEdit(false);
+ wiki.setAllowAnonym(false);
+ //wiki.setAllowRichEditor(false);
+ wiki.setLimitedInput(false);
+ wiki.setLockWhenFinished(false);
+ wiki.setAllowNewTopic(false);
+ wiki.setAllowUpload(false);
+ wiki.setReflectOnActivity(false);
+ }
+ //-------------------------get/set methods----------------
+ public Wiki getWiki() {
+ return wiki;
+ }
+
+ public void setOnlineFile(FormFile onlineFile) {
+ this.onlineFile = onlineFile;
+ }
+
+ public FormFile getOnlineFile() {
+ return onlineFile;
+ }
+
+ public void setOfflineFile(FormFile offlineFile) {
+ this.offlineFile = offlineFile;
+ }
+
+ public FormFile getOfflineFile() {
+ return offlineFile;
+ }
+
+ public String getCurrentTab() {
+ return currentTab;
+ }
+
+ public void setCurrentTab(String currentTab) {
+ this.currentTab = currentTab;
+ }
+
+ public Long getToolContentID() {
+ return toolContentID;
+ }
+
+ public void setToolContentID(Long toolContentID) {
+ this.toolContentID = toolContentID;
+ }
+
+ public List getOfflineFileList() {
+ return offlineFileList;
+ }
+
+ public void setOfflineFileList(List offlineFileList) {
+ this.offlineFileList = offlineFileList;
+ }
+
+ public List getOnlineFileList() {
+ return onlineFileList;
+ }
+
+ public void setOnlineFileList(List onlineFileList) {
+ this.onlineFileList = onlineFileList;
+ }
+ public String getSessionMapID() {
+ return sessionMapID;
+ }
+ public void setSessionMapID(String sessionMapID) {
+ this.sessionMapID = sessionMapID;
+ }
+ public String getContentFolderID() {
+ return contentFolderID;
+ }
+ public void setContentFolderID(String contentFolderID) {
+ this.contentFolderID = contentFolderID;
+ }
+
+}
Index: lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml
===================================================================
diff -u
--- lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml (revision 0)
+++ lams_tool_wiki_orig/src/java/org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+ org.lamsfoundation.lams.tool.wiki.ApplicationResources
+
+
+
+
+
+
+
+
+
+
+
+ org/lamsfoundation/lams/tool/wiki/persistence/Wiki.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/Message.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/Attachment.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/WikiUser.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/WikiReport.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/WikiToolSession.hbm.xml
+ org/lamsfoundation/lams/tool/wiki/persistence/MessageSeq.hbm.xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+ PROPAGATION_REQUIRED,-java.lang.Exception
+
+
+
+
+
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/ActionBaseTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/BaseTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/DAOBaseTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/TestUtils.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/action/AuthorActionTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/dao/MessageDAOTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/dao/WikiDAOTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/dao/WikiToolSessionDAOTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/dao/WikiUserDAOTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Fisheye: Tag 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff refers to a dead (removed) revision in file `lams_tool_wiki_orig/test/java/org/lams/lams/tool/wiki/test/service/WikiServiceTest.java'.
Fisheye: No comparison available. Pass `N' to diff?
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/ActionBaseTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/ActionBaseTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/ActionBaseTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test;
+
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+import servletunit.struts.MockStrutsTestCase;
+
+public class ActionBaseTest extends MockStrutsTestCase {
+
+ public void setUp()throws Exception{
+ super.setUp();
+ ContextLoader ctxLoader = new ContextLoader();
+ context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM,
+ XmlWebApplicationContext.class.getName());
+ context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
+ "org/lamsfoundation/lams/localApplicationContext.xml," +
+ "org/lamsfoundation/lams/contentrepository/applicationContext.xml," +
+ "org/lamsfoundation/lams/toolApplicationContext.xml," +
+ "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml," +
+ "org/lamsfoundation/lams/learning/learningApplicationContext.xml,"+
+ "org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml,");
+ ctxLoader.initWebApplicationContext(context);
+ }
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/BaseTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/BaseTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/BaseTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test;
+
+import org.lamsfoundation.lams.test.AbstractLamsTestCase;
+
+public class BaseTest extends AbstractLamsTestCase {
+
+ public BaseTest(String name) {
+ super(name);
+ }
+
+ protected String[] getContextConfigLocation() {
+ return new String[] {"org/lamsfoundation/lams/localApplicationContext.xml",
+ "org/lamsfoundation/lams/contentrepository/applicationContext.xml",
+ "org/lamsfoundation/lams/toolApplicationContext.xml",
+ "org/lamsfoundation/lams/lesson/lessonApplicationContext.xml",
+ "org/lamsfoundation/lams/learning/learningApplicationContext.xml",
+ "org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml"};
+ }
+
+ protected String getHibernateSessionFactoryName() {
+ return "wikiSessionFactory";
+ }
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/DAOBaseTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/DAOBaseTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/DAOBaseTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSessionDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUserDao;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiMessageDao;
+
+public class DAOBaseTest extends BaseTest {
+
+ protected WikiDao wikiDao;
+ protected WikiToolSessionDao wikiToolSessionDao;
+ protected WikiUserDao wikiUserDao;
+ protected WikiMessageDao wikiMessageDao;
+
+ public DAOBaseTest(String name) {
+ super(name);
+ }
+ protected void setUp() throws Exception {
+ super.setUp();
+ wikiDao = (WikiDao) context.getBean("wikiDao");
+ wikiToolSessionDao = (WikiToolSessionDao) context.getBean("wikiToolSessionDao");
+ wikiUserDao = (WikiUserDao) context.getBean("wikiUserDao");
+ wikiMessageDao = (WikiMessageDao) context.getBean("wikiMessageDao");
+ }
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/TestUtils.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/TestUtils.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/TestUtils.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,73 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+public class TestUtils {
+
+ public static Wiki getWikiA(){
+ Wiki wiki = new Wiki();
+ wiki.setContentId(new Long(1));
+
+ return wiki;
+
+ }
+ public static WikiUser getUserA(){
+ WikiUser user = new WikiUser();
+ user.setFirstName("UserA");
+ user.setUserId(new Long(1));
+
+ return user;
+ }
+ public static WikiToolSession getSessionA(){
+ WikiToolSession session = new WikiToolSession();
+ session.setSessionId(new Long(1));
+ session.setStatus(1);
+ return session;
+ }
+ public static WikiToolSession getSessionB(){
+ WikiToolSession session = new WikiToolSession();
+ session.setSessionId(new Long(2));
+ session.setStatus(2);
+ return session;
+ }
+ public static Message getMessageA() {
+ Message msg = new Message();
+ msg.setBody("bodyA");
+ msg.setSubject("subjectA");
+ return msg;
+ }
+ public static Message getMessageB() {
+ Message msg = new Message();
+ msg.setBody("bodyB");
+ msg.setSubject("subjectB");
+ return msg;
+ }
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/action/AuthorActionTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/action/AuthorActionTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/action/AuthorActionTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.action;
+
+import org.lamsfoundation.lams.tool.wiki.test.ActionBaseTest;
+
+public class AuthorActionTest extends ActionBaseTest{
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/MessageDAOTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/MessageDAOTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/MessageDAOTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,180 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.dao;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.test.DAOBaseTest;
+import org.lamsfoundation.lams.tool.wiki.test.TestUtils;
+
+public class MessageDAOTest extends DAOBaseTest{
+
+ public MessageDAOTest(String name) {
+ super(name);
+ }
+
+ public void testSave(){
+ Message msg = TestUtils.getMessageA();
+ wikiMessageDao.saveOrUpdate(msg);
+ Message tmsg = wikiMessageDao.getById(msg.getUid());
+ assertEquals(msg,tmsg);
+
+ wikiMessageDao.delete(msg.getUid());
+ }
+ public void testDelete(){
+ Message msg = TestUtils.getMessageA();
+ wikiMessageDao.saveOrUpdate(msg);
+ wikiMessageDao.delete(msg.getUid());
+
+ assertNull(wikiMessageDao.getById(msg.getUid()));
+
+ }
+
+ public void testGetBySession(){
+ WikiToolSession sessionA = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(sessionA);
+
+ Message msgA = TestUtils.getMessageA();
+ msgA.setToolSession(sessionA);
+ wikiMessageDao.saveOrUpdate(msgA);
+ Message msgB = TestUtils.getMessageB();
+ msgB.setToolSession(sessionA);
+ wikiMessageDao.saveOrUpdate(msgB);
+
+ List list = wikiMessageDao.getBySession(new Long(1));
+
+ assertEquals(2,list.size());
+ assertEquals(list.get(0),msgA);
+ assertEquals(list.get(1),msgB);
+
+ //remove test data
+ wikiMessageDao.delete(msgA.getUid());
+ wikiMessageDao.delete(msgB.getUid());
+ wikiToolSessionDao.delete(sessionA);
+ }
+ public void testGetBySessionAndUser(){
+ WikiToolSession sessionA = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(sessionA);
+ WikiUser userA = TestUtils.getUserA();
+ wikiUserDao.save(userA);
+
+ Message msgA = TestUtils.getMessageA();
+ msgA.setToolSession(sessionA);
+ msgA.setCreatedBy(userA);
+ wikiMessageDao.saveOrUpdate(msgA);
+ Message msgB = TestUtils.getMessageB();
+ msgB.setToolSession(sessionA);
+ msgB.setCreatedBy(userA);
+ wikiMessageDao.saveOrUpdate(msgB);
+
+ List list = wikiMessageDao.getByUserAndSession(userA.getUid(),sessionA.getSessionId());
+
+ assertEquals(2,list.size());
+ assertEquals(list.get(0),msgA);
+ assertEquals(list.get(1),msgB);
+
+ //remove test data
+ wikiMessageDao.delete(msgA.getUid());
+ wikiMessageDao.delete(msgB.getUid());
+ wikiToolSessionDao.delete(sessionA);
+ wikiUserDao.delete(userA);
+ }
+ public void testGetFromAuthor(){
+ WikiUser userA = TestUtils.getUserA();
+ wikiUserDao.save(userA);
+ Wiki wikiA = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wikiA);
+
+ Message msgA = TestUtils.getMessageA();
+ msgA.setCreatedBy(userA);
+ msgA.setWiki(wikiA);
+ msgA.setIsAuthored(true);
+ wikiMessageDao.saveOrUpdate(msgA);
+ Message msgB = TestUtils.getMessageB();
+ msgB.setWiki(wikiA);
+ msgB.setCreatedBy(userA);
+ msgB.setIsAuthored(false);
+ wikiMessageDao.saveOrUpdate(msgB);
+
+ List list = wikiMessageDao.getTopicsFromAuthor(wikiA.getUid());
+
+ assertEquals(1,list.size());
+ assertEquals(list.get(0),msgA);
+
+ //remove test data
+ wikiMessageDao.delete(msgA.getUid());
+ wikiMessageDao.delete(msgB.getUid());
+ wikiUserDao.delete(userA);
+ wikiDao.delete(wikiA);
+
+ }
+ public void testGetRootTopics(){
+ WikiToolSession sessionA = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(sessionA);
+
+ Message msgA = TestUtils.getMessageA();
+ msgA.setToolSession(sessionA);
+ wikiMessageDao.saveOrUpdate(msgA);
+
+ Message msgB = TestUtils.getMessageB();
+ msgB.setParent(msgA);
+ msgB.setToolSession(sessionA);
+ wikiMessageDao.saveOrUpdate(msgB);
+
+ List list = wikiMessageDao.getRootTopics(sessionA.getSessionId());
+
+ assertEquals(1,list.size());
+ assertEquals(list.get(0),msgA);
+
+ //remove test data
+ wikiMessageDao.delete(msgB.getUid());
+ wikiMessageDao.delete(msgA.getUid());
+ wikiToolSessionDao.delete(sessionA);
+ }
+ public void testGetChildrenTopics(){
+ Message msgA = TestUtils.getMessageA();
+ wikiMessageDao.saveOrUpdate(msgA);
+
+ Message msgB = TestUtils.getMessageB();
+ msgB.setParent(msgA);
+ wikiMessageDao.saveOrUpdate(msgB);
+
+ List list = wikiMessageDao.getChildrenTopics(msgA.getUid());
+
+ assertEquals(1,list.size());
+ assertEquals(list.get(0),msgB);
+
+ //remove test data
+ wikiMessageDao.delete(msgB.getUid());
+ wikiMessageDao.delete(msgA.getUid());
+ }
+
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiDAOTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiDAOTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiDAOTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.dao;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.test.DAOBaseTest;
+import org.lamsfoundation.lams.tool.wiki.test.TestUtils;
+
+public class WikiDAOTest extends DAOBaseTest{
+
+ public WikiDAOTest(String name) {
+ super(name);
+ }
+
+ public void testSave(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+
+ Wiki tWiki = wikiDao.getById(wiki.getUid());
+ assertEquals(tWiki.getContentId(),new Long(1));
+
+ //remove test data
+ wikiDao.delete(wiki);
+ }
+
+ public void testDelete(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+
+ wikiDao.delete(wiki);
+
+ assertNull(wikiDao.getById(wiki.getUid()));
+ }
+ public void testGetByContentId(){
+
+ Wiki wiki = TestUtils.getWikiA();
+
+ wikiDao.saveOrUpdate(wiki);
+ Wiki twiki = wikiDao.getByContentId(wiki.getContentId());
+ assertEquals(twiki, wiki);
+
+ //remove test data
+ wikiDao.delete(wiki);
+
+ }
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiToolSessionDAOTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiToolSessionDAOTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiToolSessionDAOTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,96 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.dao;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.test.DAOBaseTest;
+import org.lamsfoundation.lams.tool.wiki.test.TestUtils;
+
+public class WikiToolSessionDAOTest extends DAOBaseTest{
+
+ public WikiToolSessionDAOTest(String name) {
+ super(name);
+
+ }
+
+ public void testSave(){
+ WikiToolSession session = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ WikiToolSession tSession = wikiToolSessionDao.getBySessionId(session.getSessionId());
+
+ assertEquals(session,tSession);
+
+ //remove test data
+ wikiToolSessionDao.delete(session);
+
+ }
+
+ public void testDelete(){
+ WikiToolSession session = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(session);
+ wikiToolSessionDao.delete(session);
+
+ assertNull(wikiToolSessionDao.getBySessionId(session.getSessionId()));
+ }
+
+ public void testGetByContentId(){
+ Wiki wikiA = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wikiA);
+
+ WikiToolSession sessionA = TestUtils.getSessionA();
+ sessionA.setWiki(wikiA);
+ wikiToolSessionDao.saveOrUpdate(sessionA);
+ WikiToolSession sessionB = TestUtils.getSessionB();
+ sessionB.setWiki(wikiA);
+ wikiToolSessionDao.saveOrUpdate(sessionB);
+
+ List list = wikiToolSessionDao.getByContentId(new Long(1));
+
+ assertEquals(2,list.size());
+ assertEquals(list.get(0),sessionA);
+ assertEquals(list.get(1),sessionB);
+ //remove test data
+ wikiToolSessionDao.delete(sessionA);
+ wikiToolSessionDao.delete(sessionB);
+ wikiDao.delete(wikiA);
+ }
+
+ public void testGetBySessionId(){
+ WikiToolSession session = TestUtils.getSessionA();
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ WikiToolSession tSession = wikiToolSessionDao.getBySessionId(session.getSessionId());
+
+ assertEquals(session,tSession);
+
+ //remove test data
+ wikiToolSessionDao.delete(session);
+ }
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiUserDAOTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiUserDAOTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/dao/WikiUserDAOTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,56 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.dao;
+
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.test.DAOBaseTest;
+import org.lamsfoundation.lams.tool.wiki.test.TestUtils;
+
+public class WikiUserDAOTest extends DAOBaseTest{
+
+ public WikiUserDAOTest(String name) {
+ super(name);
+ }
+ public void testSave(){
+ WikiUser user = TestUtils.getUserA();
+ wikiUserDao.save(user);
+ WikiUser tUser = wikiUserDao.getByUid(user.getUid());
+ assertEquals(tUser,user);
+
+ //remove test data
+ wikiUserDao.delete(user);
+ }
+ public void testGetByUserId(){
+ WikiUser user = TestUtils.getUserA();
+ wikiUserDao.save(user);
+ WikiUser tUser = wikiUserDao.getByUserId(new Long(1));
+ assertEquals(tUser,user);
+
+ //remove test data
+ wikiUserDao.delete(user);
+ }
+
+}
Index: lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/service/WikiServiceTest.java
===================================================================
diff -u
--- lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/service/WikiServiceTest.java (revision 0)
+++ lams_tool_wiki_orig/test/java/org/lamsfoundation/lams/tool/wiki/test/service/WikiServiceTest.java (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -0,0 +1,207 @@
+/****************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ * License Information: http://lamsfoundation.org/licensing/lams/2.0/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2.0
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ****************************************************************
+ */
+
+/* $$Id$$ */
+
+package org.lamsfoundation.lams.tool.wiki.test.service;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.tool.ToolContentManager;
+import org.lamsfoundation.lams.tool.ToolSessionManager;
+import org.lamsfoundation.lams.tool.exception.DataMissingException;
+import org.lamsfoundation.lams.tool.exception.ToolException;
+import org.lamsfoundation.lams.tool.wiki.dto.MessageDTO;
+import org.lamsfoundation.lams.tool.wiki.persistence.Wiki;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiToolSession;
+import org.lamsfoundation.lams.tool.wiki.persistence.WikiUser;
+import org.lamsfoundation.lams.tool.wiki.persistence.Message;
+import org.lamsfoundation.lams.tool.wiki.service.IWikiService;
+import org.lamsfoundation.lams.tool.wiki.test.DAOBaseTest;
+import org.lamsfoundation.lams.tool.wiki.test.TestUtils;
+
+public class WikiServiceTest extends DAOBaseTest{
+ private IWikiService wikiService;
+ private ToolContentManager contentManager;
+ private ToolSessionManager sessionManager;
+
+ public WikiServiceTest(String name) {
+ super(name);
+ }
+ public void setUp()throws Exception{
+ super.setUp();
+ wikiService = (IWikiService)context.getBean("wikiService");
+ contentManager = (ToolContentManager) wikiService;
+ sessionManager = (ToolSessionManager) wikiService;
+ }
+ public void testUpdateWiki(){
+ WikiUser user = TestUtils.getUserA();
+ wikiUserDao.save(user);
+
+ Wiki wiki = TestUtils.getWikiA();
+ wiki.setCreatedBy(user);
+ wikiService.updateWiki(wiki);
+
+ //get back
+ Wiki tWiki = wikiService.getWiki(wiki.getUid());
+ assertEquals(tWiki.getContentId(),new Long(1));
+ assertEquals(tWiki.getCreatedBy(),user);
+
+ //remove test data
+ wikiDao.delete(wiki);
+ wikiUserDao.delete(user);
+ }
+ public void testCreateRootTopic(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+ WikiToolSession session = TestUtils.getSessionA();
+ session.setWiki(wiki);
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ Message msg = TestUtils.getMessageA();
+ msg.setWiki(wiki);
+
+ wikiService.createRootTopic(wiki.getUid(),session.getSessionId(),msg);
+ Message tMsg = wikiService.getMessage(msg.getUid());
+ tMsg.setUpdated(msg.getUpdated());
+ assertEquals(tMsg,msg);
+
+ //remove test data
+ wikiService.deleteTopic(msg.getUid());
+ wikiToolSessionDao.delete(session);
+ wikiDao.delete(wiki);
+ }
+ public void testUpdateTopic(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+ WikiToolSession session = TestUtils.getSessionA();
+ session.setWiki(wiki);
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ Message msg = TestUtils.getMessageA();
+ wikiService.createRootTopic(wiki.getUid(),session.getSessionId(),msg);
+
+ msg.setBody("update");
+ Message tMsg = wikiService.updateTopic(msg);
+ //update date will be different
+ tMsg.setUpdated(msg.getUpdated());
+ tMsg.setBody("update");
+ assertEquals(tMsg,msg);
+
+ //remove test data
+ wikiService.deleteTopic(msg.getUid());
+ wikiToolSessionDao.delete(session);
+ wikiDao.delete(wiki);
+ }
+ public void testReplyTopic(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+ WikiToolSession session = TestUtils.getSessionA();
+ session.setWiki(wiki);
+ wikiToolSessionDao.saveOrUpdate(session);
+ WikiUser user = TestUtils.getUserA();
+ wikiUserDao.save(user);
+
+ Message parent = TestUtils.getMessageA();
+ parent.setCreatedBy(user);
+ wikiService.createRootTopic(wiki.getUid(),session.getSessionId(),parent);
+
+ Message msg = TestUtils.getMessageB();
+ msg.setCreatedBy(user);
+ Message tMsg = wikiService.replyTopic(parent.getUid(),session.getSessionId(),msg);
+ List list = wikiService.getTopicThread(parent.getUid());
+ Message child = ((MessageDTO) list.get(1)).getMessage();
+ assertEquals(child,tMsg);
+
+// remove test data
+ wikiService.deleteTopic(parent.getUid());
+ wikiToolSessionDao.delete(session);
+ wikiDao.delete(wiki);
+ wikiUserDao.delete(user);
+
+ }
+ public void testDeleteTopic(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+ WikiToolSession session = TestUtils.getSessionA();
+ session.setWiki(wiki);
+ wikiToolSessionDao.saveOrUpdate(session);
+
+ Message parent = TestUtils.getMessageA();
+ wikiService.createRootTopic(wiki.getUid(),session.getSessionId(),parent);
+
+ Message msg = TestUtils.getMessageB();
+ wikiService.replyTopic(parent.getUid(),session.getSessionId(),msg);
+
+ //delete parent and its children.
+ wikiService.deleteTopic(parent.getUid());
+
+ assertNull(wikiService.getMessage(parent.getUid()));
+ assertNull(wikiService.getMessage(msg.getUid()));
+
+// remove test data
+ wikiToolSessionDao.delete(session);
+ wikiDao.delete(wiki);
+
+ }
+ public void testGetTopicThread(){
+ Wiki wiki = TestUtils.getWikiA();
+ wikiDao.saveOrUpdate(wiki);
+ WikiToolSession session = TestUtils.getSessionA();
+ session.setWiki(wiki);
+ wikiToolSessionDao.saveOrUpdate(session);
+ WikiUser user = TestUtils.getUserA();
+ wikiUserDao.save(user);
+
+ Message parent = TestUtils.getMessageA();
+ parent.setCreatedBy(user);
+ wikiService.createRootTopic(wiki.getUid(),session.getSessionId(),parent);
+
+ Message msg = TestUtils.getMessageB();
+ msg.setCreatedBy(user);
+ wikiService.replyTopic(parent.getUid(),session.getSessionId(),msg);
+
+ List list = wikiService.getRootTopics(session.getSessionId());
+
+ assertEquals(1,list.size());
+ assertEquals(((MessageDTO)list.get(0)).getMessage(),parent);
+
+// remove test data
+ //delete parent and its children.
+ wikiService.deleteTopic(parent.getUid());
+ wikiToolSessionDao.delete(session);
+ wikiDao.delete(wiki);
+ wikiUserDao.delete(user);
+ }
+
+ public void testCreateUser(){
+ WikiUser userA = TestUtils.getUserA();
+ wikiService.createUser(userA);
+ WikiUser user = wikiService.getUser(userA.getUid());
+ assertEquals(userA,user);
+
+
+// remove test data
+ wikiUserDao.delete(userA);
+ }
+}
Index: lams_tool_wiki_orig/web/WEB-INF/struts-config.xml
===================================================================
diff -u -re8343e8d676900d059435abdef072abc89d3b26b -r51ab92ac37624b5c280cbd5f3ae8e3972b8540ff
--- lams_tool_wiki_orig/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision e8343e8d676900d059435abdef072abc89d3b26b)
+++ lams_tool_wiki_orig/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -15,19 +15,19 @@
@@ -54,7 +54,7 @@
@@ -81,31 +81,31 @@
@@ -355,14 +355,14 @@
parameter="tiles:/blank" />
+ type="org.lamsfoundation.lams.tool.wiki.web.actions.ClearSessionAction">
-
+
Index: lams_tool_wiki_orig/web/WEB-INF/web.xml
===================================================================
diff -u -re8343e8d676900d059435abdef072abc89d3b26b -r51ab92ac37624b5c280cbd5f3ae8e3972b8540ff
--- lams_tool_wiki_orig/web/WEB-INF/web.xml (.../web.xml) (revision e8343e8d676900d059435abdef072abc89d3b26b)
+++ lams_tool_wiki_orig/web/WEB-INF/web.xml (.../web.xml) (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -7,7 +7,7 @@
javax.servlet.jsp.jstl.fmt.localizationContext
- org.lams.lams.tool.wiki.ApplicationResources
+ org.lamsfoundation.lams.tool.wiki.ApplicationResourcescontextConfigLocation
@@ -17,7 +17,7 @@
classpath:/org/lamsfoundation/lams/toolApplicationContext.xml
classpath:/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml
classpath:/org/lamsfoundation/lams/learning/learningApplicationContext.xml
- classpath:/org/lams/lams/tool/wiki/wikiApplicationContext.xml
+ classpath:/org/lamsfoundation/lams/tool/wiki/wikiApplicationContext.xml
@@ -76,7 +76,7 @@
exportPortfolio
- org.lams.lams.tool.wiki.web.actions.ExportServlet
+ org.lamsfoundation.lams.tool.wiki.web.actions.ExportServlet
Index: lams_tool_wiki_orig/web/jsps/authoring/authoring.jsp
===================================================================
diff -u -re8343e8d676900d059435abdef072abc89d3b26b -r51ab92ac37624b5c280cbd5f3ae8e3972b8540ff
--- lams_tool_wiki_orig/web/jsps/authoring/authoring.jsp (.../authoring.jsp) (revision e8343e8d676900d059435abdef072abc89d3b26b)
+++ lams_tool_wiki_orig/web/jsps/authoring/authoring.jsp (.../authoring.jsp) (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -1,5 +1,5 @@
<%@ include file="/includes/taglibs.jsp"%>
-<%@ page import="org.lams.lams.tool.wiki.util.WikiConstants"%>
+<%@ page import="org.lamsfoundation.lams.tool.wiki.util.WikiConstants"%>
Index: lams_tool_wiki_orig/web/jsps/authoring/definelater.jsp
===================================================================
diff -u -re8343e8d676900d059435abdef072abc89d3b26b -r51ab92ac37624b5c280cbd5f3ae8e3972b8540ff
--- lams_tool_wiki_orig/web/jsps/authoring/definelater.jsp (.../definelater.jsp) (revision e8343e8d676900d059435abdef072abc89d3b26b)
+++ lams_tool_wiki_orig/web/jsps/authoring/definelater.jsp (.../definelater.jsp) (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -1,5 +1,5 @@
<%@ include file="/common/taglibs.jsp"%>
-<%@ page import="org.lams.lams.tool.wiki.util.WikiConstants"%>
+<%@ page import="org.lamsfoundation.lams.tool.wiki.util.WikiConstants"%>
<%@ page import="java.util.HashSet"%>
<%@ page import="java.util.Set"%>
Index: lams_tool_wiki_orig/web/jsps/monitoring/monitoring.jsp
===================================================================
diff -u -re8343e8d676900d059435abdef072abc89d3b26b -r51ab92ac37624b5c280cbd5f3ae8e3972b8540ff
--- lams_tool_wiki_orig/web/jsps/monitoring/monitoring.jsp (.../monitoring.jsp) (revision e8343e8d676900d059435abdef072abc89d3b26b)
+++ lams_tool_wiki_orig/web/jsps/monitoring/monitoring.jsp (.../monitoring.jsp) (revision 51ab92ac37624b5c280cbd5f3ae8e3972b8540ff)
@@ -1,5 +1,5 @@
<%@ include file="/common/taglibs.jsp"%>
-<%@ page import="org.lams.lams.tool.wiki.util.WikiConstants"%>
+<%@ page import="org.lamsfoundation.lams.tool.wiki.util.WikiConstants"%>