Java Code Examples for org.kie.api.KieBase#getKiePackages()
The following examples show how to use
org.kie.api.KieBase#getKiePackages() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializationSecurityPolicyTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testSerialization() throws IOException, ClassNotFoundException { final String rule = " rule R " + " when " + " then " + " System.out.println(\"consequence!\"); " + " end"; final KieServices kieServices = KieServices.get(); final Resource drlResource = kieServices.getResources().newByteArrayResource( rule.getBytes(StandardCharsets.UTF_8.name()), StandardCharsets.UTF_8.name()); drlResource.setResourceType(ResourceType.DRL); drlResource.setTargetPath("test.drl"); final KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); kieFileSystem.write(drlResource); final KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem); kieBuilder.buildAll(); final KieBase kieBase = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId()).getKieBase(); final Collection<KiePackage> kpkgs = kieBase.getKiePackages(); final Collection<KiePackage> newCollection = new ArrayList<>(); for (KiePackage kpkg : kpkgs) { kpkg = SerializationHelper.serializeObject(kpkg); newCollection.add(kpkg); } ((InternalKnowledgeBase) kieBase).addPackages(newCollection); final KieSession kieSession = kieBase.newKieSession(); assertThat(kieSession.fireAllRules()).isEqualTo(1); }
Example 2
Source File: BaseTest.java From iot-ocp with Apache License 2.0 | 6 votes |
@Before public void setup() { KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); Results verifyResults = kContainer.verify(); for (Message m : verifyResults.getMessages()) { LOG.debug("Kie container message: {}", m); } KieBase kieBase = kContainer.getKieBase(); LOG.debug("Created kieBase"); for ( KiePackage kp : kieBase.getKiePackages() ) { for (Rule rule : kp.getRules()) { LOG.debug("kp " + kp + " rule " + rule.getName()); } } session = kieBase.newKieSession(); LOG.info(session.getGlobals().toString()); Logger kieLogger = LoggerFactory.getLogger(this.getClass()); // session.setGlobal("logger",kieLogger); }
Example 3
Source File: RulesConfiguration.java From cia with Apache License 2.0 | 6 votes |
/** * Kie container. * * @return the kie container */ @Bean public KieContainer kieContainer() { final KieServices kieServices = KieServices.Factory.get(); final KieContainer kContainer = kieServices.getKieClasspathContainer(); LOGGER.info("Using classloader {}, parent {}",kContainer.getClassLoader(),kContainer.getClassLoader().getParent()); final Results verifyResults = kContainer.verify(); for (final Message m : verifyResults.getMessages()) { LOGGER.warn("Kie container message: {}", m); } final KieBase kieBase = kContainer.getKieBase(); for (final KiePackage kp : kieBase.getKiePackages()) { for (final Rule rule : kp.getRules()) { LOGGER.info("Loadded Rule: {} {}", kp, rule.getName()); } } return kContainer; }
Example 4
Source File: DroolsUtil.java From qzr with Apache License 2.0 | 6 votes |
/** * Return a string containing the packages used to build the knowledge base. */ public static String knowledgeBaseDetails(KieBase kbase) { if (kbase == null) { return "Knowledge Base is null."; } else { StringBuilder sb = new StringBuilder( "Knowledge base built from the following packages:"); Collection<KiePackage> packages = kbase .getKiePackages(); for (KiePackage kp : packages) { sb.append("\n Package: [" + kp.getName() + "]"); for (Rule rule : kp.getRules()) { sb.append("\n Rule: [" + rule.getName() + "]"); } } return sb.toString(); } }
Example 5
Source File: KieBaseIncludesTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
/** * Helper method which determines the number of rules in the {@link KieBase}. * * @param kieBase * the {@link KieBase} * @return the number of rules in the {@link KieBase} */ private static long getNumberOfRules(KieBase kieBase) { long nrOfRules = 0; Collection<KiePackage> kiePackages = kieBase.getKiePackages(); for (KiePackage nextKiePackage : kiePackages) { Collection<Rule> rules = nextKiePackage.getRules(); System.out.println(rules); nrOfRules += rules.size(); } return nrOfRules; }
Example 6
Source File: DroolsUtil.java From qzr with Apache License 2.0 | 5 votes |
/** * * @return A String detailing the packages and rules in this knowledge base. */ public static String kbaseDetails(KieBase kbase) { StringBuilder sb = new StringBuilder(); for (KiePackage p : kbase.getKiePackages()) { sb.append("\n Package : " + p.getName()); for (Rule r : p.getRules()) { sb.append("\n Rule: " + r.getName()); } } return "Knowledge base built with packages: " + sb.toString(); }