Skip to content

Commit

Permalink
Several configuration improvements:
Browse files Browse the repository at this point in the history
 * we can use Maven profiles to setup the configuration connection
 * Load CLI accepts database credentials
  • Loading branch information
imedina committed Jul 20, 2016
1 parent af561e8 commit 925b6d3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public class LoadCommandOptions {
@Parameter(names = {"--database"}, description = "Data model type to be loaded, i.e. genome, gene, ...", required = false, arity = 1)
public String database;

@Parameter(names = {"--host"}, description = "...", required = false, arity = 1)
public String host = "localhost";

@Parameter(names = {"--port"}, description = "...", required = false, arity = 1)
public int port = 7687;

@Parameter(names = {"-u", "--user"}, description = "Data model type to be loaded, i.e. genome, gene, ...", required = false, arity = 1)
public String user;

@Parameter(names = {"-p", "--password"}, description = "Data model type to be loaded, i.e. genome, gene, ...", password = true, arity = 1)
public String password;

@Parameter(names = {"-l", "--loader"}, description = "Database specific data loader to be used", required = false, arity = 1)
public String loader = "org.opencb.bionetdb.core.neo4j.Neo4JNetworkDBAdaptor";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.opencb.bionetdb.app.cli;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import org.opencb.bionetdb.core.api.NetworkDBAdaptor;
import org.opencb.bionetdb.core.config.DatabaseConfiguration;
import org.opencb.bionetdb.core.io.BioPaxParser;
import org.opencb.bionetdb.core.models.Network;
import org.opencb.bionetdb.core.neo4j.Neo4JNetworkDBAdaptor;
import org.opencb.commons.utils.FileUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

Expand All @@ -35,11 +32,19 @@ public void execute() {
BioPaxParser bioPaxParser = new BioPaxParser("L3");
Network network = bioPaxParser.parse(inputPath);

// ObjectReader objectReader = new ObjectMapper().readerFor(Network.class);
// Network network = objectReader.readValue(Files.newBufferedReader(inputPath));
if (loadCommandOptions.database == null || loadCommandOptions.database.isEmpty()) {
loadCommandOptions.database = "unknown";

NetworkDBAdaptor networkDBAdaptor = new Neo4JNetworkDBAdaptor(loadCommandOptions.database, configuration, true);
DatabaseConfiguration databaseConfiguration = new DatabaseConfiguration(loadCommandOptions.database, null);
databaseConfiguration.setHost(loadCommandOptions.host);
databaseConfiguration.setPort(loadCommandOptions.port);
databaseConfiguration.setUser(loadCommandOptions.user);
databaseConfiguration.setPassword(loadCommandOptions.password);

configuration.getDatabases().add(databaseConfiguration);
}

NetworkDBAdaptor networkDBAdaptor = new Neo4JNetworkDBAdaptor(loadCommandOptions.database, configuration, true);
networkDBAdaptor.insert(network, null);

} catch (Exception e) {
Expand Down
9 changes: 9 additions & 0 deletions bionetdb-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

</project>
10 changes: 5 additions & 5 deletions bionetdb-core/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ defaultDatabase: "scerevisiae"
logLevel: null
logFile: null
databases:
- id: "scerevisiae"
host: "localhost"
port: "7687"
user: "neo4j"
password: "neo4j"
- id: "${BIONETDB.DATABASE}"
host: "${BIONETDB.CATALOG.DB.HOST}"
port: "${BIONETDB.CATALOG.DB.PORT}"
user: "${BIONETDB.CATALOG.DB.USER}"
password: "${BIONETDB.CATALOG.DB.PASSWORD}"
options: null
- id: "hsapiens"
host: "localhost"
Expand Down
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@
</plugins>
</build>

<profiles>
<profile>
<id>default-config</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<opencga.war.name>opencga-${bionetdb.version}</opencga.war.name>

<BIONETDB.DATABASE>scerevisiae</BIONETDB.DATABASE>
<BIONETDB.CATALOG.DB.HOST>localhost</BIONETDB.CATALOG.DB.HOST>
<BIONETDB.CATALOG.DB.PORT>7687</BIONETDB.CATALOG.DB.PORT>
<BIONETDB.CATALOG.DB.USER></BIONETDB.CATALOG.DB.USER>
<BIONETDB.CATALOG.DB.PASSWORD></BIONETDB.CATALOG.DB.PASSWORD>
</properties>
</profile>
</profiles>
<distributionManagement>
<repository>
<id>ossrh</id>
Expand Down

0 comments on commit 925b6d3

Please sign in to comment.