and(), or(), not(): decide whether a badge opens a door
Hard
An office door checks each badge swipe and shows why it opened or stayed shut.
Check these rules in order and return the first that applies
- the badge is not active:
"Denied: badge not active" - an alarm is on in any zone, and the person is not security staff:
"Denied: alarm active" - it is the weekend, or before 7:00, or 19:00 or later, and the person has neither an after-hours pass nor a security role:
"Denied: outside hours" - otherwise:
"Allowed"
Watch out
- A badge that was never activated has no value at all (null), and is not active either.
not()refuses a null. or()given a list of Booleans answers for the whole list, and some buildings have no alarms fitted, so that list can be empty.
Inputs
ri!badgeActive: Boolean, possibly nullri!alarms: List of Boolean, one per zoneri!isSecurity: Booleanri!afterHoursPass: Booleanri!isWeekend: Booleanri!hour: Integer, 0 to 23
ri! Rule Inputs
ri!badgeActiveBooleantrue
ri!alarmsList of Boolean{
false,
false
}ri!isSecurityBooleanfalse
ri!afterHoursPassBooleanfalse
ri!isWeekendBooleanfalse
ri!hourInteger10
Example 1: An ordinary weekday morning
Input: ri!badgeActive
true
Input: ri!alarms
{
false,
false
}Input: ri!isSecurity
false
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
10
Output:
"Allowed"
Example 2: A badge never activated
Input: ri!badgeActive
null
Input: ri!alarms
{
false,
false
}Input: ri!isSecurity
false
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
10
Output:
"Denied: badge not active"
Example 3: A deactivated badge
Input: ri!badgeActive
false
Input: ri!alarms
{false}Input: ri!isSecurity
true
Input: ri!afterHoursPass
true
Input: ri!isWeekend
false
Input: ri!hour
10
Output:
"Denied: badge not active"
Example 4: Alarm on, regular staff
Input: ri!badgeActive
true
Input: ri!alarms
{
false,
true
}Input: ri!isSecurity
false
Input: ri!afterHoursPass
true
Input: ri!isWeekend
false
Input: ri!hour
10
Output:
"Denied: alarm active"
Example 5: Alarm on, security staff
Input: ri!badgeActive
true
Input: ri!alarms
{true}Input: ri!isSecurity
true
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
10
Output:
"Allowed"
Example 6: Evening without a pass
Input: ri!badgeActive
true
Input: ri!alarms
{false}Input: ri!isSecurity
false
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
20
Output:
"Denied: outside hours"
Example 7: Exactly 19:00
Input: ri!badgeActive
true
Input: ri!alarms
{false}Input: ri!isSecurity
false
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
19
Output:
"Denied: outside hours"
Example 8: Weekend with an after-hours pass
Input: ri!badgeActive
true
Input: ri!alarms
{false}Input: ri!isSecurity
false
Input: ri!afterHoursPass
true
Input: ri!isWeekend
true
Input: ri!hour
11
Output:
"Allowed"
Example 9: Security before opening time
Input: ri!badgeActive
true
Input: ri!alarms
{}Input: ri!isSecurity
true
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
6
Output:
"Allowed"
Example 10: No alarms fitted
Input: ri!badgeActive
true
Input: ri!alarms
{}Input: ri!isSecurity
false
Input: ri!afterHoursPass
false
Input: ri!isWeekend
false
Input: ri!hour
9
Output:
"Allowed"
Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter