Search in sources :

Example 1 with IndividualRestriction

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

the class StudentSectioningXMLLoader method loadRestriction.

/**
 * Load restriction
 * @param restrictionEl restriction element
 * @param offering parent offering
 * @param configTable config table (of the offering)
 * @param sectionTable section table (of the offering)
 * @return loaded restriction
 */
protected Restriction loadRestriction(Element restrictionEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
    Restriction r = null;
    if ("individual".equals(restrictionEl.attributeValue("type"))) {
        Set<Long> studentIds = new HashSet<Long>();
        for (Iterator<?> k = restrictionEl.elementIterator("student"); k.hasNext(); ) {
            Element studentEl = (Element) k.next();
            studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
        }
        r = new IndividualRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, studentIds);
    } else if ("curriculum".equals(restrictionEl.attributeValue("type"))) {
        List<String> acadAreas = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("area"); k.hasNext(); ) {
            Element areaEl = (Element) k.next();
            acadAreas.add(areaEl.attributeValue("code"));
        }
        if (acadAreas.isEmpty() && restrictionEl.attributeValue("area") != null)
            acadAreas.add(restrictionEl.attributeValue("area"));
        List<String> classifications = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("classification"); k.hasNext(); ) {
            Element clasfEl = (Element) k.next();
            classifications.add(clasfEl.attributeValue("code"));
        }
        List<String> majors = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            majors.add(majorEl.attributeValue("code"));
        }
        List<String> minors = new ArrayList<String>();
        for (Iterator<?> k = restrictionEl.elementIterator("minor"); k.hasNext(); ) {
            Element minorEl = (Element) k.next();
            minors.add(minorEl.attributeValue("code"));
        }
        r = new CurriculumRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, acadAreas, classifications, majors, minors);
        for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
            Element majorEl = (Element) k.next();
            for (Iterator<?> l = majorEl.elementIterator("concentration"); l.hasNext(); ) {
                Element concentrationEl = (Element) l.next();
                ((CurriculumRestriction) r).addConcentration(majorEl.attributeValue("code"), concentrationEl.attributeValue("code"));
            }
        }
    } else if ("course".equals(restrictionEl.attributeValue("type"))) {
        long courseId = Long.parseLong(restrictionEl.attributeValue("course"));
        for (Course course : offering.getCourses()) {
            if (course.getId() == courseId)
                r = new CourseRestriction(Long.valueOf(restrictionEl.attributeValue("id")), course);
        }
    }
    if (r == null) {
        sLogger.error("Unknown reservation type " + restrictionEl.attributeValue("type"));
        return null;
    }
    for (Iterator<?> k = restrictionEl.elementIterator("config"); k.hasNext(); ) {
        Element configEl = (Element) k.next();
        r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
    }
    for (Iterator<?> k = restrictionEl.elementIterator("section"); k.hasNext(); ) {
        Element sectionEl = (Element) k.next();
        r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))));
    }
    return r;
}
Also used : IndividualRestriction(org.cpsolver.studentsct.reservation.IndividualRestriction) Element(org.dom4j.Element) CurriculumRestriction(org.cpsolver.studentsct.reservation.CurriculumRestriction) Restriction(org.cpsolver.studentsct.reservation.Restriction) IndividualRestriction(org.cpsolver.studentsct.reservation.IndividualRestriction) CourseRestriction(org.cpsolver.studentsct.reservation.CourseRestriction) CurriculumRestriction(org.cpsolver.studentsct.reservation.CurriculumRestriction) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Course(org.cpsolver.studentsct.model.Course) CourseRestriction(org.cpsolver.studentsct.reservation.CourseRestriction) HashSet(java.util.HashSet)

Example 2 with IndividualRestriction

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

the class StudentSectioningXMLSaver method saveRestriction.

/**
 * Save restriction
 * @param restrictionEl restriction element to be populated
 * @param restriction restriction to be saved
 */
protected void saveRestriction(Element restrictionEl, Restriction restriction) {
    restrictionEl.addAttribute("id", getId("restriction", restriction.getId()));
    if (restriction instanceof IndividualRestriction) {
        restrictionEl.addAttribute("type", "individual");
        for (Long studentId : ((IndividualRestriction) restriction).getStudentIds()) restrictionEl.addElement("student").addAttribute("id", getId("student", studentId));
    } else if (restriction instanceof CurriculumRestriction) {
        restrictionEl.addAttribute("type", "curriculum");
        CurriculumRestriction cr = (CurriculumRestriction) restriction;
        if (cr.getAcademicAreas().size() == 1)
            restrictionEl.addAttribute("area", cr.getAcademicAreas().iterator().next());
        else {
            for (String area : cr.getAcademicAreas()) restrictionEl.addElement("area").addAttribute("code", area);
        }
        for (String clasf : cr.getClassifications()) restrictionEl.addElement("classification").addAttribute("code", clasf);
        for (String major : cr.getMajors()) {
            Element majorEl = restrictionEl.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()) restrictionEl.addElement("minor").addAttribute("code", minor);
    } else if (restriction instanceof CourseRestriction) {
        restrictionEl.addAttribute("type", "course");
        CourseRestriction cr = (CourseRestriction) restriction;
        restrictionEl.addAttribute("course", getId("course", cr.getCourse().getId()));
    }
    for (Config config : restriction.getConfigs()) restrictionEl.addElement("config").addAttribute("id", getId("config", config.getId()));
    for (Map.Entry<Subpart, Set<Section>> entry : restriction.getSections().entrySet()) {
        for (Section section : entry.getValue()) {
            restrictionEl.addElement("section").addAttribute("id", getId("section", section.getId()));
        }
    }
}
Also used : IndividualRestriction(org.cpsolver.studentsct.reservation.IndividualRestriction) Set(java.util.Set) TreeSet(java.util.TreeSet) BitSet(java.util.BitSet) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) CurriculumRestriction(org.cpsolver.studentsct.reservation.CurriculumRestriction) Element(org.dom4j.Element) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section) CourseRestriction(org.cpsolver.studentsct.reservation.CourseRestriction)

Aggregations

CourseRestriction (org.cpsolver.studentsct.reservation.CourseRestriction)2 CurriculumRestriction (org.cpsolver.studentsct.reservation.CurriculumRestriction)2 IndividualRestriction (org.cpsolver.studentsct.reservation.IndividualRestriction)2 Element (org.dom4j.Element)2 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)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 Subpart (org.cpsolver.studentsct.model.Subpart)1 Restriction (org.cpsolver.studentsct.reservation.Restriction)1