Search in sources :

Example 11 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class PentahoConnectionFactory method getConnection.

/**
 * @param datasourceType
 * @param properties
 *          can be null
 * @param session
 *          can be null
 * @param logger
 * @return
 */
public static IPentahoConnection getConnection(final String datasourceType, Properties properties, final IPentahoSession session, final ILogger logger) {
    /*
     * TODO - This is where the "connection factory" action occurs. Based on if the datasourceType, location,
     * username, or password have changed then we create a new one.
     */
    String key = CONNECTION_PREFIX + datasourceType;
    IPentahoConnection connection = null;
    try {
        connection = PentahoSystem.getObjectFactory().get(IPentahoConnection.class, key, session);
        if (connection instanceof IPentahoLoggingConnection) {
            ((IPentahoLoggingConnection) connection).setLogger(logger);
        }
        connection.setProperties(properties);
    } catch (ObjectFactoryException e) {
        Logger.error(PentahoSystem.class.getName(), Messages.getInstance().getErrorString("PentahoConnectionFactory.ERROR_0001_COULD_NOT_CREATE_CONNECTION", key), // $NON-NLS-1$
        e);
    }
    return connection;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoLoggingConnection(org.pentaho.platform.engine.core.system.IPentahoLoggingConnection)

Example 12 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class PentahoDataSourceResolver method lookup.

public DataSource lookup(String dataSourceName) throws Exception {
    javax.sql.DataSource datasource = null;
    String unboundDsName = null;
    IDBDatasourceService datasourceSvc = null;
    try {
        datasourceSvc = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, PentahoSessionHolder.getSession());
        unboundDsName = datasourceSvc.getDSUnboundName(dataSourceName);
        datasource = datasourceSvc.getDataSource(unboundDsName);
    } catch (ObjectFactoryException e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), e);
        throw e;
    } catch (DBDatasourceServiceException e) {
        /* We tried to find the datasource using unbound name. 
      ** Now as a fall back we will attempt to find this datasource as it is.
      ** For example jboss/datasource/Hibernate. The unbound name ends up to be Hibernate
      ** We will first look for Hibernate and if we fail then look for jboss/datasource/Hibernate */
        logger.warn(Messages.getInstance().getString("PentahoXmlaServlet.WARN_0001_UNABLE_TO_FIND_UNBOUND_NAME", dataSourceName, unboundDsName), // $NON-NLS-1$
        e);
        try {
            datasource = datasourceSvc.getDataSource(dataSourceName);
        } catch (DBDatasourceServiceException dbse) {
            logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), // $NON-NLS-1$
            e);
            throw dbse;
        }
    }
    return datasource;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) DataSource(javax.sql.DataSource) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Example 13 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class XactionUtil method executeInternal.

@SuppressWarnings("rawtypes")
protected static IRuntimeContext executeInternal(RepositoryFile file, IParameterProvider requestParams, HttpServletRequest httpServletRequest, IOutputHandler outputHandler, Map<String, IParameterProvider> parameterProviders, IPentahoSession userSession, boolean forcePrompt, List messages) throws Exception {
    String processId = XactionUtil.class.getName();
    // $NON-NLS-1$
    String instanceId = httpServletRequest.getParameter("instance-id");
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("");
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, userSession);
    ISystemSettings systemSettings = PentahoSystem.getSystemSettings();
    if (solutionEngine == null) {
        throw new ObjectFactoryException("No Solution Engine");
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    boolean instanceEnds = "true".equalsIgnoreCase(requestParams.getStringParameter("instanceends", "true"));
    // $NON-NLS-1$ //$NON-NLS-2$
    String parameterXsl = systemSettings.getSystemSetting("default-parameter-xsl", "DefaultParameterForm.xsl");
    solutionEngine.setLoggingLevel(2);
    solutionEngine.init(userSession);
    solutionEngine.setForcePrompt(forcePrompt);
    if (parameterXsl != null) {
        solutionEngine.setParameterXsl(parameterXsl);
    }
    return solutionEngine.execute(file.getPath(), processId, false, instanceEnds, instanceId, false, parameterProviders, outputHandler, null, urlFactory, messages);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings)

Example 14 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class PentahoEntryCollector method getAcesIncludingMagicAces.

/**
 * Extracts ACEs including magic aces. Magic ACEs are added for (1) the owner, (2) as a result of magic ACE
 * definitions, and (3) as a result of ancestor ACL contributions.
 * <p/>
 * <p> Modifications to these ACLs are not persisted. </p>
 */
