Package com.darkhonor.rage.libs.dataaccess

Examples of com.darkhonor.rage.libs.dataaccess.CourseDAO


    }//GEN-LAST:event_btnLoadGradedEventsActionPerformed

    private void lstGradedEventsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstGradedEventsMouseClicked

        //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();
    }//GEN-LAST:event_lstGradedEventsMouseClicked
View Full Code Here


        } else
        {
            this.emf = emf;
            // Clear the ComboBox items to fill with Course names
            LOGGER.debug("Adding courses");
            CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
            EntityManager em = emf.createEntityManager();
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<Course> 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> courseResult;
//            try
//            {
            int count = 0;
            //courseResult = courseQuery.getResultList();
            courseResult = courseDAO.getAllCoursesByName();
            ccbm.removeAll();
            for (int i = 0; i < courseResult.size(); i++)
            {
                Course course = courseResult.get(i);
                ccbm.add(course);
                count++;
            }
            LOGGER.debug("Added " + count + " courses to Combo Box");
//            }
//            catch (NoResultException ex)
//            {
//                JOptionPane.showMessageDialog(this, "ERROR: No Courses found",
//                        "ERROR", JOptionPane.ERROR_MESSAGE);
//                LOGGER.error("No Courses found");
//                btnSave.setEnabled(false);
//                btnCancel.setEnabled(true);
//            }

            LOGGER.debug("Adding questions to Question List");
            // TODO: RAGE-24 - Migrate to the QuestionDAO class.  Remove
            // EntityManager and Query object creation done above once this is
            // clear.
            cb = em.getCriteriaBuilder();
            CriteriaQuery<Question> cqQuest = cb.createQuery(Question.class);
            Root<Question> questionRoot = cqQuest.from(Question.class);
            cqQuest.orderBy(cb.asc(questionRoot.get("name")));
            TypedQuery<Question> questionQuery = em.createQuery(cqQuest);
            List<Question> questionResult;
            try
            {
                count = 0;
                questionResult = questionQuery.getResultList();
                modQuestionList.removeAll();
                for (int i = 0; i < questionResult.size(); i++)
                {
                    Question question = (Question) questionResult.get(i);
                    modQuestionList.add(question);
                    count++;
                }
                LOGGER.debug("Added " + count + " questions");
            } catch (NoResultException ex)
            {
                JOptionPane.showMessageDialog(this, "ERROR: No Questions found."
                        + " Please load questions before creating a new Graded "
                        + "Event", "ERROR", JOptionPane.ERROR_MESSAGE);
                LOGGER.error("No questions found");
                btnSave.setEnabled(false);
                btnCancel.setEnabled(true);
            }
            em.close();
            courseDAO.closeConnection();
            btnSave.setEnabled(true);
            btnCancel.setEnabled(true);
            returnStatus = RET_CANCEL;
        }
        LOGGER.debug("Dialog initialized");
