Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.Instructor


                                            }
                                            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);
                                            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
                                            {
                                                em.persist(s);
                                            }
                                            else
                                            {
                                                s.setId(res.getId());
                                            }
                                            tx.commit();
                                        }
                                    }
                                    try
                                    {
                                        ins.setSections(sections);
                                    }
                                    catch (IllegalArgumentException e)
                                    {
                                        System.out.println("ERROR Setting Sections.  Size of Section list: " + sections.size());
                                    }
                                    tx.begin();
                                    query = em.createQuery("select p FROM Person p WHERE p.webID = :webid");
                                    query.setParameter("webid", ins.getWebID());
                                    Instructor res;
                                    try
                                    {
                                        res = (Instructor)query.getSingleResult();
                                    }
                                    catch (NoResultException ex)
                                    {
                                        // Instructor not found in DB
                                        res = null;
                                    }
                                    if (res == null)   // The instructor is not in the database
                                    {
                                        em.persist(ins);
                                    }
                                    else
                                    {
                                        ins.setId(res.getId());
                                    }
                                    tx.commit();
                                }
                            }
                            try
View Full Code Here


        Section section2 = new Section("M2B");
        section2.setId(new Long(2L));
        section1.setCourse(course);
        section2.setCourse(course);
       
        Instructor instructor1 = createPersistedInstructor(5L, "David", "Roberts",
                "David.Roberts");
        Instructor instructor2 = createPersistedInstructor(6L, "Sarah", "O'Reilly",
                "Sarah.OReilly");

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

        Student student4 = createPersistedStudent(4L, "Andrew", "Callow",
                "C13Andrew.Callow", new Integer(2013));
        Student student5 = createPersistedStudent(9L, "Kerry", "Beevers",
                "C11Kerry.Beevers", new Integer(2011));

        Instructor instructor1 = createPersistedInstructor(5L, "David", "Roberts",
                "David.Roberts");

        Section section1 = new Section("T5A");
        section1.setId(new Long(3L));
        Section section2 = new Section("T6A");
View Full Code Here

    private Instructor createPersistedInstructor(Long id, String firstName,
            String lastName, String webId) throws IllegalArgumentException
    {
        EntityManager em = emf.createEntityManager();
        Instructor instructor = null;

        try
        {
            instructor = findInstructorByWebId(webId);
            LOGGER.warn("Instructor already exists: " + instructor.getWebID());
        } catch (NoResultException ex)
        {
            instructor = new Instructor(firstName, lastName, webId);
            instructor.setId(id);
            instructor.setDomainAccount(webId);
            EntityTransaction tx = em.getTransaction();
            tx.begin();
            em.persist(instructor);
            tx.commit();
            LOGGER.debug("Instructor Id (post-persist): " + instructor.getId());
        }
        em.close();
        return instructor;
    }
View Full Code Here

    {
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        Section dbSection = em.find(Section.class, section.getId());
        Course dbCourse = em.find(Course.class, section.getCourse().getId());
        Instructor dbInstructor = em.find(Instructor.class, instructor.getId());
        dbSection.setInstructor(dbInstructor);
        dbInstructor.addSection(dbSection);
        if (dbCourse.getInstructors().contains(dbInstructor))
        {
            LOGGER.warn("Instructor already in the course");
        } else
        {
View Full Code Here

        // Update the Name and Course Director fields
        System.out.println("Updated Course: ");
        original.setName("CS192P");
        System.out.println("- Setting Course Director");
        Instructor courseDirector = new Instructor("David", "Roberts", "David.Roberts");
        courseDirector.setDomainAccount(courseDirector.getWebID());
        courseDirector.setId(new Long(5L));
        System.out.println("  -- CD: " + courseDirector.getDomainAccount());
        original.setCourseDirector(courseDirector);

        Course result = instance.update(original);

        // Verify the result
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", result.getName());
        assertNotNull(result.getCourseDirector());
        assertEquals(courseDirector, result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(2, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
View Full Code Here

        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(2, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
View Full Code Here

    public void testUpdateNewCourseDirector()
    {
        System.out.println("update - New Instructor as Course Director");
        Course course = createExistingCourse();
        course.setName("CS192P");
        Instructor courseDirector = new Instructor("James", "Kirk", "James.Kirk");
        courseDirector.setId(50L);
        courseDirector.setDomainAccount(courseDirector.getWebID());
        course.setCourseDirector(courseDirector);

        Course result = instance.update(course);
        // Verify the result
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS192P", result.getName());
        assertNotNull(result.getCourseDirector());
        assertEquals(courseDirector, result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(2, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
View Full Code Here

    public void testUpdateRemoveInstructor()
    {
        System.out.println("update - Instructor Removed");
        Course course = createExistingCourse();
        assertEquals(2, course.getInstructors().size());
        Instructor oldIns = new Instructor("Sarah", "O'Reilly", "Sarah.OReilly");
        oldIns.setId(new Long(6L));
        oldIns.setDomainAccount(oldIns.getWebID());
        course.removeInstructor(oldIns);
       
        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(1, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
View Full Code Here

    {
        System.out.println("update - New Instructor added");
        Course course = createExistingCourse();
        assertEquals(2, course.getInstructors().size());
       
        Instructor newIns = new Instructor("John", "Smith", "John.Smith");
        newIns.setId(new Long(42L));
        newIns.setDomainAccount(newIns.getWebID());
        course.addInstructor(newIns);

        assertTrue(instance.isOpen());
        Course result = instance.update(course);
        assertEquals(new Long(1L), result.getId());
        assertEquals("CS110", result.getName());
        assertNull(result.getCourseDirector());
        assertNotNull(result.getInstructors());
        assertEquals(3, result.getInstructors().size());
        Instructor ins1 = result.getInstructor(0);
        assertEquals("David.Roberts", ins1.getDomainAccount());
        Instructor ins2 = result.getInstructor(1);
        assertEquals("Sarah.OReilly", ins2.getDomainAccount());
        Instructor ins3 = result.getInstructor(2);
        assertEquals("John.Smith", ins3.getDomainAccount());
        assertNotNull(result.getSections());
        assertEquals(2, result.getSections().size());
        for (int i = 0; i < result.getSections().size(); i++)
        {
            Section section = result.getSection(i);
View Full Code Here

TOP

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

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.