Package com.vst.model

Examples of com.vst.model.Question


        Question question = dao.getQuestion(questionId);
        assertNotNull(question);
    }

    public void testGetQuestions() throws Exception {
        Question question = new Question();

        List results = dao.getQuestions(question);
        assertTrue(results.size() > 0);
    }
View Full Code Here


        List results = dao.getQuestions(question);
        assertTrue(results.size() > 0);
    }

    public void testSaveQuestion() throws Exception {
        Question question = dao.getQuestion(questionId);

        // update required fields

        dao.saveQuestion(question);
View Full Code Here

        questionManager = null;
    }

    public void testGetQuestions() throws Exception {
        List results = new ArrayList();
        Question question = new Question();
        results.add(question);

        // set expected behavior on dao
        questionDao.expects(once()).method("getQuestions")
            .will(returnValue(results));
View Full Code Here

    }

    public void testGetQuestion() throws Exception {
        // set expected behavior on dao
        questionDao.expects(once()).method("getQuestion")
            .will(returnValue(new Question()));
        Question question = questionManager.getQuestion(questionId);
        assertTrue(question != null);
        questionDao.verify();
    }
View Full Code Here

        assertTrue(question != null);
        questionDao.verify();
    }

    public void testSaveQuestion() throws Exception {
        Question question = new Question();

        // set expected behavior on dao
        questionDao.expects(once()).method("saveQuestion")
            .with(same(question)).isVoid();
View Full Code Here

        questionManager.saveQuestion(question);
        questionDao.verify();
    }

    public void testAddAndRemoveQuestion() throws Exception {
        Question question = new Question();

        // set required fields

        // set expected behavior on dao
        questionDao.expects(once()).method("saveQuestion")
            .with(same(question)).isVoid();
        questionManager.saveQuestion(question);
        questionDao.verify();

        // reset expectations
        questionDao.reset();

        questionDao.expects(once()).method("removeQuestion").with(eq(new Long(questionId)));
        questionManager.removeQuestion(questionId);
        questionDao.verify();

        // reset expectations
        questionDao.reset();
        // remove
        Exception ex = new ObjectRetrievalFailureException(Question.class, question.getQuestionId());
        questionDao.expects(once()).method("removeQuestion").isVoid();
        questionDao.expects(once()).method("getQuestion").will(throwException(ex));
        questionManager.removeQuestion(questionId);
        try {
            questionManager.getQuestion(questionId);
View Full Code Here

         return Question.class.isAssignableFrom(candidate);
     }

     public void validate(Object obj, Errors errors) {

         Question question=(Question)obj;

         //checking if all answer contents were filled
         List answerList=question.getAnswers();
         for (int i = 0; i < answerList.size(); i++) {
             Answer answer = (Answer) answerList.get(i);
             if(answer.getContents()==null || answer.getContents().trim().equals("")){
                 errors.rejectValue("answers["+i+"]", "question.noAnswerContents");
             }
         }

         //checking if all construction types were chosen
         if(!question.isForAllConstructions()){
         List constructionTypeList=question.getConstructionTypes();
         for (int i = 0; i < constructionTypeList.size(); i++) {
             ConstructionType constructionType = (ConstructionType) constructionTypeList.get(i);
             if(constructionType.getConstructionTypeId().equals(new Long(-1))){
                 errors.rejectValue("constructionTypes["+i+"]", "question.noConstructionType");
             }
         }
         }

         if(question.getQuestionType().getQuestionTypeId().equals(new Long(-1))){
             errors.rejectValue("questionType", "question.noQuestionType");

         }

         //checking if documentation type was chosen
         if(question.getQuestionType().getQuestionTypeId().equals(new Long(1)) && !question.isForObjectStructure() && question.getDocumentType().getDocumentTypeId().equals(new Long(-1))){
             errors.rejectValue("documentType", "question.noDocumentType");

         }

         }
View Full Code Here

         Hint hint=(Hint)obj;

         //checking if all answer contents were filled
         List questionList=hint.getQuestions();
         for (int i = 0; i < questionList.size(); i++) {
             Question question = (Question) questionList.get(i);
             if(question.getQuestionId().equals(new Long(-1))){
                 errors.rejectValue("questions["+i+"]", "hint.noQuestion");
             }
         }

         }