View Full Code Here

        {
            LOGGER.debug("All fields complete");
            GradedEvent gradedEvent = null;
            EntityManager em = emf.createEntityManager();
            LOGGER.debug("Getting selected Course");
            CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
            Course selectedCourse = (Course) cboCourse.getSelectedItem();
            Course course = courseDAO.find(selectedCourse.getId());
            //Course course = em.find(Course.class, selectedCourse.getId());
            LOGGER.debug("Course Name: " + course.getName());

            LOGGER.debug("Querying the data source to see if a GradedEvent "
                    + "already exists");
            GradedEventDAO gradedEventDAO =
                    new GradedEventDAO(emf.createEntityManager());
//            CriteriaBuilder cb = em.getCriteriaBuilder();
//            CriteriaQuery cq = cb.createQuery(GradedEvent.class);
//            Root<GradedEvent> gradedEventRoot = cq.from(GradedEvent.class);
//            cq.where(cb.and(cb.equal(gradedEventRoot.get("assignment"), txtAssignment.getText().trim()),
//                    cb.equal(gradedEventRoot.get("term"), txtTerm.getText().trim()),
//                    cb.equal(gradedEventRoot.get("course"), course),
//                    cb.equal(gradedEventRoot.get("version"), txtVersion.getText().trim())));
//
//            TypedQuery<GradedEvent> gradedEventQuery = em.createQuery(cq);
//            LOGGER.debug("Query built");
            try
            {
                //gradedEvent = gradedEventQuery.getSingleResult();
                gradedEvent = gradedEventDAO.find(course,
                        txtAssignment.getText().trim(), txtTerm.getText().trim(),
                        txtVersion.getText().trim());
            } catch (IllegalArgumentException ex)
            {
                // Because of the check at the beginning of this method, we should
                // never reach this point.  But just in case...
                LOGGER.warn("Invalid value provided.  Ensure Course, Term, "
                        + "Assignment, and Version are not blank.");
            }
            if (gradedEvent != null)
            {
                JOptionPane.showMessageDialog(this, "ERROR: This Graded "
                        + "Event already exists in the system.", "ERROR",
                        JOptionPane.ERROR_MESSAGE);
                LOGGER.error("This GradedEvent already exists in the database");
                doClose(RET_CANCEL);
            } else
            {
                LOGGER.debug("Creating a new GradedEvent");
                EntityTransaction tx = em.getTransaction();
                gradedEvent = new GradedEvent();
                gradedEvent.setCourse(course);
                gradedEvent.setAssignment(txtAssignment.getText().trim());
                gradedEvent.setTerm(txtTerm.getText().trim());
                gradedEvent.setVersion(txtVersion.getText().trim());
                gradedEvent.setPartialCredit(chkPartialCredit.isSelected());
                try
                {
                    gradedEvent.setDueDate(txtDueDate.getText().trim());
                } catch (IllegalArgumentException ex)
                {
                    LOGGER.warn("Invalid Date Specified.  No Due Date Set");
                }
                LOGGER.debug("Graded Event: " + gradedEvent.toString());
                List<Question> objects = lstQuestions.getSelectedValuesList();
                LOGGER.debug("Adding " + objects.size() + " Questions to GradedEvent");
                int count = 0;
                for (int i = 0; i < objects.size(); i++)
                {
                    // TODO: RAGE-24 - Migrate to the QuestionDAO class. 
                    // Action: Update the Question in the current Persistence Context
                    Question question = objects.get(i);
                    try
                    {
                        question = em.merge(question);
                    } catch (Exception ex)
                    {
                        LOGGER.error("Exception: " + ex.getLocalizedMessage());
                        tx.rollback();
                    }
                    gradedEvent.addQuestion(question);
                    count++;
                }
                LOGGER.debug(count + " Questions added.  Saving to database");
                Long newId;
                try
                {
                    newId = gradedEventDAO.create(gradedEvent);
                    LOGGER.info("Graded Event created with Id: " + newId);
//                tx.begin();
//                em.persist(gradedEvent);
//                tx.commit();
//            } catch (EntityExistsException ex)
//            {
//                LOGGER.error("Graded Event exists in the database previously");
//                LOGGER.error("Exception: " + ex.getLocalizedMessage());
//                em.close();
//                doClose(RET_CANCEL);
//            } catch (IllegalStateException ex)
//            {
//                LOGGER.error("EntityManager has been closed.");
//                LOGGER.error("Exception: " + ex.getLocalizedMessage());
//                em.close();
//                doClose(RET_CANCEL);
//            } catch (IllegalArgumentException ex)
//            {
//                LOGGER.error("Not saving a mapped Entity");
//                LOGGER.error("Exception: " + ex.getLocalizedMessage());
//                em.close();
//                doClose(RET_CANCEL);
//            } catch (TransactionRequiredException ex)
//            {
//                LOGGER.error("Exception: " + ex.getLocalizedMessage());
//                em.close();
//                doClose(RET_CANCEL);
                } catch (Exception ex)
                {
                    LOGGER.error("Exception: " + ex.getLocalizedMessage());
                    em.close();
                    doClose(RET_CANCEL);
                }
               
                LOGGER.debug("Graded Event saved to database");
                txtTerm.setText("");
                txtAssignment.setText("");
                txtVersion.setText("");
                txtDueDate.setText("");
                lstQuestions.setSelectedIndex(-1);
                doClose(RET_OK);
            }

            em.close();
            courseDAO.closeConnection();
            gradedEventDAO.closeConnection();
        }
    }
