Ejemplo n.º 1
0
 /**
  * Gets the task repository.
  *
  * @param name the name
  * @return the task repository
  */
 public TaskRepository getTaskRepository(String name) {
   for (TaskRepository repository : getTaskRepositories()) {
     if (repository.getName().equals(name)) {
       return repository;
     }
   }
   throw new EclipseLayerException("There is no repository with name " + name);
 }
Ejemplo n.º 2
0
  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();
  }
 @JsonApiFindOne
 public Project findOne(Long projectId, QueryParams requestParams) {
   if (projectId == null) {
     return null;
   }
   Project project = REPOSITORY.get(projectId);
   if (project == null) {
     throw new ResourceNotFoundException("Project not found!");
   }
   if (project.getTasks().isEmpty()) {
     Iterable<Task> tasks = taskRepository.findAll(null);
     tasks.forEach(
         task -> {
           if (task.getProjectId().equals(project.getId())) {
             project.getTasks().add(task);
           }
         });
     save(project);
   }
   return project;
 }