From 0d051b74415094f6d7d04a10598b2d48b71e8990 Mon Sep 17 00:00:00 2001 From: PrakruthiSomashekar Date: Sat, 29 May 2021 23:45:44 +0530 Subject: [PATCH] #307 - Allow editing settings in Query-to-File --- src/main/java/org/polypheny/qtf/Main.java | 8 -- src/main/java/org/polypheny/qtf/MainApp.java | 24 +++--- .../java/org/polypheny/qtf/QTFConfig.java | 38 ++++---- .../org/polypheny/qtf/QueryInterface.java | 6 +- .../org/polypheny/qtf/StartUpController.java | 86 +++++++++++++++++++ .../java/org/polypheny/qtf/fuse/ResultFS.java | 5 +- src/main/resources/fxml/startup.fxml | 31 +++++++ 7 files changed, 155 insertions(+), 43 deletions(-) create mode 100644 src/main/java/org/polypheny/qtf/StartUpController.java create mode 100644 src/main/resources/fxml/startup.fxml diff --git a/src/main/java/org/polypheny/qtf/Main.java b/src/main/java/org/polypheny/qtf/Main.java index db4371c..9471ba3 100644 --- a/src/main/java/org/polypheny/qtf/Main.java +++ b/src/main/java/org/polypheny/qtf/Main.java @@ -20,8 +20,6 @@ public class Main { public static void main( String[] args ) { - Main main = new Main(); - main.loadLibFuse(); if ( args.length > 0 ) { String runConsole = args[0]; if ( runConsole.equals( "console" ) ) { @@ -34,11 +32,5 @@ public static void main( String[] args ) { } } - public void loadLibFuse() { - //see https://github.com/RaiMan/SikuliX1/issues/350 - // and https://stackoverflow.com/questions/2370545/how-do-i-make-a-target-library-available-to-my-java-app - System.setProperty( "jna.library.path", QTFConfig.getLibraryPath() ); - System.load( QTFConfig.getLibfuse() ); - } } diff --git a/src/main/java/org/polypheny/qtf/MainApp.java b/src/main/java/org/polypheny/qtf/MainApp.java index 10a3221..15e9d45 100644 --- a/src/main/java/org/polypheny/qtf/MainApp.java +++ b/src/main/java/org/polypheny/qtf/MainApp.java @@ -18,6 +18,8 @@ import java.io.IOException; +import java.util.ResourceBundle; + import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -34,26 +36,22 @@ public static void run( String[] args ) { } @Override - public void start( Stage primaryStage ) { + public void start( Stage stage ) { Parent root = null; FXMLLoader loader = null; - //from https://stackoverflow.com/questions/24254000/how-to-force-anti-aliasing-in-javafx-fonts - System.setProperty( "prism.lcdtext", "false" ); try { - loader = new FXMLLoader( getClass().getResource( "/fxml/sample.fxml" ) ); + loader = new FXMLLoader( getClass().getResource( "/fxml/startup.fxml" ) ); + loader.setResources(ResourceBundle.getBundle("config")); root = loader.load(); } catch ( IOException e ) { log.error( "Could not load fxml", e ); System.exit( 1 ); } - //see https://stackoverflow.com/questions/36981599/fxml-minheight-minwidth-attributs-ignored - primaryStage.setMinWidth( root.minWidth( -1 ) ); - primaryStage.setMinHeight( root.minHeight( -1 ) ); - primaryStage.setTitle( "Polypheny-DB Query-To-File" ); - primaryStage.setScene( new Scene( root ) ); - primaryStage.show(); - //see https://stackoverflow.com/questions/44439408/javafx-controller-detect-when-stage-is-closing - Controller controller = loader.getController(); - primaryStage.setOnHidden( e -> controller.shutdown() ); + + stage.setMinWidth( root.minWidth( -1 ) ); + stage.setMinHeight( root.minHeight( -1 ) ); + stage.setTitle( "Edit Settings" ); + stage.setScene( new Scene( root ) ); + stage.show(); } } diff --git a/src/main/java/org/polypheny/qtf/QTFConfig.java b/src/main/java/org/polypheny/qtf/QTFConfig.java index 69ffb28..57e206e 100644 --- a/src/main/java/org/polypheny/qtf/QTFConfig.java +++ b/src/main/java/org/polypheny/qtf/QTFConfig.java @@ -44,25 +44,25 @@ public class QTFConfig { } - public static String getFileUrl( String fileName ) { - return String.format( "http://%s:%s/getFile/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), fileName ); - } - - public static String getRestInterface( String method ) { - return String.format( "http://%s:%s/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), method ); - } - - public static String getWebSocketUrl() { - return String.format( "ws://%s:%s/webSocket", prop.getProperty( "host" ), prop.getProperty( "port" ) ); - } - - public static String getLibraryPath() { - return prop.getProperty( "libraryPath" ); - } - - public static String getLibfuse() { - return getLibraryPath() + prop.getProperty( "libfuse" ); - } +// public static String getFileUrl( String fileName ) { +// return String.format( "http://%s:%s/getFile/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), fileName ); +// } +// +// public static String getRestInterface( String method ) { +// return String.format( "http://%s:%s/%s", prop.getProperty( "host" ), prop.getProperty( "port" ), method ); +// } +// +// public static String getWebSocketUrl() { +// return String.format( "ws://%s:%s/webSocket", prop.getProperty( "host" ), prop.getProperty( "port" ) ); +// } + +// public static String getLibraryPath() { +// return prop.getProperty( "libraryPath" ); +// } + +// public static String getLibfuse() { +// return getLibraryPath() + prop.getProperty( "libfuse" ); +// } public static int getFuseCapacityGB() { diff --git a/src/main/java/org/polypheny/qtf/QueryInterface.java b/src/main/java/org/polypheny/qtf/QueryInterface.java index 09dfbd5..7cb0368 100644 --- a/src/main/java/org/polypheny/qtf/QueryInterface.java +++ b/src/main/java/org/polypheny/qtf/QueryInterface.java @@ -34,6 +34,8 @@ import org.polypheny.qtf.web.SocketClient; import org.polypheny.qtf.web.UIRequest.QueryRequest; import org.polypheny.qtf.web.UIRequest.TableRequest; +import static org.polypheny.qtf.StartUpController.getHost; +import static org.polypheny.qtf.StartUpController.getPortNbr; @Slf4j @@ -54,7 +56,7 @@ public QueryInterface() { //myFuse.umount(); myFuse.mount( root.toPath(), false, false ); try { - this.socketClient = new SocketClient( new URI( QTFConfig.getWebSocketUrl() ), myFuse, this ); + this.socketClient = new SocketClient( new URI( String.format( "ws://%s:%s/webSocket", getHost(), getPortNbr() ) ), myFuse, this ); log.info( "Connecting to websocket..." ); if ( socketClient.connectBlocking() ) { log.info( "Established a connection with the websocket" ); @@ -87,7 +89,7 @@ Result commit() { } BatchUpdateRequest request = myFuse.getBatchUpdateRequest(); //multiPartContent: see https://github.com/Kong/unirest-java/issues/165 - MultipartBody body = Unirest.post( QTFConfig.getRestInterface( "batchUpdate" ) ).multiPartContent(); + MultipartBody body = Unirest.post( String.format( "http://%s:%s/%s", getHost(), getPortNbr(), "batchUpdate" ) ).multiPartContent(); int counter = 0; for ( Update update : request.getUpdates() ) { for ( Value value : update.getNewValues().values() ) { diff --git a/src/main/java/org/polypheny/qtf/StartUpController.java b/src/main/java/org/polypheny/qtf/StartUpController.java new file mode 100644 index 0000000..5e8ad89 --- /dev/null +++ b/src/main/java/org/polypheny/qtf/StartUpController.java @@ -0,0 +1,86 @@ +package org.polypheny.qtf; + +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; + +@Slf4j +public class StartUpController implements Initializable { + + @FXML + private TextField hostName; + @FXML + private TextField port; + @FXML + private TextField libraryPath; + @FXML + private TextField libfuse; + + private static String host; + private static String portNbr; + + public StartUpController(){ + } + + @FXML + public void submit() { + host = hostName.getText(); + portNbr = port.getText(); + + libfuse.getScene().getWindow().hide(); + loadLibFuse(); + + Parent root = null; + FXMLLoader loader = null; + //from https://stackoverflow.com/questions/24254000/how-to-force-anti-aliasing-in-javafx-fonts + System.setProperty( "prism.lcdtext", "false" ); + try { + loader = new FXMLLoader( getClass().getResource( "/fxml/sample.fxml" ) ); + root = loader.load(); + } catch ( IOException e ) { + log.error( "Could not load fxml", e ); + System.exit( 1 ); + } + Stage primaryStage = new Stage(); + //see https://stackoverflow.com/questions/36981599/fxml-minheight-minwidth-attributs-ignored + primaryStage.setMinWidth( root.minWidth( -1 ) ); + primaryStage.setMinHeight( root.minHeight( -1 ) ); + primaryStage.setTitle( "Polypheny-DB Query-To-File" ); + primaryStage.setScene( new Scene( root ) ); + primaryStage.show(); + //see https://stackoverflow.com/questions/44439408/javafx-controller-detect-when-stage-is-closing + Controller controller = loader.getController(); + primaryStage.setOnHidden( e -> controller.shutdown() ); + } + + public static String getHost() { + return host; + } + + public static String getPortNbr() { + return portNbr; + } + + + public void loadLibFuse() { + //see https://github.com/RaiMan/SikuliX1/issues/350 + // and https://stackoverflow.com/questions/2370545/how-do-i-make-a-target-library-available-to-my-java-app + System.setProperty( "jna.library.path", libraryPath.getText() ); + System.load( libraryPath.getText() + libfuse.getText() ); + } + + @Override + public void initialize( URL url, ResourceBundle resourceBundle ) { + + } + +} diff --git a/src/main/java/org/polypheny/qtf/fuse/ResultFS.java b/src/main/java/org/polypheny/qtf/fuse/ResultFS.java index a512cba..f774bc0 100644 --- a/src/main/java/org/polypheny/qtf/fuse/ResultFS.java +++ b/src/main/java/org/polypheny/qtf/fuse/ResultFS.java @@ -42,6 +42,9 @@ import ru.serce.jnrfuse.struct.FuseFileInfo; import ru.serce.jnrfuse.struct.Statvfs; +import static org.polypheny.qtf.StartUpController.getHost; +import static org.polypheny.qtf.StartUpController.getPortNbr; + @Slf4j //see https://github.com/SerCeMan/jnr-fuse/blob/master/src/main/java/ru/serce/jnrfuse/examples/MemoryFS.java @@ -260,7 +263,7 @@ private int read( Pointer buffer, long size, long offset ) { } private HttpResponse restRequest( final String fileUrl ) { - return Unirest.get( QTFConfig.getFileUrl( fileUrl ) ).asBytes(); + return Unirest.get( String.format( "http://%s:%s/getFile/%s", getHost(), getPortNbr(), fileUrl ) ).asBytes(); } private synchronized void truncate( long size ) { diff --git a/src/main/resources/fxml/startup.fxml b/src/main/resources/fxml/startup.fxml new file mode 100644 index 0000000..3c3b8e5 --- /dev/null +++ b/src/main/resources/fxml/startup.fxml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + +