-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from qbicsoftware/feature/data-options
allows to list existing and upload new datasets
- Loading branch information
Showing
9 changed files
with
494 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/life/qbic/io/commandline/DownloadDatasetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..."); | ||
} | ||
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); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/life/qbic/io/commandline/FindDatasetsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..."); | ||
} | ||
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); | ||
} | ||
} |
Oops, something went wrong.