Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Course


                {
                    // Search DB and set current course to one matched in DB
                    // Work from there instead
                    query = em.createQuery("select c from Course c where c.name = :cname");
                    query.setParameter("cname", course.getName());
                    Course c;
                    try
                    {
                        c = (Course)query.getSingleResult();
                    }
                    catch (NoResultException ex)
                    {
                        // No course in database, proceed normally since it's a new course
                        c = course;
                    }

                    // Cascade search for the course details: Instructors, Sections,
                    // and Students
                    //
                    // Since GradedEvent is listed before instructor, we need to
                    // pull one of the graded events and put it into the path so
                    // we can accurately pull the list of Instructors in the course.
                    // Since the Assignments will be loaded separately, we're not
                    // interested in them here.
                    String rootDir = txtRootDir.getText() + File.separator + c.getName();
                   
                    String assignDir = RageLib.getSingleAssignmentDirFromPath(rootDir);
                   
                    String courseDir = rootDir + File.separator + assignDir;
                   
                    if (assignDir != null// There are assignments in this directory
                    {
                        // TODO: RAGE-92
                        Set<Instructor> instructors = RageLib.getInstructorsFromPath(courseDir);
                        if (instructors != null)
                        {
                            for (Instructor ins : instructors)
                            {
                                String instructorDir = courseDir + File.separator + ins.getWebID();
                                // TODO: RAGE-91 fix
                                List<Section> sections = RageLib.getSectionsFromPath(instructorDir);
                                if (sections != null)
                                {
                                    for (Section s : sections)
                                    {
                                        String sectionDir = instructorDir + File.separator + s.getName();
                                        // TODO: RAGE-93
                                        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());
                                            Instructor insRes;
                                            try
                                            {
                                                insRes = (Instructor)query.getSingleResult();
                                            }
                                            catch (NoResultException ex)
                                            {
                                                // Instructor not found in DB
                                                insRes = null;
                                            }
                                            if (insRes == null)   // The instructor is not in the database
                                            {
                                                em.persist(ins);
                                            }
                                            else
                                            {
                                                ins.setId(insRes.getId());
                                            }

                                            query = em.createQuery("select c FROM Course c WHERE name = :name");
                                            query.setParameter("name", c.getName());
                                            Course crsRes;
                                            try
                                            {
                                                crsRes = (Course)query.getSingleResult();
                                            }
                                            catch (NoResultException ex)
                                            {
                                                // Instructor not found in DB
                                                crsRes = null;
                                            }
                                            if (crsRes == null)   // The instructor is not in the database
                                            {
                                                em.persist(c);
                                            }
                                            else
                                            {
                                                c.setId(crsRes.getId());
                                            }

                                            //s.setStudents(students);
                                            s.setInstructor(ins);
                                            s.setCourse(c);
View Full Code Here


     */
    @Ignore
    @Before
    public void setUp()
    {
        Course course = createTestCourse();
        in = new PipedInputStream();
        out = new PipedOutputStream();
        readStream = new PipedInputStream();
        writeStream = new PipedOutputStream();

View Full Code Here

     * Utility method to create the same course for testing.
     * @return      The created Course;
     */
    protected Course createTestCourse()
    {
        Course course = new Course("CS110");
        // Create 2 Sections, 2 Students per Section, and 2 Instructors
        Student student1 = new Student("John", "Doe", "C13John.Doe",
                new Integer(2013));
        Student student2 = new Student("Mary", "Johnson", "C13Mary.Johnson",
                new Integer(2013));
        Student student3 = new Student("Bob", "Reimer", "C13Robert.Reimer",
                new Integer(2013));
        Student student4 = new Student("Andrew", "Callow", "C13Andrew.Callow",
                new Integer(2013));
        Section section1 = new Section("M1A");
        Section section2 = new Section("M2B");
        Instructor instructor1 = new Instructor("David", "Roberts", "David.Roberts");
        instructor1.setDomainAccount(instructor1.getWebID());
        Instructor instructor2 = new Instructor("Sarah", "O'Reilly", "Sarah.OReilly");
        instructor2.setDomainAccount(instructor2.getWebID());

        // Set the Instructors for Sections 1 & 2
        section1.setInstructor(instructor1);
        section2.setInstructor(instructor2);

        // Add Instructors to Course
        course.addInstructor(instructor1);
        course.addInstructor(instructor2);

        // Add Students 1 & 2 to Section 1
        section1.addStudent(student1);
        student1.addSection(section1);
        section1.addStudent(student2);
        student2.addSection(section1);

        // Add Students 3 & 4 to Section 2
        section2.addStudent(student3);
        student3.addSection(section2);
        section2.addStudent(student4);
        student4.addSection(section2);

        // Add Sections 1 & 2 to Course
        section1.setCourse(course);
        section2.setCourse(course);
        course.addSection(section1);
        course.addSection(section2);

        return course;
    }
View Full Code Here

    public void testClearCourseClosedConnection()
    {
        System.out.println("clearCourse - Closed Connection");
        assertTrue(instance.isOpen());
        instance.closeConnection();
        Course course = new Course("CS110");
        course.setId(new Long(1L));
        assertTrue(instance.clearCourse(course));
    }
View Full Code Here

    @Test(expected = NullPointerException.class)
    public void testClearCourseNullCourse()
    {
        System.out.println("clearCourse  - null Course");
        assertTrue(instance.isOpen());
        Course course = null;
        assertFalse(instance.clearCourse(course));
    }
View Full Code Here

    @Test(expected = IllegalArgumentException.class)
    public void testClearCourseNullCourseId()
    {
        System.out.println("clearCourse - null Course Id");
        assertTrue(instance.isOpen());
        Course course = new Course();
        assertFalse(instance.clearCourse(course));
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testClearCourseZeroCourseId()
    {
        System.out.println("clearCourse - Course Id = 0");
        assertTrue(instance.isOpen());
        Course course = new Course();
        course.setId(new Long(0L));
        assertFalse(instance.clearCourse(course));
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testClearCourseNegativeCourseId()
    {
        System.out.println("clearCourse - Course Id < 0");
        assertTrue(instance.isOpen());
        Course course = new Course();
        course.setId(new Long(-5L));
        assertFalse(instance.clearCourse(course));
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testClearCourseNonExistentCourse()
    {
        System.out.println("clearCourse - Non-existent Course");
        assertTrue(instance.isOpen());
        Course course = new Course("CS192");
        course.setId(new Long(15L));
        assertFalse(instance.clearCourse(course));
    }
View Full Code Here

    public void testFindId()
    {
        System.out.println("find - by Id");
        assertTrue(instance.isOpen());
        Long id = new Long(2L);
        Course dbCourse = instance.find(id);
        assertNotNull(dbCourse);
        assertEquals("CS364", dbCourse.getName());
        assertEquals(id, dbCourse.getId());
        assertEquals(1, dbCourse.getInstructors().size());
        assertEquals(2, dbCourse.getSections().size());
    }
View Full Code Here

TOP

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

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.