Example usage for org.hibernate Session refresh

List of usage examples for org.hibernate Session refresh

Introduction

In this page you can find the example usage for org.hibernate Session refresh.

Prototype

void refresh(Object object);

Source Link

Document

Re-read the state of the given instance from the underlying database.

Usage

From source file:org.unitime.timetable.action.DistributionPrefsAction.java

License:Open Source License

/**
 * Delete distribution pref/*from  w ww . j av  a2s .co  m*/
 * @param distPrefId
 */
private void doDelete(HttpServletRequest request, String distPrefId) {
    /*
    String query = "delete DistributionPref dp where dp.uniqueId=:distPrefId";
            
    Query q = hibSession.createQuery(query);
    q.setLong("distPrefId", Long.parseLong(distPrefId));
    q.executeUpdate();
    */

    Transaction tx = null;

    try {

        DistributionPrefDAO dpDao = new DistributionPrefDAO();
        org.hibernate.Session hibSession = dpDao.getSession();
        tx = hibSession.getTransaction();
        if (tx == null || !tx.isActive())
            tx = hibSession.beginTransaction();

        HashSet relatedInstructionalOfferings = new HashSet();
        DistributionPref dp = dpDao.get(new Long(distPrefId));

        sessionContext.checkPermission(dp, Right.DistributionPreferenceDelete);

        Department dept = (Department) dp.getOwner();
        dept.getPreferences().remove(dp);
        for (Iterator i = dp.getDistributionObjects().iterator(); i.hasNext();) {
            DistributionObject dObj = (DistributionObject) i.next();
            PreferenceGroup pg = dObj.getPrefGroup();
            relatedInstructionalOfferings
                    .add((pg instanceof Class_ ? ((Class_) pg).getSchedulingSubpart() : (SchedulingSubpart) pg)
                            .getInstrOfferingConfig().getInstructionalOffering());
            pg.getDistributionObjects().remove(dObj);
            hibSession.saveOrUpdate(pg);
        }

        hibSession.delete(dp);
        hibSession.saveOrUpdate(dept);

        for (Iterator i = relatedInstructionalOfferings.iterator(); i.hasNext();) {
            InstructionalOffering io = (InstructionalOffering) i.next();
            ChangeLog.addChange(hibSession, sessionContext, io, ChangeLog.Source.DIST_PREF_EDIT,
                    ChangeLog.Operation.DELETE, io.getControllingCourseOffering().getSubjectArea(), null);
        }

        if (tx != null && tx.isActive())
            tx.commit();

        hibSession.flush();
        hibSession.refresh(dept);
    } catch (Exception e) {
        Debug.error(e);
        if (tx != null && tx.isActive())
            tx.rollback();
    }
}

From source file:org.unitime.timetable.action.EditRoomFeatureAction.java

License:Open Source License

/**
 * /*from   w  w  w. j  a v a  2  s  . com*/
 * @param editRoomFeatureForm
 * @param request
 * @throws Exception
 */
private void doUpdate(EditRoomFeatureForm editRoomFeatureForm, HttpServletRequest request) throws Exception {

    org.hibernate.Session hibSession = LocationDAO.getInstance().getSession();

    Transaction tx = null;
    try {
        tx = hibSession.beginTransaction();

        Location location = LocationDAO.getInstance().get(Long.valueOf(request.getParameter("id")), hibSession);

        sessionContext.checkPermission(location, Right.RoomEditFeatures);

        boolean editGlobalFeatures = sessionContext.hasPermission(location, Right.RoomEditGlobalFeatures);

        if (editGlobalFeatures && editRoomFeatureForm.getGlobalRoomFeaturesAssigned() != null) {
            List globalSelected = editRoomFeatureForm.getGlobalRoomFeaturesAssigned();
            List globalRf = editRoomFeatureForm.getGlobalRoomFeatureIds();
            if (globalSelected.size() == 0) {
                for (Iterator iter = globalRf.iterator(); iter.hasNext();) {
                    String rfId = (String) iter.next();
                    RoomFeature rf = RoomFeatureDAO.getInstance().get(Long.valueOf(rfId), hibSession);
                    location.getFeatures().remove(rf);
                    rf.getRooms().remove(location);
                    hibSession.saveOrUpdate(rf);
                }
            } else {
                int i = 0;
                for (Iterator iter = globalRf.iterator(); iter.hasNext();) {
                    String rfId = (String) iter.next();
                    String selected = (String) globalSelected.get(i);
                    RoomFeature rf = RoomFeatureDAO.getInstance().get(Long.valueOf(rfId), hibSession);
                    if (selected == null)
                        continue;

                    if (selected.equalsIgnoreCase("on") || selected.equalsIgnoreCase("true")) {
                        if (!rf.hasLocation(location)) {
                            location.getFeatures().add(rf);
                            rf.getRooms().add(location);
                        }
                    } else {
                        if (rf.hasLocation(location)) {
                            location.getFeatures().remove(rf);
                            rf.getRooms().remove(location);
                        }
                    }
                    hibSession.saveOrUpdate(rf);
                    i++;
                }
            }
        }

        Set<Department> departments = Department.getUserDepartments(sessionContext.getUser());
        if (!departments.isEmpty() && editRoomFeatureForm.getDepartmentRoomFeaturesAssigned() != null) {

            List managerSelected = editRoomFeatureForm.getDepartmentRoomFeaturesAssigned();
            List managerRf = editRoomFeatureForm.getDepartmentRoomFeatureIds();

            if (managerSelected.size() == 0) {
                for (Iterator iter = managerRf.iterator(); iter.hasNext();) {
                    String rfId = (String) iter.next();
                    DepartmentRoomFeature rf = DepartmentRoomFeatureDAO.getInstance().get(Long.valueOf(rfId),
                            hibSession);
                    if (!departments.contains(rf.getDepartment()))
                        continue;
                    rf.getRooms().remove(location);
                    hibSession.saveOrUpdate(rf);
                }
            } else {
                int i = 0;
                for (Iterator iter = managerRf.iterator(); iter.hasNext();) {
                    String rfId = (String) iter.next();
                    String selected = (String) managerSelected.get(i);
                    if (selected == null)
                        continue;

                    DepartmentRoomFeature rf = DepartmentRoomFeatureDAO.getInstance().get(Long.valueOf(rfId),
                            hibSession);
                    if (!departments.contains(rf.getDepartment()))
                        continue;

                    if (selected.equalsIgnoreCase("on") || selected.equalsIgnoreCase("true")) {
                        if (!rf.hasLocation(location)) {
                            rf.getRooms().add(location);
                            location.getFeatures().add(rf);
                        }
                    } else {
                        if (rf.hasLocation(location)) {
                            rf.getRooms().remove(location);
                            location.getFeatures().remove(rf);
                        }
                    }
                    hibSession.saveOrUpdate(rf);
                    i++;
                }
            }
        }

        hibSession.saveOrUpdate(location);

        ChangeLog.addChange(hibSession, sessionContext, location, ChangeLog.Source.ROOM_FEATURE_EDIT,
                ChangeLog.Operation.UPDATE, null, location.getControllingDepartment());

        tx.commit();
        hibSession.refresh(location);

    } catch (Exception e) {
        Debug.error(e);
        try {
            if (tx != null && tx.isActive())
                tx.rollback();
        } catch (Exception e1) {
        }
        throw e;
    }
}

