Search in sources :

Example 6 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImpl method addHostedCatalog.

public void addHostedCatalog(String name, String dataSourceInfo, InputStream inputStream, boolean overwrite, IPentahoSession session) {
    // Access
    if (!hasAccess(name, EnumSet.of(RepositoryFilePermission.WRITE), session)) {
        // $NON-NLS-1$
        LOG.debug("user does not have access; throwing exception");
        throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "OlapServiceImpl.ERROR_0003_INSUFFICIENT_PERMISSION"), IOlapServiceException.Reason.ACCESS_DENIED);
    }
    // check for existing vs. the overwrite flag.
    if (getCatalogNames(session).contains(name) && !overwrite) {
        throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "OlapServiceImpl.ERROR_0004_ALREADY_EXISTS"), IOlapServiceException.Reason.ALREADY_EXISTS);
    }
    try {
        MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(getRepository());
        helper.addHostedCatalog(inputStream, name, dataSourceInfo);
    } catch (Exception e) {
        throw new IOlapServiceException(e, IOlapServiceException.Reason.convert(e));
    }
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileSystemException(org.apache.commons.vfs2.FileSystemException) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException)

Example 7 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImpl method addOlap4jCatalog.

public void addOlap4jCatalog(String name, String className, String URL, String user, String password, Properties props, boolean overwrite, IPentahoSession session) {
    // Access
    if (!hasAccess(name, EnumSet.of(RepositoryFilePermission.WRITE), session)) {
        // $NON-NLS-1$
        LOG.debug("user does not have access; throwing exception");
        throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "OlapServiceImpl.ERROR_0003_INSUFFICIENT_PERMISSION"), IOlapServiceException.Reason.ACCESS_DENIED);
    }
    // check for existing vs. the overwrite flag.
    if (getCatalogNames(session).contains(name) && !overwrite) {
        throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "OlapServiceImpl.ERROR_0004_ALREADY_EXISTS"), IOlapServiceException.Reason.ALREADY_EXISTS);
    }
    MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(getRepository());
    helper.addOlap4jServer(name, className, URL, user, password, props);
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper)

Example 8 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImpl method getConnection.

public OlapConnection getConnection(String catalogName, IPentahoSession session) throws IOlapServiceException {
    if (catalogName == null) {
        // This is normal. It happens on XMLA's DISCOVER_DATASOURCES
        try {
            return getServer().getConnection(DATASOURCE_NAME, null, null, new Properties());
        } catch (Exception e) {
            throw new IOlapServiceException(e);
        }
    }
    // Check Access
    if (!hasAccess(catalogName, EnumSet.of(RepositoryFilePermission.READ), session)) {
        // $NON-NLS-1$
        LOG.debug("user does not have access; throwing exception");
        throw new IOlapServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "OlapServiceImpl.ERROR_0003_INSUFFICIENT_PERMISSION"), IOlapServiceException.Reason.ACCESS_DENIED);
    }
    // Check its existence.
    if (!getCatalogNames(session).contains(catalogName)) {
        throw new IOlapServiceException(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0015_CATALOG_NOT_FOUND", catalogName));
    }
    // Check if it is a remote server
    if (getHelper().getOlap4jServers().contains(catalogName)) {
        return makeOlap4jConnection(catalogName);
    }
    final StringBuilder roleName = new StringBuilder();
    Entry roleMonikor = null;
    if (this.role != null) {
        // We must use a custom role implementation.
        // Register the instance with the mondrian server.
        roleMonikor = getServer().getLockBox().register(this.role);
        roleName.append(roleMonikor.getMoniker());
    } else {
        final IConnectionUserRoleMapper mapper = PentahoSystem.get(IConnectionUserRoleMapper.class, MDXConnection.MDX_CONNECTION_MAPPER_KEY, // Don't use the user session here yet.
        null);
        String[] effectiveRoles = new String[0];
        /*
       * If Catalog/Schema are null (this happens with high level metadata requests,
       * like DISCOVER_DATASOURCES) we can't use the role mapper, even if it
       * is present and configured.
       */
        if (session != null && mapper != null) {
            // Use the role mapper.
            try {
                effectiveRoles = mapper.mapConnectionRoles(session, catalogName);
                if (effectiveRoles == null) {
                    effectiveRoles = new String[0];
                }
            } catch (PentahoAccessControlException e) {
                throw new IOlapServiceException(e);
            }
        }
        // Now we tokenize that list.
        boolean addComma = false;
        for (String role : effectiveRoles) {
            if (addComma) {
                // $NON-NLS-1$
                roleName.append(",");
            }
            roleName.append(role);
            addComma = true;
        }
    }
    // Populate some properties, like locale.
    final Properties properties = new Properties();
    properties.put(RolapConnectionProperties.Locale.name(), getLocale().toString());
    // Return a connection
    try {
        return getServer().getConnection(DATASOURCE_NAME, catalogName, Util.isEmpty(roleName.toString()) ? null : roleName.toString(), properties);
    } catch (Exception e) {
        throw new IOlapServiceException(e);
    } finally {
        // Cleanup our lockbox entry.
        if (roleMonikor != null) {
            getServer().getLockBox().deregister(roleMonikor);
        }
    }
}
Also used : Entry(mondrian.util.LockBox.Entry) IConnectionUserRoleMapper(org.pentaho.platform.api.engine.IConnectionUserRoleMapper) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileSystemException(org.apache.commons.vfs2.FileSystemException) OlapException(org.olap4j.OlapException) SQLException(java.sql.SQLException) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException)

