Search in sources :

Example 91 with IUnifiedRepository

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

the class MondrianCatalogHelper method appendCatalogsSection.

@VisibleForTesting
protected void appendCatalogsSection(IUnifiedRepository unifiedRepository, String etcMondrian, RepositoryFile etcMondrianFolder, StringBuffer datasourcesXML) {
    // $NON-NLS-1$
    datasourcesXML.append("<Catalogs>\n");
    // Creates <Catalogs> from the "/etc/mondrian/<catalog>/metadata" nodes.
    /*
       * IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); String tenantEtcFolder = null;
       * if(pentahoSession != null) { String tenantId = (String)
       * pentahoSession.getAttribute(IPentahoSession.TENANT_ID_KEY); tenantEtcFolder =
       * ServerRepositoryPaths.getTenantEtcFolderPath(tenantId); } else { tenantEtcFolder =
       * ServerRepositoryPaths.getTenantEtcFolderPath(); }
       */
    List<RepositoryFile> mondrianCatalogs = unifiedRepository.getChildren(etcMondrianFolder.getId());
    for (RepositoryFile catalog : mondrianCatalogs) {
        String catalogName = catalog.getName();
        RepositoryFile metadata = unifiedRepository.getFile(etcMondrian + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR + // $NON-NLS-1$
        "metadata");
        if (metadata != null) {
            DataNode metadataNode = unifiedRepository.getDataForRead(metadata.getId(), NodeRepositoryFileData.class).getNode();
            // $NON-NLS-1$
            String datasourceInfo = metadataNode.getProperty("datasourceInfo").getString();
            // $NON-NLS-1$
            String definition = metadataNode.getProperty("definition").getString();
            datasourcesXML.append(// $NON-NLS-1$ //$NON-NLS-2$
            "<Catalog name=\"" + Encode.forXml(catalogName) + "\">\n");
            datasourcesXML.append("<DataSourceInfo>" + Encode.forXml(datasourceInfo) + // $NON-NLS-1$
            "</DataSourceInfo>\n");
            datasourcesXML.append(// $NON-NLS-1$ //$NON-NLS-2$
            "<Definition>" + Encode.forXml(definition) + "</Definition>\n");
            // $NON-NLS-1$
            datasourcesXML.append("</Catalog>\n");
        } else {
            logger.warn(// $NON-NLS-1$
            Messages.getInstance().getString("MondrianCatalogHelper.WARN_META_DATA_IS_NULL"));
        }
    }
    // $NON-NLS-1$
    datasourcesXML.append("</Catalogs>\n");
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 92 with IUnifiedRepository

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

the class MondrianCatalogHelper method removeCatalog.

/**
 * This method removes a mondrian catalog from the JCR repository.
 */
@Override
public void removeCatalog(final String catalogName, final IPentahoSession pentahoSession) throws MondrianCatalogServiceException {
    if (MondrianCatalogHelper.logger.isDebugEnabled()) {
        // $NON-NLS-1$
        MondrianCatalogHelper.logger.debug("removeCatalog");
    }
    MondrianCatalog catalog = getCatalog(catalogName, pentahoSession);
    if (catalog == null) {
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0015_CATALOG_NOT_FOUND", // $NON-NLS-1$
        catalogName));
    }
    if (!hasAccess(catalog, RepositoryFilePermission.WRITE)) {
        if (MondrianCatalogHelper.logger.isDebugEnabled()) {
            // $NON-NLS-1$
            MondrianCatalogHelper.logger.debug("user does not have access; throwing exception");
        }
        throw new MondrianCatalogServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0003_INSUFFICIENT_PERMISSION"), // $NON-NLS-1$
        Reason.ACCESS_DENIED);
    }
    flushCacheForCatalog(catalog.getName(), pentahoSession);
    getAclHelper().removeAclFor(getMondrianCatalogRepositoryHelper().getMondrianCatalogFile(catalog.getName()));
    IUnifiedRepository solutionRepository = getRepository();
    RepositoryFile deletingFile = solutionRepository.getFile(// $NON-NLS-1$
    RepositoryFile.SEPARATOR + "etc" + RepositoryFile.SEPARATOR + "mondrian" + RepositoryFile.SEPARATOR + // $NON-NLS-1$
    catalog.getName());
    // $NON-NLS-1$
    solutionRepository.deleteFile(deletingFile.getId(), true, "");
    reInit(pentahoSession);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 93 with IUnifiedRepository

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