From source file:org.unitime.timetable.action.EditRoomGroupAction.java

License:Open Source License

/**
 * /*ww w  . ja va 2 s  .com*/
 * @param editRoomGroupForm
 * @param request
 * @throws Exception
 */
private void doUpdate(EditRoomGroupForm editRoomGroupForm, HttpServletRequest request) throws Exception {

    org.hibernate.Session hibSession = LocationDAO.getInstance().getSession();

    Transaction tx = null;
    try {
        tx = hibSession.beginTransaction();

        Location location = LocationDAO.getInstance().get(Long.valueOf(request.getParameter("id")), hibSession);

        sessionContext.checkPermission(location, Right.RoomEditGroups);

        boolean editGlobalGroups = sessionContext.hasPermission(location, Right.RoomEditGlobalGroups);
        if (editGlobalGroups && editRoomGroupForm.getGlobalRoomGroupsAssigned() != null) {
            List globalSelected = editRoomGroupForm.getGlobalRoomGroupsAssigned();
            List globalRg = editRoomGroupForm.getGlobalRoomGroupIds();
            if (globalSelected.size() == 0) {
                for (Iterator iter = globalRg.iterator(); iter.hasNext();) {
                    String rgId = (String) iter.next();
                    RoomGroup rg = RoomGroupDAO.getInstance().get(Long.valueOf(rgId), hibSession);
                    rg.getRooms().remove(location);
                    location.getRoomGroups().remove(rg);
                    hibSession.saveOrUpdate(rg);
                }
            } else {
                int i = 0;
                for (Iterator iter = globalRg.iterator(); iter.hasNext();) {
                    String rgId = (String) iter.next();
                    String selected = (String) globalSelected.get(i);
                    RoomGroup rg = RoomGroupDAO.getInstance().get(Long.valueOf(rgId), hibSession);
                    if (selected == null)
                        continue;

                    if (selected.equalsIgnoreCase("on") || selected.equalsIgnoreCase("true")) {
                        if (!rg.hasLocation(location)) {
                            rg.getRooms().add(location);
                            location.getRoomGroups().add(rg);
                        }
                    } else {
                        if (rg.hasLocation(location)) {
                            rg.getRooms().remove(location);
                            location.getRoomGroups().remove(rg);
                        }
                    }
                    hibSession.saveOrUpdate(rg);
                    i++;
                }
            }
        }

        Set<Department> departments = Department.getUserDepartments(sessionContext.getUser());
        if (!departments.isEmpty() && editRoomGroupForm.getManagerRoomGroupsAssigned() != null) {
            List managerSelected = editRoomGroupForm.getManagerRoomGroupsAssigned();
            List managerRg = editRoomGroupForm.getManagerRoomGroupIds();

            if (managerSelected.size() == 0) {
                for (Iterator iter = managerRg.iterator(); iter.hasNext();) {
                    String rgId = (String) iter.next();
                    RoomGroup rg = RoomGroupDAO.getInstance().get(Long.valueOf(rgId), hibSession);
                    if (rg.getDepartment() == null || !departments.contains(rg.getDepartment()))
                        continue;
                    rg.getRooms().remove(location);
                    hibSession.saveOrUpdate(rg);
                }
            } else {
                int i = 0;
                for (Iterator iter = managerRg.iterator(); iter.hasNext();) {
                    String rgId = (String) iter.next();
                    String selected = (String) managerSelected.get(i);
                    if (selected == null)
                        continue;

                    RoomGroup rg = RoomGroupDAO.getInstance().get(Long.valueOf(rgId), hibSession);
                    if (rg.getDepartment() == null || !departments.contains(rg.getDepartment()))
                        continue;

                    if (selected.equalsIgnoreCase("on") || selected.equalsIgnoreCase("true")) {
                        if (!rg.hasLocation(location)) {
                            rg.getRooms().add(location);
                            location.getRoomGroups().add(rg);
                        }
                    } else {
                        if (rg.hasLocation(location)) {
                            rg.getRooms().remove(location);
                            location.getRoomGroups().remove(rg);
                        }
                    }
                    hibSession.saveOrUpdate(rg);
                    i++;
                }
            }
        }

        hibSession.saveOrUpdate(location);

        ChangeLog.addChange(hibSession, sessionContext, location, ChangeLog.Source.ROOM_GROUP_EDIT,
                ChangeLog.Operation.UPDATE, null, location.getControllingDepartment());

        tx.commit();
        hibSession.refresh(location);

    } catch (Exception e) {
        Debug.error(e);
        try {
            if (tx != null && tx.isActive())
                tx.rollback();
        } catch (Exception e1) {
        }
        throw e;
    }
}

From source file:org.unitime.timetable.action.ExamDistributionPrefsAction.java

License:Open Source License

/**
 * Add new distribution pref//  w  w  w  .  ja va  2s  .c om
 * @param httpSession
 * @param frm
 */
