Skip to content

Commit 8c83278

Browse files
authored
DD-2236 itemstore commands (#9)
Added command line support for the new item store editing endpoints.
1 parent 8e49056 commit 8c83278

8 files changed

Lines changed: 338 additions & 2 deletions

File tree

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<version>1.11.0</version>
2525
</parent>
2626
<artifactId>dd-data-vault-cli</artifactId>
27-
<version>4.0.1-SNAPSHOT</version>
27+
<version>4.1.0-SNAPSHOT</version>
2828
<name>DD Data Vault CLI</name>
2929
<scm>
3030
<developerConnection>scm:git:ssh://github.com/DANS-KNAW/${project.artifactId}</developerConnection>
@@ -34,7 +34,8 @@
3434
<properties>
3535
<main-class>nl.knaw.dans.datavaultcli.DataVaultCli</main-class>
3636
<command-name>data-vault</command-name>
37-
<dd-data-vault-api.version>1.0.0</dd-data-vault-api.version>
37+
<dd-data-vault-api.version>1.1.0</dd-data-vault-api.version>
38+
<dans-java-utils.version>2.11.1</dans-java-utils.version>
3839
</properties>
3940
<dependencies>
4041
<dependency>

src/main/java/nl/knaw/dans/datavaultcli/DataVaultCli.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
import nl.knaw.dans.datavaultcli.command.ImportStatus;
3232
import nl.knaw.dans.datavaultcli.command.Layer;
3333
import nl.knaw.dans.datavaultcli.command.LayerArchive;
34+
import nl.knaw.dans.datavaultcli.command.Itemstore;
35+
import nl.knaw.dans.datavaultcli.command.ItemstoreCopyDirectoryInto;
36+
import nl.knaw.dans.datavaultcli.command.ItemstoreCopyFileTo;
37+
import nl.knaw.dans.datavaultcli.command.ItemstoreCreateDirectory;
38+
import nl.knaw.dans.datavaultcli.command.ItemstoreDeleteDirectory;
39+
import nl.knaw.dans.datavaultcli.command.ItemstoreDeleteFile;
3440
import nl.knaw.dans.datavaultcli.command.LayerGetIds;
3541
import nl.knaw.dans.datavaultcli.command.LayerGetStatus;
3642
import nl.knaw.dans.datavaultcli.command.LayerNew;
@@ -117,6 +123,12 @@ public void configureCommandLine(CommandLine commandLine, DataVaultConfiguration
117123
.addSubcommand(new LayerGetIds(this))
118124
.addSubcommand(new LayerGetStatus(this))
119125
.addSubcommand(new LayerArchive(this)))
126+
.addSubcommand(new CommandLine(new Itemstore(this))
127+
.addSubcommand(new ItemstoreCreateDirectory(this))
128+
.addSubcommand(new ItemstoreDeleteDirectory(this))
129+
.addSubcommand(new ItemstoreDeleteFile(this))
130+
.addSubcommand(new ItemstoreCopyDirectoryInto(this))
131+
.addSubcommand(new ItemstoreCopyFileTo(this)))
120132
.addSubcommand(new CopyBatch(this))
121133
.addSubcommand(new CommandLine(new ConsistencyCheck())
122134
.addSubcommand(new ConsistencyCheckNew(this))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import picocli.CommandLine.Command;
21+
22+
import java.util.concurrent.Callable;
23+
24+
@Command(name = "itemstore",
25+
mixinStandardHelpOptions = true,
26+
description = "Apply low-level edits to the item store.")
27+
@RequiredArgsConstructor
28+
public class Itemstore implements Callable<Integer> {
29+
private final Context context;
30+
31+
@Override
32+
public Integer call() throws Exception {
33+
return 0;
34+
}
35+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import nl.knaw.dans.datavaultcli.api.CopyDirectoryIntoRequestDto;
21+
import nl.knaw.dans.datavaultcli.client.ApiException;
22+
import picocli.CommandLine.Command;
23+
import picocli.CommandLine.ParentCommand;
24+
import picocli.CommandLine.Parameters;
25+
26+
import java.nio.file.Paths;
27+
import java.util.concurrent.Callable;
28+
29+
@Command(name = "copy-directory-into",
30+
mixinStandardHelpOptions = true,
31+
description = "Copy a directory into the item store.")
32+
@RequiredArgsConstructor
33+
public class ItemstoreCopyDirectoryInto implements Callable<Integer> {
34+
private final Context context;
35+
36+
@ParentCommand
37+
private Itemstore parent;
38+
39+
@Parameters(index = "0", description = "The source directory path.")
40+
private String source;
41+
42+
@Parameters(index = "1", description = "The destination directory path in the item store.")
43+
private String destination;
44+
45+
@Override
46+
public Integer call() {
47+
try {
48+
var absoluteSource = Paths.get(source).toAbsolutePath().normalize().toString();
49+
var request = new CopyDirectoryIntoRequestDto();
50+
request.setSource(absoluteSource);
51+
request.setDestination(destination);
52+
context.getApi().itemstoreCopyDirectoryIntoPost(request);
53+
System.err.println("Copied " + absoluteSource + " to " + destination + " in respository");
54+
return 0;
55+
}
56+
catch (ApiException e) {
57+
System.err.println("Error: " + e.getMessage());
58+
return 1;
59+
}
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import nl.knaw.dans.datavaultcli.api.CopyFileToRequestDto;
21+
import nl.knaw.dans.datavaultcli.client.ApiException;
22+
import picocli.CommandLine.Command;
23+
import picocli.CommandLine.ParentCommand;
24+
import picocli.CommandLine.Parameters;
25+
26+
import java.nio.file.Paths;
27+
import java.util.concurrent.Callable;
28+
29+
@Command(name = "copy-file-to",
30+
mixinStandardHelpOptions = true,
31+
description = "Copy a file into the item store.")
32+
@RequiredArgsConstructor
33+
public class ItemstoreCopyFileTo implements Callable<Integer> {
34+
private final Context context;
35+
36+
@ParentCommand
37+
private Itemstore parent;
38+
39+
@Parameters(index = "0", description = "The source file path.")
40+
private String source;
41+
42+
@Parameters(index = "1", description = "The destination path in the item store.")
43+
private String destination;
44+
45+
@Override
46+
public Integer call() {
47+
try {
48+
var absoluteSource = Paths.get(source).toAbsolutePath().normalize().toString();
49+
var request = new CopyFileToRequestDto();
50+
request.setSource(absoluteSource);
51+
request.setDestination(destination);
52+
context.getApi().itemstoreCopyFileToPost(request);
53+
System.err.println("Copied " + absoluteSource + " to " + destination + " in respository");
54+
return 0;
55+
}
56+
catch (ApiException e) {
57+
System.err.println("Error: " + e.getMessage());
58+
return 1;
59+
}
60+
}
61+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import nl.knaw.dans.datavaultcli.api.CreateDirectoryRequestDto;
21+
import nl.knaw.dans.datavaultcli.client.ApiException;
22+
import picocli.CommandLine.Command;
23+
import picocli.CommandLine.ParentCommand;
24+
import picocli.CommandLine.Parameters;
25+
26+
import java.util.concurrent.Callable;
27+
28+
@Command(name = "create-directory",
29+
mixinStandardHelpOptions = true,
30+
description = "Create a new directory in the item store.")
31+
@RequiredArgsConstructor
32+
public class ItemstoreCreateDirectory implements Callable<Integer> {
33+
private final Context context;
34+
35+
@ParentCommand
36+
private Itemstore parent;
37+
38+
@Parameters(index = "0", description = "The path to the directory to create.")
39+
private String path;
40+
41+
@Override
42+
public Integer call() {
43+
try {
44+
var request = new CreateDirectoryRequestDto();
45+
request.setPath(path);
46+
context.getApi().itemstoreCreateDirectoryPost(request);
47+
System.err.println("Created directory " + path + " in respository");
48+
return 0;
49+
}
50+
catch (ApiException e) {
51+
System.err.println("Error: " + e.getMessage());
52+
return 1;
53+
}
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import nl.knaw.dans.datavaultcli.api.DeleteDirectoryRequestDto;
21+
import nl.knaw.dans.datavaultcli.client.ApiException;
22+
import picocli.CommandLine.Command;
23+
import picocli.CommandLine.ParentCommand;
24+
import picocli.CommandLine.Parameters;
25+
26+
import java.util.concurrent.Callable;
27+
28+
@Command(name = "delete-directory",
29+
mixinStandardHelpOptions = true,
30+
description = "Delete a directory from the item store.")
31+
@RequiredArgsConstructor
32+
public class ItemstoreDeleteDirectory implements Callable<Integer> {
33+
private final Context context;
34+
35+
@ParentCommand
36+
private Itemstore parent;
37+
38+
@Parameters(index = "0", description = "The path to the directory to delete.")
39+
private String path;
40+
41+
@Override
42+
public Integer call() {
43+
try {
44+
var request = new DeleteDirectoryRequestDto();
45+
request.setPath(path);
46+
context.getApi().itemstoreDeleteDirectoryPost(request);
47+
System.err.println("Deleted directory " + path + " from respository");
48+
return 0;
49+
}
50+
catch (ApiException e) {
51+
System.err.println("Error: " + e.getMessage());
52+
return 1;
53+
}
54+
}
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2022 DANS - Data Archiving and Networked Services (info@dans.knaw.nl)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nl.knaw.dans.datavaultcli.command;
17+
18+
import lombok.RequiredArgsConstructor;
19+
import nl.knaw.dans.datavaultcli.Context;
20+
import nl.knaw.dans.datavaultcli.api.DeleteFilesRequestDto;
21+
import nl.knaw.dans.datavaultcli.client.ApiException;
22+
import picocli.CommandLine.Command;
23+
import picocli.CommandLine.ParentCommand;
24+
import picocli.CommandLine.Parameters;
25+
26+
import java.util.List;
27+
import java.util.concurrent.Callable;
28+
29+
@Command(name = "delete-file",
30+
mixinStandardHelpOptions = true,
31+
description = "Delete a file from the item store.")
32+
@RequiredArgsConstructor
33+
public class ItemstoreDeleteFile implements Callable<Integer> {
34+
private final Context context;
35+
36+
@ParentCommand
37+
private Itemstore parent;
38+
39+
@Parameters(index = "0", description = "The path to the file to delete.")
40+
private String path;
41+
42+
@Override
43+
public Integer call() {
44+
try {
45+
var request = new DeleteFilesRequestDto();
46+
request.setPaths(List.of(path));
47+
context.getApi().itemstoreDeleteFilesPost(request);
48+
System.err.println("Deleted file " + path + " from respository");
49+
return 0;
50+
}
51+
catch (ApiException e) {
52+
System.err.println("Error: " + e.getMessage());
53+
return 1;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)