-
Notifications
You must be signed in to change notification settings - Fork 1
allows to list existing and upload new datasets #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7656e04
2f525bd
e56f4b8
db4d888
3a99d0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package life.qbic.io.commandline; | ||
|
||
import ch.ethz.sis.openbis.generic.OpenBIS; | ||
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; | ||
import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; | ||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import life.qbic.App; | ||
import life.qbic.model.download.OpenbisConnector; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "list-data", | ||
description = "lists datasets and their details for a given experiment code") | ||
public class DownloadDatasetCommand implements Runnable { | ||
|
||
@Parameters(arity = "1", paramLabel = "experiment", description = "The code of the experiment data is attached to") | ||
private String experimentCode; | ||
@Option(arity = "1", paramLabel = "<space>", description = "Optional openBIS spaces to filter results", names = {"-s", "--space"}) | ||
private String space; | ||
@Mixin | ||
AuthenticationOptions auth = new AuthenticationOptions(); | ||
|
||
@Override | ||
public void run() { | ||
List<String> spaces = new ArrayList<>(); | ||
if (space != null) { | ||
System.out.println("Querying experiment in space: " + space + "..."); | ||
spaces.add(space); | ||
} else { | ||
System.out.println("Querying experiment in all available spaces..."); | ||
} | ||
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Down the line the printing could be done in a seperate method to keep the logic seperated |
||
OpenBIS authentication = App.loginToOpenBIS(auth.getPassword(), auth.getUser(), auth.getAS()); | ||
OpenbisConnector openbis = new OpenbisConnector(authentication); | ||
List<DataSet> datasets = openbis.listDatasetsOfExperiment(spaces, experimentCode).stream() | ||
.sorted(Comparator.comparing( | ||
(DataSet d) -> d.getExperiment().getProject().getSpace().getCode())).collect( | ||
Collectors.toList()); | ||
int datasetIndex = 0; | ||
for (DataSet dataSet : datasets) { | ||
datasetIndex++; | ||
System.out.println("["+datasetIndex+"]"); | ||
System.out.println(dataSet.getExperiment().getIdentifier()); | ||
System.out.println(dataSet.getCode()); | ||
System.out.println(dataSet.getType().getCode()); | ||
System.out.println(dataSet.getRegistrationDate()); | ||
System.out.println(new SimpleDateFormat("MM-dd-yyyy").format(dataSet.getRegistrationDate())); | ||
Person person = dataSet.getRegistrator(); | ||
System.out.println(person.getFirstName() + " " + person.getLastName()); | ||
System.out.println(); | ||
} | ||
} | ||
|
||
private String getTimeStamp() { | ||
final String PATTERN_FORMAT = "YYYY-MM-dd_HHmmss"; | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_FORMAT); | ||
return LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC).format(formatter); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package life.qbic.io.commandline; | ||
|
||
import ch.ethz.sis.openbis.generic.OpenBIS; | ||
import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; | ||
import ch.ethz.sis.openbis.generic.asapi.v3.dto.person.Person; | ||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import life.qbic.App; | ||
import life.qbic.model.download.OpenbisConnector; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Mixin; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
@Command(name = "list-data", | ||
description = "lists datasets and their details for a given experiment code") | ||
public class FindDatasetsCommand implements Runnable { | ||
|
||
@Parameters(arity = "1", paramLabel = "experiment", description = "The code of the experiment data is attached to") | ||
private String experimentCode; | ||
@Option(arity = "1", paramLabel = "<space>", description = "Optional openBIS spaces to filter samples", names = {"-s", "--space"}) | ||
private String space; | ||
@Mixin | ||
AuthenticationOptions auth = new AuthenticationOptions(); | ||
|
||
@Override | ||
public void run() { | ||
List<String> spaces = new ArrayList<>(); | ||
if (space != null) { | ||
System.out.println("Querying experiment in space: " + space + "..."); | ||
spaces.add(space); | ||
} else { | ||
System.out.println("Querying experiment in all available spaces..."); | ||
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: As previously mentioned, maybe a print class with distinct methods makes sense to avoid cluttering the code? |
||
} | ||
OpenBIS authentication = App.loginToOpenBIS(auth.getPassword(), auth.getUser(), auth.getAS()); | ||
OpenbisConnector openbis = new OpenbisConnector(authentication); | ||
List<DataSet> datasets = openbis.listDatasetsOfExperiment(spaces, experimentCode).stream() | ||
.sorted(Comparator.comparing( | ||
(DataSet d) -> d.getExperiment().getProject().getSpace().getCode())).collect( | ||
Collectors.toList()); | ||
int datasetIndex = 0; | ||
System.out.println(); | ||
System.out.printf("Found %s datasets for experiment %s:%n", datasets.size(), experimentCode); | ||
for (DataSet dataSet : datasets) { | ||
datasetIndex++; | ||
System.out.println("["+datasetIndex+"]"); | ||
System.out.printf("ID: %s (%s)%n", dataSet.getCode(), dataSet.getExperiment().getIdentifier()); | ||
System.out.println("Type: "+dataSet.getType().getCode()); | ||
Person person = dataSet.getRegistrator(); | ||
String simpleTime = new SimpleDateFormat("MM-dd-yy HH:mm:ss").format(dataSet.getRegistrationDate()); | ||
String name = person.getFirstName() +" "+ person.getLastName(); | ||
String uploadedBy = "Uploaded by "+name+" ("+simpleTime+")"; | ||
System.out.println(uploadedBy); | ||
System.out.println(); | ||
} | ||
} | ||
|
||
private String getTimeStamp() { | ||
final String PATTERN_FORMAT = "YYYY-MM-dd_HHmmss"; | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_FORMAT); | ||
return LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC).format(formatter); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.