private void doAddOrUpdate(HttpServletRequest request, ExamDistributionPrefsForm frm) throws Exception {

    String distPrefId = frm.getDistPrefId();

    if (distPrefId != null && !distPrefId.isEmpty()) {
        sessionContext.checkPermission(distPrefId, "DistributionPref",
                Right.ExaminationDistributionPreferenceEdit);
    } else {
        sessionContext.checkPermission(Right.ExaminationDistributionPreferenceAdd);
    }

    // Create distribution preference
    DistributionPref dp = null;
    DistributionPrefDAO dpDao = new DistributionPrefDAO();
    Transaction tx = null;
    org.hibernate.Session hibSession = dpDao.getSession();
    HashSet relatedExams = new HashSet();

    try {
        tx = hibSession.beginTransaction();

        if (distPrefId != null && !distPrefId.isEmpty()) {
            dp = dpDao.get(Long.valueOf(distPrefId), hibSession);
            Set s = dp.getDistributionObjects();
            for (Iterator i = s.iterator(); i.hasNext();) {
                DistributionObject dObj = (DistributionObject) i.next();
                PreferenceGroup pg = dObj.getPrefGroup();
                relatedExams.add(pg);
                pg.getDistributionObjects().remove(dObj);
                hibSession.saveOrUpdate(pg);
            }
            s.clear();
            dp.setDistributionObjects(s);
        } else
            dp = new DistributionPref();

        dp.setDistributionType(new DistributionTypeDAO().get(new Long(frm.getDistType()), hibSession));
        dp.setGrouping(-1);
        dp.setPrefLevel(PreferenceLevel.getPreferenceLevel(Integer.parseInt(frm.getPrefLevel())));

        dp.setOwner(SessionDAO.getInstance().get(sessionContext.getUser().getCurrentAcademicSessionId()));

        HashSet addedExams = new HashSet();
        int idx = 0;
        for (Iterator i = frm.getExam().iterator(); i.hasNext();) {
            Long examId = (Long) i.next();
            if (examId < 0)
                continue;

            Exam exam = new ExamDAO().get(examId, hibSession);
            if (exam == null)
                continue;
            if (!addedExams.add(exam))
                continue;
            relatedExams.add(exam);

            DistributionObject dObj = new DistributionObject();
            dObj.setPrefGroup(exam);
            dObj.setDistributionPref(dp);
            dObj.setSequenceNumber(new Integer(++idx));
            exam.getDistributionObjects().add(dObj);
            dp.addTodistributionObjects(dObj);
        }

        // Save
        hibSession.saveOrUpdate(dp);

        for (Iterator i = relatedExams.iterator(); i.hasNext();) {
            Exam exam = (Exam) i.next();
            ChangeLog
                    .addChange(hibSession, sessionContext, exam, ChangeLog.Source.DIST_PREF_EDIT,
                            (distPrefId != null && distPrefId.trim().length() > 0 ? ChangeLog.Operation.UPDATE
                                    : ChangeLog.Operation.CREATE),
                            exam.firstSubjectArea(), exam.firstDepartment());
        }

        tx.commit();
        hibSession.flush();
        hibSession.refresh(dp.getOwner());
        frm.setDistPrefId(dp.getUniqueId().toString());
    } catch (Exception e) {
        if (tx != null)
            tx.rollback();
        hibSession.clear();
        throw e;
    }
}

From source file:org.unitime.timetable.action.ExamDistributionPrefsAction.java

License:Open Source License

/**
 * Delete distribution pref/*w w  w  .ja  v  a2 s .  c  o m*/
 * @param distPrefId
 */
private void doDelete(HttpServletRequest request, String distPrefId) {
    Transaction tx = null;

    sessionContext.checkPermission(distPrefId, "DistributionPref",
            Right.ExaminationDistributionPreferenceDelete);

    try {

        DistributionPrefDAO dpDao = new DistributionPrefDAO();
        org.hibernate.Session hibSession = dpDao.getSession();
        tx = hibSession.getTransaction();
        if (tx == null || !tx.isActive())
            tx = hibSession.beginTransaction();

        HashSet relatedExams = new HashSet();
        DistributionPref dp = dpDao.get(new Long(distPrefId));
        PreferenceGroup owner = (PreferenceGroup) dp.getOwner();
        owner.getPreferences().remove(dp);
        for (Iterator i = dp.getDistributionObjects().iterator(); i.hasNext();) {
            DistributionObject dObj = (DistributionObject) i.next();
            PreferenceGroup pg = dObj.getPrefGroup();
            relatedExams.add(pg);
            pg.getDistributionObjects().remove(dObj);
            hibSession.saveOrUpdate(pg);
        }

        hibSession.delete(dp);
        hibSession.saveOrUpdate(owner);

        for (Iterator i = relatedExams.iterator(); i.hasNext();) {
            Exam exam = (Exam) i.next();
            ChangeLog.addChange(hibSession, sessionContext, exam, ChangeLog.Source.DIST_PREF_EDIT,
                    ChangeLog.Operation.DELETE, exam.firstSubjectArea(), exam.firstDepartment());
        }

        if (tx != null && tx.isActive())
            tx.commit();

        hibSession.flush();
        hibSession.refresh(owner);
    } catch (Exception e) {
        Debug.error(e);
        if (tx != null && tx.isActive())
            tx.rollback();
    }
}

From source file:org.unitime.timetable.action.InstructionalOfferingConfigEditAction.java

License:Open Source License

/**
 * Deletes configuration//from w  w  w  . j  a va  2  s . c om
 * and associated prefs
 * @param request
 * @param frm
 * @throws Exception
 */
private void deleteConfig(HttpServletRequest request, InstructionalOfferingConfigEditForm frm)
        throws Exception {

    org.hibernate.Session hibSession = null;
    Transaction tx = null;

    try {

        InstrOfferingConfigDAO iocDao = new InstrOfferingConfigDAO();
        hibSession = iocDao.getSession();
        tx = hibSession.beginTransaction();

        Long configId = frm.getConfigId();
        InstrOfferingConfig ioc = iocDao.get(configId);
        InstructionalOffering io = ioc.getInstructionalOffering();

        deleteSubpart(request, hibSession, ioc, new HashMap());
        io.removeConfiguration(ioc);

        io.computeLabels(hibSession);
        if (!ioc.isUnlimitedEnrollment().booleanValue())
            io.setLimit(new Integer(io.getLimit().intValue() - ioc.getLimit().intValue()));

        ChangeLog.addChange(hibSession, sessionContext, io, io.getCourseName() + " [" + ioc.getName() + "]",
                ChangeLog.Source.INSTR_CFG_EDIT, ChangeLog.Operation.DELETE,
                io.getControllingCourseOffering().getSubjectArea(), null);

        Event.deleteFromEvents(hibSession, ioc);
        Exam.deleteFromExams(hibSession, ioc);
        // The following line was calling delete ioc for the second time (which is a problem for MySQL as
        // it returns zero number of deleted lines even when called in the same transaction).
        //hibSession.delete(ioc);
        hibSession.saveOrUpdate(io);

        hibSession.flush();
        tx.commit();

        hibSession.refresh(io);

        String className = ApplicationProperty.ExternalActionInstrOffrConfigChange.value();
        if (className != null && className.trim().length() > 0) {
            ExternalInstrOffrConfigChangeAction configChangeAction = (ExternalInstrOffrConfigChangeAction) (Class
                    .forName(className).newInstance());
            configChangeAction.performExternalInstrOffrConfigChangeAction(io, hibSession);
        }

    } catch (Exception e) {
        try {
            if (tx != null && tx.isActive())
                tx.rollback();
        } catch (Exception e1) {
        }

        Debug.error(e);
        throw (e);
    }
}

