From 75cd94da8cfb89e628a5c0b8f4f3cd2c28186306 Mon Sep 17 00:00:00 2001 From: Ali Sheikhi Date: Fri, 14 Jun 2024 16:40:08 +0200 Subject: [PATCH] DD-1564-collection-level-commands --- .../command/CollectionCreateDataset.java | 51 +++++++++++++++++ .../dans/dvcli/command/CollectionDelete.java | 42 ++++++++++++++ .../dvcli/command/CollectionGetContents.java | 42 ++++++++++++++ .../command/CollectionImportDataset.java | 57 +++++++++++++++++++ .../CollectionIsMetadataBlocksRoot.java | 42 ++++++++++++++ .../command/CollectionListMetadataBlocks.java | 42 ++++++++++++++ .../dvcli/command/CollectionListRoles.java | 42 ++++++++++++++ .../dans/dvcli/command/CollectionPublish.java | 42 ++++++++++++++ .../CollectionSetMetadataBlocksRoot.java | 46 +++++++++++++++ .../dans/dvcli/command/CollectionView.java | 42 ++++++++++++++ 10 files changed, 448 insertions(+) create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionCreateDataset.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionDelete.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionGetContents.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionImportDataset.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionIsMetadataBlocksRoot.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionListMetadataBlocks.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionListRoles.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionPublish.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionSetMetadataBlocksRoot.java create mode 100644 src/main/java/nl/knaw/dans/dvcli/command/CollectionView.java 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/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()); + } +}