Esempio n. 1
0
  private static void search() {
    Research[] allResearches = service.findAllResearches();
    for (int i = 0; i < allResearches.length; i++) {
      System.out.println(i + ": " + allResearches[i].getName());
    }
    Research mResearch = allResearches[sc.nextInt()];

    Question[] questions = service.findAllQuestionsByResearch(mResearch);
    for (int i = 0; i < questions.length; i++) {
      System.out.println(i + ": " + questions[i].getQuestion());
    }

    ArrayList<Restricion> restricions = new ArrayList<Restricion>();
    while (true) {
      System.out.print("dodac? > ");
      boolean b = sc.nextBoolean();
      if (!b) {
        break;
      }
      Restricion restricion = new Restricion();
      System.out.println("nr pytania >");
      restricion.setQuestion(questions[sc.nextInt()]);
      System.out.println("restrykcja >");
      restricion.setRest(sc.next());
      System.out.println("1.equal, 2.greater, 3. less, 4.like");
      switch (sc.nextInt()) {
        case 1:
          restricion.setRestrictionType(RestrictionType.EQUAL);
          break;

        case 2:
          restricion.setRestrictionType(RestrictionType.GREATER);
          break;

        case 3:
          restricion.setRestrictionType(RestrictionType.LESS);
          break;

        case 4:
          restricion.setRestrictionType(RestrictionType.LIKE);
          break;

        default:
          break;
      }
      restricions.add(restricion);
    }

    AnswerList[] search = service.search(mResearch.getId(), restricions);
    for (AnswerList answerList : search) {
      System.out.println(answerList.getAnswers());
      for (Answer answer : answerList.getAnswers()) {
        System.out.println(answer.getQuestion() + ": " + answer.getAnswer());
      }
    }
    System.out.println("*");
  }
Esempio n. 2
0
 private static void answer() {
   Research[] allResearches = service.findAllResearches();
   for (int i = 0; i < allResearches.length; i++) {
     System.out.println(i + ": " + allResearches[i].getName());
   }
   Research mResearch = allResearches[sc.nextInt()];
   Question[] questions = service.findAllQuestionsByResearch(mResearch);
   AnswerList al = new AnswerList();
   al.setResearch(mResearch);
   List<Answer> ans = new ArrayList<Answer>();
   for (Question question : questions) {
     System.out.print(question.getQuestion() + " > ");
     Answer answer = new Answer();
     answer.setQuestion(question);
     answer.setAnswer(sc.next());
     ans.add(answer);
   }
   al.setAnswers(ans);
   service.persist(al);
 }