the class GetResourceIT method testRepositoryFile.

@Test
public void testRepositoryFile() throws ServletException, IOException {
    final String repoFileName = "repo_file.jpg";
    final int repoFileLength = 100;
    final RepositoryFile repositoryFile = mock(RepositoryFile.class);
    final InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any(byte[].class))).thenReturn(repoFileLength, -1);
    final SimpleRepositoryFileData repositoryFileData = mock(SimpleRepositoryFileData.class);
    when(repositoryFileData.getStream()).thenReturn(inputStream);
    final IUnifiedRepository repo = mock(IUnifiedRepository.class);
    when(repo.getFile(eq(repoFileName))).thenReturn(repositoryFile);
    when(repo.getDataForRead(any(Serializable.class), eq(SimpleRepositoryFileData.class))).thenReturn(repositoryFileData);
    mp.defineInstance(IUnifiedRepository.class, repo);
    when(request.getParameter(RESOURCE_PARAM)).thenReturn(repoFileName);
    final ServletOutputStream outputStream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(outputStream);
    servlet.service(request, response);
    verify(response).setContentType(eq(TEST_MIME_TYPE));
    verify(response).setHeader(eq(CONTENT_DISPOSITION_HEADER), endsWith(repoFileName));
    verify(response).setContentLength(repoFileLength);
}
Also used : Serializable(java.io.Serializable) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ServletOutputStream(javax.servlet.ServletOutputStream) InputStream(java.io.InputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Mockito.anyString(org.mockito.Mockito.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 94 with IUnifiedRepository

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

the class RepositoryFileStreamProvider method fileCreated.

public void fileCreated(String filePath) {
    IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
    RepositoryFile outputFile = repository.getFile(filePath);
    if (outputFile != null) {
        Map<String, Serializable> fileMetadata = repository.getFileMetadata(outputFile.getId());
        RepositoryFile inputFile = repository.getFile(inputFilePath);
        if (inputFile != null) {
            fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, inputFile.getId());
            repository.setFileMetadata(outputFile.getId(), fileMetadata);
        }
    }
}
Also used : Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 95 with IUnifiedRepository

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

the class ActionSequenceContentGenerator method createContent.

public void createContent(OutputStream outputStream) throws Exception {
    IParameterProvider requestParams = getRequestParameters();
    IParameterProvider pathParams = getPathParameters();
    if (// $NON-NLS-1$
    (requestParams != null) && (requestParams.getStringParameter("path", null) != null)) {
        // So far the decode that used to be here is not necessary and breaks files with special characters.
        // Leaving commented code here in case it shows up later
        // path = URLDecoder.decode( requestParams.getStringParameter( "path", "" ), "UTF-8" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        path = requestParams.getStringParameter("path", "");
    } else if ((pathParams != null) && (pathParams.getStringParameter("path", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        path = URLDecoder.decode(pathParams.getStringParameter("path", ""), "UTF-8");
    }
    if ((requestParams != null) && (requestParams.getStringParameter("contentType", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        contentType = requestParams.getStringParameter("contentType", TEXT_HTML);
    } else if ((pathParams != null) && (pathParams.getStringParameter("contentType", null) != null)) {
        // $NON-NLS-1$
        // $NON-NLS-1$
        contentType = pathParams.getStringParameter("contentType", TEXT_HTML);
    }
    if (path != null && path.length() > 0) {
        IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
        RepositoryFile file = unifiedRepository.getFile(path);
        // $NON-NLS-1$
        HttpServletRequest httpRequest = (HttpServletRequest) pathParams.getParameter("httprequest");
        // $NON-NLS-1$
        HttpServletResponse httpResponse = (HttpServletResponse) pathParams.getParameter("httpresponse");
        String buffer = XactionUtil.execute(contentType, file, httpRequest, httpResponse, PentahoSessionHolder.getSession(), outputHandler.getMimeTypeListener());
        if (buffer != null && buffer.trim().length() > 0) {
            outputStream.write(buffer.getBytes(LocaleHelper.getSystemEncoding()));
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4