Skip to content

Commit f6e369e

Browse files
authored
Merge pull request #555 from LogicalChaos/versionId_in_payload
Version id in payload
2 parents 3bb4deb + f01d233 commit f6e369e

File tree

5 files changed

+98
-53
lines changed

5 files changed

+98
-53
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
allprojects {
1717
group = 'com.spectralogic.ds3'
18-
version = '3.2.8-COMPAT-2'
18+
version = '3.2.8-COMPAT-3'
1919
}
2020

2121
subprojects {

ds3-sdk/src/main/java/com/spectralogic/ds3client/commands/DeleteObjectsRequest.java

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,28 @@
1616
// This code is auto-generated, do not modify
1717
package com.spectralogic.ds3client.commands;
1818

19-
import com.spectralogic.ds3client.networking.HttpVerb;
20-
import com.spectralogic.ds3client.models.Contents;
21-
import com.spectralogic.ds3client.models.delete.Delete;
22-
import com.spectralogic.ds3client.models.delete.DeleteObject;
23-
import com.spectralogic.ds3client.serializer.XmlOutput;
24-
2519
import java.io.ByteArrayInputStream;
2620
import java.io.InputStream;
21+
import java.nio.charset.Charset;
2722
import java.util.ArrayList;
23+
import java.util.Collection;
24+
import java.util.HashMap;
2825
import java.util.List;
29-
import java.nio.charset.Charset;
26+
import java.util.Map;
27+
import java.util.Set;
28+
import java.util.UUID;
29+
3030
import com.spectralogic.ds3client.commands.interfaces.AbstractRequest;
31+
import com.spectralogic.ds3client.models.Contents;
32+
import com.spectralogic.ds3client.models.delete.Delete;
33+
import com.spectralogic.ds3client.models.delete.DeleteObject;
34+
import com.spectralogic.ds3client.networking.HttpVerb;
35+
import com.spectralogic.ds3client.serializer.XmlOutput;
3136

3237
public class DeleteObjectsRequest extends AbstractRequest {
3338

3439
// Variables
35-
private final List<String> objects;
40+
private final Map< String, Set< UUID > > objects;
3641

3742
private final String bucketName;
3843

@@ -44,29 +49,15 @@ public class DeleteObjectsRequest extends AbstractRequest {
4449
// Constructor
4550

4651

47-
public DeleteObjectsRequest(final String bucketName, final List<String> objects) {
52+
public DeleteObjectsRequest( final String bucketName, final Map< String, Set< UUID > > objects )
53+
{
4854
this.bucketName = bucketName;
4955
this.objects = objects;
5056

5157
this.getQueryParams().put("delete", null);
5258
}
53-
5459

55-
public DeleteObjectsRequest(final String bucketName, final Iterable<Contents> objs) {
56-
this.bucketName = bucketName;
57-
58-
this.getQueryParams().put("delete", null);
59-
this.objects = contentsToString(objs);
60-
}
61-
62-
private static List<String> contentsToString(final Iterable<Contents> objs) {
63-
final List<String> objKeyList = new ArrayList<>();
64-
for (final Contents obj : objs) {
65-
objKeyList.add(obj.getKey());
66-
}
67-
return objKeyList;
68-
}
69-
60+
7061
public DeleteObjectsRequest withReplicate(final boolean replicate) {
7162
this.replicate = replicate;
7263
if (this.replicate) {
@@ -89,9 +80,20 @@ public InputStream getStream() {
8980
final Delete delete = new Delete();
9081
delete.setQuiet(quiet);
9182
final List<DeleteObject> deleteObjects = new ArrayList<>();
92-
93-
for(final String objName : objects) {
94-
deleteObjects.add(new DeleteObject(objName));
83+
84+
for ( final Map.Entry< String, Set< UUID > > entry : objects.entrySet() )
85+
{
86+
if ( null == entry.getValue() )
87+
{
88+
deleteObjects.add( new DeleteObject( entry.getKey(), null ) );
89+
}
90+
else
91+
{
92+
for ( final UUID versionId : entry.getValue() )
93+
{
94+
deleteObjects.add( new DeleteObject( entry.getKey(), versionId ) );
95+
}
96+
}
9597
}
9698

9799
delete.setDeleteObjectList(deleteObjects);
@@ -112,7 +114,10 @@ public HttpVerb getVerb() {
112114
public String getPath() {
113115
return "/" + this.bucketName;
114116
}
115-
public List<String> getObjects() {
117+
118+
119+
public Map< String, Set< UUID > > getObjects()
120+
{
116121
return this.objects;
117122
}
118123

ds3-sdk/src/main/java/com/spectralogic/ds3client/models/DeleteObjectError.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
2121
import java.lang.String;
22+
import java.util.UUID;
2223

2324
@JacksonXmlRootElement(namespace = "Data")
2425
public class DeleteObjectError {
@@ -30,6 +31,9 @@ public class DeleteObjectError {
3031
@JsonProperty("Key")
3132
private String key;
3233

34+
@JsonProperty("VersionId")
35+
private UUID versionId;
36+
3337
@JsonProperty("Message")
3438
private String message;
3539

@@ -56,8 +60,19 @@ public String getKey() {
5660
public void setKey(final String key) {
5761
this.key = key;
5862
}
59-
60-
63+
64+
65+
public UUID getVersionId()
66+
{
67+
return versionId;
68+
}
69+
70+
public void setVersionId( final UUID versionId )
71+
{
72+
this.versionId = versionId;
73+
}
74+
75+
6176
public String getMessage() {
6277
return this.message;
6378
}
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package com.spectralogic.ds3client.models.delete;
22

3+
import java.util.UUID;
4+
35
import com.fasterxml.jackson.annotation.JsonProperty;
46

57
public class DeleteObject {
68

79
@JsonProperty("Key")
810
private String key;
9-
10-
public DeleteObject(final String key) {
11+
12+
@JsonProperty("VersionId")
13+
private UUID versionId;
14+
15+
public DeleteObject(final String key, final UUID versionId) {
1116
this.key = key;
17+
this.versionId = versionId;
1218
}
1319

1420
public String getKey() {
@@ -18,4 +24,16 @@ public String getKey() {
1824
public void setKey(final String key) {
1925
this.key = key;
2026
}
27+
28+
29+
public UUID getVersionId()
30+
{
31+
return versionId;
32+
}
33+
34+
35+
public void setVersionId( final UUID versionId )
36+
{
37+
this.versionId = versionId;
38+
}
2139
}

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,21 @@
1515

1616
package com.spectralogic.ds3client;
1717

18+
import java.io.IOException;
19+
import java.net.URISyntaxException;
20+
import java.nio.channels.FileChannel;
21+
import java.nio.charset.Charset;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.nio.file.StandardOpenOption;
25+
import java.text.ParseException;
26+
import java.text.SimpleDateFormat;
27+
import java.util.*;
28+
29+
import org.junit.Before;
30+
import org.junit.Test;
31+
1832
import com.google.common.collect.ImmutableMap;
19-
import com.google.common.collect.Lists;
2033
import com.google.common.collect.Multimap;
2134
import com.google.common.collect.TreeMultimap;
2235
import com.spectralogic.ds3client.commands.*;
@@ -31,20 +44,6 @@
3144
import com.spectralogic.ds3client.networking.HttpVerb;
3245
import com.spectralogic.ds3client.utils.ByteArraySeekableByteChannel;
3346
import com.spectralogic.ds3client.utils.ResourceUtils;
34-
import org.junit.Before;
35-
import org.junit.Test;
36-
37-
import java.io.IOException;
38-
import java.net.URISyntaxException;
39-
import java.nio.channels.FileChannel;
40-
import java.nio.charset.Charset;
41-
import java.nio.file.Files;
42-
import java.nio.file.Path;
43-
import java.nio.file.StandardOpenOption;
44-
import java.text.ParseException;
45-
import java.text.SimpleDateFormat;
46-
import java.util.*;
47-
4847
import static org.hamcrest.CoreMatchers.*;
4948
import static org.hamcrest.MatcherAssert.assertThat;
5049

@@ -311,10 +310,17 @@ public void deleteObject() throws IOException {
311310

312311
@Test
313312
public void multiObjectDelete() throws IOException {
314-
final List<String> objsToDelete = Lists.newArrayList("sample1.txt", "sample2.txt");
313+
final Map< String, Set< UUID > > objsToDelete = new LinkedHashMap<>();
314+
final UUID uuid1 = UUID.randomUUID();
315+
objsToDelete.put( "sample1.txt", new HashSet<>( Collections.singletonList( uuid1 ) ) );
316+
final UUID uuid2 = UUID.randomUUID();
317+
objsToDelete.put( "sample2.txt", new HashSet<>( Collections.singletonList( uuid2 ) ) );
315318
final Map<String, String> queryParams = new HashMap<>();
316319
queryParams.put("delete", null);
317-
final String payload = "<Delete><Quiet>false</Quiet><Object><Key>sample1.txt</Key></Object><Object><Key>sample2.txt</Key></Object></Delete>";
320+
final String payload =
321+
"<Delete><Quiet>false</Quiet><Object><Key>sample1.txt</Key><VersionId>" + uuid1.toString() +
322+
"</VersionId></Object><Object><Key>sample2.txt</Key><VersionId>" + uuid2.toString() +
323+
"</VersionId></Object></Delete>";
318324

319325
final DeleteObjectsResponse response = MockNetwork
320326
.expecting(HttpVerb.POST, "/bucketName", queryParams, payload)
@@ -325,15 +331,16 @@ public void multiObjectDelete() throws IOException {
325331
" <Error>\n" +
326332
" <Key>sample2.txt</Key>\n" +
327333
" <Code>AccessDenied</Code>\n" +
328-
" <Message>Access Denied</Message>\n" +
334+
" <Message>Access Denied</Message>\n" + " <VersionId>" + uuid2 + "</VersionId>\n" +
329335
" </Error>\n" +
330336
"</DeleteResult>")
331337
.asClient()
332338
.deleteObjects(new DeleteObjectsRequest("bucketName", objsToDelete));
333339
assertThat(response.getDeleteResult().getDeletedObjects().size(), is(1));
334340
assertThat(response.getDeleteResult().getErrors().size(), is(1));
335341
}
336-
342+
343+
337344
@Test(expected = FailedRequestException.class)
338345
public void getBadBucket() throws IOException {
339346
MockNetwork

0 commit comments

Comments
 (0)