Search in sources :

Example 1 with ProblemEntry

use of cn.edu.zju.acm.onlinejudge.util.ProblemEntry in project zoj by licheng.

the class ProblemImportAction method createProblems.

private static void createProblems(ProblemPackage pack, long cid) throws Exception {
    ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
    ProblemEntry[] problems = pack.getProblemEntries();
    for (int i = 0; i < problems.length; ++i) {
        // info
        problems[i].getProblem().setContestId(cid);
        problemPersistence.createProblem(problems[i].getProblem(), 0);
        long problemId = problems[i].getProblem().getId();
        ProblemImportAction.createReference(ReferenceType.DESCRIPTION, problems[i].getText(), problemId, 0, ProblemManager.PROBLEM_TEXT_FILE, null);
        ProblemImportAction.createReference(ReferenceType.INPUT, problems[i].getInput(), problemId, 0, ProblemManager.INPUT_FILE, null);
        ProblemImportAction.createReference(ReferenceType.OUTPUT, problems[i].getOutput(), problemId, 0, ProblemManager.OUTPUT_FILE, null);
        ProblemImportAction.createReference(ReferenceType.HEADER, problems[i].getChecker(), problemId, 0, ProblemManager.CHECKER_FILE, null);
        ProblemImportAction.createReference(ReferenceType.CHECKER_SOURCE, problems[i].getCheckerSource(), problemId, 0, ProblemManager.CHECKER_SOURCE_FILE, problems[i].getCheckerSourceType());
        ProblemImportAction.createReference(ReferenceType.JUDGE_SOLUTION, problems[i].getSolution(), problemId, 0, ProblemManager.JUDGE_SOLUTION_FILE, problems[i].getSolutionType());
    // images
    }
    Map<String, byte[]> images = pack.getImages();
    String imagesPath = ConfigManager.getImagePath();
    for (String string : images.keySet()) {
        String name = string;
        String path = imagesPath + "/" + name;
        byte[] image = images.get(name);
        FileOutputStream out = new FileOutputStream(path);
        try {
            CopyUtils.copy(new ByteArrayInputStream(image), out);
        } catch (Exception e) {
            out.close();
            throw e;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ProblemEntry(cn.edu.zju.acm.onlinejudge.util.ProblemEntry) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Aggregations

ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)1 ProblemEntry (cn.edu.zju.acm.onlinejudge.util.ProblemEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1