View Full Code Here

          " q.documentType" +
        " from Question as q left join q.documentType").list();
    Map<Integer, Question> qmap = new HashMap<Integer, Question>();
    for (Object o : qlist){
      Object[] cols = (Object[]) o;
      Question question = new Question();
      question.setQuestionId((Integer) cols[0]);
      question.setQuestionPriority((Integer) cols[1]);
      question.setContents((String) cols[2]);
      question.setForAllConstructions((Boolean) cols[3]);
      question.setForObjectStructure((Boolean) cols[4]);
      question.setNecessary((Boolean) cols[5]);
      question.setNoVariants((Boolean) cols[6]);
      question.setFewAnswers((Boolean) cols[7]);
      question.setQuestionType((QuestionType) cols[8]);
      if (cols[9] != null) {
        question.setDocumentType((DocumentType) cols[9]);
      } else {
        question.setDocumentType(new DocumentType());
      }
//      q.setAnswers(new ArrayList<Answer>());
      qmap.put(question.getQuestionId(), question);
    }

    Map<Integer, Answer> amap = new HashMap<Integer, Answer>();
    List<?> alist = getSession().createQuery(
        "select " +
        " answerId, "+
          " contents, "+
          " answerInterpritation, "+
          " letter," +
          " question.questionId" +
    " from Answer").list();

    for (Object o : alist){
      Object[] cols = (Object[]) o;
      Answer answer = new Answer();
      answer.setAnswerId((Integer) cols[0]);
      answer.setContents((String) cols[1]);
      answer.setAnswerInterpritation((String) cols[2]);
      answer.setLetter((String) cols[3]);
      Question question = qmap.get((Integer) cols[4]);
      if (question!=null) {
        question.getAnswers().add(answer);
        answer.setQuestion(question);
      }
      amap.put(answer.getAnswerId(), answer);
    }


    getSession().createQuery(
      "from DangerCategory").list();
    getSession().createQuery(
       "from ObjectType").list();
    getSession().createQuery(
       "from User u left join fetch u.roles").list();

    String boHQL =
      "select new BuildingObject(objectId," +
      " technicalTask,wayToTechnicalTask, " +
      "(select object(user) from User user " +
      "  where user.id=buildingObject.user.id), " +
      " name, " +
      " description, " +
      " country, " +
      " region, " +
      " city, " +
      " street, " +
      " house, " +
      " block, " +
      " organizationName, " +
      " organizationZip, " +
      " organizationCountry, " +
      " organizationRegion, " +
      " organizationCity, " +
      "organizationHouse,organizationStreet,organizationBlock,organizationFlat, " +
      "headerFamily,headerMiddleName,headerName,organozationPhone, " +
      "(select object(dangerCategory) from DangerCategory dangerCategory  " +
      " where dangerCategory.dangerCategoryId=buildingObject.dangerCategory.dangerCategoryId), " +
      " (select object(objectType) from ObjectType objectType where objectType.objectTypeId=buildingObject.objectType.objectTypeId))" +
      " from BuildingObject buildingObject";

    List<?> buildingObjectList = null;
    if  (buildingObjectId ==null) {
      buildingObjectList = getSession().createQuery(
          boHQL).list();
    } else {
      boHQL = boHQL + " where buildingObject.objectId=?";
      buildingObjectList = getSession().createQuery(
          boHQL).setString(0, buildingObjectId.toString()).list();
    }

    Map<Integer, BuildingObject> boMap = new HashMap<Integer, BuildingObject>();
    for(Object o : buildingObjectList){
      BuildingObject bo = (BuildingObject) o;
            List objectAnswers = getSession().createQuery("select new ObjectAnswer(objectAnswerId,objectConstructionId,answerContents,answerComment,buildingObjectId,question) from ObjectAnswer where objectId=?").setString(0, String.valueOf(bo.getObjectId())).list();

           for (int j = 0; j < objectAnswers.size(); j++) {
               ObjectAnswer objectAnswer = (ObjectAnswer) objectAnswers.get(j);
               objectAnswer.setAnswers(super.getSession().createQuery("from Answer where answerId in (select answers.answerId from ObjectAnswer objectAnswer inner join objectAnswer.answers as answers where objectAnswer.objectAnswerId=?)").setString(0, objectAnswer.getObjectAnswerId().toString()).list());

           }
           bo.setDocumentationQuestions(objectAnswers);
      //we have already lazy list
      //bo.setDocQuestions(new ArrayList<ObjectAnswer>());
      //bo.setObjectQuestions(new ArrayList<ObjectAnswer>());
      //bo.setDocumentationQuestions(new ArrayList<ObjectAnswer>());
      boMap.put(bo.getObjectId(), bo);
    }

    String oaHQL = "select objectAnswerId, " +
    " buildingObjectId, " +
    " answerContents, " +
    " answerComment, " +
    " question.questionId from ObjectAnswer";

    List<?> oqustion = null;
    if  (buildingObjectId ==null) {
      oqustion = getSession().createQuery(
          oaHQL).list();
    } else {
      oaHQL = oaHQL + " where buildingObjectId=?";
      oqustion = getSession().createQuery(
          oaHQL).setString(0, buildingObjectId.toString()).list();
    }

    Map<Integer, ObjectAnswer> oaMap = new HashMap<Integer, ObjectAnswer>();
    for (Object o : oqustion) {
      Object[] cols = (Object[]) o;
      ObjectAnswer oa = new ObjectAnswer();
      oa.setObjectAnswerId((Integer) cols[0]);
      oa.setBuildingObjectId((Integer) cols[1]);
      oa.setAnswerContents((String) cols[2]);
      oa.setAnswerComment((String) cols[3]);
//      oa.setAnswers(new ArrayList<Answer>());
      Question q = qmap.get((Integer) cols[4]);
      if (q != null) {
        oa.setQuestion(q);
        BuildingObject bo = boMap.get(oa.getBuildingObjectId());
        if (bo != null) {
          oa.setBuildingObject(bo);
          if (q.isForObjectStructure()) {
            bo.getObjectQuestions().add(oa);
          } else {
            bo.getDocQuestions().add(oa);
          }
          if (q.getQuestionType().getQuestionTypeId() == 1){
            bo.getDocumentationQuestions().add(oa);
          }
        }
      }
      oaMap.put(oa.getObjectAnswerId(), oa);
View Full Code Here

          " q.questionType" +
        " from Question as q").list();
    Map<Integer, Question> qmap = new HashMap<Integer, Question>();
    for (Object o : qlist){
      Object[] cols = (Object[]) o;
      Question q = new Question();
      q.setQuestionId((Integer) cols[0]);
      q.setQuestionPriority((Integer) cols[1]);
      q.setContents((String) cols[2]);
      q.setForAllConstructions((Boolean) cols[3]);
      q.setForObjectStructure((Boolean) cols[4]);
      q.setNecessary((Boolean) cols[5]);
      q.setNoVariants((Boolean) cols[6]);
      q.setFewAnswers((Boolean) cols[7]);
      q.setQuestionType((QuestionType) cols[8]);
//      q.setAnswers(new ArrayList<Answer>());
      qmap.put(q.getQuestionId(), q);
    }

    Map<Integer, Answer> amap = new HashMap<Integer, Answer>();
    List<?> alist = getSession().createQuery(
        "select " +
        " answerId, "+
          " contents, "+
          " answerInterpritation, "+
          " letter," +
          " question.questionId" +
    " from Answer").list();

    for (Object o : alist){
      Object[] cols = (Object[]) o;
      Answer answer = new Answer();
      answer.setAnswerId((Integer) cols[0]);
      answer.setContents((String) cols[1]);
      answer.setAnswerInterpritation((String) cols[2]);
      answer.setLetter((String) cols[3]);
      Question question = qmap.get((Integer) cols[4]);
      if (question!=null) {
        question.getAnswers().add(answer);
        answer.setQuestion(question);
      }
      amap.put(answer.getAnswerId(), answer);
    }

