Package kr.or.ioi2002.RMIServer

Examples of kr.or.ioi2002.RMIServer.UserFileManager


        Vector<UserAccount> userAccounts = mediator.getAllUsers();
        for (Contest contest : allContests) {
            Map<String, User> userMap = new HashMap<String, User>();
            for (UserAccount account : userAccounts) {
                if (account.getContestIds().contains(contest.getId())) {
                    userMap.put(account.getLogin(), new User(contest.getId(), account.getLogin(),
                            workingDirectory));
                }
            }
            activeUsers.put(contest.getId(), userMap);
        }
View Full Code Here


    public void registerUserForContest(String contestId, String username) {
        Map<String, User> contestants = activeUsers.get(contestId);
        if (contestants == null)
            return;

        contestants.put(username, new User(contestId, username, workingDirectory));
    }
View Full Code Here

        if (contest == null) {
            response.sendRedirect("");
            return;
        }

        User user = contestManager.getUser(contest.getId(), userLogin);
       
        if (!contest.isTestingOn()) {
            user.getTestState().setOutputNow("Test failed: Testing now allowed");
            response.sendRedirect("main");
            return;
        }

        try {
            HttpPostFileParser postFileParser = new HttpPostFileParser();
            // convert from KBytes to bytes
            int maxUploadSize = contest.getMaxUploadSize() * 1024;
            postFileParser.init(request, maxUploadSize);

            if (postFileParser.nFile <= 1) {
                user.getTestState().setOutputNow("Test failed: Select two files");
                response.sendRedirect("main");
                return;
            }
            String srcFile = null;
            byte[] abSrcFile = null;

            srcFile = postFileParser.upFile[0].pc_file_name;
            if (srcFile != null)
                srcFile = FilenameUtils.getName(srcFile);

            String task = contestManager.getTaskFromFilename(contest, srcFile, postFileParser
                    .getParameter("task"));
            String language = contestManager.getLanguageFromFilename(contest,
                    srcFile,
                    postFileParser.getParameter("language"));

            if (task == null) {
                user
                        .getTestState()
                        .setOutputNow("Invalid task name!\nThe task you are trying to submit is not part of the contest you are registered in.");
                response.sendRedirect("main");
                return;
            }
            if (contest.getTaskByName(task).getType() == Task.PROBLEM_TYPE_OUTPUT) {
                user.getTestState().setOutputNow("Output only tasks can not be tested.");
                response.sendRedirect("main");
                return;
            }
            if (language == null) {
                user.getTestState().setOutputNow("Invalid language!");
                response.sendRedirect("main");
                return;
            }

            File fileSrcFile = postFileParser.upFile[0].GetTmpFile();
            abSrcFile = new byte[postFileParser.upFile[0].size];
            BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(
                    fileSrcFile));
            int index = 0;
            int iRead = -1;
            while ((iRead = bufferedInputStream.read(abSrcFile,
                    index,
                    postFileParser.upFile[0].size - index)) > 0) {
                index += iRead;
            }
            bufferedInputStream.close();

            // for debug only
            postFileParser.upFile[0].save("./ioidebugtest", userLogin
                    + "_"
                    + String.valueOf(postFileParser.upFile[0].hashCode()));

            String stdinFile = null;
            byte[] stdinFileData = null;
            stdinFile = postFileParser.upFile[1].pc_file_name;
            File fileStdinFile = postFileParser.upFile[1].GetTmpFile();
            FileInputStream testStream = new FileInputStream(fileStdinFile);

            if (stdinFile.endsWith(".zip")) {
                ZipInputStream zipStream = new ZipInputStream(testStream);
                ZipEntry zipEntry = null;
                try {
                    if ((zipEntry = zipStream.getNextEntry()) == null || zipEntry.isDirectory())
                        throw new java.io.IOException();

                    if (zipEntry.getSize() > 5 * contest.getMaxUploadSize() * 1024) {
                        user.getTestState().setOutputNow("Test failed: stdin file too big");
                        response.sendRedirect("main");
                        return;
                    }

                    stdinFileData = new byte[(int) zipEntry.getSize()];
                    bufferedInputStream = new BufferedInputStream(zipStream);

                    index = 0;
                    iRead = -1;
                    // TODO: isn't there an easier/cleaner way to do this?
                    while ((iRead = bufferedInputStream.read(stdinFileData, index, (int) zipEntry
                            .getSize()
                            - index)) > 0) {
                        index += iRead;
                    }

                    if (zipStream.getNextEntry() != null)
                        throw new java.io.IOException();

                    bufferedInputStream.close();
                } catch (java.io.IOException e) {
                    user
                            .getTestState()
                            .setOutputNow("Test failed: Bad zip archive - please include only single file");
                    response.sendRedirect("main");
                    return;
                }
            } else {
                int uncompressedSize = postFileParser.upFile[1].size;
                if (stdinFile.endsWith(".gz") || stdinFile.endsWith(".gzip")) {
                    File uncompressedStdinFile = new File(postFileParser.upFile[1].GetTmpFile()
                            .getAbsolutePath()
                            + "_ungzipped");
                    uncompressedSize = 0;
                    try {
                        InputStream inputStream = new GZIPInputStream(testStream);
                        OutputStream outputStream = new FileOutputStream(uncompressedStdinFile);
                        byte[] readBuffer = new byte[1024];
                        int read = -1;
                        while ((read = inputStream.read(readBuffer)) > 0) {
                            outputStream.write(readBuffer, 0, read);
                            uncompressedSize += read;
                        }
                        outputStream.close();
                        inputStream.close();
                        testStream = new FileInputStream(uncompressedStdinFile);
                    } catch (IOException e) {
                        user
                                .getTestState()
                                .setOutputNow("Test failed: Bad gzip archive - please include only single file");
                        response.sendRedirect("main");
                        return;
                    }
                }
           

                stdinFileData = new byte[uncompressedSize];
                bufferedInputStream = new BufferedInputStream(testStream);

                index = 0;
                iRead = -1;
                while ((iRead = bufferedInputStream.read(stdinFileData,
                        index,
                        uncompressedSize - index)) > 0) {
                    index += iRead;
                }
                bufferedInputStream.close();
            }

            boolean bResult = contestManager.test(contest,
                    userLogin,
                    task,
                    language,
                    srcFile,
                    abSrcFile,
                    stdinFile,
                    stdinFileData);

            if (!bResult) {
                user.getTestState()
                        .setOutputNow("Test failed: Not allowed / Already processing");
                response.sendRedirect("main");
                return;
            } else {
                response.sendRedirect("main");
            }
        } catch (java.io.IOException ex) {
            user.getTestState()
                    .setOutputNow("Test failed: File upload failed (possibly file(s) too big)");
            response.sendRedirect("main");
            return;
        }
    }
