Index: lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/McContent.hbm.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/Attic/McContent.hbm.xml,v diff -u -r1.12 -r1.13 --- lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/McContent.hbm.xml 15 Nov 2005 12:52:26 -0000 1.12 +++ lams_tool_lamc/conf/hibernate/mappings/org/lamsfoundation/lams/tool/mc/McContent.hbm.xml 10 Dec 2005 13:30:14 -0000 1.13 @@ -222,7 +222,25 @@ /> + + + + + + + + Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java,v diff -u -r1.42 -r1.43 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 27 Nov 2005 16:08:45 -0000 1.42 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 10 Dec 2005 13:30:13 -0000 1.43 @@ -231,6 +231,9 @@ public static final String LIST_UPLOADED_OFFLINE_FILES_NAME ="listUploadedOfflineFilesName"; public static final String LIST_UPLOADED_ONLINE_FILES_UUID ="listUploadedOnlineFilesUuid"; public static final String LIST_UPLOADED_ONLINE_FILES_NAME ="listUploadedOnlineFilesName"; + + public static final String LIST_OFFLINEFILES_METADATA ="listOfflineFilesMetadata"; + public static final String LIST_ONLINEFILES_METADATA ="listOnlineFilesMetadata"; public static final String POPULATED_UPLOADED_FILESDATA ="populateUploadedFilesData"; public static final String COUNT_SESSION_COMPLETE ="countSessionComplete"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAttachmentDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/Attic/McAttachmentDTO.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAttachmentDTO.java 10 Dec 2005 13:30:13 -0000 1.1 @@ -0,0 +1,88 @@ +/* + *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.mc; + + +/** + *

DTO that holds file attachment data for jsp purposes + *

+ * + * @author Ozgur Demirtas + */ +public class McAttachmentDTO +{ + private String uid; + + private String uuid; + + private boolean isOfflineFile; + + private String filename; + /** + * @return Returns the filename. + */ + public String getFilename() { + return filename; + } + /** + * @param filename The filename to set. + */ + public void setFilename(String filename) { + this.filename = filename; + } + + /** + * @return Returns the uuid. + */ + public String getUuid() { + return uuid; + } + /** + * @param uuid The uuid to set. + */ + public void setUuid(String uuid) { + this.uuid = uuid; + } + /** + * @return Returns the isOfflineFile. + */ + public boolean isOfflineFile() { + return isOfflineFile; + } + /** + * @param isOfflineFile The isOfflineFile to set. + */ + public void setOfflineFile(boolean isOfflineFile) { + this.isOfflineFile = isOfflineFile; + } + /** + * @return Returns the uid. + */ + public String getUid() { + return uid; + } + /** + * @param uid The uid to set. + */ + public void setUid(String uid) { + this.uid = uid; + } +} Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McContent.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/Attic/McContent.java,v diff -u -r1.9 -r1.10 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McContent.java 13 Nov 2005 13:20:24 -0000 1.9 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McContent.java 10 Dec 2005 13:30:13 -0000 1.10 @@ -113,9 +113,12 @@ /** persistent field */ private Set mcSessions; + + /** persistent field */ + private Set mcAttachments; /** full constructor */ - public McContent(Long mcContentId, String title, String instructions, boolean defineLater, boolean runOffline, String creationDate, Date updateDate, boolean questionsSequenced, boolean usernameVisible, String reportTitle, String monitoringReportTitle, long createdBy, boolean synchInMonitor, boolean contentInUse, String offlineInstructions, String onlineInstructions, String endLearningMessage, Integer passMark, boolean showFeedback, boolean retries, Set mcQueContents, Set mcSessions) { + public McContent(Long mcContentId, String title, String instructions, boolean defineLater, boolean runOffline, String creationDate, Date updateDate, boolean questionsSequenced, boolean usernameVisible, String reportTitle, String monitoringReportTitle, long createdBy, boolean synchInMonitor, boolean contentInUse, String offlineInstructions, String onlineInstructions, String endLearningMessage, Integer passMark, boolean showFeedback, boolean retries, Set mcQueContents, Set mcSessions, Set mcAttachments) { this.mcContentId = mcContentId; this.title = title; this.instructions = instructions; @@ -138,6 +141,7 @@ this.showFeedback = showFeedback; this.mcQueContents = mcQueContents; this.mcSessions = mcSessions; + this.mcAttachments = mcAttachments; } /** default constructor */ @@ -187,7 +191,9 @@ mc.isRetries(), mc.isShowFeedback(), new TreeSet(), - new TreeSet()); + new TreeSet(), + new TreeSet() + ); newContent.setMcQueContents(mc.deepCopyMcQueContent(newContent)); return newContent; } @@ -424,4 +430,16 @@ public void setShowReport(boolean showReport) { this.showReport = showReport; } + /** + * @return Returns the mcAttachments. + */ + public Set getMcAttachments() { + return mcAttachments; + } + /** + * @param mcAttachments The mcAttachments to set. + */ + public void setMcAttachments(Set mcAttachments) { + this.mcAttachments = mcAttachments; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml,v diff -u -r1.8 -r1.9 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml 2 Nov 2005 19:39:43 -0000 1.8 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/mcApplicationContext.xml 10 Dec 2005 13:30:13 -0000 1.9 @@ -63,6 +63,11 @@ + + + + + @@ -76,9 +81,11 @@ - - + + + + Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUploadedFileDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/Attic/IMcUploadedFileDAO.java,v diff -u -r1.6 -r1.7 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUploadedFileDAO.java 13 Nov 2005 13:20:24 -0000 1.6 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUploadedFileDAO.java 10 Dec 2005 13:30:14 -0000 1.7 @@ -165,6 +165,9 @@ * @param mcContentId * @return List */ + + public boolean isUuidPersisted(String uuid); + public void cleanUploadedFilesMetaData(); public void flush(); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUploadedFileDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/Attic/McUploadedFileDAO.java,v diff -u -r1.5 -r1.6 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUploadedFileDAO.java 11 Nov 2005 17:53:19 -0000 1.5 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUploadedFileDAO.java 10 Dec 2005 13:30:14 -0000 1.6 @@ -52,10 +52,11 @@ private static final String GET_FILES_UUID ="select mcUploadedFile.uuid from McUploadedFile mcUploadedFile where mcUploadedFile.filename=:filename"; - private static final String GET_OFFLINE_FILES_UUIDPLUSFILENAME = "select (mcUploadedFile.uuid + '~' + mcUploadedFile.filename) from McUploadedFile mcUploadedFile where mcUploadedFile.mcContentId = :mcContentId and mcUploadedFile.fileOnline=0"; private static final String FIND_ALL_UPLOADED_FILE_DATA = "from mcUploadedFile in class McUploadedFile"; + + private static final String IS_UUID_PERSISTED ="select mcUploadedFile.uuid from McUploadedFile mcUploadedFile where mcUploadedFile.uuid=:uuid"; public McUploadedFile getUploadedFileById(long submissionId) @@ -77,24 +78,28 @@ public void updateUploadFile(McUploadedFile mcUploadedFile) { + this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().update(mcUploadedFile); this.getSession().setFlushMode(FlushMode.AUTO); } public void saveUploadFile(McUploadedFile mcUploadedFile) { + this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().save(mcUploadedFile); this.getSession().setFlushMode(FlushMode.AUTO); } public void createUploadFile(McUploadedFile mcUploadedFile) { + this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().save(mcUploadedFile); } public void UpdateUploadFile(McUploadedFile mcUploadedFile) { + this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().update(mcUploadedFile); } @@ -118,6 +123,20 @@ } + public boolean isUuidPersisted(String uuid) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(IS_UUID_PERSISTED) + .setString("uuid", uuid) + .list(); + + if (list != null && list.size() > 0) + { + return true; + } + return false; + } + public String getFileUuid(String filename) { @@ -237,6 +256,7 @@ public void deleteUploadFile(McUploadedFile mcUploadedFile) { + this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(mcUploadedFile); } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java,v diff -u -r1.28 -r1.29 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 27 Nov 2005 16:08:44 -0000 1.28 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 10 Dec 2005 13:30:14 -0000 1.29 @@ -27,6 +27,7 @@ import org.lamsfoundation.lams.contentrepository.ITicket; import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.tool.BasicToolVO; import org.lamsfoundation.lams.tool.ToolSessionExportOutputData; @@ -223,5 +224,9 @@ public int countSessionIncomplete() throws McApplicationException; public List getNextAvailableDisplayOrder(final long mcContentId) throws McApplicationException; + + public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType) throws RepositoryCheckedException; + + public boolean isUuidPersisted(String uuid) throws McApplicationException; } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java,v diff -u -r1.31 -r1.32 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 27 Nov 2005 16:08:44 -0000 1.31 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 10 Dec 2005 13:30:14 -0000 1.32 @@ -39,6 +39,7 @@ import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException; +import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.contentrepository.service.IRepositoryService; import org.lamsfoundation.lams.contentrepository.service.RepositoryProxy; import org.lamsfoundation.lams.contentrepository.service.SimpleCredentials; @@ -103,6 +104,7 @@ private IUserManagementService userManagementService; private ILamsToolService toolService; + private IToolContentHandler mcToolContentHandler = null; public McServicePOJO(){} @@ -1618,8 +1620,30 @@ return listToolSessionIds; } + + public void removeAttachment(McContent content, McUploadedFile attachment) throws RepositoryCheckedException + { + try + { + attachment.setMcContent(null); + content.getMcAttachments().remove(attachment); + mcToolContentHandler.deleteFile(new Long(attachment.getUuid())); + saveMcContent(content); + } + catch (DataAccessException e) + { + throw new McApplicationException("EXCEPTION: An exception has occurred while trying to remove this attachment" + + e.getMessage(), e); + } + } + public NodeKey uploadFile(InputStream istream, String filename, String contentType, String fileType) throws RepositoryCheckedException + { + return mcToolContentHandler.uploadFile(istream, filename, contentType, fileType); + } + + /** * This method verifies the credentials of the SubmitFiles Tool and gives it * the Ticket to login and access the Content Repository. @@ -1744,9 +1768,13 @@ } } + + public boolean isUuidPersisted(String uuid) throws McApplicationException + { + return mcUploadedFileDAO.isUuidPersisted(uuid); + } + /** - * !! COMPLETE THIS !! - * * adds a new entry to the uploaded files table */ public void persistFile(String uuid, boolean isOnlineFile, String fileName, McContent mcContent) throws McApplicationException { @@ -2034,4 +2062,16 @@ this.mcUploadedFileDAO = mcUploadedFileDAO; } + /** + * @return Returns the mcToolContentHandler. + */ + public IToolContentHandler getMcToolContentHandler() { + return mcToolContentHandler; + } + /** + * @param mcToolContentHandler The mcToolContentHandler to set. + */ + public void setMcToolContentHandler(IToolContentHandler mcToolContentHandler) { + this.mcToolContentHandler = mcToolContentHandler; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/util/McToolContentHandler.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/util/McToolContentHandler.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/util/McToolContentHandler.java 10 Dec 2005 13:30:14 -0000 1.1 @@ -0,0 +1,64 @@ +/* +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.mc.util; + +import org.lamsfoundation.lams.contentrepository.client.ToolContentHandler; + +/** + * Simple client for accessing the content repository. + * + * @author Ozgur Demirtas + */ +public class McToolContentHandler extends ToolContentHandler { + + private static String repositoryWorkspaceName = "lamc11"; + private final String repositoryUser = "lamc11"; + private final char[] repositoryId = {'l','a','m','c','_','1', '1'}; + + + /** + * + */ + public McToolContentHandler() { + super(); + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryWorkspaceName() + */ + public String getRepositoryWorkspaceName() { + return repositoryWorkspaceName; + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryUser() + */ + public String getRepositoryUser() { + return repositoryUser; + } + + /* (non-Javadoc) + * @see org.lamsfoundation.lams.contentrepository.client.ToolContentHandler#getRepositoryId() + */ + public char[] getRepositoryId() { + return repositoryId; + } +} Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java,v diff -u -r1.14 -r1.15 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java 8 Dec 2005 19:40:05 -0000 1.14 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/AuthoringUtil.java 10 Dec 2005 13:30:47 -0000 1.15 @@ -3,6 +3,9 @@ */ package org.lamsfoundation.lams.tool.mc.web; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -15,8 +18,13 @@ import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; +import org.apache.struts.upload.FormFile; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.tool.exception.ToolException; import org.lamsfoundation.lams.tool.mc.McAppConstants; +import org.lamsfoundation.lams.tool.mc.McApplicationException; +import org.lamsfoundation.lams.tool.mc.McAttachmentDTO; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McContent; import org.lamsfoundation.lams.tool.mc.McOptsContent; @@ -1539,6 +1547,185 @@ } + public static McAttachmentDTO uploadFile(HttpServletRequest request, McAuthoringForm mcAuthoringForm, boolean isOfflineFile) throws RepositoryCheckedException + { + logger.debug("doing uploadFile..."); + logger.debug("isOfflineFile:" + isOfflineFile); + + InputStream stream=null; + String fileName=null; + String mimeType=null; + String fileProperty=null; + + if (isOfflineFile) + { + FormFile theOfflineFile = mcAuthoringForm.getTheOfflineFile(); + logger.debug("retrieved theOfflineFile: " + theOfflineFile); + + + try + { + stream = theOfflineFile.getInputStream(); + fileName=theOfflineFile.getFileName(); + logger.debug("retrieved fileName: " + fileName); + fileProperty="OFFLINE"; + + } + catch(FileNotFoundException e) + { + logger.debug("filenotfound exception occured in accessing the repository server for the offline file : " + e.getMessage()); + } + catch(IOException e) + { + logger.debug("io exception occured in accessing the repository server for the offline file : " + e.getMessage()); + } + + List listUploadedOfflineFileNames=(List)request.getSession().getAttribute(LIST_UPLOADED_OFFLINE_FILENAMES); + logger.debug("listUploadedOfflineFileNames:" + listUploadedOfflineFileNames); + listUploadedOfflineFileNames.add(fileName); + logger.debug("listUploadedOfflineFileNames after add :" + listUploadedOfflineFileNames); + request.getSession().setAttribute(LIST_UPLOADED_OFFLINE_FILENAMES,listUploadedOfflineFileNames); + } + else + { + FormFile theOnlineFile = mcAuthoringForm.getTheOnlineFile(); + logger.debug("retrieved theOnlineFile: " + theOnlineFile); + + try + { + stream = theOnlineFile.getInputStream(); + fileName=theOnlineFile.getFileName(); + logger.debug("retrieved fileName: " + fileName); + fileProperty="ONLINE"; + + } + catch(FileNotFoundException e) + { + logger.debug("filenotfound exception occured in accessing the repository server for the online file : " + e.getMessage()); + } + catch(IOException e) + { + logger.debug("io exception occured in accessing the repository server for the online file : " + e.getMessage()); + } + List listUploadedOnlineFileNames=(List)request.getSession().getAttribute(LIST_UPLOADED_ONLINE_FILENAMES); + logger.debug("listUploadedOnlineFileNames:" + listUploadedOnlineFileNames); + listUploadedOnlineFileNames.add(fileName); + logger.debug("listUploadedOnlineFileNames after add :" + listUploadedOnlineFileNames); + request.getSession().setAttribute(LIST_UPLOADED_ONLINE_FILENAMES,listUploadedOnlineFileNames); + } + + IMcService mcService =McUtils.getToolService(request); + logger.debug("calling uploadFile with:"); + logger.debug("istream:" + stream); + logger.debug("filename:" + fileName); + logger.debug("mimeType:" + mimeType); + logger.debug("fileProperty:" + fileProperty); + + NodeKey nodeKey=mcService.uploadFile(stream, fileName, mimeType, fileProperty); + logger.debug("nodeKey:" + nodeKey); + logger.debug("nodeKey uuid:" + nodeKey.getUuid()); + + McAttachmentDTO mcAttachmentDTO= new McAttachmentDTO(); + mcAttachmentDTO.setUid(null); + mcAttachmentDTO.setUuid(nodeKey.getUuid().toString()); + mcAttachmentDTO.setFilename(fileName); + mcAttachmentDTO.setOfflineFile(isOfflineFile); + + return mcAttachmentDTO; + } + + + public static void removeFileItem(HttpServletRequest request, String filename, String offlineFile) + { + logger.debug("offlineFile:" + offlineFile); + if (offlineFile.equals("1")) + { + logger.debug("will remove an offline file"); + List listUploadedOfflineFileNames=(List)request.getSession().getAttribute(LIST_UPLOADED_OFFLINE_FILENAMES); + logger.debug("listUploadedOfflineFileNames:" + listUploadedOfflineFileNames); + int index=findFileNameIndex(listUploadedOfflineFileNames, filename); + logger.debug("returned index:" + index); + listUploadedOfflineFileNames.remove(index); + logger.debug("listUploadedOfflineFileNames after remove :" + listUploadedOfflineFileNames); + request.getSession().setAttribute(LIST_UPLOADED_OFFLINE_FILENAMES,listUploadedOfflineFileNames); + } + else + { + logger.debug("will remove an online file"); + List listUploadedOnlineFileNames=(List)request.getSession().getAttribute(LIST_UPLOADED_ONLINE_FILENAMES); + logger.debug("listUploadedOnlineFileNames:" + listUploadedOnlineFileNames); + int index=findFileNameIndex(listUploadedOnlineFileNames, filename); + logger.debug("returned index:" + index); + listUploadedOnlineFileNames.remove(index); + logger.debug("listUploadedOnlineFileNames after remove :" + listUploadedOnlineFileNames); + request.getSession().setAttribute(LIST_UPLOADED_ONLINE_FILENAMES,listUploadedOnlineFileNames); + } + } + + + public static int findFileNameIndex(List listUploadedFileNames, String filename) + { + Iterator itListUploadedOfflineFileNames = listUploadedFileNames.iterator(); + int mainIndex=0; + while (itListUploadedOfflineFileNames.hasNext()) + { + mainIndex++; + String currentFilename=(String) itListUploadedOfflineFileNames.next(); + logger.debug("currentFilename :" + currentFilename); + if (currentFilename.equals(filename)) + { + logger.debug("currentFilename found in the list at mainIndex :" + mainIndex); + return mainIndex; + } + } + return 0; + } + + + public static void persistFilesMetaData(HttpServletRequest request, boolean isOfflineFile, McContent mcContent) + { + IMcService mcService =McUtils.getToolService(request); + + List listFilesMetaData=null; + logger.debug("doing persistFilesMetaData..."); + logger.debug("isOfflineFile:" + isOfflineFile); + + if (isOfflineFile) + { + listFilesMetaData =(List)request.getSession().getAttribute(LIST_OFFLINEFILES_METADATA); + } + else + { + listFilesMetaData =(List)request.getSession().getAttribute(LIST_ONLINEFILES_METADATA); + } + logger.debug("listFilesMetaData:" + listFilesMetaData); + + Iterator itListFilesMetaData = listFilesMetaData.iterator(); + while (itListFilesMetaData.hasNext()) + { + McAttachmentDTO mcAttachmentDTO=(McAttachmentDTO)itListFilesMetaData.next(); + logger.debug("mcAttachmentDTO:" + mcAttachmentDTO); + String uid=mcAttachmentDTO.getUid(); + logger.debug("uid:" + uid); + + String uuid=mcAttachmentDTO.getUuid(); + boolean isOnlineFile=!mcAttachmentDTO.isOfflineFile(); + String fileName=mcAttachmentDTO.getFilename(); + + if (uid == null) + { + logger.debug("persisting files metadata..."); + if (!mcService.isUuidPersisted(uuid)) + { + mcService.persistFile(uuid, isOnlineFile, fileName, mcContent); + } + } + } + } + + + + public void simulatePropertyInspector_RunOffline(HttpServletRequest request) { IMcService mcService =McUtils.getToolService(request); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java,v diff -u -r1.70 -r1.71 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java 8 Dec 2005 19:40:05 -0000 1.70 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAction.java 10 Dec 2005 13:30:47 -0000 1.71 @@ -39,8 +39,10 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.tool.mc.McAppConstants; import org.lamsfoundation.lams.tool.mc.McApplicationException; +import org.lamsfoundation.lams.tool.mc.McAttachmentDTO; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McContent; import org.lamsfoundation.lams.tool.mc.McOptsContent; @@ -1422,10 +1424,14 @@ logger.debug("calling selectAndPersistOptions"); AuthoringUtil.selectAndPersistOptions(request, mapStartupGeneralOptionsContent, mapStartupGeneralSelectedOptionsContent, mapGeneralOptionsContent, mapGeneralSelectedOptionsContent, mapStartupGeneralOptionsQueId); + logger.debug("start persisting offline files metadata"); + AuthoringUtil.persistFilesMetaData(request, true, mcContent); + logger.debug("start persisting online files metadata"); + AuthoringUtil.persistFilesMetaData(request, false, mcContent); - logger.debug("will do addUploadedFilesMetaData"); - McUtils.addUploadedFilesMetaData(request,mcContent); - logger.debug("done addUploadedFilesMetaData"); + //logger.debug("will do addUploadedFilesMetaData"); + //McUtils.addUploadedFilesMetaData(request,mcContent); + //logger.debug("done addUploadedFilesMetaData"); errors.clear(); errors.add(Globals.ERROR_KEY,new ActionMessage("submit.successful")); @@ -1529,12 +1535,59 @@ request.getSession().setAttribute(FILE_NAME, filename); mcAuthoringForm.resetUserAction(); - request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(2)); - logger.debug("setting EDIT_OPTIONS_MODE :" + 2); - return (mapping.findForward(ALL_INSTRUCTIONS)); + request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(0)); + logger.debug("setting EDIT_OPTIONS_MODE :" + 0); + return (mapping.findForward(LOAD_QUESTIONS)); } + + /** + * removes file data + * deleteFileItem(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + * + * @param request + * @param form + * @param mapping + * @return ActionForward + */ + public ActionForward deleteFileItem(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) throws IOException, + ServletException + + { + logger.debug("dispatching deleteFileItem..."); + McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; + IMcService mcService =McUtils.getToolService(request); + + AuthoringUtil.readData(request, mcAuthoringForm); + + String userAction="deleteFileItem"; + request.setAttribute(USER_ACTION, userAction); + logger.debug("userAction:" + userAction); + + String filename= request.getParameter("fileItem"); + logger.debug("filename:" + filename); + + String offlineFile= request.getParameter("offlineFile"); + logger.debug("offlineFile:" + offlineFile); + + logger.debug("start removing file:" + filename + " it is an:" + offlineFile); + AuthoringUtil.removeFileItem(request, filename, offlineFile); + logger.debug("done removing offline file"); + + mcAuthoringForm.resetUserAction(); + request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(0)); + logger.debug("setting EDIT_OPTIONS_MODE :" + 0); + return (mapping.findForward(LOAD_QUESTIONS)); + } + + /** * moves from Advanced Tab to Basic Tab * doneAdvancedTab(ActionMapping mapping, @@ -1616,7 +1669,8 @@ ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException + ServletException, + RepositoryCheckedException { logger.debug("dispatching submitOfflineFile..."); McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; @@ -1628,13 +1682,20 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - McUtils.addFileToContentRepository(request, mcAuthoringForm, true); - logger.debug("offline file added to repository successfully."); - + logger.debug("will uploadFile for offline file:"); + McAttachmentDTO mcAttachmentDTO=AuthoringUtil.uploadFile(request, mcAuthoringForm, true); + logger.debug("returned mcAttachmentDTO:" + mcAttachmentDTO); + + List listOfflineFilesMetaData =(List)request.getSession().getAttribute(LIST_OFFLINEFILES_METADATA); + logger.debug("listOfflineFilesMetaData:" + listOfflineFilesMetaData); + listOfflineFilesMetaData.add(mcAttachmentDTO); + logger.debug("listOfflineFilesMetaData after add:" + listOfflineFilesMetaData); + request.getSession().setAttribute(LIST_OFFLINEFILES_METADATA, listOfflineFilesMetaData); + mcAuthoringForm.resetUserAction(); - request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(2)); - logger.debug("setting EDIT_OPTIONS_MODE :" + 2 ); - return (mapping.findForward(ALL_INSTRUCTIONS)); + request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(0)); + logger.debug("setting EDIT_OPTIONS_MODE :" + 0); + return (mapping.findForward(LOAD_QUESTIONS)); } @@ -1654,7 +1715,8 @@ ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException + ServletException, + RepositoryCheckedException { logger.debug("dispatching submitOnlineFiles..."); McAuthoringForm mcAuthoringForm = (McAuthoringForm) form; @@ -1666,13 +1728,20 @@ request.setAttribute(USER_ACTION, userAction); logger.debug("userAction:" + userAction); - McUtils.addFileToContentRepository(request, mcAuthoringForm, false); - logger.debug("online file added to repository successfully."); - + logger.debug("will uploadFile for online file:"); + McAttachmentDTO mcAttachmentDTO=AuthoringUtil.uploadFile(request, mcAuthoringForm, false); + logger.debug("returned mcAttachmentDTO:" + mcAttachmentDTO); + + List listOnlineFilesMetaData =(List)request.getSession().getAttribute(LIST_ONLINEFILES_METADATA); + logger.debug("listOnlineFilesMetaData:" + listOnlineFilesMetaData); + listOnlineFilesMetaData.add(mcAttachmentDTO); + logger.debug("listOnlineFilesMetaData after add:" + listOnlineFilesMetaData); + request.getSession().setAttribute(LIST_ONLINEFILES_METADATA, listOnlineFilesMetaData); + mcAuthoringForm.resetUserAction(); - request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(2)); - logger.debug("setting EDIT_OPTIONS_MODE :" + 2); - return (mapping.findForward(ALL_INSTRUCTIONS)); + request.getSession().setAttribute(EDIT_OPTIONS_MODE, new Integer(0)); + logger.debug("setting EDIT_OPTIONS_MODE :" + 0); + return (mapping.findForward(LOAD_QUESTIONS)); } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java,v diff -u -r1.22 -r1.23 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java 8 Dec 2005 19:40:05 -0000 1.22 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McAuthoringForm.java 10 Dec 2005 13:30:47 -0000 1.23 @@ -24,6 +24,7 @@ protected String fileItem; protected FormFile receivedFile; + protected String offlineFile; protected String addContent; protected String removeContent; @@ -121,6 +122,7 @@ this.submitTabDone=null; this.submitOfflineFile=null; this.submitOnlineFile=null; + this.offlineFile=null; this.dispatch=null; @@ -726,4 +728,17 @@ public void setDispatch(String buttonValue) { this.dispatch = buttonValue; } + + /** + * @return Returns the offlineFile. + */ + public String getOfflineFile() { + return offlineFile; + } + /** + * @param offlineFile The offlineFile to set. + */ + public void setOfflineFile(String offlineFile) { + this.offlineFile = offlineFile; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java,v diff -u -r1.27 -r1.28 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java 27 Nov 2005 16:08:44 -0000 1.27 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McStarterAction.java 10 Dec 2005 13:30:47 -0000 1.28 @@ -589,6 +589,12 @@ request.getSession().setAttribute(LIST_UPLOADED_ONLINE_FILES,listUploadedOnlineFiles); request.getSession().setAttribute(LIST_UPLOADED_ONLINE_FILENAMES,listUploadedOnlineFileNames); + + LinkedList listOfflineFilesMetaData= new LinkedList(); + LinkedList listOnlineFilesMetaData= new LinkedList(); + request.getSession().setAttribute(LIST_OFFLINEFILES_METADATA, listOfflineFilesMetaData); + request.getSession().setAttribute(LIST_ONLINEFILES_METADATA, listOnlineFilesMetaData); + Map mapQuestionsContent= new TreeMap(new McComparator()); Map mapOptionsContent= new TreeMap(new McComparator()); Map mapDefaultOptionsContent= new TreeMap(new McComparator()); Index: lams_tool_lamc/web/InstructionsContent.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/web/Attic/InstructionsContent.jsp,v diff -u -r1.6 -r1.7 --- lams_tool_lamc/web/InstructionsContent.jsp 8 Dec 2005 19:40:29 -0000 1.6 +++ lams_tool_lamc/web/InstructionsContent.jsp 10 Dec 2005 13:30:47 -0000 1.7 @@ -16,6 +16,12 @@ submitMethod(actionMethod); } +function deleteFileItem(fileItemValue, actionMethod, offlineFile) { + document.McAuthoringForm.fileItem.value=fileItemValue; + document.McAuthoringForm.offlineFile.value=offlineFile; + submitMethod(actionMethod); +} + //--> @@ -55,6 +61,9 @@ ','viewFileItem');"> + + ','deleteFileItem', '1');"> + @@ -96,6 +105,9 @@ ','viewFileItem');"> + + ','deleteFileItem', '0');"> + Fisheye: Tag 1.6 refers to a dead (removed) revision in file `lams_tool_lamc/web/allInstructionsContent.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_lamc/web/WEB-INF/mcApplicationContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/web/WEB-INF/Attic/mcApplicationContext.xml,v diff -u -r1.2 -r1.3 --- lams_tool_lamc/web/WEB-INF/mcApplicationContext.xml 1 Oct 2005 16:23:48 -0000 1.2 +++ lams_tool_lamc/web/WEB-INF/mcApplicationContext.xml 10 Dec 2005 13:30:47 -0000 1.3 @@ -8,21 +8,22 @@ --> - + - + - /WEB-INF/McContent.hbm.xml - /WEB-INF/McSession.hbm.xml - /WEB-INF/McQueContent.hbm.xml - /WEB-INF/McQueUsr.hbm.xml - /WEB-INF/McUsrAttempt.hbm.xml - /WEB-INF/McOptionsContent.hbm.xml + /org/lamsfoundation/lams/tool/mc/McContent.hbm.xml + /org/lamsfoundation/lams/tool/mc/McQueContent.hbm.xml + /org/lamsfoundation/lams/tool/mc/McOptsContent.hbm.xml + /org/lamsfoundation/lams/tool/mc/McSession.hbm.xml + /org/lamsfoundation/lams/tool/mc/McQueUsr.hbm.xml + /org/lamsfoundation/lams/tool/mc/McUsrAttempt.hbm.xml + /org/lamsfoundation/lams/tool/mc/McUploadedFile.hbm.xml @@ -31,60 +32,73 @@ - + + + + + - + + + - + + - - - - - - - + + + + + + + + - + + + - PROPAGATION_REQUIRED,-QaApplicationException - PROPAGATION_REQUIRED,-QaApplicationException - PROPAGATION_REQUIRED, -QaApplicationException - PROPAGATION_REQUIRED,-QaApplicationException - PROPAGATION_REQUIRED,readOnly,-QacpApplicationException - PROPAGATION_REQUIRED,-QaApplicationException + PROPAGATION_REQUIRED,-McApplicationException + PROPAGATION_REQUIRED,-McApplicationException + PROPAGATION_REQUIRED, -McApplicationException + PROPAGATION_REQUIRED,-McApplicationException + PROPAGATION_REQUIRED,readOnly,-McApplicationException + PROPAGATION_REQUIRED,-McApplicationException + PROPAGATION_REQUIRED, ,-McApplicationException ---> - + Index: lams_tool_lamc/web/WEB-INF/struts-config.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/web/WEB-INF/struts-config.xml,v diff -u -r1.18 -r1.19 --- lams_tool_lamc/web/WEB-INF/struts-config.xml 8 Dec 2005 19:40:56 -0000 1.18 +++ lams_tool_lamc/web/WEB-INF/struts-config.xml 10 Dec 2005 13:30:47 -0000 1.19 @@ -94,11 +94,6 @@ redirect="true" /> - Index: lams_tool_lamc/web/WEB-INF/web.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/web/WEB-INF/web.xml,v diff -u -r1.7 -r1.8 --- lams_tool_lamc/web/WEB-INF/web.xml 7 Dec 2005 06:54:12 -0000 1.7 +++ lams_tool_lamc/web/WEB-INF/web.xml 10 Dec 2005 13:30:47 -0000 1.8 @@ -92,11 +92,29 @@ 1 + + + download + Instructions Download + Instructions Download + org.lamsfoundation.lams.contentrepository.client.ToolDownload + + toolContentHandlerBeanName + mcToolContentHandler + + 3 + + action *.do + + download + /download/* + + Connector /editor/filemanager/browser/default/connectors/jsp/connector Index: lams_tool_lamc/web/WEB-INF/tiles/tiles-defs.xml =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/web/WEB-INF/tiles/Attic/tiles-defs.xml,v diff -u -r1.15 -r1.16 --- lams_tool_lamc/web/WEB-INF/tiles/tiles-defs.xml 22 Nov 2005 20:38:07 -0000 1.15 +++ lams_tool_lamc/web/WEB-INF/tiles/tiles-defs.xml 10 Dec 2005 13:30:54 -0000 1.16 @@ -48,12 +48,6 @@ - - - - - -