package com.speedledger.measure.jenkins;

import hudson.Plugin;
import hudson.model.Descriptor;
import hudson.model.Items;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * Elasticsearch plugin to Jenkins.
 * Reports build information to Elasticsearch on build completion.
 *
 * This class only handles loading and saving the configuration of Elasticsearch, see {@link Config}.
 */
public class ElasticsearchPlugin extends Plugin {
    private Config config;

    @Override
    public void start() throws Exception {
        Items.XSTREAM.registerConverter(new Config.ConverterImpl());
        load();
    }

    @Override
    public void configure(StaplerRequest req, JSONObject jsonObject) throws IOException, ServletException, Descriptor.FormException {
        String url = jsonObject.getString("url");
        String indexName = jsonObject.getString("indexName");
        String typeName = jsonObject.getString("typeName");
        config = new Config(url, indexName, typeName);
        save();
    }

    public Config getConfig() {
        return config;
    }

    // Used by Jelly
    public String getUrl() {
        return config == null ? null : config.getUrl();
    }

    // Used by Jelly
    public String getIndexName() {
        return config == null ? null : config.getIndexName();
    }

    // Used by Jelly
    public String getTypeName() {
        return config == null ? null : config.getTypeName();
    }
}
@@ -893,17 +893,30 @@
 String(%22
-u
+elasticsearchU
 rl%22);%0A  
@@ -962,17 +962,30 @@
 String(%22
-i
+elasticsearchI
 ndexName
@@ -1036,17 +1036,30 @@
 String(%22
-t
+elasticsearchT
 ypeName%22

Fix reading wrong keys from config form response