use of life.genny.qwanda.message.QEventMessage in project rulesservice by genny-project.
the class RulesLoader method generateReports.
/**
* @param vertx
* @return
*/
public static Future<Void> generateReports(final String rulesDir) {
System.out.println("Generating Reports for all realms");
final Future<Void> fut = Future.future();
Vertx.currentContext().owner().executeBlocking(exec -> {
for (String realm : realms) {
// Generate the reports
System.out.println("---- Realm:" + realm + "----------");
EBCHandlers.initMsg("Event:GEN_REPORTS", realm, new QEventMessage("EVT_MSG", "GEN_REPORTS"), CurrentVtxCtx.getCurrentCtx().getClusterVtx().eventBus());
}
System.out.println("Rules Loaded up");
fut.complete();
}, failed -> {
});
return fut;
}
use of life.genny.qwanda.message.QEventMessage in project rulesservice by genny-project.
the class EBCHandlers method registerHandlers.
public static void registerHandlers(final EventBus eventBus) {
Consumer.getFromCmds().subscribe(arg -> {
JsonObject payload = processMessage("Service Command", arg);
if ("CMD_RELOAD_RULES".equals(payload.getString("cmd_type"))) {
if ("RELOAD_RULES_FROM_FILES".equals(payload.getString("code"))) {
String rulesDir = payload.getString("rulesDir");
RulesLoader.loadInitialRules(rulesDir);
}
}
});
Consumer.getFromEvents().subscribe(arg -> {
JsonObject payload = processMessage("Event", arg);
QEventMessage eventMsg = null;
String evtMsg = "Event:";
if (payload.getString("event_type").equals("EVT_ATTRIBUTE_VALUE_CHANGE")) {
eventMsg = JsonUtils.fromJson(payload.toString(), QEventAttributeValueChangeMessage.class);
} else if (payload.getString("event_type").equals("BTN_CLICK")) {
eventMsg = JsonUtils.fromJson(payload.toString(), QEventBtnClickMessage.class);
} else if (payload.getString("event_type").equals("EVT_LINK_CHANGE")) {
eventMsg = JsonUtils.fromJson(payload.toString(), QEventLinkChangeMessage.class);
} else {
try {
eventMsg = JsonUtils.fromJson(payload.toString(), QEventMessage.class);
} catch (NoClassDefFoundError e) {
log.error("No class def found [" + payload.toString() + "]");
}
}
processMsg("Event:" + payload.getString("event_type"), payload.getString("ruleGroup"), eventMsg, eventBus, payload.getString("token"));
});
Consumer.getFromData().subscribe(arg -> {
JsonObject payload = processMessage("Data", arg);
if (payload.getString("msg_type").equalsIgnoreCase("DATA_MSG")) {
// should always be data if coming through
// this channel
QDataAnswerMessage dataMsg = null;
// Is it a Rule?
if (payload.getString("data_type").equals(Rule.class.getSimpleName())) {
JsonArray ja = payload.getJsonArray("items");
String ruleGroup = ja.getJsonObject(0).getString("ruleGroup");
String ruleText = ja.getJsonObject(0).getString("rule");
String ruleCode = ja.getJsonObject(0).getString("code");
// QDataRuleMessage ruleMsg = gson3.fromJson(json, QDataRuleMessage.class);
System.out.println("Incoming Rule :" + ruleText);
if (rulesDir == null) {
rulesDir = "rules";
}
String rulesGroup = rulesDir;
List<Tuple3<String, String, String>> rules = new ArrayList<Tuple3<String, String, String>>();
rules.add(Tuple.of(ruleGroup, ruleCode, ruleText));
RulesLoader.setupKieRules(rulesGroup, rules);
} else if (payload.getString("data_type").equals(Answer.class.getSimpleName())) {
try {
dataMsg = JsonUtils.fromJson(payload.toString(), QDataAnswerMessage.class);
processMsg("Data:" + dataMsg.getData_type(), payload.getString("ruleGroup"), dataMsg, eventBus, payload.getString("token"));
} catch (com.google.gson.JsonSyntaxException e) {
log.error("BAD Syntax converting to json from " + dataMsg);
JsonObject json = new JsonObject(payload.toString());
JsonObject answerData = json.getJsonObject("items");
JsonArray jsonArray = new JsonArray();
jsonArray.add(answerData);
json.put("items", jsonArray);
dataMsg = JsonUtils.fromJson(json.toString(), QDataAnswerMessage.class);
processMsg("Data:" + dataMsg.getData_type(), payload.getString("ruleGroup"), dataMsg, eventBus, payload.getString("token"));
}
} else if (payload.getString("data_type").equals(GPS.class.getSimpleName())) {
QDataGPSMessage dataGPSMsg = null;
try {
dataGPSMsg = JsonUtils.fromJson(payload.toString(), QDataGPSMessage.class);
processMsg("GPS", payload.getString("ruleGroup"), dataGPSMsg, eventBus, payload.getString("token"));
} catch (com.google.gson.JsonSyntaxException e) {
log.error("BAD Syntax converting to json from " + dataGPSMsg);
JsonObject json = new JsonObject(payload.toString());
JsonObject answerData = json.getJsonObject("items");
JsonArray jsonArray = new JsonArray();
jsonArray.add(answerData);
json.put("items", jsonArray);
dataGPSMsg = JsonUtils.fromJson(json.toString(), QDataGPSMessage.class);
processMsg("GPS:" + dataGPSMsg.getData_type(), payload.getString("ruleGroup"), dataGPSMsg, eventBus, payload.getString("token"));
}
} else if (payload.getString("data_type").equals(QDataPaymentsCallbackMessage.class.getSimpleName())) {
QDataPaymentsCallbackMessage dataCallbackMsg = null;
try {
dataCallbackMsg = JsonUtils.fromJson(payload.toString(), QDataPaymentsCallbackMessage.class);
processMsg("Data:" + dataCallbackMsg.getData_type(), payload.getString("ruleGroup"), dataCallbackMsg, eventBus, payload.getString("token"));
} catch (com.google.gson.JsonSyntaxException e) {
log.error("BAD Syntax converting to json from " + dataCallbackMsg);
JsonObject json = new JsonObject(payload.toString());
dataCallbackMsg = JsonUtils.fromJson(json.toString(), QDataPaymentsCallbackMessage.class);
processMsg("Callback:" + dataCallbackMsg.getData_type(), payload.getString("ruleGroup"), dataCallbackMsg, eventBus, payload.getString("token"));
}
}
}
});
}
Aggregations