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")));
}
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");
}
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);
}
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());
}
}
}
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());
}
Aggregations