private UUID createChallengeTemplate( CodingContestGameDto dto, UUID organizationId, Map<String, ByteArrayOutputStream> files) throws IOException { ChallengeTemplate challengeTemplate = challengeTemplateRepository.findOneByCanonicalName(dto.getCanonicalName()); if (challengeTemplate != null) { return challengeTemplate.getId(); } Organization organization = organizationRepository.findOne(organizationId); if (organization == null) { throw new CodunoIllegalArgumentException("organization.invalid"); } if (dto.getPuzzles() .stream() .findAny() .filter(puzzleDto -> puzzleDto.getValidationClass() != null) .isPresent()) { throw new CodunoIllegalArgumentException("ccc.game.structure.unsuported"); } Runner runner = getRunner("/io"); Endpoint taskEndpoint = getEndpoint("CCC general task", "ccc-io-task"); Set<Language> languages = new HashSet<>(languageRepository.findAll()); Duration gameDuration = parseGameDuration(dto.getTimeframe()); challengeTemplate = mapChallengeTemplate(dto, organization, gameDuration); for (PuzzleDto puzzle : dto.getPuzzles()) { Task task = mapTask( puzzle, challengeTemplate, organization, files, gameDuration, runner, taskEndpoint, languages); Map<String, ByteArrayOutputStream> testFiles = null; if (puzzle.getInputFilePath() != null) { testFiles = unzip(files.get(puzzle.getInputFilePath()).toByteArray()); } for (PuzzleTestDto puzzleTest : puzzle.getTests()) { Test test = mapTest(puzzleTest, runner, testFiles); task.addTest(test); } task = taskRepository.save(task); challengeTemplate.addTask(task); } return challengeTemplateRepository.save(challengeTemplate).getId(); }
private ChallengeTemplate mapChallengeTemplate( CodingContestGameDto dto, Organization organization, Duration gameDuration) { Endpoint challengeEndpoint = getEndpoint("CCC challenge", "ccc-challenge"); ChallengeTemplate challengeTemplate = new ChallengeTemplate(); challengeTemplate.setCanonicalName(fixCanonicalName(dto.getCanonicalName())); challengeTemplate.setName(dto.getName()); challengeTemplate.setDescription(dto.getDescription()); challengeTemplate.setEndpoint(challengeEndpoint); challengeTemplate.setOrganization(organization); challengeTemplate.setDuration(gameDuration); challengeTemplate.setInstructions( "You will be presented with a game composed of multiple levels. " + "Each level has a description that you can download by pressing the button in the bottom right corner of the screen. " + "The input for each level will be read from stdin. Good luck and have fun!"); return challengeTemplate; }