From source file:org.unitime.timetable.action.InstructionalOfferingConfigEditAction.java

License:Open Source License

/**
 * Update configuration without destroying existing subparts/classes
 * and associated prefs//w  w w .ja v  a  2s  .c  o m
 * @param request
 * @param frm
 * @throws Exception
 */
private void updateConfig(HttpServletRequest request, InstructionalOfferingConfigEditForm frm)
        throws Exception {

    // Read user defined config
    Vector sp = (Vector) sessionContext.getAttribute(SimpleItypeConfig.CONFIGS_ATTR_NAME);

    // No subparts
    if (sp == null || sp.size() == 0)
        return;

    RoomGroup rg = RoomGroup.getGlobalDefaultRoomGroup(sessionContext.getUser().getCurrentAcademicSessionId());

    InstrOfferingConfig ioc = null;
    InstructionalOffering io = null;

    org.hibernate.Session hibSession = null;
    Transaction tx = null;

    try {

        InstructionalOfferingDAO ioDao = new InstructionalOfferingDAO();
        InstrOfferingConfigDAO iocDao = new InstrOfferingConfigDAO();
        hibSession = iocDao.getSession();
        tx = hibSession.beginTransaction();

        io = ioDao.get(new Long(frm.getInstrOfferingId()));
        Long configId = frm.getConfigId();
        Boolean unlimitedEnroll = (frm.getUnlimited() == null) ? new Boolean(false) : frm.getUnlimited();
        int limit = (unlimitedEnroll.booleanValue()) ? 0 : frm.getLimit();

        if (configId == null || configId.intValue() == 0) {
            ioc = new InstrOfferingConfig();
            ioc.setLimit(new Integer(limit));
            ioc.setName(frm.getName());
            ioc.setUnlimitedEnrollment(unlimitedEnroll);
            ioc.setInstructionalOffering(io);
            io.addToinstrOfferingConfigs(ioc);

            hibSession.saveOrUpdate(ioc);
            hibSession.saveOrUpdate(io);
        } else {
            ioc = iocDao.get(configId);
            ioc.setLimit(new Integer(limit));
            ioc.setName(frm.getName());
            ioc.setUnlimitedEnrollment(unlimitedEnroll);
        }

        HashMap notDeletedSubparts = new HashMap();

        // Update subparts in the modified config
        for (int i = 0; i < sp.size(); i++) {
            SimpleItypeConfig sic = (SimpleItypeConfig) sp.elementAt(i);
            createOrUpdateSubpart(request, hibSession, sic, ioc, null, rg, notDeletedSubparts);
            createOrUpdateClasses(request, hibSession, sic, ioc, null);
        }

        // Update Parents
        Set s = ioc.getSchedulingSubparts();
        for (Iterator i = s.iterator(); i.hasNext();) {
            SchedulingSubpart subp = (SchedulingSubpart) i.next();
            if (subp.getParentSubpart() == null) {
                Debug.debug("Setting parents for " + subp.getItypeDesc());
                updateParentClasses(subp, null, hibSession, notDeletedSubparts);
            }
        }

        // Remove any subparts that do not exist in the modified config
        deleteSubpart(request, hibSession, ioc, notDeletedSubparts);

        hibSession.saveOrUpdate(ioc);
        hibSession.saveOrUpdate(io);

        io.computeLabels(hibSession);

        ChangeLog.addChange(hibSession, sessionContext, ioc, ChangeLog.Source.INSTR_CFG_EDIT,
                (configId == null || configId.intValue() == 0 ? ChangeLog.Operation.CREATE
                        : ChangeLog.Operation.UPDATE),
                ioc.getInstructionalOffering().getControllingCourseOffering().getSubjectArea(), null);

        hibSession.flush();

        tx.commit();
        hibSession.refresh(ioc);
        hibSession.refresh(io);

        String className = ApplicationProperty.ExternalActionInstrOffrConfigChange.value();
        if (className != null && className.trim().length() > 0) {
            ExternalInstrOffrConfigChangeAction configChangeAction = (ExternalInstrOffrConfigChangeAction) (Class
                    .forName(className).newInstance());
            configChangeAction.performExternalInstrOffrConfigChangeAction(io, hibSession);
        }
    } catch (Exception e) {
        try {
            if (tx != null && tx.isActive())
                tx.rollback();
        } catch (Exception e1) {
        }

        try {
            if (ioc != null)
                hibSession.refresh(ioc);
        } catch (Exception e2) {
        }

        try {
            if (io != null)
                hibSession.refresh(io);
        } catch (Exception e3) {
        }

        Debug.error(e);
        throw (e);
    }
}

From source file:org.unitime.timetable.action.InstructionalOfferingConfigEditAction.java

License:Open Source License

/**
 * Recursively process the updated config subparts
 * @param request/*from  w w w. j a v a 2 s.co  m*/
 * @param hibSession
 * @param sic
 * @param ioc
 * @param parent
 * @param mgr
 * @param notDeletedSubparts Holds all the subpart ids encountered while recursing
 * @throws Exception
 */
