SurvivorshipManager extends KnowledgeManager { public void initKnowledgeBase() { int pos = rulePath.lastIndexOf('/'); boolean isClassPathResource = false; ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); URL survivorshipUrl = contextClassLoader.getResource("metadata/survivorship"); if (survivorshipUrl != null) { rulePath = ""; isClassPathResource = true; } else { System.err.println("The survivorship rules aren't in Classpath!"); String projectName = rulePath.substring(pos + 1); rulePath = rulePath.substring(0, pos + 1).concat(projectName.toUpperCase()); } String packagePath; if ("Real_spark_relative_path".equals(rulePath)) { rulePath = ""; packagePath = ""; } else if (isClassPathResource) { packagePath = "metadata/survivorship/" + packageName + "/"; } else { packagePath = rulePath + "/metadata/survivorship/" + packageName + "/"; } KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(newResource(packagePath + SurvivorshipConstants.DROOLS + SurvivorshipConstants.VERSION_SUFFIX + SurvivorshipConstants.PKG_ITEM_EXTENSION, isClassPathResource), ResourceType.DRL); for (RuleDefinition definition : ruleDefinitionList) { if (definition.getOrder().equals(Order.SEQ)) { kbuilder.add( newResource(packagePath + definition.getRuleName() + SurvivorshipConstants.VERSION_SUFFIX + SurvivorshipConstants.RULE_ITEM_EXTENSION, isClassPathResource), ResourceType.DRL); } } kbuilder.add(newResource(packagePath + SurvivorshipConstants.SURVIVOR_FLOW + SurvivorshipConstants.VERSION_SUFFIX + SurvivorshipConstants.FLOW_ITEM_EXTENSION, isClassPathResource), ResourceType.BPMN2); KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (errors.size() > 0) { for (KnowledgeBuilderError error : errors) { System.err.println(error.getMessage()); } throw new IllegalArgumentException("Could not parse knowledge."); } kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); dataset = new DataSet(columnList); } SurvivorshipManager(String rulePath, String packageName); KnowledgeBase getKnowledgeBase(); DataSet getDataSet(); void initKnowledgeBase(); void initKnowledgeBase(Map<org.kie.api.io.ResourceType, List<InputStream>> streamsMap); static Resource newResource(String packagePath, boolean isClassPathResource); static Resource newResource(InputStream stream); Column getColumnByName(String columnName); boolean runSessionWithJava(Object[][] data); boolean runSession(Object[][] data); Map<String, List<String>> checkConflictRuleValid(); Map<String, Object> getSurvivorMap(); List<HashSet<String>> getConflictList(); HashSet<String> getConflictsOfSurvivor();  }
@Test public void testInitKnowledgeBase() { manager.initKnowledgeBase(); KnowledgeBase base = manager.getKnowledgeBase(); assertNotNull("Model is null", base.getFactType(SampleData.PKG_NAME, "RecordIn")); assertNotNull(base.getRule(SampleData.PKG_NAME, SampleData.RULES[0].getRuleName())); assertNotNull(base.getProcess(SampleData.PKG_NAME + ".SurvivorFlow")); }