Search in sources :

Example 11 with RefactoringPageRequest

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

the class LibraryServiceImplTest method emptyFirstPage.

@Test
public void emptyFirstPage() throws Exception {
    final WorkspaceProject project = spy(WorkspaceProject.class);
    final Branch branch = mock(Branch.class);
    final Path path = mock(Path.class);
    when(project.getBranch()).thenReturn(branch);
    when(branch.getPath()).thenReturn(path);
    when(path.toURI()).thenReturn("file://a/b/c");
    doReturn(true).when(ioService).exists(any());
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 0, 10, Collections.emptyList());
    final PageResponse<RefactoringPageRow> pageRowPageResponse = new PageResponse<>();
    pageRowPageResponse.setPageRowList(new ArrayList<>());
    when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageRowPageResponse);
    libraryService.getProjectAssets(query);
    verify(refactoringQueryService).query(pageRequestArgumentCaptor.capture());
    final RefactoringPageRequest pageRequest = pageRequestArgumentCaptor.getValue();
    assertEquals(FindAllLibraryAssetsQuery.NAME, pageRequest.getQueryName());
    assertEquals(1, pageRequest.getQueryTerms().size());
    assertEquals("file://a/b/c", pageRequest.getQueryTerms().iterator().next().getValue());
    assertEquals(0, pageRequest.getStartRowIndex());
    assertEquals(10, (int) pageRequest.getPageSize());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Branch(org.guvnor.structure.repositories.Branch) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 12 with RefactoringPageRequest

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

the class ListAssetsTest method listFilesShouldNotHaveDuplicatesFromLibraryIndexer.

@Test
public void listFilesShouldNotHaveDuplicatesFromLibraryIndexer() throws IOException, InterruptedException {
    // Add test files
    addTestFile(TEST_MODULE_ROOT, "rule1.rule");
    addTestFile(TEST_MODULE_ROOT, "rule2.rule");
    addTestFile(TEST_MODULE_ROOT, "rule3.rule");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(TestFindFilesQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new ValueFullFileNameIndexTerm("*.rule", ValueIndexTerm.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) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) ValueFullFileNameIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueFullFileNameIndexTerm) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with RefactoringPageRequest

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

the class FindResourcePartsQueryValidIndexTermsTest method testIndexJavaFilesAndFindResourcePartsQuery.

@Test
public void testIndexJavaFilesAndFindResourcePartsQuery() throws Exception {
    // setup
    ioService();
    // Add test files
    String pojo1FileName = "Pojo1.java";
    Path path = basePath.resolve(pojo1FileName);
    String javaSourceText = loadText("../" + pojo1FileName);
    ioService().write(path, javaSourceText);
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath.getFileSystem()).getClusterId());
    {
        final Query query = new SingleTermQueryBuilder(new ValueResourceIndexTerm("*", ResourceType.JAVA, TermSearchType.WILDCARD)).build();
        List<KObject> hits = getConfig().getIndexProvider().findByQuery(index, query, 10);
        assertEquals(1, hits.size());
        List<Pair<String, String>> expectedValues = initExpectedValues();
        KObject doc = null;
        for (KObject kObject : hits) {
            doc = kObject;
            for (KProperty<?> property : doc.getProperties()) {
                String fieldVal = property.getValue().toString();
                if (fieldVal.startsWith("git://")) {
                    if (fieldVal.contains(pojo1FileName)) {
                        break;
                    }
                } else {
                    continue;
                }
            }
        }
        assertContains(expectedValues, doc);
    }
    {
        HashSet<ValueIndexTerm> queryTerms = new HashSet<ValueIndexTerm>();
        queryTerms.add(new ValuePartIndexTerm("o_BigDecimal", PartType.FIELD));
        final RefactoringPageRequest request = new RefactoringPageRequest(FindResourcePartsQuery.NAME, queryTerms, 0, 10);
        try {
            final PageResponse<RefactoringPageRow> response = service.query(request);
            assertNotNull("No documents found!", response);
            assertEquals(1, response.getPageRowList().size());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Could not execute query: " + e.getMessage());
        }
    }
    ;
}
Also used : Path(org.uberfire.java.nio.file.Path) ValueResourceIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueResourceIndexTerm) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Query(org.apache.lucene.search.Query) FindResourcePartsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindResourcePartsQuery) NamedQuery(org.kie.workbench.common.services.refactoring.backend.server.query.NamedQuery) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) KObject(org.uberfire.ext.metadata.model.KObject) SingleTermQueryBuilder(org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder) KProperty(org.uberfire.ext.metadata.model.KProperty) PageResponse(org.uberfire.paging.PageResponse) ArrayList(java.util.ArrayList) List(java.util.List) ValuePartIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValuePartIndexTerm) HashSet(java.util.HashSet) BaseIndexingTest(org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest) Test(org.junit.Test)

Example 14 with RefactoringPageRequest

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

the class RefactoringQueryServiceImpl method queryToPageResponse.

/* (non-Javadoc)
     * @see org.kie.workbench.common.services.refactoring.service.RefactoringQueryService#queryToPageResponse(org.kie.workbench.common.services.refactoring.service.impact.QueryOperationRequest)
     */
@Override
public PageResponse<RefactoringPageRow> queryToPageResponse(QueryOperationRequest queryOpRequest) {
    final RefactoringPageRequest request = convertToRefactoringPageRequest(queryOpRequest);
    final PageResponse<RefactoringPageRow> response = query(request);
    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 15 with RefactoringPageRequest

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

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