Skip to content

Commit

Permalink
Merge pull request #8 from qbicsoftware/feature/transfer-to-seek
Browse files Browse the repository at this point in the history
Feature/transfer to seek
  • Loading branch information
wow-such-code authored Oct 7, 2024
2 parents 7b20a9c + a87fed8 commit bd16a56
Show file tree
Hide file tree
Showing 24 changed files with 2,608 additions and 54 deletions.
105 changes: 89 additions & 16 deletions src/main/java/life/qbic/io/commandline/AuthenticationOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.StringJoiner;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
Expand All @@ -23,26 +25,32 @@ public class AuthenticationOptions {
description = "openBIS user name")
private String openbisUser;
@ArgGroup(multiplicity = "1") // ensures the password is provided once with at least one of the possible options.
PasswordOptions openbisPasswordOptions;
OpenbisPasswordOptions openbisPasswordOptions;
@ArgGroup(multiplicity = "1")
SeekPasswordOptions seekPasswordOptions;

@Option(
names = {"-as", "-as_url"},
description = "ApplicationServer URL",
description = "OpenBIS ApplicationServer URL",
scope = CommandLine.ScopeType.INHERIT)
private String as_url;

@Option(
names = {"-dss", "-dss_url"},
description = "DatastoreServer URL",
names = {"-dss", "--dss_url"},
description = "OpenBIS DatastoreServer URL",
scope = CommandLine.ScopeType.INHERIT)
private String dss_url;

@Option(
names = {"-config", "-config_file"},
description = "Config file path to provide openbis server information.",
names = {"-config", "--config_file"},
description = "Config file path to provide server and user information.",
scope = CommandLine.ScopeType.INHERIT)
public String configPath;

