use of org.drools.core.io.impl.ClassPathResource in project opennms by OpenNMS.
the class CorrelationExample method main.
/**
* <p>main</p>
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
public static void main(final String[] args) throws Exception {
final KieSession session = new KieHelper().addResource(new ClassPathResource("CorrelationExample.drl")).build().newKieSession();
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(session, "log/correlation");
try (InputStream in = CorrelationExample.class.getResourceAsStream("simulation")) {
final Simulation simulation = new Simulation();
System.out.println("Loading Simulation");
simulation.load(in);
System.out.println("Executing Simulation");
simulation.simulate(session);
}
logger.close();
}
use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class KnowledgeBuilderImpl method parseChangeSet.
private ChangeSet parseChangeSet(Resource resource) throws IOException, SAXException {
XmlChangeSetReader reader = new XmlChangeSetReader(this.configuration.getSemanticModules());
if (resource instanceof ClassPathResource) {
reader.setClassLoader(((ClassPathResource) resource).getClassLoader(), ((ClassPathResource) resource).getClazz());
} else {
reader.setClassLoader(this.configuration.getClassLoader(), null);
}
Reader resourceReader = null;
try {
resourceReader = resource.getReader();
return reader.read(resourceReader);
} finally {
if (resourceReader != null) {
resourceReader.close();
}
}
}
use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class TraitTest method testTraitActualTypeCodeWithEntities.
void testTraitActualTypeCodeWithEntities(String trig, VirtualPropertyMode mode) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("org/drools/compiler/factmodel/traits/testComplexDonShed.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
TraitFactory.setMode(mode, kbase);
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
ksession.insert(trig);
ksession.fireAllRules();
TraitableBean ent = (TraitableBean) ksession.getGlobal("core");
assertEquals(CodedHierarchyImpl.stringToBitSet("1"), ent.getCurrentTypeCode());
ksession.insert("b");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("11"), ent.getCurrentTypeCode());
ksession.insert("c");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("1011"), ent.getCurrentTypeCode());
ksession.insert("e");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("11011"), ent.getCurrentTypeCode());
ksession.insert("-c");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("11"), ent.getCurrentTypeCode());
ksession.insert("dg");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("111111"), ent.getCurrentTypeCode());
ksession.insert("-f");
ksession.fireAllRules();
assertEquals(CodedHierarchyImpl.stringToBitSet("111"), ent.getCurrentTypeCode());
}
use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class AgendaRuleFlowGroupsTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession(long id, String... rules) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (String rule : rules) {
kbuilder.add(new ClassPathResource(rule), ResourceType.DRL);
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
if (id == -1) {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
} else {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
}
}
use of org.drools.core.io.impl.ClassPathResource in project drools by kiegroup.
the class RuleFlowGroupRollbackTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("ruleflowgroup_rollback.drl"), ResourceType.DRL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
}
Aggregations