Package com.darkhonor.rage.libs.dataaccess

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


                                        Set<Student> students = RageLib.getStudentsFromPath(sectionDir, node.getInt("ClassOffset", 2000));
                                        if (students != null)
                                        {
                                            for (Student stu : students)
                                            {
                                                SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
                                                // TODO: Need to add query for name...but Sections are not equal by name...RAGE-94
                                                query = em.createQuery("select s FROM Section s WHERE s.name = :name");
                                                query.setParameter("name", s.getName());
                                                Section res;
                                                try
                                                {
                                                    res = (Section)query.getSingleResult();
                                                }
                                                catch (NoResultException ex)
                                                {
                                                    // Section not found in DB
                                                    res = null;
                                                }
                                                if (res == null)   // The section is not in the database
                                                {
                                                    tx.begin();
                                                    em.persist(s);
                                                    tx.commit();
                                                    //stu.setSection(s);
                                                }
                                                else
                                                {
                                                    tx.begin();
                                                    em.persist(res);
                                                    tx.commit();
                                                    //stu.setSection(res);
                                                }
                                                // TODO: RAGE-34 - Migrate to StudentDAO
                                                query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
                                                query.setParameter("webid", stu.getWebID());
                                                Student stuRes;
                                                try
                                                {
                                                    stuRes = (Student)query.getSingleResult();
                                                }
                                                catch (NoResultException ex)
                                                {
                                                    // Student not found in DB
                                                    stuRes = null;
                                                }
                                                if (stuRes == null)   // The student is not in the database
                                                {
                                                    tx.begin();
                                                    em.persist(stu);
                                                    tx.commit();
                                                }
                                                sectionDAO.closeConnection();
                                            }
                                            tx.begin();
                                            // TODO: RAGE-71 - Migrate to InstructorDAO
                                            query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
                                            query.setParameter("webid", ins.getWebID());
View Full Code Here


        Instructor selectedInstructor = (Instructor) cboInstructor.getSelectedItem();

        LOGGER.debug("Getting selected Course");
        Course selectedCourse = (Course) cboCourse.getSelectedItem();
        LOGGER.debug("Creating Section query");
        SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
        List<Section> result =
                sectionDAO.getSectionsForCourseAndInstructor(selectedCourse, selectedInstructor);
        if (result == null || result.size() == 0)
        {
            LOGGER.error("No Sections Found");
        } else
        {
            LOGGER.debug("Adding Sections to ComboBox");
            try
            {
                sectionComboBoxModel.add(new Section(selectedCourse, "000 - All Sections",
                        selectedInstructor));
                LOGGER.debug("Added All Sections option");
                int count = 0;
                for (Section section : result)
                {
                    sectionComboBoxModel.add(section);
                    count++;
                }
                LOGGER.debug(count + " Sections added");
            } catch (Exception ex)
            {
                LOGGER.error("Exception Caught: " + ex.getLocalizedMessage());
            } finally
            {
                sectionDAO.closeConnection();
            }
            cboStudent.setSelectedIndex(-1)// Blank out the student name as well
            cboStudent.setEnabled(false);
            cboSection.setSelectedIndex(-1);
            cboSection.setEnabled(true);
View Full Code Here

private void cboSectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboSectionActionPerformed
    if (cboSectActive)
    {
        LOGGER.debug("In cboSectionActionPerformed");
        studentComboBoxModel.removeAll();
        SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
        LOGGER.debug("Getting selected Section");
        Section selectedSection = (Section) cboSection.getSelectedItem();
        try
        {
            /**
             * Instead of just grabbing the Set of students in the section, we will
             * query the database for the list.  This is done in order to provide
             * and Ordered list to the user.  If the structure of Section is ever
             * changed to support an ordered collection, this query can be dropped.
             */
            LOGGER.debug("Finding list of students (ordered) in section "
                    + selectedSection.getName());
            Section section = sectionDAO.find(selectedSection.getId());
            LOGGER.debug("Found " + section.getStudents().size() + " Students");
            LOGGER.debug("Adding list of Students in Section "
                    + section.getName() + " to ComboBox");
            studentComboBoxModel.add(new Student(" ", "000 - All Students", "All.Students",
                    new Integer(2010)));
            int count = 0;
            for (int i = 0; i < section.getStudents().size(); i++)
            {
                studentComboBoxModel.add(section.getStudent(i));
                count++;
            }
            studentComboBoxModel.sort();
            LOGGER.debug(count + " students added to ComboBox");
            cboStudent.setSelectedIndex(0);
            cboStudent.setEnabled(true);
            btnGrade.setEnabled(true);
        } catch (IllegalStateException ex)
        {
            LOGGER.error("The EntityManager has been closed already. "
                    + ex.getLocalizedMessage());
        } catch (IllegalArgumentException ex)
        {
            LOGGER.error("Illegal Argument to command.  " + ex.getLocalizedMessage());
        } finally
        {
            sectionDAO.closeConnection();
        }
        LOGGER.debug("Finished with cboSectionActionPerformed");
        gradeAssignmentsMenuItem.setEnabled(true);
    }
}//GEN-LAST:event_cboSectionActionPerformed
View Full Code Here

                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
            {
View Full Code Here

                path = path.concat(instructor.getWebID());

                // Add the section if one is selected
                if (cboSection.getSelectedIndex() > 0)
                {
                    SectionDAO sectionDAO = new SectionDAO(emf.createEntityManager());
                    section = sectionDAO.find(selectedSection.getId());
                    //section = em.find(Section.class, selectedSection.getId());
                    //for (Section s : instructor.getSections())
                    //{
                    //    if (s.getName().equals(cboSection.getSelectedItem()))
                    //    {
                    //        sect = s;
                    //    }
                    //}
                    path = path.concat(File.separator);
                    path = path.concat(section.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());
                    }
                    sectionDAO.closeConnection();
                }
                instructorDAO.closeConnection();
            }
            // Figure out what is selected based on the path info above
            if ((cboInstructor.getSelectedIndex() == 0) && (cboSection.getSelectedIndex() < 0))
View Full Code Here

TOP

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

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.