Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -ra5b247dd91cb3ffabf9de46cba029e5537fad087 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision a5b247dd91cb3ffabf9de46cba029e5537fad087) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -23,6 +23,8 @@ package org.lamsfoundation.lams.tool.forum.service; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; @@ -103,7 +105,6 @@ import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.JsonUtil; import org.lamsfoundation.lams.util.MessageService; -import org.springframework.web.multipart.MultipartFile; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -278,7 +279,7 @@ @Override public void updateMark(Message message) { messageDao.saveOrUpdate(message); - + // send marks to gradebook, if marks are released for that session ForumUser user = message.getCreatedBy(); ForumToolSession session = message.getToolSession(); @@ -340,7 +341,7 @@ } // recursively delete clones - for (Message clone : (Set) topic.getSessionClones()) { + for (Message clone : topic.getSessionClones()) { this.deleteTopic(clone.getUid()); } @@ -398,16 +399,16 @@ } @Override - public Attachment uploadAttachment(MultipartFile uploadFile) throws PersistenceException { - if ((uploadFile == null) || StringUtils.isEmpty(uploadFile.getOriginalFilename())) { + public Attachment uploadAttachment(File uploadFile) throws PersistenceException { + if ((uploadFile == null) || StringUtils.isEmpty(uploadFile.getName())) { throw new ForumException("Could not find upload file: " + uploadFile); } NodeKey nodeKey = processFile(uploadFile); Attachment file = new Attachment(); file.setFileUuid(nodeKey.getUuid()); file.setFileVersionId(nodeKey.getVersion()); - file.setFileName(uploadFile.getOriginalFilename()); + file.setFileName(uploadFile.getName()); return file; } @@ -610,7 +611,7 @@ // update session to set MarkRelease flag session.setMarkReleased(true); forumToolSessionDao.saveOrUpdate(session); - + // notify learners on mark release if (notifyLearnersOnMarkRelease) { Map notificationMessages = new TreeMap<>(); @@ -642,10 +643,11 @@ } } - + //audit log event - String sessionName = session.getSessionName() + " (toolSessionId=" + session.getSessionId() + ")"; - String message = messageService.getMessage("tool.display.name") + ". " + messageService.getMessage("msg.mark.released", new String[] { sessionName }); + String sessionName = session.getSessionName() + " (toolSessionId=" + session.getSessionId() + ")"; + String message = messageService.getMessage("tool.display.name") + ". " + + messageService.getMessage("msg.mark.released", new String[] { sessionName }); logEventService.logToolEvent(LogEvent.TYPE_TOOL_MARK_RELEASED, forum.getContentId(), null, message); } @@ -725,19 +727,13 @@ /** * Process an uploaded file. - * - * @param forumForm - * @throws FileNotFoundException - * @throws IOException - * @throws RepositoryCheckedException - * @throws InvalidParameterException */ - private NodeKey processFile(MultipartFile file) { + private NodeKey processFile(File file) { NodeKey node = null; - if ((file != null) && !StringUtils.isEmpty(file.getOriginalFilename())) { - String fileName = file.getOriginalFilename(); + if ((file != null) && !StringUtils.isEmpty(file.getName())) { + String fileName = file.getName(); try { - node = getForumToolContentHandler().uploadFile(file.getInputStream(), fileName, file.getContentType()); + node = getForumToolContentHandler().uploadFile(new FileInputStream(file), fileName, null); } catch (InvalidParameterException e) { throw new ForumException("FileNotFoundException occured while trying to upload File" + e.getMessage()); } catch (FileNotFoundException e) { @@ -800,7 +796,7 @@ public void auditLogStartEditingActivityInMonitor(long toolContentID) { toolService.auditLogStartEditingActivityInMonitor(toolContentID); } - + @Override public boolean isLastActivity(Long toolSessionId) { return toolService.isLastActivity(toolSessionId); @@ -1179,7 +1175,7 @@ public List getConfidenceLevels(Long toolSessionId) { return null; } - + @Override public boolean isUserGroupLeader(Long userId, Long toolSessionId) { return false; Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java =================================================================== diff -u -ra5b247dd91cb3ffabf9de46cba029e5537fad087 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision a5b247dd91cb3ffabf9de46cba029e5537fad087) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -23,6 +23,7 @@ package org.lamsfoundation.lams.tool.forum.service; +import java.io.File; import java.util.Collection; import java.util.List; @@ -43,7 +44,6 @@ import org.lamsfoundation.lams.tool.forum.model.MessageSeq; import org.lamsfoundation.lams.tool.forum.util.PersistenceException; import org.lamsfoundation.lams.tool.service.ICommonToolService; -import org.springframework.web.multipart.MultipartFile; /** * User: conradb Date: 8/06/2005 Time: 14:49:59 @@ -171,7 +171,7 @@ * @return Attachment A new instance of attachment has uploaded file VersionID and UUID information. * @throws PersistenceException */ - Attachment uploadAttachment(MultipartFile file) throws PersistenceException; + Attachment uploadAttachment(File file) throws PersistenceException; // ************************************************************************************ // *********************Get topic methods ********************** Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java (.../AuthoringController.java) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java (.../AuthoringController.java) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -23,6 +23,7 @@ package org.lamsfoundation.lams.tool.forum.web.controller; +import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -64,6 +65,7 @@ import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.CommonConstants; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; @@ -77,7 +79,6 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.multipart.MultipartFile; /** * @author Steve.Ni @@ -362,6 +363,7 @@ public String newTopic(@ModelAttribute("topicFormId") MessageForm topicFormId, HttpServletRequest request) { String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); topicFormId.setSessionMapID(sessionMapID); + topicFormId.setTmpFileUploadId(FileUtil.generateTmpFileUploadId()); return "jsps/authoring/message/create"; } @@ -417,11 +419,7 @@ message.setModifiedBy(forumUser); // set attachment of this topic - Set attSet = null; - if (messageForm.getAttachmentFile() != null - && !StringUtils.isEmpty(messageForm.getAttachmentFile().getOriginalFilename())) { - attSet = setupAttachmentSet(messageForm.getAttachmentFile(), message); - } + Set attSet = setupAttachmentSet(messageForm, message); message.setAttachments(attSet); // LDEV-4696 no longer needed - cannot edit in monitoring once a session is created. @@ -513,17 +511,21 @@ request.setAttribute(ForumConstants.AUTHORING_TOPIC, topic); } + topicFormId.setTmpFileUploadId(FileUtil.generateTmpFileUploadId()); + request.setAttribute(ForumConstants.AUTHORING_TOPICS_INDEX, topicIndex); return "jsps/authoring/message/edit"; } /** * Submit user updated inforamion in a topic to memory. This update will be submit to database only when user save * whole authoring page. + * + * @throws ServletException */ @RequestMapping(path = "/updateTopic", method = RequestMethod.POST) public String updateTopic(@ModelAttribute("topicFormId") MessageForm messageForm, HttpServletRequest request) - throws PersistenceException { + throws PersistenceException, ServletException { //validate form MultiValueMap errorMap = messageForm.validate(request, messageService); if (!errorMap.isEmpty()) { @@ -553,20 +555,15 @@ newMsg.getMessage().setBody(message.getBody()); newMsg.getMessage().setUpdated(new Date()); // update attachment - if (messageForm.getAttachmentFile() != null - && !StringUtils.isEmpty(messageForm.getAttachmentFile().getOriginalFilename())) { - Attachment att = forumService.uploadAttachment(messageForm.getAttachmentFile()); - Set attSet = setupAttachmentSet(messageForm.getAttachmentFile(), newMsg.getMessage()); - newMsg.setHasAttachment(true); - newMsg.getMessage().setAttachments(attSet); - } else if (!messageForm.isHasAttachment()) { - Set att = newMsg.getMessage().getAttachments(); - if (att != null && att.size() > 0) { + if (!messageForm.isHasAttachment()) { + Set oldAttachments = newMsg.getMessage().getAttachments(); + if (oldAttachments != null && oldAttachments.size() > 0) { List delTopicAtt = getTopicDeletedAttachmentList(sessionMap); - delTopicAtt.add(att.iterator().next()); + delTopicAtt.add(oldAttachments.iterator().next()); } - newMsg.setHasAttachment(false); - newMsg.getMessage().setAttachments(null); + Set attSet = setupAttachmentSet(messageForm, newMsg.getMessage()); + newMsg.getMessage().setAttachments(attSet); + newMsg.setHasAttachment(!attSet.isEmpty()); } } @@ -575,11 +572,27 @@ } /* only allow one attachment, so replace whatever */ - private Set setupAttachmentSet(MultipartFile attachmentFile, Message msg) { - Attachment att = forumService.uploadAttachment(attachmentFile); + private Set setupAttachmentSet(MessageForm messageForm, Message msg) throws ServletException { Set attSet = new HashSet<>(); - attSet.add(att); - att.setMessage(msg); + + File uploadDir = FileUtil.getTmpFileUploadDir(messageForm.getTmpFileUploadId()); + if (uploadDir.canRead()) { + File[] files = uploadDir.listFiles(); + if (files.length > 1) { + throw new ServletException("Uploaded more than 1 file"); + } + + if (files.length == 1) { + + File file = files[0]; + Attachment att = forumService.uploadAttachment(file); + attSet.add(att); + att.setMessage(msg); + + FileUtil.deleteTmpFileUploadDir(messageForm.getTmpFileUploadId()); + } + } + return attSet; } @@ -589,6 +602,7 @@ @RequestMapping(path = "/deleteAttachment", method = RequestMethod.POST) public String deleteAttachment(HttpServletRequest request) { request.setAttribute("itemAttachment", null); + request.setAttribute("tmpFileUploadId", FileUtil.generateTmpFileUploadId()); return "jsps/authoring/parts/msgattachment"; } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/LearningController.java =================================================================== diff -u -r3ee06bc1b00b1673399c1871a73cfa1d8ec2c0db -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/LearningController.java (.../LearningController.java) (revision 3ee06bc1b00b1673399c1871a73cfa1d8ec2c0db) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/LearningController.java (.../LearningController.java) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -23,9 +23,9 @@ package org.lamsfoundation.lams.tool.forum.web.controller; +import java.io.File; import java.io.IOException; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -36,7 +36,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.lamsfoundation.lams.events.IEventNotificationService; import org.lamsfoundation.lams.notebook.model.NotebookEntry; @@ -62,6 +61,7 @@ import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.DateUtil; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.FileValidatorUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; @@ -290,7 +290,8 @@ HttpServletResponse response) { String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE); Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); @@ -338,7 +339,8 @@ Integer userId = reflectionForm.getUserID(); String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); // check for existing notebook entry @@ -406,7 +408,8 @@ Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); // get forum user and forum @@ -447,7 +450,8 @@ Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); // get forum user and forum @@ -514,7 +518,8 @@ Long highlightMessageUid = WebUtil.readLongParam(request, ForumConstants.ATTR_MESS_ID, true); String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); // get forum user and forum @@ -553,7 +558,8 @@ Long messageUid = WebUtil.readLongParam(request, ForumConstants.ATTR_MESS_ID, true); String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); // get forum user and forum @@ -588,6 +594,7 @@ public String newTopic(@ModelAttribute MessageForm messageForm, HttpServletRequest request) { // transfer SessionMapID as well messageForm.setSessionMapID(WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID)); + messageForm.setTmpFileUploadId(FileUtil.generateTmpFileUploadId()); return "jsps/learning/create"; } @@ -689,7 +696,7 @@ sessionMap.put(ForumConstants.ATTR_HIDE_REFLECTION, hideReflection); return "jsps/learning/reply"; } - + /** * Create a replayed topic for a parent topic. */ @@ -702,17 +709,19 @@ request.setAttribute("errorMap", errorMap); return "jsps/learning/reply"; } - + return "forward:/learning/replyTopicJSON.do"; } /** * In case validation was successful, we store message and return JSON object back to HTML + * + * @throws ServletException */ @RequestMapping("/replyTopicJSON") @ResponseBody public String replyTopicJSON(@ModelAttribute MessageForm messageForm, HttpServletRequest request, - HttpServletResponse response) throws InterruptedException, IOException { + HttpServletResponse response) throws InterruptedException, IOException, ServletException { SessionMap sessionMap = getSessionMap(request, messageForm); Long parentId = (Long) sessionMap.get(ForumConstants.ATTR_PARENT_TOPIC_ID); @@ -782,6 +791,8 @@ SessionMap sessionMap = getSessionMap(request, messageForm); sessionMap.put(ForumConstants.ATTR_TOPIC_ID, topicId); + messageForm.setTmpFileUploadId(FileUtil.generateTmpFileUploadId()); + // Should we show the reflection or not? We shouldn't show it when the View Forum screen is accessed // from the Monitoring Summary screen, but we should when accessed from the Learner Progress screen. // Need to constantly past this value on, rather than hiding just the once, as the View Forum @@ -806,6 +817,7 @@ SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapId); request.setAttribute(ForumConstants.ATTR_ALLOW_UPLOAD, sessionMap.get(ForumConstants.ATTR_ALLOW_UPLOAD)); request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapId); + request.setAttribute("tmpFileUploadId", FileUtil.generateTmpFileUploadId()); return "jsps/learning/message/msgattachment"; } @@ -824,15 +836,17 @@ return "forward:/learning/updateTopicJSON.do"; } - + /** * In case validation was successful, we store message and return JSON object back to HTML + * + * @throws ServletException */ @RequestMapping("/updateTopicJSON") @ResponseBody public String updateTopicJSON(@ModelAttribute MessageForm messageForm, HttpServletRequest request, - HttpServletResponse response) throws PersistenceException, IOException { - + HttpServletResponse response) throws PersistenceException, IOException, ServletException { + SessionMap sessionMap = getSessionMap(request, messageForm); Long topicId = (Long) sessionMap.get(ForumConstants.ATTR_TOPIC_ID); Message message = messageForm.getMessage(); @@ -970,7 +984,8 @@ * Validation method to check whether user posts meet minimum number. */ private boolean validateBeforeFinish(HttpServletRequest request, String sessionMapID) { - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + SessionMap sessionMap = (SessionMap) request.getSession() + .getAttribute(sessionMapID); Long sessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); ForumToolSession session = forumService.getSessionBySessionId(sessionId); @@ -1056,30 +1071,31 @@ /** * Get Forum Service. + * + * @throws ServletException */ - private void setAttachment(MessageForm messageForm, Message message) { - if (messageForm.getAttachmentFile() != null - && !StringUtils.isBlank(messageForm.getAttachmentFile().getOriginalFilename())) { - - Attachment att = forumService.uploadAttachment(messageForm.getAttachmentFile()); + private void setAttachment(MessageForm messageForm, Message message) throws ServletException { + // update attachment + if (!messageForm.isHasAttachment()) { Set attSet = message.getAttachments(); - if (attSet == null) { - attSet = new HashSet(); - } - // only allow one attachment, so replace whatever attSet.clear(); - attSet.add(att); - att.setMessage(message); - message.setAttachments(attSet); - } else if (!messageForm.isHasAttachment()) { - // user already called deleteAttachment in AJAX call - if (message.getAttachments() != null) { - Set atts = message.getAttachments(); - atts.clear(); - message.setAttachments(atts); - } else { - message.setAttachments(null); + + File uploadDir = FileUtil.getTmpFileUploadDir(messageForm.getTmpFileUploadId()); + if (uploadDir.canRead()) { + File[] files = uploadDir.listFiles(); + if (files.length > 1) { + throw new ServletException("Uploaded more than 1 file"); + } + + if (files.length == 1) { + File file = files[0]; + Attachment att = forumService.uploadAttachment(file); + attSet.add(att); + att.setMessage(message); + + FileUtil.deleteTmpFileUploadDir(messageForm.getTmpFileUploadId()); + } } } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java =================================================================== diff -u -rb71c9cb2f96eb891545d32aaca8904051d1e00d5 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java (.../MessageForm.java) (revision b71c9cb2f96eb891545d32aaca8904051d1e00d5) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java (.../MessageForm.java) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -27,14 +27,10 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.tool.forum.model.Attachment; import org.lamsfoundation.lams.tool.forum.model.Message; -import org.lamsfoundation.lams.util.FileUtil; -import org.lamsfoundation.lams.util.FileValidatorUtil; import org.lamsfoundation.lams.util.MessageService; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.multipart.MultipartFile; /** * @@ -57,9 +53,9 @@ private boolean hasAttachment; // attachment file name private String attachmentName; - // Message attachment file - private MultipartFile attachmentFile; + private String tmpFileUploadId; + public MessageForm() { message = new Message(); } @@ -70,7 +66,7 @@ */ public MultiValueMap validate(HttpServletRequest request, MessageService messageService) { - MultiValueMap errorMap = new LinkedMultiValueMap(); + MultiValueMap errorMap = new LinkedMultiValueMap<>(); try { if (StringUtils.isBlank(message.getSubject())) { @@ -81,18 +77,7 @@ errorMap.add("message.body", messageService.getMessage("error.body.required")); } - // validate item size - boolean largeFile = true; - if (request.getRequestURI().indexOf("/learning/") != -1) { - if ((this.getAttachmentFile() != null) - && FileUtil.isExecutableFile(this.getAttachmentFile().getOriginalFilename())) { - errorMap.add("message.attachments", messageService.getMessage("error.attachment.executable")); - } - largeFile = false; - } - FileValidatorUtil.validateFileSize(this.getAttachmentFile(), largeFile); - } catch (Exception e) { MessageForm.logger.error("", e); } @@ -105,7 +90,7 @@ if (message != null) { if ((message.getAttachments() != null) && (message.getAttachments().size() > 0)) { hasAttachment = true; - attachmentName = ((Attachment) message.getAttachments().iterator().next()).getFileName(); + attachmentName = message.getAttachments().iterator().next().getFileName(); } else { hasAttachment = false; attachmentName = null; @@ -149,12 +134,12 @@ this.attachmentName = attachmentName; } - public MultipartFile getAttachmentFile() { - return attachmentFile; + public String getTmpFileUploadId() { + return tmpFileUploadId; } - public void setAttachmentFile(MultipartFile attachmentFile) { - this.attachmentFile = attachmentFile; + public void setTmpFileUploadId(String tmpFileUploadId) { + this.tmpFileUploadId = tmpFileUploadId; } public String getSessionMapID() { Index: lams_tool_forum/web/common/tabbedheader.jsp =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/common/tabbedheader.jsp (.../tabbedheader.jsp) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_tool_forum/web/common/tabbedheader.jsp (.../tabbedheader.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -30,6 +30,5 @@ - Index: lams_tool_forum/web/includes/javascript/message.js =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/includes/javascript/message.js (.../message.js) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/web/includes/javascript/message.js (.../message.js) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -82,4 +82,88 @@ }); $(".rating-stars-new").removeClass("rating-stars-new"); } - + + /** + * Initialised Uppy as the file upload widget + */ + function initFileUpload(tmpFileUploadId, largeFilesAllowed, language) { + var uppyProperties = { + // upload immediately + autoProceed: true, + allowMultipleUploads: true, + debug: false, + restrictions: { + // taken from LAMS configuration + maxFileSize: largeFilesAllowed ? +UPLOAD_FILE_LARGE_MAX_SIZE : +UPLOAD_FILE_MAX_SIZE, + maxNumberOfFiles: 1 + }, + meta: { + // all uploaded files go to this subdir in LAMS tmp dir + // its format is: upload__ + 'tmpFileUploadId' : tmpFileUploadId, + 'largeFilesAllowed' : largeFilesAllowed + }, + onBeforeFileAdded: function(currentFile, files) { + var name = currentFile.data.name, + extensionIndex = name.lastIndexOf('.'), + valid = extensionIndex < 0 || !EXE_FILE_TYPES.includes(name.substring(extensionIndex).trim()); + if (!valid) { + uppy.info(EXE_FILE_ERROR, 'error', 10000); + } + + return valid; + } + }; + + switch(language) { + case 'es' : uppyProperties.locale = Uppy.locales.es_ES; break; + case 'fr' : uppyProperties.locale = Uppy.locales.fr_FR; break; + case 'el' : uppyProperties.locale = Uppy.locales.el_GR; break; + } + + + // global variable + uppy = Uppy.Core(uppyProperties); + // upload using Ajax + uppy.use(Uppy.XHRUpload, { + endpoint: LAMS_URL + 'tmpFileUpload', + fieldName : 'file', + // files are uploaded one by one + limit : 1 + }); + + uppy.use(Uppy.Dashboard, { + target: '#image-upload-area', + inline: true, + height: 300, + width: '100%', + showProgressDetails : true, + hideRetryButton : true, + hideCancelButton : true, + showRemoveButtonAfterComplete: true, + proudlyDisplayPoweredByUppy: false + }); + + uppy.use(Uppy.Webcam, { + target: Uppy.Dashboard, + modes: ['picture'] + }); + + uppy.on('upload-success', (file, response) => { + // if file name was modified by server, reflect it in Uppy + file.meta.name = response.body.name; + }); + + uppy.on('file-removed', (file, reason) => { + if (reason === 'removed-by-user') { + // delete file from temporary folder on server + $.ajax({ + url : LAMS_URL + 'tmpFileUploadDelete', + data : { + 'tmpFileUploadId' : tmpFileUploadId, + 'name' : file.meta.name + } + }) + } + }) + } Index: lams_tool_forum/web/jsps/authoring/authoring.jsp =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/authoring/authoring.jsp (.../authoring.jsp) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/web/jsps/authoring/authoring.jsp (.../authoring.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -1,16 +1,30 @@ <%@ include file="/common/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.util.Configuration" %> +<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%@ page import="org.lamsfoundation.lams.util.FileValidatorUtil" %> <%@ page import="org.lamsfoundation.lams.tool.forum.ForumConstants"%> +<%=Configuration.get(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE)%> +<%=Configuration.get(ConfigurationKeys.UPLOAD_FILE_MAX_SIZE)%> +<%=Configuration.get(ConfigurationKeys.EXE_EXTENSIONS)%> + <fmt:message key="activity.title" /> <%@ include file="/common/tabbedheader.jsp"%> - + Index: lams_tool_forum/web/jsps/authoring/basic.jsp =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/authoring/basic.jsp (.../basic.jsp) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/web/jsps/authoring/basic.jsp (.../basic.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -118,19 +118,6 @@ CKEDITOR.instances[instance].updateElement(); } - var LABEL_MAX_FILE_SIZE = '{0}'; - var LABEL_NOT_ALLOWED_FORMAT = ''; - - var fileSelect = document.getElementById('attachmentFile'); - // Get the selected files from the input. - var files = fileSelect.files; - if (files.length > 0) { - var file = files[0]; - if ( ! validateShowErrorNotExecutable(file, LABEL_NOT_ALLOWED_FORMAT, false, '${EXE_FILE_TYPES}') || ! validateShowErrorFileSize(file, '${UPLOAD_FILE_MAX_SIZE}', LABEL_MAX_FILE_SIZE, false) ) - return false; - } - - showBusy("itemAttachmentArea"); var formData = new FormData(document.getElementById("topicFormId")); $.ajax({ // create an AJAX call... data: formData, @@ -140,7 +127,6 @@ url: $("#topicFormId").attr('action'), success: function(data) { $('#messageArea').html(data); - hideBusy("itemAttachmentArea"); } }); } Index: lams_tool_forum/web/jsps/authoring/message/create.jsp =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/authoring/message/create.jsp (.../create.jsp) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/web/jsps/authoring/message/create.jsp (.../create.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -1,14 +1,29 @@ <%@ include file="/common/taglibs.jsp"%> -<%@ page import="org.lamsfoundation.lams.util.Configuration" %> -<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> -<%@ page import="org.lamsfoundation.lams.util.FileValidatorUtil" %> -<%=FileValidatorUtil.formatSize(Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE))%> <%@ include file="/common/header.jsp"%> + + + + + + + + + + + + + + + @@ -40,11 +55,12 @@
- - + + +
+ -
Index: lams_tool_forum/web/jsps/authoring/message/edit.jsp =================================================================== diff -u -rfaaf36eefd3eed3baeae46071e5f754e8b24a7b0 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/authoring/message/edit.jsp (.../edit.jsp) (revision faaf36eefd3eed3baeae46071e5f754e8b24a7b0) +++ lams_tool_forum/web/jsps/authoring/message/edit.jsp (.../edit.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -4,6 +4,8 @@ <%@ include file="/common/header.jsp"%> + + @@ -41,7 +43,6 @@
-
<%@ include file="/jsps/authoring/parts/msgattachment.jsp"%>
Index: lams_tool_forum/web/jsps/authoring/parts/msgattachment.jsp =================================================================== diff -u -rc9ee204be2fbc37ed1fd4c7eb8267bc103d98a24 -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/authoring/parts/msgattachment.jsp (.../msgattachment.jsp) (revision c9ee204be2fbc37ed1fd4c7eb8267bc103d98a24) +++ lams_tool_forum/web/jsps/authoring/parts/msgattachment.jsp (.../msgattachment.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -27,7 +27,13 @@ - + + +
+
Index: lams_tool_forum/web/jsps/learning/create.jsp =================================================================== diff -u -r24ebb6c91f49a10f1e5718036b3a3c1a80c3314f -r6132d98ee813109713fda3579007d4359596fc1e --- lams_tool_forum/web/jsps/learning/create.jsp (.../create.jsp) (revision 24ebb6c91f49a10f1e5718036b3a3c1a80c3314f) +++ lams_tool_forum/web/jsps/learning/create.jsp (.../create.jsp) (revision 6132d98ee813109713fda3579007d4359596fc1e) @@ -2,19 +2,24 @@ <%@ include file="/common/taglibs.jsp"%> <%@ page import="org.lamsfoundation.lams.util.Configuration" %> <%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%@ page import="org.lamsfoundation.lams.util.FileValidatorUtil" %> +<%@ page import="org.lamsfoundation.lams.tool.forum.ForumConstants"%> +<%=Configuration.get(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE)%> <%=Configuration.get(ConfigurationKeys.UPLOAD_FILE_MAX_SIZE)%> <%=Configuration.get(ConfigurationKeys.EXE_EXTENSIONS)%> - + <fmt:message key="activity.title" /> + +