View Full Code Here

        {
            LOGGER.error("Unknown Exception Clearing ComboBoxes: "
                    + ex.getLocalizedMessage());
        }
        LOGGER.debug("Selected Index: " + cboCourse.getSelectedIndex());
        CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
        GradedEventDAO gradedEventDAO = new GradedEventDAO(emf.createEntityManager());
        LOGGER.debug("Created CourseDAO and GradedEventDAO instances");
        Course selectedCourse = (Course) cboCourse.getSelectedItem();
        try
        {
            LOGGER.debug("Course Selected: " + selectedCourse);
            LOGGER.debug("Finding Course in DB based on selected Course id");
            Course c = courseDAO.find(selectedCourse.getId());
            LOGGER.debug("Course (" + c.getName() + ") found.  Course has "
                    + c.getInstructors().size() + " instructors and "
                    + c.getSections().size() + " sections.");

            List<GradedEvent> result =
                    gradedEventDAO.getGradedEventsForCourseAndTerm(c, node.get("Term", ""));
            /**
             * List to keep track of which events are already added to the Combo Box
             */
            List<String> events = new ArrayList<String>();
            /**
             * Loop through and only show a single graded event (no duplicate versions)
             */
            int count = 0;
            for (GradedEvent ev : result)
            {
                // This is done since multiple versions of a GradedEvent should
                // not be shown.  The version identification will happen when
                // the grading commences.
                if (!events.contains(ev.getAssignment()))
                {
                    events.add(ev.getAssignment());
                    gradedEventComboBoxModel.add(ev);
                    count++;
                }
            }
            LOGGER.debug(count + " assignments found for " + c.getName());

            // Add a new Instructor so that all instructors can be graded in
            // course
            instructorComboBoxModel.add(new Instructor("All", "000 - Instructors",
                    "All.Instructors"));
            count = 0;
            for (Instructor i : c.getInstructors())
            {
                instructorComboBoxModel.add(i);
                count++;
            }
            instructorComboBoxModel.sort();
            LOGGER.debug(c.getInstructors().size() + " instructors added to "
                    + "Instructor ComboBox");
            cboAssignment.setEnabled(true);
            cboInstructor.setEnabled(false);
            cboAssignment.setSelectedIndex(-1);
            cboInstructor.setSelectedIndex(-1);
            cboStudent.setSelectedIndex(-1)// Blank out the student name as well
            cboStudent.setEnabled(false);
            cboSection.setSelectedIndex(-1)// Blank out the section
            cboSection.setEnabled(false);
        } catch (IllegalArgumentException ex)
        {
            LOGGER.error("Illegal Argument for Query Parameter: "
                    + ex.getLocalizedMessage());
        } catch (NullPointerException ex)
        {
            LOGGER.error("Null Pointer Exception: " + ex.getLocalizedMessage());
        } catch (Exception ex)
        {
            LOGGER.error("Unknown Exception Caught: "
                    + ex.getLocalizedMessage());
        } finally
        {
            LOGGER.debug("Setting cboAssignActive to true");
            cboAssignActive = true;
            courseDAO.closeConnection();
            gradedEventDAO.closeConnection();
        }
        LOGGER.debug("Finished with cboCourseActionPerformed");
    }
}//GEN-LAST:event_cboCourseActionPerformed
View Full Code Here

        // Minimum requirement: Course and Assignment MUST be selected to continue
        if ((cboCourse.getSelectedIndex() >= 0) && (cboAssignment.getSelectedIndex() >= 0))
        {
            GradedEventDAO gradedEventDAO = new GradedEventDAO(emf.createEntityManager());
            CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
            String[] name;

            Course selectedCourse = (Course) cboCourse.getSelectedItem();
            Course course = courseDAO.find(selectedCourse.getId());
            GradedEvent selectedAssignment = (GradedEvent) cboAssignment.getSelectedItem();
            LOGGER.debug("Querying database for the selected GradedEvent");

            int numVersions = gradedEventDAO.getNumVersionsOfGradedEvent(selectedAssignment);

            GradedEvent gevent = null;
            List<GradedEvent> gevents = null;

            // If more than 1 result comes up for the GradedEvent query (not
            // including the version).  We can't set gevent until we know which
            // section is to be graded
            if (numVersions == 1)
            {
                gevent = gradedEventDAO.find(selectedAssignment.getId());
            } else
            {   // Set it to the first GradedEvent so we can get the name
                gevents = gradedEventDAO.getAllVersionsOfGradedEvent(selectedAssignment);
                gevent = gevents.get(0);
                multVersions = true;
            }

            String path = this.buildBasePath();

            Instructor selectedInstructor = null;
            Section selectedSection = null;
            Student selectedStudent = null;
            if (cboInstructor.getSelectedIndex() != -1)
            {
                selectedInstructor = (Instructor) cboInstructor.getSelectedItem();
            }
            if (cboSection.getSelectedIndex() != -1)
            {
                selectedSection = (Section) cboSection.getSelectedItem();
            }
            if (cboStudent.getSelectedIndex() != -1)
            {
                selectedStudent = (Student) cboStudent.getSelectedItem();
            }

//            // Derive the grading path from the selected comboboxes
//            String path = node.get("RootDir", "");
//            path = path.concat(File.separator);
//            path = path.concat(selectedCourse.getName());
//            path = path.concat(File.separator);
//            path = path.concat(selectedAssignment.getAssignment());

            /**
             * Get the selected Instructor and Section objects.  If either is
             * not selected, getSelectedIndex will return -1 and the object will
             * stay null.
             */
//            Instructor selectedInstructor = null;
//            Section selectedSection = null;
//            if (cboInstructor.getSelectedIndex() != -1)
//            {
//                selectedInstructor = (Instructor) cboInstructor.getSelectedItem();
//            }
//            if (cboSection.getSelectedIndex() != -1)
//            {
//                selectedSection = (Section) cboSection.getSelectedItem();
//            }
//
//            // Add the Instructor if one is selected
//            if (cboInstructor.getSelectedIndex() > 0)
//            {
//                path = path.concat(File.separator);
//
//                //InstructorDAO instructorDAO = new InstructorDAO(emf.createEntityManager());
//                //instructor = instructorDAO.find(selectedInstructor.getId());
//                path = path.concat(selectedInstructor.getWebID());
//
//                // Add the section if one is selected
//                if (cboSection.getSelectedIndex() > 0)
//                {
//                    //SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
//                    //section = sectionDAO.find(selectedSection.getId());
//
//                    path = path.concat(File.separator);
//                    path = path.concat(selectedSection.getName());
//
//                    // Add the Student if one is selected
//                    if (cboStudent.getSelectedIndex() > 0)
//                    {
//                        path = path.concat(File.separator);
//                        name = cboStudent.getSelectedItem().toString().split(",");
//                        query = em.createQuery("SELECT p FROM Person p WHERE "
//                                + "p.firstName = :fname AND p.lastName = :lname");
//                        query.setParameter("fname", name[1].trim());
//                        query.setParameter("lname", name[0].trim());
//                        student = (Student) query.getSingleResult();
//                        path = path.concat(student.getWebID());
//                    }
//                }
//            }
            // Build the thread environment regardless of whether doing student or
            ProcessBuilder launcher = new ProcessBuilder();
            Map<String, String> environment = launcher.environment();
            launcher.redirectErrorStream(true);
            File outputFile = null;
            SectionReport sectionReport = null;
            Date dateStamp = new Date();
            String dateStampString = String.format("%tY%tm%td%tH%tM", dateStamp);

            /**
             * Grade All Instructors.  Section and Student are not selected
             */
            if ((cboAssignment.getSelectedIndex() >= 0)
                    && (cboInstructor.getSelectedIndex() == 0)
                    && (cboSection.getSelectedIndex() < 0)
                    && (cboStudent.getSelectedIndex() < 0))
            {
                LOGGER.debug("Grading All Instructors.  Section and Student are "
                        + "not selected");
                for (Instructor insIter : course.getInstructors())
                {
                    String tempPath = new String();
                    tempPath = path.concat(File.separator);
                    tempPath = tempPath.concat(insIter.getWebID());
                    for (Section sectionIter : insIter.getSections())
                    {
                        sectionReport = new SectionReport(course.getName(),
                                insIter, sectionIter.getName(),
                                selectedAssignment.getAssignment());
                        try
                        {
                            outputFile = new File(tempPath + File.separator
                                    + sectionIter.getName() + File.separator
                                    + sectionIter.getName() + dateStampString + ".html");
                            LOGGER.debug("Output File: " + outputFile.getCanonicalPath());
                            outputFile.createNewFile();
                        } catch (IOException ex)
                        {
                            LOGGER.error("ERROR: IOException caught.");
                            LOGGER.error(ex.getLocalizedMessage());
                        }
                        /**
                         * If a section is selected and there are multiple versions,
                         * pull the right one for the gevent variable...can we
                         * search the list and return the right one?
                         */
                        if (multVersions)
                        {
                            /**
                             * If there are multiple versions of the GradedEvent,
                             * pull only the one for this section
                             */
                            gevent = RageLib.getGradedEventFromSectionName(gevents,
                                    sectionIter.getName());
                        }
                        // No else needed since if there are no multiple versions,
                        // gevent is already set above

                        for (Student studentIter : sectionIter.getStudents())
                        {
                            StudentReport studentReport = new StudentReport(studentIter,
                                    sectionIter);
                            String newPath = new String();
                            newPath = tempPath.concat(File.separator);
                            newPath = newPath.concat(sectionIter.getName());
                            newPath = newPath.concat(File.separator);
                            newPath = newPath.concat(studentIter.getWebID());
                            LOGGER.debug("Path to grade: " + newPath);
                            statusMessageLabel.setText("Grading: "
                                    + studentIter.getLastName()
                                    + ", " + studentIter.getFirstName());
                            LOGGER.info("Grading: " + studentIter.getLastName()
                                    + ", " + studentIter.getFirstName());
                            try
                            {
                                File directory = new File(newPath);
                                LOGGER.debug("Grading path: " + directory.getCanonicalPath());
                                launcher.directory(directory);
                                Runnable r = new GraderThread(node, launcher, directory,
                                        gevent, studentReport, type);
                                grader_thread = new Thread(r);
                                grader_thread.start();
                                while (grader_thread.isAlive())
                                {
                                }
                                // After grader is complete, add StudentReport to
                                // SectionReport
                                sectionReport.addStudentReport(studentReport);
                            } catch (IOException ex)
                            {
                                LOGGER.error("IO Exception: " + ex.getLocalizedMessage());
                            }
                        }
                        sectionReport.sortStudentReports();
                        RageLib.printSectionReport(outputFile, sectionReport);
                    }
                }
            } /**
             * Grade a single instructor, but All Sections is selected
             */
            else if ((cboInstructor.getSelectedIndex() > 0)
                    && (cboSection.getSelectedIndex() == 0)
                    && (cboStudent.getSelectedIndex() < 0))
            {
                LOGGER.debug("Grading all sections for Instructor "
                        + selectedInstructor.getLastName() + ", "
                        + selectedInstructor.getFirstName());

                // Pull the Instructor from the Data Source to be able to grab Sections
                InstructorDAO instructorDAO = new InstructorDAO(emf.createEntityManager());
                Instructor instructor = instructorDAO.find(selectedInstructor.getId());
                for (Section sectionIter : instructor.getSections())
                {
                    sectionReport = new SectionReport(course.getName(),
                            instructor, sectionIter.getName(),
                            selectedAssignment.getAssignment());
                    try
                    {
                        outputFile = new File(path + File.separator
                                + sectionIter.getName() + File.separator
                                + sectionIter.getName() + dateStampString + ".html");
                        LOGGER.debug("Output File: " + outputFile.getCanonicalPath());
                        outputFile.createNewFile();
                    } catch (IOException ex)
                    {
                        LOGGER.error("IOException caught: "
                                + ex.getLocalizedMessage());
                    }
                    /**
                     * If a section is selected and there are multiple versions,
                     * pull the right one for the gevent variable...can we
                     * search the list and return the right one?
                     */
                    if (multVersions)
                    {
                        /**
                         * If there are multiple versions of the GradedEvent,
                         * pull only the one for this section
                         */
                        gevent = RageLib.getGradedEventFromSectionName(gevents,
                                sectionIter.getName());
                    }
                    // No else needed since if there are no multiple versions,
                    // gevent is already set above

                    for (Student studentIter : sectionIter.getStudents())
                    {
//                        StudentReport studentReport = new StudentReport(studentIter);
                        StudentReport studentReport = new StudentReport(studentIter,
                                sectionIter);
                        String newPath = new String();
                        newPath = path.concat(File.separator);
                        newPath = newPath.concat(sectionIter.getName());
                        newPath = newPath.concat(File.separator);
                        newPath = newPath.concat(studentIter.getWebID());
                        LOGGER.debug("Path to grade: " + newPath);
                        statusMessageLabel.setText("Grading: " + studentIter.getLastName()
                                + ", " + studentIter.getFirstName());
                        LOGGER.info("Grading: " + studentIter.getLastName()
                                + ", " + studentIter.getFirstName());
                        File directory = new File(newPath);
                        launcher.directory(directory);
                        Runnable r = new GraderThread(node, launcher, directory,
                                gevent, studentReport, type);
                        grader_thread = new Thread(r);
                        grader_thread.start();
                        while (grader_thread.isAlive())
                        {
                        }
                        sectionReport.addStudentReport(studentReport);
                    }
                    sectionReport.sortStudentReports();
                    RageLib.printSectionReport(outputFile, sectionReport);
                }
                // Close the connection to the Data Source
                instructorDAO.closeConnection();
            } /**
             * Grade all students in a single section
             */
            else if ((cboStudent.getSelectedIndex() == 0)
                    && (cboSection.getSelectedIndex() > 0))
            {
                LOGGER.debug("Grading all students in section "
                        + selectedSection.getName());

                // Pull the Section from the Data Source to get the full list of
                // Students
                SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
                Section section = sectionDAO.find(selectedSection.getId());
                sectionReport = new SectionReport(course.getName(), selectedInstructor,
                        section.getName(), selectedAssignment.getAssignment());
                try
                {
                    outputFile = new File(path + File.separator
                            + selectedSection.getName() + dateStampString + ".html");
                    LOGGER.debug("Output File: " + outputFile.getCanonicalPath());
                    outputFile.createNewFile();
                    /**
                     * If a section is selected and there are multiple versions,
                     * pull the right one for the gevent variable...can we
                     * search the list and return the right one?
                     */
                    if (multVersions)
                    {
                        /**
                         * If there are multiple versions of the GradedEvent,
                         * pull only the one for this section
                         */
                        gevent = RageLib.getGradedEventFromSectionName(gevents,
                                selectedSection.getName());
                    }
                    // No else needed since if there are no multiple versions,
                    // gevent is already set above

                } catch (FileNotFoundException ex)
                {
                    // Do nothing...the file should be created if it's not there
                } catch (IOException ex)
                {
                    LOGGER.error("ERROR: IOException caught.");
                    LOGGER.error(ex.getLocalizedMessage());
                }
                for (Student studentIter : section.getStudents())
                {
                    StudentReport studentReport = new StudentReport(studentIter, section);
//                    StudentReport studentReport = new StudentReport(studentIter);
                    String newPath = new String();
                    newPath = path.concat(File.separator);
                    newPath = newPath.concat(studentIter.getWebID());
                    LOGGER.debug("Path to grade: " + newPath);
                    statusMessageLabel.setText("Grading: " + studentIter.getLastName()
                            + ", " + studentIter.getFirstName());
                    LOGGER.info("Grading: " + studentIter.getLastName() + ", "
                            + studentIter.getFirstName());
                    File directory = new File(newPath);
                    launcher.directory(directory);
                    Runnable r = new GraderThread(node, launcher, directory, gevent,
                            studentReport, type);
                    grader_thread = new Thread(r);
                    grader_thread.start();

                    while (grader_thread.isAlive())
                    {
                    }
                    sectionReport.addStudentReport(studentReport);
                }
                sectionReport.sortStudentReports();
                RageLib.printSectionReport(outputFile, sectionReport);

                // Close the connection to the Data Source
                sectionDAO.closeConnection();
            } /**
             * Just grade a single student
             */
            else
            {
                LOGGER.debug("Grading a single Student:" + selectedStudent.getWebID());
                LOGGER.debug("Path to grade: " + path);
                File directory = null;
                try
                {
                    directory = new File(path);
                    LOGGER.debug("Creating Output File");
                    outputFile = new File(directory.getParent()
                            + File.separator + selectedStudent.getWebID()
                            + dateStampString + ".html");
                    LOGGER.debug("Output File: " + outputFile.getCanonicalPath());
                    outputFile.createNewFile();
                    /**
                     * If a section is selected and there are multiple versions,
                     * pull the right one for the gevent variable...can we
                     * search the list and return the right one?
                     */
                    if (multVersions)
                    {
                        /**
                         * If there are multiple versions of the GradedEvent,
                         * pull only the one for this section
                         */
                        gevent = RageLib.getGradedEventFromSectionName(gevents,
                                selectedSection.getName());
                    }
                    // No else needed since if there are no multiple versions,
                    // gevent is already set above
                } catch (FileNotFoundException ex)
                {
                    // Do nothing...the file should be created if it's not there
                } catch (IOException ex)
                {
                    LOGGER.error("IOException caught.");
                    LOGGER.error(ex.getLocalizedMessage());
                } catch (NullPointerException ex)
                {
                    LOGGER.error("Null Pointer Exception: " + ex.getLocalizedMessage());
                } catch (Exception ex)
                {
                    LOGGER.error("Exception caught: " + ex.getLocalizedMessage());
                }
                LOGGER.info("Grading: " + selectedStudent.getLastName() + ", "
                        + selectedStudent.getFirstName());
                try
                {
                    LOGGER.debug("Grading Directory: " + directory.getCanonicalPath());
                    launcher.directory(directory);
                    StudentReport studentReport = new StudentReport(selectedStudent,
                            selectedSection);
                    Runnable r = new GraderThread(node, launcher, directory, gevent,
                            studentReport, type);
                    grader_thread = new Thread(r);
                    grader_thread.start();

                    statusMessageLabel.setText("");
                    while (grader_thread.isAlive())
                    {
                    }

                    sectionReport = new SectionReport(course.getName(), selectedInstructor,
                            selectedSection.getName(), gevent.getAssignment());
                    sectionReport.addStudentReport(studentReport);
                } catch (IOException ex)
                {
                    LOGGER.error("IO Exception: " + ex.getLocalizedMessage());
                }
                RageLib.printSectionReport(outputFile, sectionReport);
            }

            statusMessageLabel.setText("Grading complete");
            JOptionPane.showMessageDialog(null, "Grading complete.",
                    "Information", JOptionPane.INFORMATION_MESSAGE);
            LOGGER.info("Grading Complete");

            // Release the EntityManager objects.
            gradedEventDAO.closeConnection();
            courseDAO.closeConnection();
        }
        btnGrade.setEnabled(true);
        gradeAssignmentsMenuItem.setEnabled(true);
        btnCancel.setEnabled(false);

View Full Code Here

            Section section = null;
            int counter = 0;
            File rootDir;
            File[] files;

            CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
           
            Course selectedCourse = (Course) cboCourse.getSelectedItem();
            //course = em.find(Course.class, selectedCourse.getId());
            course = courseDAO.find(selectedCourse.getId());
            //query = em.createQuery("SELECT c FROM Course c WHERE c.name = :name");
            //query.setParameter("name", cboCourse.getSelectedItem().toString().trim());
            //course = (Course)query.getSingleResult();

//            query = em.createQuery("SELECT g FROM GradedEvent g WHERE g.course = " +
View Full Code Here

            }

            LOGGER.debug("(connectAction) Getting list of courses");
            try
            {
                CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());
                List<Course> courseList = courseDAO.getAllCoursesByName();
                if (courseList.size() > 0)
                {
                    LOGGER.debug("(connectAction) Found " + courseList.size()
                            + " courses");
                    for (int i = 0; i < courseList.size(); i++)
                    {
                        courseComboBoxModel.add(courseList.get(i));
                        LOGGER.debug("(connectAction) - Added "
                                + courseList.get(i).getName());
                    }
                } else
                {
                    JOptionPane.showMessageDialog(CourseGraderApp.getApplication()
                            .getMainFrame(), "Error: No Courses Found.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    LOGGER.warn("(connectAction) No Courses found");
                }
                LOGGER.debug("(connectAction) Closing CourseDAO connection");
                courseDAO.closeConnection();
            } catch (IllegalStateException ex)
            {
                LOGGER.error("(connectAction) Error connecting to the database "
                        + "when trying to retrieve course listing");
            } catch (Exception ex)
