当前位置: 首页>>代码示例>>Java>>正文


Java StatefulKnowledgeSession.getGlobal方法代码示例

本文整理汇总了Java中org.drools.runtime.StatefulKnowledgeSession.getGlobal方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession.getGlobal方法的具体用法?Java StatefulKnowledgeSession.getGlobal怎么用?Java StatefulKnowledgeSession.getGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.drools.runtime.StatefulKnowledgeSession的用法示例。


在下文中一共展示了StatefulKnowledgeSession.getGlobal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addGlobals

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Method to add globals.
 * 
 * @param ksession Drools Knowledge session.
 */
private void addGlobals(StatefulKnowledgeSession ksession) {
    ksession.setGlobal("cList", new ArrayList<Integer>());
    ksession.setGlobal("dList", new ArrayList<String>());
    ksession.setGlobal("vList", new ArrayList<String>());
    ksession.setGlobal("fList", new ArrayList<String>());
    ArrayList<String> definedList = (ArrayList<String>) droolsVisitor.getdList();
    java.util.Set<String> tempSet = new HashSet<String>();
    tempSet.addAll(definedList);
    definedList.removeAll(definedList);
    definedList.addAll(tempSet);
    @SuppressWarnings("unchecked")
    List<String> defL = (ArrayList<String>) ksession.getGlobal("dList");
    for (int i = 0; i < definedList.size(); i++) {
        defL.add(definedList.get(i));
    }
    Map<String, Integer> enumMap = new HashMap<String, Integer>();
    enumMap = droolsVisitor.getEnumMap();
    Iterator<String> itr = enumMap.keySet().iterator();
    while (itr.hasNext()) {
        String k = itr.next();
        ksession.setGlobal(k, enumMap.get(k));
    }
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:29,代码来源:DroolsEvaluation.java

示例2: addDroolsGlobals

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Method to add drools globals.
 * @param ksession Drools KNowledge session.
 * @return Returns the packagename of the .drl (drools rule) file.
 */
private String addDroolsGlobals(StatefulKnowledgeSession ksession) {
    this.pckg = DroolsEngine.class.getPackage().getName();
    /**
     * cList contains the rule ids of the rules that are not satisfied.
     */
    ksession.setGlobal("cList", new ArrayList<Integer>());
    ksession.setGlobal("aList", new ArrayList<String>());
    ksession.setGlobal("dList", new ArrayList<Object>());
    ksession.setGlobal("vList", new ArrayList<String>());
    /*
     * flist is the list containing names of the variables with fixed status. 
     */
    ksession.setGlobal("fList", new ArrayList<String>());
    ArrayList<String> definedList = (ArrayList<String>) droolsVisitor.getdList();
    java.util.Set<String> tempSet = new HashSet<String>();
    tempSet.addAll(definedList);
    definedList.removeAll(definedList);
    definedList.addAll(tempSet);
    @SuppressWarnings("unchecked")
    List<String> defL = (ArrayList<String>) ksession.getGlobal("dList");
    for (int i = 0; i < definedList.size(); i++) {
        defL.add(definedList.get(i));
    }
    
    addEnums(ksession);
    return this.pckg;
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:33,代码来源:DroolsEngine.java

示例3: fireRules

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Private method to fire the rules.
 * @param ksession Knowledge Session. 
 */
@SuppressWarnings("unchecked")
private void fireRules(StatefulKnowledgeSession ksession) {
    ksession.getAgenda().getAgendaGroup("Group Config").setFocus();
    ksession.fireAllRules();
    LinkedHashMap<String, Integer> importedProjectMap = droolsVisitor.getImportedProjectMap();
    Iterator<String> itr = importedProjectMap.keySet().iterator();
    
    while (itr.hasNext()) {
        String projectN = itr.next();
        ksession.getAgenda().getAgendaGroup("Group 0" + projectN).setFocus();
        ksession.fireAllRules();
    }
    
    ksession.getAgenda().getAgendaGroup("Group 0").setFocus();
    ksession.fireAllRules();
    evaluateInnerProjectScopes(ksession);
    
    
    List<String> agendaGroups = DroolsVisitor.getAgendaGroups1();
    LinkedList<String> agendaGroups2 = DroolsVisitor.getAgendaGroups2();
    
    
    Collections.sort(agendaGroups);
    Collections.sort(agendaGroups2); 
    
    runDirectModification(ksession, agendaGroups);
    
    runImplication(ksession, agendaGroups2);
    
    
    ksession.getAgenda().getAgendaGroup("Group 2").setFocus();
    ksession.fireAllRules();
    List<String> dList = (ArrayList<String>) ksession.getGlobal("dList");
    removeDuplicates(dList);
    logger.info(" dList is **** " + " **** " + dList);
    fixedVariables = (ArrayList<String>) ksession.getGlobal("fList");
    logger.info(" fList is **** " + " **** " + fixedVariables);
    
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:44,代码来源:DroolsEngine.java

示例4: assertAndExecuteClinicalFacts

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Override
public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
        FactModel factModel) {
    RuleExecutionContainer executionResponseContainer = null;
    final AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse();
    String executionResponseContainerXMLString = null;
    final Set<String> firedRuleNames = new HashSet<>();

    final StatefulKnowledgeSession session = createStatefulKnowledgeSession();
    try {
        session.insert(factModel.getXacmlResult());
        for (final ClinicalFact clinicalFact : factModel
                .getClinicalFactList()) {
            session.insert(clinicalFact);
        }

        session.addEventListener(new DefaultAgendaEventListener() {
            @Override
            public void afterActivationFired(AfterActivationFiredEvent event) {
                super.afterActivationFired(event);
                final Rule rule = event.getActivation().getRule();
                firedRuleNames.add(rule.getName());
            }
        });

        session.fireAllRules();

        logger.debug(() -> "Fired rules: " + firedRuleNames.toString());

        executionResponseContainer = (RuleExecutionContainer) session
                .getGlobal("ruleExecutionContainer");

        // Marshal rule execution response
        executionResponseContainerXMLString = marshaller
                .marshal(executionResponseContainer);
        if (firedRuleNames.size() > 0) {
            assertAndExecuteResponse.setRulesFired(firedRuleNames
                    .toString());
        }
    } catch (final Throwable e) {
        logger.error(e.getMessage(), e);
    } finally {
        firedRuleNames.clear();
        if (session != null) {
            session.dispose();
        }
    }
    assertAndExecuteResponse
            .setRuleExecutionResponseContainer(executionResponseContainerXMLString);
    return assertAndExecuteResponse;
}
 
开发者ID:bhits,项目名称:dss-api,代码行数:52,代码来源:RuleExecutionServiceImpl.java

示例5: addMessages

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
     * A private method to add messages to the reasoning result.
     * @param project Project.
     * @param result Reasoning result.
     * @param ksession Drools Knowledge Session.
     */
    @SuppressWarnings("unchecked")
    private void addMessages(Project project, ReasoningResult result, StatefulKnowledgeSession ksession) {
        cList = (ArrayList<Integer>) ksession.getGlobal("cList");
        removeDuplicates(cList);
        logger.info("Total failing constraints " + cList.size());
        List<ModelElement> conflictingConstraints = new ArrayList<ModelElement>();
        aList = (ArrayList<String>) ksession.getGlobal("aList");
        java.util.Set<String> tempSet = new HashSet<String>();
        tempSet.addAll(aList);
        aList.removeAll(aList);
        aList.addAll(tempSet);
        if (droolsVisitor.getMessages().size() != 0) {
            List<ModelElement> cMEList = droolsVisitor.getMessages();
            Message mesAttrAssgn = new Message("Constraints are not supported in the attribute "
                    + "assignment blocks", cMEList, Status.UNSUPPORTED);
            result.addMessage(mesAttrAssgn);
        }
        
        for (int i = 0; i < cList.size(); i++) {
            conflictingConstraints.add(this.ruleMapper.get(cList.get(i)));
        }

        for (int i = 0; i < aList.size(); i++) {
            conflictingConstraints.add(droolsVisitor.getAttributeMap().get(aList.get(i)));
        }
        
        List<ModelElement> notSupportedConstraints = new ArrayList<ModelElement>();
        for (int i = 0; i < droolsVisitor.getListofUnsupportedRules().size(); i++) {
            int index = droolsVisitor.getListofUnsupportedRules().get(i);
//            notSupportedConstraints.add(project.getElement(index));
            if (index < 0) {
                index = 0 - index;
            }
            notSupportedConstraints.add(ruleMapper.get(index));
        }
        
        Message mes = new Message("Constraints not satisfied", conflictingConstraints, Status.ERROR);
        if (conflictingConstraints.size() != 0) {
            messageList.add(mes);
        }
        
        Message mes2 = new Message("Constraints not supported", notSupportedConstraints, Status.UNSUPPORTED);
        if (notSupportedConstraints.size() != 0) {
            messageList.add(mes2);
        }
        logger.info("Nr. of constraints not supported " + notSupportedConstraints.size());
        
        
        for (int i = 0; i < messageList.size(); i++) {
            logger.info("message " + messageList.get(i).getDescription());
            result.addMessage(messageList.get(i));
        }
    }
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:60,代码来源:DroolsEngine.java

示例6: valuePropagate

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Private method for value propagation.
 * @param ksession Knowledge Session.
 * @param projIns The project instance.
 * @throws ConfigurationException 
 * @throws ValueDoesNotMatchTypeException 
 */
private void valuePropagate(StatefulKnowledgeSession ksession, Object projIns) throws 
    ConfigurationException, ValueDoesNotMatchTypeException  {
    
    logger.info("fact count " + ksession.getFactCount() + " " 
            + ksession.getFactHandle(projIns));
    @SuppressWarnings("unchecked")
    List<String> dList = (ArrayList<String>) ksession.getGlobal("dList");
    logger.info(" dList is **** " + " **** " + dList);
    @SuppressWarnings("unchecked")
    List<String> vList = (ArrayList<String>) ksession.getGlobal("vList");
    logger.info("vList is " + vList);
    this.dList = dList;
    this.vList = vList;
    logger.info("\n\t\t************************************************* BELOW VALUES ARE CHANGED");
    for (int in = 0; in < droolsProjects.size(); in++) {
        String project = droolsProjects.get(in);
        List<FactField> fFields = ksession.getKnowledgeBase().getFactType(pckg, project).getFields();
        setVarMap(varMap);
        for (int i = 0; i < fFields.size(); i++) {
            String typeName = fFields.get(i).getType().getSimpleName();
            Object val = fFields.get(i).get(droolsProjectIns.get(in));
            if (null != val) {
                
                if (typeName.equals(String.class.getSimpleName())) {
                    updateNonNested(fFields.get(i), val.toString());
                } else if (typeName.equals(Boolean.class.getSimpleName())) {
                    updateNonNested(fFields.get(i), val.toString());
                } else if (typeName.equals(int.class.getSimpleName())) {
                    updateNonNested(fFields.get(i), val.toString());
                } else if (typeName.equals(double.class.getSimpleName())) {
                    updateNonNested(fFields.get(i), val.toString());
                } else {
                    if (!typeName.equals("Set") && !typeName.equals("List")) {
                        List<FactField> cFields = ksession.getKnowledgeBase().getFactType(pckg, typeName)
                                .getFields();
                        updateNested(fFields.get(i), cFields, droolsProjectIns.get(in));
                    } else {
                        processCollection(val, fFields.get(i), droolsProjectIns.get(in));
                    }
                }
            }
        }
    }
    
}
 
开发者ID:SSEHUB,项目名称:EASyProducer,代码行数:53,代码来源:DroolsEngine.java

示例7: assertAndExecuteClinicalFacts

import org.drools.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Override
public AssertAndExecuteClinicalFactsResponse assertAndExecuteClinicalFacts(
		String factModelXmlString) {
	RuleExecutionContainer executionResponseContainer = null;
	FactModel factModel = new FactModel();
	AssertAndExecuteClinicalFactsResponse assertAndExecuteResponse = new AssertAndExecuteClinicalFactsResponse();

	String executionResponseContainerXMLString = null;

	LOGGER.debug("factModelXmlString: " + factModelXmlString);
	StatefulKnowledgeSession session = createStatefulKnowledgeSession();
	try {
		// unmarshall factmodel
		factModel = marshaller.unmarshallFromXml(FactModel.class,
				factModelXmlString);

		session.insert(factModel.getXacmlResult());
		for (ClinicalFact clinicalFact : factModel.getClinicalFactList()) {
			session.insert(clinicalFact);
		}

		session.addEventListener(new DefaultAgendaEventListener() {
			@Override
			public void afterActivationFired(AfterActivationFiredEvent event) {
				super.afterActivationFired(event);
				final Rule rule = event.getActivation().getRule();
				addRuleName(rule.getName());

			}
		});

		session.fireAllRules();

		LOGGER.debug("Fired rules: {}...", firedRuleNames);
		LOGGER.debug("Fired rules: " + firedRuleNames);

		executionResponseContainer = (RuleExecutionContainer) session
				.getGlobal("ruleExecutionContainer");

		// Marshal rule execution response
		executionResponseContainerXMLString = marshaller
				.marshall(executionResponseContainer);

	} catch (Throwable e) {
		LOGGER.error(e.getMessage(), e);
	} finally {
		firedRuleNames = "";
		if (session != null) {
			session.dispose();
		}
	}

	assertAndExecuteResponse
			.setRuleExecutionResponseContainer(executionResponseContainerXMLString);

	return assertAndExecuteResponse;
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:58,代码来源:RuleExecutionServiceImpl.java


注:本文中的org.drools.runtime.StatefulKnowledgeSession.getGlobal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。