use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class ZipSolutionRepositoryImportSource method initialize.
/**
* Initializes the ImportSource - it will read the zip input stream and create the list of files
*/
protected void initialize() throws org.pentaho.platform.plugin.services.importexport.InitializationException {
try {
ZipEntry entry = zipInputStream.getNextEntry();
while (entry != null) {
final String entryName = RepositoryFilenameUtils.separatorsToRepository(entry.getName());
final String extension = RepositoryFilenameUtils.getExtension(entryName);
File tempFile = null;
boolean isDir = entry.getSize() == 0;
if (!isDir) {
tempFile = File.createTempFile("zip", null);
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
IOUtils.copy(zipInputStream, fos);
fos.close();
}
File file = new File(entryName);
RepositoryFile repoFile = new RepositoryFile.Builder(file.getName()).folder(isDir).hidden(false).build();
String parentDir = new File(entryName).getParent() == null ? "/" : new File(entryName).getParent() + "/";
org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle repoFileBundle = new org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle(repoFile, null, parentDir, tempFile, charSet, getMimeType(extension.toLowerCase()));
files.add(repoFileBundle);
zipInputStream.closeEntry();
entry = zipInputStream.getNextEntry();
}
zipInputStream.close();
} catch (IOException exception) {
// TODO I18N
final String errorMessage = Messages.getInstance().getErrorString("", exception.getLocalizedMessage());
throw new org.pentaho.platform.plugin.services.importexport.InitializationException(errorMessage, exception);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class CopyFilesOperation_CopyTest method copyFiles_OverwriteMode.
@Test
public void copyFiles_OverwriteMode() {
CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(file1, file2), PATH_DEST_DIR, FileService.MODE_OVERWRITE);
// emulate, file with the same name exists.
RepositoryFile conflictFile = mockFile(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_FILE_1);
operation = spy(operation);
RepositoryFileDto fileDto = mock(RepositoryFileDto.class);
doReturn(conflictFile).when(operation).toFile(fileDto);
doReturn(fileDto).when(operation).toFileDto(eq(conflictFile), anySet(), anyBoolean());
doReturn(conflictFile).when(repo).updateFile(eq(conflictFile), any(IRepositoryFileData.class), anyString());
operation.execute();
verify(repo).updateFile(eq(conflictFile), any(IRepositoryFileData.class), anyString());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class CopyFilesOperation_CopyTest method copyFolders_RenameMode.
@Test
public void copyFolders_RenameMode() {
CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(folder1, folder2), PATH_DEST_DIR, FileService.MODE_RENAME);
// emulate, file with the same name exists.
RepositoryFile conflict = mockFolder(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_DIR_2);
String conflictFolderPath = conflict.getPath();
RepositoryFileDto dtoConflictFolder = mock(RepositoryFileDto.class);
doReturn(dtoConflictFolder).when(webService).getFile(eq(conflictFolderPath));
operation = spy(operation);
operation.execute();
verify(repo, times(2)).createFolder(eq(destFolder.getId()), any(RepositoryFile.class), any(RepositoryFileAcl.class), anyString());
verify(operation, times(2)).performFolderDeepCopy(any(RepositoryFile.class), any(RepositoryFile.class), anyInt());
verify(repo, never()).createFile(any(Serializable.class), any(RepositoryFile.class), any(IRepositoryFileData.class), any(RepositoryFileAcl.class), anyString());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class CopyFilesOperation_DeepFolderCopyTest method mockFile.
public static RepositoryFile mockFile(String id) {
RepositoryFile file = mock(RepositoryFile.class);
doReturn(id).when(file).getId();
doReturn(false).when(file).isFolder();
return file;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFile in project pentaho-platform by pentaho.
the class FileServiceTest method testDoRename.
@Test
public void testDoRename() throws Exception {
RepositoryFile repositoryFile = mock(RepositoryFile.class);
when(repositoryFile.getPath()).thenReturn("/dir/file.txt");
when(repositoryFile.getName()).thenReturn("file.txt");
when(fileService.repository.getFile(anyString())).thenReturn(repositoryFile);
when(fileService.repository.getFileById(anyString())).thenReturn(repositoryFile);
String pathId = ":dir:file.txt";
String newName = "file1.txt";
boolean success = fileService.doRename(pathId, newName);
assertTrue(success);
}
Aggregations