package com.backbase.controllers;

import org.apache.camel.*;
import org.apache.camel.builder.BuilderSupport;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by chauhan on 6/6/17.
 */
@Controller
@RequestMapping("/geocode/{address}")
public class GeocodeController {

    private final Logger logger = LoggerFactory.getLogger(GeocodeController.class);

    @Autowired
    @EndpointInject(uri="direct:start")
    private ProducerTemplate template;

    @Value("${google.map.api.key}")
    private String apiKey;



    @RequestMapping(method = RequestMethod.GET)
    public @ResponseBody String code(@PathVariable(name = "address") String address) {
        if (StringUtils.isEmpty(address.trim())) {
            return new String("{\"status\": \"ERR\"}");
        }
        final Map<String, Object> headers = new HashMap<String, Object>();
        headers.put("address", address);
        headers.put("apiKey", apiKey);

        Exchange exchange = template.send("direct:start", new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeaders(headers);

            }
        });

        String out = exchange.getOut().getBody(String.class);
        return out;
    }

    public void setTemplate(ProducerTemplate template) {
        this.template = template;
    }

}

@@ -1673,104 +1673,6 @@
  %7D%0A%0A
-    public void setTemplate(ProducerTemplate template) %7B%0A        this.template = template;%0A    %7D%0A%0A
 %7D%0A

Remove unused setter