public Single<String> selectVariant(Request request){ return loadVariants() .flatMap(variants -> { // no variant if(variants.variants.isEmpty()) return Single.just(variants.defaultTemplate); Variant selectedVariant = request.selectVariant(new ArrayList<>(variants.variants.keySet())); // no acceptable variant if(selectedVariant == null) { // if it does not exist, that's special String template = variants.defaultTemplate; FileSystem fs = AppGlobals.get().getVertx().fileSystem(); return fs.rxExists(template) .map(exists -> { if(exists) return template; throw new WebApplicationException(Status.NOT_ACCEPTABLE); }); } return Single.just(variants.variants.get(selectedVariant)); }); }
public Single<String> selectVariant(Request request){ return loadVariants() .flatMap(variants -> { // no variant if(variants.variants.isEmpty()) return Single.just(variants.defaultTemplate); Variant selectedVariant = request.selectVariant(new ArrayList<>(variants.variants.keySet())); // no acceptable variant if(selectedVariant == null) { // if it does not exist, that's special String template = variants.defaultTemplate; FileSystem fs = AppGlobals.get().getVertx().fileSystem(); return fs.rxExists(template) .map(exists -> { if(exists) return template; throw new WebApplicationException(Status.NOT_ACCEPTABLE); }); } return Single.just(variants.variants.get(selectedVariant)); }); }
private Single<JsonObject> loadConfig(JsonObject config) { if(config != null) { AppGlobals.get().setConfig(config); return Single.just(config); } String path = "conf/config.json"; return vertx.fileSystem().rxExists(path) .flatMap(exists -> { if(exists) { ConfigStoreOptions fileStore = new ConfigStoreOptions() .setType("file") .setConfig(new JsonObject().put("path", path)); ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions() .addStore(fileStore); ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions); return retriever.rxGetConfig().map(loadedConfig -> { AppGlobals.get().setConfig(loadedConfig); return loadedConfig; }); } else { // empty config JsonObject emptyConfig = new JsonObject(); AppGlobals.get().setConfig(emptyConfig); return Single.just(emptyConfig); } }); }
protected Single<JsonObject> loadConfig(JsonObject config) { if(config != null) { AppGlobals.get().setConfig(config); return Single.just(config); } String path = "conf/config.json"; return vertx.fileSystem().rxExists(path) .flatMap(exists -> { if(exists) { ConfigStoreOptions fileStore = new ConfigStoreOptions() .setType("file") .setConfig(new JsonObject().put("path", path)); ConfigRetrieverOptions configRetrieverOptions = new ConfigRetrieverOptions() .addStore(fileStore); ConfigRetriever retriever = ConfigRetriever.create(vertx, configRetrieverOptions); return retriever.rxGetConfig().map(loadedConfig -> { AppGlobals.get().setConfig(loadedConfig); return loadedConfig; }); } else { // empty config JsonObject emptyConfig = new JsonObject(); AppGlobals.get().setConfig(emptyConfig); return Single.just(emptyConfig); } }); }