Package bg.smoc.model.manager

Examples of bg.smoc.model.manager.ContestManager


    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        ServletFileUpload servletFileUpload = setUpServletFileUpload();
        ContestManager contestManager = SessionUtil.getInstance().getContestManager();

        List<FileItem> fileItemsList = null;
        try {
            fileItemsList = servletFileUpload.parseRequest(request);
        } catch (FileUploadException e) {
View Full Code Here


        // http://localhost:8080/judge/downloadTest?contestId=Contest_0&taskId=Contest_0_0&testNum=1&type=SOL
        String contestId = request.getParameter("contestId");
        String taskId = request.getParameter("taskId");
        String testNum = request.getParameter("testNum");
        String testType = request.getParameter("type");
        ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Task task = contestManager.getTask(contestId, taskId);
        if (task == null || testType == null || testNum == null) {
            response.sendRedirect("");
            return;
        }
        int testNumber = -1;
        try {
            testNumber = Integer.parseInt(testNum);
        } catch (NumberFormatException e) {
            response.sendRedirect("");
            return;
        }
        Task.TestType type;
        try {
            type = Task.TestType.valueOf(testType);
        } catch (IllegalArgumentException e) {
            response.sendRedirect("");
            return;
        }
        FileInfo fileInfo = contestManager.getTestDataFile(contestId,
                task.getName(),
                testNumber,
                type);
        if (fileInfo == null || fileInfo.getSize() > Integer.MAX_VALUE) {
            response.sendRedirect("");
View Full Code Here

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        SessionUtil sessionUtil = SessionUtil.getInstance();
        ContestManager contestManager = sessionUtil.getContestManager();
        Contest contest = contestManager.getContest(request.getParameter("contestId"));
        if (contest != null) {
            sessionUtil.getUserAccountManager().registerUserForContest(sessionUtil
                    .getLoginManager().getActiveUserLogin(request),
                    contest.getId());
        }
View Full Code Here

        String userLogin = sessionUtil.getLoginManager().getActiveUserLogin(request);

        byte[] fileAsBytes = getInputStream(request, userLogin);
        InputStream inputStream = new ByteArrayInputStream(fileAsBytes);
        if (inputStream == null) {
            ContestManager contestManager = sessionUtil.getContestManager();
            Contest contest = contestManager.getContest(request);
            if (contest == null) {
                response.sendRedirect("");
                return;
            }
            User user = contestManager.getUser(contest.getId(), userLogin);
            user.getGeneralState().setOutputNow("File not found");
            request.getSession().setAttribute("tab", "General");
            response.sendRedirect("main");
            return;
        }
View Full Code Here

        FileUtils.copyStreams(bufferInputStream, servletOutputStream);
        bufferInputStream.close();
    }

    public byte[] getInputStream(HttpServletRequest request, String userLogin) throws IOException {
        ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Contest contest = contestManager.getContest(request);

        String taskname = request.getParameter("taskname");
        if (taskname == null || contest == null)
            return null;

        byte[] bytearray = contestManager.getSourceCodeAsByteArray(contest, userLogin, taskname);
        if (bytearray == null)
            return null;

        return bytearray;
    }
View Full Code Here

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String userLogin = request.getParameter("login");
        ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Contest contest = contestManager.getContest(request.getParameter("contestId"));
        if (contest == null) {
            response.sendRedirect("");
            return;
        }
        String taskname = request.getParameter("taskId");
View Full Code Here

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String userLogin = (String) request.getSession().getAttribute("id");

        ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Contest contest = contestManager.getContest(request);
        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,
View Full Code Here

  @Override
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String contestId = request.getParameter("contestId");
    String taskId = request.getParameter("taskId");
    ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Task task = contestManager.getTask(contestId, taskId);

    request.setAttribute("contestId", contestId);
    request.setAttribute("task", task);
    request.setAttribute("taskTypes", TaskType.getAllTaskTypes());
    if (task.getName() != null)
        request.setAttribute("taskTests", contestManager.getTaskTests(contestId, task));
    else
        request.setAttribute("taskTests", null);
    request.setAttribute("testGroups", task.getTestGroups());

    request.getRequestDispatcher("editTask.jsp").forward(request, response);
View Full Code Here

    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String contestId = request.getParameter("contestId");
        String taskId = request.getParameter("id");

        ContestManager contestManager = SessionUtil.getInstance().getContestManager();
        Task task = contestManager.getTask(contestId, taskId);

        if (task != null) {
            task.setName(request.getParameter("name"));
            try {
                task.setType(new Integer(request.getParameter("type")));
                task.setNumberOfTests(Integer.parseInt(request.getParameter("numberOfTests")));
                task.setMaxSubmitSize(Integer.parseInt(request.getParameter("maxSubmitSize")));
                task.setTimeLimit(Integer.parseInt(request.getParameter("timeLimit")));
                task.setMemoryLimit(Integer.parseInt(request.getParameter("memoryLimit")));
                task.setOutputLimit(Integer.parseInt(request.getParameter("outputLimit")));
            } catch (NumberFormatException e) {
            }
            contestManager.updateTask(contestId, task);
        }

        response.sendRedirect("updateTaskList?contestId=" + contestId);
    }
View Full Code Here

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        SessionUtil sessionUtil = SessionUtil.getInstance();
        String userLogin = sessionUtil.getLoginManager().getActiveUserLogin(request);
        ContestManager contestManager = sessionUtil.getContestManager();
        Contest contest = contestManager.getContest(request);

        request.setAttribute("userLogin", userLogin);
        request.setAttribute("contest", contest);
        request.setAttribute("time", new SimpleDateFormat("yyyy.MM.dd HH:mm:ss")
                .format(new java.util.Date()));

        Hashtable<String, String> hash = contestManager.queryStatus(contest, userLogin);
        generateTable(request, hash, contest.getTasks());
        request.setAttribute("announcement", generateAnnouncement(contest.getAnnouncement()));

        String errorMessage = getErrorMessage(request.getParameter("error"), contest.isRunning());
        request.setAttribute("errorMessage", errorMessage);
View Full Code Here

TOP

Related Classes of bg.smoc.model.manager.ContestManager

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.