Search in sources :

Example 1 with UnknownRuleUnitException

use of org.drools.modelcompiler.builder.errors.UnknownRuleUnitException in project drools by kiegroup.

the class RuleContext method findUnitDescr.

private void findUnitDescr() {
    if (ruleDescr == null) {
        return;
    }
    boolean useNamingConvention = false;
    String unitName;
    AnnotationDescr unitAnn = ruleDescr.getAnnotation("Unit");
    if (unitAnn != null) {
        unitName = (String) unitAnn.getValue();
        unitName = unitName.substring(0, unitName.length() - ".class".length());
    } else if (ruleDescr.getUnit() != null) {
        unitName = ruleDescr.getUnit().getTarget();
    } else {
        if (ruleDescr.getResource() == null) {
            return;
        }
        String drlFile = ruleDescr.getResource().getSourcePath();
        if (drlFile != null) {
            String drlFileName = drlFile.substring(drlFile.lastIndexOf('/') + 1);
            unitName = packageModel.getName() + '.' + drlFileName.substring(0, drlFileName.length() - ".drl".length());
            useNamingConvention = true;
        } else {
            return;
        }
    }
    RuleUnitDescriptionLoader ruleUnitDescriptionLoader = kbuilder.getPackageRegistry(packageModel.getName()).getPackage().getRuleUnitDescriptionLoader();
    Optional<RuleUnitDescription> ruDescr = ruleUnitDescriptionLoader.getDescription(unitName);
    if (ruDescr.isPresent()) {
        ruleUnitDescr = ruDescr.get();
    } else if (!useNamingConvention) {
        throw new UnknownRuleUnitException(unitName);
    }
}
Also used : RuleUnitDescription(org.kie.internal.ruleunit.RuleUnitDescription) UnknownRuleUnitException(org.drools.modelcompiler.builder.errors.UnknownRuleUnitException) RuleUnitDescriptionLoader(org.drools.core.ruleunit.RuleUnitDescriptionLoader) AnnotationDescr(org.drools.drl.ast.descr.AnnotationDescr)

Aggregations

RuleUnitDescriptionLoader (org.drools.core.ruleunit.RuleUnitDescriptionLoader)1 AnnotationDescr (org.drools.drl.ast.descr.AnnotationDescr)1 UnknownRuleUnitException (org.drools.modelcompiler.builder.errors.UnknownRuleUnitException)1 RuleUnitDescription (org.kie.internal.ruleunit.RuleUnitDescription)1