Index: lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java,v
diff -u -r1.2 -r1.3
--- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java 29 Jul 2005 05:25:18 -0000 1.2
+++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/dto/AuthoringDTO.java 4 Aug 2005 06:13:06 -0000 1.3
@@ -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
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java,v
diff -u -r1.14 -r1.15
--- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java 4 Aug 2005 04:40:58 -0000 1.14
+++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/ISubmitFilesService.java 4 Aug 2005 06:13:06 -0000 1.15
@@ -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
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java,v
diff -u -r1.19 -r1.20
--- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java 4 Aug 2005 04:40:58 -0000 1.19
+++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/service/SubmitFilesService.java 4 Aug 2005 06:13:06 -0000 1.20
@@ -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
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java,v
diff -u -r1.6 -r1.7
--- lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java 1 Aug 2005 01:27:28 -0000 1.6
+++ lams_tool_sbmt/src/java/org/lamsfoundation/lams/tool/sbmt/web/AuthoringAction.java 4 Aug 2005 06:13:07 -0000 1.7
@@ -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
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_sbmt/web/authoring/authoring.jsp,v
diff -u -r1.6 -r1.7
--- lams_tool_sbmt/web/authoring/authoring.jsp 4 Aug 2005 04:40:58 -0000 1.6
+++ lams_tool_sbmt/web/authoring/authoring.jsp 4 Aug 2005 06:13:07 -0000 1.7
@@ -27,7 +27,7 @@