use of org.kie.workbench.common.screens.library.api.AssetQueryResult in project kie-wb-common by kiegroup.
the class LibraryServiceImplTest method queryingUnindexedProjectGivesUnindexedResult.
@Test
public void queryingUnindexedProjectGivesUnindexedResult() throws Exception {
Branch branch = new Branch("fake-branch", mockPath("file:///a/b/c"));
final WorkspaceProject project = new WorkspaceProject(ou1, repo1, branch, mock(Module.class));
when(indexOracle.isIndexed(project)).thenReturn(false);
when(ioService.exists(any())).thenReturn(true);
final ProjectAssetsQuery query = new ProjectAssetsQuery(project, "", 0, 10, Collections.emptyList());
AssetQueryResult result = libraryService.getProjectAssets(query);
assertEquals(ResultType.Unindexed, result.getResultType());
assertFalse(result.getAssetInfos().isPresent());
}
use of org.kie.workbench.common.screens.library.api.AssetQueryResult in project kie-wb-common by kiegroup.
the class PopulatedAssetsScreenTest method searchUpdateCallbackHidesBusyIndicator.
@Test
public void searchUpdateCallbackHidesBusyIndicator() throws Exception {
AssetQueryResult assetQueryResult = AssetQueryResult.normal(new ArrayList<>());
when(libraryService.getProjectAssets(any())).thenReturn(assetQueryResult);
final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
doReturn(workspaceProject).when(libraryPlaces).getActiveWorkspace();
doReturn(mock(KieModule.class)).when(workspaceProject).getMainModule();
populatedAssetsScreen.init();
populatedAssetsScreen.search("");
verify(view).clear();
verify(busyIndicatorView).showBusyIndicator(Mockito.<String>any());
verify(populatedAssetsScreen).update(any());
verify(busyIndicatorView).hideBusyIndicator();
}
use of org.kie.workbench.common.screens.library.api.AssetQueryResult in project drools-wb by kiegroup.
the class ScenarioSimulationAssetsDropdownProviderTest method addAssets.
@Test
public void addAssets() {
int size = 4;
AssetQueryResult assetQueryResult = getAssetQueryResult(size);
scenarioSimulationAssetsDropdownProvider.addAssets(assetQueryResult, assetListConsumerMock);
verify(assetListConsumerMock, times(1)).accept(listArgumentCaptor.capture());
assertEquals(size, listArgumentCaptor.getValue().size());
}
use of org.kie.workbench.common.screens.library.api.AssetQueryResult 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) {
log.info("Asset lookup result: project [{}] does not exist.", projectIdentifierFrom(query));
return AssetQueryResult.nonexistent();
} else if (!indexOracle.isIndexed(query.getProject())) {
log.info("Asset lookup result: project [{}] is not indexed.", projectIdentifierFrom(query));
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());
log.info("Asset lookup result: project [{}] is indexed with {} index hits.", projectIdentifierFrom(query), assets.size());
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.kie.workbench.common.screens.library.api.AssetQueryResult 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 Branch branch = mock(Branch.class);
when(branch.getPath()).thenReturn(path);
final WorkspaceProject project = spy(new WorkspaceProject(ou1, repo1, branch, null));
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());
}
Aggregations