Commit 5849aa6f authored by j.hoerdt's avatar j.hoerdt
Browse files

create SensorTypes at the beginning of a run

parent 80dbefb8
......@@ -20,7 +20,7 @@
!logging.properties
!sensor2graph.properties
!graphdb.gwdg.de.pem
!graphdb_create_sensor_type_info.cypher
!sensor_type_info.json
......
:param sensor_type_info => [
{
props: {
sensor_type: "asdf",
description: "asdf",
instrument_type: "asdf",
manufacturers: "asdf"
},
measured_variables: [
"humidity",
"temp"
]
}
]
unwind $sensor_type_info as sensor_type_info
merge (n:SensorType {sensor_type: sensor_type_info.props.sensor_type})
set n = sensor_type_info.props
with n, sensor_type_info
unwind sensor_type_info.measured_variables as measured_variable
merge (m:MeasuredVariable {variable: measured_variable})
merge (n)-[:MEASURES]->(m)
return n,m
\ No newline at end of file
{
"sensor_type_info": [
{
"measured_variables": [
"humidity",
"temp"
],
"props": {
"manufacturers": "asdf",
"description": "asdf",
"instrument_type": "asdf",
"sensor_type": "asdf"
}
}
]
}
\ No newline at end of file
......@@ -3,6 +3,9 @@ package sensor2graph;
import org.neo4j.driver.*;
import org.neo4j.driver.Config.*;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import sensor2graph.webdirget.*;
import java.io.*;
......@@ -53,8 +56,8 @@ public class Main {
//.withMaxTransactionRetryTime(3, TimeUnit.SECONDS)
//.withLeakedSessionsLogging()
.withMaxConnectionPoolSize(concurrency)
.withEncryption()
.withTrustStrategy(TrustStrategy.trustCustomCertificateSignedBy(neo4j_server_certificate_file))
// .withEncryption()
// .withTrustStrategy(TrustStrategy.trustCustomCertificateSignedBy(neo4j_server_certificate_file))
.build()
);
}
......@@ -162,7 +165,8 @@ public class Main {
try {
test_auth();
run();
pre_run_graphdb_actions();
//run();
} catch (org.neo4j.driver.exceptions.AuthenticationException e) {
Main.logger.log(Level.SEVERE, "Authentication failed, are your credentials correct?");
} catch (Exception e) {
......@@ -242,6 +246,27 @@ public class Main {
}
private static void pre_run_graphdb_actions() throws Exception {
Map<String, Object> parameters = new Gson().fromJson(new FileReader("sensor_type_info.json"), new TypeToken <Map<String, Object>>() {}.getType());
try (var session = Main.driver.session(SessionConfig.forDatabase(Main.database_name))) {
session.writeTransaction(tx -> {
Result res = tx.run(
"unwind $sensor_type_info as sensor_type_info\n" +
"merge (n:SensorType {sensor_type: sensor_type_info.props.sensor_type})\n" +
"set n = sensor_type_info.props\n" +
"with n, sensor_type_info\n" +
"unwind sensor_type_info.measured_variables as measured_variable\n" +
"merge (m:MeasuredVariable {variable: measured_variable})\n" +
"merge (n)-[:MEASURES]->(m)\n" +
"return 1",
parameters
);
return 5;
});
}
}
private static void test_auth() {
Main.logger.fine("testing authentication");
try (Session session = Main.driver.session(SessionConfig.forDatabase(Main.database_name))) {
......
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