Search in sources :

Example 1 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class ZipExportProcessor method exportDirectory.

/**
 * @param repositoryDir
 * @param outputStream
 */
@Override
public void exportDirectory(RepositoryFile repositoryDir, OutputStream outputStream, String filePath) throws ExportException, IOException {
    addToManifest(repositoryDir);
    List<RepositoryFile> children = getUnifiedRepository().getChildren(new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
    for (RepositoryFile repositoryFile : children) {
        // exclude 'etc' folder - datasources and etc.
        if (isExportCandidate(repositoryFile.getPath())) {
            if (repositoryFile.isFolder()) {
                if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
                    ZipOutputStream zos = (ZipOutputStream) outputStream;
                    String zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
                    ZipEntry entry = new ZipEntry(zipEntryName);
                    zos.putNextEntry(entry);
                }
                exportDirectory(repositoryFile, outputStream, filePath);
            } else {
                try {
                    exportFile(repositoryFile, outputStream, filePath);
                } catch (ZipException e) {
                    // possible duplicate entry, log it and continue on with the other files in the directory
                    log.debug(e.getMessage(), e);
                }
            }
        }
    }
    createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) ZipException(java.util.zip.ZipException)

Example 2 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class ZipExportProcessorTest method init.

@Before
public void init() throws IOException, PlatformInitializationException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    List<Locale> availableLocales = java.util.Collections.singletonList(LOCALE_DEFAULT);
    Properties localePropertries = new Properties();
    localePropertries.setProperty("name1", "value1");
    final RepositoryFile file0 = new RepositoryFile.Builder("").path("/").id("/").folder(true).build();
    final RepositoryFile file1 = new RepositoryFile.Builder("home").path("/home/").id("/home/").folder(true).build();
    final RepositoryFile file2 = new RepositoryFile.Builder("test user").path("/home/test user/").id("/home/test user/").folder(true).build();
    final RepositoryFile file3 = new RepositoryFile.Builder("two words").path("/home/test user/two words/").id("/home/test user/two words/").folder(true).build();
    final RepositoryFile fileX = new RepositoryFile.Builder("eval (+)%.prpt").path("/home/test user/two words/eval (+)%.prpt").id("/home/test user/two words/eval (+)%.prpt").folder(false).build();
    final RepositoryFile[] repoFiles = new RepositoryFile[] { file0, file1, file2, file3, fileX };
    final Map<Serializable, RepositoryFile> repoFilesMap = new HashMap<Serializable, RepositoryFile>();
    for (RepositoryFile f : repoFiles) {
        repoFilesMap.put(f.getId(), f);
    }
    repo = mock(IUnifiedRepository.class);
    final Answer<RepositoryFile> answerRepoGetFile = new Answer<RepositoryFile>() {

        @Override
        public RepositoryFile answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            final Object fileId = args[0];
            return getRepoFile(repoFilesMap, fileId);
        }
    };
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFile(anyString(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean());
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), Mockito.anyBoolean(), any(IPentahoLocale.class));
    Mockito.doAnswer(answerRepoGetFile).when(repo).getFileById(any(Serializable.class), any(IPentahoLocale.class));
    Answer<List<RepositoryFile>> answerRepoGetChildren = new Answer<List<RepositoryFile>>() {

        @Override
        public List<RepositoryFile> answer(InvocationOnMock invocation) throws Throwable {
            // returns the following item from <repoFiles>
            RepositoryRequest r = (RepositoryRequest) invocation.getArguments()[0];
            String path = r.getPath();
            RepositoryFile thisFile = getRepoFile(repoFilesMap, path);
            if (thisFile == null || !thisFile.isFolder()) {
                return Collections.emptyList();
            }
            for (int i = 0, n = repoFiles.length - 1; i < n; i++) {
                RepositoryFile iFile = repoFiles[i];
                if (iFile == thisFile || iFile.getId().equals(thisFile.getId())) {
                    return Collections.singletonList(repoFiles[i + 1]);
                }
            }
            return Collections.emptyList();
        }
    };
    Mockito.doAnswer(answerRepoGetChildren).when(repo).getChildren(any(RepositoryRequest.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFile(Mockito.any(RepositoryFile.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileById(Mockito.any(Serializable.class));
    doReturn(availableLocales).when(repo).getAvailableLocalesForFileByPath(Mockito.any(String.class));
    doReturn(localePropertries).when(repo).getLocalePropertiesForFileById(Mockito.any(File.class), Mockito.anyString());
    RepositoryFileSid sid = mock(RepositoryFileSid.class);
    doReturn("testUser").when(sid).getName();
    doReturn(Type.USER).when(sid).getType();
    final RepositoryFileAcl mockAcl = mock(RepositoryFileAcl.class);
    doReturn(sid).when(mockAcl).getOwner();
    doReturn(mockAcl).when(repo).getAcl(any(Serializable.class));
    Answer<IRepositoryFileData> answerGetDataForRead = new Answer<IRepositoryFileData>() {

        @Override
        public IRepositoryFileData answer(InvocationOnMock invocation) throws Throwable {
            Serializable id = (Serializable) invocation.getArguments()[0];
            RepositoryFile file = getRepoFile(repoFilesMap, id);
            if (!file.isFolder()) {
                return new SimpleRepositoryFileData(new ByteArrayInputStream(new byte[0]), "UTF-8", MIME_PRPT.getName());
            }
            return null;
        }
    };
    doAnswer(answerGetDataForRead).when(repo).getDataForRead(Mockito.any(Serializable.class), Mockito.any(Class.class));
    exportHandler = new DefaultExportHandler();
    defaultConverter = new StreamConverter(repo);
    PentahoSystem.clearObjectFactory();
    microPlatform = new MicroPlatform(getSolutionPath());
    microPlatform.defineInstance(IUnifiedRepository.class, repo);
    // microPlatform.defineInstance( IPlatformMimeResolver.class, mimeResolver );
    microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
    microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
    microPlatform.start();
    exportSession = new StandaloneSession();
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    PentahoSessionHolder.setSession(exportSession);
}
Also used : Locale(java.util.Locale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) SolutionEngine(org.pentaho.platform.engine.services.solution.SolutionEngine) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

Example 3 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method getTree.

/**
 * {@inheritDoc}
 */
@Override
@Deprecated
public RepositoryFileTree getTree(final String relPath, final int depth, final String filter, final boolean showHidden) {
    Assert.hasText(relPath);
    final RepositoryRequest repositoryRequest = new RepositoryRequest(relPath, showHidden, depth, filter);
    return (RepositoryFileTree) jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            String absPath = pathConversionHelper.relToAbs(relPath);
            return JcrRepositoryFileUtils.getTree(session, pentahoJcrConstants, pathConversionHelper, lockHelper, absPath, repositoryRequest, accessVoterManager);
        }
    });
}
Also used : RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) Session(javax.jcr.Session)

