Issue 100: set metadata support

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1975 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-10-12 19:08:00 +00:00
parent 79a3e40d14
commit 13f3bc422f
4 changed files with 23 additions and 23 deletions

View File

@ -24,11 +24,11 @@
package org.jclouds.nirvanix.sdn;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.Future;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
@ -50,8 +50,6 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import com.google.common.collect.Multimap;
/**
* Provides access to Nirvanix SDN resources via their REST API.
* <p/>
@ -85,11 +83,11 @@ public interface SDNConnection {
/**
* The SetMetadata method is used to set specified metadata for a file or folder.
*/
@PUT
@GET
@Path("/ws/Metadata/SetMetadata.ashx")
@QueryParams(keys = SDNQueryParams.PATH, values = "{path}")
Future<Void> setMetadata(@PathParam("path") String path,
@BinderParam(BindMetadataToQueryParams.class) Multimap<String, String> metadata);
@BinderParam(BindMetadataToQueryParams.class) Map<String, String> metadata);
/**
* The GetMetadata method is used to retrieve all metadata from a file or folder.

View File

@ -4,6 +4,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.jclouds.http.HttpRequest;
@ -11,22 +12,21 @@ import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
public class BindMetadataToQueryParams implements Binder {
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Object input) {
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest,
"this decorator is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof Multimap,
"this decorator is only valid for Multimaps!");
Multimap<String, String> userMetadata = (Multimap<String, String>) input;
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(input, "input") instanceof Map,
"this binder is only valid for Maps!");
Map<String, String> userMetadata = (Map<String, String>) input;
List<String> metadata = Lists.newArrayList();
for (Entry<String, String> entry : userMetadata.entries()) {
for (Entry<String, String> entry : userMetadata.entrySet()) {
metadata.add(String.format("%s:%s", entry.getKey().toLowerCase(), entry.getValue()));
}
((GeneratedHttpRequest)request).replaceQueryParam("metadata", metadata.toArray());
((GeneratedHttpRequest) request).replaceQueryParam("metadata", metadata.toArray());
}
}

View File

@ -1,9 +1,11 @@
package org.jclouds.nirvanix.sdn;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -16,6 +18,8 @@ import org.jclouds.nirvanix.sdn.domain.UploadInfo;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code SDNConnection}
*
@ -59,8 +63,8 @@ public class SDNConnectionLiveTest {
String content = connection.getFile(containerName + "/test.txt").get(30, TimeUnit.SECONDS);
assertEquals(content, "value");
// Multimap<String, String> metadata = ImmutableMultimap.of("chef", "sushi", "foo", "bar");
// connection.setMetadata(containerName+"/test.txt", metadata).get(30, TimeUnit.SECONDS);
Map<String, String> metadata = ImmutableMap.of("chef", "sushi", "foo", "bar");
connection.setMetadata(containerName+"/test.txt", metadata).get(30, TimeUnit.SECONDS);
}
}

View File

@ -30,6 +30,7 @@ import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
@ -56,8 +57,7 @@ import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -117,18 +117,16 @@ public class SDNConnectionTest {
}
public void testSetMetadata() throws SecurityException, NoSuchMethodException, IOException {
Method method = SDNConnection.class.getMethod("setMetadata", String.class, Multimap.class);
Method method = SDNConnection.class.getMethod("setMetadata", String.class, Map.class);
GeneratedHttpRequest<SDNConnection> httpMethod = processor
.createRequest(method, new Object[] { "adriansmovies/sushi.avi",
ImmutableMultimap.of("Chef", "Kawasaki") });
ImmutableMap.of("Chef", "Kawasaki") });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Metadata/SetMetadata.ashx");
assertEquals(httpMethod.getEndpoint().getQuery(),
"output=json&path=adriansmovies/sushi.avi&metadata=chef:Kawasaki");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList(0 + ""));
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(httpMethod.getEntity(), null);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class);