private void createOrUpdateSubpart(HttpServletRequest request, org.hibernate.Session hibSession,
        SimpleItypeConfig sic, InstrOfferingConfig ioc, SchedulingSubpart parent, RoomGroup rg,
        HashMap notDeletedSubparts) throws Exception {

    // Set attributes
    String subpartId = request.getParameter("subpartId" + sic.getId());
    String minLimitPerClass = request.getParameter("mnlpc" + sic.getId());
    String maxLimitPerClass = request.getParameter("mxlpc" + sic.getId());
    String minPerWk = request.getParameter("mpw" + sic.getId());
    String numClasses = request.getParameter("nc" + sic.getId());
    String numRooms = request.getParameter("nr" + sic.getId());
    String roomRatio = request.getParameter("rr" + sic.getId());
    String managingDept = request.getParameter("md" + sic.getId());
    String disabled = request.getParameter("disabled" + sic.getId());

    if (subpartId != null)
        sic.setSubpartId(Long.parseLong(subpartId));
    if (minLimitPerClass != null)
        sic.setMinLimitPerClass(Constants.getPositiveInteger(minLimitPerClass, 0));
    if (maxLimitPerClass != null)
        sic.setMaxLimitPerClass(Constants.getPositiveInteger(maxLimitPerClass, 0));
    if (minPerWk != null)
        sic.setMinPerWeek(Integer.parseInt(minPerWk));
    if (numClasses != null)
        sic.setNumClasses(Integer.parseInt(numClasses));
    if (numRooms != null)
        sic.setNumRooms(Constants.getPositiveInteger(numRooms, 0));
    if (roomRatio != null)
        sic.setRoomRatio(Constants.getPositiveFloat(roomRatio, 0.0f));
    if (managingDept != null)
        sic.setManagingDeptId(Long.parseLong(managingDept));
    if (disabled != null)
        sic.setDisabled(new Boolean(request.getParameter("disabled" + sic.getId())).booleanValue());

    // Read attributes
    long sid = sic.getSubpartId();
    int mnlpc = sic.getMinLimitPerClass();
    int mxlpc = sic.getMaxLimitPerClass();
    int mpw = sic.getMinPerWeek();
    int nr = sic.getNumRooms();
    float rr = sic.getRoomRatio();
    long md = sic.getManagingDeptId();
    boolean db = sic.isDisabled();

    if (ioc.isUnlimitedEnrollment().booleanValue()) {
        mnlpc = 0;
        mxlpc = 0;
        nr = 0;
        rr = 0;
    }

    if (request.getParameter("varLimits") == null) {
        mnlpc = mxlpc;
    }

    SchedulingSubpart subpart = null;

    // Subpart does not exist
    if (sid < 0) {
        Debug.debug("Subpart does not exist ... Creating subpart - " + sic.getItype().getDesc());

        // Create subpart
        subpart = new SchedulingSubpart();
        subpart.setInstrOfferingConfig(ioc);
        subpart.setItype(sic.getItype());
        subpart.setMinutesPerWk(new Integer(mpw));
        subpart.setParentSubpart(parent);
        subpart.setAutoSpreadInTime(ApplicationProperty.SchedulingSubpartAutoSpreadInTimeDefault.isTrue());
        subpart.setStudentAllowOverlap(ApplicationProperty.SchedulingSubpartStudentOverlapsDefault.isTrue());
        ioc.addToschedulingSubparts(subpart);

        if (md < 0 && !ioc.isUnlimitedEnrollment().booleanValue() && rg != null) {
            // Add default room group pref of classroom
            HashSet prefs = new HashSet();
            RoomGroupPref rgp = new RoomGroupPref();

            rgp.setPrefLevel(
                    PreferenceLevel.getPreferenceLevel(Integer.parseInt(PreferenceLevel.PREF_LEVEL_REQUIRED)));
            rgp.setRoomGroup(rg);
            rgp.setOwner(subpart);
            prefs.add(rgp);
            subpart.setPreferences(prefs);
        }

        hibSession.saveOrUpdate(subpart);
        hibSession.flush();

        hibSession.refresh(subpart);
        sid = subpart.getUniqueId().longValue();
        Debug.debug("New subpart uniqueid: " + sid);
        sic.setSubpartId(sid);
        notDeletedSubparts.put(new Long(sid), "");
    } // End If: Subpart does not exist

    // Subpart exists
    else {
        Debug.debug("Subpart exists ... Updating");

        notDeletedSubparts.put(new Long(sid), "");

        Set s = ioc.getSchedulingSubparts();
        for (Iterator i = s.iterator(); i.hasNext();) {
            SchedulingSubpart tmpSubpart = (SchedulingSubpart) i.next();
            if (tmpSubpart.getUniqueId().longValue() == sid) {
                subpart = tmpSubpart;
                break;
            }
        }

        if (subpart == null)
            throw new Exception("Scheduling Subpart " + sid + " was not found.");

        Debug.debug("Creating / Updating subpart - " + subpart.getItypeDesc());

        Set classes = subpart.getClasses();

        // Update only if user has permissions and does not have mixed managed classes
        //if (subpart.isEditableBy(Web.getUser(request.getSession())) && !subpart.hasMixedManagedClasses()) {
        if (!db) {

            // If minutes per week has changed then delete time pattern and time prefs
            if (subpart.getMinutesPerWk().intValue() != mpw) {
                Debug.debug("Minutes per week changed ... Deleting time prefs on subpart and classes");
                subpart.setMinutesPerWk(new Integer(mpw));
                Set prefs = subpart.getPreferences();
                for (Iterator i = prefs.iterator(); i.hasNext();) {
                    Preference pref = (Preference) i.next();
                    if (pref instanceof TimePref) {
                        pref.setOwner(null);
                        hibSession.delete(pref);
                        i.remove();
                    }
                }

                for (Iterator i = classes.iterator(); i.hasNext();) {
                    Class_ c = (Class_) i.next();
                    Set cPrefs = c.getPreferences();
                    for (Iterator j = cPrefs.iterator(); j.hasNext();) {
                        Preference pref = (Preference) j.next();
                        if (pref instanceof TimePref) {
                            pref.setOwner(null);
                            hibSession.delete(pref);
                            j.remove();
                        }
                    }
                    hibSession.saveOrUpdate(c);
                }
            }

            // Manager changed
            boolean managerChanged = false;
            long mdId = md;
            if (md < 0) {
                mdId = subpart.getInstrOfferingConfig().getControllingCourseOffering().getSubjectArea()
                        .getDepartment().getUniqueId().longValue();
            }

            if (subpart.getManagingDept().getUniqueId().longValue() != mdId) {
                Debug.debug("Subpart Managing department changed ...");
                managerChanged = true;

                // Remove from distribution prefs
                subpart.deleteAllDistributionPreferences(hibSession);

                // Clear all prefs - except time & distribution
                Set prefs = subpart.getPreferences();
                for (Iterator prefI = prefs.iterator(); prefI.hasNext();) {
                    Object a = prefI.next();

                    if (a instanceof RoomPref || a instanceof BuildingPref || a instanceof RoomGroupPref
                            || a instanceof RoomFeaturePref) {
                        prefI.remove();
                    }

                    //Weaken time preferences if the new manager is external
                    if (a instanceof TimePref) {
                        Department mgDept = new DepartmentDAO().get(new Long(mdId));
                        if (mgDept.isExternalManager().booleanValue()) {
                            //weaken only when both controling and managing departments do not allow required time
                            if (subpart.getControllingDept().isAllowReqTime() == null
                                    || !subpart.getControllingDept().isAllowReqTime().booleanValue()) {
                                if (mgDept.isAllowReqTime() == null
                                        || !mgDept.isAllowReqTime().booleanValue()) {
                                    ((TimePref) a).weakenHardPreferences();
                                }
                            }
                        }
                        /*
                        // Set all time prefs to neutral in order to preserve time pattern
                        TimePref tp = new TimePref();
                        tp.setTimePattern(((TimePref) a).getTimePattern());
                        String prefStr = tp.getTimePatternModel().getPreferences();
                        ((TimePref) a).setPreference(tp.getPreference());
                        */
                    }
                }

                // Check if changed to Department and is not unlimited enroll
                if (md < 0 && !ioc.isUnlimitedEnrollment().booleanValue() && rg != null) {
                    // Add default room group pref of classroom
                    RoomGroupPref rgp = new RoomGroupPref();
                    rgp.setPrefLevel(PreferenceLevel
                            .getPreferenceLevel(Integer.parseInt(PreferenceLevel.PREF_LEVEL_REQUIRED)));
                    rgp.setRoomGroup(rg);
                    rgp.setOwner(subpart);
                    prefs.add(rgp);
                }
            }

            // Update expected capacity and room capacity
            for (Iterator i = classes.iterator(); i.hasNext();) {
                Debug.debug("Updating expected capacity and room capacity on class ...");
                Class_ c = (Class_) i.next();
                c.setExpectedCapacity(new Integer(mnlpc));
                c.setMaxExpectedCapacity(new Integer(mxlpc));
                c.setRoomRatio(new Float(rr));
                c.setNbrRooms(new Integer(nr));
                if (c.getDisplayInstructor() == null) {
                    c.setDisplayInstructor(new Boolean(true));
                }
                if (c.getEnabledForStudentScheduling() == null) {
                    c.setEnabledForStudentScheduling(new Boolean(true));
                }

                if (managerChanged) {
                    if (c.getManagingDept().getUniqueId().longValue() != mdId) {
                        Debug.debug("Class Managing department changed ...");

                        // Update Managing Department
                        c.setManagingDept(new DepartmentDAO().get(new Long(mdId)));

                        // Remove from distribution prefs
                        c.deleteAllDistributionPreferences(hibSession);

                        // Clear all prefs - except time & distribution
                        Set prefs = c.getPreferences();
                        for (Iterator prefI = prefs.iterator(); prefI.hasNext();) {
                            Object a = prefI.next();

                            if (a instanceof RoomPref || a instanceof BuildingPref || a instanceof RoomGroupPref
                                    || a instanceof RoomFeaturePref) {
                                prefI.remove();
                            }

                            // Weaken time preferences if the new manager is external, remove exact times
                            if (a instanceof TimePref) {
                                if (((TimePref) a).getTimePattern().getType()
                                        .intValue() == TimePattern.sTypeExactTime) {
                                    prefI.remove();
                                } else {
                                    if (c.getManagingDept().isExternalManager().booleanValue()) {
                                        //weaken only when both controling and managing departments do not allow required time
                                        if (c.getControllingDept().isAllowReqTime() == null
                                                || !c.getControllingDept().isAllowReqTime().booleanValue()) {
                                            if (c.getManagingDept().isAllowReqTime() == null
                                                    || !c.getManagingDept().isAllowReqTime().booleanValue()) {
                                                ((TimePref) a).weakenHardPreferences();
                                            }
                                        }
                                    }
                                    /*
                                    // Set all time prefs to neutral in order to preserve time pattern
                                    TimePref tp = new TimePref();
                                    tp.setTimePattern(((TimePref) a).getTimePattern());
                                    String prefStr = tp.getTimePatternModel().getPreferences();
                                    ((TimePref) a).setPreference(prefStr);
                                    */
                                }
                            }
                        }
                    } else {
                        Debug.debug("Class Managing department same as subpart ... ignoring");
                    }
                }
                hibSession.saveOrUpdate(c);
            }
        } // End: Update only if user has permissions and does not have mixed managed classes

        // Update Parent
        if ((parent != null && subpart.getParentSubpart() != null && !subpart.getParentSubpart().equals(parent))
                || (parent == null && subpart.getParentSubpart() != null)
                || (parent != null && subpart.getParentSubpart() == null)) {

            Debug.debug("Updating parent subparts and classes ...");
            subpart.setParentSubpart(parent);

            // Update parent for classes
            if (parent == null) {
                Debug.debug("No parent subparts ... making top level class");
                for (Iterator cci = subpart.getClasses().iterator(); cci.hasNext();) {
                    Class_ childClass = (Class_) cci.next();
                    childClass.setParentClass(null);
                    hibSession.saveOrUpdate(childClass);
                }
            } else {
                Debug.debug("Parent subpart exists ... setting parent class");

                ArrayList classesList = new ArrayList(classes);
                Collections.sort(classesList, new ClassComparator(ClassComparator.COMPARE_BY_ID));

                Set parentClasses = parent.getClasses();
                int parentNumClasses = parentClasses.size();
                if (parentNumClasses > 0) {
                    Iterator cci = classesList.iterator();
                    int classPerParent = classesList.size() / parentNumClasses;
                    int classPerParentRem = classesList.size() % parentNumClasses;
                    Debug.debug("Setting " + classPerParent + " class(es) per parent");
                    Debug.debug("Odd number of classes found - " + classPerParentRem + " classes ... ");

                    for (Iterator i = parentClasses.iterator(); (i.hasNext() && classPerParent != 0);) {
                        Class_ parentClass = (Class_) i.next();
                        for (int j = 0; j < classPerParent; j++) {
                            Class_ childClass = (Class_) cci.next();
                            Debug.debug("Setting class " + childClass.getClassLabel() + " to parent "
                                    + parentClass.getClassLabel());
                            childClass.setParentClass(parentClass);
                            parentClass.addTochildClasses(childClass);
                            hibSession.saveOrUpdate(parentClass);
                            hibSession.saveOrUpdate(childClass);

                            if (classPerParentRem != 0) {
                                if (cci.hasNext()) {
                                    childClass = (Class_) cci.next();
                                    Debug.debug("Setting ODD class " + childClass.getClassLabel()
                                            + " to parent " + parentClass.getClassLabel());
                                    childClass.setParentClass(parentClass);
                                    parentClass.addTochildClasses(childClass);
                                    hibSession.saveOrUpdate(parentClass);
                                    hibSession.saveOrUpdate(childClass);
                                }

                                --classPerParentRem;
                            }
                        }
                    }

                    if (classPerParentRem != 0) {
                        Iterator cci2 = classesList.iterator();
                        for (Iterator i = parentClasses.iterator(); i.hasNext();) {
                            Class_ parentClass = (Class_) i.next();
                            if (cci2.hasNext()) {
                                Class_ childClass = (Class_) cci2.next();
                                Debug.debug("Setting ODD class " + childClass.getClassLabel() + " to parent "
                                        + parentClass.getClassLabel());
                                childClass.setParentClass(parentClass);
                                parentClass.addTochildClasses(childClass);
                                hibSession.saveOrUpdate(parentClass);
                                hibSession.saveOrUpdate(childClass);
                            }

                            --classPerParentRem;
                            if (classPerParentRem == 0)
                                break;
                        }
                    }

                    hibSession.saveOrUpdate(parent);
                }
            }
        } // End If: Update Parent

        hibSession.saveOrUpdate(subpart);
        hibSession.flush();
        hibSession.refresh(subpart);
        if (parent != null)
            hibSession.refresh(parent);

    } // End If: Subpart Exists

    // Loop through children sub-parts
    Vector v = sic.getSubparts();
    for (int i = 0; i < v.size(); i++) {
        SimpleItypeConfig sic1 = (SimpleItypeConfig) v.elementAt(i);
        createOrUpdateSubpart(request, hibSession, sic1, ioc, subpart, rg, notDeletedSubparts);
    }

    hibSession.saveOrUpdate(ioc);
    hibSession.flush();
}

