Commit 8bde568c authored by j.hoerdt's avatar j.hoerdt
Browse files

adapt cli while allowing old arg count

+ refactor
parent b48e1245
......@@ -6,7 +6,6 @@ import org.neo4j.driver.Config.*;
import sensor2graph.webdirget.*;
import java.io.*;
import java.net.PasswordAuthentication;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
......@@ -17,9 +16,8 @@ import java.util.stream.*;
public class Main {
// configurable through command line arguments {
private static String config_file = "sensor2graph.properties";
public static PasswordAuthentication pid_registry_credentials;
// }
// configurable in configuration file {
public static String already_uploaded_days_file;
public static String failed_to_upload_sensors_file;
......@@ -43,10 +41,10 @@ public class Main {
logger = java.util.logging.Logger.getLogger(Main.class.getName());
}
private static void initialize_driver(AuthToken authToken) {
private static void initialize_driver() {
driver = GraphDatabase.driver(
neo4j_uri,
authToken,
AuthTokens.basic(System.getenv("SENSOR2GRAPH_GRAPHDB_USER"), System.getenv("SENSOR2GRAPH_GRAPHDB_PASS")),
Config.builder()
.withLogging(Logging.console(Level.INFO))
//.withConnectionAcquisitionTimeout(20, TimeUnit.SECONDS)
......@@ -160,10 +158,7 @@ public class Main {
System.setProperty("http.agent", http_agent);
Main.logger.fine("initializing neo4j driver.");
initialize_driver(AuthTokens.basic(System.getenv("SENSOR2GRAPH_GRAPHDB_USER"), System.getenv("SENSOR2GRAPH_GRAPHDB_PASS")));
Main.logger.fine("setting pid registry credentials");
pid_registry_credentials = new PasswordAuthentication(System.getenv("SENSOR2GRAPH_PIDREG_USER"), System.getenv("SENSOR2GRAPH_PIDREG_PASS").toCharArray());
initialize_driver();
try {
test_auth();
......@@ -228,7 +223,12 @@ public class Main {
private static boolean check_args(String[] args) {
Main.logger.fine("checking for correct arg count");
if (args.length == 4) {
if (args.length == 0 || args.length == 4) {
return true;
}
if (args.length == 1) {
config_file = args[0];
return true;
}
......@@ -237,7 +237,7 @@ public class Main {
return true;
}
System.out.println("Usage: <this_program> <graphdb_username> <graphdb_password> <pid_registry_username> <pid_registry_password> [config_file]");
System.out.println("Usage: <this_program> [config_file]");
return false;
}
......@@ -248,8 +248,4 @@ public class Main {
session.readTransaction(tx -> tx.run(new Query("match (n) return n limit 3")));
}
}
// private static void print_result(Result result) {
// result.forEachRemaining(record -> System.out.println(record));
// }
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ class Sensor {
private static HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20))
.authenticator(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return Main.pid_registry_credentials;
return new PasswordAuthentication(System.getenv("SENSOR2GRAPH_PIDREG_USER"), System.getenv("SENSOR2GRAPH_PIDREG_PASS").toCharArray());
}
}).build();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment