{-# LANGUAGE CPP #-}
module WeekDaze.ProblemConfiguration.TimetableValidationSwitches(
TimetableValidationSwitches(..),
checkBookedSubjectsAreRequiredTag,
checkBookedSubjectsHaveServiceTag,
checkExistenceOfLocationIdsTag,
checkExistenceOfStudentBodiesTag,
checkExistenceOfTeacherIdsTag,
checkForBookingMeetingClashTag,
checkForMisplacedLessonsTag,
checkForOverbookedSubjectsTag,
checkForOverloadedStudentBodiesTag,
checkForOverloadedTeachersTag,
checkForResourceConflictsTag,
checkMinimumConsecutiveLessonsTag,
checkResourceAvailabilityTag,
checkSynchronisedCoursesTag,
checkTimeslotsPerDayTag
) where
import qualified Control.DeepSeq
import qualified Data.Default
import qualified Text.XML.HXT.Arrow.Pickle as HXT
import qualified WeekDaze.ProblemConfiguration.ValidationSwitch as ProblemConfiguration.ValidationSwitch
import WeekDaze.Enhanced.EnhancedBool()
#ifdef USE_HDBC
import qualified Database.HDBC
import qualified Data.Maybe
import qualified WeekDaze.Database.Selector as Database.Selector
instance Database.Selector.Selector TimetableValidationSwitches where
fromDatabase connection projectIdSql = let
tableName :: Database.Selector.TableName
tableName = showString Database.Selector.tablePrefix tag
in do
switchesRows <- map (
map $ Data.Maybe.fromMaybe ProblemConfiguration.ValidationSwitch.defaultCheck . either (
error . showString "WeekDaze.ProblemConfiguration.TimetableValidationSwitches.fromDatabase:\tfailed to parse the value for a switch read from the database; " . show
) id . Database.HDBC.safeFromSql
) `fmap` Database.Selector.select connection [
checkBookedSubjectsAreRequiredTag,
checkBookedSubjectsHaveServiceTag,
checkExistenceOfLocationIdsTag,
checkExistenceOfStudentBodiesTag,
checkExistenceOfTeacherIdsTag,
checkForBookingMeetingClashTag,
checkForMisplacedLessonsTag,
checkForOverbookedSubjectsTag,
checkForOverloadedStudentBodiesTag,
checkForOverloadedTeachersTag,
checkForResourceConflictsTag,
checkMinimumConsecutiveLessonsTag,
checkResourceAvailabilityTag,
checkSynchronisedCoursesTag,
checkTimeslotsPerDayTag
] [tableName] [(Database.Selector.projectIdColumnName, projectIdSql)]
return $ case switchesRows of
[] -> Data.Default.def
[switchesRow] -> case switchesRow of
[
checkBookedSubjectsAreRequired,
checkBookedSubjectsHaveService,
checkSynchronisedCourses,
checkExistenceOfLocationIds,
checkExistenceOfStudentBodies,
checkExistenceOfTeacherIds,
checkForBookingMeetingClash,
checkForMisplacedLessons,
checkForOverbookedSubjects,
checkForOverloadedStudentBodies,
checkForOverloadedTeachers,
checkForResourceConflicts,
checkMinimumConsecutiveLessons,
checkResourceAvailability,
checkTimeslotsPerDay
] -> MkTimetableValidationSwitches {
getCheckBookedSubjectsAreRequired = checkBookedSubjectsAreRequired,
getCheckBookedSubjectsHaveService = checkBookedSubjectsHaveService,
getCheckSynchronisedCourses = checkSynchronisedCourses,
getCheckExistenceOfLocationIds = checkExistenceOfLocationIds,
getCheckExistenceOfStudentBodies = checkExistenceOfStudentBodies,
getCheckExistenceOfTeacherIds = checkExistenceOfTeacherIds,
getCheckForBookingMeetingClash = checkForBookingMeetingClash,
getCheckForMisplacedLessons = checkForMisplacedLessons,
getCheckForOverbookedSubjects = checkForOverbookedSubjects,
getCheckForOverloadedStudentBodies = checkForOverloadedStudentBodies,
getCheckForOverloadedTeachers = checkForOverloadedTeachers,
getCheckForResourceConflicts = checkForResourceConflicts,
getCheckMinimumConsecutiveLessons = checkMinimumConsecutiveLessons,
getCheckResourceAvailability = checkResourceAvailability,
getCheckTimeslotsPerDay = checkTimeslotsPerDay
}
_ -> error $ "WeekDaze.ProblemConfiguration.TimetableValidationSwitches.fromDatabase:\tunexpected number of columns=" ++ show (length switchesRow) ++ " in row of table " ++ show tableName ++ "."
_ -> error $ "WeekDaze.ProblemConfiguration.TimetableValidationSwitches.fromDatabase:\tunexpected number of rows=" ++ show (length switchesRows) ++ " selected from table " ++ show tableName ++ "."
#endif /* USE_HDBC */
tag :: String
tag = "timetableValidationSwitches"
checkBookedSubjectsAreRequiredTag :: String
checkBookedSubjectsAreRequiredTag = "checkBookedSubjectsAreRequired"
checkBookedSubjectsHaveServiceTag :: String
checkBookedSubjectsHaveServiceTag = "checkBookedSubjectsHaveService"
checkExistenceOfLocationIdsTag :: String
checkExistenceOfLocationIdsTag = "checkExistenceOfLocationIds"
checkExistenceOfStudentBodiesTag :: String
checkExistenceOfStudentBodiesTag = "checkExistenceOfStudentBodies"
checkExistenceOfTeacherIdsTag :: String
checkExistenceOfTeacherIdsTag = "checkExistenceOfTeacherIds"
checkForBookingMeetingClashTag :: String
checkForBookingMeetingClashTag = "checkForBookingMeetingClash"
checkForMisplacedLessonsTag :: String
checkForMisplacedLessonsTag = "checkForMisplacedLessons"
checkForOverbookedSubjectsTag :: String
checkForOverbookedSubjectsTag = "checkForOverbookedSubjects"
checkForOverloadedStudentBodiesTag :: String
checkForOverloadedStudentBodiesTag = "checkForOverloadedStudentBodies"
checkForOverloadedTeachersTag :: String
checkForOverloadedTeachersTag = "checkForOverloadedTeachers"
checkForResourceConflictsTag :: String
checkForResourceConflictsTag = "checkForResourceConflicts"
checkMinimumConsecutiveLessonsTag :: String
checkMinimumConsecutiveLessonsTag = "checkMinimumConsecutiveLessons"
checkResourceAvailabilityTag :: String
checkResourceAvailabilityTag = "checkResourceAvailability"
checkSynchronisedCoursesTag :: String
checkSynchronisedCoursesTag = "checkSynchronisedCourses"
checkTimeslotsPerDayTag :: String
checkTimeslotsPerDayTag = "checkTimeslotsPerDay"
data TimetableValidationSwitches = MkTimetableValidationSwitches {
getCheckBookedSubjectsAreRequired :: ProblemConfiguration.ValidationSwitch.Check,
getCheckBookedSubjectsHaveService :: ProblemConfiguration.ValidationSwitch.Check,
getCheckExistenceOfLocationIds :: ProblemConfiguration.ValidationSwitch.Check,
getCheckExistenceOfStudentBodies :: ProblemConfiguration.ValidationSwitch.Check,
getCheckExistenceOfTeacherIds :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForBookingMeetingClash :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForMisplacedLessons :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForOverbookedSubjects :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForOverloadedStudentBodies :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForOverloadedTeachers :: ProblemConfiguration.ValidationSwitch.Check,
getCheckForResourceConflicts :: ProblemConfiguration.ValidationSwitch.Check,
getCheckMinimumConsecutiveLessons :: ProblemConfiguration.ValidationSwitch.Check,
getCheckResourceAvailability :: ProblemConfiguration.ValidationSwitch.Check,
getCheckSynchronisedCourses :: ProblemConfiguration.ValidationSwitch.Check,
getCheckTimeslotsPerDay :: ProblemConfiguration.ValidationSwitch.Check
} deriving (Eq, Show)
instance () => HXT.XmlPickler TimetableValidationSwitches where
xpickle = HXT.xpElem tag . HXT.xpWrap (
\(a, b, c, d, e, f, h, i, j, k, l, m, n, o, p) -> MkTimetableValidationSwitches a b c d e f h i j k l m n o p,
\MkTimetableValidationSwitches {
getCheckBookedSubjectsAreRequired = checkBookedSubjectsAreRequired,
getCheckBookedSubjectsHaveService = checkBookedSubjectsHaveService,
getCheckSynchronisedCourses = checkSynchronisedCourses,
getCheckExistenceOfLocationIds = checkExistenceOfLocationIds,
getCheckExistenceOfStudentBodies = checkExistenceOfStudentBodies,
getCheckExistenceOfTeacherIds = checkExistenceOfTeacherIds,
getCheckForBookingMeetingClash = checkForBookingMeetingClash,
getCheckForMisplacedLessons = checkForMisplacedLessons,
getCheckForOverbookedSubjects = checkForOverbookedSubjects,
getCheckForOverloadedStudentBodies = checkForOverloadedStudentBodies,
getCheckForOverloadedTeachers = checkForOverloadedTeachers,
getCheckForResourceConflicts = checkForResourceConflicts,
getCheckMinimumConsecutiveLessons = checkMinimumConsecutiveLessons,
getCheckResourceAvailability = checkResourceAvailability,
getCheckTimeslotsPerDay = checkTimeslotsPerDay
} -> (
checkBookedSubjectsAreRequired,
checkBookedSubjectsHaveService,
checkSynchronisedCourses,
checkExistenceOfLocationIds,
checkExistenceOfStudentBodies,
checkExistenceOfTeacherIds,
checkForBookingMeetingClash,
checkForMisplacedLessons,
checkForOverbookedSubjects,
checkForOverloadedStudentBodies,
checkForOverloadedTeachers,
checkForResourceConflicts,
checkMinimumConsecutiveLessons,
checkResourceAvailability,
checkTimeslotsPerDay
)
) $ HXT.xp15Tuple (
getCheckBookedSubjectsAreRequired def `HXT.xpDefault` HXT.xpAttr checkBookedSubjectsAreRequiredTag HXT.xpickle
) (
getCheckBookedSubjectsHaveService def `HXT.xpDefault` HXT.xpAttr checkBookedSubjectsHaveServiceTag HXT.xpickle
) (
getCheckExistenceOfLocationIds def `HXT.xpDefault` HXT.xpAttr checkExistenceOfLocationIdsTag HXT.xpickle
) (
getCheckExistenceOfStudentBodies def `HXT.xpDefault` HXT.xpAttr checkExistenceOfStudentBodiesTag HXT.xpickle
) (
getCheckExistenceOfTeacherIds def `HXT.xpDefault` HXT.xpAttr checkExistenceOfTeacherIdsTag HXT.xpickle
) (
getCheckForBookingMeetingClash def `HXT.xpDefault` HXT.xpAttr checkForBookingMeetingClashTag HXT.xpickle
) (
getCheckForMisplacedLessons def `HXT.xpDefault` HXT.xpAttr checkForMisplacedLessonsTag HXT.xpickle
) (
getCheckForOverbookedSubjects def `HXT.xpDefault` HXT.xpAttr checkForOverbookedSubjectsTag HXT.xpickle
) (
getCheckForOverloadedStudentBodies def `HXT.xpDefault` HXT.xpAttr checkForOverloadedStudentBodiesTag HXT.xpickle
) (
getCheckForOverloadedTeachers def `HXT.xpDefault` HXT.xpAttr checkForOverloadedTeachersTag HXT.xpickle
) (
getCheckForResourceConflicts def `HXT.xpDefault` HXT.xpAttr checkForResourceConflictsTag HXT.xpickle
) (
getCheckMinimumConsecutiveLessons def `HXT.xpDefault` HXT.xpAttr checkMinimumConsecutiveLessonsTag HXT.xpickle
) (
getCheckResourceAvailability def `HXT.xpDefault` HXT.xpAttr checkResourceAvailabilityTag HXT.xpickle
) (
getCheckSynchronisedCourses def `HXT.xpDefault` HXT.xpAttr checkSynchronisedCoursesTag HXT.xpickle
) (
getCheckTimeslotsPerDay def `HXT.xpDefault` HXT.xpAttr checkTimeslotsPerDayTag HXT.xpickle
) where
def :: TimetableValidationSwitches
def = Data.Default.def
instance Data.Default.Default TimetableValidationSwitches where
def = MkTimetableValidationSwitches {
getCheckBookedSubjectsAreRequired = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckBookedSubjectsHaveService = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckSynchronisedCourses = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckExistenceOfLocationIds = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckExistenceOfStudentBodies = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckExistenceOfTeacherIds = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForBookingMeetingClash = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForMisplacedLessons = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForOverbookedSubjects = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForOverloadedStudentBodies = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForOverloadedTeachers = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckForResourceConflicts = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckMinimumConsecutiveLessons = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckResourceAvailability = ProblemConfiguration.ValidationSwitch.defaultCheck,
getCheckTimeslotsPerDay = ProblemConfiguration.ValidationSwitch.defaultCheck
}
instance ProblemConfiguration.ValidationSwitch.ValidationSwitchSet TimetableValidationSwitches where
areAllOff timetableValidationSwitches = not $ any ($ timetableValidationSwitches) [
getCheckBookedSubjectsAreRequired,
getCheckBookedSubjectsHaveService,
getCheckSynchronisedCourses,
getCheckExistenceOfLocationIds,
getCheckExistenceOfStudentBodies,
getCheckExistenceOfTeacherIds,
getCheckForBookingMeetingClash,
getCheckForMisplacedLessons,
getCheckForOverbookedSubjects,
getCheckForOverloadedStudentBodies,
getCheckForOverloadedTeachers,
getCheckForResourceConflicts,
getCheckMinimumConsecutiveLessons,
getCheckResourceAvailability,
getCheckTimeslotsPerDay
]
instance Control.DeepSeq.NFData TimetableValidationSwitches where
rnf (MkTimetableValidationSwitches x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14) = Control.DeepSeq.rnf [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14]