diff --git a/src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java b/src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java index f28281d..d12401c 100644 --- a/src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java +++ b/src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java @@ -19,8 +19,18 @@ import lombok.extern.slf4j.Slf4j; import nl.knaw.dans.dvcli.command.CollectionAssignRole; import nl.knaw.dans.dvcli.command.CollectionCmd; +import nl.knaw.dans.dvcli.command.CollectionCreateDataset; +import nl.knaw.dans.dvcli.command.CollectionDelete; +import nl.knaw.dans.dvcli.command.CollectionGetContents; import nl.knaw.dans.dvcli.command.CollectionGetStorageSize; +import nl.knaw.dans.dvcli.command.CollectionImportDataset; +import nl.knaw.dans.dvcli.command.CollectionIsMetadataBlocksRoot; +import nl.knaw.dans.dvcli.command.CollectionListMetadataBlocks; import nl.knaw.dans.dvcli.command.CollectionListRoleAssignments; +import nl.knaw.dans.dvcli.command.CollectionListRoles; +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.config.DdDataverseCliConfig; import nl.knaw.dans.lib.util.AbstractCommandLineApp; import nl.knaw.dans.lib.util.CliVersionProvider; @@ -46,11 +56,22 @@ public void configureCommandLine(CommandLine commandLine, DdDataverseCliConfig c log.debug("Building Dataverse client"); var dataverseClient = config.getDataverse().build(); - log.debug("Configuring command line"); commandLine.addSubcommand(new CommandLine(new CollectionCmd()) - .addSubcommand(new CollectionGetStorageSize(dataverseClient)) .addSubcommand(new CollectionAssignRole(dataverseClient)) - .addSubcommand(new CollectionListRoleAssignments(dataverseClient))); + .addSubcommand(new CollectionCreateDataset(dataverseClient)) + .addSubcommand(new CollectionDelete(dataverseClient)) + .addSubcommand(new CollectionGetContents(dataverseClient)) + .addSubcommand(new CollectionGetStorageSize(dataverseClient)) + .addSubcommand(new CollectionImportDataset(dataverseClient)) + .addSubcommand(new CollectionIsMetadataBlocksRoot(dataverseClient)) + .addSubcommand(new CollectionListMetadataBlocks(dataverseClient)) + .addSubcommand(new CollectionListRoleAssignments(dataverseClient)) + .addSubcommand(new CollectionListRoles(dataverseClient)) + .addSubcommand(new CollectionPublish(dataverseClient)) + .addSubcommand(new CollectionSetMetadataBlocksRoot(dataverseClient)) + .addSubcommand(new CollectionView(dataverseClient)) + ); + log.debug("Configuring command line"); } } diff --git a/src/main/java/nl/knaw/dans/dvcli/command/AbstractCmd.java b/src/main/java/nl/knaw/dans/dvcli/command/AbstractCmd.java index 7922980..162054d 100644 --- a/src/main/java/nl/knaw/dans/dvcli/command/AbstractCmd.java +++ b/src/main/java/nl/knaw/dans/dvcli/command/AbstractCmd.java @@ -24,11 +24,10 @@ import java.util.concurrent.Callable; @RequiredArgsConstructor -public abstract class AbstractCmd implements Callable { +public abstract class AbstractCmd implements Callable { @NonNull protected final DataverseClient dataverseClient; - @Override public Integer call() throws Exception { try { @@ -40,6 +39,6 @@ public Integer call() throws Exception { return 1; } } - + public abstract void doCall() throws IOException, DataverseException; } diff --git a/src/main/java/nl/knaw/dans/dvcli/command/AbstractSubcommandContainer.java b/src/main/java/nl/knaw/dans/dvcli/command/AbstractSubcommandContainer.java index f392458..4331fef 100644 --- a/src/main/java/nl/knaw/dans/dvcli/command/AbstractSubcommandContainer.java +++ b/src/main/java/nl/knaw/dans/dvcli/command/AbstractSubcommandContainer.java @@ -17,7 +17,7 @@ import java.util.concurrent.Callable; -public abstract class AbstractSubcommandContainer implements Callable { +public abstract class AbstractSubcommandContainer implements Callable { @Override public Integer call() throws Exception { return 0; diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionCmd.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionCmd.java index 01af138..ea051cb 100644 --- a/src/main/java/nl/knaw/dans/dvcli/command/CollectionCmd.java +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionCmd.java @@ -26,6 +26,5 @@ public class CollectionCmd extends AbstractSubcommandContainer { @Parameters(index = "0", paramLabel = "alias", description = "The alias of the dataverse collection (default: root)", defaultValue = "root") @Getter private String alias; - - + } diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionCreateDataset.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionCreateDataset.java new file mode 100644 index 0000000..9859434 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionCreateDataset.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +@Command(name = "create-dataset", + mixinStandardHelpOptions = true, + description = "Create a dataset in a dataverse collection.") +public class CollectionCreateDataset extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + @CommandLine.Parameters(index = "0", paramLabel = "dataset", description = "A JSON string defining the dataset to create..") + private String dataset; + + @CommandLine.Option(names = { "-m", "--mdkeys" }, paramLabel = "metadataKeys", description = "Maps the names of the metadata blocks to their 'secret' key values") + private Map metadataKeys = new HashMap<>(); + + public CollectionCreateDataset(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).createDataset(dataset, metadataKeys); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionDelete.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionDelete.java new file mode 100644 index 0000000..4f89009 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionDelete.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "delete", + mixinStandardHelpOptions = true, + description = "Delete a Dataverse collection.") +public class CollectionDelete extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionDelete(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).delete(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetContents.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetContents.java new file mode 100644 index 0000000..e1b81e5 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetContents.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "get-contents", + mixinStandardHelpOptions = true, + description = "Show contents of a dataverse collection.") +public class CollectionGetContents extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionGetContents(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).getContents(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetStorageSize.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetStorageSize.java index f279647..8e95d7b 100644 --- a/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetStorageSize.java +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionGetStorageSize.java @@ -29,7 +29,7 @@ public class CollectionGetStorageSize extends AbstractCmd { @ParentCommand private CollectionCmd collectionCmd; - + public CollectionGetStorageSize(@NonNull DataverseClient dataverseClient) { super(dataverseClient); } diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionImportDataset.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionImportDataset.java new file mode 100644 index 0000000..93b6700 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionImportDataset.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +@Command(name = "import-dataset", + mixinStandardHelpOptions = true, + description = "Import a JSON dataset into a dataverse collection.") +public class CollectionImportDataset extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + @CommandLine.Parameters(index = "0", paramLabel = "dataset", description = "A JSON string defining the dataset to import..") + private String dataset; + + @CommandLine.Option(names = { "-p", "--persistentId" }, paramLabel = "persistentId", description = "Existing persistent identifier (PID)") + String persistentId = ""; + + @CommandLine.Option(names = { "-a", "--autoPublish" }, paramLabel = "autoPublish", type = Boolean.class, description = "Immediately publish the dataset") + Boolean autoPublish = false; + + @CommandLine.Option(names = { "-m", "--mdkeys" }, paramLabel = "metadataKeys", description = "Maps the names of the metadata blocks to their 'secret' key values") + private Map metadataKeys = new HashMap<>(); + + public CollectionImportDataset(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).importDataset(dataset, persistentId, autoPublish, metadataKeys); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionIsMetadataBlocksRoot.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionIsMetadataBlocksRoot.java new file mode 100644 index 0000000..fd7af52 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionIsMetadataBlocksRoot.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "is-metadata-blocks-root", + mixinStandardHelpOptions = true, + description = "Determine if a dataverse collection inherits its metadata blocks from its parent.") +public class CollectionIsMetadataBlocksRoot extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionIsMetadataBlocksRoot(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).isMetadataBlocksRoot(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionListMetadataBlocks.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionListMetadataBlocks.java new file mode 100644 index 0000000..93e92be --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionListMetadataBlocks.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "list-metadata-blocks", + mixinStandardHelpOptions = true, + description = "Get a list of metadata blocks defined on a dataverse collection.") +public class CollectionListMetadataBlocks extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionListMetadataBlocks(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).listMetadataBlocks(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionListRoles.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionListRoles.java new file mode 100644 index 0000000..31ad90a --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionListRoles.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "list-roles", + mixinStandardHelpOptions = true, + description = "Get a list of roles defined in a dataverse collection.") +public class CollectionListRoles extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionListRoles(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).listRoles(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionPublish.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionPublish.java new file mode 100644 index 0000000..490b893 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionPublish.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "publish", + mixinStandardHelpOptions = true, + description = "Publish a dataverse collection.") +public class CollectionPublish extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionPublish(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).publish(); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionSetMetadataBlocksRoot.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionSetMetadataBlocksRoot.java new file mode 100644 index 0000000..6fabcea --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionSetMetadataBlocksRoot.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "set-metadata-blocks-root", + mixinStandardHelpOptions = true, + description = "Configure a dataverse collection to inherit its metadata blocks from its parent.") +public class CollectionSetMetadataBlocksRoot extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + @CommandLine.Parameters(index = "0", paramLabel = "isRoot", type = Boolean.class, description = "Whether to make it a metadata blocks root.") + private Boolean isRoot; + + public CollectionSetMetadataBlocksRoot(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).setMetadataBlocksRoot(isRoot); + System.out.println(r.getEnvelopeAsString()); + } +} diff --git a/src/main/java/nl/knaw/dans/dvcli/command/CollectionView.java b/src/main/java/nl/knaw/dans/dvcli/command/CollectionView.java new file mode 100644 index 0000000..74c230c --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvcli/command/CollectionView.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvcli.command; + +import lombok.NonNull; +import nl.knaw.dans.lib.dataverse.DataverseClient; +import nl.knaw.dans.lib.dataverse.DataverseException; +import picocli.CommandLine.Command; +import picocli.CommandLine.ParentCommand; + +import java.io.IOException; + +@Command(name = "view", + mixinStandardHelpOptions = true, + description = "Get the information of a Dataverse collection.") +public class CollectionView extends AbstractCmd { + @ParentCommand + private CollectionCmd collectionCmd; + + public CollectionView(@NonNull DataverseClient dataverseClient) { + super(dataverseClient); + } + + @Override + public void doCall() throws IOException, DataverseException { + var r = dataverseClient.dataverse(collectionCmd.getAlias()).view(); + System.out.println(r.getEnvelopeAsString()); + } +}