Search in sources :

Example 1 with QueryOperationRequest

use of org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest 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 2 with QueryOperationRequest

use of org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest in project kie-wb-common by kiegroup.

the class QueryOperationRequestTest method exampleCode.

@Test
@SuppressWarnings("unused")
public void exampleCode() {
    String className = this.getClass().getName();
    String projectName = "org.my.package:my-project:1.0";
    String projectRootPathURI = "default://repo/my-project";
    String newClassName = Random.class.getName();
    DeleteOperationRequest delReq = DeleteOperationRequest.deleteReferences(className, ResourceType.JAVA).inModule(projectName).onAllBranches();
    delReq = DeleteOperationRequest.deleteReferences(className, ResourceType.JAVA).inModuleRootPathURI(projectRootPathURI).onAllBranches();
    delReq = DeleteOperationRequest.deletePartReferences(className, "setAge(long)", PartType.METHOD).inModule(projectName).onAllBranches();
    delReq = DeleteOperationRequest.deletePartReferences(className, "setAge(long)", PartType.METHOD).inModuleRootPathURI(projectRootPathURI).onAllBranches();
    RefactorOperationRequest refOp = RefactorOperationRequest.refactorReferences(className, ResourceType.JAVA, newClassName).inModule(projectName).onBranch("branch-name");
    refOp = RefactorOperationRequest.refactorReferences(className, ResourceType.JAVA, newClassName).inModuleRootPathURI(projectRootPathURI).onBranch("branch-name");
    refOp = RefactorOperationRequest.refactorPartReferences(className, "toName(int)", PartType.METHOD, "toSurName(int)").inModule(projectName).onAllBranches();
    refOp = RefactorOperationRequest.refactorPartReferences(className, "toName(int)", PartType.METHOD, "toSurName(int)").inModuleRootPathURI(projectRootPathURI).onAllBranches();
    refOp = RefactorOperationRequest.refactorPartReferences(className, "toName(int)", PartType.METHOD, "toSurName(int)").inModule(projectName).onBranch("branch-name");
    QueryOperationRequest queOp = QueryOperationRequest.references(className, ResourceType.JAVA).inModule(projectName).onBranch("branch-name");
    queOp = QueryOperationRequest.references(className, ResourceType.JAVA).inModuleRootPathURI(projectRootPathURI).onBranch("branch-name");
}
Also used : RefactorOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.RefactorOperationRequest) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) DeleteOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.DeleteOperationRequest) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 3 with QueryOperationRequest

use of org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest in project kie-wb-common by kiegroup.

the class ImpactAnalysisJavaFileTest method testReferenceQueryInfrastructure.

@Test
public void testReferenceQueryInfrastructure() throws Exception {
    Class referencedClass = AnnotationValuesAnnotation.class;
    QueryOperationRequest queryOpRequest = QueryOperationRequest.references(referencedClass.getName(), ResourceType.JAVA).inAllModules().onAllBranches();
    testQueryOperationRequest(queryOpRequest);
    queryOpRequest = QueryOperationRequest.references(referencedClass.getName(), ResourceType.JAVA).inModule(TEST_MODULE_NAME).onAllBranches();
    testQueryOperationRequest(queryOpRequest);
    queryOpRequest = QueryOperationRequest.references(referencedClass.getName(), ResourceType.JAVA).inModuleRootPathURI(TEST_MODULE_ROOT).onAllBranches();
    testQueryOperationRequest(queryOpRequest);
    queryOpRequest = QueryOperationRequest.references(referencedClass.getName(), ResourceType.JAVA).inAllModules().onBranch("master");
    testQueryOperationRequest(queryOpRequest);
}
Also used : QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 4 with QueryOperationRequest

use of org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest 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)

Example 5 with QueryOperationRequest

use of org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest in project kie-wb-common by kiegroup.

the class AssetsUsageServiceImpl method getQueryList.

protected List<Path> getQueryList(Path assetPath, RefactorOperationBuilder<QueryOperationRequest>.RequiresModule builder) {
    KieModule project = moduleService.resolveModule(assetPath);
    String branch = "master";
    org.uberfire.java.nio.file.Path nioPath = Paths.convert(assetPath);
    if (nioPath instanceof SegmentedPath) {
        branch = ((SegmentedPath) nioPath).getSegmentId();
    }
    QueryOperationRequest request = builder.inModuleRootPathURI(project.getRootPath().toURI()).onBranch(branch);
    return refactoringQueryService.queryToList(request).stream().map(row -> (Path) row.getValue()).collect(Collectors.toList());
}
Also used : KieModule(org.kie.workbench.common.services.shared.project.KieModule) RefactorOperationBuilder(org.kie.workbench.common.services.refactoring.service.impact.RefactorOperationBuilder) AssetsUsageService(org.kie.workbench.common.services.refactoring.service.AssetsUsageService) Collectors(java.util.stream.Collectors) PartType(org.kie.workbench.common.services.refactoring.service.PartType) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) List(java.util.List) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) ResourceType(org.kie.workbench.common.services.refactoring.service.ResourceType) RefactoringQueryService(org.kie.workbench.common.services.refactoring.service.RefactoringQueryService) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Service(org.jboss.errai.bus.server.annotations.Service) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Path(org.uberfire.backend.vfs.Path) SegmentedPath(org.uberfire.java.nio.base.SegmentedPath) Path(org.uberfire.backend.vfs.Path) SegmentedPath(org.uberfire.java.nio.base.SegmentedPath) QueryOperationRequest(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest) SegmentedPath(org.uberfire.java.nio.base.SegmentedPath) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Aggregations

QueryOperationRequest (org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest)6 Test (org.junit.Test)5 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)5 List (java.util.List)3 Path (org.uberfire.java.nio.file.Path)3 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 Service (org.jboss.errai.bus.server.annotations.Service)1 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)1 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)1 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)1 AssetsUsageService (org.kie.workbench.common.services.refactoring.service.AssetsUsageService)1 PartType (org.kie.workbench.common.services.refactoring.service.PartType)1 RefactoringQueryService (org.kie.workbench.common.services.refactoring.service.RefactoringQueryService)1