diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java new file mode 100644 index 0000000000..b0643cd0a7 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/binders/BindTemplateMetadataToQueryParams.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.cloudstack.binders; + +import org.jclouds.cloudstack.domain.TemplateMetadata; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.rest.Binder; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.ws.rs.core.UriBuilder; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Richard Downer + */ +public class BindTemplateMetadataToQueryParams implements Binder { + private final Provider uriBuilderProvider; + + @Inject + public BindTemplateMetadataToQueryParams(Provider uriBuilderProvider) { + this.uriBuilderProvider = checkNotNull(uriBuilderProvider, "uriBuilderProvider"); + } + + @Override + public R bindToRequest(R request, Object input) { + checkArgument(input instanceof TemplateMetadata, "this binder is only valid for TemplateMetadata"); + TemplateMetadata metadata = (TemplateMetadata) input; + request = ModifyRequest.addQueryParam(request, "name", metadata.getName(), uriBuilderProvider.get()); + request = ModifyRequest.addQueryParam(request, "ostypeid", metadata.getOsTypeId(), uriBuilderProvider.get()); + request = ModifyRequest.addQueryParam(request, "displaytext", metadata.getDisplayText(), uriBuilderProvider.get()); + return request; + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java index 1834456db1..1605cb67e8 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/Template.java @@ -233,6 +233,19 @@ public class Template implements Comparable