package com.boman.system.common; import com.google.common.collect.Lists; import org.apache.commons.collections4.keyvalue.DefaultMapEntry; import org.springframework.beans.factory.InitializingBean; import java.util.Collection; import java.util.Map; import java.util.function.BiPredicate; /** * @author shiqian * @description * @date 2021年03月22日 10:42 **/ public abstract class Feature implements InitializingBean { public static final BiPredicate matchAll = (tableName, actionName) -> { return true; }; private String name; private String description; private boolean isSystem; private Collection, Validator>> validates; private Collection, Filter>> filters; protected Feature() { this.validates = Lists.newArrayList(); this.filters = Lists.newArrayList(); this.isSystem = false; } protected Feature(String name, String description, boolean isSystem) { this(); this.name = name; this.description = description; this.isSystem = isSystem; } @Override public final void afterPropertiesSet() throws Exception { this.initialization(); } protected abstract void initialization(); protected final void addValidator(Validator validator, BiPredicate condition) { this.validates.add(new DefaultMapEntry(condition, validator)); } protected final void addFilter(Filter filter, BiPredicate condition) { this.filters.add(new DefaultMapEntry(condition, filter)); } protected final void addGlobalValidator(Validator validator) { this.addValidator(validator, matchAll); } protected final void addGlobalFilter(Filter filter) { this.addFilter(filter, matchAll); } public String getName() { return this.name; } protected void setName(final String name) { this.name = name; } public String getDescription() { return this.description; } protected void setDescription(final String description) { this.description = description; } public boolean isSystem() { return this.isSystem; } protected void setSystem(final boolean isSystem) { this.isSystem = isSystem; } public Collection, Validator>> getValidates() { return this.validates; } public Collection, Filter>> getFilters() { return this.filters; } }