Search in sources :

Example 16 with RefactoringPageRequest

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

the class RefactoringQueryServiceImpl method queryToList.

@Override
public List<RefactoringPageRow> queryToList(final QueryOperationRequest queryOpRequest) {
    final RefactoringPageRequest request = convertToRefactoringPageRequest(queryOpRequest);
    final List<RefactoringPageRow> response = query(request.getQueryName(), request.getQueryTerms());
    return response;
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 17 with RefactoringPageRequest

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

the class FindResourcePartReferencesQueryInvalidIndexTermsTest method testFindResourcePartReferencesQueryInvalidIndexTerms.

@Test
public void testFindResourcePartReferencesQueryInvalidIndexTerms() throws IOException, InterruptedException {
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>(), 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().startsWith("At least 1 term must be submitted"));
        // and Swallow. Expected
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().startsWith("Index term 'ref:rule' can not be used with"));
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA));
                add(new ValueReferenceIndexTerm("myRule", ResourceType.RULE));
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains(" can not be used with the " + FindResourcePartReferencesQuery.NAME));
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 18 with RefactoringPageRequest

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

the class FindResourcePartReferencesQueryValidIndexTermsTest method testFindResourcePartReferencesQueryValidIndexTerms.

@Test
public void testFindResourcePartReferencesQueryValidIndexTerms() throws IOException, InterruptedException {
    // Add test files
    Path[] path = { basePath.resolve("drl1.drl"), basePath.resolve("drl2.drl"), basePath.resolve("drl3.drl") };
    String[] content = { loadText("../findresourceparts/drl1.drl"), loadText("../findresourceparts/drl2.drl"), loadText("../findresourceparts/drl3.drl") };
    for (int i = 0; i < path.length; ++i) {
        ioService().write(path[i], content[i]);
    }
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValuePartReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", "age", PartType.FIELD));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
            assertResponseContains(response.getPageRowList(), path[1]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartReferencesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueSharedPartIndexTerm("myRuleFlowGroup", PartType.RULEFLOW_GROUP));
            }
        }, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull(response);
            assertEquals(2, response.getPageRowList().size());
            assertResponseContains(response.getPageRowList(), path[0]);
            assertResponseContains(response.getPageRowList(), path[2]);
        } catch (IllegalArgumentException e) {
            fail("Exception thrown: " + e.getMessage());
        }
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueSharedPartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueSharedPartIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValuePartReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartReferenceIndexTerm) PageResponse(org.uberfire.paging.PageResponse) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 19 with RefactoringPageRequest

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

the class FindResourcePartsQueryInvalidIndexTermsTest method testFindResourcePartsQueryInvalidIndexTerms.

@Test
public void testFindResourcePartsQueryInvalidIndexTerms() throws IOException, InterruptedException {
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcePartsQuery", new HashSet<ValueIndexTerm>(), 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().startsWith("Expected '" + ValuePartIndexTerm.class.getSimpleName() + "' term was not found"));
        // and Swallow. Expected
        }
    }
    ValueIndexTerm ruleRefTerm = new ValueReferenceIndexTerm("myRule", ResourceType.RULE);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcePartsQuery", new HashSet<ValueIndexTerm>() {

            {
                add(ruleRefTerm);
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().startsWith("Index term '" + ruleRefTerm.getTerm() + "' can not be used with"));
        // and Swallow. Expected
        }
    }
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourcePartsQuery", new HashSet<ValueIndexTerm>() {

            {
                add(new ValueReferenceIndexTerm("org.kie.workbench.common.services.refactoring.backend.server.drl.classes.Applicant", ResourceType.JAVA));
                add(ruleRefTerm);
            }
        }, 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            assertTrue("Unexpected exception: " + e.getMessage(), e.getMessage().contains(" can not be used with the " + FindResourcePartsQuery.NAME));
        // and Swallow. Expected
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueReferenceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Example 20 with RefactoringPageRequest

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

the class FindResourceReferencesQueryInvalidIndexTermsTest method testQueryInvalidIndexTerms.

@Test
public void testQueryInvalidIndexTerms() throws IOException, InterruptedException {
    {
        final RefactoringPageRequest request = new RefactoringPageRequest("FindResourceReferencesQuery", new HashSet<ValueIndexTerm>(), 0, -1);
        try {
            service.query(request);
            fail();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().startsWith("Expected 'ref:*' term was not found"));
        // and Swallow. Expected
        }
    }
}
Also used : RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) HashSet(java.util.HashSet) Test(org.junit.Test) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)

Aggregations

RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)22 Test (org.junit.Test)17 HashSet (java.util.HashSet)16 PageResponse (org.uberfire.paging.PageResponse)12 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)10 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)10 ValueIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm)8 LibraryValueModuleRootPathIndexTerm (org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm)5 Path (org.uberfire.backend.vfs.Path)5 Path (org.uberfire.java.nio.file.Path)5 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)4 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)3 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 Branch (org.guvnor.structure.repositories.Branch)2 ValueModuleRootPathIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueModuleRootPathIndexTerm)2 ValueResourceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm)2 Collection (java.util.Collection)1