use of org.openksavi.sponge.rule.RuleEventSpec in project sponge by softelnet.
the class AbstractRuleAdapter method setEventSpecs.
public void setEventSpecs(List<Object> events) {
String[] eventNames = new String[events.size()];
String[] eventAliases = new String[events.size()];
EventMode[] modes = new EventMode[events.size()];
for (int i = 0; i < events.size(); i++) {
RuleEventSpec eventSpec = getKnowledgeBase().getInterpreter().getRuleEventSpec(events.get(i));
eventNames[i] = eventSpec.getEventName();
eventAliases[i] = eventSpec.getEventAlias();
modes[i] = eventSpec.getEventMode();
}
setEventNames(eventNames);
setEventAliases(eventAliases);
setEventModes(modes);
}
use of org.openksavi.sponge.rule.RuleEventSpec 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);
}
Aggregations