Search in sources :

Example 1 with AssetInfo

use of org.kie.workbench.common.screens.library.api.AssetInfo in project kie-wb-common by kiegroup.

the class ProjectScreenTestBase method getAssetInfo.

protected AssetInfo getAssetInfo(final String assetPathString, final FolderItemType itemType, final String itemName) {
    final Path assetPath = mock(Path.class);
    doReturn(assetPathString).when(assetPath).toURI();
    final FolderItem asset = mock(FolderItem.class);
    doReturn(itemType).when(asset).getType();
    doReturn(itemName).when(asset).getFileName();
    doReturn(assetPath).when(asset).getItem();
    return new AssetInfo(asset, new Date(), new Date());
}
Also used : Path(org.uberfire.backend.vfs.Path) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) Date(java.util.Date)

Example 2 with AssetInfo

use of org.kie.workbench.common.screens.library.api.AssetInfo 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()));
}
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) POM(org.guvnor.common.services.project.model.POM) BranchPermissions(org.guvnor.structure.organizationalunit.config.BranchPermissions) RefactoringQueryService(org.kie.workbench.common.services.refactoring.service.RefactoringQueryService) LibraryValueFileNameIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueFileNameIndexTerm) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) ContributorType(org.uberfire.security.ContributorType) Service(org.jboss.errai.bus.server.annotations.Service) SessionInfo(org.uberfire.rpc.SessionInfo) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) RepositoryAction(org.guvnor.structure.security.RepositoryAction) LibraryValueRepositoryRootIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueRepositoryRootIndexTerm) UserManagerService(org.uberfire.ext.security.management.api.service.UserManagerService) Repository(org.guvnor.structure.repositories.Repository) SpaceConfigStorageRegistry(org.guvnor.structure.organizationalunit.config.SpaceConfigStorageRegistry) 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) LibraryValueFileExtensionIndexTerm(org.kie.workbench.common.services.refactoring.backend.server.query.standard.LibraryValueFileExtensionIndexTerm) 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) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClusterService(org.uberfire.commons.cluster.ClusterService) 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) ArchetypeService(org.kie.workbench.common.screens.archetype.mgmt.shared.services.ArchetypeService) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Archetype(org.kie.workbench.common.screens.archetype.mgmt.shared.model.Archetype) Named(javax.inject.Named) 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) FindAllLibraryAssetsQuery(org.kie.workbench.common.services.refactoring.backend.server.query.standard.FindAllLibraryAssetsQuery) ExplorerServiceHelper(org.kie.workbench.common.screens.explorer.backend.server.ExplorerServiceHelper) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) ExamplesService(org.kie.workbench.common.screens.examples.service.ExamplesService) Contributor(org.uberfire.security.Contributor) NewWorkspaceProjectUtils(org.guvnor.common.services.project.utils.NewWorkspaceProjectUtils) User(org.jboss.errai.security.shared.api.identity.User) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) OrganizationalUnitAction(org.guvnor.structure.security.OrganizationalUnitAction) UnauthorizedException(org.jboss.errai.security.shared.exception.UnauthorizedException) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) IOService(org.uberfire.io.IOService) ValueIndexTerm(org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueIndexTerm) Collections(java.util.Collections) Branch(org.guvnor.structure.repositories.Branch) 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 3 with AssetInfo

use of org.kie.workbench.common.screens.library.api.AssetInfo 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());
}
Also used : Path(org.uberfire.backend.vfs.Path) RefactoringPageRequest(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ArrayList(java.util.ArrayList) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo) ProjectAssetsQuery(org.kie.workbench.common.screens.library.api.ProjectAssetsQuery) Branch(org.guvnor.structure.repositories.Branch) AssetQueryResult(org.kie.workbench.common.screens.library.api.AssetQueryResult) PageResponse(org.uberfire.paging.PageResponse) RefactoringPageRow(org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow) Test(org.junit.Test)

Example 4 with AssetInfo

use of org.kie.workbench.common.screens.library.api.AssetInfo in project drools-wb by kiegroup.

the class ScenarioSimulationAssetsDropdownProviderTest method getAssetInfoMock.

private AssetInfo getAssetInfoMock() {
    AssetInfo toReturn = mock(AssetInfo.class);
    final FolderItem folderItemMock = getFolderItemMock();
    when(toReturn.getFolderItem()).thenReturn(folderItemMock);
    return toReturn;
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) AssetInfo(org.kie.workbench.common.screens.library.api.AssetInfo)

Aggregations

AssetInfo (org.kie.workbench.common.screens.library.api.AssetInfo)4 FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)3 Path (org.uberfire.backend.vfs.Path)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 Branch (org.guvnor.structure.repositories.Branch)2 AssetQueryResult (org.kie.workbench.common.screens.library.api.AssetQueryResult)2 ProjectAssetsQuery (org.kie.workbench.common.screens.library.api.ProjectAssetsQuery)2 RefactoringPageRequest (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRequest)2 RefactoringPageRow (org.kie.workbench.common.services.refactoring.model.query.RefactoringPageRow)2 NoSuchFileException (org.uberfire.java.nio.file.NoSuchFileException)2 PageResponse (org.uberfire.paging.PageResponse)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1