Example 4 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method getChildren.

@Override
public List<RepositoryFile> getChildren(RepositoryRequest repositoryRequest) {
    List<RepositoryFile> children = new ArrayList<RepositoryFile>();
    File folder = new File(getPhysicalFileLocation(repositoryRequest.getPath()));
    for (Iterator<File> iterator = FileUtils.listFiles(folder, new WildcardFileFilter(repositoryRequest.getChildNodeFilter()), null).iterator(); iterator.hasNext(); ) {
        children.add(internalGetFile((File) iterator.next()));
    }
    return children;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Example 5 with RepositoryRequest

use of org.pentaho.platform.api.repository2.unified.RepositoryRequest in project pentaho-platform by pentaho.

the class FileService method doGetChildren.

public List<RepositoryFileDto> doGetChildren(String pathId, String filter, Boolean showHidden, Boolean includeAcls) {
    List<RepositoryFileDto> repositoryFileDtoList = new ArrayList<RepositoryFileDto>();
    RepositoryFileDto repositoryFileDto = getRepoWs().getFile(FileUtils.idToPath(pathId));
    if (repositoryFileDto != null && isPathValid(repositoryFileDto.getPath())) {
        RepositoryRequest repositoryRequest = getRepositoryRequest(repositoryFileDto, showHidden, filter, includeAcls);
        repositoryFileDtoList = getRepoWs().getChildrenFromRequest(repositoryRequest);
        // BISERVER-9599 - Use special sort order
        if (isShowingTitle(repositoryRequest)) {
            Collator collator = getCollator(Collator.PRIMARY);
            sortByLocaleTitle(collator, repositoryFileDtoList);
        }
    }
    return repositoryFileDtoList;
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator)

Aggregations

RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)19 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)8 ITenant (org.pentaho.platform.api.mt.ITenant)7 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Collator (java.text.Collator)4 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)4 File (java.io.File)3 Serializable (java.io.Serializable)3 ObjectId (org.pentaho.di.repository.ObjectId)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2