Search in sources :

Example 1 with Reference

use of cn.edu.zju.acm.onlinejudge.bean.Reference in project zoj by licheng.

the class AddProblemAction method createReference.

private void createReference(ReferenceType type, FormFile formFile, long problemId, long user) throws Exception {
    if (formFile == null) {
        return;
    }
    ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
    byte[] data = formFile.getFileData();
    if (data.length == 0) {
        return;
    }
    Reference ref = new Reference();
    ref.setContent(data);
    ref.setReferenceType(type);
    ref.setSize(data.length);
    referencePersistence.createProblemReference(problemId, ref, user);
}
Also used : ReferencePersistence(cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Example 2 with Reference

use of cn.edu.zju.acm.onlinejudge.bean.Reference in project zoj by licheng.

the class JudgeClientJudgeThread method zipProblemData.

private void zipProblemData(File outputFile, Problem problem) throws PersistenceException, JudgeServerErrorException, ProblemDataErrorException {
    try {
        ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outputFile));
        try {
            List<Reference> inputFiles = this.referenceDAO.getProblemReferences(problem.getId(), ReferenceType.INPUT);
            List<Reference> outputFiles = this.referenceDAO.getProblemReferences(problem.getId(), ReferenceType.OUTPUT);
            if (inputFiles.size() != outputFiles.size() && inputFiles.size() > 0 && outputFiles.size() > 0) {
                throw new ProblemDataErrorException("Unequal number of inputs and outputs for problem " + problem.getId());
            }
            for (Reference input : inputFiles) {
                if (input.getContent() == null) {
                    throw new ProblemDataErrorException("Can not find content for input with reference id " + input.getId());
                }
            }
            for (Reference output : outputFiles) {
                if (output.getContent() == null) {
                    throw new ProblemDataErrorException("Can not find content for output with reference id " + output.getId());
                }
            }
            Reference specialJudge = null;
            if (problem.isChecker()) {
                List<Reference> specialJudges = this.referenceDAO.getProblemReferences(problem.getId(), ReferenceType.CHECKER_SOURCE);
                if (specialJudges.size() == 0) {
                    throw new ProblemDataErrorException("Can not find special judge for problem " + problem.getId());
                }
                if (specialJudges.size() > 1) {
                    throw new ProblemDataErrorException("Find more than one special judge for problem " + problem.getId());
                }
                specialJudge = specialJudges.get(0);
                String contentType = specialJudge.getContentType();
                if (contentType == null) {
                    throw new ProblemDataErrorException("Can not find source content type for special judge with reference id " + specialJudge.getId());
                }
                byte[] content = specialJudge.getContent();
                if (content == null) {
                    throw new ProblemDataErrorException("Can not find source content for special judge with reference id " + specialJudge.getId());
                }
                if (content.length == 0) {
                    throw new ProblemDataErrorException("Empty source for special judge with reference id " + specialJudge.getId());
                }
            }
            for (int i = 0; i < inputFiles.size(); i++) {
                zipOut.putNextEntry(new ZipEntry(String.format("%d.in", i + 1)));
                CopyUtils.copy(inputFiles.get(i).getContent(), zipOut);
            }
            for (int i = 0; i < outputFiles.size(); i++) {
                zipOut.putNextEntry(new ZipEntry(String.format("%d.out", i + 1)));
                CopyUtils.copy(outputFiles.get(i).getContent(), zipOut);
            }
            if (specialJudge != null) {
                zipOut.putNextEntry(new ZipEntry(String.format("judge.%s", specialJudge.getContentType())));
                CopyUtils.copy(specialJudge.getContent(), zipOut);
            }
        } finally {
            zipOut.close();
        }
    } catch (IOException e) {
        throw new JudgeServerErrorException("Fail to zip problem data", e);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 3 with Reference

use of cn.edu.zju.acm.onlinejudge.bean.Reference in project zoj by licheng.

the class EditProblemAction method setReference.

private void setReference(String typeKey, ReferenceType type, long problemId, ContextAdapter context) throws Exception {
    ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
    List<Reference> references = referencePersistence.getProblemReferenceInfo(problemId, type);
    if (references.size() > 0) {
        context.setAttribute(typeKey, references.get(0));
    }
}
Also used : ReferencePersistence(cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Example 4 with Reference

use of cn.edu.zju.acm.onlinejudge.bean.Reference in project zoj by licheng.

the class EditProblemAction method updateReference.

private void updateReference(ReferenceType type, FormFile formFile, long problemId, long user) throws Exception {
    if (formFile == null || formFile.getFileName() == null || formFile.getFileName().trim().length() == 0) {
        return;
    }
    String name = formFile.getFileName();
    String contentType = null;
    int p = name.lastIndexOf('.');
    if (p != -1) {
        contentType = name.substring(p + 1);
    }
    byte[] data = formFile.getFileData();
    ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
    List<Reference> references = referencePersistence.getProblemReferenceInfo(problemId, type);
    if (references.size() == 0) {
        Reference ref = new Reference();
        ref.setContent(data);
        ref.setContentType(contentType);
        ref.setReferenceType(type);
        ref.setSize(data.length);
        referencePersistence.createProblemReference(problemId, ref, user);
    } else {
        Reference ref = references.get(0);
        ref.setContent(data);
        ref.setContentType(contentType);
        ref.setSize(data.length);
        referencePersistence.updateReference(ref, user);
    }
}
Also used : ReferencePersistence(cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Example 5 with Reference

use of cn.edu.zju.acm.onlinejudge.bean.Reference in project zoj by licheng.

the class ProblemImportAction method createReference.

private static void createReference(ReferenceType type, byte[] data, long problemId, long user, String fileName, String fileType) throws Exception {
    if (data == null) {
        return;
    }
    ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
    if (fileType != null && fileType.trim().length() > 0) {
        fileName = fileName + "." + fileType;
    }
    Reference ref = new Reference();
    ref.setName(fileName);
    ref.setContentType(fileType);
    ref.setContent(data);
    ref.setReferenceType(type);
    ref.setSize(data.length);
    referencePersistence.createProblemReference(problemId, ref, user);
}
Also used : ReferencePersistence(cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence) Reference(cn.edu.zju.acm.onlinejudge.bean.Reference)

Aggregations

Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)20 ReferencePersistence (cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)5 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)3 ArrayList (java.util.ArrayList)3 BeforeClass (org.junit.BeforeClass)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)2 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)2 SubmissionPersistence (cn.edu.zju.acm.onlinejudge.persistence.SubmissionPersistence)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 List (java.util.List)2 ZipEntry (java.util.zip.ZipEntry)2 ActionForward (org.apache.struts.action.ActionForward)2