Search in sources :

Example 6 with RefactoringPageRow

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

the class PackageDescrIndexVisitorIndexingTest method allPackageDescrIndexVisitorMethodsTest.

@Test
public void allPackageDescrIndexVisitorMethodsTest() throws IOException, InterruptedException {
    // Add test files
    Path path = basePath.resolve(getUniqueDrlFileName());
    String accFunctionName = "testAcc";
    String accFunctionClass = "org.kie.test.objects.TestAccumulator";
    String entryPointName = "testEntryPoint";
    String entryPointAnno = "testAnno";
    String windowName = "TestWindow";
    String funcDeclName = "myFunction";
    String rule1Name = "ruleOne";
    String rule2Name = "windowRule";
    String rule3Name = "condBranchRule";
    String drlSource = "package org.kie.indexing;\n" + "import org.kie.test.objects.*;\n" + "import accumulate " + accFunctionClass + " " + accFunctionName + "\n\n" + // 3
    "declare entry-point '" + entryPointName + "' @" + entryPointAnno + " end\n\n" + // 5
    "declare enum Workload\n" + // this info (local reference) can *not* be retrieved via compilation!
    "  LIGHT( 4 ),\n" + "  MEDIUM( 8 ),\n" + "  HEAVY( 12 );\n" + "  hours   : int\n" + "end\n\n" + // 12
    "declare TestWork\n" + "  load  : WorkLoad\n" + "  num   : int = 111\n" + "  pers  : Person \n" + "end\n\n" + // (Trace why this test fails, to see why.. )
    "declare window " + windowName + "\n" + "Person( name == 'mark' )\n" + "  over window:length( 10 )\n" + "  from entry-point " + entryPointName + "\n" + "end\n\n" + "function String " + funcDeclName + "(Cheese cheese) {\n" + "  return 'Hello' cheese.type\n" + "}\n\n" + "rule EnumRule\n" + "when\n" + // Workload.LIGHT reference info must be retrieved via compilation!
    "  TestWork( WorkLoad.LIGHT, $h : load.hours )\n" + "then\n" + "  list.add( $h );\n" + "end\n" + "rule " + rule1Name + "\n" + "when\n" + "  Person( name == \"mark\", cheese.(price == 10, type.(length == 10) ) )\n" + "then\n" + "end\n\n" + // 28
    "rule " + rule2Name + "\n" + "when\n" + "  accumulate( Person( name == 'mark' ) from window TestWindow, $cnt : " + accFunctionName + "(1) )\n" + "then\n" + "  // there has been $cnt RHT ticks over the last 10 ticks\n" + "end\n\n" + // 35
    "rule " + rule3Name + "\n" + "when\n" + "  $customer : Customer( age > 60 )\n" + "  if ( type == Golden ) do[giveDiscount]\n" + "  $car : Car ( owner == $customer )\n" + "then\n" + "  modify($car) { setFreeParking( true ) }\n" + "then[giveDiscount]\n" + "  modify($customer) { setDiscount( 0.1 ) }\n" + "end\n";
    ioService().write(path, drlSource);
    path = basePath.resolve(getUniqueDrlFileName());
    drlSource = loadText("accumulate.drl");
    ioService().write(path, drlSource);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    String className = Person.class.getName();
    QueryOperationRequest refOpRequest = QueryOperationRequest.referencesPart(className, "setName(String)", PartType.METHOD).inAllModules().onAllBranches();
    List<RefactoringPageRow> response = service.queryToList(refOpRequest);
    assertNotNull("Null PageResonse", response);
    assertNotNull("Null PageRefactoringRow list", response);
    assertEquals("Objects referencing " + className, 1, response.size());
    Object pageRowValue = response.get(0).getValue();
    assertTrue("Expected a " + org.uberfire.backend.vfs.Path.class.getName() + ", not a " + pageRowValue.getClass().getSimpleName(), org.uberfire.backend.vfs.Path.class.isAssignableFrom(pageRowValue.getClass()));
    String fileName = ((org.uberfire.backend.vfs.Path) pageRowValue).getFileName();
    assertTrue("File does not end with '.java'", fileName.endsWith(".java"));
    assertEquals("File name", className, fileName.subSequence(0, fileName.indexOf(".java")));
}
Also used : Path(org.uberfire.java.nio.file.Path) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 7 with RefactoringPageRow

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

the class RuleNameServiceImpl method convertToRuleNames.

private List<String> convertToRuleNames(List<RefactoringPageRow> results) {
    final List<String> ruleNames = new ArrayList<String>();
    for (RefactoringPageRow row : results) {
        ruleNames.add(((RefactoringRuleNamePageRow.RuleName) row.getValue()).getSimpleRuleName());
    }
    Collections.sort(ruleNames);
    return ruleNames;
}
Also used : ArrayList(java.util.ArrayList) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) RefactoringRuleNamePageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringRuleNamePageRow)

Example 8 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow 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)

Example 9 with RefactoringPageRow

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

the class FindAllLibraryAssetsQueryTest method listAllInModule.

@Test
public void listAllInModule() throws IOException, InterruptedException {
    // Add test files
    addTestFile(TEST_MODULE_ROOT, "drl1.drl");
    addTestFile(TEST_MODULE_ROOT, "drl2.ext2");
    addTestFile(SOME_OTHER_MODULE_ROOT, "drl3.ext3");
    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));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            for (RefactoringPageRow refactoringPageRow : response.getPageRowList()) {
                System.out.println(refactoringPageRow.getValue());
            }
            assertEquals(3, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) 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)

Example 10 with RefactoringPageRow

use of org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow 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)

Aggregations

RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)26 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)11 Path (org.uberfire.backend.vfs.Path)10 PageResponse (org.uberfire.paging.PageResponse)9 HashSet (java.util.HashSet)8 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)8 Path (org.uberfire.java.nio.file.Path)5 Map (java.util.Map)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)4 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)4 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)4 Set (java.util.Set)3 Branch (org.guvnor.structure.repositories.Branch)3 List (java.util.List)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 AssetInfo (org.kie.workbench.common.screens.library.api.AssetInfo)2