Search in sources :

Example 6 with RefactoringPageRequest

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

the class FindAllLibraryAssetsQueryTest method listAllInModule.

@Test
public void listAllInModule() throws IOException, InterruptedException {
    // Add test files
    addTestFile(TEST_MODULE_ROOT, "drl1.drl");
    addTestFile(TEST_MODULE_ROOT, "drl2.ext2");
    addTestFile(SOME_OTHER_MODULE_ROOT, "drl3.ext3");
    addTestFile(TEST_MODULE_ROOT, "functions.functions");
    // wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
    Thread.sleep(5000);
    {
        final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

            {
                add(new LibraryValueModuleRootPathIndexTerm(TEST_MODULE_ROOT, 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) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with RefactoringPageRequest

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

the class FindAllLibraryAssetsSortedQueryTest method listAllInProjectSortedPaged.

@Test
public void listAllInProjectSortedPaged() throws IOException, InterruptedException {
    setUp(TEST_PROJECT_ROOT2);
    final RefactoringPageRequest request1 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT2, TermSearchType.WILDCARD));
        }
    }, 0, 4);
    final PageResponse<RefactoringPageRow> response1 = service.query(request1);
    assertNotNull(response1);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet1 = new TreeSet<>();
    for (RefactoringPageRow row : response1.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet1.add(fileName);
    }
    String[] expectedResult1 = new String[] { "DRL4.drl", "drl1.drl", "drl2.ext2", "drl3.ext3" };
    assertArrayEquals(expectedResult1, resultSet1.toArray());
    final RefactoringPageRequest request2 = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT2, TermSearchType.WILDCARD));
        }
    }, 4, 4);
    final PageResponse<RefactoringPageRow> response2 = service.query(request2);
    assertNotNull(response2);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet2 = new TreeSet<>();
    for (RefactoringPageRow row : response2.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet2.add(fileName);
    }
    String[] expectedResult2 = new String[] { "RULE4.rule", "functions.functions", "rule3.rule" };
    assertArrayEquals(expectedResult2, resultSet2.toArray());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeSet(java.util.TreeSet) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 8 with RefactoringPageRequest

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

the class FindAllLibraryAssetsSortedQueryTest method listAllInProjectSorted.

@Test
public void listAllInProjectSorted() throws IOException, InterruptedException {
    setUp(TEST_PROJECT_ROOT1);
    final RefactoringPageRequest request = new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, new HashSet<ValueIndexTerm>() {

        {
            add(new LibraryValueModuleRootPathIndexTerm(TEST_PROJECT_ROOT1, TermSearchType.WILDCARD));
        }
    }, 0, 10);
    final PageResponse<RefactoringPageRow> response = service.query(request);
    assertNotNull(response);
    // Remove duplicates and sort file names alphabetically
    Set<String> resultSet = new TreeSet<>();
    for (RefactoringPageRow row : response.getPageRowList()) {
        String fileName = ((Path) row.getValue()).getFileName();
        System.out.println(fileName);
        resultSet.add(fileName);
    }
    assertArrayEquals(FILE_NAMES, resultSet.toArray());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) TreeSet(java.util.TreeSet) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 9 with RefactoringPageRequest

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

the class LibraryServiceImpl method getProjectAssets.