@SuppressWarnings("unchecked")
protected List<PentahoEntry> getAcesIncludingMagicAces(final String path, final String owner, final ACLTemplate ancestorAcl, final ACLTemplate acl) throws RepositoryException {
    if (PentahoSessionHolder.getSession() == null || PentahoSessionHolder.getSession().getId() == null || PentahoSessionHolder.getSession().getId().trim().equals("")) {
        // $NON-NLS-1$
        if (log.isDebugEnabled()) {
            // $NON-NLS-1$
            log.debug("no PentahoSession so no magic ACEs");
        }
        return Collections.emptyList();
    }
    if (owner != null) {
        addOwnerAce(owner, acl);
    }
    boolean match = false;
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = null;
    try {
        roleBindingDao = PentahoSystem.getObjectFactory().get(IRoleAuthorizationPolicyRoleBindingDao.class, "roleAuthorizationPolicyRoleBindingDaoTarget", PentahoSessionHolder.getSession());
    } catch (ObjectFactoryException e) {
        e.printStackTrace();
    }
    ITenant tenant = JcrTenantUtils.getTenant();
    for (final MagicAceDefinition def : getMagicAceDefinitions()) {
        match = false;
        String substitutedPath = MessageFormat.format(def.path, tenant.getRootFolderAbsolutePath());
        if (isAllowed(roleBindingDao, def.logicalRole)) {
            if (def.applyToTarget) {
                match = path.equals(substitutedPath);
            }
            if (!match && def.applyToChildren) {
                match = path.startsWith(substitutedPath + "/");
                // check to see if we should exclude the match due to the exclude list
                if (match && def.exceptChildren != null) {
                    for (String childPath : def.exceptChildren) {
                        String substitutedChildPath = MessageFormat.format(childPath, tenant.getRootFolderAbsolutePath());
                        if (path.startsWith(substitutedChildPath + "/")) {
                            match = false;
                            break;
                        }
                    }
                }
            }
            if (!match && def.applyToAncestors) {
                match = substitutedPath.startsWith(path + "/");
            }
        }
        if (match) {
            Principal principal = new MagicPrincipal(JcrTenantUtils.getTenantedUser(PentahoSessionHolder.getSession().getName()));
            // unfortunately, we need the ACLTemplate because it alone can create ACEs that can be cast successfully
            // later;
            // changed never persisted
            acl.addAccessControlEntry(principal, def.privileges);
        }
    }
    @SuppressWarnings("rawtypes") List acEntries = new ArrayList();
    // leaf ACEs go first so ACL metadata ACE stays first
    acEntries.addAll(buildPentahoEntries(acl));
    acEntries.addAll(getRelevantAncestorAces(ancestorAcl));
    return acEntries;
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) ITenant(org.pentaho.platform.api.mt.ITenant) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Principal(java.security.Principal)

Example 15 with ObjectFactoryException

use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.

the class EmbeddedQuartzSystemListener method startup.

public boolean startup(final IPentahoSession session) {
    boolean result = true;
    Properties quartzProps = null;
    if (quartzPropertiesFile != null) {
        quartzProps = PentahoSystem.getSystemSettings().getSystemSettingsProperties(quartzPropertiesFile);
    } else if (quartzProperties != null) {
        quartzProps = quartzProperties;
    }
    try {
        if (quartzProps == null) {
            quartzProps = findPropertiesInClasspath();
        }
        if (quartzProps == null) {
            result = false;
        } else {
            // $NON-NLS-1$
            String dsName = quartzProps.getProperty("org.quartz.dataSource.myDS.jndiURL");
            if (dsName != null) {
                IDBDatasourceService datasourceService = getQuartzDatasourceService(session);
                String boundDsName = datasourceService.getDSBoundName(dsName);
                if (boundDsName != null) {
                    // $NON-NLS-1$
                    quartzProps.setProperty("org.quartz.dataSource.myDS.jndiURL", boundDsName);
                }
                DataSource ds = datasourceService.getDataSource(dsName);
                result = verifyQuartzIsConfigured(ds);
            }
            // $NON-NLS-1$
            QuartzScheduler scheduler = (QuartzScheduler) PentahoSystem.get(IScheduler.class, "IScheduler2", null);
            if (logger.isDebugEnabled()) {
                // $NON-NLS-1$
                logger.debug("Quartz configured with properties");
                // $NON-NLS-1$
                quartzProps.store(System.out, "debugging");
            }
            scheduler.setQuartzSchedulerFactory(new org.quartz.impl.StdSchedulerFactory(quartzProps));
            if (logger.isDebugEnabled()) {
                logger.debug(scheduler.getQuartzScheduler().getSchedulerName());
            }
            scheduler.start();
        }
    } catch (IOException ex) {
        result = false;
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0004_LOAD_PROPERTIES_FROM_CLASSPATH"), // $NON-NLS-1$
        ex);
    } catch (ObjectFactoryException objface) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0005_UNABLE_TO_INSTANTIATE_OBJECT", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        objface);
        result = false;
    } catch (DBDatasourceServiceException dse) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0006_UNABLE_TO_GET_DATASOURCE", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        dse);
        result = false;
    } catch (SQLException sqle) {
        // $NON-NLS-1$
        logger.error("EmbeddedQuartzSystemListener.ERROR_0007_SQLERROR", sqle);
        result = false;
    } catch (SchedulerException e) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        e);
        result = false;
    } catch (org.pentaho.platform.api.scheduler2.SchedulerException e) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        e);
        result = false;
    }
    return result;
}
Also used : SchedulerException(org.quartz.SchedulerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) DataSource(javax.sql.DataSource) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Aggregations

ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)27 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)10 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)7 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)5 DataSource (javax.sql.DataSource)4 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)4 ArrayList (java.util.ArrayList)3 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)3 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 PBEKeySpec (javax.crypto.spec.PBEKeySpec)1 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)1