//    BuildingObject bo = new BuildingObject(objectId, "dummy");
    BuildingObject bo = (BuildingObject) getSession()
      .createCriteria(BuildingObject.class)
      .add(Restrictions.idEq(objectId))
      .setFetchMode("photoes", FetchMode.SELECT)
      .setFetchMode("constructionTypes", FetchMode.SELECT)
      .setFetchMode("documentationQuestions", FetchMode.SELECT)
      .setFetchMode("currentDocumentationQuestions", FetchMode.SELECT)
      .setFetchMode("constructionExamples", FetchMode.SELECT)
      .setFetchMode("objectQuestions", FetchMode.SELECT)
      .setFetchMode("docQuestions", FetchMode.SELECT)
      .setFetchMode("currentObjectQuestions", FetchMode.SELECT)
      .setFetchMode("levelPlanList", FetchMode.SELECT)
      .uniqueResult();

    Session sess = getSession();
    for(Question question: qmap.values()){
      if(question.getQuestionType().getQuestionTypeId()==1){
        ObjectAnswer objectAnswer = new ObjectAnswer();
        objectAnswer.setBuildingObject(bo);
        objectAnswer.setObjectConstruction(null);
                objectAnswer.setQuestion(question);
                bo.getDocumentationQuestions().add(objectAnswer);
View Full Code Here

TOP

Related Classes of com.vst.model.Question

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.