View Full Code Here

           
            Task task = contest.getTaskByName(taskName);

            // TODO: export these as error messages or sth
            if (task == null || taskName == null) {
              User user = contestManager.getUser(contest.getId(), userId);
              user.setStrLastTaskSubmit("Invalid task name!\nThe task you are trying to submit is not part of the contest you are registered in.");
              user.setOutputSubmit(null);
              response.sendRedirect("main");
              return;
            }
            if (postFileParser.upFile[0].size > contest.getTaskByName(taskName).getMaxSubmitSize()) {
                response.sendRedirect("main?error=14");
                return;
            }
            if (contest.getTaskByName(taskName).getType() == Task.PROBLEM_TYPE_OUTPUT) {
                String index = null;
                int indexNumber = 0;
                if (srcFile != null && srcFile.split("\\.").length >= 2)
                    index = srcFile.split("\\.")[1];
                    if ("txt".equals(index)) {
                        indexNumber = 1;
                    } else {
                        try {
                            indexNumber = Integer.parseInt(index);
                            if (indexNumber <= 0 ||
                                indexNumber > contest.getTaskByName(taskName).getNumberOfTests()) {
                                index = null;
                            }
                        } catch (NumberFormatException e) {
                            index = null;
                        }
                    }
                 if (index == null) {
                     User user = contestManager.getUser(contest.getId(), userId);
                     user.setStrLastTaskSubmit("Invalid file name!\nFormat is [taskname].[case_number].txt (e.g. output.10.txt).");
                     user.setOutputSubmit(null);
                     response.sendRedirect("main");
                     return;
                 }
                 // TODO: remove HACK
                 language = String.format("%0" + Task.TESTCASE_PADDING_LENGTH + "d", indexNumber);
            }
            if (language == null) {
              User user = contestManager.getUser(contest.getId(), userId);
              user.setStrLastTaskSubmit("Invalid language!");
              user.setOutputSubmit(null);
              response.sendRedirect("main");
              return;
            }
           
            java.io.File fileSrcFile = postFileParser.upFile[0].GetTmpFile();
