66import io .vertx .core .eventbus .DeliveryOptions ;
77import io .vertx .core .eventbus .MessageConsumer ;
88import io .vertx .core .http .HttpServer ;
9+ import io .vertx .core .http .HttpServerRequest ;
910import io .vertx .core .json .JsonObject ;
1011import io .vertx .ext .web .*;
1112import io .vertx .ext .web .handler .*;
@@ -62,6 +63,7 @@ public void start(Future<Void> start) {
6263 context .put ("connected" , ElasticWriter .isConnected ());
6364 context .put ("tls" , Configuration .isElasticTLS ());
6465 context .put ("index" , Configuration .getDefaultIndex ());
66+ context .put ("indexLocked" , Configuration .isIndexLocked ());
6567 context .put ("supportedFiles" , String .join (", " , ParserFactory .getSupportedExtensions ()));
6668 context .next ();
6769 });
@@ -147,7 +149,9 @@ private Future<Integer> onComplete(RoutingContext context, String fileName) {
147149 // when the file has been read from disk, parsed and imported.
148150 return Future .<Integer >future ().setHandler (result -> {
149151 if (result .succeeded ()) {
150- String index = context .request ().params ().get (INDEX );
152+ String index = getIndexFromRequest (context .request ());
153+
154+
151155 logger .info (String .format ("Imported file '%s' successfully into '%s'." , fileName , index ));
152156
153157 context .put (INDEX , index );
@@ -163,14 +167,20 @@ private Future<Integer> onComplete(RoutingContext context, String fileName) {
163167 });
164168 }
165169
170+ private String getIndexFromRequest (HttpServerRequest request ) {
171+ // only read the index from the request if the target index is not locked.
172+ return (Configuration .isIndexLocked ()) ?
173+ Configuration .getDefaultIndex () : request .params ().get (INDEX );
174+ }
175+
166176 /**
167177 * Parses a file upload request, converting the excel payload into json and waits
168178 * for elasticsearch to complete indexing.
169179 *
170180 * @param uploadedFileName the actual file on disk that contains the uploaded file.
171- * @param params upload parameters
172- * @param fileName the name of the uploaded file
173- * @param future callback on completed parse + indexing.
181+ * @param params upload parameters
182+ * @param fileName the name of the uploaded file
183+ * @param future callback on completed parse + indexing.
174184 */
175185 private void parse (String uploadedFileName , MultiMap params , String fileName , Future <Integer > future ) {
176186 vertx .executeBlocking (blocking -> {
0 commit comments