use of org.pentaho.platform.dataaccess.datasource.wizard.models.FileInfo in project data-access by pentaho.
the class FileUtilsTest method testDeleteFile.
@Test
public void testDeleteFile() {
FileUtils fu = new FileUtils();
String testUniqueFileName = "testFileToDelete-" + System.currentTimeMillis();
File testUniqueFile = new File(fu.getRelativeSolutionPath() + File.separatorChar + testUniqueFileName);
try {
testUniqueFile.createNewFile();
} catch (IOException ioe) {
fail("File creation failed");
}
// Make sure the file got deleted
if (!testUniqueFile.exists()) {
fail("File could not be created");
}
FileInfo[] files = fu.listFiles();
if (files != null && files.length > 0) {
fu.deleteFile(testUniqueFileName);
FileInfo[] files1 = fu.listFiles();
System.err.println("File1 length " + files1.length);
System.err.println("Files length " + files.length);
try {
assertTrue(files1.length < files.length);
} finally {
for (FileInfo file : files1) {
if (file.getName().contains(testUniqueFileName)) {
testUniqueFile.deleteOnExit();
fail("File should have been deleted. We will delete the file ourselves");
}
}
}
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.models.FileInfo in project data-access by pentaho.
the class CsvDatasourceServiceImplTest method testHasPermissions.
@Test
public void testHasPermissions() throws Exception {
hasPermissions = true;
final ISystemSettings systemSettings = mock(ISystemSettings.class);
when(systemSettings.getSystemSetting("data-access-override", "false")).thenReturn("false");
PentahoSystem.setSystemSettingsService(systemSettings);
String filename = "anotherStageFile_CsvFile.csv";
File file = createTmpCsvFile(filename);
file.deleteOnExit();
try {
ModelInfo modelInfo = service.stageFile(filename, ",", "\n", true, "utf-8");
CsvFileInfo fileInfo = modelInfo.getFileInfo();
assertEquals("One header row", 1, fileInfo.getHeaderRows());
assertEquals("Header + content row", 2, fileInfo.getContents().size());
assertEquals(filename, fileInfo.getTmpFilename());
final FileInfo[] stagedFiles = service.getStagedFiles();
assertNotNull(stagedFiles);
boolean present = false;
for (FileInfo info : stagedFiles) {
if (filename.equals(info.getName())) {
present = true;
break;
}
}
assertTrue(present);
final String encoding = service.getEncoding(filename);
assertNotNull(encoding);
final List<String> previewRows = service.getPreviewRows(filename, true, 1, "utf-8");
assertNotNull(previewRows);
assertEquals(1, previewRows.size());
assertEquals("col1,col2", previewRows.get(0));
final DatasourceDTO datasourceDto = mock(DatasourceDTO.class);
when(datasourceDto.getCsvModelInfo()).thenReturn(modelInfo);
try {
final FileTransformStats fileTransformStats = service.generateDomain(datasourceDto);
} catch (Exception e) {
// Testing this logic is not a purpose of this junit
}
// Passed permissions check
verify(datasourceDto, times(1)).getCsvModelInfo();
} finally {
file.delete();
}
}
use of org.pentaho.platform.dataaccess.datasource.wizard.models.FileInfo in project data-access by pentaho.
the class CsvDatasourceServiceImpl method getStagedFiles.
public FileInfo[] getStagedFiles() throws Exception {
checkPermissions();
FileInfo[] files;
try {
FileUtils fileService = new FileUtils();
files = fileService.listFiles();
} catch (Exception e) {
logger.error(e);
throw e;
}
return files;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.models.FileInfo in project data-access by pentaho.
the class FileUtils method listFiles.
public FileInfo[] listFiles() {
List<FileInfo> fileList = new ArrayList<FileInfo>();
String path = getRelativeSolutionPath();
File folder = new File(path);
if (folder.exists()) {
File[] files = folder.listFiles();
for (File file : files) {
String name = file.getName();
if (file.isFile()) {
long lastModified = file.lastModified();
DateFormat fmt = LocaleHelper.getShortDateFormat(true, true);
Date modified = new Date();
modified.setTime(lastModified);
String modifiedStr = fmt.format(modified);
long size = file.length();
FileInfo info = new FileInfo();
info.setModified(modifiedStr);
info.setName(name);
info.setSize(size);
fileList.add(info);
}
}
}
return fileList.toArray(new FileInfo[fileList.size()]);
}
Aggregations