use of org.folio.rulez.Rules in project raml-module-builder by folio-org.
the class RestVerticle method cmdProcessing.
private void cmdProcessing() throws Exception {
String importDataPath = null;
String droolsPath = null;
// TODO need to add a normal command line parser
List<String> cmdParams = processArgs();
if (cmdParams != null) {
for (Iterator iterator = cmdParams.iterator(); iterator.hasNext(); ) {
String param = (String) iterator.next();
if (param.startsWith("-Dhttp.port=")) {
port = Integer.parseInt(param.split("=")[1]);
LogUtil.formatLogMessage(className, "cmdProcessing", "port to listen on " + port);
} else if (param.startsWith("drools_dir=")) {
droolsPath = param.split("=")[1];
LogUtil.formatLogMessage(className, "cmdProcessing", "Drools rules file dir set to " + droolsPath);
} else if (param.startsWith("debug_log_package=")) {
String debugPackage = param.split("=")[1];
if (debugPackage != null && debugPackage.length() > 0) {
LogUtil.formatLogMessage(className, "cmdProcessing", "Setting package " + debugPackage + " to debug");
LogUtil.updateLogConfiguration(debugPackage, "FINE");
}
} else if (param.startsWith("db_connection=")) {
String dbconnection = param.split("=")[1];
PostgresClient.setConfigFilePath(dbconnection);
PostgresClient.setIsEmbedded(false);
LogUtil.formatLogMessage(className, "cmdProcessing", "Setting path to db config file.... " + dbconnection);
} else if (param.startsWith("embed_postgres=true")) {
// allow setting config() from unit test mode which runs embedded
LogUtil.formatLogMessage(className, "cmdProcessing", "Using embedded postgres... starting... ");
// this blocks
PostgresClient.setIsEmbedded(true);
PostgresClient.setConfigFilePath(null);
} else if (param != null && param.startsWith("postgres_import_path=")) {
try {
importDataPath = param.split("=")[1];
System.out.println("Setting path to import DB file.... " + importDataPath);
} catch (Exception e) {
// any problems - print exception and continue
log.error(e);
}
} else {
// assume module specific cmd line args with '=' separator
String[] arg = param.split("=");
if (arg.length == 2) {
MODULE_SPECIFIC_ARGS.put(arg[0], arg[1]);
log.info("module specific argument added: " + arg[0] + " with value " + arg[1]);
} else {
log.warn("The following cmd line parameter was skipped, " + param + ". Expected format key=value\nIf this is a " + "JVM argument, pass it before the jar, not after");
}
}
}
if (PostgresClient.isEmbedded() || importDataPath != null) {
PostgresClient.getInstance(vertx).startEmbeddedPostgres();
}
if (importDataPath != null) {
// blocks as well for now
System.out.println("Import DB file.... " + importDataPath);
PostgresClient.getInstance(vertx).importFileEmbedded(importDataPath);
}
}
try {
droolsSession = new Rules(droolsPath).buildSession();
} catch (Exception e) {
log.error(e);
}
}
use of org.folio.rulez.Rules in project raml-module-builder by folio-org.
the class RulesUtil method reloadDrools.
/**
* will overwrite existing drools session and re-create it
* will rules from list
*/
public static void reloadDrools(Vertx vertx, List<String> rules, Handler<AsyncResult<Object>> handler) {
vertx.executeBlocking(doThis -> {
try {
KieSession temp = new Rules(rules).buildSession();
RestVerticle.updateDroolsSession(temp);
doThis.complete();
} catch (Exception e) {
log.error("Unable to load new rules, " + e.getMessage());
doThis.fail("error");
}
}, doThisWhenDone -> {
handler.handle(doThisWhenDone);
});
}
Aggregations