Index: lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java =================================================================== diff -u -rbdbfb41770c933c155f327d5dd1cfbd09138b31a -radd24141d43ff78942c251760e1614925db89464 --- lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java (.../QuestionsController.java) (revision bdbfb41770c933c155f327d5dd1cfbd09138b31a) +++ lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java (.../QuestionsController.java) (revision add24141d43ff78942c251760e1614925db89464) @@ -1,6 +1,7 @@ package org.lamsfoundation.lams.web; import java.io.File; +import java.io.FileInputStream; import java.io.InputStream; import java.util.Collections; import java.util.Set; @@ -16,6 +17,7 @@ import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.FileUtil; import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; @@ -26,7 +28,6 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; /** * Runs extraction of chosen IMS QTI zip file and prepares form for user to manually choose interesting question. @@ -42,22 +43,24 @@ private IQbService qbService; @RequestMapping("/questions") - public String execute(@RequestParam(name = "file", required = false) MultipartFile file, - @RequestParam String returnURL, @RequestParam("limitType") String limitTypeParam, - @RequestParam String callerID, @RequestParam(required = false) Boolean collectionChoice, - HttpServletRequest request) throws Exception { + public String execute(@RequestParam String tmpFileUploadId, @RequestParam String returnURL, + @RequestParam("limitType") String limitTypeParam, @RequestParam String callerID, + @RequestParam(required = false) Boolean collectionChoice, HttpServletRequest request) throws Exception { - String tempDirName = Configuration.get(ConfigurationKeys.LAMS_TEMP_DIR); - File tempDir = new File(tempDirName); - if (!tempDir.exists()) { - tempDir.mkdirs(); - } - - InputStream uploadedFileStream = null; + MultiValueMap errorMap = new LinkedMultiValueMap<>(); String packageName = null; - if (file != null) { - packageName = file.getOriginalFilename().toLowerCase(); - uploadedFileStream = file.getInputStream(); + + File file = null; + File uploadDir = FileUtil.getTmpFileUploadDir(tmpFileUploadId); + if (uploadDir.canRead()) { + File[] files = uploadDir.listFiles(); + if (files.length > 1) { + errorMap.add("GLOBAL", "Uploaded more than 1 file"); + } else if (files.length == 1) { + file = files[0]; + packageName = file.getName().toLowerCase(); + ; + } } // this parameter is not really used at the moment @@ -75,20 +78,31 @@ } // user did not choose a file - if ((uploadedFileStream == null) || !(packageName.endsWith(".zip") || packageName.endsWith(".xml"))) { - MultiValueMap errorMap = new LinkedMultiValueMap<>(); + if (file == null || !(packageName.endsWith(".zip") || packageName.endsWith(".xml"))) { errorMap.add("GLOBAL", messageService.getMessage("label.questions.file.missing")); + } + + if (!errorMap.isEmpty()) { + request.setAttribute("tmpFileUploadId", tmpFileUploadId); request.setAttribute("errorMap", errorMap); return "questions/questionFile"; } + String tempDirName = Configuration.get(ConfigurationKeys.LAMS_TEMP_DIR); + File tempDir = new File(tempDirName); + if (!tempDir.exists()) { + tempDir.mkdirs(); + } + Set limitType = null; if (!StringUtils.isBlank(limitTypeParam)) { limitType = new TreeSet<>(); // comma delimited acceptable question types, for example "mc,fb" Collections.addAll(limitType, limitTypeParam.split(",")); } + InputStream uploadedFileStream = new FileInputStream(file); + Question[] questions = packageName.endsWith(".xml") ? QuestionParser.parseQTIFile(uploadedFileStream, null, limitType) : QuestionParser.parseQTIPackage(uploadedFileStream, limitType); Index: lams_central/web/authoring/template/comms.jsp =================================================================== diff -u -r9f75aff30e9b0b3941d5c719a840b17ad8a7364a -radd24141d43ff78942c251760e1614925db89464 --- lams_central/web/authoring/template/comms.jsp (.../comms.jsp) (revision 9f75aff30e9b0b3941d5c719a840b17ad8a7364a) +++ lams_central/web/authoring/template/comms.jsp (.../comms.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -138,7 +138,7 @@ } // open import pop up window, centered horizontally var left = ((screen.width / 2) - (500 / 2)); - window.open(url,'QuestionFile','width=500,height=240,scrollbars=yes,top=150,left=' + left); + window.open(url,'QuestionFile','width=500,height=370,scrollbars=yes,top=150,left=' + left); } function createAssessment(questionType, numAssessmentsFieldname, containingDivName, qbQuestionUid, collapse) { Index: lams_central/web/qb/collection.jsp =================================================================== diff -u -rcf4300b8c69fbf72488c91ab3250246c07800701 -radd24141d43ff78942c251760e1614925db89464 --- lams_central/web/qb/collection.jsp (.../collection.jsp) (revision cf4300b8c69fbf72488c91ab3250246c07800701) +++ lams_central/web/qb/collection.jsp (.../collection.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -372,7 +372,7 @@ function importQTI(){ window.open('questions/questionFile.jsp', - 'QuestionFile','width=500,height=240,scrollbars=yes'); + 'QuestionFile','width=500,height=370,scrollbars=yes'); } function saveQTI(formHTML, formName) { Index: lams_central/web/questions/questionFile.jsp =================================================================== diff -u -r05c00f92856ef13cd90d6fce06acb069418c2512 -radd24141d43ff78942c251760e1614925db89464 --- lams_central/web/questions/questionFile.jsp (.../questionFile.jsp) (revision 05c00f92856ef13cd90d6fce06acb069418c2512) +++ lams_central/web/questions/questionFile.jsp (.../questionFile.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -2,49 +2,107 @@ <%@ 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.util.FileUtil" %> <%=Configuration.get(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE)%> -<%=FileValidatorUtil.formatSize(Configuration.getAsInt(ConfigurationKeys.UPLOAD_FILE_LARGE_MAX_SIZE))%> -<%=Configuration.get(ConfigurationKeys.EXE_EXTENSIONS)%> +<%=FileUtil.generateTmpFileUploadId()%> <fmt:message key="title.lams" /> :: <fmt:message key="label.questions.file.title" /> + - + + + + + + + + + + + + + + @@ -57,22 +115,24 @@ -
- - - - - - -
- - -
- - +
+ + + + + + +
+ +
+ + +
+
+
\ No newline at end of file Index: lams_tool_assessment/web/pages/authoring/basic.jsp =================================================================== diff -u -rf7837f2892736221011a0eb6cbef1027b6692224 -radd24141d43ff78942c251760e1614925db89464 --- lams_tool_assessment/web/pages/authoring/basic.jsp (.../basic.jsp) (revision f7837f2892736221011a0eb6cbef1027b6692224) +++ lams_tool_assessment/web/pages/authoring/basic.jsp (.../basic.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -143,7 +143,7 @@ function importQTI(){ window.open('questions/questionFile.jsp?collectionChoice=true', - 'QuestionFile','width=500,height=240,scrollbars=yes'); + 'QuestionFile','width=500,height=370,scrollbars=yes'); } // this method is called by QTI questionChoice.jsp Index: lams_tool_lamc/web/authoring/BasicContent.jsp =================================================================== diff -u -rbd5bbb74ec968f0048a3be657eae4ed7bdeef7d6 -radd24141d43ff78942c251760e1614925db89464 --- lams_tool_lamc/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision bd5bbb74ec968f0048a3be657eae4ed7bdeef7d6) +++ lams_tool_lamc/web/authoring/BasicContent.jsp (.../BasicContent.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -54,7 +54,7 @@ function importQTI(){ // open a pop up with filtered questions and a collection choice window.open('questions/questionFile.jsp?limitType=mc&collectionChoice=true', - 'QuestionFile','width=500,height=240,scrollbars=yes'); + 'QuestionFile','width=500,height=370,scrollbars=yes'); } // this method is called by QTI questionChoice.jsp Index: lams_tool_scratchie/web/pages/authoring/basic.jsp =================================================================== diff -u -rbd5bbb74ec968f0048a3be657eae4ed7bdeef7d6 -radd24141d43ff78942c251760e1614925db89464 --- lams_tool_scratchie/web/pages/authoring/basic.jsp (.../basic.jsp) (revision bd5bbb74ec968f0048a3be657eae4ed7bdeef7d6) +++ lams_tool_scratchie/web/pages/authoring/basic.jsp (.../basic.jsp) (revision add24141d43ff78942c251760e1614925db89464) @@ -84,7 +84,7 @@ function importQTI(){ window.open('questions/questionFile.jsp?limitType=mc&collectionChoice=true', - 'QuestionFile','width=500,height=240,scrollbars=yes'); + 'QuestionFile','width=500,height=370,scrollbars=yes'); } // this method is called by QTI questionChoice.jsp