Skip to content

Commit

Permalink
DD-1564-collection-level-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aliassheikh committed Jun 14, 2024
1 parent 11d9763 commit 75cd94d
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 0 deletions.
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
@@ -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());
}
}
42 changes: 42 additions & 0 deletions src/main/java/nl/knaw/dans/dvcli/command/CollectionListRoles.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 = "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());
}
}
42 changes: 42 additions & 0 deletions src/main/java/nl/knaw/dans/dvcli/command/CollectionPublish.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 = "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());
}
}
Loading

0 comments on commit 75cd94d

Please sign in to comment.