@Override
    public boolean check(UserContext user, Department source) {
      if (!permissionDepartment.check(user, source)) return false;

      if (!source.isAllowEvents()) return false;

      int nrRooms =
          ((Number)
                  DepartmentDAO.getInstance()
                      .getSession()
                      .createQuery(
                          "select count(r) from Room r "
                              + "where r.eventDepartment.uniqueId=:deptId")
                      .setLong("deptId", source.getUniqueId())
                      .setCacheable(true)
                      .uniqueResult())
              .intValue();

      if (nrRooms > 0) return true;

      int nrLocations =
          ((Number)
                  DepartmentDAO.getInstance()
                      .getSession()
                      .createQuery(
                          "select count(r) from NonUniversityLocation r "
                              + "where r.eventDepartment.uniqueId=:deptId")
                      .setLong("deptId", source.getUniqueId())
                      .setCacheable(true)
                      .uniqueResult())
              .intValue();

      return nrLocations > 0;
    }
    @Override
    public boolean check(UserContext user, TimetableManager source) {
      for (Department d : source.getDepartments())
        if (!permissionSession.check(user, d.getSession())) return false;

      return true;
    }
    @Override
    public boolean check(UserContext user, TimetableManager source) {
      for (Department d : source.getDepartments()) {
        if (d.getSessionId().equals(user.getCurrentAcademicSessionId())) {
          return permissionSession.check(user, d.getSession());
        }
      }

      return true;
    }
    @Override
    public boolean check(UserContext user, Department source) {
      if (!permissionDepartment.check(user, source)) return false;

      if (source.getSolverGroup() != null) return false;

      int nrOffered =
          ((Number)
                  DepartmentDAO.getInstance()
                      .getSession()
                      .createQuery(
                          "select count(io) from CourseOffering co inner join co.instructionalOffering io "
                              + "where co.subjectArea.department.uniqueId=:deptId and io.notOffered = 0")
                      .setLong("deptId", source.getUniqueId())
                      .setCacheable(true)
                      .uniqueResult())
              .intValue();

      return nrOffered == 0;
    }
 protected Department lookuDepartment(
     org.hibernate.Session hibSession,
     DepartmentInterface original,
     boolean future,
     Long sessionId) {
   if (original == null) return null;
   if (future) {
     return Department.findByDeptCode(original.getDeptCode(), sessionId, hibSession);
   } else {
     return DepartmentDAO.getInstance().get(original.getId(), hibSession);
   }
 }
    @Override
    public boolean check(UserContext user, Department source) {
      if (!permissionDepartmentEdit.check(user, source)) return false;

      if (source.isExternalManager()) {
        int nrExtManaged =
            ((Number)
                    DepartmentDAO.getInstance()
                        .getSession()
                        .createQuery(
                            "select count(c) from Class_ c where c.managingDept.uniqueId=:deptId")
                        .setLong("deptId", source.getUniqueId())
                        .setCacheable(true)
                        .uniqueResult())
                .intValue();

        return nrExtManaged == 0;
      } else {
        return source.getSubjectAreas().isEmpty();
      }
    }
