Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java =================================================================== diff -u -r17032ee407bc324b8b3a6121cb291b66cab7293a -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java (.../QaAppConstants.java) (revision 17032ee407bc324b8b3a6121cb291b66cab7293a) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaAppConstants.java (.../QaAppConstants.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -43,6 +43,7 @@ public static final String LOAD_LEARNER ="loadLearner"; public static final String LEARNING_STARTER ="learningStarter"; public static final String MONITORING_STARTER ="monitoringStarter"; + public static final String EXPORT_PORTFOLIO = "exportPortfolio"; public static final String LOAD_MONITORING ="loadMonitoring"; public static final String LOAD_VIEW_ONLY ="loadViewOnly"; public static final String EDIT_RESPONSE ="editResponse"; @@ -52,6 +53,7 @@ public static final String ERROR_LIST_LEARNER ="errorListLearner"; public static final String DEFAULT_CONTENT_ID_STR ="defaultContentIdStr"; public static final String TOOL_SESSION_ID = "toolSessionID"; + public static final String EXPORT_USER_ID ="exportUserId"; public static final String ACTIVE_MODULE ="activeModule"; public static final String AUTHORING ="authoring"; Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java =================================================================== diff -u -rf2b7c28c53bfee9c676b5a836e42b71e0e1bf20f -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java (.../QaContent.java) (revision f2b7c28c53bfee9c676b5a836e42b71e0e1bf20f) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaContent.java (.../QaContent.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -64,6 +64,9 @@ /** nullable persistent field */ private String instructions; + /** persistent field, used for export portfolio */ + private String content; + /** nullable persistent field */ private String reportTitle; @@ -119,6 +122,7 @@ /** full constructor */ public QaContent(Long qaContentId, + String content, String title, String instructions, String reportTitle, @@ -140,6 +144,7 @@ Set qaUploadedFiles) { this.qaContentId = qaContentId; + this.content = content; this.title = title; this.instructions = instructions; this.reportTitle = reportTitle; @@ -174,6 +179,7 @@ Long newContentId) { QaContent newContent = new QaContent(newContentId, + qa.getContent(), qa.getTitle(), qa.getInstructions(), qa.getReportTitle(), @@ -200,7 +206,6 @@ } - //part of the contract: make sure that this works! public Set deepCopyQaQueContent(QaContent newQaContent) { logger.debug(logger + " " + "QaContent" + " " + "start of deepCopyQaQueContent"); @@ -217,8 +222,6 @@ } - - public Set deepCopyQaSession(QaContent newQaSession) { return new TreeSet(); @@ -298,13 +301,7 @@ .toString(); } - - /** - * Since the survey content id is assigned variable, we can use content id - * to ensure two survey objects are equal. - * @see java.lang.Object#equals(java.lang.Object) - */ public boolean equals(Object other) { if (!(other instanceof QaContent)) @@ -315,11 +312,7 @@ .isEquals(); } - /** - * Since the survey content id is assigned variable, we can use content id - * to ensure two survey objects are equal. - * @see java.lang.Object#hashCode() - */ + public int hashCode() { return new HashCodeBuilder().append(getQaContentId()).toHashCode(); @@ -533,4 +526,16 @@ public void setUid(Long uid) { this.uid = uid; } + /** + * @return Returns the content. + */ + public String getContent() { + return content; + } + /** + * @param content The content to set. + */ + public void setContent(String content) { + this.content = content; + } } Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties =================================================================== diff -u -r17032ee407bc324b8b3a6121cb291b66cab7293a -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties (.../QaResources.properties) (revision 17032ee407bc324b8b3a6121cb291b66cab7293a) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/QaResources.properties (.../QaResources.properties) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -1,5 +1,6 @@ # Project lams_tool_qa #Authoring mode resources +label.tool.shortname =Q/A label.authoring =Q/A Authoring label.monitoring =Q/A Monitoring label.authoring.qa =Questions and Answers @@ -27,6 +28,7 @@ label.onlineInstructions.col =Online Instructions: label.offlineFiles =Offline Files: label.onlineFiles =Online Files: +label.exportPortfolio.simple =Export Portfolio instructions.type.online =Online instructions.type.offline =Offline @@ -109,8 +111,9 @@ error.userId.existing =Tool Activity Error! Can't continue. The user id passed to the Tool Activity refers to a student that has already used the activity. Each learner activity should be associated with a unique userId. error.defaultContent.notSetup =Tool Activity Error! Can't continue. The default content for the tool has not been setup properly. error.mode.required =Tool Activity Error! Can't continue URL is not complete. The Tool Activity requires a mode. -error.toolSession.notAvailable =Tool Activity Error! Can't continue. Tool session is not ready in the tool's database yet. Please verify the API method: public void createToolSession(Long toolSessionId, Long toolContentId) has already been executed. +error.toolSession.notAvailable =Tool Activity Error! Can't continue. Tool session is not ready in the tool's database yet. error.learningUser.notAvailable =Tool Activity Error! Can't continue. Tool Activity expects a user id. +error.learner.userId.required ==Tool Activity Error! Can't continue. Tool Activity expects learner's user id. error.noLearnerActivity =Summary report is not available since no users attempted the activity yet. #Monitoring mode resources Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java =================================================================== diff -u -r4beb496ffd830646c5752e770f04ca60e56ef231 -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java (.../IQaQueUsrDAO.java) (revision 4beb496ffd830646c5752e770f04ca60e56ef231) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/IQaQueUsrDAO.java (.../IQaQueUsrDAO.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -38,8 +38,10 @@ public QaQueUsr getQaQueUsrById(long qaQueUsrId); - public QaQueUsr loadQaQueUsrById(long qaQueUsrId); + public QaQueUsr loadQaQueUsrById(long qaQueUsrId); + public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId); + public void createUsr(QaQueUsr usr); public void deleteQaQueUsr(QaQueUsr qaQueUsr); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java =================================================================== diff -u -r4beb496ffd830646c5752e770f04ca60e56ef231 -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java (.../QaQueUsrDAO.java) (revision 4beb496ffd830646c5752e770f04ca60e56ef231) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/dao/hibernate/QaQueUsrDAO.java (.../QaQueUsrDAO.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -77,7 +77,27 @@ return null; } + + public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId) + { + + String strGetUser = "from qaQueUsr in class QaQueUsr where qaQueUsr.queUsrId=:queUsrId and qaQueUsr.qaSessionId=:qaSessionId"; + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(strGetUser) + .setLong("queUsrId", queUsrId.longValue()) + .setLong("qaSessionId", qaSessionId.longValue()) + .list(); + + if(list != null && list.size() > 0){ + QaQueUsr usr = (QaQueUsr) list.get(0); + return usr; + } + return null; + } + + + public List getUserBySessionOnly(final QaSession qaSession) { HibernateTemplate templ = this.getHibernateTemplate(); Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java =================================================================== diff -u -r6bfa03ad456ce58485d7f46bf300ddaf54f64a89 -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 6bfa03ad456ce58485d7f46bf300ddaf54f64a89) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/IQaService.java (.../IQaService.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -53,7 +53,7 @@ * @return the qa object */ - public QaContent retrieveQa(long toolContentId) throws QaApplicationException;; + public QaContent retrieveQa(long toolContentId) throws QaApplicationException; /** @@ -62,89 +62,93 @@ * @return the qa object or null */ - public QaContent loadQa(long toolContentId) throws QaApplicationException;; + public QaContent loadQa(long toolContentId) throws QaApplicationException; - public QaContent getQaContentByUID(Long uid) throws QaApplicationException;; + public QaContent getQaContentByUID(Long uid) throws QaApplicationException; - public int getTotalNumberOfUsers() throws QaApplicationException;; + public int getTotalNumberOfUsers() throws QaApplicationException; - public int countSessionComplete() throws QaApplicationException;; + public int countSessionComplete() throws QaApplicationException; /** * Return the question content object according to the requested question content id. * @param qaQueContentId qa question content id * @return the qa question object */ - public QaQueContent retrieveQaQue(long qaQueContentId) throws QaApplicationException;; + public QaQueContent retrieveQaQue(long qaQueContentId) throws QaApplicationException; - public QaQueUsr loadQaQueUsr(Long userId) throws QaApplicationException;; + public QaQueUsr loadQaQueUsr(Long userId) throws QaApplicationException; - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long qaQueContentId) throws QaApplicationException;; + public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long qaQueContentId) throws QaApplicationException; - public void createQaQue(QaQueContent qaQueContent) throws QaApplicationException;; + public void createQaQue(QaQueContent qaQueContent) throws QaApplicationException; - public void createQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException;; + public void createQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException; - public QaUsrResp retrieveQaUsrResp(long responseId) throws QaApplicationException;; + public QaUsrResp retrieveQaUsrResp(long responseId) throws QaApplicationException; - public void updateQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException;; + public void updateQaUsrResp(QaUsrResp qaUsrResp) throws QaApplicationException; /** * Return the qa session object according to the requested session id. * @param qaSessionId qa session id * @return the qa session object */ - public QaSession retrieveQaSession(long qaSessionId) throws QaApplicationException;; + public QaSession retrieveQaSession(long qaSessionId) throws QaApplicationException; public QaSession retrieveQaSessionOrNullById(long qaSessionId) throws QaApplicationException; - public void createQaSession(QaSession qaSession) throws QaApplicationException;; + public void createQaSession(QaSession qaSession) throws QaApplicationException; - public List getSessionNamesFromContent(QaContent qaContent) throws QaApplicationException;; + public List getSessionNamesFromContent(QaContent qaContent) throws QaApplicationException; - public String getSessionNameById(long qaSessionId) throws QaApplicationException;; + public String getSessionNameById(long qaSessionId) throws QaApplicationException; public void removeToolSession(Long toolSessionId) throws DataMissingException, ToolException; - public List getSessionsFromContent(QaContent qaContent) throws QaApplicationException;; + public List getSessionsFromContent(QaContent qaContent) throws QaApplicationException; - public void createQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException;; + public void createQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException; - public void updateQaSession(QaSession qaSession) throws QaApplicationException;; + public void updateQaSession(QaSession qaSession) throws QaApplicationException; /** * Return the qa que user object according to the requested usr id. * @param qaQaUsrId qa usr id * @return the qa que usr object */ - public QaQueUsr retrieveQaQueUsr(long qaQaUsrId) throws QaApplicationException;; + public QaQueUsr retrieveQaQueUsr(long qaQaUsrId) throws QaApplicationException; - public QaQueUsr getQaQueUsrById(long qaQueUsrId) throws QaApplicationException;; + public QaQueUsr getQaQueUsrById(long qaQueUsrId) throws QaApplicationException; - public void updateQa(QaContent qa) throws QaApplicationException;; + public void updateQa(QaContent qa) throws QaApplicationException; - public void createQa(QaContent qa) throws QaApplicationException;; + public void createQa(QaContent qa) throws QaApplicationException; - public void deleteQa(QaContent qa) throws QaApplicationException;; + public void deleteQa(QaContent qa) throws QaApplicationException; public void deleteQaSession(QaSession QaSession) throws QaApplicationException; - public void deleteUsrRespByQueId(Long qaQueId) throws QaApplicationException;; + public QaContent retrieveQaBySession(long qaSessionId) throws QaApplicationException; - public void deleteQaById(Long qaId) throws QaApplicationException;; + public void deleteUsrRespByQueId(Long qaQueId) throws QaApplicationException; - public void deleteQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException;; + public void deleteQaById(Long qaId) throws QaApplicationException; - public void removeUserResponse(QaUsrResp resp) throws QaApplicationException;; + public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId) throws QaApplicationException; + public void deleteQaQueUsr(QaQueUsr qaQueUsr) throws QaApplicationException; + + public void removeUserResponse(QaUsrResp resp) throws QaApplicationException; + public List getAllQuestionEntries(final Long uid) throws QaApplicationException; - public User getCurrentUserData(String username) throws QaApplicationException;; + public User getCurrentUserData(String username) throws QaApplicationException; - public List getUserBySessionOnly(final QaSession qaSession) throws QaApplicationException;; + public List getUserBySessionOnly(final QaSession qaSession) throws QaApplicationException; /** * copyToolContent(Long fromContentId, Long toContentId) @@ -156,25 +160,25 @@ public void setAsDefineLater(Long toolContentId) throws DataMissingException, ToolException; - public void unsetAsDefineLater(Long toolContentId) throws QaApplicationException;; + public void unsetAsDefineLater(Long toolContentId) throws QaApplicationException; public void setAsRunOffline(Long toolContentId) throws DataMissingException, ToolException; - public void setAsForceComplete(Long userId) throws QaApplicationException;; + public void setAsForceComplete(Long userId) throws QaApplicationException; - public void setAsForceCompleteSession(Long toolSessionId) throws QaApplicationException;; + public void setAsForceCompleteSession(Long toolSessionId) throws QaApplicationException; - public boolean studentActivityOccurred(QaContent qa) throws QaApplicationException;; + public boolean studentActivityOccurred(QaContent qa) throws QaApplicationException; - public boolean studentActivityOccurredGlobal(QaContent qaContent) throws QaApplicationException;; + public boolean studentActivityOccurredGlobal(QaContent qaContent) throws QaApplicationException; /** * removeToolContent(Long toolContentId) * return void * @param toolContentId */ - public void removeToolContent(Long toolContentId) throws QaApplicationException;; + public void removeToolContent(Long toolContentId) throws QaApplicationException; /** @@ -197,15 +201,15 @@ */ public String leaveToolSession(Long toolSessionId,Long learnerId) throws DataMissingException, ToolException; - public BasicToolVO getToolBySignature(String toolSignature) throws QaApplicationException;; + public BasicToolVO getToolBySignature(String toolSignature) throws QaApplicationException; - public long getToolDefaultContentIdBySignature(String toolSignature) throws QaApplicationException;; + public long getToolDefaultContentIdBySignature(String toolSignature) throws QaApplicationException; - public int countSessionUser(QaSession qaSession) throws QaApplicationException;; + public int countSessionUser(QaSession qaSession) throws QaApplicationException; - public List getToolSessionsForContent(QaContent qa) throws QaApplicationException;; + public List getToolSessionsForContent(QaContent qa) throws QaApplicationException; - public QaQueContent getToolDefaultQuestionContent(long contentId) throws QaApplicationException;; + public QaQueContent getToolDefaultQuestionContent(long contentId) throws QaApplicationException; public void configureContentRepository() throws QaApplicationException; Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java =================================================================== diff -u -r6bfa03ad456ce58485d7f46bf300ddaf54f64a89 -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 6bfa03ad456ce58485d7f46bf300ddaf54f64a89) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/service/QaServicePOJO.java (.../QaServicePOJO.java) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -289,6 +289,21 @@ } + public QaQueUsr getQaUserBySession(final Long queUsrId, final Long qaSessionId) throws QaApplicationException + { + try + { + return qaQueUsrDAO.getQaUserBySession(queUsrId, qaSessionId); + } + catch (DataAccessException e) + { + throw new QaApplicationException("Exception occured when lams is getting qa QueUsr: " + + e.getMessage(), + e); + } + } + + public QaQueUsr loadQaQueUsr(Long userId) throws QaApplicationException { try Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportAction.java =================================================================== diff -u --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportAction.java (revision 0) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportAction.java (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -0,0 +1,307 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ +package org.lamsfoundation.lams.tool.qa.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.apache.struts.Globals; +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.qa.QaAppConstants; +import org.lamsfoundation.lams.tool.qa.QaContent; +import org.lamsfoundation.lams.tool.qa.QaQueUsr; +import org.lamsfoundation.lams.tool.qa.QaSession; +import org.lamsfoundation.lams.tool.qa.QaUtils; +import org.lamsfoundation.lams.tool.qa.service.IQaService; +import org.lamsfoundation.lams.tool.qa.service.QaServiceProxy; +import org.lamsfoundation.lams.web.action.LamsDispatchAction; +import org.lamsfoundation.lams.web.util.AttributeNames; + + +/** + * @author Ozgur Demirtas + * + * enables the learner and teacher to export the contents of the mcq tool. + */ + +public class QaExportAction extends LamsDispatchAction implements QaAppConstants{ + + static Logger logger = Logger.getLogger(QaExportAction.class.getName()); + + public ActionForward unspecified( + ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + { + return mapping.findForward(EXPORT_PORTFOLIO); + } + + + /** + * provides export portfolio functionality for learner + * learner(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * + * @param mapping + * @param form + * @param request + * @param response + * @return ActionForward + */ + public ActionForward learner(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + { + logger.debug("dispatching export portfolio for learner..."); + QaUtils.cleanUpSessionAbsolute(request); + + IQaService qaService = (IQaService)request.getSession().getAttribute(TOOL_SERVICE); + logger.debug("qaService: " + qaService); + if (qaService == null) + { + logger.debug("will retrieve qaService"); + qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); + logger.debug("retrieving qaService from session: " + qaService); + } + + + QaExportForm exportForm = (QaExportForm)form; + + /* required parameters are toolSessionId and userId */ + boolean parametersCorrect=validateLearnerExportParameters(form, request); + logger.debug("learner parametersCorrect: " + parametersCorrect); + if (parametersCorrect == false) + { + logger.debug("learner parameters are not properly passed: " + parametersCorrect); + return (mapping.findForward(ERROR_LIST)); + } + + Long toolSessionId =(Long)request.getSession().getAttribute(TOOL_SESSION_ID); + logger.debug("toolSessionId: " + toolSessionId); + + QaSession qaSession=qaService.retrieveQaSessionOrNullById(toolSessionId.longValue()); + logger.debug("retrieving qaSession: " + qaSession); + + if (qaSession == null) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_NO_TOOL_SESSIONS, new Boolean(true).toString()); + persistError(request, "error.toolSession.doesNoExist"); + return (mapping.findForward(ERROR_LIST)); + } + + Long toolSessionUid= qaSession.getUid(); + logger.debug("qaSession is identified by : " + toolSessionUid); + + Long exportUserId =(Long)request.getSession().getAttribute(EXPORT_USER_ID); + logger.debug("exportUserId : " + exportUserId); + + QaQueUsr qaQueUsr=qaService.getQaUserBySession(exportUserId, toolSessionUid); + logger.debug("existing tool user qaQueUsr : " + qaQueUsr); + if (qaQueUsr == null) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_USER_DOESNOTEXIST, new Boolean(true).toString()); + persistError(request, "error.learningUser.notAvailable"); + return (mapping.findForward(ERROR_LIST)); + } + + logger.debug("getting qaContent based on toolSessionId : " + toolSessionId); + QaContent qaContent=qaService.retrieveQaBySession(toolSessionId.longValue()); + logger.debug("qaContent : " + qaContent); + if (qaContent == null) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_CONTENT_DOESNOTEXIST, new Boolean(true).toString()); + persistError(request, "error.content.doesNotExist"); + return (mapping.findForward(ERROR_LIST)); + } + + exportForm.populateForm(qaContent); + return mapping.findForward(EXPORT_PORTFOLIO); + } + + + /** + * provides export portfolio functionality for teacher + * teacher(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + * + * @param mapping + * @param form + * @param request + * @param response + * @return ActionForward + */ + public ActionForward teacher(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + { + //given the toolcontentId as a parameter + logger.debug("dispatching export portfolio for teacher..."); + QaUtils.cleanUpSessionAbsolute(request); + + IQaService qaService = (IQaService)request.getSession().getAttribute(TOOL_SERVICE); + logger.debug("qaService: " + qaService); + if (qaService == null) + { + logger.debug("will retrieve qaService"); + qaService = QaServiceProxy.getQaService(getServlet().getServletContext()); + logger.debug("retrieving qaService from session: " + qaService); + } + QaExportForm exportForm = (QaExportForm)form; + + /* required parameters are toolSessionId and userId */ + boolean parametersCorrect=validateTeacherExportParameters(form, request); + logger.debug("learner parametersCorrect: " + parametersCorrect); + if (parametersCorrect == false) + { + logger.debug("teacher parameters are not properly passed: " + parametersCorrect); + return (mapping.findForward(ERROR_LIST)); + } + + Long toolContentId =(Long)request.getSession().getAttribute(TOOL_CONTENT_ID); + logger.debug("toolContentId: " + toolContentId); + + QaContent qaContent=qaService.loadQa(toolContentId.longValue()); + logger.debug("existing qaContent:" + qaContent); + if (qaContent == null) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_CONTENT_DOESNOTEXIST, new Boolean(true).toString()); + persistError(request, "error.content.doesNotExist"); + return (mapping.findForward(ERROR_LIST)); + } + + exportForm.populateForm(qaContent); + + return mapping.findForward(EXPORT_PORTFOLIO); + } + + + + /** + * validates learner export portfolio parameters + * validateLearnerExportParameters(ActionForm form, HttpServletRequest request) + * + * @param form + * @param request + * @return boolean + */ + protected boolean validateLearnerExportParameters(ActionForm form, HttpServletRequest request) + { + String strToolSessionId=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); + + if ((strToolSessionId == null) || (strToolSessionId.length() == 0)) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_TOOLSESSIONID_REQUIRED, new Boolean(true).toString()); + persistError(request, "error.toolSessionId.required"); + return false; + } + else + { + try + { + long testToolSessionId=new Long(strToolSessionId).longValue(); + request.getSession().setAttribute(TOOL_SESSION_ID,new Long(strToolSessionId)); + } + catch(NumberFormatException e) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_NUMBERFORMAT, new Boolean(true).toString()); + persistError(request, "error.sessionId.numberFormatException"); + logger.debug("add error.sessionId.numberFormatException to ActionMessages."); + return false; + } + } + + /*USER_ID should be added to AttributeNames*/ + String userId=request.getParameter(USER_ID); + logger.debug("userId: " + userId); + if ((userId == null) || (userId.length() == 0)) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_USER_DOESNOTEXIST, new Boolean(true).toString()); + persistError(request, "error.learner.userId.required"); + return false; + } + request.getSession().setAttribute(EXPORT_USER_ID,new Long(userId)); + + return true; + } + + + /** + * validates teacher export portfolio parameters + * validateTeacherExportParameters(ActionForm form, HttpServletRequest request) + * + * @param form + * @param request + * @return boolean + */ + protected boolean validateTeacherExportParameters(ActionForm form, HttpServletRequest request) + { + String strToolContentId=request.getParameter(AttributeNames.PARAM_TOOL_CONTENT_ID); + logger.debug("strToolContentId: " + strToolContentId); + + if ((strToolContentId == null) || (strToolContentId.length() == 0)) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_CONTENTID_REQUIRED, new Boolean(true).toString()); + persistError(request, "error.contentId.required"); + return false; + } + else + { + try + { + long toolContentId=new Long(strToolContentId).longValue(); + logger.debug("passed TOOL_CONTENT_ID : " + new Long(toolContentId)); + request.getSession().setAttribute(TOOL_CONTENT_ID,new Long(toolContentId)); + } + catch(NumberFormatException e) + { + QaUtils.cleanUpSessionAbsolute(request); + request.getSession().setAttribute(USER_EXCEPTION_NUMBERFORMAT, new Boolean(true).toString()); + persistError(request, "error.contentId.numberFormatException"); + return false; + } + } + return true; + } + + + + /** + * persists error messages to request scope + * @param request + * @param message + */ + public void persistError(HttpServletRequest request, String message) + { + ActionMessages errors= new ActionMessages(); + errors.add(Globals.ERROR_KEY, new ActionMessage(message)); + logger.debug("add " + message +" to ActionMessages:"); + saveErrors(request,errors); + } +} Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportForm.java =================================================================== diff -u --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportForm.java (revision 0) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/QaExportForm.java (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ +package org.lamsfoundation.lams.tool.qa.web; + +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.lamsfoundation.lams.tool.qa.QaContent; + +/** + * @author Ozgur Demirtas + */ + +public class QaExportForm extends ActionForm { + + static Logger logger = Logger.getLogger(QaExportForm.class.getName()); + + private String title; + private String content; + + private String toolContentID; + private String toolSessionID; + private String userID; + private String mode; + + /** + * @return Returns the logger. + */ + public static Logger getLogger() { + return logger; + } + /** + * @param logger The logger to set. + */ + public static void setLogger(Logger logger) { + QaExportForm.logger = logger; + } + /** + * @return Returns the content. + */ + public String getContent() { + return content; + } + /** + * @param content The content to set. + */ + public void setContent(String content) { + this.content = content; + } + /** + * @return Returns the mode. + */ + public String getMode() { + return mode; + } + /** + * @param mode The mode to set. + */ + public void setMode(String mode) { + this.mode = mode; + } + /** + * @return Returns the title. + */ + public String getTitle() { + return title; + } + /** + * @param title The title to set. + */ + public void setTitle(String title) { + this.title = title; + } + /** + * @return Returns the toolContentId. + */ + public String getToolContentID() { + return toolContentID; + } + /** + * @param toolContentId The toolContentId to set. + */ + public void setToolContentID(String toolContentId) { + this.toolContentID = toolContentId; + } + /** + * @return Returns the toolSessionId. + */ + public String getToolSessionID() { + return toolSessionID; + } + /** + * @param toolSessionId The toolSessionId to set. + */ + public void setToolSessionID(String toolSessionId) { + this.toolSessionID = toolSessionId; + } + /** + * @return Returns the userId. + */ + public String getUserID() { + return userID; + } + /** + * @param userId The userId to set. + */ + public void setUserID(String userId) { + this.userID = userId; + } + + public void reset() + { + this.mode = null; + this.title = null; + this.content = null; + this.toolContentID = null; + this.toolSessionID = null; + this.userID = null; + } + + public void populateForm(QaContent content) + { + setTitle(content.getTitle()); + setContent(content.getContent()); + } +} Index: lams_tool_laqa/web/learning/answersContent.jsp =================================================================== diff -u -r17032ee407bc324b8b3a6121cb291b66cab7293a -r29b508d4481abb4c95cbbf153b49f698c58f433b --- lams_tool_laqa/web/learning/answersContent.jsp (.../answersContent.jsp) (revision 17032ee407bc324b8b3a6121cb291b66cab7293a) +++ lams_tool_laqa/web/learning/answersContent.jsp (.../answersContent.jsp) (revision 29b508d4481abb4c95cbbf153b49f698c58f433b) @@ -39,8 +39,11 @@ - + + +       +