View Full Code Here

                LOGGER.debug("-- Section: " + newCourse.getSection(i).getName()
                        + " (" + sectionStudentCount + " students)");
                courseStudentCount += sectionStudentCount;
            }
            LOGGER.debug("- # Students: " + courseStudentCount);
            CourseDAO courseDAO = new CourseDAO(emf.createEntityManager());

            LOGGER.debug("Saving Course to Database");
            Long newId = courseDAO.create(newCourse);
            LOGGER.info("Course Saved to Database: " + newId);

            if (courseDAO.isOpen())
            {
                LOGGER.debug("Closing EntityManager.");
                courseDAO.closeConnection();
            } else
            {
                LOGGER.debug("EntityManager previously closed");
            }

            /**
             * Update the Window to show the new Course.  Clear all other lists.
             */
            LOGGER.debug("Updating window with all courses in the DB");
            // Clear Course List Model
            clm.removeAll();
            // Clear Instructor List Model
            ilm.removeAll();
            // Clear Section List Model
            slm.removeAll();
            // Clear Student List Model
            studentListModel.removeAll();

            // Get a full list of courses from the Data Source
            List<Course> courses = courseDAO.getAllCoursesByName();
            LOGGER.debug("# Courses Found: " + courses.size());
            for (int i = 0; i < courses.size(); i++)
            {
                clm.add(courses.get(i));
            }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.libs.dataaccess.CourseDAO

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.