Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rbbd946d0a18f784ff7f72d0cebaaa3828980dfd0 -r7dd6c7cb14fde37748dddaf510d178232d13db84 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/RatingServlet.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,101 @@ +/**************************************************************** + * 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.web; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.tomcat.util.json.JSONException; +import org.apache.tomcat.util.json.JSONObject; +import org.lamsfoundation.lams.rating.dto.RatingDTO; +import org.lamsfoundation.lams.rating.service.RatingService; +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.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * Stores rating. + * + * @author Andrey Balan + * + * @web:servlet name="ratingServlet" + * @web:servlet-mapping url-pattern="/servlet/rateItem" + */ +public class RatingServlet extends HttpServlet { + + private static Logger log = Logger.getLogger(RatingServlet.class); + private static RatingService ratingService; + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + getRatingService(); + + float rating = Float.parseFloat((String) request.getParameter("rate")); + String objectId = WebUtil.readStrParam(request, "idBox"); + Long ratingCriteriaId = Long.parseLong(objectId.split("-")[0]); + Long itemId = Long.parseLong(objectId.split("-")[1]); + UserDTO user = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + Integer userId = user.getUserID(); + + RatingDTO averageRatingDTO = ratingService.rateItem(ratingCriteriaId, userId, itemId, rating); + + // refresh numOfRatings + // int numOfRatings = ratingService.getNumOfRatingsByUserAndForum(userUid, forumUid); + + JSONObject JSONObject = new JSONObject(); + try { + JSONObject.put("averageRating", averageRatingDTO.getAverageRating()); + JSONObject.put("numberOfVotes", averageRatingDTO.getNumberOfVotes()); + + } catch (JSONException e) { + throw new ServletException(e); + } + // JSONObject.put("numOfRatings", numOfRatings); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(JSONObject); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + doGet(request, response); + } + + private RatingService getRatingService() { + if (ratingService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()); + ratingService = (RatingService) ctx.getBean("ratingService"); + } + return ratingService; + } +} Index: lams_central/web/css/defaultHTML.css =================================================================== diff -u -r0b85d3d42a2ec95d010ecdf98807043a3522f654 -r7dd6c7cb14fde37748dddaf510d178232d13db84 --- lams_central/web/css/defaultHTML.css (.../defaultHTML.css) (revision 0b85d3d42a2ec95d010ecdf98807043a3522f654) +++ lams_central/web/css/defaultHTML.css (.../defaultHTML.css) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -1684,4 +1684,37 @@ border: thin solid #2E6E9E !important; color: #222222 !important; background-color: #D0E5F5;" -} \ No newline at end of file +} + +.rating-criteria-tag { + width: 60%; + padding-bottom: 25px; +} +.rating-criteria-tag input[type="text"] { + width: 100%; +} +#criterias-table td { + vertical-align:middle; +} +img.up-arrow, img.up-arrow-disabled, img.down-arrow, img.down-arrow-disabled, img.delete-arrow { + width:0px; + height:0px; + padding: 4px 8px; + border:0; + background-repeat: no-repeat; +} +img.up-arrow { + background-image: url('../images/uparrow.gif'); +} +img.up-arrow-disabled { + background-image: url('../images/uparrow_disabled.gif'); +} +img.down-arrow { + background-image: url('../images/downarrow.gif'); +} +img.down-arrow-disabled { + background-image: url('../images/downarrow_disabled.gif'); +} +img.delete-arrow { + background-image: url('../images/disposal.gif'); +} Index: lams_central/web/css/jquery.jRating.css =================================================================== diff -u -rf7d806b0ab4f783c2dd89e920d7f6edf370c04db -r7dd6c7cb14fde37748dddaf510d178232d13db84 --- lams_central/web/css/jquery.jRating.css (.../jquery.jRating.css) (revision f7d806b0ab4f783c2dd89e920d7f6edf370c04db) +++ lams_central/web/css/jquery.jRating.css (.../jquery.jRating.css) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -40,11 +40,17 @@ text-align:center; padding-top:5px; } - p.jRatingInfos span.maxRate { - color:#c9c9c9; - font-size:14px; - } +p.jRatingInfos span.maxRate { + color:#c9c9c9; + font-size:14px; +} + /** Please, note this is a LAMS customization. In case of library upgrade copy these lines manually. **/ +.rating-stars-holder {width: 150px; text-align: center;} +.rating-stars-caption {padding-top: 6px;} +.rating-stars, .rating-stars-disabled {margin: 0px auto;} + +/** Remove the following once we move all tools to use Rating.tag. **/ .rating-stars-div {float:right; padding-right: 10px; margin-top: -8px; min-height: 45px;} -.rating-stars-caption {text-align: center; padding-top: 6px;} +.rating-stars-caption {text-align: center} \ No newline at end of file Index: lams_central/web/includes/javascript/jquery.jRating.js =================================================================== diff -u -rf7d806b0ab4f783c2dd89e920d7f6edf370c04db -r7dd6c7cb14fde37748dddaf510d178232d13db84 --- lams_central/web/includes/javascript/jquery.jRating.js (.../jquery.jRating.js) (revision f7d806b0ab4f783c2dd89e920d7f6edf370c04db) +++ lams_central/web/includes/javascript/jquery.jRating.js (.../jquery.jRating.js) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -62,7 +62,8 @@ $(this).height(starHeight); var average = parseFloat($(this).attr('data-average')), // get the average of all rates - idBox = parseInt($(this).attr('data-id')), // get the id of the box + //**LAMS** customized. originally it looked like idBox = parseInt($(this).attr('data-id')), + idBox = $(this).attr('data-id'), // get the id of the box widthRatingContainer = starWidth*opts.length, // Width of the Container widthColor = average/opts.rateMax*widthRatingContainer, // Width of the color Container Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/Rating.hbm.xml (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/rating/RatingCriteria.hbm.xml (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,64 @@ + + + + + + + + @hibernate.class table="lams_rating_criteria" + true + + + @hibernate.id generator-class="native" type="java.lang.Long" column="rating_criteria_id" + + + + + + + @hibernate.property column="title" length="255" + + + + @hibernate.property column="order_id" length="11" + + + + @hibernate.property column="rating_criteria_type_id" length="11" + + + + + @hibernate.class + + + + @hibernate.class + + + + + @hibernate.class + + + + + @hibernate.class + + + + @hibernate.column name="lesson_id" + + + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -r27f1c5a7f08417a5d6f5e4c7faff092f520078a6 -r7dd6c7cb14fde37748dddaf510d178232d13db84 --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 27f1c5a7f08417a5d6f5e4c7faff092f520078a6) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -198,7 +198,7 @@ - + @@ -222,6 +222,31 @@ + + + + + + + + + + + + + + + true + + + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + + + + @@ -391,6 +416,14 @@ + + + + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch02040041.sql (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,57 @@ +-- Turn off autocommit, so nothing is committed if there is an error + +SET AUTOCOMMIT = 0; +SET FOREIGN_KEY_CHECKS=0; + +-- LDEV-3450 Implement peer review feature +CREATE TABLE lams_rating_criteria_type ( + rating_criteria_type_id INT(11) NOT NULL DEFAULT 0 + , description VARCHAR(255) NOT NULL + , PRIMARY KEY (rating_criteria_type_id) +)ENGINE=InnoDB; + +CREATE TABLE lams_rating_criteria ( + rating_criteria_id BIGINT(20) NOT NULL AUTO_INCREMENT + , title VARCHAR(255) + , rating_criteria_type_id INT(11) NOT NULL DEFAULT 0 + , order_id INT(11) NOT NULL + , tool_content_id BIGINT(20) + , item_id BIGINT(20) + , lesson_id BIGINT(20) + , PRIMARY KEY (rating_criteria_id) + , INDEX (rating_criteria_type_id) + , CONSTRAINT FK_lams_rating_criteria_1 FOREIGN KEY (rating_criteria_type_id) + REFERENCES lams_rating_criteria_type (rating_criteria_type_id) + , INDEX (tool_content_id) + , CONSTRAINT FK_lams_rating_criteria_2 FOREIGN KEY (tool_content_id) + REFERENCES lams_tool_content (tool_content_id) ON DELETE NO ACTION ON UPDATE NO ACTION + , INDEX (lesson_id) + , CONSTRAINT FK_lams_rating_criteria_3 FOREIGN KEY (lesson_id) + REFERENCES lams_lesson (lesson_id) ON DELETE NO ACTION ON UPDATE NO ACTION +)ENGINE=InnoDB; + +CREATE TABLE lams_rating ( + uid BIGINT(20) NOT NULL AUTO_INCREMENT + , rating_criteria_id BIGINT(20) NOT NULL + , item_id BIGINT(20) + , user_id BIGINT(20) NOT NULL + , rating FLOAT + , PRIMARY KEY (uid) + , INDEX (rating_criteria_id) + , CONSTRAINT FK_lams_rating_1 FOREIGN KEY (rating_criteria_id) + REFERENCES lams_rating_criteria (rating_criteria_id) ON DELETE CASCADE ON UPDATE CASCADE + , INDEX (user_id) + , CONSTRAINT FK_lams_rating_2 FOREIGN KEY (user_id) + REFERENCES lams_user (user_id) ON DELETE CASCADE ON UPDATE CASCADE +)ENGINE=InnoDB; + +INSERT INTO lams_rating_criteria_type VALUES (1, 'TOOL_ACTIVITY'); +INSERT INTO lams_rating_criteria_type VALUES (2, 'AUTHORED_ITEM'); +INSERT INTO lams_rating_criteria_type VALUES (3, 'LEARNER_ITEM'); +INSERT INTO lams_rating_criteria_type VALUES (4, 'LESSON'); + + +-- If there were no errors, commit and restore autocommit to on +SET FOREIGN_KEY_CHECKS=0; +COMMIT; +SET AUTOCOMMIT = 1; Index: lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/RatingCriteriaOrderComparator.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -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.rating; + +import java.io.Serializable; +import java.util.Comparator; + +import org.lamsfoundation.lams.rating.model.RatingCriteria; + +/** + * The ratingCriteria order comparator used for sorted set. Order id is used as the primary comparing criteria as it is + * unique within a complex ratingCriteria. If they are the same, ratingCriteria id are used for comparison to ensure the + * sorted set won't treat two activities with the same order id as the same ratingCriteria. If either of the + * ratingCriteria ids are null (activities are not yet saved in the database) use the ratingCriteria ui id. The ui ids + * will compare nulls if required, with null being lower than not null. Two nulls will equal true. + * + * @author andreyb + */ +public class RatingCriteriaOrderComparator implements Comparator, Serializable { + + @Override + public int compare(Object o1, Object o2) { + RatingCriteria ratingCriteria1 = (RatingCriteria) o1; + RatingCriteria ratingCriteria2 = (RatingCriteria) o2; + + if (ratingCriteria1.getOrderId() == null || ratingCriteria2.getOrderId() == null) + return compareRatingCriteriaId(ratingCriteria1, ratingCriteria2); + + int orderDiff = ratingCriteria1.getOrderId().compareTo(ratingCriteria2.getOrderId()); + // return order id compare result if they are not the same + if (orderDiff != 0) + return orderDiff; + // if order id are the same, compare ratingCriteria id. + else + return compareRatingCriteriaId(ratingCriteria1, ratingCriteria2); + } + + private int compareRatingCriteriaId(RatingCriteria ratingCriteria1, RatingCriteria ratingCriteria2) { + if (ratingCriteria1.getRatingCriteriaId() == null && ratingCriteria2.getRatingCriteriaId() == null) { + return 0; + } + if (ratingCriteria1.getRatingCriteriaId() == null) { + return -1; + } + if (ratingCriteria2.getRatingCriteriaId() == null) { + return 1; + } + return ratingCriteria1.getRatingCriteriaId().compareTo(ratingCriteria2.getRatingCriteriaId()); + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingCriteriaDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -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.rating.dao; + +import java.util.List; + +import org.lamsfoundation.lams.rating.model.RatingCriteria; + +public interface IRatingCriteriaDAO { + + void saveOrUpdate(RatingCriteria criteria); + + void deleteRatingCriteria(Long ratingCriteriaId); + + List getByToolContentId(Long toolContentId); + + RatingCriteria getByUid(Long ratingCriteriaId); + +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/IRatingDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,51 @@ +/**************************************************************** + * 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.rating.dao; + +import org.lamsfoundation.lams.rating.dto.RatingDTO; +import org.lamsfoundation.lams.rating.model.Rating; + +public interface IRatingDAO { + + void saveOrUpdate(Rating rating); + + Rating getRating(Long ratingCriteriaId, Integer userId, Long itemId); + + Rating getRating(Long ratingCriteriaId, Integer userId); + + /** + * Returns rating statistics by particular item + * + * @param itemId + * @return + */ + RatingDTO getRatingAverageDTOByItem(Long ratingCriteriaId, Long itemId); + + RatingDTO getRatingAverageDTOByUser(Long ratingCriteriaId, Long itemId, Integer userId); + + Rating get(Long uid); + +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingCriteriaDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,65 @@ +/**************************************************************** + * 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.rating.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.dao.hibernate.BaseDAO; +import org.lamsfoundation.lams.notebook.model.NotebookEntry; +import org.lamsfoundation.lams.rating.dao.IRatingCriteriaDAO; +import org.lamsfoundation.lams.rating.model.Rating; +import org.lamsfoundation.lams.rating.model.RatingCriteria; +import org.lamsfoundation.lams.rating.model.ToolActivityRatingCriteria; + +public class RatingCriteriaDAO extends BaseDAO implements IRatingCriteriaDAO { + + private static final String FIND_BY_TOOL_CONTENT_ID = "from " + RatingCriteria.class.getName() + + " as r where r.toolContentId=? order by r.orderId asc"; + + @Override + public void saveOrUpdate(RatingCriteria criteria) { + this.getHibernateTemplate().saveOrUpdate(criteria); + this.getHibernateTemplate().flush(); + } + + @Override + public void deleteRatingCriteria(Long ratingCriteriaId) { + this.deleteById(RatingCriteria.class, ratingCriteriaId); + } + + @Override + public List getByToolContentId(Long toolContentId) { + return (List) (getHibernateTemplate().find(FIND_BY_TOOL_CONTENT_ID, + new Object[] { toolContentId })); + } + + public RatingCriteria getByUid(Long ratingCriteriaId) { + if (ratingCriteriaId != null) { + Object o = getHibernateTemplate().get(RatingCriteria.class, ratingCriteriaId); + return (RatingCriteria) o; + } else { + return null; + } + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/dao/hibernate/RatingDAO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,115 @@ +/**************************************************************** + * 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.rating.dao.hibernate; + +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; + +import org.lamsfoundation.lams.dao.hibernate.BaseDAO; +import org.lamsfoundation.lams.rating.dao.IRatingDAO; +import org.lamsfoundation.lams.rating.dto.RatingDTO; +import org.lamsfoundation.lams.rating.model.Rating; + +public class RatingDAO extends BaseDAO implements IRatingDAO { + + private static final String FIND_RATING_BY_CRITERIA_AND_USER_AND_ITEM = "FROM " + Rating.class.getName() + + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=? AND r.itemId=?"; + private static final String FIND_RATING_VALUE = "SELECT r.rating FROM " + Rating.class.getName() + + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=? AND r.itemId=?"; + private static final String FIND_RATING_BY_CRITERIA_AND_USER = "FROM " + Rating.class.getName() + + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=?"; + private static final String FIND_RATING_AVERAGE_BY_ITEM = "SELECT AVG(r.rating), COUNT(*) FROM " + + Rating.class.getName() + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.itemId=?"; + + @Override + public void saveOrUpdate(Rating rating) { + this.getHibernateTemplate().saveOrUpdate(rating); + this.getHibernateTemplate().flush(); + } + + @Override + public Rating getRating(Long ratingCriteriaId, Integer userId, Long itemId) { + List list = getHibernateTemplate().find(FIND_RATING_BY_CRITERIA_AND_USER_AND_ITEM, + new Object[] { ratingCriteriaId, userId, itemId }); + if (list.size() > 0) { + return (Rating) list.get(0); + } else { + return null; + } + } + + @Override + public Rating getRating(Long ratingCriteriaId, Integer userId) { + List list = getHibernateTemplate().find(FIND_RATING_BY_CRITERIA_AND_USER, + new Object[] { ratingCriteriaId, userId }); + if (list.size() > 0) { + return (Rating) list.get(0); + } else { + return null; + } + } + + @Override + public RatingDTO getRatingAverageDTOByItem(Long ratingCriteriaId, Long itemId) { + List list = getHibernateTemplate().find(FIND_RATING_AVERAGE_BY_ITEM, new Object[] { ratingCriteriaId, itemId }); + Object[] results = list.get(0); + + Object averageRatingObj = (results[0] == null) ? 0 : results[0]; + NumberFormat numberFormat = NumberFormat.getInstance(Locale.US); + numberFormat.setMaximumFractionDigits(1); + String averageRating = numberFormat.format(averageRatingObj); + + String numberOfVotes = (results[1] == null) ? "0" : String.valueOf(results[1]); + return new RatingDTO(averageRating, numberOfVotes); + } + + @Override + public RatingDTO getRatingAverageDTOByUser(Long ratingCriteriaId, Long itemId, Integer userId) { + + RatingDTO ratingDTO = getRatingAverageDTOByItem(ratingCriteriaId, itemId); + + Float userRating = 0F; + List list = getHibernateTemplate().find(FIND_RATING_VALUE, + new Object[] { ratingCriteriaId, userId, itemId }); + if (list.size() > 0) { + userRating = (Float) list.get(0); + } + ratingDTO.setUserRating(userRating.toString()); + ratingDTO.setItemId(itemId); + + return ratingDTO; + } + + public Rating get(Long uid) { + if (uid != null) { + Object o = getHibernateTemplate().get(Rating.class, uid); + return (Rating) o; + } else { + return null; + } + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/dto/RatingDTO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/dto/RatingDTO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/dto/RatingDTO.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -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.rating.dto; + +import org.lamsfoundation.lams.rating.model.RatingCriteria; + +public class RatingDTO { + + private String userRating; + private String averageRating; + private String numberOfVotes; + private Long itemId; + private RatingCriteria ratingCriteria; + + public RatingDTO(String rating, String numberOfVotes) { + this.averageRating = rating; + this.numberOfVotes = numberOfVotes; + } + + public String getUserRating() { + return userRating; + } + + public void setUserRating(String userRating) { + this.userRating = userRating; + } + + public String getAverageRating() { + return averageRating; + } + + public void setAverageRating(String averageRating) { + this.averageRating = averageRating; + } + + public String getNumberOfVotes() { + return numberOfVotes; + } + + public void setNumberOfVotes(String numberOfVotes) { + this.numberOfVotes = numberOfVotes; + } + + public Long getItemId() { + return itemId; + } + + public void setItemId(Long itemId) { + this.itemId = itemId; + } + + public RatingCriteria getRatingCriteria() { + return ratingCriteria; + } + + public void setRatingCriteria(RatingCriteria ratingCriteria) { + this.ratingCriteria = ratingCriteria; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/AuthoredItemRatingCriteria.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/AuthoredItemRatingCriteria.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/AuthoredItemRatingCriteria.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -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.rating.model; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.ToStringBuilder; + +public class AuthoredItemRatingCriteria extends ToolActivityRatingCriteria implements Cloneable, Serializable { + /** Holds value of property itemId. */ + private Long itemId; + + @Override + public Object clone() { + AuthoredItemRatingCriteria newCriteria = (AuthoredItemRatingCriteria) super.clone(); + return newCriteria; + } + + public String toString() { + return new ToStringBuilder(this).append("ratingCriteriaId", getRatingCriteriaId()).toString(); + } + + /** + * @see org.lamsfoundation.lams.util.Nullable#isNull() + */ + public boolean isNull() { + return false; + } + + /** + * Getter for property itemId. + * + * @return Value of property itemId. + */ + public Long getItemId() { + return this.itemId; + } + + /** + * Setter for property itemId. + * + * @param itemId + * New value of property itemId. + */ + public void setItemId(Long itemId) { + this.itemId = itemId; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/LearnerItemRatingCriteria.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/LearnerItemRatingCriteria.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/LearnerItemRatingCriteria.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -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.rating.model; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.ToStringBuilder; + +public class LearnerItemRatingCriteria extends ToolActivityRatingCriteria implements Cloneable, Serializable { + + @Override + public Object clone() { + LearnerItemRatingCriteria newCriteria = (LearnerItemRatingCriteria) super.clone(); + return newCriteria; + } + + public String toString() { + return new ToStringBuilder(this).append("ratingCriteriaId", getRatingCriteriaId()).toString(); + } + + /** + * @see org.lamsfoundation.lams.util.Nullable#isNull() + */ + public boolean isNull() { + return false; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/LessonRatingCriteria.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/LessonRatingCriteria.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/LessonRatingCriteria.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,71 @@ +/**************************************************************** + * 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.rating.model; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.lamsfoundation.lams.lesson.Lesson; + +public class LessonRatingCriteria extends RatingCriteria implements Cloneable, Serializable { + /** Holds value of property lessonId. */ + private Lesson lesson; + + @Override + public Object clone() { + LessonRatingCriteria newCriteria = (LessonRatingCriteria) super.clone(); + newCriteria.setLesson(null); + return newCriteria; + } + + public String toString() { + return new ToStringBuilder(this).append("ratingCriteriaId", getRatingCriteriaId()).toString(); + } + + /** + * @see org.lamsfoundation.lams.util.Nullable#isNull() + */ + public boolean isNull() { + return false; + } + + /** + * Getter for property lesson. + * + * @return Value of property lesson. + */ + public Lesson getLesson() { + return this.lesson; + } + + /** + * Setter for property lesson. + * + * @param lessonId + * New value of property lesson. + */ + public void setLesson(Lesson lesson) { + this.lesson = lesson; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/Rating.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/Rating.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/Rating.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,105 @@ +/**************************************************************** + * 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.rating.model; + +import org.lamsfoundation.lams.usermanagement.User; + +/** + */ +public class Rating implements java.io.Serializable, Cloneable { + + private static final long serialVersionUID = 4831819420875651676L; + + private Long uid; + + private RatingCriteria ratingCriteria; + + private Long itemId; + + private User learner; + + private float rating; + + public Rating() { + } + + public Rating(Long itemId, RatingCriteria ratingCriteria, User learner, Float rating) { + this.itemId = itemId; + this.ratingCriteria = ratingCriteria; + this.learner = learner; + this.rating = rating; + } + + /** + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + /** + */ + public Long getItemId() { + return itemId; + } + + public void setItemId(Long itemId) { + this.itemId = itemId; + } + + /** + */ + public RatingCriteria getRatingCriteria() { + return ratingCriteria; + } + + public void setRatingCriteria(RatingCriteria ratingCriteria) { + this.ratingCriteria = ratingCriteria; + } + + /** + */ + public User getLearner() { + return learner; + } + + public void setLearner(User learner) { + this.learner = learner; + } + + /** + */ + public void setRating(float rating) { + this.rating = rating; + } + + public float getRating() { + return this.rating; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/RatingCriteria.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/RatingCriteria.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/RatingCriteria.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,256 @@ +/*************************************************************************** + * 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.rating.model; + +import java.io.Serializable; +import java.util.Date; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.util.Nullable; + +/** + * Base class for all RatingCriterias. If you add another subclass, you must update + * RatingCriteriaDAO.getRatingCriteriaByRatingCriteriaId() and add a ACTIVITY_TYPE constant. + */ +public abstract class RatingCriteria implements Serializable, Nullable, Comparable, Cloneable { + + private static final Logger log = Logger.getLogger(RatingCriteria.class); + private static final long serialVersionUID = -2282899640789455260L; + // --------------------------------------------------------------------- + // Class Level Constants + // --------------------------------------------------------------------- + /* + * static final variables indicating the type of activities available for a LearningDesign. As new types of + * activities are added, these constants must be updated, as well as + * RatingCriteriaDAO.getRatingCriteriaByRatingCriteriaId() + * + * OPTIONS_WITH_SEQUENCES_TYPE is set up just to support Flash. The server treads OptionsRatingCriteria and + * OptionalSequenceRatingCriteria the same. + */ + /* **************************************************************** */ + public static final int TOOL_ACTIVITY_CRITERIA_TYPE = 1; + public static final int AUTHORED_ITEM_CRITERIA_TYPE = 2; + public static final int LEARNER_ITEM_CRITERIA_TYPE = 3; + public static final int LESSON_CRITERIA_TYPE = 4; + /** *************************************************************** */ + + /** + * Entries for an ratingCriteria in a language property file + */ + public static final String I18N_TITLE = "rating.criteria.title"; + public static final String I18N_DESCRIPTION = "rating.criteria.description"; + public static final String I18N_HELP_TEXT = "rating.criteria.helptext"; + + // --------------------------------------------------------------------- + // Instance variables + // --------------------------------------------------------------------- + + /** identifier field */ + private Long ratingCriteriaId; + + /** Title of the ratingCriteria */ + private String title; + + /** + * Indicates the order in which the activities appear inside complex activities. Starts from 0, 1 and so on. + */ + private Integer orderId; + + /** The type of ratingCriteria */ + private Integer ratingCriteriaTypeId; + + // --------------------------------------------------------------------- + // Object constructors + // --------------------------------------------------------------------- + + /* + * For the createDateTime fields, if the value is null, then it will default to the current time. + */ + + /** full constructor */ + public RatingCriteria(Long ratingCriteriaId, String title, Integer orderId, Date createDateTime, + Integer ratingCriteriaTypeId) { + this.ratingCriteriaId = ratingCriteriaId; + this.title = title; + this.orderId = orderId; + this.ratingCriteriaTypeId = ratingCriteriaTypeId; + } + + /** default constructor */ + public RatingCriteria() { + } + + /** minimal constructor */ + public RatingCriteria(Long ratingCriteriaId, Date createDateTime, RatingCriteria parentRatingCriteria, + Integer ratingCriteriaTypeId) { + this.ratingCriteriaId = ratingCriteriaId; + this.ratingCriteriaTypeId = ratingCriteriaTypeId; + } + + public static RatingCriteria getRatingCriteriaInstance(int ratingCriteriaType) { + // the default constructors don't set up the ratingCriteria type + // so we need to do that manually + // also default to a sensible category type + RatingCriteria ratingCriteria = null; + switch (ratingCriteriaType) { + case TOOL_ACTIVITY_CRITERIA_TYPE: + ratingCriteria = new ToolActivityRatingCriteria(); + break; + case AUTHORED_ITEM_CRITERIA_TYPE: + ratingCriteria = new AuthoredItemRatingCriteria(); + break; + case LEARNER_ITEM_CRITERIA_TYPE: + ratingCriteria = new LearnerItemRatingCriteria(); + break; + case LESSON_CRITERIA_TYPE: + default: + ratingCriteria = new LessonRatingCriteria(); + break; + } + ratingCriteria.setRatingCriteriaTypeId(new Integer(ratingCriteriaType)); + return ratingCriteria; + } + + // --------------------------------------------------------------------- + // Getters and Setters + // --------------------------------------------------------------------- + public Long getRatingCriteriaId() { + return ratingCriteriaId; + } + + public void setRatingCriteriaId(Long ratingCriteriaId) { + this.ratingCriteriaId = ratingCriteriaId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Integer getOrderId() { + return orderId; + } + + public void setOrderId(Integer orderId) { + this.orderId = orderId; + } + + public Integer getRatingCriteriaTypeId() { + return ratingCriteriaTypeId; + } + + public void setRatingCriteriaTypeId(Integer ratingCriteriaTypeId) { + this.ratingCriteriaTypeId = ratingCriteriaTypeId; + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("ratingCriteriaId", ratingCriteriaId).toString(); + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (!(other instanceof RatingCriteria)) { + return false; + } + RatingCriteria castOther = (RatingCriteria) other; + return new EqualsBuilder().append(this.getOrderId(), castOther.getOrderId()) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(getOrderId()).toHashCode(); + } + + // --------------------------------------------------------------------- + // Service Methods + // --------------------------------------------------------------------- + + // --------------------------------------------------------------------- + // RatingCriteria Type checking methods + // --------------------------------------------------------------------- + /** + * Check up whether an ratingCriteria is tool ratingCriteria or not. + * + * @return is this ratingCriteria a tool ratingCriteria? + */ + public boolean isToolActivityRatingCriteria() { + return getRatingCriteriaTypeId().intValue() == RatingCriteria.TOOL_ACTIVITY_CRITERIA_TYPE; + } + + /** + * Check up whether an ratingCriteria is authored ratingCriteria or not. + * + * @return is this ratingCriteria authored? + */ + public boolean isAuthoredItemRatingCriteria() { + return getRatingCriteriaTypeId().intValue() == RatingCriteria.AUTHORED_ITEM_CRITERIA_TYPE; + } + + public boolean isLearnerItemRatingCriteria() { + return getRatingCriteriaTypeId().intValue() == RatingCriteria.LEARNER_ITEM_CRITERIA_TYPE; + } + + public boolean isLessonRatingCriteria() { + return getRatingCriteriaTypeId().intValue() == RatingCriteria.LESSON_CRITERIA_TYPE; + } + + // --------------------------------------------------------------------- + // Data Transfer object creation methods + // --------------------------------------------------------------------- + + @Override + public Object clone() { + RatingCriteria criteria = null; + try { + criteria = (RatingCriteria) super.clone(); + criteria.setRatingCriteriaId(null); + } catch (CloneNotSupportedException e) { + RatingCriteria.log.error("When clone " + RatingCriteria.class + " failed"); + } + + return criteria; + } + + public int compareTo(Object o) { + + if ((o != null) && o instanceof RatingCriteria) { + RatingCriteria anotherCriteria = (RatingCriteria) o; + return (int) (orderId - anotherCriteria.getOrderId()); + } else { + return 1; + } + } + +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/rating/model/ToolActivityRatingCriteria.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/model/ToolActivityRatingCriteria.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/model/ToolActivityRatingCriteria.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,75 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +/* $Id$ */ +package org.lamsfoundation.lams.rating.model; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.ToStringBuilder; + +/** + */ +public class ToolActivityRatingCriteria extends RatingCriteria implements Serializable, Cloneable { + + private static final long serialVersionUID = 6459453751049962314L; + /** Holds value of property toolContentId. */ + private Long toolContentId; + + @Override + public Object clone() { + ToolActivityRatingCriteria newCriteria = (ToolActivityRatingCriteria) super.clone(); + newCriteria.setToolContentId(null); + return newCriteria; + } + + public String toString() { + return new ToStringBuilder(this).append("ratingCriteriaId", getRatingCriteriaId()).toString(); + } + + /** + * @see org.lamsfoundation.lams.util.Nullable#isNull() + */ + public boolean isNull() { + return false; + } + + /** + * Getter for property toolContentId. + * + * @return Value of property toolContentId. + */ + public Long getToolContentId() { + return this.toolContentId; + } + + /** + * Setter for property toolContentId. + * + * @param toolContentId + * New value of property toolContentId. + */ + public void setToolContentId(Long toolContentId) { + this.toolContentId = toolContentId; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/service/IRatingService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/service/IRatingService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/service/IRatingService.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,91 @@ +/**************************************************************** + * 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.rating.service; + +import java.util.List; + +import org.lamsfoundation.lams.rating.dto.RatingDTO; +import org.lamsfoundation.lams.rating.model.Rating; +import org.lamsfoundation.lams.rating.model.RatingCriteria; +import org.lamsfoundation.lams.rating.model.ToolActivityRatingCriteria; + +public interface IRatingService { + +// Long createRating(Long id, Integer idType, String signature, Integer userID, String title, String entry); +// +// TreeMap> getEntryByLesson(Integer userID, Integer idType); +// +// List getEntry(Long id, Integer idType, String signature, Integer userID); +// +// List getEntry(Long id, Integer idType, String signature); +// +// List getEntry(Long id, Integer idType, Integer userID); +// +// List getEntry(Integer userID); +// +// List getEntry(Integer userID, Integer idType); +// +// List getEntry(Integer userID, Long lessonID); +// +// Rating getEntry(Long uid); +// +// void updateEntry(Long uid, String title, String entry); +// +// void updateEntry(Rating rating); + + void saveOrUpdateRating(Rating rating); + + void saveOrUpdateRatingCriteria(RatingCriteria criteria); + + void deleteRatingCriteria(Long ratingCriteriaId); + + List getCriteriasByToolContentId(Long toolContentId); + + /** + * Return Rating by the given itemId and userId. + * + * @param itemId + * @param userId + * @return + */ + Rating getRatingByItemAndUser(Long itemId, Integer userId); + + /** + * Return list of imageRatings by the the given itemId. + * + * @param itemId + * @return + */ + List getRatingsByItem(Long itemId); + + RatingDTO rateItem(Long ratingCriteriaId, Integer userId, Long itemId, float ratingFloat); + + RatingDTO getRatingDTOByUser(Long ratingCriteriaId, Long itemId, Integer userId); + +// IUserManagementService getUserManagementService(); +// +// MessageService getMessageService(); +} Index: lams_common/src/java/org/lamsfoundation/lams/rating/service/RatingService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/rating/service/RatingService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/rating/service/RatingService.java (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -0,0 +1,203 @@ +/**************************************************************** + * 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.rating.service; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.rating.dao.IRatingCriteriaDAO; +import org.lamsfoundation.lams.rating.dao.IRatingDAO; +import org.lamsfoundation.lams.rating.dto.RatingDTO; +import org.lamsfoundation.lams.rating.model.Rating; +import org.lamsfoundation.lams.rating.model.RatingCriteria; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; + +public class RatingService implements IRatingService { + + private static Logger log = Logger.getLogger(RatingService.class); + + private IRatingDAO ratingDAO; + + private IRatingCriteriaDAO ratingCriteriaDAO; + + protected IUserManagementService userManagementService; + + protected MessageService messageService; + +// public TreeMap> getEntryByLesson(Integer userID, Integer idType) { +// TreeMap> entryMap = new TreeMap>(); +// List list = getEntry(userID, idType); +// +// for (Rating entry : list) { +// if (entryMap.containsKey(entry.getItemId())) { +// String lessonName = (String) entryMap.get(entry.getItemId()).get(0).getRating(); +// entry.setRating(lessonName); +// entryMap.get(entry.getItemId()).add(entry); +// } else { +// Lesson lesson = (Lesson) baseDAO.find(Lesson.class, entry.getItemId()); +// List newEntryList = new ArrayList(); +// +// entry.setRating(lesson.getLessonName()); +// newEntryList.add(entry); +// +// entryMap.put(entry.getItemId(), newEntryList); +// } +// } +// +// return entryMap; +// } +// +// public List getEntry(Long id, Integer idType, String signature, Integer userID) { +// return ratingDAO.get(id, idType, signature, userID); +// } +// +// public List getEntry(Long id, Integer idType, String signature) { +// return ratingDAO.get(id, idType, signature); +// } +// +// public List getEntry(Long id, Integer idType, Integer userID) { +// return ratingDAO.get(id, idType, userID); +// } +// +// public List getEntry(Integer userID) { +// return ratingDAO.get(userID); +// } +// +// public List getEntry(Integer userID, Integer idType) { +// return ratingDAO.get(userID, idType); +// } +// +// public List getEntry(Integer userID, Long lessonID) { +// return ratingDAO.get(userID, lessonID); +// } +// +// public Rating getEntry(Long uid) { +// return ratingDAO.get(uid); +// } +// +// public void updateEntry(Long uid, String title, String entry) { +// Rating ne = getEntry(uid); +// if (ne != null) { +// ne.setTitle(title); +// ne.setEntry(entry); +// ne.setLastModified(new Date()); +// saveOrUpdateRating(ne); +// } else { +// log.debug("updateEntry: uid " + uid + "does not exist"); +// } +// } +// +// public void updateEntry(Rating rating) { +// rating.setLastModified(new Date()); +// saveOrUpdateRating(rating); +// } + + @Override + public Rating getRatingByItemAndUser(Long itemId, Integer userId) { + return null; + } + + @Override + public List getRatingsByItem(Long itemId) { + return null; + } + + @Override + public void saveOrUpdateRating(Rating rating) { + ratingDAO.saveOrUpdate(rating); + } + + @Override + public RatingDTO rateItem(Long ratingCriteriaId, Integer userId, Long itemId, float ratingFloat) { + Rating rating = ratingDAO.getRating(ratingCriteriaId, userId, itemId); + + //persist MessageRating changes in DB + if (rating == null) { // add + rating = new Rating(); + rating.setItemId(itemId); + + User learner = (User) userManagementService.findById(User.class, userId); + rating.setLearner(learner); + + RatingCriteria ratingCriteria = (RatingCriteria) userManagementService.findById(RatingCriteria.class, ratingCriteriaId); + rating.setRatingCriteria(ratingCriteria); + } + rating.setRating(ratingFloat); + ratingDAO.saveOrUpdate(rating); + + //to make available new changes be visible on a jsp page + return ratingDAO.getRatingAverageDTOByItem(ratingCriteriaId, itemId); + } + + @Override + public RatingDTO getRatingDTOByUser(Long ratingCriteriaId, Long itemId, Integer userId) { + return ratingDAO.getRatingAverageDTOByUser(ratingCriteriaId, itemId, userId); + } + + @Override + public List getCriteriasByToolContentId(Long toolContentId) { + List criterias = ratingCriteriaDAO.getByToolContentId(toolContentId); + return criterias; + } + + @Override + public void saveOrUpdateRatingCriteria(RatingCriteria criteria) { + ratingCriteriaDAO.saveOrUpdate(criteria); + } + + @Override + public void deleteRatingCriteria(Long ratingCriteriaId) { + ratingCriteriaDAO.deleteRatingCriteria(ratingCriteriaId); + } + + /* ********** Used by Spring to "inject" the linked objects ************* */ + + public void setRatingDAO(IRatingDAO ratingDAO) { + this.ratingDAO = ratingDAO; + } + + public void setRatingCriteriaDAO(IRatingCriteriaDAO ratingCriteriaDAO) { + this.ratingCriteriaDAO = ratingCriteriaDAO; + } + + /** + * + * @param IUserManagementService + * The userManagementService to set. + */ + public void setUserManagementService(IUserManagementService userManagementService) { + this.userManagementService = userManagementService; + } + + /** + * Set i18n MessageService + */ + public void setMessageService(MessageService messageService) { + this.messageService = messageService; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java =================================================================== diff -u -rc135649b64e98c9233da20bdcfb7689598116314 -r7dd6c7cb14fde37748dddaf510d178232d13db84 --- lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision c135649b64e98c9233da20bdcfb7689598116314) +++ lams_common/src/java/org/lamsfoundation/lams/web/util/AttributeNames.java (.../AttributeNames.java) (revision 7dd6c7cb14fde37748dddaf510d178232d13db84) @@ -84,6 +84,8 @@ public static final String ATTR_SESSION_STATUS = "sessionStatus"; public static final String ATTR_ACTIVITY_POSITION = "activityPosition"; public static final String ATTR_LEARNER_CONTENT_FOLDER = "learnerContentFolder"; + public static final String ATTR_RATING_CRITERIAS = "ratingCriterias"; + public static final String ATTR_RATINGS = "ratings"; // for Pedagogical Planner public static final String PARAM_COMMAND = "command";