@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(input instanceof TemplateMetadata, "this binder is only valid for TemplateMetadata");
TemplateMetadata metadata = (TemplateMetadata) input;
Builder<String, String> builder = ImmutableMultimap.<String, String>builder();
builder.put("name", metadata.getName());
builder.put("ostypeid", metadata.getOsTypeId());
builder.put("displaytext", metadata.getDisplayText());
if (metadata.getSnapshotId() != null) {
builder.put("snapshotid", metadata.getSnapshotId());
}
if (metadata.getVolumeId() != null) {
builder.put("volumeid", metadata.getVolumeId());
}
if (metadata.getVirtualMachineId() != null) {
builder.put("virtualmachineid", metadata.getVirtualMachineId());
}
if (metadata.isPasswordEnabled() != null) {
builder.put("passwordenabled", metadata.isPasswordEnabled().toString());
}
return (R) request.toBuilder().replaceQueryParams(builder.build()).build();
}