Search in sources :

Example 31 with SingleTermQueryBuilder

use of org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder in project drools-wb by kiegroup.

the class IndexGuidedRuleTemplateAttributesTest method testIndexGuidedRuleTemplateAttributes.

@Test
public void testIndexGuidedRuleTemplateAttributes() throws IOException, InterruptedException {
    // Add test files
    final Path path = basePath.resolve("template1.template");
    final TemplateModel model = GuidedRuleTemplateFactory.makeModelWithAttributes("org.drools.workbench.screens.guided.template.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage"));
        }
    }, "template1");
    final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
    ioService().write(path, xml);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP, TermSearchType.WILDCARD)).build();
        searchFor(index, query, 1, path);
    }
    // Rule Template defining a RuleFlow-Group named myRuleFlowGroup. This should match template1.template
    // This checks whether there is a Rule Attribute "ruleflow-group" and its Value is "myRuleflowGroup"
    {
        final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP)).build();
        searchFor(index, query, 1, path);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 32 with SingleTermQueryBuilder

use of org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder in project drools-wb by kiegroup.

the class IndexGuidedScoreCardTest method testIndexGuidedScoreCard.

@Test
public void testIndexGuidedScoreCard() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("scorecard1.scgd");
    final ScoreCardModel model1 = GuidedScoreCardFactory.makeScoreCardWithCharacteristics("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage"));
        }
    }, "scorecard1");
    final String xml1 = GuidedScoreCardXMLPersistence.getInstance().marshal(model1);
    ioService().write(path1, xml1);
    final Path path2 = basePath.resolve("scorecard2.scgd");
    final ScoreCardModel model2 = GuidedScoreCardFactory.makeScoreCardWithoutCharacteristics("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", new ArrayList<Import>() {

        {
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant"));
            add(new Import("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage"));
        }
    }, "scorecard2");
    final String xml2 = GuidedScoreCardXMLPersistence.getInstance().marshal(model2);
    ioService().write(path2, xml2);
    final Path path3 = basePath.resolve("scorecard3.scgd");
    final ScoreCardModel model3 = GuidedScoreCardFactory.makeEmptyScoreCard("org.drools.workbench.screens.guided.scorecard.backend.server.indexing", "scorecard3");
    final String xml3 = GuidedScoreCardXMLPersistence.getInstance().marshal(model3);
    ioService().write(path3, xml3);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    // Score Cards using org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
    // Score Cards referring to org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1);
    }
    // Score Cards using org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage#amount
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.drools.workbench.screens.guided.scorecard.backend.server.indexing.classes.Mortgage", "amount", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    // Score Cards using java.lang.Integer
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("java.lang.Integer", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) Import(org.kie.soup.project.datamodel.imports.Import) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ScoreCardModel(org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 33 with SingleTermQueryBuilder

use of org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder in project drools-wb by kiegroup.

the class IndexDecisionTableXLSAttributeNameTest method testIndexDecisionTableXLSAttributeName.

@Test
public void testIndexDecisionTableXLSAttributeName() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = loadXLSFile(basePath, "dtable1.xls");
    final Path path2 = loadXLSFile(basePath, "dtable2.xls");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("*", PartType.RULEFLOW_GROUP, TermSearchType.WILDCARD)).build();
        searchFor(index, query, 1, path1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 34 with SingleTermQueryBuilder

use of org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder in project drools-wb by kiegroup.

the class IndexDecisionTableXLSInvalidDrlTest method testIndexDecisionTableXLSInvalidDrl.

@Test
public void testIndexDecisionTableXLSInvalidDrl() throws IOException, InterruptedException {
    // Setup logging
    final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender<ILoggingEvent> mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    // Add test files
    loadXLSFile(basePath, "bz1269366.xls");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP)).build();
        searchFor(index, query, 0);
        verify(mockAppender).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {

            @Override
            public boolean matches(final Object argument) {
                return ((ILoggingEvent) argument).getMessage().startsWith("Unable to parse DRL");
            }
        }));
    }
}
Also used : ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 35 with SingleTermQueryBuilder

use of org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder in project drools-wb by kiegroup.

the class IndexDecisionTableXLSMultipleTypesTest method testIndexDecisionTableXLSMultipleTypes.

@Test
public void testIndexDecisionTableXLSMultipleTypes() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = loadXLSFile(basePath, "dtable1.xls");
    final Path path2 = loadXLSFile(basePath, "dtable2.xls");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.dtablexls.backend.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 2, path1, path2);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.dtablexls.backend.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
        // Mortgage import statement in both .xls files
        searchFor(index, query, 2, path2);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Query(org.apache.lucene.search.Query) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Aggregations

Query (org.apache.lucene.search.Query)38 Test (org.junit.Test)38 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)38 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)38 Path (org.uberfire.java.nio.file.Path)37 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)23 Import (org.kie.soup.project.datamodel.imports.Import)11 ValueSharedPartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm)10 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)7 Logger (ch.qos.logback.classic.Logger)6 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)6 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)6 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)3 ValuePartReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm)3 ScoreCardModel (org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel)1 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)1 GuidedDecisionTableEditorGraphModel (org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel)1