@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;
    }
 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 (!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;
    }
    @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();
      }
    }