List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public String[] getJobNames(ObjectId id_directory, boolean includeDeleted) throws KettleException { try {//from w w w . j a v a 2 s . c om List<String> list = new ArrayList<String>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory(id_directory); String folderName = calcDirectoryName(directory); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FILE)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { String name = child.getName().getBaseName(); if (name.endsWith(EXT_JOB)) { String jobName = name.substring(0, name.length() - 4); list.add(jobName); } } } } return list.toArray(new String[list.size()]); } catch (Exception e) { throw new KettleException( "Unable to get list of transformations names in folder with id : " + id_directory, e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
private ObjectId[] getRootObjectIDs(String extension) throws KettleException { try {// w w w. j a v a2s . co m // Get all the files in the root directory with a certain extension... // List<ObjectId> list = new ArrayList<ObjectId>(); String folderName = repositoryMeta.getBaseDirectory(); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FILE)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { String name = child.getName().getBaseName(); if (name.endsWith(extension)) { list.add(new StringObjectId(name)); } } } } return list.toArray(new ObjectId[list.size()]); } catch (Exception e) { throw new KettleException("Unable to get root object ids for extension [" + extension + "]", e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public String[] getTransformationNames(ObjectId id_directory, boolean includeDeleted) throws KettleException { try {/* w ww .j a va 2s. c om*/ List<String> list = new ArrayList<String>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory(id_directory); String folderName = calcDirectoryName(directory); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FILE)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { String name = child.getName().getBaseName(); if (name.endsWith(EXT_TRANSFORMATION)) { String transName = name.substring(0, name.length() - 4); list.add(transName); } } } } return list.toArray(new String[list.size()]); } catch (Exception e) { throw new KettleException( "Unable to get list of transformations names in folder with id : " + id_directory, e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(RepositoryDirectoryInterface dir) throws KettleException { try {/*from ww w .j av a2s . c o m*/ String folderName = calcDirectoryName(dir); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FOLDER)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { if (!".meta".equals(child.getName().getBaseName())) { RepositoryDirectory subDir = new RepositoryDirectory(dir, child.getName().getBaseName()); subDir.setObjectId(new StringObjectId(calcObjectId(subDir))); dir.addSubdirectory(subDir); loadRepositoryDirectoryTree(subDir); } } } } return dir; } catch (Exception e) { throw new KettleException("Unable to load the directory tree from this file repository", e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public List<RepositoryElementMetaInterface> getTransformationObjects(ObjectId idDirectory, boolean includeDeleted) throws KettleException { try {//from w w w. j av a 2 s. co m List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory(idDirectory); String folderName = calcDirectoryName(directory); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FILE)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { String name = child.getName().getBaseName(); if (name.endsWith(EXT_TRANSFORMATION)) { String transName = name.substring(0, name.length() - 4); ObjectId id = new StringObjectId( calcObjectId(directory, transName, EXT_TRANSFORMATION)); Date date = new Date(child.getContent().getLastModifiedTime()); list.add(new RepositoryObject(id, transName, directory, "-", date, RepositoryObjectType.TRANSFORMATION, "", false)); } } } } return list; } catch (Exception e) { throw new KettleException("Unable to get list of transformations in folder with id : " + idDirectory, e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public List<RepositoryElementMetaInterface> getJobObjects(ObjectId id_directory, boolean includeDeleted) throws KettleException { try {/*from w w w. j a v a 2s .c om*/ List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>(); RepositoryDirectoryInterface tree = loadRepositoryDirectoryTree(); RepositoryDirectoryInterface directory = tree.findDirectory(id_directory); String folderName = calcDirectoryName(directory); FileObject folder = KettleVFS.getFileObject(folderName); for (FileObject child : folder.getChildren()) { if (child.getType().equals(FileType.FILE)) { if (!child.isHidden() || !repositoryMeta.isHidingHiddenFiles()) { String name = child.getName().getBaseName(); if (name.endsWith(EXT_JOB)) { String jobName = name.substring(0, name.length() - 4); ObjectId id = new StringObjectId(calcObjectId(directory, jobName, EXT_JOB)); Date date = new Date(child.getContent().getLastModifiedTime()); list.add(new RepositoryObject(id, jobName, directory, "-", date, RepositoryObjectType.JOB, "", false)); } } } } return list; } catch (Exception e) { throw new KettleException("Unable to get list of jobs in folder with id : " + id_directory, e); } }
From source file:org.pentaho.di.repository.filerep.KettleFileRepository.java
public RepositoryObject getObjectInformation(ObjectId objectId, RepositoryObjectType objectType) throws KettleException { try {/*from w ww. j a v a 2s . c om*/ String filename = calcDirectoryName(null); if (objectId.getId().startsWith("/")) { filename += objectId.getId().substring(1); } else { filename += objectId.getId(); } FileObject fileObject = KettleVFS.getFileObject(filename); if (!fileObject.exists()) { return null; } FileName fname = fileObject.getName(); String name = fname.getBaseName(); if (!Const.isEmpty(fname.getExtension()) && name.length() > fname.getExtension().length()) { name = name.substring(0, name.length() - fname.getExtension().length() - 1); } String filePath = fileObject.getParent().getName().getPath(); final FileObject baseDirObject = KettleVFS.getFileObject(repositoryMeta.getBaseDirectory()); final int baseDirObjectPathLength = baseDirObject.getName().getPath().length(); final String dirPath = baseDirObjectPathLength <= filePath.length() ? filePath.substring(baseDirObjectPathLength) : "/"; RepositoryDirectoryInterface directory = loadRepositoryDirectoryTree().findDirectory(dirPath); Date lastModified = new Date(fileObject.getContent().getLastModifiedTime()); return new RepositoryObject(objectId, name, directory, "-", lastModified, objectType, "", false); } catch (Exception e) { throw new KettleException("Unable to get object information for object with id=" + objectId, e); } }
From source file:org.pentaho.di.repository.KettleDatabaseRepositoryTest.java
protected void verifyJobSamples(RepositoryDirectoryInterface samplesDirectory) throws Exception { FileObject jobSamplesFolder = KettleVFS.getFileObject("samples/jobs/"); FileObject[] files = jobSamplesFolder.findFiles(new FileSelector() { @Override/*from ww w.ja v a2 s . c om*/ public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getExtension().equalsIgnoreCase("kjb"); } }); List<FileObject> filesList = Arrays.asList(files); Collections.sort(filesList, new Comparator<FileObject>() { @Override public int compare(FileObject o1, FileObject o2) { return o1.getName().getPath().compareTo(o2.getName().getPath()); } }); for (FileObject file : filesList) { String jobFilename = file.getName().getPath(); System.out.println("Storing/Loading/validating job '" + jobFilename + "'"); // Load the JobMeta object... // JobMeta jobMeta = new JobMeta(jobFilename, repository); if (Const.isEmpty(jobMeta.getName())) { jobMeta.setName(Const.createName(file.getName().getBaseName())); } // Save it in the repository in the samples folder // jobMeta.setRepositoryDirectory(samplesDirectory); repository.save(jobMeta, "unit testing"); assertNotNull(jobMeta.getObjectId()); // Load it back up again... // JobMeta repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String oneXml = repJobMeta.getXML(); // Save & load it again // repository.save(jobMeta, "unit testing"); repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String twoXml = repJobMeta.getXML(); // The XML needs to be identical after loading // // storeFile(oneXml, "/tmp/one.ktr"); // storeFile(twoXml, "/tmp/two.ktr"); // assertEquals(oneXml, twoXml); } // Verify the number of stored files, see if we can find them all again. // System.out.println("Stored " + files.length + " job samples in folder " + samplesDirectory.getPath()); String[] jobNames = repository.getJobNames(samplesDirectory.getObjectId(), false); assertEquals(files.length, jobNames.length); }
From source file:org.pentaho.di.repository.KettleFileRepositoryTest.java
private void verifyJobSamples(RepositoryDirectoryInterface samplesDirectory) throws Exception { FileObject jobSamplesFolder = KettleVFS.getFileObject("samples/jobs/"); FileObject[] files = jobSamplesFolder.findFiles(new FileSelector() { @Override/*from w ww . j a v a 2s . co m*/ public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { return true; } @Override public boolean includeFile(FileSelectInfo info) throws Exception { return info.getFile().getName().getExtension().equalsIgnoreCase("kjb"); } }); List<FileObject> filesList = Arrays.asList(files); Collections.sort(filesList, new Comparator<FileObject>() { @Override public int compare(FileObject o1, FileObject o2) { return o1.getName().getPath().compareTo(o2.getName().getPath()); } }); for (FileObject file : filesList) { String jobFilename = file.getName().getPath(); System.out.println("Storing/Loading/validating job '" + jobFilename + "'"); // Load the JobMeta object... // JobMeta jobMeta = new JobMeta(jobFilename, repository); jobMeta.setFilename(null); // The name is sometimes empty in the file, duplicates are present too... // Replaces slashes and the like as well... // jobMeta.setName(Const.createName(file.getName().getBaseName())); jobMeta.setName(jobMeta.getName().replace('/', '-')); if (Const.isEmpty(jobMeta.getName())) { jobMeta.setName(Const.createName(file.getName().getBaseName())); } if (jobMeta.getName().contains("/")) { jobMeta.setName(jobMeta.getName().replace('/', '-')); } // Save it in the repository in the samples folder // jobMeta.setRepositoryDirectory(samplesDirectory); repository.save(jobMeta, "unit testing"); assertNotNull(jobMeta.getObjectId()); // Load it back up again... // JobMeta repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String oneXml = repJobMeta.getXML(); // Save & load it again // repository.save(jobMeta, "unit testing"); repJobMeta = repository.loadJob(jobMeta.getObjectId(), null); String twoXml = repJobMeta.getXML(); // The XML needs to be identical after loading // // storeFile(oneXml, "/tmp/one.ktr"); // storeFile(twoXml, "/tmp/two.ktr"); // assertEquals(oneXml, twoXml); } // Verify the number of stored files, see if we can find them all again. // System.out.println("Stored " + files.length + " job samples in folder " + samplesDirectory.getPath()); String[] jobNames = repository.getJobNames(samplesDirectory.getObjectId(), false); assertEquals(files.length, jobNames.length); }
From source file:org.pentaho.di.resource.NameResourceTest.java
/** * This tests ResourceNamingInterface.nameResouce(), comparing the directory maps generated by the legacy and new * method./*ww w. j ava 2s.com*/ * * @param fileName * @param pathOnly * Resolve the path - leave out the file name * @throws Exception * * Legacy: namingResource(String, String, String, FileNamingType) New: namingResource(FileObject, TransMeta) */ private void testNamingResourceLegacyAndNew(String fileName, String extension, String fileMask) throws Exception { // Create a new transformation. TransMeta transMeta = new TransMeta(); FileObject fileObject = KettleVFS.getFileObject(fileName, transMeta); // This code is modeled after the legacy code in legacy step meta classes // that have an exportResources method that deal with file masks // e.g., ExcelInputMeta // // There is a big exception: where the legacy code does a "getName()" // this code does a "getURL()". This is because of the JIRA case // that resulted in the refactoring of ResourceNamingInterface. // // The UNC and VFS protocols where being dropped. // The code you see here would be the fix for that without adding // the new nameResource() to ResourceNamingInterface. // String path = null; String prefix = null; if (Const.isEmpty(fileMask)) { prefix = fileObject.getName().getBaseName(); path = fileObject.getParent().getURL().toString(); } else { prefix = ""; path = fileObject.getURL().toString(); } // Create a resource naming interface to use the legacy method call ResourceNamingInterface resourceNamingInterface_LEGACY = new SequenceResourceNaming(); // Create two resource naming interfaces, one for legacy call, the other for new method call ResourceNamingInterface resourceNamingInterface_NEW = new SequenceResourceNaming(); // The old and new interfaces to get the file name. String resolvedFileName_LEGACY = resourceNamingInterface_LEGACY.nameResource(prefix, path, extension, FileNamingType.DATA_FILE); String resolvedFileName_NEW = resourceNamingInterface_NEW.nameResource(fileObject, transMeta, Const.isEmpty(fileMask)); // get the variable name from both naming interfaces directory maps String pathFromMap_LEGACY = resourceNamingInterface_LEGACY.getDirectoryMap().get(path); String pathFromMap_NEW = resourceNamingInterface_NEW.getDirectoryMap().get(path); // The paths in both directories should be the same assertEquals(pathFromMap_LEGACY, pathFromMap_NEW); // The file names should be the same assertEquals(resolvedFileName_LEGACY, resolvedFileName_NEW); }