Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java =================================================================== diff -u -r917358423e83fc323518885887537421fd0afafb -rc80bf4c3ad4122cedca89d2965789b5f380df406 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java (.../AuthoringDTO.java) (revision 917358423e83fc323518885887537421fd0afafb) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java (.../AuthoringDTO.java) (revision c80bf4c3ad4122cedca89d2965789b5f380df406) @@ -56,6 +56,8 @@ public AuthoringDTO(){ } public AuthoringDTO(SubmitFilesContent content){ + if(content == null) + return; try { PropertyUtils.copyProperties(this,content); } catch (IllegalAccessException e) { Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java =================================================================== diff -u -reebdf6c7a06bd126cf6331883dd60e4ca72ac5c9 -rc80bf4c3ad4122cedca89d2965789b5f380df406 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java (.../ISubmitFilesService.java) (revision eebdf6c7a06bd126cf6331883dd60e4ca72ac5c9) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java (.../ISubmitFilesService.java) (revision c80bf4c3ad4122cedca89d2965789b5f380df406) @@ -27,6 +27,7 @@ import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.contentrepository.IVersionedNode; +import org.lamsfoundation.lams.tool.sbmt.InstructionFiles; import org.lamsfoundation.lams.tool.sbmt.Learner; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesReport; @@ -95,8 +96,17 @@ */ public void uploadFileToSession(Long sessionID, FormFile uploadFile, String fileDescription, Long userID) throws SubmitFilesException; - public void uploadFileToContent(Long contentID, FormFile uploadFile, String fileType) throws SubmitFilesException; /** + * Upload file to repository and persist relative attributes into database. + * + * @param contentID + * @param uploadFile + * @param fileType + * @return If successs, return an instance of InstructionFile. Otherwise, return null. + * @throws SubmitFilesException + */ + public InstructionFiles uploadFileToContent(Long contentID, FormFile uploadFile, String fileType) throws SubmitFilesException; + /** * This method returns a list of files that were uploaded by the * given User for given contentID. * Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java =================================================================== diff -u -reebdf6c7a06bd126cf6331883dd60e4ca72ac5c9 -rc80bf4c3ad4122cedca89d2965789b5f380df406 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java (.../SubmitFilesService.java) (revision eebdf6c7a06bd126cf6331883dd60e4ca72ac5c9) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java (.../SubmitFilesService.java) (revision c80bf4c3ad4122cedca89d2965789b5f380df406) @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -36,6 +37,7 @@ import java.util.Set; import java.util.TreeSet; +import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts.upload.FormFile; @@ -466,8 +468,8 @@ * * @see org.lamsfoundation.lams.tool.ToolSessionManager# uploadFileToContent(Long,FormFile ) */ - public void uploadFileToContent(Long contentID, FormFile uploadFile,String fileType) throws SubmitFilesException{ - + public InstructionFiles uploadFileToContent(Long contentID, FormFile uploadFile,String fileType) throws SubmitFilesException{ + InstructionFiles refile = null; if(uploadFile == null || StringUtils.isEmpty(uploadFile.getFileName())) throw new SubmitFilesException("Could not find upload file: " + uploadFile); @@ -489,6 +491,14 @@ file.setName(uploadFile.getFileName()); fileSet.add(file); submitFilesContentDAO.save(content); + + refile = new InstructionFiles(); + try { + PropertyUtils.copyProperties(refile,file); + } catch (Exception e) { + throw new SubmitFilesException("Could not get return InstructionFile instance" +e.getMessage()); + } + return refile; } /** * (non-Javadoc) Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java =================================================================== diff -u -rd7aed7203c6ebc9f86f1577f3f037c8a0899d409 -rc80bf4c3ad4122cedca89d2965789b5f380df406 --- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java (.../AuthoringAction.java) (revision d7aed7203c6ebc9f86f1577f3f037c8a0899d409) +++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java (.../AuthoringAction.java) (revision c80bf4c3ad4122cedca89d2965789b5f380df406) @@ -1,13 +1,13 @@ /* * Created on May 19, 2005 * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates */ package org.lamsfoundation.lams.tool.sbmt.web; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -21,6 +21,7 @@ import org.apache.struts.actions.LookupDispatchAction; import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; +import org.lamsfoundation.lams.tool.sbmt.InstructionFiles; import org.lamsfoundation.lams.tool.sbmt.SubmitFilesContent; import org.lamsfoundation.lams.tool.sbmt.dto.AuthoringDTO; import org.lamsfoundation.lams.tool.sbmt.service.ISubmitFilesService; @@ -43,7 +44,7 @@ * type="org.lamsfoundation.lams.tool.sbmt.exception.SubmitFilesException" * key="authoring.exception" * path="/authoring/authoring.jsp" - * + */ public class AuthoringAction extends LookupDispatchAction { private Logger log = Logger.getLogger(AuthoringAction.class); @@ -135,69 +136,29 @@ file = (FormFile) authForm.get("onlineFile"); SubmitFilesContent content = getContent(form); + //Call setUp() as early as possible , so never loss the screen value if any exception happen. + setUp(request,content); submitFilesService = SubmitFilesServiceProxy.getSubmitFilesService(this .getServlet().getServletContext()); - submitFilesService.uploadFileToContent(content.getContentID(), file, type); - //send back the upload file list and display them on page SubmitFilesContent persistContent = submitFilesService.getSubmitFilesContent(content.getContentID()); content.setInstructionFiles(persistContent.getInstructionFiles()); - AuthoringDTO authorDto = new AuthoringDTO(content); - request.setAttribute(SbmtConstants.AUTHORING_DTO,authorDto); - return mapping.getInputForward(); - - } - /** - * Delete online file - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - public ActionForward deleteOffline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping, form, IToolContentHandler.TYPE_OFFLINE,request); - } - /** - * Delete offline file - * @param mapping - * @param form - * @param request - * @param response - * @return - */ - public ActionForward deleteOnline(ActionMapping mapping, ActionForm form, - HttpServletRequest request, HttpServletResponse response) { - return deleteFile(mapping, form, IToolContentHandler.TYPE_ONLINE,request); - } - - private ActionForward deleteFile(ActionMapping mapping, ActionForm form, String type, HttpServletRequest request) { - - SubmitFilesContent content = getContent(form); - submitFilesService = SubmitFilesServiceProxy.getSubmitFilesService(this - .getServlet().getServletContext()); - - Long uuid = new Long(WebUtil.readLongParam(request,"uuid")); - Long versionID = new Long(WebUtil.readLongParam(request,"versionID")); - submitFilesService.deleteFromRepository(uuid,versionID); + //content change, so call setup again. + setUp(request,content); - //send back the upload file list and display them on page - SubmitFilesContent persistContent = submitFilesService.getSubmitFilesContent(content.getContentID()); - content.setInstructionFiles(persistContent.getInstructionFiles()); - AuthoringDTO authorDto = new AuthoringDTO(content); - request.setAttribute(SbmtConstants.AUTHORING_DTO,authorDto); + submitFilesService.uploadFileToContent(content.getContentID(), file, type); + //add new uploaded file into DTO becuase content instruction file list comes from persistCotent. + //so it is not need refresh content again. + //content change, so call setup again. + setUp(request,content); return mapping.getInputForward(); - - } + } protected Map getKeyMethodMap() { Map map = new HashMap(); map.put("label.authoring.upload.online.button", "uploadOnline"); map.put("label.authoring.upload.offline.button", "uploadOffline"); map.put("label.authoring.save.button", "updateContent"); - map.put("label.authoring.online.delete","deleteOnline"); - map.put("label.authoring.offline.delete","deleteOffline"); return map; } @@ -221,14 +182,16 @@ SubmitFilesContent persistContent = submitFilesService.getSubmitFilesContent(contentID); //if this content does not exist, then reset the contentID to current value to keep it on HTML page. + if(persistContent == null) + persistContent = new SubmitFilesContent(); persistContent.setContentID(contentID); + setUp(request,persistContent); - AuthoringDTO authorDto = new AuthoringDTO(persistContent); - request.setAttribute(SbmtConstants.AUTHORING_DTO,authorDto); //set back STRUTS component value DynaActionForm authForm = (DynaActionForm) form; - authForm.set("title",authorDto.getTitle()); - authForm.set("lockOnFinished",authorDto.isLockOnFinished()?"1":null); + authForm.set("toolContentID",contentID); + authForm.set("title",persistContent.getTitle()); + authForm.set("lockOnFinished",persistContent.isLockOnFinished()?"1":null); return mapping.getInputForward(); } @@ -262,4 +225,15 @@ // content.setToolSession(); return content; } + /** + * This method will set initial values in authroing web page. Any method which handle request/response + * will call setUp() as early as possible , so never loss the screen value if any exception happen. + * @param request + * @param content + */ + private void setUp(HttpServletRequest request, SubmitFilesContent content) { + AuthoringDTO authorDto = new AuthoringDTO(content); + request.setAttribute(SbmtConstants.AUTHORING_DTO,authorDto); + } + } Index: lams_tool_sbmt/web/authoring/authoring.jsp =================================================================== diff -u -reebdf6c7a06bd126cf6331883dd60e4ca72ac5c9 -rc80bf4c3ad4122cedca89d2965789b5f380df406 --- lams_tool_sbmt/web/authoring/authoring.jsp (.../authoring.jsp) (revision eebdf6c7a06bd126cf6331883dd60e4ca72ac5c9) +++ lams_tool_sbmt/web/authoring/authoring.jsp (.../authoring.jsp) (revision c80bf4c3ad4122cedca89d2965789b5f380df406) @@ -27,7 +27,7 @@

- + @@ -48,7 +48,6 @@

:
- @@ -148,8 +147,6 @@

- -