Search in sources :

Example 1 with LearningCommunityReservation

use of org.cpsolver.studentsct.reservation.LearningCommunityReservation in project cpsolver by UniTime.

the class StudentSectioningXMLLoader method loadReservation.

/**
 * Load reservation
 * @param reservationEl reservation element
 * @param offering parent offering
 * @param configTable config table (of the offering)
 * @param sectionTable section table (of the offering)
 * @return loaded reservation
 */
protected Reservation loadReservation(Element reservationEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
    Reservation r = null;
    if ("individual".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new IndividualReservation(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    } else if ("group".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new GroupReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, studentIds);
    } else if ("lc".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        long courseId = Long.parseLong(reservationEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new LearningCommunityReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), course, studentIds);
        }
    } else if ("curriculum".equals(reservationEl.attributeValue("type")) || "curriculum-override".equals(reservationEl.attributeValue("type"))) {
        List<String> acadAreas = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("area"); k.hasNext(); ) {
            Element areaEl = (Element) k.next();
            acadAreas.add(areaEl.attributeValue("code"));
        }
        if (acadAreas.isEmpty() && reservationEl.attributeValue("area") != null)
            acadAreas.add(reservationEl.attributeValue("area"));
        List<String> classifications = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("classification"); k.hasNext(); ) {
            Element clasfEl = (Element) k.next();
            classifications.add(clasfEl.attributeValue("code"));
        }
        List<String> majors = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            majors.add(majorEl.attributeValue("code"));
        }
        List<String> minors = new ArrayList<String>();
        for (Iterator<?> k = reservationEl.elementIterator("minor"); k.hasNext(); ) {
            Element minorEl = (Element) k.next();
            minors.add(minorEl.attributeValue("code"));
        }
        if ("curriculum".equals(reservationEl.attributeValue("type")))
            r = new CurriculumReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, acadAreas, classifications, majors, minors);
        else
            r = new CurriculumOverride(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, acadAreas, classifications, majors, minors);
        for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            for (Iterator<?> l = majorEl.elementIterator("concentration"); l.hasNext(); ) {
                Element concentrationEl = (Element) l.next();
                ((CurriculumReservation) r).addConcentration(majorEl.attributeValue("code"), concentrationEl.attributeValue("code"));
            }
        }
    } else if ("course".equals(reservationEl.attributeValue("type"))) {
        long courseId = Long.parseLong(reservationEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new CourseReservation(Long.valueOf(reservationEl.attributeValue("id")), course);
        }
    } else if ("dummy".equals(reservationEl.attributeValue("type"))) {
        r = new DummyReservation(offering);
    } else if ("override".equals(reservationEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new ReservationOverride(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
    }
    if (r == null) {
        sLogger.error("Unknown reservation type " + reservationEl.attributeValue("type"));
        return null;
    }
    r.setExpired("true".equals(reservationEl.attributeValue("expired", "false")));
    for (Iterator<?> k = reservationEl.elementIterator("config"); k.hasNext(); ) {
        Element configEl = (Element) k.next();
        r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
    }
    for (Iterator<?> k = reservationEl.elementIterator("section"); k.hasNext(); ) {
        Element sectionEl = (Element) k.next();
        r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))), false);
    }
    r.setPriority(Integer.parseInt(reservationEl.attributeValue("priority", String.valueOf(r.getPriority()))));
    r.setMustBeUsed("true".equals(reservationEl.attributeValue("mustBeUsed", r.mustBeUsed() ? "true" : "false")));
    r.setAllowOverlap("true".equals(reservationEl.attributeValue("allowOverlap", r.isAllowOverlap() ? "true" : "false")));
    r.setCanAssignOverLimit("true".equals(reservationEl.attributeValue("canAssignOverLimit", r.canAssignOverLimit() ? "true" : "false")));
    r.setAllowDisabled("true".equals(reservationEl.attributeValue("allowDisabled", r.isAllowDisabled() ? "true" : "false")));
    r.setNeverIncluded("true".equals(reservationEl.attributeValue("neverIncluded", "false")));
    r.setBreakLinkedSections("true".equals(reservationEl.attributeValue("breakLinkedSections", "false")));
    return r;
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Set(java.util.Set) HashSet(java.util.HashSet) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Element(org.dom4j.Element) CurriculumOverride(org.cpsolver.studentsct.reservation.CurriculumOverride) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) LearningCommunityReservation(org.cpsolver.studentsct.reservation.LearningCommunityReservation) Reservation(org.cpsolver.studentsct.reservation.Reservation) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) LearningCommunityReservation(org.cpsolver.studentsct.reservation.LearningCommunityReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet)

Example 2 with LearningCommunityReservation

use of org.cpsolver.studentsct.reservation.LearningCommunityReservation in project cpsolver by UniTime.

the class StudentSectioningXMLSaver method saveReservation.

/**
 * Save reservation
 * @param reservationEl reservation element to be populated
 * @param reservation reservation to be saved
 */
