Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Question


    @Test
    @Ignore
    public void testCreate()
    {
        System.out.println("create");
        Question question = null;
        Long expResult = null;
        Long result = instance.create(question);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
View Full Code Here


    @Ignore
    public void testFind_Long()
    {
        System.out.println("find");
        Long id = null;
        Question expResult = null;
        Question result = instance.find(id);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

    @Ignore
    public void testFind_String()
    {
        System.out.println("find");
        String name = "";
        Question expResult = null;
        Question result = instance.find(name);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

    @Test
    @Ignore
    public void testUpdate()
    {
        System.out.println("update");
        Question question = null;
        Question expResult = null;
        Question result = instance.update(question);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

    @Test
    @Ignore
    public void testDelete_Question()
    {
        System.out.println("delete");
        Question question = null;
        instance.delete(question);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

                CriteriaQuery<Question> cq = cb.createQuery(Question.class);
                Root<Question> questionRoot = cq.from(Question.class);
                cq.where(cb.equal(questionRoot.get("name"), question.getName()));
                TypedQuery<Question> questionQuery = em.createQuery(cq);

                Question resultQ = questionQuery.getSingleResult();
            } catch (NoResultException ex)
            {
                LOGGER.error("Question not found in Data Source");
                throw new IllegalArgumentException("Question not found in "
                        + "Data Source");
View Full Code Here

                CriteriaQuery<Question> cq = cb.createQuery(Question.class);
                Root<Question> questionRoot = cq.from(Question.class);
                cq.where(cb.equal(questionRoot.get("name"), question.getName()));
                TypedQuery<Question> questionQuery = em.createQuery(cq);

                Question resultQ = questionQuery.getSingleResult();
            } catch (NoResultException ex)
            {
                LOGGER.error("Question not found in Data Source");
                throw new IllegalArgumentException("Question not found in "
                        + "Data Source");
View Full Code Here

         * Since Send to DB and Generate XML will both do this first part (create
         * Question object, this should probably be a static function in RageLib.
         */
        // Set the question name first...if the question name isn't a valid name
        // no further processing should happen and an error should be displayed
        Question question = new Question();
        File refFileName = new File(txtRefProgram.getText());
        // Retrieve the question name based upon the filename
        // TODO: RAGE-98
        String name = RageLib.getQuestionNameFromFilename(refFileName.getName());
        if ((name != null) && (!name.startsWith("ERROR in Filename:")))
        {
            LOGGER.debug("Creating Question for " + name);
            // This is a valid question name (not null or "ERROR in Filename:"
            question.setName(name);

            // Set whether question requires a verbatim response
            question.setVerbatim(chkVerbatim.isSelected());

            // Set whether question requires ordered output
            question.setOrderedOutput(chkOrdered.isSelected());

            // Set the description
            try
            {
                question.setDescription(txtDescription.getText(0, 50));
            } catch (BadLocationException ex)
            {
                question.setDescription(txtDescription.getText());

            } catch (IllegalArgumentException ex)
            {
                // Description is blank so just ignore...not required for question
            }

            /** Set the question category--this is not a nullable field
             *  This button will not activate if the txtCategory field is null or
             *  empty, so we can safely not check for it here.
             */
            question.setCategory(new Category(txtCategory.getText()));

            /**
             * As long as there are test cases, we can continue...otherwise stop
             */
            if (modTCList.getSize() > 0)
            {
                // Store the test cases in the question
                try
                {
                    question.setTestCases(modTCList.cloneTestCases());
                } catch (CloneNotSupportedException ex)
                {
                    LOGGER.error("Clone not supported");
                }

                /**
                 * Run Raptor and store the returned outputs in the TestCase object
                 */
                ProcessBuilder launcher = new ProcessBuilder();
                Map<String, String> environment = launcher.environment();
                launcher.redirectErrorStream(true);
                launcher.directory(refFileName.getParentFile());
                int type = 0;
                if (rBtnRaptor.isSelected())
                {
                    type = 0;
                } else if (rBtnProcessing.isSelected())
                {
                    type = 1;
                }
                Runnable r = new TestCaseGenThread(node, launcher, refFileName, question, type);

                Thread testCaseGenThread = new Thread(r);
                testCaseGenThread.run();
                while (testCaseGenThread.isAlive())
                {
                }

                /**
                 * Build the XML document--move this to a static function in RageLib
                 */
                // TODO: RAGE-99 - Epic
                Document doc = DocumentHelper.createDocument();
                doc.setXMLEncoding("UTF-8");
                doc.addDocType("GradedEvent", RAGEConst.DEFAULT_PUBLIC_URI,
                        RAGEConst.DEFAULT_SYSTEM_URI);
                Element root = doc.addElement("GradedEvent");
                Element term = root.addElement("Term").addAttribute("name", node.get("Term", "No Term"));
                Element course = root.addElement("Course").addAttribute("name", "CS110");
                Element assignment = root.addElement("Assignment").addAttribute("name", "Dummy");
                Element versionElement = root.addElement("Version").addAttribute("id", "ALL");
                Element dueDate = root.addElement("DueDate").addText("25 Jan 2020");
                Element pc = root.addElement("PartialCredit").addAttribute("value", "false");
                Element question1 = root.addElement("Question").addAttribute("category", question.getCategory().getName());
                Element qName = question1.addElement("Name").addAttribute("name", question.getName());
                Element qDesc = question1.addElement("Description").addText(question.getDescription());
                if (question.getVerbatim())
                {
                    Element qVerbatim = question1.addElement("Verbatim").addAttribute("value", "true");
                } else
                {
                    Element qVerbatim = question1.addElement("Verbatim").addAttribute("value", "false");
                }
                if (question.getOrderedOutput())
                {
                    Element qOrdered = question1.addElement("OrderedOutput").addAttribute("value", "true");
                } else
                {
                    Element qOrdered = question1.addElement("OrderedOutput").addAttribute("value", "false");
                }
                for (TestCase tc : question.getTestCases())
                {
                    Element qTestCase = question1.addElement("TestCase");
                    Element tcValue = qTestCase.addElement("Value").addAttribute("value", tc.getValue().toPlainString());
                    LOGGER.debug("Inputs / Outputs: " + tc.getInputs().size()
                            + " / " + tc.getOutputs().size());
View Full Code Here

                    TypedQuery<Question> questionQuery = em.createQuery(cq);
                    EntityTransaction tx = em.getTransaction();
                    //See if we are editing a question or creating a new question
                    try
                    {
                        Question question = questionQuery.getSingleResult();
                        LOGGER.debug("Question" + question.getName()
                                + "already exists in the database");
                        tx.begin();
                        em.remove(question);
                        tx.commit();

                    } catch (NoResultException e)
                    {
                        LOGGER.error("That question doesn't exist in the database. "
                                + e.getLocalizedMessage());
                    } catch (IllegalStateException ex)
                    {
                        LOGGER.error("Illegal State Exception: "
                                + ex.getLocalizedMessage());
                    } catch (IllegalArgumentException ex)
                    {
                        LOGGER.error("Illegal Argument Exception: "
                                + ex.getLocalizedMessage());
                    } catch (TransactionRequiredException ex)
                    {
                        LOGGER.error("Transaction Required Exception: "
                                + ex.getLocalizedMessage());
                    } catch (Exception ex)
                    {
                        LOGGER.error("Exception Caught: "
                                + ex.getLocalizedMessage());
                    }
                    // This is a valid question name (not null or "ERROR in Filename:"
                    Question question = new Question();
                    question.setName(name);

                    // Set whether question requires a verbatim response
                    question.setVerbatim(chkVerbatim.isSelected());

                    // Set whether question requires ordered output
                    question.setOrderedOutput(chkOrdered.isSelected());

                    // Set the description
                    try
                    {
                        question.setDescription(txtDescription.getText(0, 50));
                    } catch (BadLocationException ex)
                    {
                        question.setDescription(txtDescription.getText());

                    } catch (IllegalArgumentException ex)
                    {
                        // Description is blank so just ignore...not required for question
                    }

                    /**
                     * As long as there are test cases, we can continue...otherwise stop
                     */
                    if (modTCList.getSize() > 0)
                    {
                        try
                        {
                            // Store the test cases in the question
                            question.setTestCases(modTCList.cloneTestCases());
                        } catch (CloneNotSupportedException ex)
                        {
                            LOGGER.error("Clone not supported");
                        }

                        /**
                         * Run Raptor and store the returned outputs in the TestCase object
                         */
                        ProcessBuilder launcher = new ProcessBuilder();
                        Map<String, String> environment = launcher.environment();
                        launcher.redirectErrorStream(true);

                        launcher.directory(refFileName.getParentFile());
                        int type = 0;
                        if (rBtnRaptor.isSelected())
                        {
                            type = 0;
                        } else if (rBtnProcessing.isSelected())
                        {
                            type = 1;
                        }
                        Runnable r = new TestCaseGenThread(node, launcher,
                                refFileName, question, type);

                        Thread testCaseGenThread = new Thread(r);
                        testCaseGenThread.run();
                        while (testCaseGenThread.isAlive())
                        {
                        }

                        /** Set the question category--this is not a nullable field
                         *  This button will not activate if the txtCategory field is
                         *  null or empty, so we can safely not check for it here.
                         *
                         * First check to see if category already exists in database
                         */
                        //cq = cb.createQuery(Category.class);
                        //Root<Category> categoryRoot = cq.from(Category.class);
                        //cq.where(cb.equal(categoryRoot.get("name"),
                        //      txtCategory.getText().trim()));
                        //TypedQuery<Category> categoryQuery = em.createQuery(cq);
                        CategoryDAO catDAO = new CategoryDAO(emf.createEntityManager());
                        Category queryCat;
                        try
                        {
                            //queryCat = categoryQuery.getSingleResult();
                            queryCat = catDAO.find(txtCategory.getText().trim());
                            LOGGER.info("Category already exists in database: "
                                    + queryCat.getName());
                        } catch (NoResultException ex)
                        {
                            queryCat = new Category(txtCategory.getText().trim());
                            //tx.begin();
                            //em.persist(queryCat);
                            //tx.commit();
                            Long newCatId = catDAO.create(queryCat);
                            queryCat.setId(newCatId);
                            LOGGER.info("Added Category: " + queryCat.getName());
                        }
                        question.setCategory(queryCat);
                        if (catDAO.isOpen())
                        {
                            catDAO.closeConnection();
                        }
                       
                        // TODO: RAGE-24 - Migrate to the QuestionDAO class
                        cq = cb.createQuery(Question.class);
                        questionRoot = cq.from(Question.class);
                        cq.where(cb.and(cb.equal(questionRoot.get("name"),
                                question.getName()), cb.equal(questionRoot.get("category"),
                                question.getCategory())));
                        questionQuery = em.createQuery(cq);

                        Question quest;
                        try
                        {
                            quest = questionQuery.getSingleResult();
                            JOptionPane.showMessageDialog(this, "ERROR: Question " +
                                    "already exists.", "Error",
                                    JOptionPane.ERROR_MESSAGE);
                            LOGGER.warn("Question already exists: "
                                    + quest.getName());
                        } catch (NoResultException ex)
                        {
                            LOGGER.debug("Question not in database.  Inserting "
                                    + "new question");

View Full Code Here

        {
            LOGGER.debug("Creating EntityManager");
            EntityManager em = emf.createEntityManager();
            EntityTransaction tx = em.getTransaction();

            Question selectedQuestion = (Question) lstQuestions.getSelectedValue();
            // TODO: RAGE-24 - Migrate to the QuestionDAO class
            Question question = em.find(Question.class, selectedQuestion.getId());
            if (question != null)
            {

                GradedEventDAO gradedEventDAO =
                    new GradedEventDAO(emf.createEntityManager());
                try
                {
                    // Remove the Question from any GradedEvents it's current part of
                    int count = gradedEventDAO.removeQuestionFromAllGradedEvents(question);
                    LOGGER.info("Question (" + question.getName() + ") removed from "
                        + count + " Graded Events");
                } catch (Exception ex)
                {
                    LOGGER.warn("(btnRemoveQuestionActionPerformed) Error removing "
                        + "Question (" + question.getName() + ") from all Graded"
                        + " Events");
                } finally
                {
                    gradedEventDAO.closeConnection();
                }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.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.