Пример #1
0
  public String submitAnswer(
      String username, String assignmentName, ArrayList<String> codeStrings, int cyclomaticNumber) {

    String ret = "";
    String answerName = assignmentName + "_" + username;

    Student stu = studentRepository.findByUsername(username);
    Assignment assign = assignmentRepository.findByName(assignmentName);
    Answer ans = null;

    EndResult<Answer> anss = answerRepository.findAll();
    for (Answer an : anss) {
      if (answerName.equals(an.getName())) {
        ans = an;
        break;
      }
    }

    if (stu == null) {
      ret = "Student doesn't exist!";
      return ret;
    }

    if (assign == null) {
      ret = "Assignment doesn't exist!";
      return ret;
    }

    if (ans == null) {

      ans = new Answer(answerName, stu, assign);
      ans.setCodeStrings(codeStrings);
      ans.setCyclomaticNumber(cyclomaticNumber);

      stu.addAnswer(ans);
      assign.addAnswer(ans);

      answerRepository.save(ans);
      studentRepository.save(stu);
      assignmentRepository.save(assign);

    } else {
      ret = "Resubmission is not allowed.";
    }

    return ret;
  }
Пример #2
0
  public String loadTestData() {
    String ret = "";

    Student stu = new Student();
    stu.setFirstName("Amy");
    stu.setLastName("Johnson");
    stu.setPassword("111");
    stu.setUsername("0002");
    studentRepository.save(stu);
    ret += getStudentInfo("0002");

    stu = new Student();
    stu.setFirstName("John");
    stu.setLastName("Don");
    stu.setPassword("111");
    stu.setUsername("0003");
    studentRepository.save(stu);
    ret += getStudentInfo("0003");

    stu = new Student();
    stu.setFirstName("Richard");
    stu.setLastName("Lee");
    stu.setPassword("111");
    stu.setUsername("0004");
    studentRepository.save(stu);
    ret += getStudentInfo("0004");

    stu = new Student();
    stu.setFirstName("Mary");
    stu.setLastName("Kate");
    stu.setPassword("111");
    stu.setUsername("0005");
    studentRepository.save(stu);
    ret += getStudentInfo("0005");

    stu = new Student();
    stu.setFirstName("Sam");
    stu.setLastName("Washington");
    stu.setPassword("111");
    stu.setUsername("0006");
    studentRepository.save(stu);
    ret += getStudentInfo("0006");

    stu = new Student();
    stu.setFirstName("Linda");
    stu.setLastName("Wong");
    stu.setPassword("111");
    stu.setUsername("0007");
    studentRepository.save(stu);
    ret += getStudentInfo("0007");

    stu = new Student();
    stu.setFirstName("Shawn");
    stu.setLastName("Tran");
    stu.setPassword("111");
    stu.setUsername("0008");
    studentRepository.save(stu);
    ret += getStudentInfo("0008");

    stu = new Student();
    stu.setFirstName("Alex");
    stu.setLastName("Patel");
    stu.setPassword("111");
    stu.setUsername("0009");
    studentRepository.save(stu);
    ret += getStudentInfo("0009");

    System.out.println(ret);
    return ret;
  }