protected void saveReservation(Element reservationEl, Reservation reservation) {
    reservationEl.addAttribute("id", getId("reservation", reservation.getId()));
    reservationEl.addAttribute("expired", reservation.isExpired() ? "true" : "false");
    if (reservation instanceof LearningCommunityReservation) {
        LearningCommunityReservation lc = (LearningCommunityReservation) reservation;
        reservationEl.addAttribute("type", "lc");
        for (Long studentId : lc.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
        if (lc.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(lc.getReservationLimit()));
        reservationEl.addAttribute("course", getId("course", lc.getCourse().getId()));
    } else if (reservation instanceof GroupReservation) {
        GroupReservation gr = (GroupReservation) reservation;
        reservationEl.addAttribute("type", "group");
        for (Long studentId : gr.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
        if (gr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(gr.getReservationLimit()));
    } else if (reservation instanceof ReservationOverride) {
        reservationEl.addAttribute("type", "override");
        ReservationOverride o = (ReservationOverride) reservation;
        for (Long studentId : o.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof IndividualReservation) {
        reservationEl.addAttribute("type", "individual");
        for (Long studentId : ((IndividualReservation) reservation).getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (reservation instanceof CurriculumReservation) {
        reservationEl.addAttribute("type", (reservation instanceof CurriculumOverride ? "curriculum-override" : "curriculum"));
        CurriculumReservation cr = (CurriculumReservation) reservation;
        if (cr.getReservationLimit() >= 0.0)
            reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
        if (cr.getAcademicAreas().size() == 1)
            reservationEl.addAttribute("area", cr.getAcademicAreas().iterator().next());
        else {
            for (String area : cr.getAcademicAreas()) reservationEl.addElement("area").addAttribute("code", area);
        }
        for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
        for (String major : cr.getMajors()) {
            Element majorEl = reservationEl.addElement("major").addAttribute("code", major);
            Set<String> concentrations = cr.getConcentrations(major);
            if (concentrations != null)
                for (String conc : concentrations) majorEl.addElement("concentration").addAttribute("code", conc);
        }
        for (String minor : cr.getMinors()) reservationEl.addElement("minor").addAttribute("code", minor);
    } else if (reservation instanceof CourseReservation) {
        reservationEl.addAttribute("type", "course");
        CourseReservation cr = (CourseReservation) reservation;
        reservationEl.addAttribute("course", getId("course", cr.getCourse().getId()));
    } else if (reservation instanceof DummyReservation) {
        reservationEl.addAttribute("type", "dummy");
    }
    reservationEl.addAttribute("priority", String.valueOf(reservation.getPriority()));
    reservationEl.addAttribute("mustBeUsed", reservation.mustBeUsed() ? "true" : "false");
    reservationEl.addAttribute("allowOverlap", reservation.isAllowOverlap() ? "true" : "false");
    reservationEl.addAttribute("canAssignOverLimit", reservation.canAssignOverLimit() ? "true" : "false");
    reservationEl.addAttribute("allowDisabled", reservation.isAllowDisabled() ? "true" : "false");
    if (reservation.neverIncluded())
        reservationEl.addAttribute("neverIncluded", "true");
    if (reservation.canBreakLinkedSections())
        reservationEl.addAttribute("breakLinkedSections", "true");
    for (Config config : reservation.getConfigs()) reservationEl.addElement("config").addAttribute("id", getId("config", config.getId()));
    for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
        for (Section section : entry.getValue()) {
            reservationEl.addElement("section").addAttribute("id", getId("section", section.getId()));
        }
    }
}
Also used : GroupReservation(org.cpsolver.studentsct.reservation.GroupReservation) CourseReservation(org.cpsolver.studentsct.reservation.CourseReservation) Set(java.util.Set) TreeSet(java.util.TreeSet) BitSet(java.util.BitSet) IndividualReservation(org.cpsolver.studentsct.reservation.IndividualReservation) Config(org.cpsolver.studentsct.model.Config) Element(org.dom4j.Element) CurriculumOverride(org.cpsolver.studentsct.reservation.CurriculumOverride) Section(org.cpsolver.studentsct.model.Section) DummyReservation(org.cpsolver.studentsct.reservation.DummyReservation) LearningCommunityReservation(org.cpsolver.studentsct.reservation.LearningCommunityReservation) CurriculumReservation(org.cpsolver.studentsct.reservation.CurriculumReservation) Subpart(org.cpsolver.studentsct.model.Subpart) ReservationOverride(org.cpsolver.studentsct.reservation.ReservationOverride) Map(java.util.Map)

Aggregations

BitSet (java.util.BitSet)2 Set (java.util.Set)2 CourseReservation (org.cpsolver.studentsct.reservation.CourseReservation)2 CurriculumOverride (org.cpsolver.studentsct.reservation.CurriculumOverride)2 CurriculumReservation (org.cpsolver.studentsct.reservation.CurriculumReservation)2 DummyReservation (org.cpsolver.studentsct.reservation.DummyReservation)2 GroupReservation (org.cpsolver.studentsct.reservation.GroupReservation)2 IndividualReservation (org.cpsolver.studentsct.reservation.IndividualReservation)2 LearningCommunityReservation (org.cpsolver.studentsct.reservation.LearningCommunityReservation)2 ReservationOverride (org.cpsolver.studentsct.reservation.ReservationOverride)2 Element (org.dom4j.Element)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Config (org.cpsolver.studentsct.model.Config)1 Course (org.cpsolver.studentsct.model.Course)1 Section (org.cpsolver.studentsct.model.Section)1