@Option(
names = {"-su", "--seek-user"},
description = "Seek user name (email)",
scope = CommandLine.ScopeType.INHERIT)
private String seekUser;
@Option(
names = {"-seek-server", "-seek_url"},
description = "SEEK API URL",
Expand All @@ -52,45 +60,76 @@ public class AuthenticationOptions {
public String getOpenbisUser() {
if(openbisUser == null & configPath!=null && !configPath.isBlank()) {
openbisUser = ReadProperties.getProperties(configPath).get("user");
} else {
log.error("No openBIS user provided.");
System.exit(2);
}
return openbisUser;
}

public String getSeekUser() {
if(seekUser == null & configPath!=null && !configPath.isBlank()) {
seekUser = ReadProperties.getProperties(configPath).get("seek_user");
} else {
log.error("No SEEK user/email provided.");
System.exit(2);
}
return seekUser;
}

public String getSeekURL() {
log.error("No URL to the SEEK address provided.");
System.exit(2);
if(seek_url == null & configPath!=null && !configPath.isBlank()) {
seek_url = ReadProperties.getProperties(configPath).get("seek_url");
} else {
log.error("No URL to the SEEK address provided.");
System.exit(2);
}
return seek_url;
}

public String getDSS() {
public String getOpenbisDSS() {
if(dss_url == null & configPath!=null && !configPath.isBlank()) {
dss_url = ReadProperties.getProperties(configPath).get("dss");
}
return dss_url;
}

public String getAS() {
public String getOpenbisAS() {
if(as_url == null & configPath!=null && !configPath.isBlank()) {
as_url = ReadProperties.getProperties(configPath).get("as");
}
return as_url;
}

public char[] getSeekPassword() {
return seekPasswordOptions.getPassword();
}

public char[] getOpenbisPassword() {
return openbisPasswordOptions.getPassword();
}

public String getOpenbisBaseURL() throws MalformedURLException {
URL asURL = new URL(as_url);
String res = asURL.getProtocol()+ "://" +asURL.getHost();
if(asURL.getPort()!=-1) {
res+=":"+asURL.getPort();
}
System.err.println(res);
return res;
}

/**
* <a href="https://picocli.info/#_optionally_interactive">official picocli documentation example</a>
*/
static class PasswordOptions {
@Option(names = "--password:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
static class OpenbisPasswordOptions {
@Option(names = "--openbis-pw:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
protected String passwordEnvironmentVariable = "";

@Option(names = "--password:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
@Option(names = "--openbis-pw:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
protected String passwordProperty = "";

@Option(names = "--password", arity = "0", description = "please provide your password", interactive = true)
@Option(names = "--openbis-pw", arity = "0", description = "please provide your openBIS password", interactive = true)
protected char[] password = null;

/**
Expand All @@ -116,9 +155,43 @@ char[] getPassword() {
System.exit(2);
return null; // not reachable due to System.exit in previous line
}

}

static class SeekPasswordOptions {
@Option(names = "--seek-pw:env", arity = "1", paramLabel = "<environment-variable>", description = "provide the name of an environment variable to read in your password from")
protected String passwordEnvironmentVariable = "";

@Option(names = "--seek-pw:prop", arity = "1", paramLabel = "<system-property>", description = "provide the name of a system property to read in your password from")
protected String passwordProperty = "";

@Option(names = "--seek-pw", arity = "0", description = "please provide your SEEK password", interactive = true)
protected char[] password = null;

/**
* Gets the password. If no password is provided, the program exits.
* @return the password provided by the user.
*/
char[] getPassword() {
if (nonNull(password)) {
return password;
}
// System.getProperty(String key) does not work for empty or blank keys.
if (!passwordProperty.isBlank()) {
String systemProperty = System.getProperty(passwordProperty);
if (nonNull(systemProperty)) {
return systemProperty.toCharArray();
}
}
String environmentVariable = System.getenv(passwordEnvironmentVariable);
if (nonNull(environmentVariable) && !environmentVariable.isBlank()) {
return environmentVariable.toCharArray();
}
log.error("No password provided. Please provide your password.");
System.exit(2);
return null; // not reachable due to System.exit in previous line
}

}
@Override
public String toString() {
return new StringJoiner(", ", AuthenticationOptions.class.getSimpleName() + "[", "]")
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/life/qbic/io/commandline/CommandLineOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

// main command with format specifiers for the usage help message
@Command(name = "openbis-scripts",
subcommands = { SampleHierarchyCommand.class, FindDatasetsCommand.class, DownloadPetabCommand.class,
UploadPetabResultCommand.class, UploadDatasetCommand.class, SpaceStatisticsCommand.class },
description = "A client software for querying openBIS.",
mixinStandardHelpOptions = true, versionProvider = ManifestVersionProvider.class)
subcommands = {SampleHierarchyCommand.class, TransferSampleTypesToSeekCommand.class,
DownloadPetabCommand.class, UploadPetabResultCommand.class, UploadDatasetCommand.class,
SpaceStatisticsCommand.class, TransferDataToSeekCommand.class, FindDatasetsCommand.class},
description = "A client software for querying openBIS.",
mixinStandardHelpOptions = true, versionProvider = ManifestVersionProvider.class)
public class CommandLineOptions {

private static final Logger LOG = LogManager.getLogger(CommandLineOptions.class);

@Option(names = {"-V", "--version"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DownloadPetabCommand implements Runnable {

@Override
public void run() {
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS(), auth.getDSS());
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getOpenbisAS(), auth.getOpenbisDSS());
OpenbisConnector openbis = new OpenbisConnector(authentication);

List<DataSet> datasets = openbis.findDataSets(Collections.singletonList(datasetCode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void run() {
} else {
System.out.println("Querying experiment in all available spaces...");
}
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS());
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getOpenbisAS());
OpenbisConnector openbis = new OpenbisConnector(authentication);
List<DataSet> datasets = openbis.listDatasetsOfExperiment(spaces, experimentCode).stream()
.sorted(Comparator.comparing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void run() {
} else {
summary.add("Querying samples in all available spaces...");
}
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS());
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getOpenbisAS());
OpenbisConnector openbis = new OpenbisConnector(authentication);
Map<SampleTypeConnection, Integer> hierarchy = openbis.queryFullSampleHierarchy(spaces);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void run() {
} else {
summary.add("Querying samples in all available spaces...");
}
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getAS());
OpenBIS authentication = App.loginToOpenBIS(auth.getOpenbisPassword(), auth.getOpenbisUser(), auth.getOpenbisAS());
OpenbisConnector openbis = new OpenbisConnector(authentication);

if (spaces.isEmpty()) {
Expand Down
Loading

0 comments on commit bd16a56

Please sign in to comment.