private List<CatalogItem> getNamespaceChildrenForPath(NamespaceKey path) { final List<CatalogItem> catalogItems = new ArrayList<>(); try { final List<NameSpaceContainer> list = namespaceService.list(path); for (NameSpaceContainer container : list) { final Optional<CatalogItem> item = CatalogItem.fromNamespaceContainer(container); if (item.isPresent()) { catalogItems.add(item.get()); } } } catch (NamespaceException e) { logger.warn(e.getMessage()); } return catalogItems; }
@GET @Path("/folder/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public Folder getFolder(@PathParam("path") String path, @QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws Exception { FolderPath folderPath = FolderPath.fromURLPath(homeName, path); try { final FolderConfig folderConfig = namespaceService.getFolder(folderPath.toNamespaceKey()); final NamespaceTree contents = includeContents ? newNamespaceTree(namespaceService.list(folderPath.toNamespaceKey())) : null; return newFolder(folderPath, folderConfig, contents); } catch (NamespaceNotFoundException nfe) { throw new FolderNotFoundException(folderPath, nfe); } }
public List<ResourceTreeEntity> listPath(NamespaceKey root, boolean showDatasets) throws NamespaceException, UnsupportedEncodingException { final List<ResourceTreeEntity> resources = Lists.newArrayList(); for (NameSpaceContainer container : namespaceService.get().list(root)) { if (container.getType() == Type.FOLDER) { resources.add(new ResourceTreeEntity(container.getFolder())); } else if (showDatasets && container.getType() == Type.DATASET) { resources.add(new ResourceTreeEntity(container.getDataset())); } } return resources; }
@GET @Path("/folder/{path: .*}") @Produces(MediaType.APPLICATION_JSON) public Folder getFolder(@PathParam("path") String path, @QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws NamespaceException, FolderNotFoundException, DatasetNotFoundException { FolderPath folderPath = FolderPath.fromURLPath(spaceName, path); try { final FolderConfig folderConfig = namespaceService.getFolder(folderPath.toNamespaceKey()); final NamespaceTree contents = includeContents ? newNamespaceTree(namespaceService.list(folderPath.toNamespaceKey())) : null; return newFolder(folderPath, folderConfig, contents); } catch (NamespaceNotFoundException nfe) { throw new FolderNotFoundException(folderPath, nfe); } }
public static Map<String, NameSpaceContainer> listHome(NamespaceService ns, String parent) throws Exception { Map<String, NameSpaceContainer> children = new HashMap<>(); for (NameSpaceContainer container : ns.list(new NamespaceKey(parent))) { children.put(PathUtils.constructFullPath(container.getFullPathList()), container); } return children; }
for(NameSpaceContainer entity : ns.list(folderNSKey)) { if (entity.getType() == Type.DATASET) { tableNames.add(resolveTableNameToValidPath(entity.getDataset().getFullPathList()));
@GET @Produces(MediaType.APPLICATION_JSON) public Space getSpace(@QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws Exception { try { final SpaceConfig config = namespaceService.getSpace(spacePath.toNamespaceKey()); final int datasetCount = namespaceService.getDatasetCount(spacePath.toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount(); NamespaceTree contents = includeContents ? newNamespaceTree(namespaceService.list(spacePath.toNamespaceKey())) : null; final Space space = newSpace(config, contents, datasetCount); return space; } catch (NamespaceNotFoundException nfe) { throw new SpaceNotFoundException(spacePath.getSpaceName().getName(), nfe); } }
public NamespaceTree listSource(SourceName sourceName, SourceConfig sourceConfig, String userName) throws IOException, PhysicalDatasetNotFoundException, NamespaceException { try { final StoragePlugin plugin = checkNotNull(catalogService.getSource(sourceName.getName()), "storage plugin %s not found", sourceName); if (plugin instanceof FileSystemPlugin) { final NamespaceTree ns = new NamespaceTree(); addToNamespaceTree(ns, ((FileSystemPlugin) plugin).list(singletonList(sourceName.getName()), userName), sourceName, sourceName.getName()); fillInTags(ns); return ns; } else { return newNamespaceTree(namespaceService.list(new NamespaceKey(singletonList(sourceConfig.getName())))); } } catch (IOException | DatasetNotFoundException e) { throw new RuntimeException(e); } }
@GET @Produces(MediaType.APPLICATION_JSON) public Home getHome(@QueryParam("includeContents") @DefaultValue("true") boolean includeContents) throws NamespaceException, HomeNotFoundException, DatasetNotFoundException { try { long dsCount = namespaceService.getDatasetCount(homePath.toNamespaceKey(), BoundedDatasetCount.SEARCH_TIME_LIMIT_MS, BoundedDatasetCount.COUNT_LIMIT_TO_STOP_SEARCH).getCount(); final HomeConfig homeConfig = namespaceService.getHome(homePath.toNamespaceKey()).setExtendedConfig(new ExtendedConfig().setDatasetCount(dsCount)); Home home = newHome(homePath, homeConfig); if (includeContents) { home.setContents(newNamespaceTree(namespaceService.list(homePath.toNamespaceKey()))); } return home; } catch (NamespaceNotFoundException nfe) { throw new HomeNotFoundException(homePath.getHomeName(), nfe); } }
public static Map<String, NameSpaceContainer> listFolder(NamespaceService ns, String parent) throws Exception { Map<String, NameSpaceContainer> children = new HashMap<>(); for (NameSpaceContainer container : ns.list(new NamespaceKey(PathUtils.parseFullPath(parent)))) { children.put(PathUtils.constructFullPath(container.getFullPathList()), container); } return children; }
/** * Fetches a single item from the filesystem plugin */ public SchemaEntity get(List<String> path, String userName) { try { final FileStatus status = getFS(userName).getFileStatus(PathUtils.toFSPath(resolveTableNameToValidPath(path))); final Set<List<String>> tableNames = Sets.newHashSet(); final NamespaceService ns = context.getNamespaceService(userName); final NamespaceKey folderNSKey = new NamespaceKey(path); if (ns.exists(folderNSKey)) { for(NameSpaceContainer entity : ns.list(folderNSKey)) { if (entity.getType() == Type.DATASET) { tableNames.add(resolveTableNameToValidPath(entity.getDataset().getFullPathList())); } } } List<String> p = PathUtils.toPathComponents(status.getPath()); return getSchemaEntity(status, tableNames, p); } catch (IOException | NamespaceException e) { throw new RuntimeException(e); } }
public NamespaceTree listFolder(SourceName sourceName, SourceFolderPath folderPath, String userName) throws IOException, PhysicalDatasetNotFoundException, NamespaceException { final String name = sourceName.getName(); final String prefix = folderPath.toPathString(); try { final StoragePlugin plugin = checkNotNull(catalogService.getSource(name), "storage plugin %s not found", sourceName); if (plugin instanceof FileSystemPlugin) { final NamespaceTree ns = new NamespaceTree(); addToNamespaceTree(ns, ((FileSystemPlugin) plugin).list(folderPath.toPathList(), userName), sourceName, prefix); fillInTags(ns); return ns; } else { return newNamespaceTree(namespaceService.list(folderPath.toNamespaceKey())); } } catch (IOException | DatasetNotFoundException e) { throw new RuntimeException(e); } }
@Test public void testGetSpaceCatalogEntityById() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setId(new EntityId("space-id")); spaceConfig.setName("mySpace"); NameSpaceContainer namespaceContainer = new NameSpaceContainer(); namespaceContainer.setType(NameSpaceContainer.Type.SPACE); namespaceContainer.setSpace(spaceConfig); when(namespaceService.getEntityById(spaceConfig.getId().getId())).thenReturn(namespaceContainer); when(namespaceService.getEntities(Collections.singletonList(new NamespaceKey(spaceConfig.getName())))).thenReturn(Collections.singletonList(namespaceContainer)); // for children listing, we just send the space back to keep it simple when(namespaceService.list(new NamespaceKey(spaceConfig.getName()))).thenReturn(Collections.singletonList(namespaceContainer)); Optional<CatalogEntity> catalogEntityById = catalogServiceHelper.getCatalogEntityById(spaceConfig.getId().getId()); assertTrue(catalogEntityById.isPresent()); CatalogEntity catalogEntity = catalogEntityById.get(); assertTrue(catalogEntity instanceof Space); Space space = (Space) catalogEntity; assertEquals(space.getId(), spaceConfig.getId().getId()); assertEquals(space.getChildren().size(), 1); }
assertEquals(0, namespaceService.list(new NamespaceKey("src1")).size());