Index: lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -r9dcdc46408a8664a0fb27f09ae58a340c15f5764 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 9dcdc46408a8664a0fb27f09ae58a340c15f5764) +++ lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -180,5 +180,13 @@ monitor.summary.date.restriction.removed =Date restriction has been removed label.monitoring.heading =Scratchie monitoring +admin.page.title =Scratchie Settings +admin.success =Configuration successfully saved. +admin.return =Return to maintain LAMS +admin.button.save =Save +admin.extra.mark =Enable an extra mark for the first correct scratchie attempt option. +admin.preset.marks =Marks in a form of a comma-separated values +error.required.fields.missing =Marks should not be left blank. Please, enter it in a format of comma separated values. +error.entered.marks.not.comma.separates =Entered marks are not in a correct format of comma separated values. #======= End labels: Exported 173 labels for en AU ===== Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r4428202881c5551dd3973c9011d7a70e0a517060 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 4428202881c5551dd3973c9011d7a70e0a517060) +++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -155,7 +155,7 @@ - + @@ -216,7 +216,8 @@ - + + @@ -239,6 +240,26 @@ type="org.lamsfoundation.lams.tool.scratchie.web.action.MonitoringAction" parameter="exportExcel" > + + + + + + + + + + Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java =================================================================== diff -u -r4428202881c5551dd3973c9011d7a70e0a517060 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision 4428202881c5551dd3973c9011d7a70e0a517060) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -154,4 +154,7 @@ public static final String ATTR_IS_SUBMISSION_DEADLINE_PASSED = "isSubmissionDeadlinePassed"; public static final String LEARNER_MARK = "learner.mark"; + + public static final String ERROR_MSG_REQUIRED_FIELDS_MISSING = "error.required.fields.missing"; + public static final String ERROR_MSG_ENTERED_MARKS_NOT_COMMA_SEPARATED_INTEGERS = "error.entered.marks.not.comma.separates"; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieConfigItemDAO.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieConfigItemDAO.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieConfigItemDAO.java (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.scratchie.dao; + +import org.lamsfoundation.lams.dao.IBaseDAO; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; + +public interface ScratchieConfigItemDAO extends IBaseDAO { + void saveOrUpdate(ScratchieConfigItem toConfig); + + ScratchieConfigItem getConfigItemByKey(final String configKey); +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieConfigItemDAOHibernate.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieConfigItemDAOHibernate.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieConfigItemDAOHibernate.java (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,52 @@ +/**************************************************************** + * 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.scratchie.dao.hibernate; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.lamsfoundation.lams.dao.hibernate.BaseDAO; +import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieConfigItemDAO; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; +import org.springframework.orm.hibernate3.HibernateCallback; + +public class ScratchieConfigItemDAOHibernate extends BaseDAO implements ScratchieConfigItemDAO { + private static final String LOAD_CONFIG_ITEM_BY_KEY = "from ScratchieConfigItem configuration" + + " where configuration.configKey=:key"; + + @Override + public ScratchieConfigItem getConfigItemByKey(final String configKey) { + return (ScratchieConfigItem) getHibernateTemplate().execute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + return session.createQuery(LOAD_CONFIG_ITEM_BY_KEY).setString("key", configKey).uniqueResult(); + } + }); + + } + + @Override + public void saveOrUpdate(ScratchieConfigItem mdlForumConfigItem) { + this.getHibernateTemplate().saveOrUpdate(mdlForumConfigItem); + this.getHibernateTemplate().flush(); + } +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20140613.sql =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20140613.sql (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20140613.sql (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,28 @@ +-- 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-3251 Create configurable grading scale for scratchie +CREATE TABLE tl_lascrt11_configuration ( + uid BIGINT NOT NULL auto_increment, + config_key VARCHAR(30) UNIQUE, + config_value VARCHAR(255), + PRIMARY KEY (uid) +)ENGINE=InnoDB; +UPDATE lams_tool SET admin_url='tool/lascrt11/admin/start.do' WHERE tool_signature='lascrt11'; + +INSERT INTO `tl_lascrt11_configuration` (`config_key`, `config_value`) VALUES + ('isEnabledExtraPointOption', 'true'); +INSERT INTO `tl_lascrt11_configuration` (`config_key`, `config_value`) VALUES + ('presetMarks', '4,2,1,0'); + + +UPDATE lams_tool SET tool_version='20140613' WHERE tool_signature='lascrt11'; + +----------------------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; \ No newline at end of file Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieConfigItem.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieConfigItem.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieConfigItem.java (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -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.scratchie.model; + +/** + * @hibernate.class table="tl_lascrt11_configuration" + */ +public class ScratchieConfigItem implements java.io.Serializable { + + private static final long serialVersionUID = 6360672537352753361L; + + public static final String KEY_IS_ENABLED_EXTRA_POINT_OPTION = "isEnabledExtraPointOption"; + public static final String KEY_PRESET_MARKS = "presetMarks"; + + private Long id; + private String configKey; + private String configValue; + + /** + * @hibernate.id generator-class="native" type="java.lang.Long" column="uid" + * + */ + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + /** + * @hibernate.property column="config_key" length="30" not-null="false" unique="true" + */ + public String getConfigKey() { + return configKey; + } + + public void setConfigKey(String configKey) { + this.configKey = configKey; + } + + /** + * @hibernate.property column="config_value" length="255" not-null="false" + */ + public String getConfigValue() { + return configValue; + } + + public void setConfigValue(String configValue) { + this.configValue = configValue; + } +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml =================================================================== diff -u -r40eb54374e84591563d8b6a679ac719dbc85c8f7 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision 40eb54374e84591563d8b6a679ac719dbc85c8f7) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -40,11 +40,16 @@ + + + + + + - + - @@ -66,6 +71,9 @@ + + + Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -r4428202881c5551dd3973c9011d7a70e0a517060 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision 4428202881c5551dd3973c9011d7a70e0a517060) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -32,9 +32,9 @@ import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.tool.scratchie.dto.GroupSummary; import org.lamsfoundation.lams.tool.scratchie.dto.ReflectDTO; -import org.lamsfoundation.lams.tool.scratchie.dto.Summary; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswer; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; @@ -293,4 +293,8 @@ List deletedItems); void releaseItemsFromCache(Scratchie scratchie); + + ScratchieConfigItem getConfigItem(String key); + + void saveOrUpdateScratchieConfigItem(ScratchieConfigItem item); } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -r860c30a34e97d8bc893cf7abbeda5dcae2ef45b1 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision 860c30a34e97d8bc893cf7abbeda5dcae2ef45b1) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -40,7 +40,6 @@ import java.util.SortedMap; import java.util.TreeSet; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -65,6 +64,7 @@ import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieAnswerVisitDAO; +import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieConfigItemDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieItemDAO; import org.lamsfoundation.lams.tool.scratchie.dao.ScratchieSessionDAO; @@ -74,6 +74,7 @@ import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswer; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswerVisitLog; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieSession; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; @@ -106,6 +107,8 @@ private ScratchieSessionDAO scratchieSessionDao; private ScratchieAnswerVisitDAO scratchieAnswerVisitDao; + + private ScratchieConfigItemDAO scratchieConfigItemDao; // tool service private ScratchieToolContentHandler scratchieToolContentHandler; @@ -188,8 +191,18 @@ scratchieItemDao.releaseItemFromCache(item); } } + + @Override + public ScratchieConfigItem getConfigItem(String key) { + return scratchieConfigItemDao.getConfigItemByKey(key); + } @Override + public void saveOrUpdateScratchieConfigItem(ScratchieConfigItem item) { + scratchieConfigItemDao.saveOrUpdate(item); + } + + @Override public void deleteScratchieItem(Long uid) { scratchieItemDao.removeObject(ScratchieItem.class, uid); } @@ -299,12 +312,13 @@ ScratchieSession session = this.getScratchieSessionBySessionId(sessionId); Scratchie scratchie = session.getScratchie(); Set items = scratchie.getScratchieItems(); + String presetMarks = getConfigItem(ScratchieConfigItem.KEY_PRESET_MARKS).getConfigValue(); // calculate mark int mark = 0; if (!items.isEmpty()) { for (ScratchieItem item : items) { - mark += getUserMarkPerItem(scratchie, item, userLogs); + mark += getUserMarkPerItem(scratchie, item, userLogs, presetMarks); } } @@ -581,42 +595,31 @@ /** * - * * @param scratchie * @param item * @param userLogs * uses list of logs to reduce number of queries to DB + * @param presetMarks + * presetMarks to reduce number of queries to DB * @return */ - private int getUserMarkPerItem(Scratchie scratchie, ScratchieItem item, List userLogs) { + private int getUserMarkPerItem(Scratchie scratchie, ScratchieItem item, List userLogs, + String presetMarks) { + + String[] marksArray = presetMarks.split(","); int mark = 0; // add mark only if an item was unraveled if (isItemUnraveled(item, userLogs)) { int itemAttempts = calculateItemAttempts(userLogs, item); - // If the student gets it right the first time, then he should get 4 points. - // If he gets it right the second time, the score is 2 - // Third time right, 1 point - // Anything over the third attempt gets 0 - switch (itemAttempts) { - case 1: - mark = 4; - - // add extra point if needed - if (scratchie.isExtraPoint()) { - mark++; - } - break; + String markStr = (itemAttempts <= marksArray.length) ? marksArray[itemAttempts - 1] + : marksArray[marksArray.length - 1]; + mark = Integer.parseInt(markStr); - case 2: - mark = 2; - break; - case 3: - mark = 1; - break; - default: - mark = 0; + // add extra point if needed + if (scratchie.isExtraPoint() && (itemAttempts == 1)) { + mark++; } } @@ -1356,6 +1359,8 @@ */ private List getSummaryByTeam(Scratchie scratchie, Collection sortedItems) { List groupSummaries = new ArrayList(); + + String presetMarks = getConfigItem(ScratchieConfigItem.KEY_PRESET_MARKS).getConfigValue(); List sessionList = scratchieSessionDao.getByContentId(scratchie.getContentId()); for (ScratchieSession session : sessionList) { @@ -1381,7 +1386,7 @@ numberOfAttempts = calculateItemAttempts(answerLogs, item); // for displaying purposes if there is no attemps we assign -1 which will be shown as "-" - mark = (numberOfAttempts == 0) ? -1 : getUserMarkPerItem(scratchie, item, answerLogs); + mark = (numberOfAttempts == 0) ? -1 : getUserMarkPerItem(scratchie, item, answerLogs, presetMarks); isFirstChoice = (numberOfAttempts == 1) && isItemUnraveled(item, answerLogs); @@ -1483,13 +1488,13 @@ this.toolService = toolService; } - public ScratchieAnswerVisitDAO getScratchieAnswerVisitDao() { - return scratchieAnswerVisitDao; - } - public void setScratchieAnswerVisitDao(ScratchieAnswerVisitDAO scratchieItemVisitDao) { this.scratchieAnswerVisitDao = scratchieItemVisitDao; } + + public void setScratchieConfigItemDao(ScratchieConfigItemDAO scratchieConfigItemDao) { + this.scratchieConfigItemDao = scratchieConfigItemDao; + } // ******************************************************************************* // ToolContentManager, ToolSessionManager methods Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AdminAction.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AdminAction.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AdminAction.java (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,142 @@ +/**************************************************************** + * 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.scratchie.web.action; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +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.tool.scratchie.ScratchieConstants; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; +import org.lamsfoundation.lams.tool.scratchie.service.IScratchieService; +import org.lamsfoundation.lams.tool.scratchie.service.ScratchieServiceProxy; +import org.lamsfoundation.lams.tool.scratchie.web.form.AdminForm; + +/** + * @author Andrey Balan + */ +public class AdminAction extends Action { + private IScratchieService scratchieService; + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + String param = mapping.getParameter(); + if (param.equals("start")) { + return start(mapping, form, request, response); + } + if (param.equals("saveContent")) { + return saveContent(mapping, form, request, response); + } + + return start(mapping, form, request, response); + } + + public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + // set up scratchieService + if (scratchieService == null) { + scratchieService = ScratchieServiceProxy.getScratchieService(this.getServlet().getServletContext()); + } + + AdminForm adminForm = (AdminForm) form; + + ScratchieConfigItem isEnabledExtraPointOption = scratchieService + .getConfigItem(ScratchieConfigItem.KEY_IS_ENABLED_EXTRA_POINT_OPTION); + if (isEnabledExtraPointOption != null) { + adminForm.setEnabledExtraPointOption(new Boolean(isEnabledExtraPointOption.getConfigValue())); + } + + ScratchieConfigItem presetMarks = scratchieService.getConfigItem(ScratchieConfigItem.KEY_PRESET_MARKS); + if (presetMarks != null) { + adminForm.setPresetMarks(presetMarks.getConfigValue()); + } + + request.setAttribute("error", false); + return mapping.findForward("config"); + } + + public ActionForward saveContent(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + AdminForm adminForm = (AdminForm) form; + + ActionErrors errors = validateAdminForm(adminForm); + if (!errors.isEmpty()) { + this.addErrors(request, errors); + return mapping.findForward("config"); + } + + // set up scratchieService + if (scratchieService == null) { + scratchieService = ScratchieServiceProxy.getScratchieService(this.getServlet().getServletContext()); + } + + ScratchieConfigItem isEnabledExtraPointOption = scratchieService + .getConfigItem(ScratchieConfigItem.KEY_IS_ENABLED_EXTRA_POINT_OPTION); + isEnabledExtraPointOption.setConfigValue("" + adminForm.isEnabledExtraPointOption()); + scratchieService.saveOrUpdateScratchieConfigItem(isEnabledExtraPointOption); + + ScratchieConfigItem presetMarks = scratchieService.getConfigItem(ScratchieConfigItem.KEY_PRESET_MARKS); + presetMarks.setConfigValue(adminForm.getPresetMarks()); + scratchieService.saveOrUpdateScratchieConfigItem(presetMarks); + + request.setAttribute("savedSuccess", true); + return mapping.findForward("config"); + + } + + /** + * Validate ScratchieConfigItems. + * + * @param adminForm + * @return + */ + private ActionErrors validateAdminForm(AdminForm adminForm) { + ActionErrors errors = new ActionErrors(); + + String presetMarks = adminForm.getPresetMarks(); + if (StringUtils.isNotBlank(presetMarks)) { + + //it's not a comma separated numbers + if (!presetMarks.matches("[0-9]+(,[0-9]+)*")) { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + ScratchieConstants.ERROR_MSG_ENTERED_MARKS_NOT_COMMA_SEPARATED_INTEGERS)); + } + + } else { + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage( + ScratchieConstants.ERROR_MSG_REQUIRED_FIELDS_MISSING)); + } + + return errors; + } +} Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AuthoringAction.java =================================================================== diff -u -r4470fc3acedcc7f384fbe5bbf0c7183b791c93b2 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision 4470fc3acedcc7f384fbe5bbf0c7183b791c93b2) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/AuthoringAction.java (.../AuthoringAction.java) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -62,8 +62,8 @@ import org.lamsfoundation.lams.tool.scratchie.ScratchieConstants; import org.lamsfoundation.lams.tool.scratchie.model.Scratchie; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieAnswer; +import org.lamsfoundation.lams.tool.scratchie.model.ScratchieConfigItem; import org.lamsfoundation.lams.tool.scratchie.model.ScratchieItem; -import org.lamsfoundation.lams.tool.scratchie.model.ScratchieUser; import org.lamsfoundation.lams.tool.scratchie.service.IScratchieService; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieAnswerComparator; import org.lamsfoundation.lams.tool.scratchie.util.ScratchieItemComparator; @@ -193,6 +193,11 @@ SessionMap sessionMap = new SessionMap(); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); scratchieForm.setSessionMapID(sessionMap.getSessionID()); + + ScratchieConfigItem isEnabledExtraPointOption = service + .getConfigItem(ScratchieConfigItem.KEY_IS_ENABLED_EXTRA_POINT_OPTION); + sessionMap.put(ScratchieConfigItem.KEY_IS_ENABLED_EXTRA_POINT_OPTION, + new Boolean(isEnabledExtraPointOption.getConfigValue())); // Get contentFolderID and save to form. String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID); Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/form/AdminForm.java =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/form/AdminForm.java (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/form/AdminForm.java (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,66 @@ +/**************************************************************** + * 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.scratchie.web.form; + +import javax.servlet.http.HttpServletRequest; + +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; + +/** + * @struts.form name="scratchieAdminForm" + */ +public class AdminForm extends ActionForm { + private static final long serialVersionUID = 414425664356226L; + + private boolean enabledExtraPointOption; + + private String presetMarks; + + @Override + public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { + ActionErrors ac = new ActionErrors(); + ac.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("this is an error")); + return ac; + } + + public boolean isEnabledExtraPointOption() { + return enabledExtraPointOption; + } + + public void setEnabledExtraPointOption(boolean isEnabledExtraPointOption) { + this.enabledExtraPointOption = isEnabledExtraPointOption; + } + + public String getPresetMarks() { + return presetMarks; + } + + public void setPresetMarks(String presetMarks) { + this.presetMarks = presetMarks; + } +} Index: lams_tool_scratchie/web/pages/admin/config.jsp =================================================================== diff -u --- lams_tool_scratchie/web/pages/admin/config.jsp (revision 0) +++ lams_tool_scratchie/web/pages/admin/config.jsp (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -0,0 +1,62 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + <fmt:message key="admin.page.title" /> + + + + +
+ +

+ +

+ + + +

+ + <%@ include file="/common/messages.jsp"%> + + +

+ +

+ + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ +
+ +

+ + + + + + \ No newline at end of file Index: lams_tool_scratchie/web/pages/authoring/advance.jsp =================================================================== diff -u -r94be37497fa57d778f02fbb3e13436e673b12e30 -re5a3c4e8e88340e636c501f79cec1b91ab59a5cf --- lams_tool_scratchie/web/pages/authoring/advance.jsp (.../advance.jsp) (revision 94be37497fa57d778f02fbb3e13436e673b12e30) +++ lams_tool_scratchie/web/pages/authoring/advance.jsp (.../advance.jsp) (revision e5a3c4e8e88340e636c501f79cec1b91ab59a5cf) @@ -3,12 +3,14 @@ -

- - -

+ +

+ + +

+