示例#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("*");
  }
示例#2
0
 private static void createNewResearch() {
   Research r = new Research();
   r.setCreationDate(new Date());
   System.out.print("nazwa tabeli >");
   r.setName(sc.next());
   ArrayList<Question> qs = new ArrayList<Question>();
   while (true) {
     System.out.print("dodac? > ");
     boolean b = sc.nextBoolean();
     if (!b) {
       break;
     }
     Question question = new Question();
     System.out.print("tresc pytania >");
     question.setQuestion(sc.next());
     System.out.print("typ 1.boolean, 2.string, 3.date, 4.integer>");
     switch (sc.nextInt()) {
       case 1:
         question.setQuestionType(QuestionType.BOOLEAN);
         break;
       case 2:
         question.setQuestionType(QuestionType.STRING);
         break;
       case 3:
         question.setQuestionType(QuestionType.DATE);
         break;
       case 4:
         question.setQuestionType(QuestionType.INTEGER);
         break;
       default:
         break;
     }
     qs.add(question);
   }
   r.setQuestions(qs);
   service.persist(r);
 }