Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml
===================================================================
diff -u -rfcd37060ecca18e6c4a2cac2fa0d888aa968a6ff -r5f1cadc89726925aa93eac489cd88e76439cbc4a
--- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision fcd37060ecca18e6c4a2cac2fa0d888aa968a6ff)
+++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 5f1cadc89726925aa93eac489cd88e76439cbc4a)
@@ -212,6 +212,14 @@
+
+
+
+
getBurningQuestionsByItemUid(Long itemUid);
+ List getBurningQuestionsByContentId(Long scratchieUid, Long sessionId);
ScratchieBurningQuestion getBurningQuestionBySessionAndItem(Long sessionId, Long itemUid);
Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java
===================================================================
diff -u
--- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java (revision 0)
+++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/BurningQuestionLikeDAOHibernate.java (revision 5f1cadc89726925aa93eac489cd88e76439cbc4a)
@@ -0,0 +1,37 @@
+package org.lamsfoundation.lams.tool.scratchie.dao.hibernate;
+
+import java.util.List;
+
+import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO;
+import org.lamsfoundation.lams.tool.scratchie.dao.BurningQuestionLikeDAO;
+import org.lamsfoundation.lams.tool.scratchie.model.BurningQuestionLike;
+
+public class BurningQuestionLikeDAOHibernate extends LAMSBaseDAO implements BurningQuestionLikeDAO {
+
+ private static String INSERT_LIKE = "INSERT IGNORE INTO tl_lascrt11_burning_que_like(burning_question_uid, session_id) VALUES (:burningQuestionUid,:sessionId);";
+
+ public boolean addLike(Long burningQuestionUid, Long sessionId) {
+ int status = getSession().createSQLQuery(INSERT_LIKE)
+ .setParameter("burningQuestionUid", burningQuestionUid)
+ .setParameter("sessionId", sessionId)
+ .executeUpdate();
+ return status == 1;
+ }
+
+ public void removeLike(Long burningQuestionUid, Long sessionId) {
+
+ final String FIND_BY_SESSION_AND_BURNING_QUESTION = "from " + BurningQuestionLike.class.getName()
+ + " as l where l.sessionId=? and l.burningQuestion.uid = ?";
+
+ List list = find(FIND_BY_SESSION_AND_BURNING_QUESTION, new Object[] {sessionId, burningQuestionUid});
+ if (list == null || list.size() == 0) {
+ return;
+ }
+ BurningQuestionLike like = list.get(0);
+
+ if (like != null) {
+ delete(like);
+ }
+ }
+
+}
Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java
===================================================================
diff -u -r1e3d5be6bfe7e9e224d35d05f1e9599c04f2bf9c -r5f1cadc89726925aa93eac489cd88e76439cbc4a
--- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java (.../ScratchieBurningQuestionDAOHibernate.java) (revision 1e3d5be6bfe7e9e224d35d05f1e9599c04f2bf9c)
+++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieBurningQuestionDAOHibernate.java (.../ScratchieBurningQuestionDAOHibernate.java) (revision 5f1cadc89726925aa93eac489cd88e76439cbc4a)
@@ -23,10 +23,17 @@
/* $Id$ */
package org.lamsfoundation.lams.tool.scratchie.dao.hibernate;
+import java.util.ArrayList;
import java.util.List;
+import org.hibernate.Hibernate;
+import org.hibernate.SQLQuery;
+import org.hibernate.type.IntegerType;
+import org.hibernate.type.LongType;
+import org.hibernate.type.StringType;
import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO;
import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieBurningQuestionDAO;
+import org.lamsfoundation.lams.tool.scratchie.dto.BurningQuestionDTO;
import org.lamsfoundation.lams.tool.scratchie.model.ScratchieBurningQuestion;
public class ScratchieBurningQuestionDAOHibernate extends LAMSBaseDAO implements ScratchieBurningQuestionDAO {
@@ -49,8 +56,57 @@
// }
@Override
- public List getBurningQuestionsByItemUid(Long itemUid) {
- return (List) this.doFind(FIND_BY_ITEM_UID, new Object[] { itemUid});
+ @SuppressWarnings("unchecked")
+ public List getBurningQuestionsByContentId(Long scratchieUid, Long sessionId) {
+
+ /* Thread based lookups - Returns a complex structure so that the likes information can be passed
+ * back with it. */
+ String GET_BURNING_QUESTIONS_WITH_LIKES =
+ "SELECT bq.*, ANY_VALUE(session.session_name) sessionName, count(like1.uid) total_likes ";
+ //in case sessionId is provided - we need to also return which burning questions leader has liked
+ if (sessionId != null) {
+ GET_BURNING_QUESTIONS_WITH_LIKES +=
+ ", EXISTS(select * from tl_lascrt11_burning_que_like like2 where bq.uid = like2.burning_question_uid AND like2.session_id=:sessionId) user_liked";
+ }
+ GET_BURNING_QUESTIONS_WITH_LIKES +=
+ " FROM tl_lascrt11_burning_question bq "
+ + " JOIN tl_lascrt11_session session"
+ + " ON session.scratchie_uid = :scratchieUid AND bq.session_id = session.session_id "
+ + " LEFT JOIN tl_lascrt11_burning_que_like like1 ON bq.uid = like1.burning_question_uid "
+ + " WHERE bq.question IS NOT NULL AND bq.question != ''"
+ + " GROUP BY bq.uid";
+
+ SQLQuery query = getSession().createSQLQuery(GET_BURNING_QUESTIONS_WITH_LIKES);
+ query.addEntity("bq", ScratchieBurningQuestion.class)
+ .addScalar("sessionName", StringType.INSTANCE)
+ .addScalar("total_likes", IntegerType.INSTANCE)
+ .setLong("scratchieUid", scratchieUid);
+ if (sessionId != null) {
+ query.addScalar("user_liked", IntegerType.INSTANCE)
+ .setLong("sessionId", sessionId);
+ }
+ List