From source file:org.unitime.timetable.action.InstructionalOfferingModifyAction.java

License:Open Source License

/**
 * Update the instructional offering config
 * @param request//from ww  w . j  av  a  2  s .  co  m
 * @param frm
 */
private void doUpdate(HttpServletRequest request, InstructionalOfferingModifyForm frm) throws Exception {

    // Get Instructional Offering Config
    InstrOfferingConfigDAO iocdao = new InstrOfferingConfigDAO();
    InstrOfferingConfig ioc = iocdao.get(frm.getInstrOffrConfigId());
    Session hibSession = iocdao.getSession();
    // Get default room group
    RoomGroup rg = RoomGroup.getGlobalDefaultRoomGroup(ioc.getSession());

    sessionContext.checkPermission(ioc, Right.MultipleClassSetup);

    Transaction tx = null;

    try {
        tx = hibSession.beginTransaction();

        // If the instructional offering config limit or unlimited flag has changed update it.
        if (frm.isInstrOffrConfigUnlimited() != ioc.isUnlimitedEnrollment()) {
            ioc.setUnlimitedEnrollment(frm.isInstrOffrConfigUnlimited());
            ioc.setLimit(frm.isInstrOffrConfigUnlimited() ? 0 : frm.getInstrOffrConfigLimit());
            hibSession.update(ioc);
        } else if (!frm.getInstrOffrConfigLimit().equals(ioc.getLimit())) {
            ioc.setLimit(frm.getInstrOffrConfigLimit());
            hibSession.update(ioc);
        }

        // Get map of subpart ownership so that after the classes have changed it is possible to see if the ownership for a subparts has changed
        HashMap origSubpartManagingDept = new HashMap();
        if (ioc.getSchedulingSubparts() != null) {
            SchedulingSubpart ss = null;
            for (Iterator it = ioc.getSchedulingSubparts().iterator(); it.hasNext();) {
                ss = (SchedulingSubpart) it.next();
                origSubpartManagingDept.put(ss.getUniqueId(), ss.getManagingDept());
            }
        }

        // For all added classes, create the classes and save them, get back a map of the temp ids to the new classes
        HashMap tmpClassIdsToClasses = addClasses(frm, ioc, hibSession);

        // For all changed classes, update them
        modifyClasses(frm, ioc, hibSession, rg, tmpClassIdsToClasses);

        // Update subpart ownership
        modifySubparts(ioc, origSubpartManagingDept, rg, hibSession);

        // Delete all classes in the original classes that are no longer in the modified classes
        deleteClasses(frm, ioc, hibSession, tmpClassIdsToClasses);

        ioc.getInstructionalOffering().computeLabels(hibSession);

        ChangeLog.addChange(hibSession, sessionContext, ioc, ChangeLog.Source.CLASS_SETUP,
                ChangeLog.Operation.UPDATE,
                ioc.getInstructionalOffering().getControllingCourseOffering().getSubjectArea(), null);

        tx.commit();
        hibSession.flush();
        hibSession.refresh(ioc);
        hibSession.refresh(ioc.getInstructionalOffering());
        String className = ApplicationProperty.ExternalActionInstrOffrConfigChange.value();
        if (className != null && className.trim().length() > 0) {
            ExternalInstrOffrConfigChangeAction configChangeAction = (ExternalInstrOffrConfigChangeAction) (Class
                    .forName(className).newInstance());
            configChangeAction.performExternalInstrOffrConfigChangeAction(ioc.getInstructionalOffering(),
                    hibSession);
        }

    } catch (Exception e) {
        Debug.error(e);
        try {
            if (tx != null && tx.isActive())
                tx.rollback();
        } catch (Exception e1) {
        }
        throw e;
    }
}

