Search in sources :

Example 1 with ValueReferenceIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.

the class ResourceReference method toIndexElements.

@Override
public List<KProperty<?>> toIndexElements() {
    final List<KProperty<?>> indexElements = new ArrayList<>();
    // Impact Analysis references
    if (resourceFQN != null) {
        ValueReferenceIndexTerm refTerm = new ValueReferenceIndexTerm(this.resourceFQN, this.resourceType);
        indexElements.add(new KPropertyImpl<>(refTerm.getTerm(), refTerm.getValue()));
    }
    if (this.fieldNamepartReferenceMap != null) {
        fieldNamepartReferenceMap.values().forEach((refPartTerm) -> indexElements.add(new KPropertyImpl<>(refPartTerm.getTerm(), refPartTerm.getValue())));
    }
    return indexElements;
}
Also used : KProperty(org.uberfire.ext.metadata.model.KProperty) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ArrayList(java.util.ArrayList)

Example 2 with ValueReferenceIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.

the class FindResourcesQueryInvalidIndexTermsTest method testFindResourcesQueryInvalidIndexTerms.

@Test
public void testFindResourcesQueryInvalidIndexTerms() throws IOException, InterruptedException {
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>(), 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            String msg = "Expected '" + ValueResourceIndexTerm.class.getSimpleName() + "' term was not found";
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().startsWith(msg));
        // and Swallow. Expected
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains("Index term 'ref:rule' can not be used with "));
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA));
                add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains(" can not be used with the " + FindResourcesQuery.NAME));
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 3 with ValueReferenceIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.

the class IndexDrlInvalidDrlTest method testIndexDrlInvalidRuleName.

@Test
@SuppressWarnings("unchecked")
public void testIndexDrlInvalidRuleName() throws IOException, InterruptedException, ExecutionException {
    // 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
    final Path path1 = basePath.resolve("bz1269366.drl");
    final String drl1 = loadText("bz1269366.drl");
    ioService().write(path1, drl1);
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 0);
        verify(mockAppender).doAppend(argThat(argument -> argument.getMessage().startsWith("Unable to parse DRL")));
    }
}
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) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 4 with ValueReferenceIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.

the class IndexDrlLHSTypeExpressionField2Test method testIndexDrlLHSTypeExpressionField2.

@Test
public void testIndexDrlLHSTypeExpressionField2() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("drl4.drl");
    final String drl1 = loadText("drl4.drl");
    ioService().write(path1, drl1);
    // 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).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", "applicant", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) 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)

Example 5 with ValueReferenceIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm in project kie-wb-common by kiegroup.

the class IndexDrlLHSTypeExpressionField4Test method testIndexDrlLHSTypeExpressionField4.

@Test
public void testIndexDrlLHSTypeExpressionField4() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("drl6.drl");
    final String drl1 = loadText("drl6.drl");
    ioService().write(path1, drl1);
    // 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).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Bank", "mortgage", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Mortgage", "applicant", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
    {
        final Query query = new SingleTermQueryBuilder(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD)).build();
        searchFor(index, query, 1, path1);
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) 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

ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)39 Test (org.junit.Test)35 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)35 Path (org.uberfire.java.nio.file.Path)32 Query (org.apache.lucene.search.Query)31 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)31 Import (org.kie.soup.project.datamodel.imports.Import)9 ValuePartReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm)7 Logger (ch.qos.logback.classic.Logger)5 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)5 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)5 HashSet (java.util.HashSet)4 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)4 ArrayList (java.util.ArrayList)2 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TopScoreDocCollector (org.apache.lucene.search.TopScoreDocCollector)1 ScoreCardModel (org.drools.workbench.models.guided.scorecard.shared.ScoreCardModel)1 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)1