Beispiel #7
0
  /**
   * Method validate
   *
   * @param mapping
   * @param request
   * @return ActionErrors
   */
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();

    if (name == null || name.equalsIgnoreCase("")) {
      errors.add("roomGroup", new ActionMessage("errors.required", "Name"));
    }

    if (abbv == null || abbv.equalsIgnoreCase("")) {
      errors.add("roomGroup", new ActionMessage("errors.required", "Abbreviation"));
    }

    try {

      for (Iterator i = RoomGroup.getAllGlobalRoomGroups(getSessionId()).iterator();
          i.hasNext(); ) {
        RoomGroup rg = (RoomGroup) i.next();
        if (rg.getName().equalsIgnoreCase(name) && !rg.getUniqueId().toString().equals(id))
          errors.add("name", new ActionMessage("errors.exists", name));
      }

      Department dept =
          (deptCode == null ? null : Department.findByDeptCode(deptCode, getSessionId()));
      if (dept != null) {
        for (Iterator i = RoomGroup.getAllDepartmentRoomGroups(dept).iterator(); i.hasNext(); ) {
          RoomGroup rg = (RoomGroup) i.next();
          if (rg.getName().equalsIgnoreCase(name) && !rg.getUniqueId().toString().equals(id))
            errors.add("name", new ActionMessage("errors.exists", name));
        }
      }

    } catch (Exception e) {
      Debug.error(e);
      errors.add("name", new ActionMessage("errors.generic", e.getMessage()));
    }

    if (!global && (deptCode == null || deptCode.equalsIgnoreCase(""))) {
      errors.add("Department", new ActionMessage("errors.required", "Department"));
    }

    return errors;
  }
    @Override
    public boolean check(UserContext user, Department source) {
      if (!permissionDepartment.check(user, source)) return false;

      return source.isAllowEvents() && !Roles.findAllInstructorRoles().isEmpty();
    }
  /**
   * Method execute
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws HibernateException
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    BackTracker.markForBack(request, null, null, false, true);

    sessionContext.checkPermission(Right.Classes);

    sessionContext.setAttribute("callingPage", "classShowSearch");

    Object sas = sessionContext.getAttribute(SessionAttribute.ClassesSubjectAreas);
    Object cn = sessionContext.getAttribute(SessionAttribute.ClassesCourseNumber);
    String subjectAreaIds = "";
    String courseNbr = "";

    if ((sas == null || sas.toString().trim().isEmpty())
        && (cn == null || cn.toString().trim().isEmpty())) {
      // use session variables from io search
      sas = sessionContext.getAttribute(SessionAttribute.OfferingsSubjectArea);
      cn = sessionContext.getAttribute(SessionAttribute.OfferingsCourseNumber);
    }

    request.setAttribute(
        Department.EXTERNAL_DEPT_ATTR_NAME,
        Department.findAllExternal(sessionContext.getUser().getCurrentAcademicSessionId()));

    ClassListForm classListForm = (ClassListForm) form;
    ClassSearchAction.setupGeneralFormFilters(sessionContext, classListForm);
    ClassSearchAction.setupClassListSpecificFormFilters(sessionContext, classListForm);

    if (!sessionContext.hasPermission(Right.CourseTimetabling)) classListForm.setTimetable(null);

    if (!sessionContext.hasPermission(Right.Examinations)) classListForm.setExams(null);

    classListForm.setSubjectAreas(SubjectArea.getUserSubjectAreas(sessionContext.getUser()));

    if (sas == null && classListForm.getSubjectAreas().size() == 1)
      sas =
          ((SubjectArea) classListForm.getSubjectAreas().iterator().next())
              .getUniqueId()
              .toString();

    if (Constants.ALL_OPTION_VALUE.equals(sas)) sas = null;

    // Subject Areas are saved to the session - Perform automatic search
    if (sas != null && sas.toString().trim().length() > 0) {
      subjectAreaIds = sas.toString();

      try {

        if (cn != null && cn.toString().trim().length() > 0) courseNbr = cn.toString();

        Debug.debug("Subject Areas: " + subjectAreaIds);
        Debug.debug("Course Number: " + courseNbr);

        classListForm.setSubjectAreaIds(subjectAreaIds.split(","));
        classListForm.setCourseNbr(courseNbr);
        StringBuffer ids = new StringBuffer();
        StringBuffer names = new StringBuffer();
        StringBuffer subjIds = new StringBuffer();
        classListForm.setClasses(
            ClassSearchAction.getClasses(
                classListForm, WebSolver.getClassAssignmentProxy(request.getSession())));
        Collection classes = classListForm.getClasses();
        if (classes.isEmpty()) {
          ActionMessages errors = new ActionMessages();
          errors.add(
              "searchResult",
              new ActionMessage(
                  "errors.generic", "No records matching the search criteria were found."));
          saveErrors(request, errors);
          return mapping.findForward("showClassSearch");
        } else {
          for (int i = 0; i < classListForm.getSubjectAreaIds().length; i++) {
            if (i > 0) {
              names.append(",");
              subjIds.append(",");
            }
            ids.append("&subjectAreaIds=" + classListForm.getSubjectAreaIds()[i]);
            subjIds.append(classListForm.getSubjectAreaIds()[i]);
            names.append(
                ((new SubjectAreaDAO()).get(new Long(classListForm.getSubjectAreaIds()[i])))
                    .getSubjectAreaAbbreviation());
          }
          BackTracker.markForBack(
              request,
              "classSearch.do?doit=Search&loadFilter=1&"
                  + ids
                  + "&courseNbr="
                  + classListForm.getCourseNbr(),
              "Classes ("
                  + names
                  + (classListForm.getCourseNbr() == null
                          || classListForm.getCourseNbr().length() == 0
                      ? ""
                      : " " + classListForm.getCourseNbr())
                  + ")",
              true,
              true);
          return mapping.findForward("showClassList");
        }
      } catch (NumberFormatException nfe) {
        Debug.error("Subject Area Ids session attribute is corrupted. Resetting ... ");
        sessionContext.removeAttribute(SessionAttribute.ClassesSubjectAreas);
        sessionContext.removeAttribute(SessionAttribute.ClassesCourseNumber);
      }
    }

    return mapping.findForward("showClassSearch");
  }
  @Override
  public FeatureInterface execute(UpdateRoomFeatureRequest request, SessionContext context) {
    if (request.hasSessionId()) context = new EventContext(context, request.getSessionId());

    Transaction tx = null;
    RoomFeature f = null;
    try {
      org.hibernate.Session hibSession = new RoomDeptDAO().getSession();
      tx = hibSession.beginTransaction();

      if (request.hasFeature()) {

        if (request.hasFutureSessions())
          for (Long id : request.getFutureSessions())
            createOrUpdateFeature(
                request.getFeature(),
                request.getAddLocations(),
                request.getDropLocations(),
                id,
                hibSession,
                new EventContext(context, context.getUser(), id),
                true);
        f =
            createOrUpdateFeature(
                request.getFeature(),
                request.getAddLocations(),
                request.getDropLocations(),
                context.getUser().getCurrentAcademicSessionId(),
                hibSession,
                context,
                false);

      } else if (request.getDeleteFeatureId() != null) {

        if (request.hasFutureSessions())
          for (Long id : request.getFutureSessions())
            dropFeature(
                request.getDeleteFeatureId(),
                id,
                hibSession,
                new EventContext(context, context.getUser(), id),
                true);
        dropFeature(
            request.getDeleteFeatureId(),
            context.getUser().getCurrentAcademicSessionId(),
            hibSession,
            context,
            false);

      } else {
        throw new GwtRpcException("Bad request.");
      }

      FeatureInterface feature = null;
      if (f != null) {
        feature = new FeatureInterface(f.getUniqueId(), f.getAbbv(), f.getLabel());
        if (f.getFeatureType() != null)
          feature.setType(
              new FeatureTypeInterface(
                  f.getFeatureType().getUniqueId(),
                  f.getFeatureType().getReference(),
                  f.getFeatureType().getLabel(),
                  f.getFeatureType().isShowInEventManagement()));
        if (f instanceof DepartmentRoomFeature) {
          Department d = ((DepartmentRoomFeature) f).getDepartment();
          feature.setDepartment(RoomDetailsBackend.wrap(d, null, null));
          feature.setTitle(
              f.getLabel()
                  + " ("
                  + d.getName()
                  + (f.getFeatureType() == null ? "" : ", " + f.getFeatureType().getLabel())
                  + ")");
        } else {
          feature.setTitle(
              f.getLabel()
                  + (f.getFeatureType() == null ? "" : " (" + f.getFeatureType().getLabel() + ")"));
        }
      }

      tx.commit();

      return feature;
    } catch (Exception e) {
      e.printStackTrace();
      if (tx != null) tx.rollback();
      if (e instanceof GwtRpcException) throw (GwtRpcException) e;
      throw new GwtRpcException(e.getMessage());
    }
  }
  protected RoomFeature createOrUpdateFeature(
      FeatureInterface feature,
      List<Long> add,
      List<Long> drop,
      Long sessionId,
      org.hibernate.Session hibSession,
      SessionContext context,
      boolean future) {
    Department d =
        feature.isDepartmental()
            ? lookuDepartment(hibSession, feature.getDepartment(), future, sessionId)
            : null;
    if (feature.isDepartmental() && d == null) return null;

    RoomFeature rf =
        (feature.getId() == null ? null : lookupFeature(hibSession, feature, future, sessionId));

    if (rf == null) {
      if (!future && feature.getId() != null)
        throw new GwtRpcException(MESSAGES.errorRoomFeatureDoesNotExist(feature.getId()));
      if (d == null) {
        context.checkPermission(Right.GlobalRoomFeatureAdd);
        rf = new GlobalRoomFeature();
        ((GlobalRoomFeature) rf).setSession(SessionDAO.getInstance().get(sessionId));
      } else {
        context.checkPermission(d, Right.DepartmentRoomFeatureAdd);
        rf = new DepartmentRoomFeature();
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
      rf.setRooms(new HashSet<Location>());
    } else {
      if (rf instanceof GlobalRoomFeature) {
        context.checkPermission(rf, Right.GlobalRoomFeatureEdit);
      } else {
        context.checkPermission(rf, Right.DepartmenalRoomFeatureEdit);
        ((DepartmentRoomFeature) rf).setDepartment(d);
      }
    }

    for (Iterator i = RoomFeature.getAllGlobalRoomFeatures(sessionId).iterator(); i.hasNext(); ) {
      RoomFeature x = (RoomFeature) i.next();
      if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
              || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
          && !x.getUniqueId().equals(rf.getUniqueId()))
        throw new GwtRpcException(
            MESSAGES.errorRoomFeatureAlreadyExists(
                feature.getLabel(), SessionDAO.getInstance().get(sessionId).getLabel()));
    }

    if (rf instanceof DepartmentRoomFeature) {
      for (Iterator i = RoomFeature.getAllDepartmentRoomFeatures(d).iterator(); i.hasNext(); ) {
        RoomFeature x = (RoomFeature) i.next();
        if ((x.getLabel().equalsIgnoreCase(feature.getLabel())
                || x.getAbbv().equalsIgnoreCase(feature.getAbbreviation()))
            && !x.getUniqueId().equals(rf.getUniqueId()))
          throw new GwtRpcException(
              MESSAGES.errorRoomFeatureAlreadyExists(
                  feature.getLabel(), d.getSession().getLabel()));
      }
    }

    rf.setAbbv(feature.getAbbreviation());
    rf.setLabel(feature.getLabel());
    rf.setFeatureType(
        feature.getType() == null
            ? null
            : RoomFeatureTypeDAO.getInstance().get(feature.getType().getId(), hibSession));

    hibSession.saveOrUpdate(rf);

    if (add != null && !add.isEmpty())
      for (Location location : lookupLocations(hibSession, add, future, sessionId)) {
        rf.getRooms().add(location);
        location.getFeatures().add(rf);
        hibSession.saveOrUpdate(location);
      }

    if (drop != null && !drop.isEmpty())
      for (Location location : lookupLocations(hibSession, drop, future, sessionId)) {
        rf.getRooms().remove(location);
        location.getFeatures().remove(rf);
        hibSession.saveOrUpdate(location);
      }

    hibSession.saveOrUpdate(rf);

    ChangeLog.addChange(
        hibSession,
        context,
        rf,
        ChangeLog.Source.ROOM_FEATURE_EDIT,
        (feature.getId() == null ? ChangeLog.Operation.CREATE : ChangeLog.Operation.UPDATE),
        null,
        rf instanceof DepartmentRoomFeature ? ((DepartmentRoomFeature) rf).getDepartment() : null);

    return rf;
  }
Beispiel #12
0
  public void loadXml(Element root) throws Exception {
    if (!root.getName().equalsIgnoreCase("roomSharing")) {
      throw new Exception("Given XML file is not a Room Sharing load file.");
    }
    try {
      beginTransaction();

      String campus = root.attributeValue("campus");
      String year = root.attributeValue("year");
      String term = root.attributeValue("term");
      iTimeFormat = root.attributeValue("timeFormat");
      if (iTimeFormat == null) iTimeFormat = "HHmm";

      Session session = Session.getSessionUsingInitiativeYearTerm(campus, year, term);
      if (session == null) {
        throw new Exception("No session found for the given campus, year, and term.");
      }

      if (!"true".equals(root.attributeValue("force"))
          && Solution.hasTimetable(session.getUniqueId())) {
        info(
            "Note: set the attribute force='true' of the root element to override the following import eligibility check.");
        throw new Exception(
            "Room sharing import is disabled: "
                + session.getLabel()
                + " already has a committed timetable.");
      }

      info("Loading rooms...");
      Set<String> avoidRoomId = new HashSet<String>();
      Set<String> avoidRoomName = new HashSet<String>();
      Map<String, Location> id2location = new HashMap<String, Location>();
      Map<String, Location> name2location = new HashMap<String, Location>();
      for (Location location :
          (List<Location>)
              getHibSession()
                  .createQuery("from Location where session.uniqueId = :sessionId")
                  .setLong("sessionId", session.getUniqueId())
                  .list()) {
        if (location.getExternalUniqueId() != null && !avoidRoomId.contains(avoidRoomId)) {
          Location old = id2location.put(location.getExternalUniqueId(), location);
          if (old != null) {
            warn(
                "There are two or more rooms with the same external id "
                    + location.getExternalUniqueId()
                    + ": "
                    + location.getLabel()
                    + " and "
                    + old.getLabel()
                    + ".");
            avoidRoomId.add(location.getExternalUniqueId());
          }
        }
        if (!avoidRoomName.contains(location.getLabel())) {
          Location old = name2location.put(location.getLabel(), location);
          if (old != null) {
            warn("There are two or more rooms with the same name " + location.getLabel() + ".");
            avoidRoomName.add(location.getLabel());
          }
        }
      }

      info("Loading departments...");
      Map<String, Department> id2department = new HashMap<String, Department>();
      Map<String, Department> code2department = new HashMap<String, Department>();
      for (Department dept :
          (List<Department>)
              getHibSession()
                  .createQuery("from Department where session.uniqueId = :sessionId")
                  .setLong("sessionId", session.getUniqueId())
                  .list()) {
        if (dept.getExternalUniqueId() != null) {
          Department old = id2department.put(dept.getExternalUniqueId(), dept);
          if (old != null) {
            warn(
                "There are two departments with the same external id "
                    + dept.getExternalUniqueId()
                    + ": "
                    + dept.getLabel()
                    + " and "
                    + old.getLabel()
                    + ".");
          }
        }
        Department old = code2department.put(dept.getDeptCode(), dept);
        if (old != null) {
          warn(
              "There are two rooms with the same code "
                  + dept.getDeptCode()
                  + ": "
                  + dept.getName()
                  + " and "
                  + old.getName()
                  + ".");
        }
      }

      info("Importing room sharing...");
      int nrChanged = 0;
      for (Iterator i = root.elementIterator("location"); i.hasNext(); ) {
        Element locEl = (Element) i.next();
        Location location = null;

        String locId = locEl.attributeValue("id");
        if (locId != null && !avoidRoomId.contains(locId)) {
          location = id2location.get(locId);
          if (location == null) warn("Location of id " + locId + " does not exist.");
        }

        if (location == null) {
          String building = locEl.attributeValue("building");
          String roomNbr = locEl.attributeValue("roomNbr");
          if (building != null
              && roomNbr != null
              && !avoidRoomName.contains(building + " " + roomNbr)) {
            location = name2location.get(building + " " + roomNbr);
            if (location == null)
              warn(
                  "Location of building "
                      + building
                      + " and room number "
                      + roomNbr
                      + " does not exist.");
          }
        }

        if (location == null) {
          String name = locEl.attributeValue("name");
          if (name != null && !avoidRoomName.contains(name)) {
            location = name2location.get(name);
            if (location == null) warn("Location of name " + name + " does not exist.");
          }
        }

        if (location == null) continue;

        Set<RoomDept> existing = new HashSet<RoomDept>(location.getRoomDepts());
        Set<Department> departments = new HashSet<Department>();
        boolean changed = false;

        String note = locEl.attributeValue("note");
        if (note == null && location.getShareNote() != null) {
          location.setShareNote(null);
          info(location.getLabel() + ": share note removed.");
          changed = true;
        } else if (note != null && !note.equals(location.getShareNote())) {
          location.setShareNote(note);
          info(location.getLabel() + ": share note changed to '" + note + "'.");
          changed = true;
        }

        department:
        for (Iterator j = locEl.elementIterator("department"); j.hasNext(); ) {
          Element deptEl = (Element) j.next();
          Department dept = null;

          String deptId = deptEl.attributeValue("id");
          if (deptId != null) {
            dept = id2department.get(deptId);
            if (dept == null)
              warn(location.getLabel() + ": Department of id " + deptId + " does not exist.");
          }

          String deptCode = deptEl.attributeValue("code");
          if (deptCode != null) {
            dept = code2department.get(deptCode);
            if (dept == null)
              warn(location.getLabel() + ": Department of code " + deptCode + " does not exist.");
          }

          if (dept == null) continue;
          Boolean control = "true".equals(deptEl.attributeValue("control"));

          for (Iterator<RoomDept> k = existing.iterator(); k.hasNext(); ) {
            RoomDept rd = k.next();
            if (rd.getDepartment().equals(dept)) {
              if (!control.equals(rd.getControl())) {
                rd.setControl(control);
                getHibSession().update(rd);
                info(
                    location.getLabel()
                        + ": "
                        + (control
                            ? " control moved to " + dept.getLabel()
                            : " control removed from " + dept.getLabel()));
                changed = true;
              }
              k.remove();
              departments.add(dept);
              continue department;
            }
          }

          RoomDept rd = new RoomDept();
          rd.setControl(control);
          rd.setDepartment(dept);
          rd.setRoom(location);
          location.getRoomDepts().add(rd);
          dept.getRoomDepts().add(rd);
          getHibSession().save(rd);
          departments.add(dept);
          info(
              location.getLabel()
                  + ": added "
                  + (control ? "controlling " : "")
                  + " department"
                  + dept.getLabel());
          changed = true;
        }

        for (RoomDept rd : existing) {
          info(
              location.getLabel()
                  + ": removed "
                  + (rd.isControl() ? "controlling " : "")
                  + " department"
                  + rd.getDepartment().getLabel());
          location.getRoomDepts().remove(rd);
          rd.getDepartment().getRoomDepts().remove(rd);
          getHibSession().delete(rd);
          changed = true;
        }

        RoomSharingModel model = location.getRoomSharingModel();
        String oldModel = model.toString();
        model.setPreferences(null);

        Element sharingEl = locEl.element("sharing");
        if (sharingEl != null) {
          for (Iterator j = sharingEl.elementIterator(); j.hasNext(); ) {
            Element el = (Element) j.next();
            TimeObject time =
                new TimeObject(
                    el.attributeValue("start"),
                    el.attributeValue("end"),
                    el.attributeValue("days"));

            String pref = null;
            if ("unavailable".equals(el.getName())) {
              pref = RoomSharingModel.sNotAvailablePref.toString();
            } else if ("assigned".equals(el.getName())) {
              Department dept = null;

              String deptId = el.attributeValue("id");
              if (deptId != null) {
                dept = id2department.get(deptId);
                if (dept == null)
                  warn(location.getLabel() + ": Department of id " + deptId + " does not exist.");
              }

              String deptCode = el.attributeValue("code");
              if (deptCode != null) {
                dept = code2department.get(deptCode);
                if (dept == null)
                  warn(
                      location.getLabel()
                          + ": Department of code "
                          + deptCode
                          + " does not exist.");
              }

              if (dept == null) continue;
              if (!departments.contains(dept)) {
                warn(
                    location.getLabel()
                        + ": Department "
                        + dept.getLabel()
                        + " is not among the room sharing departments.");
                continue;
              }

              pref = dept.getUniqueId().toString();
            }

            if (pref == null) continue;

            if (time.hasDays()) {
              for (int d : time.getDays())
                for (int t = time.getStartPeriod(); t < time.getEndPeriod(); t++)
                  model.setPreference(d, t, pref);
            } else {
              for (int d = 0; d < model.getNrDays(); d++)
                for (int t = time.getStartPeriod(); t < time.getEndPeriod(); t++)
                  model.setPreference(d, t, pref);
            }
          }
        }

        String newModel = model.toString();
        if (!oldModel.equals(newModel)) {
          info(
              location.getLabel()
                  + ": room sharing changed to "
                  + (newModel.isEmpty() ? "free for all" : newModel));
          changed = true;
        }

        location.setRoomSharingModel(model);
        getHibSession().update(location);

        if (changed) nrChanged++;
      }

      if (nrChanged == 0) {
        info("No change detected.");
      } else {
        info(nrChanged + " locations have changed.");
      }
      info("All done.");

      commitTransaction();
    } catch (Exception e) {
      fatal("Exception: " + e.getMessage(), e);
      rollbackTransaction();
      throw e;
    }
  }