View Full Code Here

            String task = contestManager.getTaskFromFilename(contest, srcFile, postFileParser.getParameter("task"));
            String language = contestManager.getLanguageFromFilename(contest, srcFile, postFileParser.getParameter("language"));
           
            // TODO: export these as error messages or sth
            if (task == null) {
              User user = contestManager.getUser(contest.getId(), userLogin);
              user.setStrLastTaskTest("Invalid task name!\nThe task you are trying to submit is not part of the contest you are registered in.");
              user.setOutputTest(null);
              response.sendRedirect("main");
              return;
            }
            if (contest.getTaskByName(task).getType() == Task.PROBLEM_TYPE_OUTPUT) {
                User user = contestManager.getUser(contest.getId(), userLogin);
                user.setStrLastTaskTest("Output only tasks can not be tested.");
                user.setOutputTest(null);
                response.sendRedirect("main");
                return;
            }
            if (language == null) {
              User user = contestManager.getUser(contest.getId(), userLogin);
              user.setStrLastTaskTest("Invalid language!");
              user.setOutputTest(null);
              response.sendRedirect("main");
              return;
            }
           
            File fileSrcFile = postFileParser.upFile[0].GetTmpFile();
View Full Code Here

        return contest.hasTaskNamed(taskName);
    }

    public boolean submitSourceCode(String contestId, String userid, String task, TempFile tmpsrc,
            String language, String srcFilename, byte[] output) throws IOException {
        User user = contestManager.getUser(contestId, userid);
        if (user == null)
            return false;

        return user.submitSourceCode(task, tmpsrc, language, srcFilename, output);
    }
View Full Code Here

        return user.submitSourceCode(task, tmpsrc, language, srcFilename, output);
    }

    public boolean submitAttemptFailed(String contestId, String userid, String task, byte[] output) {
        User user = contestManager.getUser(contestId, userid);
        if (user == null)
            return false;

        return user.submitAttemptFailed(task, output);
    }
View Full Code Here

        return user.submitAttemptFailed(task, output);
    }

    public boolean testFinish(String contestId, String userid, String task, byte[] output) {
        User user = contestManager.getUser(contestId, userid);
        if (user == null)
            return false;

        return user.testFinish(task, output);
    }
View Full Code Here

    private User getUser(Contest contest, String userLogin) {
        return getUser(contest.getId(), userLogin);
    }

    public Hashtable<String, String> queryStatus(Contest contest, String userLogin) {
        User user = getUser(contest, userLogin);
        if (user == null)
            return null;

        Hashtable<String, String> hash = user.getStatus();

        hash.put("submitProgress", String.valueOf(user.getSubmitProgress()));
        hash.put("testProgress", String.valueOf(user.getTestProgress()));

        return hash;
    }
View Full Code Here

        return contestants.get(userLogin);
    }
   
    public boolean test(Contest contest, String userId, String task,
            String language, String sourceFileName, byte[] sourceFileData, String stdinFileName, byte[] stdinFileData) {
        User user = getUser(contest, userId);
        if (user == null)
            return false;

        TempFile tmp = null;
        TempFile tmp2 = null;
        try {
            tmp = TempFile.createFromByteArray(sourceFileData);
            if (stdinFileName != null && stdinFileData != null) {
                tmp2 = TempFile.createFromByteArray(stdinFileData);
            }
        } catch (java.io.IOException e) {
            Syslog.log("IOIGraderImpl: submit: " + e.toString());
            return false;
        }

        if (contest == null || !contest.isRunning() || !contest.isTestingOn())
            return false;

        if (!user.testStart())
            return false;

        mediator.test(contest.getId(), userId, task, language, tmp, tmp2, user);
        LogTest.log(userId + ",START");
        return true;
View Full Code Here

TOP

Related Classes of kr.or.ioi2002.RMIServer.UserFileManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.