Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Section


        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section("T1A");
        section.setCourse(course);
        section.setId(5L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        Long newId = instance.create(section);

        Long expectedId = new Long(5L);
        assertEquals(expectedId, newId);

        section = instance.find(5L);
        assertNotNull(section);
        assertEquals("T1A", section.getName());
        assertNotNull(section.getCourse());
        assertEquals("CS364", section.getCourse().getName());
    }
View Full Code Here


    @Test(expected=NullPointerException.class)
    public void testCreateNullSection()
    {
        System.out.println("createNullSection");
        Section section = null;
       
        assertTrue(instance.isOpen());
        Long newId = instance.create(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("David", "Roberts",
                "David.Roberts");
        instructor.setId(5L);
        instructor.setDomainAccount("David.Roberts");

        Section section = new Section("T5A");
        section.setCourse(course);
        section.setId(3L);
        section.setInstructor(instructor);

        assertTrue(instance.isOpen());
        Long newId = instance.create(section);
    }
View Full Code Here

        Instructor instructor = new Instructor("Sarah", "O'Reilly",
                "Sarah.OReilly");
        instructor.setId(6L);
        instructor.setDomainAccount("Sarah.OReilly");

        Section section = new Section("T1A");
        //System.out.println("- Setting Course");
        section.setId(5L);
        section.setInstructor(instructor);

        System.out.println("- Saving to Database");
        assertTrue(instance.isOpen());
        Long newId = instance.create(section);
    }
View Full Code Here

        Course course = new Course("CS364");
        course.setId(2L);

        Instructor instructor = null;

        Section section = new Section("T1A");
        section.setCourse(course);
        section.setId(5L);
        //System.out.println("- Setting Instructor");
        //section.setInstructor(instructor);

        System.out.println("- Saving to Database");
        assertTrue(instance.isOpen());
