Search in sources :

Example 6 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm 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 7 with ValueIndexTerm

use of org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm 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 8 with ValueIndexTerm

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

the class FindAllLibraryAssetsSortedQueryTest method listAllInProjectSortedPaged.

@Test
public void listAllInProjectSortedPaged() throws IOException, InterruptedException {
    setUp(TEST_PROJECT_ROOT2);
    final RefactoringPageRequest request1 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT2, TermSearchType.WILDCARD));
        }
    }, 0, 4);
    final PageResponse<RefactoringPageRow> response1 = service.query(request1);
    assertNotNull(response1);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet1 = new TreeSet<>();
    for (RefactoringPageRow row : response1.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet1.add(fileName);
    }
    String[] expectedResult1 = new String[] { "DRL4.drl", "drl1.drl", "drl2.ext2", "drl3.ext3" };
    assertArrayEquals(expectedResult1, resultSet1.toArray());
    final RefactoringPageRequest request2 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT2, TermSearchType.WILDCARD));
        }
    }, 4, 4);
    final PageResponse<RefactoringPageRow> response2 = service.query(request2);
    assertNotNull(response2);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet2 = new TreeSet<>();
    for (RefactoringPageRow row : response2.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet2.add(fileName);
    }
    String[] expectedResult2 = new String[] { "RULE4.rule", "functions.functions", "rule3.rule" };
    assertArrayEquals(expectedResult2, resultSet2.toArray());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeSet(java.util.TreeSet) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 9 with ValueIndexTerm

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

the class FindAllLibraryAssetsSortedQueryTest method listAllInProjectSorted.

@Test
public void listAllInProjectSorted() throws IOException, InterruptedException {
    setUp(TEST_PROJECT_ROOT1);
    final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT1, TermSearchType.WILDCARD));
        }
    }, 0, 10);
    final PageResponse<RefactoringPageRow> response = service.query(request);
    assertNotNull(response);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet = new TreeSet<>();
    for (RefactoringPageRow row : response.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet.add(fileName);
    }
    assertArrayEquals(FILE_NAMES, resultSet.toArray());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeSet(java.util.TreeSet) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 10 with ValueIndexTerm

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

the class BpmnFileIndexerTest method testBpmnIndexing.

@Test
public void testBpmnIndexing() throws Exception {
    List<Path> pathList = new ArrayList<>();
    ioService().startBatch(ioService().getFileSystem(basePath.toUri()));
    for (int i = 0; i < BPMN_FILES.length; ++i) {
        String bpmnFile = BPMN_FILES[i];
        if (bpmnFile.endsWith("bpmn")) {
            Path path = basePath.resolve(bpmnFile);
            pathList.add(path);
            String bpmnStr = loadText(bpmnFile);
            ioService().write(path, bpmnStr);
        }
    }
    ioService().endBatch();
    Path[] paths = pathList.toArray(new Path[pathList.size()]);
    {
        PageResponse<RefactoringPageRow> response = null;
        try {
            for (int i = 0; i < MAX_WAIT_TIMES; i++) {
                Thread.sleep(WAIT_TIME_MILLIS);
                response = queryBPMN2Resources();
                if (response != null && response.getPageRowList() != null && response.getPageRowList().size() >= paths.length) {
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
        assertNotNull(response);
        assertEquals(paths.length, response.getPageRowList().size());
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("*", PartType.RULEFLOW_GROUP, ValueIndexTerm.TermSearchType.WILDCARD).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[4]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("MySignal", PartType.SIGNAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[5]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("BrokenSignal", PartType.SIGNAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(1, response.size());
            assertResponseContains(response, paths[6]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        QueryOperationRequest request = QueryOperationRequest.referencesSharedPart("name", PartType.GLOBAL).inAllModules().onAllBranches();
        try {
            final List<RefactoringPageRow> response = service.queryToList(request);
            assertNotNull(response);
            assertEquals(2, response.size());
            assertResponseContains(response, paths[5]);
            assertResponseContains(response, paths[6]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>() {

            {
                add(new ValueResourceIndexTerm("*", ResourceType.BPMN2, ValueIndexTerm.TermSearchType.WILDCARD));
            }
        };
        try {
            List<RefactoringPageRow> response = service.query(FindBpmnProcessIdsQuery.NAME, queryTerms);
            assertNotNull(response);
            assertEquals(paths.length, response.size());
            for (String expectedId : PROCESS_IDS) {
                boolean foundId = false;
                for (RefactoringPageRow row : response) {
                    Map<String, org.uberfire.backend.vfs.Path> mapRow = (Map<String, org.uberfire.backend.vfs.Path>) row.getValue();
                    for (String rKey : mapRow.keySet()) {
                        assertTrue(PROCESS_IDS.contains(rKey));
                        foundId = true;
                    }
                }
                if (!foundId) {
                    fail("Process with ID <" + expectedId + " not found in results for " + FindBpmnProcessIdsQuery.NAME);
                }
            }
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) HashSet(java.util.HashSet) Set(java.util.Set) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) ArrayList(java.util.ArrayList) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Map(java.util.Map) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Aggregations

ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)23 HashSet (java.util.HashSet)13 Test (org.junit.Test)12 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)10 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)8 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)8 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)7 Path (org.uberfire.java.nio.file.Path)6 ArrayList (java.util.ArrayList)5 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 ValueSharedPartIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm)5 PageResponse (org.uberfire.paging.PageResponse)5 Map (java.util.Map)4 Term (org.apache.lucene.index.Term)4 List (java.util.List)3 Set (java.util.Set)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 Query (org.apache.lucene.search.Query)3 TermQuery (org.apache.lucene.search.TermQuery)3 Path (org.uberfire.backend.vfs.Path)3