Search in sources :

Example 1 with ValueModuleRootPathIndexTerm

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

the class FindRulesByModuleQuery method toQuery.

@Override
public Query toQuery(final Set<ValueIndexTerm> terms) {
    checkNotNullAndNotEmpty(terms);
    ValuePackageNameIndexTerm packageTerm = null;
    ValueModuleRootPathIndexTerm projectTerm = null;
    ValueResourceIndexTerm ruleTerm = null;
    for (ValueIndexTerm term : terms) {
        if (term instanceof ValuePackageNameIndexTerm) {
            packageTerm = (ValuePackageNameIndexTerm) term;
        } else if (term instanceof ValueModuleRootPathIndexTerm) {
            projectTerm = (ValueModuleRootPathIndexTerm) term;
        } else if (term instanceof ValueResourceIndexTerm) {
            ruleTerm = (ValueResourceIndexTerm) term;
        }
    }
    SearchEmptyQueryBuilder queryBuilder = new SearchEmptyQueryBuilder().addTerm(packageTerm).addTerm(projectTerm);
    if (ruleTerm != null) {
        queryBuilder.addTerm(ruleTerm);
    } else {
        queryBuilder.addRuleNameWildCardTerm();
    }
    return queryBuilder.build();
}
Also used : ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) SearchEmptyQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SearchEmptyQueryBuilder) ValuePackageNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePackageNameIndexTerm) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)

Example 2 with ValueModuleRootPathIndexTerm

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

the class RefactoringQueryServiceImpl method convertToRefactoringPageRequest.

private RefactoringPageRequest convertToRefactoringPageRequest(QueryOperationRequest refOpRequest) {
    RefactoringPageRequest request = new RefactoringPageRequest(FindAllChangeImpactQuery.NAME, new HashSet<>(), refOpRequest.getStartRowIndex(), refOpRequest.getPageSize());
    request.getQueryTerms().addAll(refOpRequest.getQueryTerms());
    // add project info
    String projectName = refOpRequest.getModuleName();
    if (projectName != null && projectName != QueryOperationRequest.ALL) {
        ValueModuleNameIndexTerm valueIndexTerm = new ValueModuleNameIndexTerm(projectName);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    String projectRootPathURI = refOpRequest.getModuleRootPathURI();
    if (projectRootPathURI != null && projectRootPathURI != QueryOperationRequest.ALL) {
        ValueModuleRootPathIndexTerm valueIndexTerm = new ValueModuleRootPathIndexTerm(projectRootPathURI);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    String branchName = refOpRequest.getBranchName();
    if (branchName != null && branchName != QueryOperationRequest.ALL) {
        ValueBranchNameIndexTerm valueIndexTerm = new ValueBranchNameIndexTerm(branchName);
        Set<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>(1);
        queryTerms.add(valueIndexTerm);
        request.getQueryTerms().addAll(queryTerms);
    }
    return request;
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ValueBranchNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueBranchNameIndexTerm) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm) ValueModuleNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleNameIndexTerm) HashSet(java.util.HashSet)

Example 3 with ValueModuleRootPathIndexTerm

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

the class FindRulesByModuleQueryValidIndexTermsTest method testQueryValidIndexTerms.

@Test
public void testQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl1.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl2.drl");
    addTestFile(SOME_OTHER_PROJECT_ROOT, "drl3.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl4.drl");
    addTestFile(BaseIndexingTest.TEST_MODULE_ROOT, "drl5.drl");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT, TermSearchType.WILDCARD));
                add(new ValuePackageNameIndexTerm("", TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "noPackage", "");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm("*", TermSearchType.WILDCARD));
                add(new ValuePackageNameIndexTerm("*", TermSearchType.WILDCARD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(5, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule2", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule3", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "my.Rule4", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "noPackage", "");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(3, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "myRule2", "org.kie.workbench.mock.package");
            assertResponseContains(response.getPageRowList(), "my.Rule4", "org.kie.workbench.mock.package");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(SOME_OTHER_PROJECT_ROOT));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(1, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), "myRule3", "org.kie.workbench.mock.package");
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm(BaseIndexingTest.TEST_MODULE_ROOT));
                add(new ValuePackageNameIndexTerm("non-existent-package-name"));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            fail("Unable to query: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindRulesByModuleQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueModuleRootPathIndexTerm("non-existent-module-root"));
                add(new ValuePackageNameIndexTerm(BaseIndexingTest.TEST_PACKAGE_NAME));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(0, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Unable to query: " + e.getMessage());
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) PageResponse(org.uberfire.paging.PageResponse) ValueModuleRootPathIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm) ValuePackageNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePackageNameIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Aggregations

ValueModuleRootPathIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)3 HashSet (java.util.HashSet)2 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)2 ValuePackageNameIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePackageNameIndexTerm)2 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)2 Test (org.junit.Test)1 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)1 SearchEmptyQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SearchEmptyQueryBuilder)1 ValueBranchNameIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueBranchNameIndexTerm)1 ValueModuleNameIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleNameIndexTerm)1 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)1 PageResponse (org.uberfire.paging.PageResponse)1