Search in sources :

Example 6 with Buffer

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;
}
Also used : Buffer(io.vertx.rxjava.core.buffer.Buffer) Tuple2(io.vavr.Tuple2) ArrayList(java.util.ArrayList) File(java.io.File) DecodeException(io.vertx.core.json.DecodeException)

Aggregations

Buffer (io.vertx.rxjava.core.buffer.Buffer)6 DecodeException (io.vertx.core.json.DecodeException)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Tuple2 (io.vavr.Tuple2)2 JsonObject (io.vertx.core.json.JsonObject)2 AbstractVerticle (io.vertx.rxjava.core.AbstractVerticle)2 AddressConstants (io.georocket.constants.AddressConstants)1 ConfigConstants (io.georocket.constants.ConfigConstants)1 XMLCRSIndexer (io.georocket.index.xml.XMLCRSIndexer)1 Result (io.georocket.input.Splitter.Result)1 GeoJsonSplitter (io.georocket.input.geojson.GeoJsonSplitter)1 FirstLevelSplitter (io.georocket.input.xml.FirstLevelSplitter)1 XMLSplitter (io.georocket.input.xml.XMLSplitter)1 ChunkMeta (io.georocket.storage.ChunkMeta)1 IndexMeta (io.georocket.storage.IndexMeta)1 RxStore (io.georocket.storage.RxStore)1 StoreFactory (io.georocket.storage.StoreFactory)1 HttpException (io.georocket.util.HttpException)1 JsonParserOperator (io.georocket.util.JsonParserOperator)1