use of io.vertx.rxjava.core.buffer.Buffer in project rulesservice by genny-project.
the class RulesLoader method processFile.
private static List<Tuple2<String, String>> processFile(String inputFileStr) {
File file = new File(inputFileStr);
String fileName = inputFileStr.replaceFirst(".*/(\\w+).*", "$1");
String fileNameExt = inputFileStr.replaceFirst(".*/\\w+\\.(.*)", "$1");
List<Tuple2<String, String>> rules = new ArrayList<Tuple2<String, String>>();
if (!file.isFile()) {
if (!fileName.startsWith("XX")) {
final List<String> filesList = Vertx.currentContext().owner().fileSystem().readDirBlocking(inputFileStr);
for (final String dirFileStr : filesList) {
// use directory name as
List<Tuple2<String, String>> childRules = processFile(dirFileStr);
// rulegroup
rules.addAll(childRules);
}
}
return rules;
} else {
Buffer buf = Vertx.currentContext().owner().fileSystem().readFileBlocking(inputFileStr);
try {
if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("drl"))) {
// ignore files that start
// with XX
final String ruleText = buf.toString();
Tuple2<String, String> rule = (Tuple.of(fileName + "." + fileNameExt, ruleText));
System.out.println("Loading in Rule:" + rule._1 + " of " + inputFileStr);
rules.add(rule);
} else if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("bpmn"))) {
// ignore files
// that start
// with XX
final String bpmnText = buf.toString();
Tuple2<String, String> bpmn = (Tuple.of(fileName + "." + fileNameExt, bpmnText));
System.out.println("Loading in BPMN:" + bpmn._1 + " of " + inputFileStr);
rules.add(bpmn);
} else if ((!fileName.startsWith("XX")) && (fileNameExt.equalsIgnoreCase("xls"))) {
// ignore files that
// start with XX
final String xlsText = buf.toString();
Tuple2<String, String> xls = (Tuple.of(fileName + "." + fileNameExt, xlsText));
System.out.println("Loading in XLS:" + xls._1 + " of " + inputFileStr);
rules.add(xls);
}
return rules;
} catch (final DecodeException dE) {
}
}
return null;
}
Aggregations