private Task getTastInfo(Map<String, String> fieldValues, ContestManager contestManager) { if (fieldValues.get("contestId") == null || fieldValues.get("taskId") == null) return null; Contest contest = contestManager.getContest(fieldValues.get("contestId")); if (contest == null) { return null; } return contest.getTaskById(fieldValues.get("taskId")); }
protected String parseZipEntry( ZipEntry zipEntry, ZipInputStream zipStream, Task task, String contestId, ContestManager contestManager) { String fileName = new File(zipEntry.getName()).getName().toLowerCase(); if (fileName.equals(task.getName() + ".txt")) { return null; } String[] fileNameParts = fileName.split("\\."); if (fileNameParts.length != 3) { return getErrorMessage(zipEntry, "is not named properly and will be ignored."); } if (!fileNameParts[0].equals(task.getName())) { return getErrorMessage( zipEntry, "seems like a test case but does not seem to start with the task name:" + task.getName()); } Task.TestType testType; if ("in".equals(fileNameParts[2])) { testType = Task.TestType.IN; } else if ("sol".equals(fileNameParts[2])) { testType = Task.TestType.SOL; } else { return getErrorMessage( zipEntry, " is neither .in nor .sol file but is ." + fileNameParts[2] + " ?"); } int testNumber = -1; try { testNumber = Integer.parseInt(fileNameParts[1]); if (testNumber < 1 || testNumber > task.getNumberOfTests()) { testNumber = -1; } } catch (NumberFormatException e) { } finally { if (testNumber < 0) { return getErrorMessage( zipEntry, " has incorrect value for a test number :" + fileNameParts[1] + " . Must be an integer between 1 and " + Integer.toString(task.getNumberOfTests())); } } if (contestManager.uploadTaskData(contestId, task, testNumber, testType, zipStream)) { return null; } else { return getErrorMessage( zipEntry, " was recognized as a test data file but the server was unable to store it."); } }
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userId = (String) request.getSession().getAttribute("id"); if (userId == null) { response.sendRedirect("index.jsp"); return; } PrintManager printManager = SessionUtil.getInstance().getPrintManager(); ContestManager contestManager = SessionUtil.getInstance().getContestManager(); Contest currContest = contestManager.getContest(request); // do not allow printing in open contests if (currContest.isOpenContest()) { response.sendRedirect("main?error=52"); return; } try { // request parsing HttpPostFileParser postFileParser = new HttpPostFileParser(); // convert from KBytes to bytes int maxFileSize = printManager.getMaxFileSize() * 1024; postFileParser.init(request, maxFileSize); if (postFileParser.nFile == 0) { response.sendRedirect("main?error=12"); return; } File fileSrcFile = postFileParser.upFile[0].GetTmpFile(); boolean bResult = printManager.print(fileSrcFile, userId); if (!bResult) { response.sendRedirect("main?error=52"); } else { response.sendRedirect("main?error=50"); } } catch (java.io.IOException ex) { response.sendRedirect("main?error=14"); } }
private void setUpDefaultMetaInfo(Task task, ContestManager contestManager, String contestId) { task.setTestGroups(new LinkedList<TestGroup>()); for (int i = 1; i <= task.getNumberOfTests(); ++i) { TestGroup group = new TestGroup(); group.setFeedbackEnabled(i * 5 <= task.getNumberOfTests()); group.setTestCases(Arrays.asList(i)); group.setPoints(new BigDecimal(100 / task.getNumberOfTests())); task.addTestGroup(group); } contestManager.updateTask(contestId, task); }
private boolean handleMetaInfo( ZipEntry zipEntry, Task task, ZipInputStream zipStream, List<String> errorMessages, ContestManager contestManager, String contestId) { String fileName = new File(zipEntry.getName()).getName().toLowerCase(); if (!fileName.equals(task.getName() + ".txt")) return false; List<TestGroup> testGroups = new LinkedList<TestGroup>(); BufferedReader reader = new BufferedReader(new InputStreamReader(zipStream)); String line = null; int lineNumber = 0; try { while ((line = reader.readLine()) != null) { String secondLine = reader.readLine(); lineNumber += 2; if (secondLine == null) { if ("".equals(line)) { break; } else { addMessageOnLine(errorMessages, lineNumber, "Line appears to be empty."); return false; } } TestGroup group = new TestGroup(); if (!parseOddLineOfMetaInfo(errorMessages, line, lineNumber, group) || !parseEvenLineOfMetaInfo(secondLine, task, errorMessages, lineNumber, group)) { return false; } testGroups.add(group); } } catch (IOException e) { addMessageOnLine(errorMessages, lineNumber, "Cannot read the file after this line."); return false; } task.setTestGroups(testGroups); contestManager.updateTask(contestId, task); return true; }