Skip to content
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

DD-1564 Implement Dataverse collection level commands in dd-dataverse-cli #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main/java/nl/knaw/dans/dvcli/DdDataverseCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");

}
}
5 changes: 2 additions & 3 deletions src/main/java/nl/knaw/dans/dvcli/command/AbstractCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
import java.util.concurrent.Callable;

@RequiredArgsConstructor
public abstract class AbstractCmd implements Callable<Integer> {
public abstract class AbstractCmd implements Callable<Integer> {
@NonNull
protected final DataverseClient dataverseClient;


@Override
public Integer call() throws Exception {
try {
Expand All @@ -40,6 +39,6 @@ public Integer call() throws Exception {
return 1;
}
}

public abstract void doCall() throws IOException, DataverseException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.concurrent.Callable;

public abstract class AbstractSubcommandContainer implements Callable<Integer> {
public abstract class AbstractSubcommandContainer implements Callable<Integer> {
@Override
public Integer call() throws Exception {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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<String, String> 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());
}
}
42 changes: 42 additions & 0 deletions src/main/java/nl/knaw/dans/dvcli/command/CollectionDelete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class CollectionGetStorageSize extends AbstractCmd {
@ParentCommand
private CollectionCmd collectionCmd;

public CollectionGetStorageSize(@NonNull DataverseClient dataverseClient) {
super(dataverseClient);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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<String, String> 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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());
}
}
Loading