Search in sources :

Example 6 with DSLMappingFile

use of org.drools.compiler.lang.dsl.DSLMappingFile in project drools-wb by kiegroup.

the class GuidedRuleDslrFileIndexer method getDSLExpander.

/**
 * Returns an expander for DSLs (only if there is a DSL configured for this package).
 * @param path The {@link Path} of the resource to index
 * @return a {@link Expander} used to produce a DRL of the file
 */
public Expander getDSLExpander(final Path path) {
    final Expander expander = new DefaultExpander();
    final List<DSLMappingFile> dsls = getDSLMappingFiles(path);
    for (DSLMappingFile dsl : dsls) {
        expander.addDSLMapping(dsl.getMapping());
    }
    return expander;
}
Also used : DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) Expander(org.drools.compiler.lang.Expander) DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile)

Example 7 with DSLMappingFile

use of org.drools.compiler.lang.dsl.DSLMappingFile in project drools-wb by kiegroup.

the class GuidedRuleTemplateSourceService method getDSLMappingFiles.

private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
    final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
    final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
    final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
    final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(packagePath);
    final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
    for (final org.uberfire.java.nio.file.Path dslPath : dslPaths) {
        final String dslDefinition = ioService.readAllString(dslPath);
        final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
        try {
            if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
                dsls.add(dslFile);
            } else {
                logger.error("Unable to parse DSL definition: " + dslDefinition);
            }
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
        }
    }
    return dsls;
}
Also used : Path(org.uberfire.java.nio.file.Path) Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile) StringReader(java.io.StringReader) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 8 with DSLMappingFile

use of org.drools.compiler.lang.dsl.DSLMappingFile in project drools-wb by kiegroup.

the class GuidedDecisionTableSourceService method getDSLExpander.

/**
 * Returns an expander for DSLs (only if there is a DSL configured for this package).
 */
private Expander getDSLExpander(final Path path) {
    final Expander expander = new DefaultExpander();
    final List<DSLMappingFile> dsls = getDSLMappingFiles(path);
    for (DSLMappingFile dsl : dsls) {
        expander.addDSLMapping(dsl.getMapping());
    }
    return expander;
}
Also used : DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) Expander(org.drools.compiler.lang.Expander) DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile)

Example 9 with DSLMappingFile

use of org.drools.compiler.lang.dsl.DSLMappingFile in project drools-wb by kiegroup.

the class GuidedRuleDslrFileIndexer method getDSLMappingFiles.

private List<DSLMappingFile> getDSLMappingFiles(final Path path) {
    final List<DSLMappingFile> dsls = new ArrayList<DSLMappingFile>();
    final org.uberfire.backend.vfs.Path vfsPath = Paths.convert(path);
    final org.uberfire.backend.vfs.Path packagePath = moduleService.resolvePackage(vfsPath).getPackageMainResourcesPath();
    final Path nioPackagePath = Paths.convert(packagePath);
    final Collection<Path> dslPaths = fileDiscoveryService.discoverFiles(nioPackagePath, FILTER_DSLS);
    for (final Path dslPath : dslPaths) {
        final String dslDefinition = ioService.readAllString(dslPath);
        final DSLTokenizedMappingFile dslFile = new DSLTokenizedMappingFile();
        try {
            if (dslFile.parseAndLoad(new StringReader(dslDefinition))) {
                dsls.add(dslFile);
            } else {
                logger.error("Unable to parse DSL definition: " + dslDefinition);
            }
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
        }
    }
    return dsls;
}
Also used : Path(org.uberfire.java.nio.file.Path) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) IOException(java.io.IOException) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile) DSLTokenizedMappingFile(org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)

Example 10 with DSLMappingFile

use of org.drools.compiler.lang.dsl.DSLMappingFile in project drools-wb by kiegroup.

the class GuidedRuleTemplateSourceService method getDSLExpander.

/**
 * Returns an expander for DSLs (only if there is a DSL configured for this package).
 */
private Expander getDSLExpander(final Path path) {
    final Expander expander = new DefaultExpander();
    final List<DSLMappingFile> dsls = getDSLMappingFiles(path);
    for (DSLMappingFile dsl : dsls) {
        expander.addDSLMapping(dsl.getMapping());
    }
    return expander;
}
Also used : DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) Expander(org.drools.compiler.lang.Expander) DefaultExpander(org.drools.compiler.lang.dsl.DefaultExpander) DSLMappingFile(org.drools.compiler.lang.dsl.DSLMappingFile)

Aggregations

DSLMappingFile (org.drools.compiler.lang.dsl.DSLMappingFile)12 StringReader (java.io.StringReader)7 Expander (org.drools.compiler.lang.Expander)7 DSLTokenizedMappingFile (org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)7 DefaultExpander (org.drools.compiler.lang.dsl.DefaultExpander)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Path (org.uberfire.java.nio.file.Path)5 Test (org.junit.Test)2 DefaultExpanderResolver (org.drools.compiler.lang.dsl.DefaultExpanderResolver)1 DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)1 DSLVariableValue (org.drools.workbench.models.datamodel.rule.DSLVariableValue)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1