Search in sources :

Example 1 with GenericRuleEventSpec

use of org.openksavi.sponge.core.rule.GenericRuleEventSpec in project sponge by softelnet.

the class BaseKnowledgeBaseInterpreter method getCustomRuleEventSpec.

/**
 * Resolves event specification "<name> <alias> : <mode>". Uses default value when one not provided.
 *
 * @param eventSpecString event specification.
 * @return rule event specification, i.e. a triple of (name, alias, mode).
 */
protected RuleEventSpec getCustomRuleEventSpec(String eventSpecString) {
    if (eventSpecString == null) {
        throw new SpongeException("Event specification is null");
    }
    List<String> mainList = Arrays.stream(eventSpecString.split(":")).map(s -> s.trim()).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    if (mainList.isEmpty()) {
        throw new SpongeException("Event specification is empty");
    } else if (mainList.size() > 2) {
        throw new SpongeException("Event specification has too many elements separated by ':'");
    }
    ImmutablePair<String, String> nameAlias = resolveEventNameAndAlias(mainList.get(0));
    EventMode eventMode = RuleAdapter.DEFAULT_MODE;
    if (mainList.size() == 2) {
        try {
            eventMode = EventMode.valueOf(mainList.get(1).toUpperCase());
        } catch (Exception e) {
            throw new SpongeException("Event mode is incorrect: " + mainList.get(1));
        }
    }
    return new GenericRuleEventSpec(nameAlias.getLeft(), nameAlias.getRight(), eventMode);
}
Also used : Arrays(java.util.Arrays) KnowledgeBaseInterpreter(org.openksavi.sponge.kb.KnowledgeBaseInterpreter) Logger(org.slf4j.Logger) Plugin(org.openksavi.sponge.plugin.Plugin) LoggerFactory(org.slf4j.LoggerFactory) GenericRuleEventSpec(org.openksavi.sponge.core.rule.GenericRuleEventSpec) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) KnowledgeBaseEngineOperations(org.openksavi.sponge.kb.KnowledgeBaseEngineOperations) EventMode(org.openksavi.sponge.rule.EventMode) KnowledgeBaseType(org.openksavi.sponge.kb.KnowledgeBaseType) List(java.util.List) RuleAdapter(org.openksavi.sponge.rule.RuleAdapter) RuleEventSpec(org.openksavi.sponge.rule.RuleEventSpec) StringTokenizer(java.util.StringTokenizer) SpongeException(org.openksavi.sponge.SpongeException) Processor(org.openksavi.sponge.Processor) SpongeUtils(org.openksavi.sponge.core.util.SpongeUtils) EventMode(org.openksavi.sponge.rule.EventMode) SpongeException(org.openksavi.sponge.SpongeException) GenericRuleEventSpec(org.openksavi.sponge.core.rule.GenericRuleEventSpec) SpongeException(org.openksavi.sponge.SpongeException)

Aggregations

Arrays (java.util.Arrays)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 Collectors (java.util.stream.Collectors)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Processor (org.openksavi.sponge.Processor)1 SpongeException (org.openksavi.sponge.SpongeException)1 GenericRuleEventSpec (org.openksavi.sponge.core.rule.GenericRuleEventSpec)1 SpongeUtils (org.openksavi.sponge.core.util.SpongeUtils)1 KnowledgeBaseEngineOperations (org.openksavi.sponge.kb.KnowledgeBaseEngineOperations)1 KnowledgeBaseInterpreter (org.openksavi.sponge.kb.KnowledgeBaseInterpreter)1 KnowledgeBaseType (org.openksavi.sponge.kb.KnowledgeBaseType)1 Plugin (org.openksavi.sponge.plugin.Plugin)1 EventMode (org.openksavi.sponge.rule.EventMode)1 RuleAdapter (org.openksavi.sponge.rule.RuleAdapter)1 RuleEventSpec (org.openksavi.sponge.rule.RuleEventSpec)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1