Skip to content

Commit 909a80c

Browse files
committed
Merge pull request #82 from RachelTucker/master
Added delete folder
2 parents f028dbf + 0c778da commit 909a80c

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/BucketIntegration_Test.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,29 @@ public void deleteBucket() throws IOException, SignatureException {
9999
is(HeadBucketResponse.Status.DOESNTEXIST));
100100
}
101101

102+
@Test
103+
public void deleteFolder() throws IOException, SignatureException, URISyntaxException, XmlProcessingException {
104+
final String bucketName = "test_delete_folder";
105+
try {
106+
client.putBucket(new PutBucketRequest(bucketName));
107+
Util.loadBookTestDataWithPrefix(client, bucketName, "folder/");
108+
109+
HeadObjectResponse response = client.headObject(new HeadObjectRequest(
110+
bucketName, "folder/beowulf.txt"));
111+
assertThat(response.getStatus(),
112+
is(HeadObjectResponse.Status.EXISTS));
113+
114+
client.deleteFolder(new DeleteFolderRequest(bucketName, "folder"));
115+
116+
response = client.headObject(new HeadObjectRequest(
117+
bucketName, "folder/beowulf.txt"));
118+
assertThat(response.getStatus(),
119+
is(HeadObjectResponse.Status.DOESNTEXIST));
120+
} finally {
121+
Util.deleteAllContents(client, bucketName);
122+
}
123+
}
124+
102125
@Test
103126
public void emptyBucket() throws IOException, SignatureException {
104127
final String bucketName = "test_empty_bucket";

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3Client.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ HeadBucketResponse headBucket(HeadBucketRequest request)
100100
DeleteBucketResponse deleteBucket(
101101
DeleteBucketRequest request) throws IOException, SignatureException;
102102

103+
/**
104+
* Recursively deletes the specified folder from a DS3 endpoint.
105+
* @param request The Delete Folder Request object used to customize the HTTP request. The put bucket request object
106+
* has some options for customizing the request. See {@link DeleteFolderRequest} for the full list of
107+
* options that can be configured.
108+
* @return The response object is returned primarily to be consistent with the rest of the API. Additional data
109+
* may be returned here in the future but nothing is currently. See {@link DeleteFolderResponse} for the most
110+
* up to date information on what is returned.
111+
* @throws IOException
112+
* @throws SignatureException
113+
*/
114+
DeleteFolderResponse deleteFolder(
115+
DeleteFolderRequest request) throws IOException, SignatureException;
116+
103117
/**
104118
* Deletes an object in a bucket from a DS3 endpoint
105119
* @param request The Put Bucket Request object used to customize the HTTP request. The put bucket request object

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public DeleteBucketResponse deleteBucket(final DeleteBucketRequest request) thro
6666
return new DeleteBucketResponse(this.netClient.getResponse(request));
6767
}
6868

69+
@Override
70+
public DeleteFolderResponse deleteFolder(final DeleteFolderRequest request) throws IOException, SignatureException {
71+
return new DeleteFolderResponse(this.netClient.getResponse(request));
72+
}
73+
6974
@Override
7075
public DeleteObjectResponse deleteObject(final DeleteObjectRequest request) throws IOException, SignatureException {
7176
return new DeleteObjectResponse(this.netClient.getResponse(request));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.commands;
17+
18+
import com.spectralogic.ds3client.HttpVerb;
19+
20+
public class DeleteFolderRequest extends AbstractRequest {
21+
22+
private final String folderName;
23+
private final String bucketName;
24+
25+
public DeleteFolderRequest(final String bucketName, final String folderName) {
26+
this.bucketName = bucketName;
27+
this.folderName = folderName;
28+
getQueryParams().put("bucketId", this.bucketName);
29+
getQueryParams().put("recursive", null);
30+
}
31+
32+
public String getBucket() { return this.bucketName; }
33+
34+
public String getFolder() { return this.folderName; }
35+
36+
@Override
37+
public String getPath() { return "/_rest_/folder/" + this.folderName; }
38+
39+
@Override
40+
public HttpVerb getVerb() { return HttpVerb.DELETE; }
41+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2015 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.commands;
17+
18+
import com.spectralogic.ds3client.networking.WebResponse;
19+
import java.io.IOException;
20+
21+
public class DeleteFolderResponse extends AbstractResponse {
22+
23+
public DeleteFolderResponse(final WebResponse response) throws IOException {
24+
super(response);
25+
}
26+
27+
@Override
28+
protected void processResponse() throws IOException {
29+
try {
30+
this.checkStatusCode(204);
31+
} finally {
32+
this.getResponse().close();
33+
}
34+
}
35+
}

ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,19 @@ public void deleteBucket() throws IOException, SignatureException {
186186
.deleteBucket(new DeleteBucketRequest("bucketName"));
187187
}
188188

189+
@Test
190+
public void deleteFolder() throws IOException, SignatureException {
191+
final Map<String, String> queryParams = new HashMap<>();
192+
queryParams.put("bucketId", "bucketName");
193+
queryParams.put("recursive", null);
194+
195+
MockNetwork
196+
.expecting(HttpVerb.DELETE, "/_rest_/folder/folderName", queryParams, null)
197+
.returning(204, "")
198+
.asClient()
199+
.deleteFolder(new DeleteFolderRequest("bucketName","folderName"));
200+
}
201+
189202
@Test
190203
public void deleteObject() throws IOException, SignatureException {
191204
MockNetwork

0 commit comments

Comments
 (0)