Index: lams_build/lib/lams/lams.jar =================================================================== diff -u -rbe118ba177d68f16232e2414606a569b398ee2a0 -r5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b Binary files differ Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.hbm.xml (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -r2abc3485dc2d24ea02044a64271f3ee0d3b8c11b -r5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 2abc3485dc2d24ea02044a64271f3ee0d3b8c11b) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -321,6 +321,36 @@ + + + + + + + + + + + + + true + + + + + + + + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + + + + + @@ -583,6 +613,11 @@ + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/ConfidenceLevel.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,85 @@ +package org.lamsfoundation.lams.confidencelevel; + +import org.lamsfoundation.lams.usermanagement.User; + +/** + * Object for storing confidence levels left by learners in MCQ and Assessment tools. + */ +public class ConfidenceLevel implements java.io.Serializable, Cloneable { + + private static final long serialVersionUID = -6417303272123399980L; + + private Long uid; + + private Long questionUid; + + private User learner; + + private int confidenceLevel; + + private Long toolSessionId; + + public ConfidenceLevel() { + } + + public ConfidenceLevel(Long itemId, User learner, int confidenceLevel) { + this.questionUid = itemId; + this.learner = learner; + this.confidenceLevel = confidenceLevel; + } + + public ConfidenceLevel(Long itemId, User learner, Long toolSessionId, int confidenceLevel) { + this.questionUid = itemId; + this.learner = learner; + this.toolSessionId = toolSessionId; + this.confidenceLevel = confidenceLevel; + } + + /** + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + /** + */ + public Long getQuestionUid() { + return questionUid; + } + + public void setQuestionUid(Long itemId) { + this.questionUid = itemId; + } + + /** + */ + public User getLearner() { + return learner; + } + + public void setLearner(User learner) { + this.learner = learner; + } + + /** + */ + public void setConfidenceLevel(int confidenceLevel) { + this.confidenceLevel = confidenceLevel; + } + + public int getConfidenceLevel() { + return this.confidenceLevel; + } + + public Long getToolSessionId() { + return toolSessionId; + } + + public void setToolSessionId(Long toolSessionId) { + this.toolSessionId = toolSessionId; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/IConfidenceLevelDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/IConfidenceLevelDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/IConfidenceLevelDAO.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -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 + * **************************************************************** + */ + + + +package org.lamsfoundation.lams.confidencelevel.dao; + +import java.util.List; + +import org.lamsfoundation.lams.confidencelevel.ConfidenceLevel; + +public interface IConfidenceLevelDAO { + + void saveOrUpdate(Object object); + + void delete(Object object); + + /** Not limiting by session as the userId is restrictive enough */ + ConfidenceLevel getConfidenceLevel(Integer userId, Long questionUid); + + /** Limiting by tool session */ + List getConfidenceLevelsByItem(Long contentId, Long toolSessionId, Long questionUid); + + /** Not limiting by session as the userId is restrictive enough */ + List getConfidenceLevelsByUser(Integer userId, Long toolSessionId); + + List getConfidenceLevelsByQuestionAndSession(Long questionUid, Long toolSessionId); + + ConfidenceLevel get(Long uid); + +} Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/hibernate/ConfidenceLevelDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/hibernate/ConfidenceLevelDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dao/hibernate/ConfidenceLevelDAO.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,109 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + + +package org.lamsfoundation.lams.confidencelevel.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.confidencelevel.ConfidenceLevel; +import org.lamsfoundation.lams.confidencelevel.dao.IConfidenceLevelDAO; +import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; + +public class ConfidenceLevelDAO extends LAMSBaseDAO implements IConfidenceLevelDAO { + + private static final String FIND_CONFIDENCE_BY_AND_USER_AND_ITEM = "FROM " + ConfidenceLevel.class.getName() + + " AS r where r.learner.userId=? AND r.questionUid=?"; + + private static final String FIND_RATING_BY_CRITERIA_AND_USER = "FROM " + ConfidenceLevel.class.getName() + + " AS r where r.ratingCriteria.ratingCriteriaId=? AND r.learner.userId=?"; + + private static final String FIND_RATINGS_BY_ITEM = "FROM " + ConfidenceLevel.class.getName() + + " AS r where r.ratingCriteria.toolContentId=? AND r.toolSessionId=? AND r.questionUid=?"; + + private static final String FIND_CONFIDENCES_BY_USER = "FROM " + ConfidenceLevel.class.getName() + + " AS r where r.learner.userId=? AND r.toolSessionId=?"; + + private static final String FIND_CONFIDENCES_BY_QUESTION_AND_SESSION = "FROM " + ConfidenceLevel.class.getName() + + " AS r where r.questionUid=? AND r.toolSessionId=?"; + + @Override + public void saveOrUpdate(Object object) { + getSession().saveOrUpdate(object); + getSession().flush(); + } + + public void delete(Object object) { + getSession().delete(object); + getSession().flush(); + } + + @Override + public ConfidenceLevel getConfidenceLevel(Integer userId, Long questionUid) { + List list = (List) doFind(FIND_CONFIDENCE_BY_AND_USER_AND_ITEM, + new Object[] { userId, questionUid }); + if (list.size() > 0) { + return list.get(0); + } else { + return null; + } + } + + @Override + public List getConfidenceLevelsByItem(Long contentId, Long toolSessionId, Long questionUid) { + return super.find(FIND_RATINGS_BY_ITEM, new Object[] { contentId, toolSessionId, questionUid }); + } + + // method is not used at the moment + private ConfidenceLevel getConfidenceLevel(Long ratingCriteriaId, Integer userId) { + List list = (List) doFind(FIND_RATING_BY_CRITERIA_AND_USER, + new Object[] { ratingCriteriaId, userId }); + if (list.size() > 0) { + return list.get(0); + } else { + return null; + } + } + + @Override + public List getConfidenceLevelsByUser(Integer userId, Long toolSessionId) { + return (List) doFind(FIND_CONFIDENCES_BY_USER, new Object[] { userId, toolSessionId }); + } + + @Override + public List getConfidenceLevelsByQuestionAndSession(Long questionUid, Long toolSessionId) { + return (List) doFind(FIND_CONFIDENCES_BY_QUESTION_AND_SESSION, new Object[] { questionUid, toolSessionId }); + } + + @Override + public ConfidenceLevel get(Long uid) { + if (uid != null) { + Object o = super.find(ConfidenceLevel.class, uid); + return (ConfidenceLevel) o; + } else { + return null; + } + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/ConfidenceLevelDTO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/ConfidenceLevelDTO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/ConfidenceLevelDTO.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,30 @@ +package org.lamsfoundation.lams.confidencelevel.dto; + +import org.lamsfoundation.lams.usermanagement.User; + +public class ConfidenceLevelDTO { + + private User learner; + + private String rating; + + /** + */ + public User getLearner() { + return learner; + } + + public void setLearner(User learner) { + this.learner = learner; + } + + /** + */ + public void setRating(String rating) { + this.rating = rating; + } + + public String getRating() { + return this.rating; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/QuestionConfidenceLevelDTO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/QuestionConfidenceLevelDTO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/dto/QuestionConfidenceLevelDTO.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,29 @@ +package org.lamsfoundation.lams.confidencelevel.dto; + +import java.util.Collection; + +public class QuestionConfidenceLevelDTO { + + //common properties + private Long questionUid; + private Collection confidenceLevelDtos; + + public QuestionConfidenceLevelDTO() { + } + + public Long getQuestionUid() { + return questionUid; + } + + public void setQuestionUid(Long itemId) { + this.questionUid = itemId; + } + + public Collection getConfidenceLevelDtos() { + return confidenceLevelDtos; + } + + public void setConfidenceLevelDtos(Collection criteriaDtos) { + this.confidenceLevelDtos = criteriaDtos; + } +} Index: lams_common/src/java/org/lamsfoundation/lams/confidencelevel/service/ConfidenceLevelService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/service/ConfidenceLevelService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/service/ConfidenceLevelService.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,145 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + + +package org.lamsfoundation.lams.confidencelevel.service; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.confidencelevel.ConfidenceLevel; +import org.lamsfoundation.lams.confidencelevel.dao.IConfidenceLevelDAO; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; + +public class ConfidenceLevelService implements IConfidenceLevelService { + + private static Logger log = Logger.getLogger(ConfidenceLevelService.class); + + private IConfidenceLevelDAO confidenceLevelDAO; + + protected IUserManagementService userManagementService; + + protected MessageService messageService; + + @Override + public void removeUserCommitsByContent(Integer userId, Long toolSessionId) { + List confidenceLevels = confidenceLevelDAO.getConfidenceLevelsByUser(userId, toolSessionId); + for (ConfidenceLevel confidenceLevel : confidenceLevels) { + confidenceLevelDAO.delete(confidenceLevel); + } + } + + @Override + public void saveOrUpdateConfidenceLevel(ConfidenceLevel confidenceLevel) { + confidenceLevelDAO.saveOrUpdate(confidenceLevel); + } + + @Override + public void saveConfidenceLevel(Long toolSessionId, Integer userId, Long questionUid, int confidenceLevelInt) { + + ConfidenceLevel confidenceLevel = confidenceLevelDAO.getConfidenceLevel(userId, questionUid); + + // persist MessageConfidenceLevel changes in DB + if (confidenceLevel == null) { // add + confidenceLevel = new ConfidenceLevel(); + confidenceLevel.setQuestionUid(questionUid); + + User learner = (User) userManagementService.findById(User.class, userId); + confidenceLevel.setLearner(learner); + + confidenceLevel.setToolSessionId(toolSessionId); + } + + confidenceLevel.setConfidenceLevel(confidenceLevelInt); + confidenceLevelDAO.saveOrUpdate(confidenceLevel); + } + + @Override + public int saveConfidenceLevels(Long toolSessionId, Integer userId, Map questionUidToConfidenceLevelMap) { + + User learner = (User) userManagementService.findById(User.class, userId); + int numConfidenceLevels = 0; + + List dbConfidenceLevels = confidenceLevelDAO.getConfidenceLevelsByUser(userId, toolSessionId); + for ( ConfidenceLevel dbConfidenceLevel: dbConfidenceLevels ) { + Long questionUid = dbConfidenceLevel.getQuestionUid(); + Integer newConfidenceLevel = questionUidToConfidenceLevelMap.get(questionUid); + if ( newConfidenceLevel != null ) { + dbConfidenceLevel.setConfidenceLevel(newConfidenceLevel); + questionUidToConfidenceLevelMap.remove(questionUid); + numConfidenceLevels++; + confidenceLevelDAO.saveOrUpdate(dbConfidenceLevel); + } else { + dbConfidenceLevel.setConfidenceLevel(0); + } + } + for ( Map.Entry entry : questionUidToConfidenceLevelMap.entrySet() ) { + ConfidenceLevel confidenceLevel = new ConfidenceLevel(); + confidenceLevel.setQuestionUid(entry.getKey()); + confidenceLevel.setLearner(learner); + confidenceLevel.setConfidenceLevel(entry.getValue()); + confidenceLevel.setToolSessionId(toolSessionId); + confidenceLevelDAO.saveOrUpdate(confidenceLevel); + numConfidenceLevels++; + } + + return numConfidenceLevels; + } + + @Override + public List getConfidenceLevelsByUser(Integer userId, Long toolSessionId) { + return confidenceLevelDAO.getConfidenceLevelsByUser(userId.intValue(), toolSessionId); + } + + @Override + public List getConfidenceLevelsByQuestionAndSession(Long questionUid, Long toolSessionId) { + return confidenceLevelDAO.getConfidenceLevelsByQuestionAndSession(questionUid, toolSessionId); + } + + /* ********** Used by Spring to "inject" the linked objects ************* */ + + public void setConfidenceLevelDAO(IConfidenceLevelDAO confidenceLevelDAO) { + this.confidenceLevelDAO = confidenceLevelDAO; + } + + /** + * + * @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/confidencelevel/service/IConfidenceLevelService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/confidencelevel/service/IConfidenceLevelService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/confidencelevel/service/IConfidenceLevelService.java (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -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 + * **************************************************************** + */ + + + +package org.lamsfoundation.lams.confidencelevel.service; + +import java.util.List; +import java.util.Map; + +import org.lamsfoundation.lams.confidencelevel.ConfidenceLevel; + +public interface IConfidenceLevelService { + + void saveOrUpdateConfidenceLevel(ConfidenceLevel confidenceLevel); + + /** + * Save a group of confidenceLevels as the new confidenceLevels for this criteria, marking any existing confidenceLevels NULL. + * Returns the number of "real" confidenceLevels, which should be newConfidenceLevels.size. + * @return + */ + int saveConfidenceLevels(Long toolSessionId, Integer userId, Map questionUidToConfidenceLevelMap); + + void saveConfidenceLevel(Long toolSessionId, Integer userId, Long questionUid, int confidenceLevelInt); + + /** + * Returns all confidence levels user left in this activity. + * + * @param userId + * @param toolSessionId + * @return + */ + List getConfidenceLevelsByUser(Integer userId, Long toolSessionId); + + /** + * Returns all confidence levels that was left for the specified question and by the users from the specified session. + * + * @param userId + * @param toolSessionId + * @return + */ + List getConfidenceLevelsByQuestionAndSession(Long questionUid, Long toolSessionId); + + /** + * Removes all confidenceLevels and comments left by the specified user. + * + * @param contentId + * @param userId + * @return + */ + void removeUserCommitsByContent(Integer userId, Long toolSessionId); + +} Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20171016.sql =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20171016.sql (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20171016.sql (revision 5eca912646ea4d81e3cf72fa0fe8b0567aea3c3b) @@ -0,0 +1,24 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; +SET FOREIGN_KEY_CHECKS=0; +----------------------Put all sql statements below here------------------------- + +-- LDEV-4451 Ability to choose confidence levels in Assessment and MCQ and display them later in Scratchie +CREATE TABLE lams_confidence_level ( + uid bigint(20) NOT NULL AUTO_INCREMENT, + question_uid bigint(20), + user_id bigint(20) NOT NULL, + confidence_level int, + tool_session_id BIGINT(20), + PRIMARY KEY (uid), + KEY user_id (user_id), + CONSTRAINT FK_lams_confidence_level_1 FOREIGN KEY (user_id) + REFERENCES lams_user (user_id) ON DELETE CASCADE ON UPDATE CASCADE +); + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; +SET FOREIGN_KEY_CHECKS=1;