Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.GradedEvent


    @Test
    public void testGetGradedEventFromSectionName() {
        System.out.println("getGradedEventFromSectionName");
        List<GradedEvent> glist = null;
        String section = "";
        GradedEvent expResult = null;
        GradedEvent result = RageLib.getGradedEventFromSectionName(glist, section);
        assertEquals(expResult, result);
        // TODO Develop JUnit test for RageLib.getGradedEventFromSectionName() method
        fail("The test case is a prototype.");
    }
View Full Code Here


            LOGGER.error("(update) Badly formed Graded Event.  Throwing "
                    + "IlegalArgumentException");
            throw new IllegalArgumentException("Badly formed Graded Event.");
        } else
        {
            GradedEvent event = em.find(GradedEvent.class, gradedEvent.getId());
            if (event == null)
            {
                LOGGER.error("(update) GradedEvent not found to update.");
                throw new IllegalArgumentException("Graded Event not found to update");
            }
            EntityTransaction tx = em.getTransaction();

            event.setAssignment(gradedEvent.getAssignment());
            event.setCourse(gradedEvent.getCourse());

            // Due Date is optional, but will throw an exception if you try to set
            // a null value
            if (gradedEvent.getDueDate() != null)
            {
                event.setDueDate(gradedEvent.getDueDate());
            }

            event.setPartialCredit(gradedEvent.getPartialCredit());
            event.setTerm(gradedEvent.getTerm());
            event.setVersion(gradedEvent.getVersion());

            LOGGER.debug("update: # of Questions in event (pre-update): "
                    + event.getQuestions().size());

            GradedEvent tempEvent = new GradedEvent();

            int numQuestions = gradedEvent.getQuestions().size();
            LOGGER.debug("update: # of Questions in input Graded event: "
                    + numQuestions);

            int count = 0;
            try
            {
                for (int i = 0; i < numQuestions; i++)
                {
                    LOGGER.debug("i = " + i);
                    tempEvent.addQuestion(gradedEvent.getQuestion(i));
                    LOGGER.debug("update: Question " + i + ": "
                            + gradedEvent.getQuestion(i).getName());
                    count++;
                }
            } catch (IndexOutOfBoundsException ex)
            {
                LOGGER.error("Out of Bounds Exception caught: "
                        + ex.getLocalizedMessage());
            }

            LOGGER.debug("update: Added " + count + " Questions");
            event.clearQuestions();

            count = 0;
            try
            {
                for (int i = 0; i < numQuestions; i++)
                {
                    LOGGER.debug("i = " + i);
                    event.addQuestion(tempEvent.getQuestion(i));
                    LOGGER.debug("update: Question " + i + ": "
                            + tempEvent.getQuestion(i).getName());
                    count++;
                }
            } catch (IndexOutOfBoundsException ex)
            {
                LOGGER.error("Out of Bounds Exception caught: "
View Full Code Here

                        cb.equal(gradedEventRoot.get("version"),
                        gradedEvent.getVersion())));
                TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cq);

                tx.begin();
                GradedEvent result = gradedEventQuery.getSingleResult();
                tx.commit();

                tx.begin();
                em.remove(result);
                tx.commit();
