> +import org.jclouds.b2.domain.UploadUrlResponse;
> +import org.jclouds.b2.reference.B2Headers;
> +import org.jclouds.rest.MapBinder;
> +
> +import com.google.common.base.Preconditions;
> +import com.google.common.net.HttpHeaders;
> +import com.google.common.net.PercentEscaper;
> +
> +public final class UploadFileBinder implements MapBinder {
> +   public static final PercentEscaper escaper = new 
> PercentEscaper("._-/~!$'()*;=:@", false);
> +
> +   @Override
> +   public <R extends HttpRequest> R bindToRequest(R request, Map<String, 
> Object> postParams) {
> +      UploadUrlResponse uploadUrl = (UploadUrlResponse) 
> postParams.get("uploadUrl");
> +      B2Object b2Object = (B2Object) postParams.get("b2Object");
> +      Preconditions.checkArgument(b2Object.fileId() == null, "fileId must be 
> null, was %s", b2Object.fileId());

One way we handle this (in Openstack providers) if to have 2 separate classes, 
one that is used to create an object, and one that is used when reading an 
object. Thus fields that can only be used for updating or reading cannot be 
specified incorrectly. AutoValue makes it easier to implement - you implement a 
regular autovalue for the "read" version of the class, and you implement an 
AutoValue with an AutoValue builder for the create/update (update could  be a 
separate class as well).

I also think that doing client-side validation checks is largely empty work and 
removing them helps to (sometimes completely) eliminate binders and mappers.

Thoughts?

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/276/files/d27eef19e1ef39d560170786aa7a9ef1f711b71b#r65642740

Reply via email to