本文整理汇总了Java中org.drools.definition.KnowledgePackage类的典型用法代码示例。如果您正苦于以下问题:Java KnowledgePackage类的具体用法?Java KnowledgePackage怎么用?Java KnowledgePackage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KnowledgePackage类属于org.drools.definition包,在下文中一共展示了KnowledgePackage类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DroolsFrameAdapter
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public DroolsFrameAdapter(KnowledgeBase kb) {
this.kb = kb;
setName("Drools Runtime Engine");
List<String> names = new ArrayList<String>();
for (KnowledgePackage pkg : kb.getKnowledgePackages()) {
names.add(pkg.getName());
}
addMeta("drools.packages", names);
// custom 'ALL' trigger, let the KnowledgeBase resolve what it wants to do.
addTrigger(new IFrameTrigger<PatientEvent<IPatientObject>>(PatientEvent.class, null) {
protected boolean doEval(PatientEvent<IPatientObject> event) {
// TODO: only return true if there was an activation?
return true;
}
});
}
示例2: initializeRules
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void initializeRules() {
Resource ruleSet = null;
if(ruleString != null) {
ruleSet = ResourceFactory.newReaderResource(new StringReader(ruleString));
} else {
ruleSet = ResourceFactory.newFileResource(ruleFilePath);
}
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ruleSet, ResourceType.DRL);
if(kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Failed to compile drl");
}
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
// Cache the knowledge base as its creation is intensive
kbase.addKnowledgePackages(pkgs);
}
示例3: initializeRules
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void initializeRules() {
Resource ruleSet = null;
if (ruleString != null) {
ruleSet = ResourceFactory.newReaderResource(new StringReader(ruleString));
} else {
ruleSet = ResourceFactory.newFileResource(ruleFilePath);
}
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ruleSet, ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException(BaseMessages.getString(PKG, "RulesData.Error.CompileDRL")); //$NON-NLS-1$
}
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
// Cache the knowledge base as its creation is intensive
kbase.addKnowledgePackages(pkgs);
}
示例4: registerKnowledgeBase
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
/**
* register the knowledge base from the rule builder in the knowledge base.
*/
protected void registerKnowledgeBase() {
if (null != kbase) {
// we don't need to register the knowledge-base again.
return;
}
log.debug("register knowledge base.");
// get the compiled packages
final Collection<KnowledgePackage> pkgs = kbuilder
.getKnowledgePackages();
// add the packages to a knowledge-base (deploy the knowledge packages).
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
}
示例5: syncNow
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
private void syncNow() {
LOG.debug("Initiating new synchornization");
Date previousLastDate = lastDeploymentDate;
LOG.debug("Previous deployment last date '{}'", previousLastDate);
LOG.debug("Creating package builder and configuring it");
PackageBuilder builder = new PackageBuilder();
BPMN2ProcessFactory.configurePackageBuilder(builder);
List<WorkflowDefinition> allDefs = workflowService.getAllWorkflowDefinition();
int installed = 0;
LOG.debug("Checking {} workflow definitions", allDefs.size());
for (WorkflowDefinition def : allDefs) {
Deployment deployment = workflowService.getDeployment(def.getDeploymemtId());
LOG.debug("Check if deployment must be sincronized, deployment date: {} ", deployment.getDeploymentDate());
if (deployment.getDeploymentDate().compareTo(previousLastDate) > 0) {
try {
LOG.debug("Need to deploy to kbase, building process for Workflow, Id: {}, Key: {}, Version: {}",
new Object[] { def.getId(), def.getKey(), def.getVersion() });
builder.addProcessFromXml(getResourceFromDefinition(def));
installed++;
Date deploymentDate = deployment.getDeploymentDate();
lastDeploymentDate = deploymentDate.compareTo(lastDeploymentDate) > 0 ? deploymentDate : lastDeploymentDate;
} catch (Exception e) {
LOG.error(String.format("Cant register process %s becouse has thorwn an exception", def.getKey()), e);
}
}
}
if (installed > 0 && builder.getPackage() != null) {
LOG.debug("Total process builts: {}", installed);
kbase.addKnowledgePackages(Arrays.asList((KnowledgePackage) new KnowledgePackageImp(builder.getPackage())));
}
}
示例6: execute
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void execute(String ruleSet) {
log.info("Starting PrintOutAllKnowledgePackages Execution");
try {
KnowledgeBaseWrapper knowledgeBaseWrapper = gigaSpace.read(new KnowledgeBaseWrapper(ruleSet));
if(knowledgeBaseWrapper != null) {
KnowledgeBase knowledgeBase = knowledgeBaseWrapper.getKnowledgeBase();
Collection<KnowledgePackage> knowledgePackages = knowledgeBase.getKnowledgePackages();
if(knowledgePackages != null) {
for(KnowledgePackage knowledgePackage : knowledgePackages) {
log.info("Begin KnowledgePackage: " + knowledgePackage.getName());
Collection<Rule> rules = knowledgePackage.getRules();
if(rules != null) {
for(Rule rule : rules) {
log.info("Rule ID: " + rule.getId());
log.info("Rule Name: " + rule.getName());
}
}else {
log.info("rules are null for ruleSet: " + ruleSet);
}
log.info("End KnowledgePackage: " + knowledgePackage.getName());
}
}else {
log.info("knowledgePackages are null for ruleSet: " + ruleSet);
}
}else {
log.info("knowledgeBaseWrapper is null for ruleSet: " + ruleSet);
}
}catch(Exception e) {
log.error(e.getMessage(), e);
}
log.info("End PrintOutAllKnowledgePackages Execution");
}
示例7: execute
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void execute(String ruleSet, String packageName) {
log.info("Starting PrintOutSingleKnowledgePackage Execution");
try {
KnowledgeBaseWrapper knowledgeBaseWrapper = gigaSpace.read(new KnowledgeBaseWrapper(ruleSet));
if(knowledgeBaseWrapper != null) {
KnowledgeBase knowledgeBase = knowledgeBaseWrapper.getKnowledgeBase();
KnowledgePackage knowledgePackage = knowledgeBase.getKnowledgePackage(packageName);
if(knowledgePackage != null) {
log.info("Begin KnowledgePackage: " + knowledgePackage.getName());
Collection<Rule> rules = knowledgePackage.getRules();
if(rules != null) {
for(Rule rule : rules) {
log.info("Rule ID: " + rule.getId());
log.info("Rule Name: " + rule.getName());
}
}else {
log.info("rules are null for ruleSet: " + ruleSet);
}
log.info("End KnowledgePackage: " + knowledgePackage.getName());
}else {
log.info("knowledgePackage is null : " + packageName);
}
}else {
log.info("knowledgeBaseWrapper is null for ruleSet: " + ruleSet);
}
}catch(Exception e) {
log.error(e.getMessage(), e);
}
log.info("End PrintOutSingleKnowledgePackage Execution");
}
示例8: initializeRules
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void initializeRules() {
// To ensure the plugin classloader use for dependency resolution
ClassLoader orig = Thread.currentThread().getContextClassLoader();
ClassLoader loader = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader( loader );
Resource ruleSet = null;
if ( ruleString != null ) {
ruleSet = ResourceFactory.newReaderResource( new StringReader( ruleString ) );
} else {
ruleSet = ResourceFactory.newFileResource( ruleFilePath );
}
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ruleSet, ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
System.out.println( kbuilder.getErrors().toString() );
throw new RuntimeException( BaseMessages.getString( PKG, "RulesData.Error.CompileDRL" ) );
}
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
// Cache the knowledge base as its creation is intensive
kbase.addKnowledgePackages( pkgs );
// reset classloader back to original
Thread.currentThread().setContextClassLoader( orig );
}
示例9: init
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
@PostConstruct
public void init() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource("waltz.drl", WaltzKb.class), ResourceType.DRL );
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
logger.error("DRL Error "+error);
}
}
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( pkgs );
}
示例10: addRuleSet
import org.drools.definition.KnowledgePackage; //导入依赖的package包/类
public void addRuleSet(RuleSet ruleSet) throws RuleConfigurationException {
for (Rule rule : ruleSet.getRules()) {
InputStream ruleInputStream = RuleSetLoader.getRuleSetAsStream(rule, classLoader);
if (rule.getResourceType().equals(Constants.RULE_RESOURCE_TYPE_REGULAR)) {
//check the file type before adding it to knowledge builder for "file" source type
if (rule.getSourceType().equalsIgnoreCase(Constants.RULE_SOURCE_TYPE_FILE) && (rule.getValue().lastIndexOf(".drl") < 0) ) {
throw new RuleConfigurationException(
"Error in rule service configuration : Select \"dtable\" as Resource Type for decision tables "
+ "or attached file is not supported by rule engine");
} else {
this.knowledgeBuilder.add(ResourceFactory.newInputStreamResource(ruleInputStream), ResourceType.DRL);
}
} else if (rule.getResourceType().equals(Constants.RULE_RESOURCE_TYPE_DTABLE)) {
//check the file type before adding it to knowledge builder for "file" source type
if (rule.getSourceType().equalsIgnoreCase(Constants.RULE_SOURCE_TYPE_FILE) &&
rule.getValue().lastIndexOf(".xls") < 0 &&
rule.getValue().lastIndexOf(".csv") < 0) {
throw new RuleConfigurationException(
"Error in rule service configuration : Select \"regular\" as Resource Type for regular rules "
+ "or attached file is not supported by rule engine");
} else {
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
//check whether the decision tables is base on .xsl file of .csv format (inline input or .csv file input)
if (rule.getSourceType().equalsIgnoreCase(Constants.RULE_SOURCE_TYPE_INLINE) ||
rule.getValue().lastIndexOf(".csv") > 0) {
//decision table in .xls format
dtconf.setInputType(DecisionTableInputType.CSV);
} else {
//decision table in .xls format
dtconf.setInputType(DecisionTableInputType.XLS);
}
this.knowledgeBuilder.add(ResourceFactory.newInputStreamResource(ruleInputStream),
ResourceType.DTABLE, dtconf);
}
}
if (this.knowledgeBuilder.hasErrors()) {
throw new RuleConfigurationException("Error during creating rule set: " +
this.knowledgeBuilder.getErrors());
}
Collection<KnowledgePackage> pkgs = this.knowledgeBuilder.getKnowledgePackages();
this.knowledgeBase.addKnowledgePackages(pkgs);
}
}