/*
 * Licensed Materials - Property of IBM
 * © Copyright IBM Corporation 2015. All Rights Reserved.
 */

package com.ibm.mil.cafejava;

import com.worklight.wlclient.api.WLResourceRequest;
import com.worklight.wlclient.api.WLResponseListener;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;

public final class JavaProcedureInvoker implements ProcedureInvoker {
    private final String adapterName;
    private final String procedureName;
    private HashMap<String, String> parameters;

    private JavaProcedureInvoker(String adapterName, String procedureName) {
        this.adapterName = adapterName;
        this.procedureName = procedureName;
    }

    @Override
    public void invoke(WLResponseListener wlResponseListener) {
        String url = "adapters/" + adapterName + "/" + "procedureName";
        try {
            WLResourceRequest request = new WLResourceRequest(new URI(url), WLResourceRequest.GET);
            request.setQueryParameters(parameters);
            request.send(wlResponseListener);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

    public class Builder {
        private final String adapterName;
        private final String procedureName;
        private HashMap<String, String> parameters;

        public Builder(String adapterName, String procedureName) {
            this.adapterName = adapterName;
            this.procedureName = procedureName;
        }

        public Builder parameters(HashMap<String, String> parameters) {
            this.parameters = parameters;
            return this;
        }

        public JavaProcedureInvoker build() {
            JavaProcedureInvoker invoker = new JavaProcedureInvoker(adapterName, procedureName);
            invoker.parameters = parameters;
            return invoker;
        }
    }

}

@@ -130,16 +130,62 @@
 ejava;%0A%0A
+import android.support.annotation.StringDef;%0A%0A
 import c
@@ -284,16 +284,100 @@
 tener;%0A%0A
+import java.lang.annotation.Retention;%0Aimport java.lang.annotation.RetentionPolicy;%0A
 import j
@@ -518,24 +518,379 @@
 reInvoker %7B%0A
+    @Retention(RetentionPolicy.SOURCE)%0A    @StringDef(%7B%0A            GET,%0A            POST,%0A            PUT,%0A            DELETE%0A    %7D)%0A    public @interface HttpMethod %7B%7D%0A    public static final String GET = %22GET%22;%0A    public static final String POST = %22POST%22;%0A    public static final String PUT = %22PUT%22;%0A    public static final String DELETE = %22DELETE%22;%0A%0A
     private 
@@ -998,24 +998,67 @@
  parameters;
+%0A    private @HttpMethod String httpMethod;
 %0A%0A    privat
@@ -1459,29 +1459,18 @@
 l), 
-WLResourceRequest.GET
+httpMethod
 );%0A 
@@ -1821,16 +1821,69 @@
 ameters;
+%0A        private @HttpMethod String httpMethod = GET;
 %0A%0A      
@@ -2188,32 +2188,177 @@
 his;%0A        %7D%0A%0A
+        public Builder httpMethod(@HttpMethod String httpMethod) %7B%0A            this.httpMethod = httpMethod;%0A            return this;%0A        %7D%0A%0A
         public J
@@ -2521,32 +2521,77 @@
 s = parameters;%0A
+            invoker.httpMethod = httpMethod;%0A
             retu

Allow HttpMethod configuration with JavaProcedureInvoker using @StringDef