protected Folder createFolder(Folder folder, NamespaceAttribute... attributes) throws NamespaceException { NamespaceKey parentKey = new NamespaceKey(folder.getPath().subList(0, folder.getPath().size() - 1)); List<NameSpaceContainer> entities = namespaceService.getEntities(Collections.singletonList(parentKey)); NameSpaceContainer container = entities.get(0); if (container == null) { // if we can't find it by id, maybe its not in the namespace throw new IllegalArgumentException(String.format("Could not find entity with path [%s].", folder.getPath())); } NamespaceKey key = new NamespaceKey(folder.getPath()); switch (container.getType()) { case SPACE: case HOME: case FOLDER: { namespaceService.addOrUpdateFolder(key, getFolderConfig(folder), attributes); break; } default: { throw new UnsupportedOperationException(String.format("Can not create a folder inside a [%s].", container.getType())); } } return getFolderFromConfig(namespaceService.getFolder(key), null); }
@POST @Path("/folder/{path: .*}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Folder createFolder(FolderName name, @PathParam("path") String path) throws Exception { String fullPath = PathUtils.toFSPathString(Arrays.asList(path, name.toString())); FolderPath folderPath = FolderPath.fromURLPath(homeName, fullPath); final FolderConfig folderConfig = new FolderConfig(); folderConfig.setFullPathList(folderPath.toPathList()); folderConfig.setName(folderPath.getFolderName().getName()); try { namespaceService.addOrUpdateFolder(folderPath.toNamespaceKey(), folderConfig); } catch(NamespaceNotFoundException nfe) { throw new ClientErrorException("Parent folder doesn't exist", nfe); } return newFolder(folderPath, folderConfig, null); }
@POST @Path("/folder/{path: .*}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Folder createFolder(FolderName name, @PathParam("path") String path) throws NamespaceException { String fullPath = PathUtils.toFSPathString(Arrays.asList(path, name.toString())); FolderPath folderPath = FolderPath.fromURLPath(spaceName, fullPath); final FolderConfig folderConfig = new FolderConfig(); folderConfig.setFullPathList(folderPath.toPathList()); folderConfig.setName(folderPath.getFolderName().getName()); try { namespaceService.addOrUpdateFolder(folderPath.toNamespaceKey(), folderConfig); } catch(NamespaceNotFoundException nfe) { throw new ClientErrorException("Parent folder doesn't exist", nfe); } return newFolder(folderPath, folderConfig, null); }
protected void updateFolder(Folder folder, NamespaceAttribute... attributes) throws NamespaceException { NamespaceKey namespaceKey = new NamespaceKey(folder.getPath()); FolderConfig folderConfig = namespaceService.getFolder(namespaceKey); Preconditions.checkArgument(CollectionUtils.isEqualCollection(folder.getPath(), folderConfig.getFullPathList()), "Folder path is immutable."); NameSpaceContainer rootContainer = getRootContainer(folder.getPath()); if (rootContainer.getType() == NameSpaceContainer.Type.SOURCE) { throw new UnsupportedOperationException("Can not update a folder inside a source"); } namespaceService.addOrUpdateFolder(namespaceKey, getFolderConfig(folder), attributes); }
public static void addFolder(NamespaceService ns, String name) throws Exception { final FolderConfig folder = new FolderConfig(); final NamespaceKey folderPath = new NamespaceKey(PathUtils.parseFullPath(name)); folder.setName(folderPath.getName()); folder.setFullPathList(folderPath.getPathComponents()); ns.addOrUpdateFolder(folderPath, folder); }
protected void setSpace() throws NamespaceException, IOException { clearAllDataExceptUser(); final SpaceConfig foo = new SpaceConfig().setName("spacefoo"); SpacePath spacePath = new SpacePath(new SpaceName(foo.getName())); newNamespaceService().addOrUpdateSpace(spacePath.toNamespaceKey(), foo); newNamespaceService().addOrUpdateFolder(new FolderPath("spacefoo.folderbar").toNamespaceKey(), new FolderConfig().setName("folderbar").setFullPathList(asList("spacefoo", "folderbar"))); newNamespaceService().addOrUpdateFolder(new FolderPath("spacefoo.folderbar.folderbaz").toNamespaceKey(), new FolderConfig().setName("folderbaz").setFullPathList(asList("spacefoo", "folderbar", "folderbaz"))); }
private static void runTests(HomeFileConf homeFileStore) throws Exception { // text file Path textFile = new Path(FileUtils.getResourceAsFile("/datasets/text/comma.txt").getAbsolutePath()); uploadFile(homeFileStore, textFile, "comma", "txt", new TextFileConfig().setFieldDelimiter(","), null); Path csvFile = new Path(FileUtils.getResourceAsFile("/datasets/csv/comma.csv").getAbsolutePath()); uploadFile(homeFileStore, csvFile, "comma1", "csv", new TextFileConfig().setFieldDelimiter(","), null); Path jsonFile = new Path(FileUtils.getResourceAsFile("/datasets/users.json").getAbsolutePath()); uploadFile(homeFileStore, jsonFile, "users", "json", new JsonFileConfig(), null); Path excelFile = new Path(FileUtils.getResourceAsFile("/testfiles/excel.xlsx").getAbsolutePath()); uploadFile(homeFileStore, excelFile, "excel", "xlsx", new ExcelFileConfig(), null); // query files runQuery("comma", 4, 3, null); runQuery("comma1", 4, 3, null); runQuery("users", 3, 2, null); runQuery("excel", 6, 5, null); // add file to folder FolderPath folderPath = new FolderPath(ImmutableList.of(HomeName.getUserHomePath(DEFAULT_USER_NAME).getName(), "testupload")); newNamespaceService().addOrUpdateFolder(folderPath.toNamespaceKey(), new FolderConfig() .setName("testupload") .setFullPathList(folderPath.toPathList())); uploadFile(homeFileStore, textFile, "comma", "txt", new TextFileConfig().setFieldDelimiter(","), folderPath); runQuery("comma", 4, 3, folderPath); }
public void addCPSource(boolean createFolder) throws Exception { getSourceService().registerSourceWithRuntime(InternalFileConf.create(TEST_SOURCE, new URI("classpath:///acceleration/"), SchemaMutability.ALL, CatalogService.DEFAULT_METADATA_POLICY)); final NamespaceService nsService = getNamespaceService(); final SpaceConfig config = new SpaceConfig().setName(TEST_SPACE); if(!nsService.exists(new SpacePath(config.getName()).toNamespaceKey())) { nsService.addOrUpdateSpace(new SpacePath(config.getName()).toNamespaceKey(), config); } if (createFolder) { final FolderConfig folderConfig = new FolderConfig().setName(TEST_FOLDER); nsService.addOrUpdateFolder(TEST_FOLDER_PATH.toNamespaceKey(), folderConfig); } }
@Test public void testDownloadWithRelativeDatasetPath() throws Exception { SpaceConfig spaceConfig = new SpaceConfig(); spaceConfig.setName("mySpace"); newNamespaceService().addOrUpdateSpace(new NamespaceKey("mySpace"), spaceConfig); FolderConfig folderConfig = new FolderConfig(); List<String> path = Arrays.asList("mySpace", "folder"); folderConfig.setFullPathList(path); folderConfig.setName("folder"); newNamespaceService().addOrUpdateFolder(new NamespaceKey(path), folderConfig); final DatasetPath dsPath = new DatasetPath("mySpace.folder.testVDS"); DatasetUI ds = createDatasetFromSQLAndSave(dsPath,"select * from DG.dsg1 LIMIT 10", asList("cp")); final DatasetPath dsPath2 = new DatasetPath("mySpace.folder.testVDS2"); DatasetUI ds2 = createDatasetFromSQLAndSave(dsPath2,"select * from testVDS", path); Job job = datasetService.prepareDownload(dsPath2, ds2.getDatasetVersion(), DownloadFormat.CSV, 50, SampleDataPopulator.DEFAULT_USER_NAME); job.getData().loadIfNecessary(); DownloadDataResponse downloadDataResponse = datasetService.downloadData(job.getJobAttempt().getInfo().getDownloadInfo(), SampleDataPopulator.DEFAULT_USER_NAME); final List<TestData> downloadedData = readDataCsv(downloadDataResponse.getInput()); assertEquals(10, downloadedData.size()); for (int i = 0; i < 10; ++i) { assertEquals("user" + i, downloadedData.get(i).getUser()); assertEquals(i%25, downloadedData.get(i).getAge()); assertEquals("address" + i, downloadedData.get(i).getAddress()); } }