Search in sources :

Example 6 with MondrianCatalogRepositoryHelper

use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.

the class MondrianCatalogHelperIT method addCatalog_WithAcl.

@Test
public void addCatalog_WithAcl() throws Exception {
    initMondrianCatalogsCache();
    MondrianCatalogHelper helperSpy = spy(helper);
    IPentahoSession session = mock(IPentahoSession.class);
    doNothing().when(helperSpy).init(session);
    doReturn(Collections.<MondrianCatalog>emptyList()).when(helperSpy).getCatalogs(session);
    doReturn(null).when(helperSpy).makeSchema(anyString());
    MondrianCatalog cat = createTestCatalog();
    RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
    IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
    doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), eq(acl));
    doReturn(aclHelper).when(helperSpy).getAclHelper();
    doReturn(null).when(helperSpy).makeSchema(CATALOG_NAME);
    doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
    MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
    helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, acl, session);
    verify(aclHelper, times(1)).setAclFor(any(RepositoryFile.class), eq(acl));
    doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
    helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
    verify(aclHelper, times(2)).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 7 with MondrianCatalogRepositoryHelper

use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project pentaho-platform by pentaho.

the class MondrianCatalogHelperIT method removeCatalog_WithAcl.

@Test
public void removeCatalog_WithAcl() throws Exception {
    IPentahoSession session = mock(IPentahoSession.class);
    helper = spy(helper);
    doReturn(createTestCatalog()).when(helper).getCatalog(eq(CATALOG_NAME), eq(session));
    doNothing().when(helper).reInit(eq(session));
    MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    doReturn(repositoryHelper).when(helper).getMondrianCatalogRepositoryHelper();
    IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
    when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
    doReturn(aclHelper).when(helper).getAclHelper();
    RepositoryFile file = mock(RepositoryFile.class);
    when(file.getId()).thenReturn("1");
    when(repo.getFile("/etc/mondrian/" + CATALOG_NAME)).thenReturn(file);
    helper.removeCatalog(CATALOG_NAME, session);
    verify(aclHelper).removeAclFor(any(RepositoryFile.class));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) EnumSet(java.util.EnumSet) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 8 with MondrianCatalogRepositoryHelper

use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project data-access by pentaho.

the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownload.

@Test
public void testDoGetDSWFilesAsDownload() throws Exception {
    Map<String, InputStream> mockFileData = mock(Map.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    MondrianCatalogRepositoryHelper mockMondrianCatalogRepositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    doReturn(true).when(dataSourceWizardService).canManageACL();
    doReturn(mockFileData).when(dataSourceWizardService).getMetadataFiles(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockMondrianCatalogRepositoryHelper).when(dataSourceWizardService).createMondrianCatalogRepositoryHelper();
    doNothing().when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId, mockFileData);
    Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
    assertEquals(mockFileData, response);
    verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Matchers.anyString(org.mockito.Matchers.anyString) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 9 with MondrianCatalogRepositoryHelper

use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project data-access by pentaho.

the class AnalysisService method createPlatformBundle.

/**
 * helper method to create the platform bundle used by the Jcr repository
 *
 * @param parameters
 * @param dataInputStream
 * @param catalogName
 * @param overWriteInRepository
 * @param fileName
 * @param xmlaEnabled
 * @param acl acl information for the data source. This parameter is optional.
 * @return IPlatformImportBundle
 */
private IPlatformImportBundle createPlatformBundle(String parameters, InputStream dataInputStream, String catalogName, boolean overWriteInRepository, String fileName, boolean xmlaEnabled, RepositoryFileAclDto acl) {
    byte[] bytes = null;
    try {
        bytes = IOUtils.toByteArray(dataInputStream);
        if (bytes.length == 0 && catalogName != null) {
            MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
            Map<String, InputStream> fileData = helper.getModrianSchemaFiles(catalogName);
            dataInputStream = fileData.get("schema.xml");
            bytes = IOUtils.toByteArray(dataInputStream);
        }
    } catch (IOException e) {
        logger.error(e);
    }
    String datasource = getValue(parameters, "Datasource");
    String domainId = this.determineDomainCatalogName(parameters, catalogName, fileName, new ByteArrayInputStream(bytes));
    String sep = ";";
    if (StringUtils.isEmpty(parameters)) {
        parameters = "Provider=mondrian";
        parameters += sep + DATASOURCE_NAME + "=" + datasource;
        parameters += sep + ENABLE_XMLA + "=" + xmlaEnabled;
    }
    RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().input(new ByteArrayInputStream(bytes)).charSet(UTF_8).hidden(false).name(domainId).overwriteFile(overWriteInRepository).mime(MONDRIAN_MIME_TYPE).withParam(PARAMETERS, parameters).withParam(DOMAIN_ID, domainId);
    if (acl != null) {
        bundleBuilder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
    }
    bundleBuilder.withParam(ENABLE_XMLA, Boolean.toString(xmlaEnabled));
    IPlatformImportBundle bundle = bundleBuilder.build();
    return bundle;
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) IOException(java.io.IOException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 10 with MondrianCatalogRepositoryHelper

use of org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper in project data-access by pentaho.

the class DataSourceWizardService method doGetDSWFilesAsDownload.

public Map<String, InputStream> doGetDSWFilesAsDownload(String dswId) throws PentahoAccessControlException {
    if (!canManageACL()) {
        throw new PentahoAccessControlException();
    }
    // First get the metadata files;
    Map<String, InputStream> fileData = getMetadataFiles(dswId);
    // Then get the corresponding mondrian files
    Domain domain = metadataDomainRepository.getDomain(dswId);
    ModelerWorkspace model = createModelerWorkspace();
    model.setDomain(domain);
    LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
    if (logicalModel == null) {
        logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
    }
    if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
        MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper();
        String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
        fileData.putAll(helper.getModrianSchemaFiles(catalogRef));
        parseMondrianSchemaNameWrapper(dswId, fileData);
    }
    return fileData;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

Aggregations

MondrianCatalogRepositoryHelper (org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper)13 Test (org.junit.Test)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 IAclNodeHelper (org.pentaho.platform.api.repository2.unified.IAclNodeHelper)4 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)4 EnumSet (java.util.EnumSet)3 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ZipInputStream (java.util.zip.ZipInputStream)2 MondrianException (mondrian.olap.MondrianException)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 OlapException (org.olap4j.OlapException)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2