use of org.uberfire.paging.PageResponse 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()));
}
use of org.uberfire.paging.PageResponse 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());
}
use of org.uberfire.paging.PageResponse in project kie-wb-common by kiegroup.
the class LibraryServiceImplTest method queryAnItemThatIsInLuceneIndexButAlreadyDeletedFromGitRepository.
@Test
public void queryAnItemThatIsInLuceneIndexButAlreadyDeletedFromGitRepository() throws Exception {
final Path path = mockPath("file://the_project");
final WorkspaceProject project = spy(WorkspaceProject.class);
final Branch branch = mock(Branch.class);
when(project.getBranch()).thenReturn(branch);
when(branch.getPath()).thenReturn(path);
doReturn(true).when(ioService).exists(any());
final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 10, 20, Collections.emptyList());
final PageResponse<RefactoringPageRow> pageRowPageResponse = new PageResponse<>();
final ArrayList<RefactoringPageRow> assetPageRowList = new ArrayList<>();
final RefactoringPageRow pageRow = mock(RefactoringPageRow.class);
final Path filePath = mockPath("file://the_project/delete.me");
when(filePath.getFileName()).thenReturn("delete.me");
when(pageRow.getValue()).thenReturn(filePath);
assetPageRowList.add(pageRow);
pageRowPageResponse.setPageRowList(assetPageRowList);
when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageRowPageResponse);
when(ioService.readAttributes(any())).thenThrow(new NoSuchFileException());
final AssetQueryResult result = libraryService.getProjectAssets(query);
assertEquals(ResultType.Normal, result.getResultType());
assertTrue(result.getAssetInfos().isPresent());
List<AssetInfo> projectAssets = result.getAssetInfos().get();
assertTrue(projectAssets.isEmpty());
}
use of org.uberfire.paging.PageResponse 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());
}
use of org.uberfire.paging.PageResponse 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());
}
}
}
Aggregations