Skip to content

Commit

Permalink
DD-1605 Implement several dd-dataverse-cli dataset commands - II
Browse files Browse the repository at this point in the history
  • Loading branch information
aliassheikh committed Aug 14, 2024
1 parent 0504900 commit 06c652b
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 138 deletions.
6 changes: 3 additions & 3 deletions src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
import nl.knaw.dans.dvcli.command.CollectionPublish;
import nl.knaw.dans.dvcli.command.CollectionSetMetadataBlocksRoot;
import nl.knaw.dans.dvcli.command.CollectionView;
import nl.knaw.dans.dvcli.command.DatasetRoleAssignment;
import nl.knaw.dans.dvcli.command.DatasetCmd;
import nl.knaw.dans.dvcli.command.DatasetGetFiles;
import nl.knaw.dans.dvcli.command.DatasetDeleteDraft;
import nl.knaw.dans.dvcli.command.DatasetGetFiles;
import nl.knaw.dans.dvcli.command.DatasetGetLatestVersion;
import nl.knaw.dans.dvcli.command.DatasetGetVersion;
import nl.knaw.dans.dvcli.command.DatasetPublish;
import nl.knaw.dans.dvcli.command.DatasetAssignRole;
import nl.knaw.dans.dvcli.config.DdDataverseCliConfig;
import nl.knaw.dans.lib.util.AbstractCommandLineApp;
import nl.knaw.dans.lib.util.PicocliVersionProvider;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void configureCommandLine(CommandLine commandLine, DdDataverseCliConfig c
.addSubcommand(new DatasetGetLatestVersion())
.addSubcommand(new DatasetGetVersion())
.addSubcommand(new DatasetPublish())
.addSubcommand(new DatasetAssignRole())
.addSubcommand(new DatasetRoleAssignment())
);
log.debug("Configuring command line");
}
Expand Down
123 changes: 0 additions & 123 deletions src/main/java/nl/knaw/dans/dvcli/command/DatasetAssignRole.java

This file was deleted.

16 changes: 13 additions & 3 deletions src/main/java/nl/knaw/dans/dvcli/command/DatasetGetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import nl.knaw.dans.dvcli.action.ConsoleReport;
import nl.knaw.dans.lib.dataverse.DataverseException;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;

Expand All @@ -29,14 +31,22 @@
public class DatasetGetVersion extends AbstractCmd {
@ParentCommand
private DatasetCmd datasetCmd;
@Parameters(index = "0", paramLabel = "version", description = "version to retrieve.")
String version;

@ArgGroup(exclusive = true, multiplicity = "1")
VersionInfo versionInfo;

static class VersionInfo {
@Parameters(description = "Specified a version to retrieve.")
String version = "";
@Option(names = "--all", description = "Get all versions")
boolean allVersions;
}

@Override
public void doCall() throws IOException, DataverseException {
datasetCmd.batchProcessorBuilder()
.action(d -> {
var r = d.getVersion(version);
var r = versionInfo.allVersions ? d.getAllVersions() : d.getVersion(versionInfo.version);
return r.getEnvelopeAsString();
})
.report(new ConsoleReport<>())
Expand Down
43 changes: 34 additions & 9 deletions src/main/java/nl/knaw/dans/dvcli/command/DatasetPublish.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import nl.knaw.dans.dvcli.action.ConsoleReport;
import nl.knaw.dans.lib.dataverse.DatasetApi;
import nl.knaw.dans.lib.dataverse.DataverseException;
import nl.knaw.dans.lib.dataverse.model.dataset.UpdateType;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.ParentCommand;

import java.io.IOException;
import java.util.EnumSet;

@Command(name = "publish",
mixinStandardHelpOptions = true,
Expand All @@ -34,19 +34,46 @@ public class DatasetPublish extends AbstractCmd {
@ParentCommand
private DatasetCmd datasetCmd;

@Option(names={"-u", "--update-type"}, type =UpdateType.class, description ="'major' or 'minor' version update.")
private EnumSet<UpdateType> updateType = EnumSet.of(UpdateType.major);
static class PublishParams {
@ArgGroup(exclusive = true)
VersionUpdateType versionUpdateType;

@Option(names={"-a", "--assure-indexed"}, paramLabel = "assure-indexed", type = Boolean.class, description = "To make sure that indexing has already happened and it is set to 'true'.")
private boolean assureIsIndexed = true;
static class VersionUpdateType {
@Option(names = "--major", description = "Version update type: major (default)")
boolean major;
@Option(names = "--minor", description = "Version update type: minor")
boolean minor;
}

@Option(names = { "-a", "--assure-indexed" }, paramLabel = "assure-indexed", description = "Set to true to ensure that indexing has already happened before publish.")
private boolean assureIsIndexed = true;
}

@ArgGroup(exclusive = false)
PublishParams publishParams;

private UpdateType getUpdateType() {
if (publishParams != null && publishParams.versionUpdateType != null) {
if (publishParams.versionUpdateType.minor) {
return UpdateType.minor;
}
}
return UpdateType.major;
}

private boolean isAssureIndexed() {
if (publishParams != null)
return publishParams.assureIsIndexed;

return true;
}

@Override
public void doCall() throws IOException, DataverseException {
BatchProcessor.<DatasetApi, String> builder()
.labeledItems(datasetCmd.getItems())
.action(d -> {
var r = d.publish();
var r = d.publish(this.getUpdateType(), this.isAssureIndexed());
return r.getEnvelopeAsString();
})
.report(new ConsoleReport<>())
Expand All @@ -55,6 +82,4 @@ BatchProcessor.<DatasetApi, String> builder()
.process();
}

enum UpdateType {major, minor}

}
Loading

0 comments on commit 06c652b

Please sign in to comment.