Example 9 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testGetOlap4jCatalogsWithoutAccess.

/**
 * Validates getting a list of remote catalogs if we don't have access to them.
 */
@Test
public void testGetOlap4jCatalogsWithoutAccess() throws Exception {
    stubGetChildren(repository, olapFolderPath, "myServer");
    // Stub /etc/olap-servers/myServer
    final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    // Stub /etc/olap-servers/myServer/metadata
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
    // Stub the security
    accessMock = new DefaultAccessImpl() {

        public boolean hasAccess(String path, EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
            if (!perms.contains(RepositoryFilePermission.READ)) {
                fail();
            }
            return false;
        }
    };
    // Get a list of catalogs.
    final List<String> catalogs = olapService.getCatalogNames(session);
    assertEquals(0, catalogs.size());
    verify(repository).getChildren(eq(makeIdObject(olapFolderPath)));
    // Now try obtaining it anyways.
    try {
        olapService.getConnection("myServer", session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.ACCESS_DENIED, e.getReason());
        assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0003"));
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with IOlapServiceException

use of org.pentaho.platform.plugin.action.olap.IOlapServiceException in project pentaho-platform by pentaho.

the class OlapServiceImplTest method testImportGenericOverwriteFlag.

/**
 * Verifies that we can create locally hosted mondrian instances.
 */
@Test
public void testImportGenericOverwriteFlag() throws Exception {
    stubGetChildren(repository, olapFolderPath, "myServer");
    // Stub /etc/olap-servers/myServer
    final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
    stubGetFolder(repository, testServerPath);
    stubGetChildren(repository, testServerPath, "metadata");
    // Stub /etc/olap-servers/myServer/metadata
    final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
    stubGetFile(repository, metadataPath);
    stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
    // Try to save it without the overwrite flag. We expect it to fail.
    try {
        olapService.addOlap4jCatalog("myServer", "class-name", "url", "user", "password", new Properties(), false, session);
        fail();
    } catch (IOlapServiceException e) {
        assertEquals(IOlapServiceException.Reason.ALREADY_EXISTS, e.getReason());
        assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0004"));
    }
    // Make sure we didn't invoke the update or write methods.
    verify(repository, never()).updateFile((RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
    verify(repository, never()).createFile((RepositoryFile) anyObject(), (RepositoryFile) anyObject(), (IRepositoryFileData) anyObject(), anyString());
    // Now do it again.
    olapService.addOlap4jCatalog("myServer", "class-name", "url", "user", "password", new Properties(), true, session);
    verify(repository).updateFile(argThat(isLikeFile(makeFileObject(metadataPath))), argThat(hasData(pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/className", "class-name"), pathPropertyPair("/server/URL", "url"), pathPropertyPair("/server/user", "user"), pathPropertyPair("/server/password", "password"))), anyString());
}
Also used : IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) Matchers.anyString(org.mockito.Matchers.anyString) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)17 Test (org.junit.Test)8 SQLException (java.sql.SQLException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Properties (java.util.Properties)5 RolapConnectionProperties (mondrian.rolap.RolapConnectionProperties)5 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 OlapException (org.olap4j.OlapException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 RolapConnection (mondrian.rolap.RolapConnection)4 OlapConnection (org.olap4j.OlapConnection)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)3 InputStream (java.io.InputStream)2 Connection (java.sql.Connection)2 Callable (java.util.concurrent.Callable)2 IOlapConnectionFilter (org.pentaho.platform.plugin.action.olap.IOlapConnectionFilter)2