Skip to content

Commit

Permalink
fix: set empty neo4j settings to non empty default values so that the…
Browse files Browse the repository at this point in the history
…y appear in the setting view in local mode
  • Loading branch information
ClemDoum committed Jan 19, 2024
1 parent e7216c5 commit bb51090
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/main/java/org/icij/datashare/Neo4jResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@ public class Neo4jResource implements AutoCloseable {
"Name of the single project which will be able to user the extension when using neo4j"
+ " Community Edition"
),
List.of("neo4jHost", "neo4j", "Hostname of the neo4j DB."),
List.of("neo4jHost", "127.0.0.1", "Hostname of the neo4j DB."),
List.of("neo4jPort", 7687, "Port of the neo4j DB."),
List.of(
"neo4jUriScheme",
"",
"bolt",
"URI scheme used to connect to the neo4j DB (can be: bolt, neo4j, bolt+s, neo4j+s,"
+ " ....)"
),
List.of("neo4jUser", "", "User name used to connect to the neo4j DB"),
List.of("neo4jPassword", "", "Password used to connect to the neo4j DB"),
List.of("neo4jUser", "neo4j", "User name used to connect to the neo4j DB"),
List.of(
"neo4jPassword",
"please-change-this-password",
"Password used to connect to the neo4j DB"
),
List.of(
TASK_POLL_INTERVAL_S,
2,
Expand Down Expand Up @@ -139,9 +143,7 @@ public class Neo4jResource implements AutoCloseable {
protected Neo4jResource(PropertiesProvider propertiesProvider) {
this.propertiesProvider = propertiesProvider;
Properties neo4jDefaultProps = new Properties();
neo4jDefaultProps.putAll(DEFAULT_NEO4J_PROPERTIES_MAP.entrySet().stream()
.filter(entry -> !entry.getValue().isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
neo4jDefaultProps.putAll(DEFAULT_NEO4J_PROPERTIES_MAP);
this.propertiesProvider.mergeWith(neo4jDefaultProps);
this.appLoader = new Neo4jAppLoader(this.propertiesProvider);
this.port = Integer.parseInt(propertiesProvider.get("neo4jAppPort").orElse("8080"));
Expand Down Expand Up @@ -226,10 +228,11 @@ protected void startServerProcess(boolean forceMigrations) {
logger.debug("Copying Datashare properties to temporary location {}",
lazy(propertiesFile::getAbsolutePath));

Properties setProperties = filterUnset(this.propertiesProvider.getProperties());

try {
this.propertiesProvider
.getProperties()
.store(Files.newOutputStream(propertiesFile.toPath().toAbsolutePath()), null);
setProperties.store(
Files.newOutputStream(propertiesFile.toPath().toAbsolutePath()), null);
} catch (IOException e) {
throw new RuntimeException("Failed to write properties in temporary location", e);
}
Expand Down Expand Up @@ -306,6 +309,7 @@ protected void startServerProcess(boolean forceMigrations) {
}
}


protected boolean supportsNeo4jEnterprise() {
checkNeo4jAppStarted();
synchronized (Neo4jResource.class) {
Expand Down Expand Up @@ -613,6 +617,16 @@ private long getDocumentNodesLimit() {
.orElse(NEO4J_DEFAULT_DUMPED_DOCUMENTS);
}

static Properties filterUnset(Properties properties) {
Properties filtered = new Properties(properties.size());
properties.forEach((key, value) -> {
if (!((String) value).isEmpty()) {
filtered.setProperty(key.toString(), value.toString());
}
});
return filtered;
}

@Override
public void close() throws Exception {
this.client.close();
Expand Down

0 comments on commit bb51090

Please sign in to comment.