View Full Code Here

                    throw new IllegalStateException("Instructors not added to DB "
                            + "properly");
                }

                LOGGER.debug("(create) Determining if Section is already in DB");
                Section dbSection = null;
                CriteriaQuery<Section> cqSection = cb.createQuery(Section.class);
                Root<Section> sectionRoot = cqSection.from(Section.class);
                cqSection.where(cb.and(cb.equal(sectionRoot.get("course"), dbCourse)),
                        cb.equal(sectionRoot.get("name"), section.getName()));
                TypedQuery<Section> sectionQuery =
                        entityManager.createQuery(cqSection);
                try
                {
                    dbSection = sectionQuery.getSingleResult();
                    LOGGER.debug("(create) Section found.  ID: " + dbSection.getId());
                } catch (NoResultException ex)
                {
                    LOGGER.debug("(create) Section " + section.getName()
                            + " doesn't exist in the database.  Adding.");
                    dbSection = new Section(dbCourse, section.getName(), dbInstructor);
                    if (section.getId() != null)
                    {
                        dbSection.setId(section.getId());
                    }
                    tx.begin();
                    entityManager.persist(dbSection);
                    dbCourse = entityManager.merge(dbCourse);
                    dbInstructor = entityManager.merge(dbInstructor);
                    tx.commit();
                    LOGGER.debug("(create) Section added.  ID: " + dbSection.getId());
                }

                /**
                 * All sections for this course were removed previously, so we don't
                 * need to query the database for potential merged sections.  We
                 * do need to look for potential existing students and update the
                 * students accordingly.
                 */
                LOGGER.debug("(create) Looping through " + section.getStudents().size()
                        + " students");
                for (Student student : section.getStudents())
                {
                    LOGGER.debug("(create) Querying for Student: " + student.getWebID()
                            + ", " + student.getFirstName() + ", "
                            + student.getLastName() + " (" + student.getClassYear()
                            + ")");
                    Student dbStudent = null;
                    CriteriaQuery<Student> cqStudent = cb.createQuery(Student.class);
                    Root<Student> studentRoot = cqStudent.from(Student.class);
                    cqStudent.where(cb.and(
                            cb.equal(studentRoot.get("webID"), student.getWebID()),
                            cb.equal(studentRoot.get("firstName"),
                            student.getFirstName()),
                            cb.equal(studentRoot.get("lastName"),
                            student.getLastName()),
                            cb.equal(studentRoot.get("classYear"),
                            student.getClassYear())));
                    TypedQuery<Student> studentQuery =
                            entityManager.createQuery(cqStudent);

                    try
                    {
                        dbStudent = studentQuery.getSingleResult();
                        LOGGER.debug("(create) Student " + dbStudent.getLastName()
                                + ", " + dbStudent.getFirstName() + " ("
                                + dbStudent.getClassYear() + ") does exist in DB.  "
                                + "Adding to Section " + dbSection);
                        LOGGER.debug("(create) Student ID: " + dbStudent.getId());
                    } // Student in Database
                    catch (NoResultException ex)
                    {
                        LOGGER.debug("(create) Student " + student.getLastName()
                                + ", " + student.getFirstName() + " ("
                                + student.getClassYear() + ") doesn't exist in DB.  "
                                + "Adding to Section " + dbSection);
                        dbStudent = new Student(student.getFirstName(),
                                student.getLastName(), student.getWebID(),
                                student.getClassYear());
                        if (student.getId() != null)
                        {
                            dbStudent.setId(student.getId());
                        }
                        tx.begin();
                        entityManager.persist(dbStudent);
                        tx.commit();
                        LOGGER.debug("(create) Student ID: " + dbStudent.getId());
                    } // Student not in Database
                    dbSection.addStudent(dbStudent);
                    tx.begin();
                    dbSection = entityManager.merge(dbSection);
                    tx.commit();
                // Loop through Students
                dbCourse.addSection(dbSection);
                tx.begin();
                dbCourse = entityManager.merge(dbCourse);
                //entityManager.persist(dbSection);
                //dbSection = entityManager.merge(dbSection);
                tx.commit();
                LOGGER.debug("(create) Course ID (Added Section " + dbSection
                        + "): " + dbCourse.getId() + "; Section Course ID: "
                        + dbSection.getCourse().getId());
            // Loop through Course Sections

            LOGGER.debug("- Instructors: " + dbCourse.getInstructors().size());
            LOGGER.debug("- Sections: " + dbCourse.getSections().size());

View Full Code Here

            for (int i = course.getSections().size() - 1;
                    i
                    >= 0; i--)
            {
                LOGGER.debug("- Iteration " + i);
                Section section = course.getSection(i);
                LOGGER.debug("- Section: " + section + ", Id = " + section.getId());
                Section dbSection = entityManager.find(Section.class, section.getId());
                if (dbSection == null)
                {
                    LOGGER.error("(clearCourse) Section not found in data source");
                    throw new IllegalStateException("Section not found in data source");
                }
                LOGGER.debug("(clearCourse) Section " + dbSection + " found in the DB");
                LOGGER.debug("(clearCourse) Section ID: " + dbSection.getId());
                LOGGER.debug("(clearCourse) # Students in Section (Pre): "
                        + dbSection.getStudents().size());

                dbSection.clearStudents();
                tx.begin();
                dbSection = entityManager.merge(dbSection);
                entityManager.flush();
                tx.commit();
                LOGGER.debug("(clearCourse) # Students in Section (Post): "
                        + dbSection.getStudents().size());

                // Find the Instructor for the Section in the Database
                Instructor dbInstructor = entityManager.find(Instructor.class,
                        dbSection.getInstructor().getId());
                if (dbInstructor == null)
                {
                    LOGGER.error("(clearCourse) Section " + dbSection
                            + " Instructor not found in DB");
                    throw new IllegalStateException("Section Instructor not "
                            + "found in DB");
                // Instructor not found in Database

                LOGGER.debug("(clearCourse) Removing Instructor from Section "
                        + dbSection + ": " + dbSection.getInstructor().getDomainAccount());
                dbSection.removeInstructor();

                dbCourse.removeSection(dbSection);
                dbSection.removeCourse();

                try
                {
                    tx.begin();
                    LOGGER.debug("(clearCourse) Merging Instructor with Database");
View Full Code Here

                LOGGER.debug("- # of Sections in new Course: "
                        + course.getSections().size());
                for (int i = 0; i < course.getSections().size(); i++)
                {
                    LOGGER.debug("- Looping through Sections.  Instance " + i);
                    Section section = null;
                    if (course.getSection(i).getId() != null)
                    {
                        LOGGER.debug("- Section has id = "
                                + course.getSection(i).getId());
                        section = entityManager.find(Section.class,
                                course.getSection(i).getId());
                    }
                    /**
                     * Don't need to look up Section by name since matching names
                     * can happen.  The Id is critical.
                     */
                    if (section != null)
                    {
                        LOGGER.debug("- Adding existing section: "
                                + section);
                        section.setName(course.getSection(i).getName());
                        dbCourse.addSection(section);
                    } else
                    {
                        LOGGER.debug("- Adding non-existent section: "
                                + course.getSection(i));
View Full Code Here

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

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

TOP

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

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.