-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba7aeab
commit baa6a94
Showing
33 changed files
with
703 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
nop-rule/nop-rule-core/src/main/java/io/nop/rule/core/IRuleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
nop-rule/nop-rule-core/src/main/java/io/nop/rule/core/execute/ComputedInputRule.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...le/nop-rule-core/src/main/java/io/nop/rule/core/execute/NormalizeInputExecutableRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.nop.rule.core.execute; | ||
|
||
import io.nop.api.core.exceptions.NopException; | ||
import io.nop.api.core.util.Guard; | ||
import io.nop.commons.util.StringHelper; | ||
import io.nop.core.reflect.bean.BeanTool; | ||
import io.nop.core.type.IGenericType; | ||
import io.nop.rule.core.IExecutableRule; | ||
import io.nop.rule.core.IRuleRuntime; | ||
import io.nop.rule.core.model.RuleInputDefineModel; | ||
|
||
import java.util.List; | ||
|
||
import static io.nop.rule.core.RuleErrors.ARG_DISPLAY_NAME; | ||
import static io.nop.rule.core.RuleErrors.ARG_VAR_NAME; | ||
import static io.nop.rule.core.RuleErrors.ERR_RULE_INPUT_VAR_NOT_ALLOW_EMPTY; | ||
|
||
public class NormalizeInputExecutableRule implements IExecutableRule { | ||
private final List<RuleInputDefineModel> inputDefines; | ||
private final IExecutableRule rule; | ||
|
||
public NormalizeInputExecutableRule(List<RuleInputDefineModel> inputDefines, IExecutableRule rule) { | ||
this.inputDefines = Guard.notEmpty(inputDefines, "inputDefines"); | ||
this.rule = rule; | ||
} | ||
|
||
@Override | ||
public boolean execute(IRuleRuntime ruleRt) { | ||
for (RuleInputDefineModel inputDefine : inputDefines) { | ||
String name = inputDefine.getName(); | ||
Object value = ruleRt.getInput(name); | ||
|
||
if (inputDefine.isComputed()) { | ||
// 计算表达式 | ||
value = inputDefine.getDefaultExpr() == null ? null : inputDefine.getDefaultExpr().invoke(ruleRt); | ||
} else if (value == null) { | ||
if (inputDefine.getDefaultExpr() != null) { | ||
value = inputDefine.getDefaultExpr().invoke(ruleRt); | ||
} | ||
} | ||
|
||
if (inputDefine.isMandatory()) { | ||
if (StringHelper.isEmptyObject(value)) | ||
throw new NopException(ERR_RULE_INPUT_VAR_NOT_ALLOW_EMPTY) | ||
.source(inputDefine) | ||
.param(ARG_VAR_NAME, name) | ||
.param(ARG_DISPLAY_NAME, inputDefine.getDisplayName()); | ||
} | ||
|
||
IGenericType type = inputDefine.getType(); | ||
if (type != null && value != null) { | ||
value = BeanTool.castBeanToType(value, type); | ||
} | ||
ruleRt.getEvalScope().setLocalValue(name, value); | ||
} | ||
return rule.execute(ruleRt); | ||
} | ||
} |
Oops, something went wrong.