All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.diff.handler.log.LogProcess Maven / Gradle / Ivy

There is a newer version: 0.2.15
Show newest version
package com.arextest.diff.handler.log;

import com.arextest.diff.factory.PluginServiceFactory;
import com.arextest.diff.handler.log.filterrules.IPFilter;
import com.arextest.diff.handler.log.filterrules.OnlyCompareSameColumnsFilter;
import com.arextest.diff.handler.log.filterrules.OnlyExistListElementFilter;
import com.arextest.diff.handler.log.filterrules.UnmatchedTypeFilter;
import com.arextest.diff.handler.log.filterrules.UuidFilter;
import com.arextest.diff.model.RulesConfig;
import com.arextest.diff.model.log.LogEntity;
import com.arextest.diff.plugin.LogEntityFilter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class LogProcess {

  private static List> globalFilterRules = new ArrayList>() {{
    add(new UnmatchedTypeFilter());
  }};


  private RulesConfig rulesConfig;
  private List> filterRules;

  public void setRulesConfig(RulesConfig rulesConfig) {
    this.rulesConfig = rulesConfig;
  }

  public void appendFilterRules(Predicate rule) {
    if (this.filterRules == null) {
      this.filterRules = new ArrayList<>();
    }
    this.filterRules.add(rule);
  }

  public void appendFilterRules(List> rules) {
    if (this.filterRules == null) {
      this.filterRules = new ArrayList<>();
    }
    this.filterRules.addAll(rules);
  }

  public void appendOtherFilterRules(RulesConfig rulesConfig) {
    if (this.filterRules == null) {
      this.filterRules = new ArrayList<>();
    }
    if (rulesConfig.isUuidIgnore()) {
      this.filterRules.add(new UuidFilter());
    }
    if (rulesConfig.isIpIgnore()) {
      this.filterRules.add(new IPFilter());
    }
    if (rulesConfig.isOnlyCompareCoincidentColumn()) {
      this.filterRules.add(new OnlyCompareSameColumnsFilter());
    }
    if (rulesConfig.isOnlyCompareExistListElements()) {
      this.filterRules.add(new OnlyExistListElementFilter());
    }
  }

  public boolean process(List logEntities) {

    Stream stream = logEntities.stream();
    for (Predicate filterRule : globalFilterRules) {
      stream = stream.filter(filterRule);
    }
    for (Predicate filterRule : this.filterRules) {
      stream = stream.filter(filterRule);
    }

    for (LogEntityFilter logEntityFilter : PluginServiceFactory.getLogEntityFilterList()) {
      stream = stream.filter(item -> {
        try {
          return !logEntityFilter.isIgnore(item, rulesConfig);
        } catch (Throwable e) {
        }
        return true;
      });
    }
    return stream.count() == 0;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy