Search in sources :

Example 91 with RepositoryFile

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);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File)

Example 92 with RepositoryFile

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());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 93 with RepositoryFile

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());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 94 with RepositoryFile

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;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 95 with RepositoryFile

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);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32