Search in sources :

Example 26 with FolderItem

use of org.kie.workbench.common.screens.explorer.model.FolderItem in project kie-wb-common by kiegroup.

the class BaseBreadcrumbNavigatorTest method testLoadContentEmpty.

@Test
public void testLoadContentEmpty() {
    final BreadcrumbNavigator navigator = spy(new BreadcrumbNavigator(activeOptions, hiddenTypeDef, user));
    final FolderItem item = new FolderItem(path, "item1", FolderItemType.FILE);
    final List<FolderItem> content = new ArrayList<FolderItem>();
    final List<FolderItem> segments = new ArrayList<FolderItem>();
    final FolderListing listing = new FolderListing(item, content, segments);
    navigator.loadContent(listing);
    verify(navigator).setupBreadcrumb(listing);
    verify(navigator).setupUpFolder(listing);
    verify(navigator).setupContent(listing);
    verifyNavigatorPanelVisibility(navigator);
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) Test(org.junit.Test)

Example 27 with FolderItem

use of org.kie.workbench.common.screens.explorer.model.FolderItem 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 28 with FolderItem

use of org.kie.workbench.common.screens.explorer.model.FolderItem in project kie-wb-common by kiegroup.

the class ExplorerServiceHelper method getPackageSegments.

public List<FolderItem> getPackageSegments(final Package _pkg) {
    List<FolderItem> result = new ArrayList<FolderItem>();
    Package pkg = _pkg;
    while (pkg != null) {
        final Package parent = moduleService.resolveParentPackage(pkg);
        if (parent != null) {
            result.add(toFolderItem(parent));
        }
        pkg = parent;
    }
    return Lists.reverse(result);
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package)

Example 29 with FolderItem

use of org.kie.workbench.common.screens.explorer.model.FolderItem in project kie-wb-common by kiegroup.

the class ExplorerServiceHelper method getFolderListing.

public FolderListing getFolderListing(final Path path, final ActiveOptions options) {
    // Get list of files and folders contained in the path
    final List<FolderItem> folderItems = new ArrayList<FolderItem>();
    final boolean includeTags = options.contains(Option.SHOW_TAG_FILTER);
    // Scan upwards until the path exists (as the current path could have been deleted)
    org.uberfire.java.nio.file.Path nioPath = Paths.convert(path);
    while (!Files.exists(nioPath)) {
        nioPath = nioPath.getParent();
    }
    final Path basePath = Paths.convert(nioPath);
    final DirectoryStream<org.uberfire.java.nio.file.Path> nioPaths = ioService.newDirectoryStream(nioPath, dotFileFilter);
    for (org.uberfire.java.nio.file.Path np : nioPaths) {
        if (Files.isRegularFile(np)) {
            final org.uberfire.backend.vfs.Path p = Paths.convert(np);
            final String lockedBy = Paths.readLockedBy(p);
            final FolderItem folderItem = new FolderItem(p, p.getFileName(), FolderItemType.FILE, false, lockedBy, includeTags ? metadataService.getTags(p) : Collections.<String>emptyList(), getRestrictedOperations(p));
            folderItems.add(folderItem);
        } else if (Files.isDirectory(np)) {
            final org.uberfire.backend.vfs.Path p = Paths.convert(np);
            boolean lockedItems = !lockService.retrieveLockInfos(Paths.convert(np), true).isEmpty();
            final FolderItem folderItem = new FolderItem(p, p.getFileName(), FolderItemType.FOLDER, lockedItems, null, Collections.<String>emptyList(), getRestrictedOperations(p));
            folderItems.add(folderItem);
        }
    }
    Collections.sort(folderItems, Sorters.ITEM_SORTER);
    return new FolderListing(toFolderItem(nioPath), folderItems, getPathSegments(basePath));
}
Also used : Path(org.uberfire.backend.vfs.Path) ArrayList(java.util.ArrayList) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) Path(org.uberfire.backend.vfs.Path)

Example 30 with FolderItem

use of org.kie.workbench.common.screens.explorer.model.FolderItem in project kie-wb-common by kiegroup.

the class ExplorerServiceHelper method getItems.

public List<FolderItem> getItems(final Package pkg, final ActiveOptions options) {
    final List<FolderItem> folderItems = new ArrayList<FolderItem>();
    if (pkg == null) {
        return emptyList();
    }
    final Set<Package> childPackages = moduleService.resolvePackages(pkg);
    for (final Package childPackage : childPackages) {
        folderItems.add(toFolderItem(childPackage));
    }
    folderItems.addAll(getItems(pkg.getPackageMainSrcPath(), options));
    folderItems.addAll(getItems(pkg.getPackageTestSrcPath(), options));
    folderItems.addAll(getItems(pkg.getPackageMainResourcesPath(), options));
    folderItems.addAll(getItems(pkg.getPackageTestResourcesPath(), options));
    Collections.sort(folderItems, Sorters.ITEM_SORTER);
    return folderItems;
}
Also used : FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package)

Aggregations

FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)31 ArrayList (java.util.ArrayList)15 Path (org.uberfire.backend.vfs.Path)14 Test (org.junit.Test)13 Package (org.guvnor.common.services.project.model.Package)8 FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)8 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)5 List (java.util.List)4 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Module (org.guvnor.common.services.project.model.Module)3 FolderItemType (org.kie.workbench.common.screens.explorer.model.FolderItemType)3 ClientResourceType (org.uberfire.client.workbench.type.ClientResourceType)3 Window (com.google.gwt.user.client.Window)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 PostConstruct (javax.annotation.PostConstruct)2 Event (javax.enterprise.event.Event)2