@Override
public AssetQueryResult getProjectAssets(final ProjectAssetsQuery query) {
    checkNotNull("query", query);
    final boolean projectStillExists = ioService.exists(Paths.convert(query.getProject().getBranch().getPath()));
    if (!projectStillExists) {
        return AssetQueryResult.nonexistent();
    } else if (!indexOracle.isIndexed(query.getProject())) {
        return AssetQueryResult.unindexed();
    }
    final HashSet<ValueIndexTerm> queryTerms = buildProjectAssetsQuery(query);
    final PageResponse<RefactoringPageRow> findRulesByProjectQuery = refactoringQueryService.query(new RefactoringPageRequest(FindAllLibraryAssetsQuery.NAME, queryTerms, query.getStartIndex(), query.getAmount(), Boolean.TRUE));
    final List<FolderItem> assets = findRulesByProjectQuery.getPageRowList().stream().map(row -> {
        final Path path = (Path) row.getValue();
        return new FolderItem(path, path.getFileName(), FolderItemType.FILE, false, Paths.readLockedBy(path), Collections.<String>emptyList(), explorerServiceHelper.getRestrictedOperations(path));
    }).collect(Collectors.toList());
    return AssetQueryResult.normal(assets.stream().map(asset -> {
        AssetInfo info = null;
        try {
            final Map<String, Object> attributes = ioService.readAttributes(Paths.convert((Path) asset.getItem()));
            final FileTime lastModifiedFileTime = (FileTime) getAttribute(LibraryService.LAST_MODIFIED_TIME, attributes).get();
            final FileTime createdFileTime = (FileTime) getAttribute(LibraryService.CREATED_TIME, attributes).get();
            final Date lastModifiedTime = new Date(lastModifiedFileTime.toMillis());
            final Date createdTime = new Date(createdFileTime.toMillis());
            info = new AssetInfo(asset, lastModifiedTime, createdTime);
        } catch (NoSuchFileException nfe) {
            log.debug("File '" + asset.getFileName() + "' in LibraryIndex but not VFS. Suspected deletion. Skipping.");
        }
        return Optional.ofNullable(info);
    }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
}
Also used : FileTime(org.uberfire.java.nio.file.attribute.FileTime) Date(java.util.Date) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) GAV(org.guvnor.common.services.project.model.GAV) LoggerFactory(org.slf4j.LoggerFactory) AuthorizationManager(org.uberfire.security.authz.AuthorizationManager) OrganizationalUnitService(org.guvnor.structure.organizationalunit.OrganizationalUnitService) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Paths(org.uberfire.backend.server.util.Paths) LibraryValueFileNameIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueFileNameIndexTerm) POM(org.guvnor.common.services.project.model.POM) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) RefactoringQueryService(org.kie.workbench.common.services.refactoring.service.RefactoringQueryService) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) Service(org.jboss.errai.bus.server.annotations.Service) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) SessionInfo(org.uberfire.rpc.SessionInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Repository(org.guvnor.structure.repositories.Repository) NewWorkspaceProjectUtils(org.kie.workbench.common.screens.projecteditor.util.NewWorkspaceProjectUtils) LibraryInfo(org.kie.workbench.common.screens.library.api.LibraryInfo) Collection(java.util.Collection) Set(java.util.Set) LibraryService(org.kie.workbench.common.screens.library.api.LibraryService) Collectors(java.util.stream.Collectors) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) OrganizationalUnitRepositoryInfo(org.kie.workbench.common.screens.library.api.OrganizationalUnitRepositoryInfo) LibraryPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryPreferences) LibraryInternalPreferences(org.kie.workbench.common.screens.library.api.preferences.LibraryInternalPreferences) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) LibraryValueModuleRootPathIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueModuleRootPathIndexTerm) Pattern(java.util.regex.Pattern) PageResponse(org.uberfire.paging.PageResponse) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) PortablePreconditions.checkNotNull(org.kie.soup.commons.validation.PortablePreconditions.checkNotNull) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) LibraryValueFileExtensionIndexTerm(org.kie.workbench.common.screens.library.api.index.LibraryValueFileExtensionIndexTerm) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Named(javax.inject.Named) SocialUserRepositoryAPI(org.ext.uberfire.social.activities.service.SocialUserRepositoryAPI) Path(org.uberfire.backend.vfs.Path) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) FolderItemType(org.kie.workbench.common.screens.explorer.model.FolderItemType) Logger(org.slf4j.Logger) RepositoryService(org.guvnor.structure.repositories.RepositoryService) ExplorerServiceHelper(org.kie.workbench.common.screens.explorer.backend.server.ExplorerServiceHelper) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) ExamplesService(org.kie.workbench.common.screens.examples.service.ExamplesService) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) OrganizationalUnitAction(org.guvnor.structure.security.OrganizationalUnitAction) IOService(org.uberfire.io.IOService) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject) SocialUser(org.ext.uberfire.social.activities.model.SocialUser) Collections(java.util.Collections) Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) Optional(java.util.Optional) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) FileTime(org.uberfire.java.nio.file.attribute.FileTime) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) Date(java.util.Date) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)

Example 10 with RefactoringPageRequest

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

the class LibraryServiceImplTest method queryWithAFilter.

@Test
public void queryWithAFilter() throws Exception {
    final WorkspaceProject project = spy(WorkspaceProject.class);
    final Branch branch = mock(Branch.class);
    final Path path = mockPath("file://the_project");
    when(branch.getPath()).thenReturn(path);
    when(project.getBranch()).thenReturn(branch);
    doReturn(true).when(ioService).exists(any());
    final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "helloo", 10, 20, Arrays.asList("xml"));
    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(3, pageRequest.getQueryTerms().size());
    assertQueryTermsContains(pageRequest.getQueryTerms(), "file://the_project");
    assertQueryTermsContains(pageRequest.getQueryTerms(), "*helloo*");
    assertQueryTermsContains(pageRequest.getQueryTerms(), ".*(xml)");
    assertEquals(10, pageRequest.getStartRowIndex());
    assertEquals(20, (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)

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