Package org.apache.unomi.api.rules
Class Rule
java.lang.Object
org.apache.unomi.api.Item
org.apache.unomi.api.MetadataItem
org.apache.unomi.api.rules.Rule
- All Implemented Interfaces:
Serializable
A conditional set of actions to be executed in response to incoming events. Triggering of rules is guarded by a condition: the rule is only triggered if the associated
condition (
getCondition()
) is satisfied. Once a rule triggers, a list of actions (getActions()
can be performed as consequences.
When rules trigger, a specific event is raised so that other parts of unomi can react to it accordingly. We can control how that event should be raised using
isRaiseEventOnlyOnceForProfile()
and isRaiseEventOnlyOnceForSession()
.
We could also specify a priority for our rule in case it needs to be executed before other ones when similar conditions match. This is accomplished using the
getPriority()
property.- See Also:
-
Field Summary
FieldsFields inherited from class org.apache.unomi.api.MetadataItem
metadata
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the actions to be performed when this rule triggers.Retrieves the condition that, when satisfied, triggers the rule.Retrieves the linked items.int
Retrieves the priority in case this Rule needs to be executed before other ones when similar conditions match.boolean
Determines whether the event raised when the rule is triggered should only be raised onceboolean
Determines whether the event raised when the rule is triggered should only be raised once perProfile
.boolean
Determines whether the event raised when the rule is triggered should only be raised once perSession
.void
setActions
(List<Action> actions) Sets the actions to be performed when this rule triggers.void
setCondition
(Condition condition) Sets the condition that, when satisfied, triggers the rule..void
setLinkedItems
(List<String> linkedItems) Sets the linked items.void
setPriority
(int priority) Sets the priority in case this Rule needs to be executed before other ones when similar conditions match.void
setRaiseEventOnlyOnce
(boolean raiseEventOnlyOnce) Specifies whether the event raised when the rule is triggered should only be raised once perEvent
.void
setRaiseEventOnlyOnceForProfile
(boolean raiseEventOnlyOnceForProfile) Specifies whether the event raised when the rule is triggered should only be raised once perProfile
.void
setRaiseEventOnlyOnceForSession
(boolean raiseEventOnlyOnceForSession) Specifies whether the event raised when the rule is triggered should only be raised once perSession
.Methods inherited from class org.apache.unomi.api.MetadataItem
getMetadata, getScope, setMetadata
Methods inherited from class org.apache.unomi.api.Item
equals, getItemId, getItemType, getItemType, getSystemMetadata, getVersion, hashCode, setItemId, setItemType, setScope, setSystemMetadata, setVersion
-
Field Details
-
ITEM_TYPE
The Rule ITEM_TYPE.
-
-
Constructor Details
-
Rule
public Rule()Instantiates a new Rule. -
Rule
Instantiates a new Rule with the specifiedMetadata
.- Parameters:
metadata
- the metadata
-
-
Method Details
-
getCondition
Retrieves the condition that, when satisfied, triggers the rule.- Returns:
- the condition that, when satisfied, triggers the rule.
-
setCondition
Sets the condition that, when satisfied, triggers the rule..- Parameters:
condition
- the condition that, when satisfied, triggers the rule.
-
getActions
Retrieves the actions to be performed when this rule triggers.- Returns:
- the actions to be performed when this rule triggers
-
setActions
Sets the actions to be performed when this rule triggers.- Parameters:
actions
- the actions to be performed when this rule triggers
-
getLinkedItems
Retrieves the linked items.- Returns:
- the linked items
-
setLinkedItems
Sets the linked items.- Parameters:
linkedItems
- the linked items
-
isRaiseEventOnlyOnceForProfile
public boolean isRaiseEventOnlyOnceForProfile()Determines whether the event raised when the rule is triggered should only be raised once perProfile
.- Returns:
true
if the rule-triggered event should only be raised once per profile,false
otherwise
-
isRaiseEventOnlyOnce
public boolean isRaiseEventOnlyOnce()Determines whether the event raised when the rule is triggered should only be raised once- Returns:
true
if the rule-triggered event should only be raised once per profile
-
setRaiseEventOnlyOnceForProfile
public void setRaiseEventOnlyOnceForProfile(boolean raiseEventOnlyOnceForProfile) Specifies whether the event raised when the rule is triggered should only be raised once perProfile
.- Parameters:
raiseEventOnlyOnceForProfile
-true
if the rule-triggered event should only be raised once per profile,false
otherwise
-
isRaiseEventOnlyOnceForSession
public boolean isRaiseEventOnlyOnceForSession()Determines whether the event raised when the rule is triggered should only be raised once perSession
.- Returns:
true
if the rule-triggered event should only be raised once per session,false
otherwise
-
setRaiseEventOnlyOnceForSession
public void setRaiseEventOnlyOnceForSession(boolean raiseEventOnlyOnceForSession) Specifies whether the event raised when the rule is triggered should only be raised once perSession
.- Parameters:
raiseEventOnlyOnceForSession
-true
if the rule-triggered event should only be raised once per session,false
otherwise
-
setRaiseEventOnlyOnce
public void setRaiseEventOnlyOnce(boolean raiseEventOnlyOnce) Specifies whether the event raised when the rule is triggered should only be raised once perEvent
.- Parameters:
raiseEventOnlyOnce
-true
if the rule-triggered event should only be raised once per event,false
otherwise
-
getPriority
public int getPriority()Retrieves the priority in case this Rule needs to be executed before other ones when similar conditions match.- Returns:
- the priority
-
setPriority
public void setPriority(int priority) Sets the priority in case this Rule needs to be executed before other ones when similar conditions match.- Parameters:
priority
- the priority
-