// Path: hangout-filters/hangout-filters-filters/src/main/java/com/ctrip/ops/sysdev/filters/Filters.java
// @Log4j2
// public class Filters extends BaseFilter {
//     public Filters(Map config) {
//         super(config);
//     }
// 
//     protected List<BaseFilter> filterProcessors;
//     private Map<String, Object> event;
// 
//     protected void prepare() {
//         ArrayList<Map> filters = (ArrayList<Map>) config.get("filters");
// 
//         this.filterProcessors = Utils.createFilterProcessors(filters);
//         for (BaseFilter filterProcessor : filterProcessors) {
//             if (filterProcessor.processExtraEventsFunc == true) {
//                 this.processExtraEventsFunc = true;
//             }
//         }
//     }
// 
//     @Override
//     protected Map filter(Map event) {
//         if (this.processExtraEventsFunc == true) {
//             //will prcess the event in filterExtraEvents
//             this.event = event;
//             return event;
//         }
//         if (this.filterProcessors != null) {
//             for (BaseFilter bf : filterProcessors) {
//                 if (event == null) {
//                     break;
//                 }
//                 event = bf.process(event);
//             }
//         }
//         return event;
//     }
// 
//     @Override
//     protected void filterExtraEvents(Stack<Map<String, Object>> to_st) {
//         Stack<Map<String, Object>> from_st = new Stack<Map<String, Object>>();
//         from_st.push(event);
// 
//         for (BaseFilter bf : filterProcessors) {
//             while (!from_st.empty()) {
//                 Map rst = bf.process(from_st.pop());
//                 if (rst != null) {
//                     to_st.push(rst);
//                 }
//             }
//             if (bf.processExtraEventsFunc == true) {
//                 bf.processExtraEvents(to_st);
//             }
//         }
//         return;
//     }
// }


import com.ctrip.ops.sysdev.filters.Filters;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.Yaml;
import java.util.HashMap;
import java.util.Map;
        event.put("message", "2016-06-10T13:30:33.040+08:00 username info messsage body.");
        event = Filtersfilter.process(event);
        Assert.assertEquals(event.get("message"), "2016-06-10T13:30:33.040+08:00 username info messsage body.");
        Assert.assertNull(event.get("user"));
        Assert.assertNotNull(event.get("message"));

        event = new HashMap();
        event.put("message", "2016-06-10T13:30:33.040+08:00 username warning message body.");
        event = Filtersfilter.process(event);
        Assert.assertEquals(event.get("user"), "username");
        Assert.assertEquals(event.get("level"), "warning");
        Assert.assertNull(event.get("message"));


        c = String.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
                "if:",
                "  - '<#if message??>true</#if>'",
                "  - '<#if message?contains(\"liu\")>true<#elseif message?contains(\"warn\")>true</#if>'",
                "filters:",
                "    - Add:",
                "        fields:",
                "            a: 'a'",
                "    - Add:",
                "        fields:",
                "            b: 'b'");

        yaml = new Yaml();
        config = (Map) yaml.load(c);
        Assert.assertNotNull(config);

// Path: hangout-filters/hangout-filters-filters/src/main/java/com/ctrip/ops/sysdev/filters/Filters.java
// @Log4j2
// public class Filters extends BaseFilter {
//     public Filters(Map config) {
//         super(config);
//     }
// 
//     protected List<BaseFilter> filterProcessors;
//     private Map<String, Object> event;
// 
//     protected void prepare() {
//         ArrayList<Map> filters = (ArrayList<Map>) config.get("filters");
// 
//         this.filterProcessors = Utils.createFilterProcessors(filters);
//         for (BaseFilter filterProcessor : filterProcessors) {
//             if (filterProcessor.processExtraEventsFunc == true) {
//                 this.processExtraEventsFunc = true;
//             }
//         }
//     }
// 
//     @Override
//     protected Map filter(Map event) {
//         if (this.processExtraEventsFunc == true) {
//             //will prcess the event in filterExtraEvents
//             this.event = event;
//             return event;
//         }
//         if (this.filterProcessors != null) {
//             for (BaseFilter bf : filterProcessors) {
//                 if (event == null) {
//                     break;
//                 }
//                 event = bf.process(event);
//             }
//         }
//         return event;
//     }
// 
//     @Override
//     protected void filterExtraEvents(Stack<Map<String, Object>> to_st) {
//         Stack<Map<String, Object>> from_st = new Stack<Map<String, Object>>();
//         from_st.push(event);
// 
//         for (BaseFilter bf : filterProcessors) {
//             while (!from_st.empty()) {
//                 Map rst = bf.process(from_st.pop());
//                 if (rst != null) {
//                     to_st.push(rst);
//                 }
//             }
//             if (bf.processExtraEventsFunc == true) {
//                 bf.processExtraEvents(to_st);
//             }
//         }
//         return;
//     }
// }


// Path: hangout-filters/hangout-filters-filters/src/test/java/com/ctrip/ops/sysdev/test/TestFilters.java
import com.ctrip.ops.sysdev.filters.Filters;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.yaml.snakeyaml.Yaml;
import java.util.HashMap;
import java.util.Map;

        event.put("message", "2016-06-10T13:30:33.040+08:00 username info messsage body.");
        event = Filtersfilter.process(event);
        Assert.assertEquals(event.get("message"), "2016-06-10T13:30:33.040+08:00 username info messsage body.");
        Assert.assertNull(event.get("user"));
        Assert.assertNotNull(event.get("message"));

        event = new HashMap();
        event.put("message", "2016-06-10T13:30:33.040+08:00 username warning message body.");
        event = Filtersfilter.process(event);
        Assert.assertEquals(event.get("user"), "username");
        Assert.assertEquals(event.get("level"), "warning");
        Assert.assertNull(event.get("message"));


        c = String.format("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
                "if:",
                "  - '<#if message??>true</#if>'",
                "  - '<#if message?contains(\"liu\")>true<#elseif message?contains(\"warn\")>true</#if>'",
                "filters:",
                "    - Add:",
                "        fields:",
                "            a: 'a'",
                "    - Add:",
                "        fields:",
                "            b: 'b'");

        yaml = new Yaml();
        config = (Map) yaml.load(c);
        Assert.assertNotNull(config);

        Filtersfilter = new Filters(config);