From source file:org.unitime.timetable.action.RoomDeptEditAction.java

License:Open Source License

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    RoomDeptEditForm myForm = (RoomDeptEditForm) form;

    Department d = null;//from  w ww .  ja  v a2  s .c o  m
    if (sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom) != null) {
        String deptCode = (String) sessionContext.getAttribute(SessionAttribute.DepartmentCodeRoom);
        if (deptCode != null && deptCode.matches("Exam[0-9]*")) {
            myForm.setId(null);
            myForm.setExamType(Long.valueOf(deptCode.substring(4)));
            sessionContext.checkPermission(Right.EditRoomDepartmentsExams);
        } else {
            sessionContext.checkPermission(deptCode, "Department", Right.EditRoomDepartments);
            d = Department.findByDeptCode(deptCode, sessionContext.getUser().getCurrentAcademicSessionId());
            myForm.setId(d.getUniqueId());
            myForm.setExamType(null);
        }
    }

    if (request.getParameter("deptId") != null) {
        String id = request.getParameter("deptId");
        if (id != null && id.matches("Exam[0-9]*")) {
            sessionContext.checkPermission(Right.EditRoomDepartmentsExams);
            myForm.setId(null);
            myForm.setExamType(Long.valueOf(id.substring(4)));
        } else {
            d = new DepartmentDAO().get(Long.valueOf(id));
            sessionContext.checkPermission(d, Right.EditRoomDepartments);
            myForm.setId(d.getUniqueId());
            myForm.setExamType(null);
        }
    }

    if (d == null && myForm.getId() != null && myForm.getExamType() < 0)
        d = new DepartmentDAO().get(myForm.getId());

    TreeSet<Room> rooms = new TreeSet<Room>();
    if (sessionContext.getUser().getCurrentAuthority().hasRight(Right.DepartmentIndependent)) {
        rooms.addAll(Location.findAllRooms(sessionContext.getUser().getCurrentAcademicSessionId()));
    } else {
        for (Department department : Department.getUserDepartments(sessionContext.getUser())) {
            for (RoomDept rd : department.getRoomDepts()) {
                if (rd.getRoom() instanceof Room)
                    rooms.add((Room) rd.getRoom());
            }
        }
    }

    ExamType examType = (myForm.getExamType() == null ? null
            : ExamTypeDAO.getInstance().get(myForm.getExamType()));

    if (d != null)
        myForm.setName(d.getDeptCode() + " " + d.getName());
    else if (examType != null)
        myForm.setName(examType.getLabel() + "Examination Rooms");
    else
        myForm.setName("Unknown");

    String op = myForm.getOp();
    if (request.getParameter("op") != null)
        op = request.getParameter("op");
    if (request.getParameter("ord") != null && request.getParameter("ord").length() > 0)
        op = "ord";

    if (op == null) {
        myForm.getAssignedSet().clear();
        if (d == null) {
            for (Iterator i = Location
                    .findAllExamLocations(sessionContext.getUser().getCurrentAcademicSessionId(), examType)
                    .iterator(); i.hasNext();) {
                Location location = (Location) i.next();
                myForm.getAssignedSet().add(location.getUniqueId());
            }
        } else {
            for (Iterator i = d.getRoomDepts().iterator(); i.hasNext();) {
                RoomDept rd = (RoomDept) i.next();
                myForm.getAssignedSet().add(rd.getRoom().getUniqueId());
            }
        }
    }

    if ("Back".equals(op)) {
        return mapping.findForward("back");
    }

    if ("Update".equals(op)) {
        ActionMessages errors = myForm.validate(mapping, request);
        if (errors.size() == 0) {
            Transaction tx = null;
            try {
                org.hibernate.Session hibSession = new RoomDeptDAO().getSession();
                tx = hibSession.beginTransaction();

                for (Iterator i = rooms.iterator(); i.hasNext();) {
                    Location location = (Location) i.next();
                    boolean checked = myForm.getAssignedSet().contains(location.getUniqueId());
                    boolean current = (d == null ? location.isExamEnabled(examType) : location.hasRoomDept(d));
                    if (current != checked) {
                        if (d == null) {
                            location.setExamEnabled(examType, checked);
                            hibSession.update(location);
                            ChangeLog.addChange(hibSession, sessionContext, location,
                                    ChangeLog.Source.ROOM_DEPT_EDIT, ChangeLog.Operation.UPDATE, null, null);
                        } else if (checked) {
                            RoomDept rd = new RoomDept();
                            rd.setDepartment(d);
                            rd.setRoom(location);
                            rd.setControl(Boolean.FALSE);
                            d.getRoomDepts().add(rd);
                            location.getRoomDepts().add(rd);
                            hibSession.saveOrUpdate(location);
                            hibSession.saveOrUpdate(rd);
                            ChangeLog.addChange(hibSession, sessionContext, location,
                                    ChangeLog.Source.ROOM_DEPT_EDIT, ChangeLog.Operation.CREATE, null, d);
                        } else {
                            RoomDept rd = null;
                            for (Iterator j = location.getRoomDepts().iterator(); rd == null && j.hasNext();) {
                                RoomDept x = (RoomDept) j.next();
                                if (x.getDepartment().equals(d))
                                    rd = x;
                            }
                            ChangeLog.addChange(hibSession, sessionContext, location,
                                    ChangeLog.Source.ROOM_DEPT_EDIT, ChangeLog.Operation.DELETE, null, d);
                            d.getRoomDepts().remove(rd);
                            location.getRoomDepts().remove(rd);
                            hibSession.saveOrUpdate(rd.getRoom());
                            hibSession.delete(rd);
                            location.removedFromDepartment(d, hibSession);
                        }
                    }
                }

                if (d != null)
                    hibSession.saveOrUpdate(d);
                tx.commit();
                if (d != null)
                    hibSession.refresh(d);

                return mapping.findForward("back");
            } catch (Exception e) {
                if (tx != null)
                    tx.rollback();
                throw e;
            }
        } else {
            saveErrors(request, errors);
        }
    }

    WebTable table = (d == null
            ? new WebTable(7, null,
                    "javascript:document.getElementsByName('ord')[0].value=%%;roomDeptEditForm.submit();",
                    new String[] { "Use", "Room", "Capacity", "Exam Capacity", "Type", "Global<br>Groups",
                            "Global<br>Features" },
                    new String[] { "left", "left", "right", "right", "left", "left", "left", "left" },
                    new boolean[] { true, true, true, true, true, true, true })
            : new WebTable(6, null,
                    "javascript:document.getElementsByName('ord')[0].value=%%;roomDeptEditForm.submit();",
                    new String[] { "Use", "Room", "Capacity", "Type", "Global<br>Groups",
                            "Global<br>Features" },
                    new String[] { "left", "left", "right", "left", "left", "left" },
                    new boolean[] { true, true, true, true, true, true }));

    for (Iterator i = rooms.iterator(); i.hasNext();) {
        Location location = (Location) i.next();
        boolean checked = myForm.getAssignedSet().contains(location.getUniqueId());
        String g = "", f = "";
        for (Iterator j = location.getGlobalRoomFeatures().iterator(); j.hasNext();) {
            GlobalRoomFeature grf = (GlobalRoomFeature) j.next();
            f += grf.getAbbv();
            if (j.hasNext())
                f += ", ";
        }
        for (Iterator j = location.getRoomGroups().iterator(); j.hasNext();) {
            RoomGroup rg = (RoomGroup) j.next();
            if (rg.isGlobal()) {
                if (g.length() > 0)
                    g += ", ";
                g += rg.getAbbv();
            }
        }
        if (d == null)
            table.addLine(
                    new String[] {
                            "<input type='checkbox' name='assigned' value='" + location.getUniqueId() + "' "
                                    + (checked ? "checked='checked'" : "") + ">",
                            location.getLabel(), String.valueOf(location.getCapacity()),
                            String.valueOf(location.getExamCapacity()), location.getRoomTypeLabel(), g, f },
                    new Comparable[] { (!checked ? 1 : 0), location.getLabel(), location.getCapacity(),
                            location.getExamCapacity(), location.getRoomTypeLabel(), null, null });
        else
            table.addLine(
                    new String[] {
                            "<input type='checkbox' name='assigned' value='" + location.getUniqueId() + "' "
                                    + (checked ? "checked='checked'" : "") + ">",
                            location.getLabel(), String.valueOf(location.getCapacity()),
                            location.getRoomTypeLabel(), g, f },
                    new Comparable[] { (!checked ? 1 : 0), location.getLabel(), location.getCapacity(),
                            location.getRoomTypeLabel(), null, null });
    }

    WebTable.setOrder(sessionContext, "RoomDeptEdit.ord", request.getParameter("ord"), (d == null ? 4 : 5));
    myForm.setTable(table.printTable(WebTable.getOrder(sessionContext, "RoomDeptEdit.ord")));

    return mapping.findForward("show");
}