Search in sources :

Example 1 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest 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 2 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.

the class FindResourcesQueryValidIndexTermsTest method testQueryValidRuleAttributeIndexTerms.

@Test
public void testQueryValidRuleAttributeIndexTerms() throws IOException, InterruptedException {
    // Add test files
    final Path[] path = { basePath.resolve("drl1.drl"), basePath.resolve("drl2.drl"), basePath.resolve("drl3.drl"), basePath.resolve("functions.drl") };
    final String[] content = { loadText("drl1.drl"), loadText("drl2.drl"), loadText("drl3.drl"), loadText("functions.drl") };
    for (int i = 0; i < path.length; ++i) {
        ioService().write(path[i], content[i]);
    }
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.myRule", ResourceType.RULE));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.myRule*", ResourceType.RULE, TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(3, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
            assertResponseContains(response.getPageRowList(), path[1]);
            assertResponseContains(response.getPageRowList(), path[2]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("org.kie.workbench.mock.package.f4", ResourceType.FUNCTION, TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[3]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) PageResponse(org.uberfire.paging.PageResponse) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 3 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.

the class FindResourcesQueryValidIndexTermsTest method testFindResourcesQueryValidIndexTerms.

@Test
public void testFindResourcesQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    final Path path1 = basePath.resolve("Pojo1.java");
    final String javaFile1 = loadText("../Pojo1.java");
    ioService().write(path1, javaFile1);
    final Path path2 = basePath.resolve("Interface1.java");
    final String javaFile2 = loadText("../Interface1.java");
    ioService().write(path2, javaFile2);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD));
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull("No documents found!", response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path1);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValueResourceIndexTerm("org.kie.workbench.common.screens.datamodeller.backend.server.indexing", ResourceType.JAVA, // Prefix! :)
        TermSearchType.PREFIX));
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull("No documents found!", response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path1);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValueResourceIndexTerm("*Pojo1", ResourceType.JAVA, // Wildcard! :)
        TermSearchType.WILDCARD));
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcesQuery", queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path1);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) PageResponse(org.uberfire.paging.PageResponse) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 4 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.

the class LibraryServiceImpl method getNumberOfAssets.

@Override
public int getNumberOfAssets(final WorkspaceProject module) {
    final HashSet<ValueIndexTerm> queryTerms = new HashSet<>();
    queryTerms.add(new LibraryValueModuleRootPathIndexTerm((module.getRootPath().toURI())));
    return refactoringQueryService.queryHitCount(new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, queryTerms, 0, null, Boolean.TRUE));
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) HashSet(java.util.HashSet)

Example 5 with RefactoringPageRequest

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest in project kie-wb-common by kiegroup.

the class FindAllLibraryAssetsQueryTest method filterFilesFromModule.

@Test
public void filterFilesFromModule() throws IOException, InterruptedException {
    // Add test files
    addTestFile(TEST_MODULE_ROOT, "rule1.rule");
    addTestFile(TEST_MODULE_ROOT, "rule2.rule");
    addTestFile(SOME_OTHER_MODULE_ROOT, "rule3.rule");
    addTestFile(TEST_MODULE_ROOT, "functions.functions");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new LibraryValueModuleRootPathIndexTerm(TEST_MODULE_ROOT, TermSearchType.WILDCARD));
                add(new LibraryValueFileNameIndexTerm("*rule*", TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            for (RefactoringPageRow refactoringPageRow : response.getPageRowList()) {
                System.out.println(refactoringPageRow.getValue());
            }
            assertEquals(2, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) LibraryValueFileNameIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueFileNameIndexTerm) PageResponse(org.uberfire.paging.PageResponse) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)22 Test (org.junit.Test)17 HashSet (java.util.HashSet)16 PageResponse (org.uberfire.paging.PageResponse)12 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)10 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)10 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)8 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 Path (org.uberfire.backend.vfs.Path)5 Path (org.uberfire.java.nio.file.Path)5 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)3 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 Branch (org.guvnor.structure.repositories.Branch)2 ValueModuleRootPathIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 Collection (java.util.Collection)1