@Test public void queryingUnindexedProjectGivesUnindexedResult() throws Exception { Branch branch = new Branch("fake-branch", mockPath("file: 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()); }
@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())); }
LibraryServiceImpl implements LibraryService { @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())); } }
LibraryServiceImpl implements LibraryService { @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())); } LibraryServiceImpl(); @Inject  LibraryServiceImpl(final OrganizationalUnitService ouService,
                              final RefactoringQueryService refactoringQueryService,
                              final LibraryPreferences preferences,
                              final AuthorizationManager authorizationManager,
                              final SessionInfo sessionInfo,
                              final ExplorerServiceHelper explorerServiceHelper,
                              final WorkspaceProjectService projectService,
                              final KieModuleService moduleService,
                              final ExamplesService examplesService,
                              @Named("ioStrategy") final IOService ioService,
                              final UserManagerService userManagerService,
                              final IndexStatusOracle indexOracle,
                              final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                              final ClusterService clusterService,
                              final ArchetypeService archetypeService); }
LibraryServiceImpl implements LibraryService { @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())); } LibraryServiceImpl(); @Inject  LibraryServiceImpl(final OrganizationalUnitService ouService,
                              final RefactoringQueryService refactoringQueryService,
                              final LibraryPreferences preferences,
                              final AuthorizationManager authorizationManager,
                              final SessionInfo sessionInfo,
                              final ExplorerServiceHelper explorerServiceHelper,
                              final WorkspaceProjectService projectService,
                              final KieModuleService moduleService,
                              final ExamplesService examplesService,
                              @Named("ioStrategy") final IOService ioService,
                              final UserManagerService userManagerService,
                              final IndexStatusOracle indexOracle,
                              final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                              final ClusterService clusterService,
                              final ArchetypeService archetypeService); @Override OrganizationalUnitRepositoryInfo getDefaultOrganizationalUnitRepositoryInfo(); @Override OrganizationalUnitRepositoryInfo getOrganizationalUnitRepositoryInfo(final OrganizationalUnit selectedOrganizationalUnit); @Override LibraryInfo getLibraryInfo(final OrganizationalUnit organizationalUnit); @Override WorkspaceProject createProject(final OrganizationalUnit organizationalUnit,
                                          final String remoteRepositoryUrl,
                                          final String repositoryAlias); @Override WorkspaceProject createProject(final String projectName,
                                          final OrganizationalUnit selectedOrganizationalUnit,
                                          final String projectDescription,
                                          final DeploymentMode deploymentMode); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode,
                                          final String templateId); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode,
                                          final String templateId,
                                          final String remoteRepositoryUrl); @Override Boolean thereIsAProjectInTheWorkbench(); @Override AssetQueryResult getProjectAssets(final ProjectAssetsQuery query); @Override Boolean hasProjects(final OrganizationalUnit organizationalUnit); @Override Boolean hasAssets(final WorkspaceProject project); @Override Set<ImportProject> getExampleProjects(OrganizationalUnit organizationalUnit); @Override List<OrganizationalUnit> getOrganizationalUnits(); @Override GAV createGAV(final String projectName,
                         final OrganizationalUnit selectedOrganizationalUnit); @Override synchronized List<String> getAllUsers(); @Override void addBranch(final String newBranchName,
                          final String baseBranchName,
                          final WorkspaceProject project); @Override void removeBranch(final WorkspaceProject project,
                             final Branch branch); @Override BranchPermissions loadBranchPermissions(final String spaceName,
                                                   final String projectIdentifier,
                                                   final String branchName); @Override void saveBranchPermissions(final String spaceName,
                                      final String projectIdentifier,
                                      final String branchName,
                                      final BranchPermissions branchPermissions); @Override Boolean isClustered(); @Override int getNumberOfAssets(final ProjectAssetsQuery query); @Override int getNumberOfAssets(final WorkspaceProject module); @Override OrganizationalUnit getDefaultOrganizationalUnit(); }
LibraryServiceImpl implements LibraryService { @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())); } LibraryServiceImpl(); @Inject  LibraryServiceImpl(final OrganizationalUnitService ouService,
                              final RefactoringQueryService refactoringQueryService,
                              final LibraryPreferences preferences,
                              final AuthorizationManager authorizationManager,
                              final SessionInfo sessionInfo,
                              final ExplorerServiceHelper explorerServiceHelper,
                              final WorkspaceProjectService projectService,
                              final KieModuleService moduleService,
                              final ExamplesService examplesService,
                              @Named("ioStrategy") final IOService ioService,
                              final UserManagerService userManagerService,
                              final IndexStatusOracle indexOracle,
                              final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                              final ClusterService clusterService,
                              final ArchetypeService archetypeService); @Override OrganizationalUnitRepositoryInfo getDefaultOrganizationalUnitRepositoryInfo(); @Override OrganizationalUnitRepositoryInfo getOrganizationalUnitRepositoryInfo(final OrganizationalUnit selectedOrganizationalUnit); @Override LibraryInfo getLibraryInfo(final OrganizationalUnit organizationalUnit); @Override WorkspaceProject createProject(final OrganizationalUnit organizationalUnit,
                                          final String remoteRepositoryUrl,
                                          final String repositoryAlias); @Override WorkspaceProject createProject(final String projectName,
                                          final OrganizationalUnit selectedOrganizationalUnit,
                                          final String projectDescription,
                                          final DeploymentMode deploymentMode); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode,
                                          final String templateId); @Override WorkspaceProject createProject(final OrganizationalUnit activeOrganizationalUnit,
                                          final POM pom,
                                          final DeploymentMode mode,
                                          final String templateId,
                                          final String remoteRepositoryUrl); @Override Boolean thereIsAProjectInTheWorkbench(); @Override AssetQueryResult getProjectAssets(final ProjectAssetsQuery query); @Override Boolean hasProjects(final OrganizationalUnit organizationalUnit); @Override Boolean hasAssets(final WorkspaceProject project); @Override Set<ImportProject> getExampleProjects(OrganizationalUnit organizationalUnit); @Override List<OrganizationalUnit> getOrganizationalUnits(); @Override GAV createGAV(final String projectName,
                         final OrganizationalUnit selectedOrganizationalUnit); @Override synchronized List<String> getAllUsers(); @Override void addBranch(final String newBranchName,
                          final String baseBranchName,
                          final WorkspaceProject project); @Override void removeBranch(final WorkspaceProject project,
                             final Branch branch); @Override BranchPermissions loadBranchPermissions(final String spaceName,
                                                   final String projectIdentifier,
                                                   final String branchName); @Override void saveBranchPermissions(final String spaceName,
                                      final String projectIdentifier,
                                      final String branchName,
                                      final BranchPermissions branchPermissions); @Override Boolean isClustered(); @Override int getNumberOfAssets(final ProjectAssetsQuery query); @Override int getNumberOfAssets(final WorkspaceProject module); @Override OrganizationalUnit getDefaultOrganizationalUnit();  }