Made updates to the parser as Adrian suggested

This commit is contained in:
andreisavu 2011-12-02 18:06:47 +02:00
parent a6c43a5c4c
commit 9415797075
2 changed files with 9 additions and 6 deletions

View File

@ -57,7 +57,6 @@ public interface AsyncJobAsyncClient {
*/ */
@GET @GET
@QueryParams(keys = "command", values = "listAsyncJobs") @QueryParams(keys = "command", values = "listAsyncJobs")
@SelectJson("asyncjobs")
@ResponseParser(ParseAsyncJobsFromHttpResponse.class) @ResponseParser(ParseAsyncJobsFromHttpResponse.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<AsyncJob<?>>> listAsyncJobs(ListAsyncJobsOptions... options); ListenableFuture<Set<AsyncJob<?>>> listAsyncJobs(ListAsyncJobsOptions... options);

View File

@ -25,30 +25,34 @@ import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.domain.JsonBall; import org.jclouds.domain.JsonBall;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Inject; import com.google.inject.Inject;
import org.jclouds.json.internal.GsonWrapper;
/** /**
*
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class ParseAsyncJobsFromHttpResponse implements Function<HttpResponse, Set<AsyncJob<?>>> { public class ParseAsyncJobsFromHttpResponse implements Function<HttpResponse, Set<AsyncJob<?>>> {
private final UnwrapOnlyNestedJsonValue<Set<AsyncJob<Map<String, JsonBall>>>> parser; private final ParseFirstJsonValueNamed<Set<AsyncJob<Map<String, JsonBall>>>> parser;
private final ParseTypedAsyncJob parseTyped; private final ParseTypedAsyncJob parseTyped;
@Inject @Inject
public ParseAsyncJobsFromHttpResponse(ParseTypedAsyncJob parseTyped, public ParseAsyncJobsFromHttpResponse(ParseTypedAsyncJob parseTyped, GsonWrapper gsonWrapper) {
UnwrapOnlyNestedJsonValue<Set<AsyncJob<Map<String, JsonBall>>>> parser) {
this.parseTyped = checkNotNull(parseTyped, "parseTyped"); this.parseTyped = checkNotNull(parseTyped, "parseTyped");
this.parser = checkNotNull(parser, "parser"); this.parser = new ParseFirstJsonValueNamed<Set<AsyncJob<Map<String, JsonBall>>>>(
checkNotNull(gsonWrapper, "gsonWrapper"),
new TypeLiteral<Set<AsyncJob<Map<String, JsonBall>>>>() { },
"asyncjobs");
} }
public Set<AsyncJob<?>> apply(HttpResponse response) { public Set<AsyncJob<?>> apply(HttpResponse response) {