package com.merakianalytics.kernel;

import org.apache.deltaspike.core.api.exclude.Exclude;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.merakianalytics.kernel.filters.CORSFilter;
import com.merakianalytics.orianna.datapipeline.PipelineConfiguration;
import com.merakianalytics.orianna.datapipeline.riotapi.RiotAPI;
import com.merakianalytics.orianna.types.common.Platform;

@Exclude
public class KernelConfiguration {
    private static PipelineConfiguration defaultPipelineConfiguration() {
        final PipelineConfiguration config = new PipelineConfiguration();

        final PipelineConfiguration.PipelineElementConfiguration riotAPI = new PipelineConfiguration.PipelineElementConfiguration();
        riotAPI.setClassName(RiotAPI.class.getCanonicalName());
        riotAPI.setConfigClassName(RiotAPI.Configuration.class.getCanonicalName());
        riotAPI.setConfig(new ObjectMapper().setSerializationInclusion(Include.NON_DEFAULT).valueToTree(new RiotAPI.Configuration()));
        config.getElements().add(riotAPI);

        return config;
    }

    private CORSFilter.Configuration CORS = new CORSFilter.Configuration();
    private Platform defaultPlatform = Platform.NORTH_AMERICA;
    private PipelineConfiguration pipeline = defaultPipelineConfiguration();

    /**
     * @return the CORS
     */
    public CORSFilter.Configuration getCORS() {
        return CORS;
    }

    /**
     * @return the defaultPlatform
     */
    public Platform getDefaultPlatform() {
        return defaultPlatform;
    }

    /**
     * @return the pipeline
     */
    public PipelineConfiguration getPipeline() {
        return pipeline;
    }

    /**
     * @param CORS
     *        the CORS to set
     */
    public void setCORS(final CORSFilter.Configuration CORS) {
        this.CORS = CORS;
    }

    /**
     * @param defaultPlatform
     *        the defaultPlatform to set
     */
    public void setDefaultPlatform(final Platform defaultPlatform) {
        this.defaultPlatform = defaultPlatform;
    }

    /**
     * @param pipeline
     *        the pipeline to set
     */
    public void setPipeline(final PipelineConfiguration pipeline) {
        this.pipeline = pipeline;
    }
}

@@ -30,16 +30,62 @@
 ernel;%0A%0A
+import java.util.List;%0Aimport java.util.Set;%0A%0A
 import o
@@ -130,16 +130,73 @@
 Exclude;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -317,107 +317,456 @@
 com.
-merakianalytics.kernel.filters.CORSFilter;%0Aimport com.merakianalytics.orianna.datapipeline.Pipeline
+google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableSet;%0Aimport com.merakianalytics.datapipelines.PipelineElement;%0Aimport com.merakianalytics.kernel.filters.CORSFilter;%0Aimport com.merakianalytics.orianna.datapipeline.PipelineConfiguration;%0Aimport com.merakianalytics.orianna.datapipeline.PipelineConfiguration.PipelineElementConfiguration;%0Aimport com.merakianalytics.orianna.datapipeline.PipelineConfiguration.Transformer
 Conf
@@ -944,16 +944,104 @@
 ation %7B%0A
+    private static Logger LOGGER = LoggerFactory.getLogger(KernelConfiguration.class);%0A%0A
     priv
@@ -1191,32 +1191,162 @@
       final 
+Set%3CTransformerConfiguration%3E transformers = ImmutableSet.of();%0A        config.setTransformers(transformers);%0A%0A        final List%3C
 Pipeline
 Configuratio
@@ -1325,32 +1325,39 @@
 al List%3CPipeline
+Element
 Configuration.Pi
@@ -1357,51 +1357,262 @@
 tion
-.PipelineElementConfiguration riotAPI = new
+%3E elements = ImmutableList.of(%0A            element(RiotAPI.class));%0A        config.setElements(elements);%0A%0A        return config;%0A    %7D%0A%0A    private static PipelineElementConfiguration element(final Class%3C? extends PipelineElement%3E clazz) %7B%0A        final
  Pip
@@ -1608,32 +1608,39 @@
   final Pipeline
+Element
 Configuration.Pi
@@ -1628,33 +1628,47 @@
 entConfiguration
-.
+ element = new 
 PipelineElementC
@@ -1687,31 +1687,31 @@
 ();%0A        
-riotAPI
+element
 .setClassNam
@@ -1712,29 +1712,21 @@
 assName(
-RiotAPI.
 cla
-ss
+zz
 .getCano
@@ -1751,99 +1751,442 @@
     
-riotAPI.setConfigClassName(RiotAPI.Configuration.class.getCanonicalName());%0A        riotAPI
+for(final Class%3C?%3E subClazz : clazz.getDeclaredClasses()) %7B%0A            // We're assuming there's a public static inner class named Configuration if the element needs a configuration.%0A            if(subClazz.getName().endsWith(%22Configuration%22)) %7B%0A                element.setConfigClassName(subClazz.getName());%0A%0A                try %7B%0A                    final Object defaultConfig = subClazz.newInstance();%0A                    element
 .set
@@ -2274,37 +2274,23 @@
 ree(
-new RiotAPI.Configuration(
+defaultConfig
 ))
-)
 ;%0A  
@@ -2299,43 +2299,237 @@
     
+      
-config.getElements().add(riotAPI);%0A
+  %7D catch(InstantiationException %7C IllegalAccessException e) %7B%0A                    LOGGER.error(%22Failed to generate default configuration for %22 + clazz.getCanonicalName() + %22!%22, e);%0A                %7D%0A            %7D%0A        %7D
 %0A   
@@ -2532,38 +2532,39 @@
 %0A        return 
-config
+element
 ;%0A    %7D%0A%0A    pri

Improve default pipeline creation