Search in sources :

Example 1 with DuplicateRule

use of org.drools.compiler.compiler.DuplicateRule in project drools by kiegroup.

the class KnowledgeBuilderImpl method validateUniqueRuleNames.

protected void validateUniqueRuleNames(final PackageDescr packageDescr) {
    final Set<String> names = new HashSet<String>();
    PackageRegistry packageRegistry = this.pkgRegistryMap.get(packageDescr.getNamespace());
    InternalKnowledgePackage pkg = null;
    if (packageRegistry != null) {
        pkg = packageRegistry.getPackage();
    }
    for (final RuleDescr rule : packageDescr.getRules()) {
        validateRule(packageDescr, rule);
        final String name = rule.getName();
        if (names.contains(name)) {
            addBuilderResult(new ParserError(rule.getResource(), "Duplicate rule name: " + name, rule.getLine(), rule.getColumn(), packageDescr.getNamespace()));
        }
        if (pkg != null) {
            RuleImpl duplicatedRule = pkg.getRule(name);
            if (duplicatedRule != null) {
                Resource resource = rule.getResource();
                Resource duplicatedResource = duplicatedRule.getResource();
                if (resource == null || duplicatedResource == null || duplicatedResource.getSourcePath() == null || duplicatedResource.getSourcePath().equals(resource.getSourcePath())) {
                    addBuilderResult(new DuplicateRule(rule, packageDescr, this.configuration));
                } else {
                    addBuilderResult(new ParserError(rule.getResource(), "Duplicate rule name: " + name, rule.getLine(), rule.getColumn(), packageDescr.getNamespace()));
                }
            }
        }
        names.add(name);
    }
}
Also used : PackageRegistry(org.drools.compiler.compiler.PackageRegistry) DuplicateRule(org.drools.compiler.compiler.DuplicateRule) ParserError(org.drools.compiler.compiler.ParserError) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) BaseResource(org.drools.core.io.impl.BaseResource) DescrResource(org.drools.core.io.impl.DescrResource) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Resource(org.kie.api.io.Resource) ReaderResource(org.drools.core.io.impl.ReaderResource) PMMLResource(org.drools.compiler.compiler.PMMLResource) InternalResource(org.drools.core.io.internal.InternalResource) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) HashSet(java.util.HashSet) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Aggregations

HashSet (java.util.HashSet)1 DuplicateRule (org.drools.compiler.compiler.DuplicateRule)1 PMMLResource (org.drools.compiler.compiler.PMMLResource)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 ParserError (org.drools.compiler.compiler.ParserError)1 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 BaseResource (org.drools.core.io.impl.BaseResource)1 ClassPathResource (org.drools.core.io.impl.ClassPathResource)1 DescrResource (org.drools.core.io.impl.DescrResource)1 ReaderResource (org.drools.core.io.impl.ReaderResource)1 InternalResource (org.drools.core.io.internal.InternalResource)1 Resource (org.kie.api.io.Resource)1