proj_name stringclasses 131
values | relative_path stringlengths 30 228 | class_name stringlengths 1 68 | func_name stringlengths 1 48 | masked_class stringlengths 78 9.82k | func_body stringlengths 46 9.61k | len_input int64 29 2.01k | len_output int64 14 1.94k | total int64 55 2.05k | relevant_context stringlengths 0 38.4k |
|---|---|---|---|---|---|---|---|---|---|
j-easy_easy-rules | easy-rules/easy-rules-core/src/main/java/org/jeasy/rules/core/DefaultRulesEngine.java | DefaultRulesEngine | check | class DefaultRulesEngine extends AbstractRulesEngine {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRulesEngine.class);
/**
* Create a new {@link DefaultRulesEngine} with default parameters.
*/
public DefaultRulesEngine() {
super();
}
/**
* Create a n... |
Objects.requireNonNull(rules, "Rules must not be null");
Objects.requireNonNull(facts, "Facts must not be null");
triggerListenersBeforeRules(rules, facts);
Map<Rule, Boolean> result = doCheck(rules, facts);
triggerListenersAfterRules(rules, facts);
return result;
| 1,668 | 90 | 1,758 | <methods>public org.jeasy.rules.api.RulesEngineParameters getParameters() ,public List<org.jeasy.rules.api.RuleListener> getRuleListeners() ,public List<org.jeasy.rules.api.RulesEngineListener> getRulesEngineListeners() ,public void registerRuleListener(org.jeasy.rules.api.RuleListener) ,public void registerRuleListene... |
j-easy_easy-rules | easy-rules/easy-rules-core/src/main/java/org/jeasy/rules/core/InferenceRulesEngine.java | InferenceRulesEngine | fire | class InferenceRulesEngine extends AbstractRulesEngine {
private static final Logger LOGGER = LoggerFactory.getLogger(InferenceRulesEngine.class);
private final DefaultRulesEngine delegate;
/**
* Create a new inference rules engine with default parameters.
*/
public InferenceRulesEngine() {... |
Objects.requireNonNull(rules, "Rules must not be null");
Objects.requireNonNull(facts, "Facts must not be null");
Set<Rule> selectedRules;
do {
LOGGER.debug("Selecting candidate rules based on the following facts: {}", facts);
selectedRules = selectCandidates(rul... | 652 | 155 | 807 | <methods>public org.jeasy.rules.api.RulesEngineParameters getParameters() ,public List<org.jeasy.rules.api.RuleListener> getRuleListeners() ,public List<org.jeasy.rules.api.RulesEngineListener> getRulesEngineListeners() ,public void registerRuleListener(org.jeasy.rules.api.RuleListener) ,public void registerRuleListene... |
j-easy_easy-rules | easy-rules/easy-rules-core/src/main/java/org/jeasy/rules/core/RuleDefinitionValidator.java | RuleDefinitionValidator | checkConditionMethod | class RuleDefinitionValidator {
void validateRuleDefinition(final Object rule) {
checkRuleClass(rule);
checkConditionMethod(rule);
checkActionMethods(rule);
checkPriorityMethod(rule);
}
private void checkRuleClass(final Object rule) {
if (!isRuleClassWellDefined(rul... |
List<Method> conditionMethods = getMethodsAnnotatedWith(Condition.class, rule);
if (conditionMethods.isEmpty()) {
throw new IllegalArgumentException(format("Rule '%s' must have a public method annotated with '%s'", rule.getClass().getName(), Condition.class.getName()));
}
i... | 1,204 | 231 | 1,435 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-core/src/main/java/org/jeasy/rules/core/Utils.java | Utils | findAnnotation | class Utils {
private Utils() { }
static <A extends Annotation> A findAnnotation(final Class<A> targetAnnotation, final Class<?> annotatedType) {<FILL_FUNCTION_BODY>}
static boolean isAnnotationPresent(final Class<? extends Annotation> targetAnnotation, final Class<?> annotatedType) {
return find... |
A foundAnnotation = annotatedType.getAnnotation(targetAnnotation);
if (foundAnnotation == null) {
for (Annotation annotation : annotatedType.getAnnotations()) {
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType.isAnn... | 111 | 110 | 221 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl/JexlAction.java | JexlAction | execute | class JexlAction implements Action {
private static final Logger LOGGER = LoggerFactory.getLogger(JexlAction.class);
private final JexlScript compiledScript;
private final String expression;
public JexlAction(String expression) {
this.expression = Objects.requireNonNull(expression, "expressio... |
Objects.requireNonNull(facts, "facts cannot be null");
MapContext ctx = new MapContext(facts.asMap());
try {
compiledScript.execute(ctx);
} catch (JexlException e) {
LOGGER.error("Unable to execute expression: '" + expression + "' on facts: " + facts, e);
... | 227 | 98 | 325 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl/JexlCondition.java | JexlCondition | evaluate | class JexlCondition implements Condition {
private final JexlScript compiledScript;
public JexlCondition(String expression) {
Objects.requireNonNull(expression, "expression cannot be null");
this.compiledScript = JexlRule.DEFAULT_JEXL.createScript(expression);
}
public JexlCondition(S... |
Objects.requireNonNull(facts, "facts cannot be null");
MapContext ctx = new MapContext(facts.asMap());
return (Boolean) compiledScript.execute(ctx);
| 187 | 51 | 238 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl/JexlRule.java | JexlRule | then | class JexlRule extends BasicRule {
static final JexlEngine DEFAULT_JEXL = new JexlBuilder().create();
private Condition condition = Condition.FALSE;
private final List<Action> actions = new ArrayList<>();
private final JexlEngine jexl;
public JexlRule() {
this(DEFAULT_JEXL);
}
pu... |
Objects.requireNonNull(action, "action cannot be null");
this.actions.add(new JexlAction(action, jexl));
return this;
| 481 | 45 | 526 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.String, java.lang.String) ,public void <init>(java.lang.String, java.lang.String, int) ,public int compareTo(org.jeasy.rules.api.Rule) ,public boolean equals(java.lang.Object) ,public boolean evaluate(org.jeasy.rules.api.F... |
j-easy_easy-rules | easy-rules/easy-rules-jexl/src/main/java/org/jeasy/rules/jexl/JexlRuleFactory.java | JexlRuleFactory | createRule | class JexlRuleFactory extends AbstractRuleFactory {
private final RuleDefinitionReader reader;
private final JexlEngine jexl;
public JexlRuleFactory(RuleDefinitionReader reader) {
this(reader, JexlRule.DEFAULT_JEXL);
}
public JexlRuleFactory(RuleDefinitionReader reader, JexlEngine jexl) {... |
Objects.requireNonNull(ruleDescriptor, "ruleDescriptor cannot be null");
Objects.requireNonNull(jexl, "jexl cannot be null");
List<RuleDefinition> ruleDefinitions = reader.read(ruleDescriptor);
if (ruleDefinitions.isEmpty()) {
throw new IllegalArgumentException("rule descrip... | 408 | 104 | 512 | <methods>public non-sealed void <init>() <variables>private static final List<java.lang.String> ALLOWED_COMPOSITE_RULE_TYPES,private static final Logger LOGGER |
j-easy_easy-rules | easy-rules/easy-rules-mvel/src/main/java/org/jeasy/rules/mvel/MVELAction.java | MVELAction | execute | class MVELAction implements Action {
private static final Logger LOGGER = LoggerFactory.getLogger(MVELAction.class);
private final String expression;
private final Serializable compiledExpression;
/**
* Create a new {@link MVELAction}.
*
* @param expression the action written in expres... |
try {
MVEL.executeExpression(compiledExpression, facts.asMap());
} catch (Exception e) {
LOGGER.error("Unable to evaluate expression: '" + expression + "' on facts: " + facts, e);
throw e;
}
| 244 | 68 | 312 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-mvel/src/main/java/org/jeasy/rules/mvel/MVELCondition.java | MVELCondition | evaluate | class MVELCondition implements Condition {
private final Serializable compiledExpression;
/**
* Create a new {@link MVELCondition}.
*
* @param expression the condition written in expression language
*/
public MVELCondition(String expression) {
compiledExpression = MVEL.compileE... |
// MVEL.evalToBoolean does not accept compiled expressions..
return (boolean) MVEL.executeExpression(compiledExpression, facts.asMap());
| 191 | 39 | 230 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-mvel/src/main/java/org/jeasy/rules/mvel/MVELRuleFactory.java | MVELRuleFactory | createSimpleRule | class MVELRuleFactory extends AbstractRuleFactory {
private final RuleDefinitionReader reader;
private final ParserContext parserContext;
/**
* Create a new {@link MVELRuleFactory} with a given reader.
*
* @param reader used to read rule definitions
* @see YamlRuleDefinitionReader
... |
MVELRule mvelRule = new MVELRule(parserContext)
.name(ruleDefinition.getName())
.description(ruleDefinition.getDescription())
.priority(ruleDefinition.getPriority())
.when(ruleDefinition.getCondition());
for (String action : ruleDefinition... | 597 | 98 | 695 | <methods>public non-sealed void <init>() <variables>private static final List<java.lang.String> ALLOWED_COMPOSITE_RULE_TYPES,private static final Logger LOGGER |
j-easy_easy-rules | easy-rules/easy-rules-spel/src/main/java/org/jeasy/rules/spel/SpELAction.java | SpELAction | execute | class SpELAction implements Action {
private static final Logger LOGGER = LoggerFactory.getLogger(SpELAction.class);
private final ExpressionParser parser = new SpelExpressionParser();
private final String expression;
private final Expression compiledExpression;
private BeanResolver beanResolver;
... |
try {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(facts.asMap());
context.setVariables(facts.asMap());
if (beanResolver != null) {
context.setBeanResolver(beanResolver);
}
comp... | 486 | 127 | 613 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-spel/src/main/java/org/jeasy/rules/spel/SpELCondition.java | SpELCondition | evaluate | class SpELCondition implements Condition {
private final ExpressionParser parser = new SpelExpressionParser();
private final Expression compiledExpression;
private BeanResolver beanResolver;
/**
* Create a new {@link SpELCondition}.
*
* @param expression the condition written in express... |
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(facts.asMap());
context.setVariables(facts.asMap());
if (beanResolver != null) {
context.setBeanResolver(beanResolver);
}
return compiledExpression.getValue(context, Bo... | 430 | 84 | 514 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-spel/src/main/java/org/jeasy/rules/spel/SpELRuleFactory.java | SpELRuleFactory | createRule | class SpELRuleFactory extends AbstractRuleFactory {
private final RuleDefinitionReader reader;
private BeanResolver beanResolver;
private ParserContext parserContext;
/**
* Create a new {@link SpELRuleFactory} with a given reader.
*
* @param reader used to read rule definitions
* @... |
List<RuleDefinition> ruleDefinitions = reader.read(ruleDescriptor);
if (ruleDefinitions.isEmpty()) {
throw new IllegalArgumentException("rule descriptor is empty");
}
return createRule(ruleDefinitions.get(0));
| 908 | 64 | 972 | <methods>public non-sealed void <init>() <variables>private static final List<java.lang.String> ALLOWED_COMPOSITE_RULE_TYPES,private static final Logger LOGGER |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/AbstractRuleFactory.java | AbstractRuleFactory | createCompositeRule | class AbstractRuleFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRuleFactory.class);
private static final List<String> ALLOWED_COMPOSITE_RULE_TYPES = Arrays.asList(
UnitRuleGroup.class.getSimpleName(),
ConditionalRuleGroup.class.getSimpleName(),
... |
if (ruleDefinition.getCondition() != null) {
LOGGER.warn(
"Condition '{}' in composite rule '{}' of type {} will be ignored.",
ruleDefinition.getCondition(),
ruleDefinition.getName(),
ruleDefinition.getCompositeRuleType... | 207 | 378 | 585 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/composite/ActivationRuleGroup.java | ActivationRuleGroup | evaluate | class ActivationRuleGroup extends CompositeRule {
private Rule selectedRule;
/**
* Create an activation rule group.
*/
public ActivationRuleGroup() {
rules = new TreeSet<>(rules);
}
/**
* Create an activation rule group.
*
* @param name of the activation rule grou... |
for (Rule rule : rules) {
if (rule.evaluate(facts)) {
selectedRule = rule;
return true;
}
}
return false;
| 370 | 49 | 419 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.String, java.lang.String) ,public void <init>(java.lang.String, java.lang.String, int) ,public void addRule(java.lang.Object) ,public abstract boolean evaluate(org.jeasy.rules.api.Facts) ,public abstract void execute(org.j... |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/composite/CompositeRule.java | CompositeRule | removeRule | class CompositeRule extends BasicRule {
/**
* The set of composing rules.
*/
protected Set<Rule> rules;
private final Map<Object, Rule> proxyRules;
/**
* Create a new {@link CompositeRule}.
*/
public CompositeRule() {
this(Rule.DEFAULT_NAME, Rule.DEFAULT_DESCRIPTION, Ru... |
Rule proxy = proxyRules.get(rule);
if (proxy != null) {
rules.remove(proxy);
}
| 513 | 37 | 550 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.String, java.lang.String) ,public void <init>(java.lang.String, java.lang.String, int) ,public int compareTo(org.jeasy.rules.api.Rule) ,public boolean equals(java.lang.Object) ,public boolean evaluate(org.jeasy.rules.api.F... |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/composite/ConditionalRuleGroup.java | ConditionalRuleGroup | evaluate | class ConditionalRuleGroup extends CompositeRule {
private Set<Rule> successfulEvaluations;
private Rule conditionalRule;
/**
* Create a conditional rule group.
*/
public ConditionalRuleGroup() {
}
/**
* Create a conditional rule group.
*
* @param name of the conditio... |
successfulEvaluations = new HashSet<>();
conditionalRule = getRuleWithHighestPriority();
if (conditionalRule.evaluate(facts)) {
for (Rule rule : rules) {
if (rule != conditionalRule && rule.evaluate(facts)) {
successfulEvaluations.add(rule);
... | 633 | 102 | 735 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.String, java.lang.String) ,public void <init>(java.lang.String, java.lang.String, int) ,public void addRule(java.lang.Object) ,public abstract boolean evaluate(org.jeasy.rules.api.Facts) ,public abstract void execute(org.j... |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/composite/UnitRuleGroup.java | UnitRuleGroup | evaluate | class UnitRuleGroup extends CompositeRule {
/**
* Create a unit rule group.
*/
public UnitRuleGroup() {
}
/**
* Create a unit rule group.
* @param name of the composite rule
*/
public UnitRuleGroup(String name) {
super(name);
}
/**
* Create a unit rul... |
if (!rules.isEmpty()) {
for (Rule rule : rules) {
if (!rule.evaluate(facts)) {
return false;
}
}
return true;
}
return false;
| 293 | 59 | 352 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.String, java.lang.String) ,public void <init>(java.lang.String, java.lang.String, int) ,public void addRule(java.lang.Object) ,public abstract boolean evaluate(org.jeasy.rules.api.Facts) ,public abstract void execute(org.j... |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/reader/AbstractRuleDefinitionReader.java | AbstractRuleDefinitionReader | createRuleDefinition | class AbstractRuleDefinitionReader implements RuleDefinitionReader {
public List<RuleDefinition> read(Reader reader) throws Exception {
List<RuleDefinition> ruleDefinitions = new ArrayList<>();
Iterable<Map<String, Object>> rules = loadRules(reader);
for (Map<String, Object> rule : rules) {... |
RuleDefinition ruleDefinition = new RuleDefinition();
String name = (String) map.get("name");
ruleDefinition.setName(name != null ? name : Rule.DEFAULT_NAME);
String description = (String) map.get("description");
ruleDefinition.setDescription(description != null ? description ... | 257 | 532 | 789 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/reader/JsonRuleDefinitionReader.java | JsonRuleDefinitionReader | loadRules | class JsonRuleDefinitionReader extends AbstractRuleDefinitionReader {
private final ObjectMapper objectMapper;
/**
* Create a new {@link JsonRuleDefinitionReader}.
*/
public JsonRuleDefinitionReader() {
this(new ObjectMapper());
}
/**
* Create a new {@link JsonRuleDefinitio... |
List<Map<String, Object>> rulesList = new ArrayList<>();
Object[] rules = objectMapper.readValue(reader, Object[].class);
for (Object rule : rules) {
rulesList.add((Map<String, Object>) rule);
}
return rulesList;
| 167 | 74 | 241 | <methods>public non-sealed void <init>() ,public List<org.jeasy.rules.support.RuleDefinition> read(java.io.Reader) throws java.lang.Exception<variables> |
j-easy_easy-rules | easy-rules/easy-rules-support/src/main/java/org/jeasy/rules/support/reader/YamlRuleDefinitionReader.java | YamlRuleDefinitionReader | loadRules | class YamlRuleDefinitionReader extends AbstractRuleDefinitionReader {
private final Yaml yaml;
/**
* Create a new {@link YamlRuleDefinitionReader}.
*/
public YamlRuleDefinitionReader() {
this(new Yaml());
}
/**
* Create a new {@link YamlRuleDefinitionReader}.
*
* ... |
List<Map<String, Object>> rulesList = new ArrayList<>();
Iterable<Object> rules = yaml.loadAll(reader);
for (Object rule : rules) {
rulesList.add((Map<String, Object>) rule);
}
return rulesList;
| 169 | 72 | 241 | <methods>public non-sealed void <init>() ,public List<org.jeasy.rules.support.RuleDefinition> read(java.io.Reader) throws java.lang.Exception<variables> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/airco/DecreaseTemperatureAction.java | DecreaseTemperatureAction | execute | class DecreaseTemperatureAction implements Action {
static DecreaseTemperatureAction decreaseTemperature() {
return new DecreaseTemperatureAction();
}
@Override
public void execute(Facts facts) {<FILL_FUNCTION_BODY>}
} |
System.out.println("It is hot! cooling air..");
Integer temperature = facts.get("temperature");
facts.put("temperature", temperature - 1);
| 70 | 43 | 113 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/airco/Launcher.java | Launcher | main | class Launcher {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// define facts
Facts facts = new Facts();
facts.put("temperature", 30);
// define rules
Rule airConditioningRule = new RuleBuilder()
.name("air conditioning rule")
.when(itIsHot())
.then(decreaseTemperature())
.bu... | 33 | 135 | 168 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz/FizzBuzz.java | FizzBuzz | main | class FizzBuzz { // Everything in Java is a class
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} | // Every program must have main()
for (int i = 1; i <= 100; i++) { // count from 1 to 100
if (((i % 5) == 0) && ((i % 7) == 0)) // A multiple of both?
System.out.print("fizzbuzz");
else if ((i % 5) == 0) System.out.print("fizz"); // else a multiple of 5?
... | 41 | 181 | 222 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz/FizzBuzzWithEasyRules.java | FizzBuzzWithEasyRules | main | class FizzBuzzWithEasyRules {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// create rules engine
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);
// create rules
Rules rules = new Rules();
rules.register(new FizzRule());
rules.... | 38 | 191 | 229 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/fizzbuzz/NonFizzBuzzRule.java | NonFizzBuzzRule | isNotFizzNorBuzz | class NonFizzBuzzRule {
@Condition
public boolean isNotFizzNorBuzz(@Fact("number") Integer number) {<FILL_FUNCTION_BODY>}
@Action
public void printInput(@Fact("number") Integer number) {
System.out.print(number);
}
@Priority
public int getPriority() {
return 3;
}
} |
// can return true, because this is the latest rule to trigger according to assigned priorities
// and in which case, the number is not fizz nor buzz
return number % 5 != 0 || number % 7 != 0;
| 103 | 58 | 161 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/helloworld/Launcher.java | Launcher | main | class Launcher {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// create facts
Facts facts = new Facts();
// create rules
Rules rules = new Rules();
rules.register(new HelloWorldRule());
// create a rules engine and fire rules on known facts
RulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.fire(rule... | 32 | 84 | 116 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop/Launcher.java | Launcher | main | class Launcher {
public static void main(String[] args) throws Exception {<FILL_FUNCTION_BODY>}
} |
//create a person instance (fact)
Person tom = new Person("Tom", 14);
Facts facts = new Facts();
facts.put("person", tom);
// create rules
MVELRule ageRule = new MVELRule()
.name("age rule")
.description("Check if person's age is > 18 and... | 35 | 323 | 358 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop/Person.java | Person | toString | class Person {
private String name;
private int age;
private boolean adult;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean i... |
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", adult=" + adult +
'}';
| 160 | 45 | 205 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/weather/Launcher.java | Launcher | main | class Launcher {
public static void main(String[] args) {<FILL_FUNCTION_BODY>}
} |
// define facts
Facts facts = new Facts();
facts.put("rain", true);
// define rules
WeatherRule weatherRule = new WeatherRule();
Rules rules = new Rules();
rules.register(weatherRule);
// fire rules on known facts
RulesEngine rulesEngine = new D... | 33 | 97 | 130 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web/IndexServlet.java | IndexServlet | doGet | class IndexServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {<FILL_FUNCTION_BODY>}
private boolean isSuspicious(HttpServletRequest request) {
return request.getAttribute(SUSPICIOUS) != null;
}
} |
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
if (isSuspicious(request)) {
out.print("Access denied\n");
} else {
out.print("Welcome!\n");
}
| 82 | 67 | 149 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web/SuspiciousRequestFilter.java | SuspiciousRequestFilter | init | class SuspiciousRequestFilter implements Filter {
private Rules rules;
private RulesEngine rulesEngine;
@Override
public void init(FilterConfig filterConfig) {<FILL_FUNCTION_BODY>}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws... |
rulesEngine = new DefaultRulesEngine();
rules = new Rules();
rules.register(new SuspiciousRequestRule());
| 152 | 34 | 186 | <no_super_class> |
j-easy_easy-rules | easy-rules/easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/web/SuspiciousRequestRule.java | SuspiciousRequestRule | isSuspicious | class SuspiciousRequestRule {
static final String SUSPICIOUS = "suspicious";
@Condition
public boolean isSuspicious(@Fact("request") HttpServletRequest request) {<FILL_FUNCTION_BODY>}
@Action
public void setSuspicious(@Fact("request") HttpServletRequest request) {
request.setAttribute... |
// criteria of suspicious could be based on ip, user-agent, etc.
// here for simplicity, it is based on the presence of a request parameter 'suspicious'
return request.getParameter(SUSPICIOUS) != null;
| 108 | 62 | 170 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/config/EruptNodeInterceptor.java | EruptNodeInterceptor | preHandle | class EruptNodeInterceptor implements WebMvcConfigurer, AsyncHandlerInterceptor {
@Resource
private EruptNodeProp eruptNodeProp;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this).addPathPatterns(EruptRestPath.ERUPT_API + "/**");
}
@Ove... |
if (!eruptNodeProp.getAccessToken().equals(request.getHeader(CloudCommonConst.HEADER_ACCESS_TOKEN))) {
throw new EruptWebApiRuntimeException("AccessToken incorrect");
}
MetaContext.registerToken(request.getHeader(EruptMutualConst.TOKEN));
Optional.ofNullable(request.getHeade... | 175 | 227 | 402 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/config/EruptNodeProp.java | EruptNodeProp | getBalanceAddress | class EruptNodeProp {
public static final String SPACE = "erupt.cloud-node";
//是否开启NODE节点注册
private boolean enableRegister = true;
//是否开启附件上传代理,开启后上传能力全部交予server端实现【server端请求node端获取附件上传要求】
// private boolean attachmentProxy = true;
//接入应用名称,推荐填写当前 Java 项目名称
private String nodeName;
/... |
if (this.serverAddresses.length == 1) {
return this.serverAddresses[0];
}
if (count >= Integer.MAX_VALUE) {
count = 0;
}
String address = this.serverAddresses[count++ % this.serverAddresses.length];
if (address.endsWith("/")) {
return ... | 315 | 113 | 428 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/interceptor/EruptCloutNodeInterceptor.java | EruptCloutNodeInterceptor | preHandle | class EruptCloutNodeInterceptor implements WebMvcConfigurer, AsyncHandlerInterceptor {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(this).addPathPatterns(EruptRestPath.ERUPT_API + "/**");
}
@Override
public boolean preHandle(HttpServletReque... |
String erupt = request.getHeader(EruptMutualConst.ERUPT);
if (null != erupt) {
if (null == EruptCoreService.getErupt(erupt)) {
response.setStatus(HttpStatus.NOT_FOUND.value());
return false;
}
}
return true;
| 122 | 87 | 209 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/invoke/NodePowerInvoke.java | NodePowerInvoke | handler | class NodePowerInvoke implements PowerHandler {
static {
PowerInvoke.registerPowerHandler(NodePowerInvoke.class);
}
@Resource
private EruptNodeProp eruptNodeProp;
@Override
public void handler(PowerObject power) {<FILL_FUNCTION_BODY>}
} |
EruptModel eruptModel = EruptCoreService.getErupt(MetaContext.getErupt().getName());
if (!eruptModel.getErupt().authVerify()) {
return;
}
String powerObjectString = HttpUtil.createGet(eruptNodeProp.getBalanceAddress() + CloudRestApiConst.ERUPT_POWER)
.form("n... | 83 | 347 | 430 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/service/ServerRemoteService.java | ServerRemoteService | getRemoteUserInfo | class ServerRemoteService {
@Resource
private EruptNodeProp eruptNodeProp;
//校验菜单权限
public boolean getMenuCodePermission(String menuValue) {
String permissionResult =
HttpUtil.createGet(eruptNodeProp.getBalanceAddress() + EruptRestPath.ERUPT_CODE_PERMISSION + "/" + menuValue)
... |
String userinfo = HttpUtil.createGet(eruptNodeProp.getBalanceAddress() + CloudRestApiConst.ERUPT_USER_INFO + eruptNodeProp.getNodeName())
.header(EruptMutualConst.TOKEN, MetaContext.getToken())
.header(CloudCommonConst.HEADER_ACCESS_TOKEN, eruptNodeProp.getAccessToken())
... | 344 | 129 | 473 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-node/src/main/java/xyz/erupt/cloud/node/task/EruptNodeTask.java | EruptNodeTask | run | class EruptNodeTask implements Runnable, ApplicationRunner, DisposableBean {
@Resource
private EruptNodeProp eruptNodeProp;
@Resource
private ServerProperties serverProperties;
private boolean runner = true;
private final Gson gson = GsonFactory.getGson();
private final String instanceI... |
log.info(ansi().fg(Ansi.Color.BLUE) + " \n" +
" _ _ \n" +
" ___ ___ _ _ ___| |_ ___ ___ _| |___ \n" +
"| -_| _| | | . | _| | | . | . | -_|\n" +
"|___|_| |___| _|_| |_|_|___|___|___|\n" +
... | 965 | 241 | 1,206 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/EruptCloudServerAutoConfiguration.java | EruptCloudServerAutoConfiguration | initMenus | class EruptCloudServerAutoConfiguration implements EruptModule {
static {
EruptModuleInvoke.addEruptModule(EruptCloudServerAutoConfiguration.class);
}
@Override
public ModuleInfo info() {
return ModuleInfo.builder().name("erupt-cloud-server").build();
}
@Override
public Li... |
MetaMenu nodeManager = MetaMenu.createRootMenu("$NodeManager", "微节点管理", "fa fa-cloud", 70);
MetaMenu nodeMenu = MetaMenu.createEruptClassMenu(CloudNode.class, nodeManager, 20);
return Arrays.asList(nodeManager,
MetaMenu.createEruptClassMenu(CloudNodeGroup.class, nodeManager, 10,... | 111 | 273 | 384 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/controller/EruptMicroserviceController.java | EruptMicroserviceController | registerNode | class EruptMicroserviceController {
private final EruptNodeMicroservice eruptNodeMicroservice;
@PostMapping(CloudRestApiConst.REGISTER_NODE)
public void registerNode(@RequestBody MetaNode metaNode, HttpServletRequest request, HttpServletResponse response) {<FILL_FUNCTION_BODY>}
//移除实例
@PostMappin... |
CloudNode cloudNode = eruptNodeMicroservice.findNodeByAppName(metaNode.getNodeName(), metaNode.getAccessToken());
if (!cloudNode.getStatus()) {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
throw new RuntimeException(metaNode.getNodeName() + " prohibiting the reg... | 197 | 204 | 401 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/controller/EruptServerApi.java | EruptServerApi | getNodeGroupConfig | class EruptServerApi {
@Resource
private EruptDao eruptDao;
@Resource
private EruptSessionService eruptSessionService;
@Resource
private EruptContextService eruptContextService;
@Resource
private EruptUserService eruptUserService;
@Resource
private EruptNodeMicroservice erup... |
return (String) eruptDao.getEntityManager()
.createQuery("select cloudNodeGroup.config from CloudNode where nodeName = :nodeName and accessToken = :accessToken")
.setParameter("nodeName", nodeName)
.setParameter("accessToken", accessToken).getSingleResult();
| 856 | 76 | 932 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/distribute/ChannelSwapModel.java | ChannelSwapModel | create | class ChannelSwapModel {
private String instanceId;
private Command command;
private Object data;
private ChannelSwapModel() {
}
public static ChannelSwapModel create(String instanceId, Command command, Object data) {<FILL_FUNCTION_BODY>}
public enum Command {
PUT, REMOVE
}... |
ChannelSwapModel channelSwapModel = new ChannelSwapModel();
channelSwapModel.instanceId = instanceId;
channelSwapModel.command = command;
channelSwapModel.data = data;
return channelSwapModel;
| 97 | 63 | 160 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/model/CloudNode.java | CloudNode | afterFetch | class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>, TagsFetchHandler, Tpl.TplHandler {
public static final String NODE_NAME = LambdaSee.field(CloudNode::getNodeName);
public static final String ACCESS_TOKEN = LambdaSee.field(CloudNode::getAccessToken);
@Column(unique = true)
@E... |
for (Map<String, Object> map : list) {
Optional.ofNullable(map.get(ACCESS_TOKEN)).ifPresent(it -> {
String token = it.toString();
map.put(ACCESS_TOKEN, token.substring(0, 3) + "******" + token.substring(token.length() - 3));
});
map.put(Lambda... | 1,369 | 505 | 1,874 | <methods>public non-sealed void <init>() <variables>private java.lang.String updateBy,private java.time.LocalDateTime updateTime |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/node/NodeManager.java | NodeManager | findAllNodes | class NodeManager {
public static final String NODE_SPACE = "node:";
@Resource
private EruptDao eruptDao;
private RedisTemplate<String, MetaNode> redisTemplate;
@Autowired
public void setRedisTemplate(RedisTemplate<?, ?> redisTemplate) {
RedisSerializer<String> stringSerializer = new... |
List<String> keys = eruptDao.queryEntityList(CloudNode.class).stream().map(it ->
eruptCloudServerProp.getCloudNameSpace() + NODE_SPACE + it.getNodeName()
).collect(Collectors.toList());
if (!keys.isEmpty()) {
List<MetaNode> metaNodes = Optional.ofNullable(redisTempla... | 480 | 148 | 628 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/node/NodeWorker.java | NodeWorker | run | class NodeWorker implements Runnable {
private final NodeManager nodeManager;
private final EruptCloudServerProp eruptCloudServerProp;
@PostConstruct
public void postConstruct() {
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(this, 0,
eruptCloudServerProp.getNodeSurv... |
for (MetaNode node : nodeManager.findAllNodes()) {
if (node.getLocations().removeIf(location ->
!CloudServerUtil.retryableNodeHealth(node.getNodeName(),
location, 2, 200))) {
nodeManager.putNode(node);
}
}
| 137 | 83 | 220 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/service/EruptNodeMicroservice.java | EruptNodeMicroservice | findNodeByAppName | class EruptNodeMicroservice {
@Resource
private EruptDao eruptDao;
@Resource
private NodeManager nodeManager;
@Resource
private NodeWorker nodeWorker;
@Resource
private EruptCloudServerProp eruptCloudServerProp;
public CloudNode findNodeByAppName(String nodeName, String accessTo... |
CloudNode cloudNode = eruptDao.queryEntity(CloudNode.class, CloudNode.NODE_NAME + " = :" + CloudNode.NODE_NAME, new HashMap<String, Object>() {{
this.put(CloudNode.NODE_NAME, nodeName);
}});
if (null == cloudNode) {
throw new RuntimeException("NodeName: '" + nodeName + "... | 282 | 170 | 452 | <no_super_class> |
erupts_erupt | erupt/erupt-cloud/erupt-cloud-server/src/main/java/xyz/erupt/cloud/server/util/CloudServerUtil.java | CloudServerUtil | nodeHealth | class CloudServerUtil {
public static EruptCloudServer.Proxy findEruptCloudServerAnnotation() {
EruptCloudServer eruptCloudServer = EruptApplication.getPrimarySource().getAnnotation(EruptCloudServer.class);
return null == eruptCloudServer ? null : EruptSpringUtil.getBean(eruptCloudServer.value());
... |
try {
HttpResponse httpResponse = HttpUtil.createGet(location + CloudRestApiConst.NODE_HEALTH).timeout(1000).execute();
String body = httpResponse.body();
if (StringUtils.isNotBlank(body) && !nodeName.equals(body)) {
log.warn("nodeName mismatch {} != {}", nod... | 279 | 140 | 419 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/cache/EruptCacheLRU.java | EruptCacheLRU | removeEldestEntry | class EruptCacheLRU<V> extends LinkedHashMap<String, EruptCacheLRU.ExpireNode<V>> implements EruptCache<V> {
private final int capacity;
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
public EruptCacheLRU(int capacity) {
super((int) Math.ceil(capacity / 0.75) + 1, 0.75f... |
if (this.size() > capacity) this.clean();
return this.size() > this.capacity;
| 759 | 31 | 790 | <methods>public void <init>() ,public void <init>(int) ,public void <init>(Map<? extends java.lang.String,? extends ExpireNode<V>>) ,public void <init>(int, float) ,public void <init>(int, float, boolean) ,public void clear() ,public boolean containsValue(java.lang.Object) ,public Set<Entry<java.lang.String,ExpireNode<... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/config/EruptGsonExclusionStrategies.java | EruptGsonExclusionStrategies | shouldSkipField | class EruptGsonExclusionStrategies implements ExclusionStrategy {
@Override
@SneakyThrows
public boolean shouldSkipField(FieldAttributes f) {<FILL_FUNCTION_BODY>}
@Override
public boolean shouldSkipClass(Class<?> incomingClass) {
return false;
}
} |
MetaErupt metaErupt = MetaContext.getErupt();
if (null == metaErupt || null == metaErupt.getName()) return false;
if (null == f.getAnnotation(EruptSmartSkipSerialize.class)) return false;
Class<?> currEruptClass = EruptCoreService.getErupt(metaErupt.getName()).getClazz();
if (f.... | 86 | 192 | 278 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/config/MvcConfig.java | MvcConfig | addResourceHandlers | class MvcConfig implements WebMvcConfigurer {
private final EruptProp eruptProp;
private final Set<String> gsonMessageConverterPackage = Stream.of(EruptConst.BASE_PACKAGE, Gson.class.getPackage().getName()).collect(Collectors.toSet());
@Override
public void extendMessageConverters(List<HttpMessageCon... |
String uploadPath = eruptProp.getUploadPath().endsWith("/") ? eruptProp.getUploadPath() : eruptProp.getUploadPath() + "/";
ResourceHandlerRegistration resourceHandlerRegistration = registry.addResourceHandler(EruptRestPath.ERUPT_ATTACHMENT + "/**");
if (uploadPath.startsWith("classpath:")) {
... | 363 | 133 | 496 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/controller/EruptBuildController.java | EruptBuildController | getEruptBuild | class EruptBuildController {
@GetMapping("/{erupt}")
@EruptRouter(authIndex = 1, verifyType = EruptRouter.VerifyType.ERUPT)
@SneakyThrows
public EruptBuildModel getEruptBuild(@PathVariable("erupt") String eruptName) {<FILL_FUNCTION_BODY>}
@GetMapping("/{erupt}/{field}")
@EruptRouter(authIndex ... |
EruptModel eruptView = EruptCoreService.getEruptView(eruptName);
{
//default search conditions
Map<String, Object> conditionsMap = new HashMap<>();
DataProxyInvoke.invoke(eruptView, it -> it.searchCondition(conditionsMap));
eruptView.setSearchCondition(co... | 214 | 652 | 866 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/controller/EruptComponentController.java | EruptComponentController | codeEditHints | class EruptComponentController {
/**
* 自动完成组件联动接口
*
* @param field 自动完成组件字段
* @param val 输入框的值
* @param formData 完整表单对象
* @return 联想结果
*/
@PostMapping("/auto-complete/{erupt}/{field}")
@EruptRouter(authIndex = 2, verifyType = EruptRouter.VerifyType.ERUPT)
publ... |
EruptFieldModel fieldModel = EruptCoreService.getErupt(eruptName).getEruptFieldMap().get(field);
CodeEditorType codeEditType = fieldModel.getEruptField().edit().codeEditType();
return EruptSpringUtil.getBean(codeEditType.hint()).hint(codeEditType.hintParams());
| 801 | 88 | 889 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/controller/EruptTabController.java | EruptTabController | updateTabEruptData | class EruptTabController {
private final Gson gson = GsonFactory.getGson();
//TAB组件新增行为
@PostMapping({"/tab-add/{erupt}/{tabName}"})
@EruptRouter(skipAuthIndex = 3, authIndex = 2, verifyType = EruptRouter.VerifyType.ERUPT)
public EruptApiModel addTabEruptData(@PathVariable("erupt") String erupt, @... |
EruptModel eruptModel = getTabErupt(erupt, tabName);
Object obj = gson.fromJson(data.toString(), eruptModel.getClazz());
EruptApiModel eruptApiModel = this.tabValidate(eruptModel, data, dp -> {
dp.beforeUpdate(obj);
dp.afterUpdate(obj);
});
eruptApiModel.... | 877 | 117 | 994 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/controller/advice/EruptExceptionAdvice.java | EruptExceptionAdvice | eruptException | class EruptExceptionAdvice {
private static final String ERE = "erupt exception";
@ExceptionHandler(EruptApiErrorTip.class)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public EruptApiModel eruptApiErrorTip(EruptApiErrorTip e) {
log.error(ERE, e);
e.eruptApiModel.setErrorIn... |
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
log.error(ERE, e);
return new EruptExceptionVo(request.getServletPath(), response.getStatus(), ERE, e instanceof RuntimeException ? e.getMessage() : null);
| 174 | 70 | 244 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/exception/EruptAnnotationException.java | EruptAnnotationException | validateEruptInfo | class EruptAnnotationException extends RuntimeException {
public EruptAnnotationException(String message) {
super(message);
}
public static void validateEruptInfo(EruptModel eruptModel) {<FILL_FUNCTION_BODY>}
} |
if (null == eruptModel.getEruptFieldMap().get(eruptModel.getErupt().primaryKeyCol())) {
throw ExceptionAnsi.styleEruptException(eruptModel, "找不到主键,请确认主键列名是否为" + eruptModel.getErupt().primaryKeyCol() +
",如果你不想将主键名定义为'" + eruptModel.getErupt().primaryKeyCol() + "'则可以修改@erupt->prim... | 66 | 128 | 194 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.Throwable) ,public void <init>(java.lang.String, java.lang.Throwable) <variables>static final long serialVersionUID |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/exception/EruptFieldAnnotationException.java | EruptFieldAnnotationException | validateEruptFieldInfo | class EruptFieldAnnotationException extends RuntimeException {
public EruptFieldAnnotationException(String message) {
super(message);
}
public static void validateEruptFieldInfo(EruptFieldModel eruptFieldModel) {<FILL_FUNCTION_BODY>}
} |
Edit edit = eruptFieldModel.getEruptField().edit();
switch (edit.type()) {
case REFERENCE_TREE:
case REFERENCE_TABLE:
for (View view : eruptFieldModel.getEruptField().views()) {
if ("".equals(view.column())) {
throw Exc... | 70 | 133 | 203 | <methods>public void <init>() ,public void <init>(java.lang.String) ,public void <init>(java.lang.Throwable) ,public void <init>(java.lang.String, java.lang.Throwable) <variables>static final long serialVersionUID |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/exception/ExceptionAnsi.java | ExceptionAnsi | styleEruptFieldException | class ExceptionAnsi {
public static EruptFieldAnnotationException styleEruptFieldException(EruptFieldModel eruptFieldModel, String message) {<FILL_FUNCTION_BODY>}
public static EruptAnnotationException styleEruptException(EruptModel eruptModel, String message) {
return new EruptAnnotationException(
... |
return new EruptFieldAnnotationException(
ansi().fg(Ansi.Color.RED).a(message).fg(Ansi.Color.BLUE)
.a("(" + eruptFieldModel.getField().getDeclaringClass().getName() + EruptConst.DOT
+ eruptFieldModel.getField().getName() + ")").reset().toS... | 147 | 93 | 240 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/i18n/I18nRunner.java | I18nRunner | run | class I18nRunner extends LinkedCaseInsensitiveMap<Map<String, String>> implements ApplicationRunner {
//语言文件对应文字映射
private static final I18nRunner langMappings = new I18nRunner();
private static final String I18N_EXT = ".csv";
public static String getI18nValue(String lang, String key) {
if (n... |
Enumeration<URL> urls = I18nRunner.class.getClassLoader().getResources("i18n/");
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
switch (url.getProtocol()) {
case "file":
scanFile(new File(URLDecoder.decode(url.getFile(), Charse... | 831 | 156 | 987 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/i18n/I18nTranslate.java | I18nTranslate | getLang | class I18nTranslate {
@Resource
private HttpServletRequest request;
@Resource
private EruptProp eruptProp;
public static String $translate(String key) {
return EruptSpringUtil.getBean(I18nTranslate.class).translate(key);
}
public String translate(String key) {
String lang... |
try {
return request.getHeader("lang");
} catch (Exception ignored) {
return null;
}
| 160 | 34 | 194 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/invoke/DataProcessorManager.java | DataProcessorManager | getEruptDataProcessor | class DataProcessorManager {
private static final Map<String, Class<? extends IEruptDataService>> eruptDataServiceMap = new HashMap<>();
public static void register(String name, Class<? extends IEruptDataService> eruptDataService) {
eruptDataServiceMap.put(name, eruptDataService);
}
public st... |
EruptDataProcessor eruptDataProcessor = clazz.getAnnotation(EruptDataProcessor.class);
return EruptSpringUtil.getBean(eruptDataServiceMap.get(null == eruptDataProcessor ?
EruptConst.DEFAULT_DATA_PROCESSOR : eruptDataProcessor.value()));
| 119 | 75 | 194 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/invoke/DataProxyInvoke.java | DataProxyInvoke | invoke | class DataProxyInvoke {
public static void invoke(EruptModel eruptModel, Consumer<DataProxy<Object>> consumer) {<FILL_FUNCTION_BODY>}
private static void actionInvokePreDataProxy(Class<?> clazz, Consumer<DataProxy<Object>> consumer) {
//接口
Stream.of(clazz.getInterfaces()).forEach(it -> Optiona... |
//父类及接口 @PreDataProxy
ReflectUtil.findClassExtendStack(eruptModel.getClazz()).forEach(clazz -> DataProxyInvoke.actionInvokePreDataProxy(clazz, consumer));
//本类及接口 @PreDataProxy
DataProxyInvoke.actionInvokePreDataProxy(eruptModel.getClazz(), consumer);
//@Erupt → DataProxy
... | 239 | 135 | 374 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/invoke/ExprInvoke.java | ExprInvoke | getExpr | class ExprInvoke {
public static String getExpr(Expr expr) {
String value = expr.value();
if (!expr.exprHandler().isInterface()) {
value = EruptSpringUtil.getBean(expr.exprHandler()).handler(value, expr.params());
}
return value;
}
public static Boolean getExpr(... |
float value = expr.value();
if (!expr.exprHandler().isInterface()) {
value = EruptSpringUtil.getBean(expr.exprHandler()).handler(value, expr.params());
}
return value;
| 347 | 61 | 408 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/invoke/PowerInvoke.java | PowerInvoke | getPowerObject | class PowerInvoke {
private static final List<Class<? extends PowerHandler>> powerHandlerStack = new ArrayList<>();
public static void registerPowerHandler(Class<? extends PowerHandler> powerHandler) {
powerHandlerStack.add(powerHandler);
}
//动态获取erupt power值
public static PowerObject get... |
Power power = eruptModel.getErupt().power();
if (eruptModel.getErupt().authVerify()) {
PowerObject powerBean = new PowerObject(power);
if (eruptModel.getErupt().authVerify()) {
powerHandlerStack.forEach(ph -> EruptSpringUtil.getBean(ph).handler(powerBean));
... | 106 | 147 | 253 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/module/MetaMenu.java | MetaMenu | createSimpleMenu | class MetaMenu {
private Long id; //无需传递此参数
private String code;
private String name;
private MenuStatus status;
private String type;
private String value;
private Integer sort;
private String icon;
private MetaMenu parentMenu;
public MetaMenu() {
}
public stat... |
MetaMenu metaMenu = new MetaMenu();
metaMenu.code = code;
metaMenu.name = name;
metaMenu.status = menuStatus;
metaMenu.type = type;
metaMenu.value = value;
metaMenu.sort = sort;
metaMenu.parentMenu = parent;
metaMenu.icon = icon;
return me... | 603 | 96 | 699 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/naming/EruptRecordNaming.java | EruptRecordNaming | naming | class EruptRecordNaming implements EruptRecordOperate.DynamicConfig {
@Override
public String naming(String desc, String menuName, String eruptName, Method method) {<FILL_FUNCTION_BODY>}
} |
EruptRouter eruptRouter = method.getAnnotation(EruptRouter.class);
if (null != eruptRouter && eruptRouter.verifyType() == EruptRouter.VerifyType.ERUPT) {
String prefix = desc + " | ";
if (null != menuName) {
return prefix + menuName;
} else if (null !... | 60 | 187 | 247 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/naming/EruptRowOperationNaming.java | EruptRowOperationNaming | findRowOperation | class EruptRowOperationNaming implements EruptRecordOperate.DynamicConfig {
@Resource
private HttpServletRequest request;
@Override
public String naming(String desc, String menuName, String eruptName, Method method) {
EruptModel erupt = EruptCoreService.getErupt(eruptName);
if (null ==... |
String code = request.getServletPath().split(EruptDataController.OPERATOR_PATH_STR + "/")[1];
return Arrays.stream(eruptModel.getErupt().rowOperation())
.filter(operation -> operation.code().equals(code)).findFirst()
.orElseThrow(() -> new RuntimeException(eruptModel.get... | 166 | 105 | 271 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/AnnotationProcess.java | AnnotationProcess | annotationToJsonByReflect | class AnnotationProcess {
private static final String[] ANNOTATION_NUMBER_TYPE = {"short", "int", "long", "float", "double"};
private static final String[] ANNOTATION_STRING_TYPE = {"String", "byte", "char"};
private static final String EMPTY_ARRAY = "[]";
private static final String VALUE_VAR = "va... |
JsonObject jsonObject = new JsonObject();
for (Method method : annotation.annotationType().getDeclaredMethods()) {
Transient tran = method.getAnnotation(Transient.class);
if (null != tran && tran.value()) continue;
String methodName = method.getName();
Er... | 624 | 1,052 | 1,676 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/AnnotationProxy.java | AnnotationProxy | newProxy | class AnnotationProxy<A, PA> {
// 原始注解
public A rawAnnotation;
// 代理后新注解
public A proxyAnnotation;
// 向上引用
protected AnnotationProxy<PA, ?> parent;
protected abstract Object invocation(MethodInvocation invocation);
public A newProxy(A annotation) {
return this.newProxy(annot... |
this.parent = parent;
this.rawAnnotation = annotation;
ProxyFactory proxyFactory = new ProxyFactory(annotation);
MethodInterceptor interceptor = this::invocation;
proxyFactory.addAdvice(interceptor);
this.proxyAnnotation = (A) proxyFactory.getProxy(this.getClass().getCla... | 264 | 96 | 360 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/AnnotationProxyPool.java | AnnotationProxyPool | getOrPut | class AnnotationProxyPool {
/**
* generic key raw annotation
* generic value proxy annotation
*/
private static final Map<Annotation, Annotation> annotationPool = new HashMap<>();
public static <A extends Annotation> A getOrPut(A rawAnnotation, Function<A, A> function) {<FILL_FUNCTION_BODY>... |
if (annotationPool.containsKey(rawAnnotation)) return (A) annotationPool.get(rawAnnotation);
A proxyAnnotation = function.apply(rawAnnotation);
annotationPool.put(rawAnnotation, proxyAnnotation);
return proxyAnnotation;
| 92 | 60 | 152 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/EruptFieldProxy.java | EruptFieldProxy | invocation | class EruptFieldProxy extends AnnotationProxy<EruptField, Void> {
private static final EruptField tplEruptField;
static {
try {
tplEruptField = EruptTpl.class.getField(EruptField.class.getSimpleName()).getAnnotation(EruptField.class);
} catch (NoSuchFieldException e) {
... |
if (super.matchMethod(invocation, EruptField::views)) {
View[] views = this.rawAnnotation.views();
List<View> proxyViews = new ArrayList<>();
for (View view : views) {
if (ExprInvoke.getExpr(view.ifRender())) {
proxyViews.add(AnnotationPro... | 149 | 239 | 388 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.EruptField newProxy(xyz.erupt.annotation.EruptField) ,public xyz.erupt.annotation.EruptField newProxy(xyz.erupt.annotation.EruptField, Ann... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/EruptProxy.java | EruptProxy | invocation | class EruptProxy extends AnnotationProxy<Erupt, Void> {
@Override
@SneakyThrows
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, Erupt::filter)) {
Filter[] filters = this.rawAnnotation.filter();
Filter[] proxyFilters = new Filter[filters.length];
for (int i = 0; i < filters.length; i++) {
proxyFilters[i] = AnnotationProxyPool.getOrPut(filters[i], filte... | 59 | 427 | 486 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.Erupt newProxy(xyz.erupt.annotation.Erupt) ,public xyz.erupt.annotation.Erupt newProxy(xyz.erupt.annotation.Erupt, AnnotationProxy<java.la... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/ProxyContext.java | ProxyContext | translate | class ProxyContext {
private static final ThreadLocal<ProxyContext> proxyContextThreadLocal = ThreadLocal.withInitial(ProxyContext::new);
private Class<?> clazz;
private Field field;
private boolean i18n = false;
public static void set(Class<?> clazz) {
proxyContextThreadLocal.get().set... |
if (ProxyContext.get().i18n) {
return EruptSpringUtil.getBean(I18nTranslate.class).translate(key);
} else {
return key;
}
| 248 | 56 | 304 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt/DrillProxy.java | DrillProxy | invocation | class DrillProxy extends AnnotationProxy<Drill, Erupt> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, Drill::code) && AnnotationConst.EMPTY_STR.equals(this.rawAnnotation.code())) {
return Integer.toString(this.rawAnnotation.title().hashCode());
} else if (super.matchMethod(invocation, Drill::title)) {
return ProxyContext.translate(this.rawAnnota... | 51 | 107 | 158 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_erupt.Drill newProxy(xyz.erupt.annotation.sub_erupt.Drill) ,public xyz.erupt.annotation.sub_erupt.Drill newProxy(xyz.erupt.annotation.... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt/FilterProxy.java | FilterProxy | invocation | class FilterProxy<P> extends AnnotationProxy<Filter, P> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, Filter::value)) {
String condition = this.rawAnnotation.value();
if (!this.rawAnnotation.conditionHandler().isInterface()) {
FilterHandler ch = EruptSpringUtil.getBean(this.rawAnnotation.conditionHandler());
condition = c... | 51 | 109 | 160 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_erupt.Filter newProxy(xyz.erupt.annotation.sub_erupt.Filter) ,public xyz.erupt.annotation.sub_erupt.Filter newProxy(xyz.erupt.annotati... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt/RowOperationProxy.java | RowOperationProxy | invocation | class RowOperationProxy extends AnnotationProxy<RowOperation, Erupt> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, RowOperation::code)) {
if (AnnotationConst.EMPTY_STR.equals(this.rawAnnotation.code())) {
return Integer.toString(this.rawAnnotation.title().hashCode());
}
} else if (super.matchMethod(invocation, RowOperation::tip)) {
... | 50 | 193 | 243 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_erupt.RowOperation newProxy(xyz.erupt.annotation.sub_erupt.RowOperation) ,public xyz.erupt.annotation.sub_erupt.RowOperation newProxy(... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt_field/EditProxy.java | EditProxy | invocation | class EditProxy extends AnnotationProxy<Edit, EruptField> {
@Override
@SneakyThrows
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, Edit::type)) {
if (EditType.AUTO == this.rawAnnotation.type()) {
String returnType = ProxyContext.get().getField().getType().getSimpleName();
if (boolean.class.getSimpleName().equalsIgnoreCase(returnType)) {
retur... | 58 | 541 | 599 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_field.Edit newProxy(xyz.erupt.annotation.sub_field.Edit) ,public xyz.erupt.annotation.sub_field.Edit newProxy(xyz.erupt.annotation.sub... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt_field/ReadonlyProxy.java | ReadonlyProxy | invocation | class ReadonlyProxy extends AnnotationProxy<Readonly, Edit> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
Readonly readonly = this.rawAnnotation;
if (!readonly.exprHandler().isInterface()) {
Readonly.ReadonlyHandler readonlyHandler = EruptSpringUtil.getBean(readonly.exprHandler());
if (super.matchMethod(invocation, Readonly::add)) {
return readonlyHandler.add(readonl... | 50 | 142 | 192 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_field.Readonly newProxy(xyz.erupt.annotation.sub_field.Readonly) ,public xyz.erupt.annotation.sub_field.Readonly newProxy(xyz.erupt.an... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt_field/ViewProxy.java | ViewProxy | invocation | class ViewProxy extends AnnotationProxy<View, EruptField> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, View::type)) {
if (ViewType.AUTO == this.rawAnnotation.type()) {
Edit edit = this.parent.proxyAnnotation.edit();
if (!AnnotationConst.EMPTY_STR.equals(edit.title())) {
switch (edit.type()) {
... | 50 | 517 | 567 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_field.View newProxy(xyz.erupt.annotation.sub_field.View) ,public xyz.erupt.annotation.sub_field.View newProxy(xyz.erupt.annotation.sub... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/proxy/erupt_field/type/BoolTypeProxy.java | BoolTypeProxy | invocation | class BoolTypeProxy extends AnnotationProxy<BoolType, Edit> {
@Override
protected Object invocation(MethodInvocation invocation) {<FILL_FUNCTION_BODY>}
} |
if (super.matchMethod(invocation, BoolType::trueText)) {
return I18nTranslate.$translate(this.rawAnnotation.trueText());
} else if (super.matchMethod(invocation, BoolType::falseText)) {
return I18nTranslate.$translate(this.rawAnnotation.falseText());
}
return thi... | 51 | 100 | 151 | <methods>public non-sealed void <init>() ,public java.lang.Object invoke(MethodInvocation) ,public boolean matchMethod(MethodInvocation, SFunction<T,R>) ,public xyz.erupt.annotation.sub_field.sub_edit.BoolType newProxy(xyz.erupt.annotation.sub_field.sub_edit.BoolType) ,public xyz.erupt.annotation.sub_field.sub_edit.Boo... |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/service/EruptApplication.java | EruptApplication | registerBeanDefinitions | class EruptApplication implements ImportBeanDefinitionRegistrar {
private static Class<?> primarySource;
private static final Set<String> scanPackage = new HashSet<>();
public static Class<?> getPrimarySource() {
return primarySource;
}
public static String[] getScanPackage() {
r... |
Class<?> clazz = ClassUtils.forName(importingClassMetadata.getClassName(), ClassUtils.getDefaultClassLoader());
Optional.ofNullable(clazz.getAnnotation(SpringBootApplication.class)).ifPresent(it -> primarySource = clazz);
EruptScan eruptScan = clazz.getAnnotation(EruptScan.class);
try {... | 146 | 241 | 387 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/service/EruptCoreService.java | EruptCoreService | initEruptModel | class EruptCoreService implements ApplicationRunner {
private static final Map<String, EruptModel> ERUPTS = new LinkedCaseInsensitiveMap<>();
private static final List<EruptModel> ERUPT_LIST = new ArrayList<>();
private static final List<String> MODULES = new ArrayList<>();
public static List<String... |
// erupt class data to memory
EruptModel eruptModel = new EruptModel(clazz);
// erupt field data to memory
eruptModel.setEruptFieldModels(new ArrayList<>());
eruptModel.setEruptFieldMap(new LinkedCaseInsensitiveMap<>());
ReflectUtil.findClassAllFields(clazz, field -> Opt... | 1,081 | 274 | 1,355 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/service/EruptService.java | EruptService | getEruptData | class EruptService {
@Resource
private HttpServletRequest request;
/**
* @param eruptModel eruptModel
* @param tableQuery 前端查询对象
* @param serverCondition 自定义条件
* @param customCondition 条件字符串
*/
public Page getEruptData(EruptModel eruptModel, TableQuery tableQuery, Li... |
Erupts.powerLegal(eruptModel, PowerObject::isQuery);
List<Condition> legalConditions = EruptUtil.geneEruptSearchCondition(eruptModel, tableQuery.getCondition());
List<String> conditionStrings = new ArrayList<>();
//DependTree logic
LinkTree dependTree = eruptModel.getErupt().lin... | 733 | 722 | 1,455 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/service/PreEruptDataService.java | PreEruptDataService | createColumnQuery | class PreEruptDataService {
/**
* 根据要素生成树结构
*
* @param eruptModel eruptModel
* @param id id
* @param label label
* @param pid parent id
* @param query 查询对象
* @return 树对象
*/
public Collection<TreeModel> geneTree(EruptModel eruptModel, String ... |
List<String> conditionStrings = new ArrayList<>();
DataProxyInvoke.invoke(eruptModel, (dataProxy -> {
String condition = dataProxy.beforeFetch(query.getConditions());
if (StringUtils.isNotBlank(condition)) {
conditionStrings.add(condition);
}
... | 414 | 303 | 717 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/toolkit/TimeRecorder.java | TimeRecorder | recorder | class TimeRecorder {
private Long current;
public TimeRecorder() {
this.current = System.currentTimeMillis();
}
public synchronized long recorder() {<FILL_FUNCTION_BODY>}
} |
try {
return System.currentTimeMillis() - this.current;
} finally {
this.current = System.currentTimeMillis();
}
| 64 | 43 | 107 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/CloneSupport.java | CloneSupport | clone | class CloneSupport<T> implements Cloneable {
@Override
public T clone() {<FILL_FUNCTION_BODY>}
} |
try {
return (T) super.clone();
} catch (Exception e) {
throw new RuntimeException(e);
}
| 40 | 38 | 78 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/DataHandlerUtil.java | DataHandlerUtil | convertColumnValue | class DataHandlerUtil {
// 引用方式 生成树结构数据
public static List<TreeModel> quoteTree(List<TreeModel> treeModels) {
Map<String, TreeModel> treeModelMap = new LinkedHashMap<>(treeModels.size());
treeModels.forEach(treeModel -> treeModelMap.put(treeModel.getId(), treeModel));
List<TreeModel> re... |
if (null == value) return null;
Edit edit = fieldModel.getEruptField().edit();
switch (edit.type()) {
case CHOICE:
Map<String, String> cm = choiceItems.get(fieldModel.getFieldName());
if (null == cm) {
cm = EruptUtil.getChoiceMap(e... | 826 | 169 | 995 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/DateUtil.java | DateUtil | getDate | class DateUtil {
public static final String DATE = "yyyy-MM-dd";
public static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";
public static String getSimpleFormatDateTime(Date date) {
return getFormatDate(date, DATE_TIME);
}
public static String getSimpleFormatDate(Date date) {
... |
if (targetDateType == Date.class) {
if (str.length() == 10) {
return new SimpleDateFormat(DATE).parse(str);
} else {
return new SimpleDateFormat(DATE_TIME).parse(str);
}
} else if (targetDateType == LocalDate.class) {
retur... | 202 | 163 | 365 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/EruptAssert.java | EruptAssert | notNull | class EruptAssert {
public static void notNull(Object[] arr, String message) {<FILL_FUNCTION_BODY>}
} |
if (null == arr || arr.length == 0) {
throw new IllegalArgumentException(message);
}
| 38 | 30 | 68 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/EruptSpringUtil.java | EruptSpringUtil | getBean | class EruptSpringUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (EruptSpringUtil.applicationContext == null) {
EruptSpringUtil.... |
if (null != clazz.getDeclaredAnnotation(Component.class)
|| null != clazz.getDeclaredAnnotation(Service.class)
|| null != clazz.getDeclaredAnnotation(Repository.class)
|| null != clazz.getDeclaredAnnotation(RestController.class)
|| null != clazz.g... | 537 | 126 | 663 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/MD5Util.java | MD5Util | byteToArrayString | class MD5Util {
private final static String[] STR_DIGITS = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
private static String byteToArrayString(byte bByte) {<FILL_FUNCTION_BODY>}
private static String byteToString(byte[] bByte) {
StringBuilder sb = new StringB... |
int iRet = bByte;
if (iRet < 0) {
iRet += 256;
}
int iD1 = iRet / 16;
int iD2 = iRet % 16;
return STR_DIGITS[iD1] + STR_DIGITS[iD2];
| 345 | 88 | 433 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/MimeUtil.java | MimeUtil | getMimeType | class MimeUtil {
private static final Properties mimes = new Properties();
static {
try (InputStream in = MimeUtil.class.getClassLoader().getResourceAsStream("mime.properties")) {
mimes.load(in);
} catch (IOException e) {
log.warn("mime file load error", e);
}
... |
String[] nameSplits = fileName.split("\\.");
String type = mimes.getProperty(nameSplits[nameSplits.length - 1]);
if (StringUtils.isBlank(type)) {
type = MediaType.APPLICATION_OCTET_STREAM_VALUE;
}
return type;
| 121 | 88 | 209 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/ProjectUtil.java | ProjectUtil | projectStartLoaded | class ProjectUtil {
private static final String LOADED_EXT = ".loaded";
/**
* @param projectName 标识名
* @param first bool回调,表示函数是否为第一次调用
*/
@SneakyThrows
public void projectStartLoaded(String projectName, Consumer<Boolean> first) {<FILL_FUNCTION_BODY>}
} |
String userDir = System.getProperty("user.dir");
File dirFile = new File(userDir, EruptConst.ERUPT_DIR);
String warnTxt = " The erupt initialization ID file could not be created";
if (!dirFile.exists() && !dirFile.mkdirs()) {
log.warn(dirFile + warnTxt);
}
Fi... | 103 | 213 | 316 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/ReflectUtil.java | ReflectUtil | findFieldChain | class ReflectUtil {
//递归查找类字段
public static Field findClassField(Class<?> clazz, String fieldName) {
Field field;
while (clazz != null) {
try {
field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
... |
String[] fields = fieldName.split("\\.");
for (String field : fields) {
Field f = findClassField(obj.getClass(), field);
if (f == null) {
throw new RuntimeException(obj.getClass().getName() + EruptConst.DOT + fieldName + " not found");
}
i... | 611 | 115 | 726 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/SecretUtil.java | SecretUtil | decodeSecret | class SecretUtil {
public static String decodeSecret(String str) {
return decodeSecret(str, 1);
}
/**
* 解密Base64
*
* @param str 加密字符串
* @param encodeNum 被加密了几次
* @return 原文
*/
@SneakyThrows
public static String decodeSecret(String str, int encodeNum) {<... |
for (int i = 0; i < encodeNum; i++) {
str = new String(Base64.getDecoder().decode(str));
}
return URLDecoder.decode(str, StandardCharsets.UTF_8.name());
| 128 | 64 | 192 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/SecurityUtil.java | SecurityUtil | xssInspect | class SecurityUtil {
// xss跨站脚本检测
public static boolean xssInspect(String value) {<FILL_FUNCTION_BODY>}
//检测 跨站请求伪造
public static boolean csrfInspect(HttpServletRequest request, HttpServletResponse response) {
String origin = request.getHeader("Origin");
if (null != origin && !origin.c... |
if (StringUtils.isNotBlank(value)) {
// 避免script 标签
Pattern scriptPattern = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE);
if (scriptPattern.matcher(value).find()) {
return true;
}
// 避免src形式的表达式
scrip... | 238 | 921 | 1,159 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/util/TypeUtil.java | TypeUtil | typeStrConvertObject | class TypeUtil {
private static final String[] SIMPLE_JPA_TYPE = {
"byte", "short", "int", "integer", "long", "float", "double", "boolean", "char", "String", "date", "character", "char"
};
private static final String[] NUMBER_TYPE = {
"short", "int", "integer", "long", "float", "doub... |
String str = obj.toString();
if (NumberUtils.isCreatable(str)) {
if (str.endsWith(".0")) { //处理gson序列化数值多了一个0
str = str.substring(0, str.length() - 2);
}
}
if (int.class == targetType || Integer.class == targetType) {
return Integer.v... | 581 | 337 | 918 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/view/EruptApiModel.java | EruptApiModel | errorNoInterceptApi | class EruptApiModel {
private Status status;
private PromptWay promptWay;
private String message;
private Object data;
private boolean errorIntercept = true;
public EruptApiModel(Status status, String message, Object data, PromptWay promptWay) {
this.status = status;
this.m... |
EruptApiModel eruptApiModel = new EruptApiModel(Status.ERROR, message, null, PromptWay.DIALOG);
eruptApiModel.errorIntercept = false;
return eruptApiModel;
| 573 | 59 | 632 | <no_super_class> |
erupts_erupt | erupt/erupt-core/src/main/java/xyz/erupt/core/view/EruptModel.java | EruptModel | clone | class EruptModel implements Cloneable {
private transient Class<?> clazz;
private transient Erupt erupt;
private transient AnnotationProxy<Erupt, Void> eruptAnnotationProxy = new EruptProxy();
private transient Map<String, EruptFieldModel> eruptFieldMap;
private transient boolean i18n;
pri... |
EruptModel eruptModel = (EruptModel) super.clone();
eruptModel.eruptJson = AnnotationProcess.annotationToJsonByReflect(this.getErupt());
eruptModel.eruptFieldModels = eruptFieldModels.stream().map(CloneSupport::clone)
.peek(EruptFieldModel::serializable).collect(Collectors.toLis... | 403 | 103 | 506 | <no_super_class> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.