View Full Code Here

            throw new IllegalArgumentException("GradedEvent Id is less than 1");
        } else
        {
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            GradedEvent result = em.find(GradedEvent.class, id);
            tx.commit();

            if (result == null)
            {
                LOGGER.error("GradedEvent not found in the Data Source");
View Full Code Here

                    + "Throwing IllegalArgumentException");
            throw new IllegalArgumentException("Question Name is null");
        } else
        {
            EntityTransaction tx = em.getTransaction();
            GradedEvent result = null;
            if (gradedEvent.getId() != null)
            {
                result = em.find(GradedEvent.class, gradedEvent.getId());
            } else
            {
                try
                {
                    // Build the Query
                    CriteriaBuilder cb = em.getCriteriaBuilder();
                    CriteriaQuery<GradedEvent> cq = cb.createQuery(GradedEvent.class);
                    Root<GradedEvent> gradedEventRoot = cq.from(GradedEvent.class);
                    cq.where(cb.and(cb.equal(gradedEventRoot.get("course"),
                            gradedEvent.getCourse()),
                            cb.equal(gradedEventRoot.get("term"),
                            gradedEvent.getTerm()),
                            cb.equal(gradedEventRoot.get("assignment"),
                            gradedEvent.getAssignment()),
                            cb.equal(gradedEventRoot.get("version"),
                            gradedEvent.getVersion())));
                    TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cq);

                    result = gradedEventQuery.getSingleResult();
                } catch (NoResultException ex)
                {
                    LOGGER.error("GradedEvent not found in Data Source");
                    throw new IllegalArgumentException("GradedEvent not found in "
                            + "Data Source");
                }

            }

            if (result == null)
            {
                LOGGER.error("GradedEvent not found in the Data Source");
                throw new IllegalArgumentException("GradedEvent not found in the "
                        + "Data Source");
            }

            try
            {
                // Build the Query
                CriteriaBuilder cb = em.getCriteriaBuilder();
                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");
            }

            if (!result.getQuestions().contains(question))
            {
                LOGGER.error("Question not assigned to GradedEvent.  Raising "
                        + "IllegalArgumentException");
                throw new IllegalArgumentException("Question not assigned to "
                        + "GradedEvent");
            }

            result.removeQuestion(question);
            tx.begin();
            em.merge(result);
            tx.commit();
        }
    }
View Full Code Here

            int count = 0;
            LOGGER.debug("(removeQuestionFromAllGradedEvents) Looping...");
            for (int i = 0; i < gradedEvents.size(); i++)
            {
                LOGGER.debug("i = " + i);
                GradedEvent event = em.find(GradedEvent.class, gradedEvents.get(i).getId());
                if (event.getQuestions().contains(question))
                {
                    LOGGER.debug("(removeQuestionFromAllGradedEvents) Question in " +
                            "event " + event.getId());
                    LOGGER.debug("Questions in Event " + event.getId() + " (pre): " +
                            event.getQuestions().size());
                    tx.begin();
                    event.removeQuestion(question);
                    event = em.merge(event);
                    tx.commit();
                    count++;
                    LOGGER.debug("Questions in Event " + event.getId() + " (post): " +
                            event.getQuestions().size());
                }
            }
            LOGGER.debug("Question removed from " + count + " Graded Events");

            return count;
View Full Code Here

        Question question2 = createPersistedQuestion(2L, category2, "Looper",
                "Test Question 2", false, false, testCases);
        Question question3 = createPersistedQuestion(3L, category2, "Jumper",
                "Test Question 3", true, true, testCases);

        GradedEvent gradedEvent1 = createPersistedGradedEvent(5L, "Summer 2010", course1,
                "PEX1", false, "ALL");
        gradedEvent1 = addQuestionToGradedEvent(gradedEvent1, question1);
        gradedEvent1 = addQuestionToGradedEvent(gradedEvent1, question2);

        GradedEvent gradedEvent2a = createPersistedGradedEvent(2L, "Summer 2010", course1,
                "PEX2", true, "M1");
        gradedEvent2a = addQuestionToGradedEvent(gradedEvent2a, question2);

        GradedEvent gradedEvent2b = createPersistedGradedEvent(3L, "Summer 2010", course1,
                "PEX2", true, "M2");
        gradedEvent2b = addQuestionToGradedEvent(gradedEvent2b, question3);

        GradedEvent gradedEvent3 = createPersistedGradedEvent(4L, "Summer 2010", course2,
                "Design 1", true, "FALSE");
        gradedEvent3 = addQuestionToGradedEvent(gradedEvent3, question3);

        initialized = true;
    }
View Full Code Here

    private GradedEvent createPersistedGradedEvent(Long id, String term, Course course,
            String assignment, boolean partialCredit, String version)
    {
        EntityManager em = emf.createEntityManager();
        GradedEvent gevent = null;
       
        try
        {
            gevent = findGradedEvent(term, course, assignment, version);
            LOGGER.warn("Graded Event exists: " + gevent);
        } catch (NoResultException ex)
        {
            gevent = new GradedEvent();
            gevent.setId(id);
            gevent.setCourse(course);
            gevent.setAssignment(assignment);
            gevent.setDueDate("29 Apr 2010");
            gevent.setPartialCredit(partialCredit);
            gevent.setTerm(term);
            gevent.setVersion(version);

            // Save to the database
            em.getTransaction().begin();
            em.persist(gevent);
            em.merge(course);
            em.getTransaction().commit();
            LOGGER.debug("GradedEvent Id (post-persist): " + gevent.getId());
        }
        em.close();
        return gevent;
    }
View Full Code Here

        //EntityManager em = emf.createEntityManager();
        CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
        GradedEventDAO gradedEventDAO = new GradedEventDAO(emf.createEntityManager());
        //EntityTransaction tx = em.getTransaction();

        GradedEvent event = (GradedEvent) lstGradedEvents.getSelectedValue();
        if (event != null)
        {
            txtAssignment.setText(event.getAssignment());
            txtTermYear.setText(event.getTerm());
            txtVersion.setText(event.getVersion());
            chkPartialCredit.setSelected(event.getPartialCredit());
            txtDueDate.setText(event.getDueDate());

            // Get the course for this GradedEvent
            cboCourse.removeAllItems();
            //CriteriaBuilder cb = em.getCriteriaBuilder();
            //CriteriaQuery cq = cb.createQuery(Course.class);
            //Root<Course> courseRoot = cq.from(Course.class);
            //cq.orderBy(cb.asc(courseRoot.get("name")));
            //TypedQuery<Course> courseQuery = em.createQuery(cq);
            //List<Course> courses = courseQuery.getResultList();
            List<Course> courses = courseDAO.getAllCoursesByName();
            for (int i = 0; i < courses.size(); i++)
            {
                cboCourse.addItem(courses.get(i).getName());
                if (courses.get(i).equals(event.getCourse()))
                {
                    cboCourse.setSelectedIndex(i);
                }
            }

            // Get the list of questions for this event
            //GradedEvent gevent = em.find(GradedEvent.class, event.getId());
            GradedEvent gevent = gradedEventDAO.find(event.getId());
           
            modGradedEventQuestions.removeAll();
            for (int i = 0; i < gevent.getQuestions().size(); i++)
            {
                modGradedEventQuestions.add(gevent.getQuestions().get(i));
            }
        }
        //em.close();
        courseDAO.closeConnection();
        gradedEventDAO.closeConnection();
View Full Code Here

                && (lstGradedEvents.getSelectedIndex() >= 0))
        {
            //EntityManager em = emf.createEntityManager();
            //EntityTransaction tx = em.getTransaction();

            GradedEvent selectedEvent = (GradedEvent) lstGradedEvents.getSelectedValue();
            GradedEventDAO gradedEventDAO = new GradedEventDAO(emf.createEntityManager());
            GradedEvent gevent = gradedEventDAO.find(selectedEvent.getId());
            //GradedEvent gevent = em.find(GradedEvent.class, selectedEvent.getId());

            // We were able to pull the GradedEvent object from the DB...now
            // we need to pull it's list of questions and then remove the selected
            // one from it's list and re-persist
            if (gevent != null)
            {
                Question quest = (Question) lstGradedEventQuestions.getSelectedValue();
                if (gevent.removeQuestion(quest))
                {
                    JOptionPane.showMessageDialog(this, "Question " + quest.getName()
                            + " removed from Graded Event " + gevent.getAssignment(),
                            "Success", JOptionPane.INFORMATION_MESSAGE);
                    modGradedEventQuestions.remove(lstGradedEventQuestions.getSelectedIndex());
                    LOGGER.info("Question " + quest.getName() + " removed from "
                            + "Graded Event.");
                } else
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.GradedEvent

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.