Search in sources :

Example 1 with IComponent

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

the class RuntimeContext method executeAction.

private void executeAction(final ISolutionActionDefinition actionDefinition, final Map pParameterProviders, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionInitializationException, ActionExecutionException, UnresolvedParameterException {
    this.parameterProviders = pParameterProviders;
    // TODO get audit setting from action definition
    long start = new Date().getTime();
    if (audit) {
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_START, MessageTypes.START, "", 0);
    }
    try {
        // resolve the parameters
        resolveParameters();
    } catch (UnresolvedParameterException ex) {
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0013_BAD_PARAMETERS"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        ex.setActionClass(actionDefinition.getComponentName());
        ex.setStepDescription(actionDefinition.getDescription());
        throw ex;
    }
    status = IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_OK;
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PRE-EXECUTE_AUDIT"));
    }
    List auditPre = actionDefinition.getPreExecuteAuditList();
    audit(auditPre);
    // initialize the component
    IComponent component = actionDefinition.getComponent();
    if (RuntimeContext.debug) {
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_SETTING_LOGGING", // $NON-NLS-1$
        Logger.getLogLevelName(loggingLevel)));
    }
    component.setLoggingLevel(loggingLevel);
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_INITIALIZING_COMPONENT"));
    }
    boolean initResult = false;
    try {
        initResult = component.init();
    /*
       * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
       * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
       * prevent valuable feedback in the log or response.
       */
    } catch (Throwable t) {
        throw new ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    if (!initResult) {
        status = IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL;
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw new ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    try {
        executeComponent(actionDefinition);
    } catch (ActionExecutionException ex) {
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw ex;
    }
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_POST-EXECUTE_AUDIT"));
    }
    List auditPost = actionDefinition.getPostExecuteAuditList();
    audit(auditPost);
    if (audit) {
        long end = new Date().getTime();
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_END, MessageTypes.END, "", (int) (end - start));
    }
    if (doneListener != null) {
        doneListener.actionComplete(this);
    }
    if (execListener != null) {
        execListener.action(this, actionDefinition);
    }
}
Also used : UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) IComponent(org.pentaho.platform.api.engine.IComponent) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) Date(java.util.Date)

Example 2 with IComponent

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

the class RuntimeContext method validateComponents.

private void validateComponents(final IActionSequence sequence, final IExecutionListener execListener) throws ActionValidationException {
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator it = defList.iterator(); it.hasNext(); ) {
        listItem = it.next();
        if (listItem instanceof IActionSequence) {
            validateComponents((IActionSequence) listItem, execListener);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_VALIDATING_COMPONENT", actionDef.getComponentName()));
            }
            IComponent component = null;
            try {
                component = resolveComponent(actionDef, instanceId, processId, session);
                component.setLoggingLevel(loggingLevel);
                // allow the ActionDefinition to cache the component
                actionDef.setComponent(component);
                paramManager.setCurrentParameters(actionDef);
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable ex) {
                ActionDefinition actionDefinition = new ActionDefinition((Element) actionDef.getNode(), null);
                throw new ActionValidationException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0009_COULD_NOT_CREATE_COMPONENT", // $NON-NLS-1$
                actionDef.getComponentName().trim()), // $NON-NLS-1$
                ex, session.getName(), instanceId, getActionSequence().getSequenceName(), actionDefinition.getDescription(), actionDefinition.getComponentName());
            }
            int validateResult = IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK;
            try {
                validateResult = component.validate();
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable t) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), // $NON-NLS-1$
                t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            if (validateResult != IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            paramManager.addOutputParameters(actionDef);
            // $NON-NLS-1$
            setCurrentComponent("");
            setCurrentActionDef(null);
        }
    }
    if (execListener != null) {
        execListener.validated(this);
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IComponent(org.pentaho.platform.api.engine.IComponent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition)

Example 3 with IComponent

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

the class RuntimeContext method resolveComponent.

protected IComponent resolveComponent(final ISolutionActionDefinition actionDefinition, final String currentInstanceId, final String currentProcessId, final IPentahoSession currentSession) throws ClassNotFoundException, PluginBeanException, InstantiationException, IllegalAccessException {
    // try to create an instance of the component class specified in the
    // action document
    String componentAlias = actionDefinition.getComponentName().trim();
    String componentClassName = RuntimeContext.getComponentClassName(componentAlias, this);
    Element componentDefinition = (Element) actionDefinition.getComponentSection();
    setCurrentComponent(componentClassName);
    setCurrentActionDef(actionDefinition);
    IComponent component = null;
    Class componentClass = null;
    Object componentTmp = null;
    // Explicitly using the short name instead of the fully layed out class name
    if ((pluginManager != null) && (pluginManager.isBeanRegistered(componentAlias))) {
        if (RuntimeContext.debug) {
            // $NON-NLS-1$ //$NON-NLS-2$
            this.debug("Component alias " + componentAlias + " will be resolved by the plugin manager.");
        }
        componentTmp = pluginManager.getBean(componentAlias);
        if (RuntimeContext.debug) {
            // $NON-NLS-1$
            this.debug("Component found in a plugin, class is: " + componentTmp.getClass().getName());
        }
    }
    if (RuntimeContext.debug) {
        // $NON-NLS-1$ //$NON-NLS-2$
        this.debug("Component alias " + componentAlias + " will be resolved by the platform");
    }
    // Ok - the plugin didn't load - try the old route
    if (componentTmp == null) {
        componentClass = Class.forName(componentClassName);
        componentTmp = componentClass.newInstance();
    }
    if (componentTmp instanceof IComponent) {
        component = (IComponent) componentTmp;
    } else if (componentTmp instanceof IAction) {
        component = new ActionDelegate(componentTmp);
    } else {
        // Try this out...
        PojoComponent pc = new PojoComponent();
        pc.setPojo(componentTmp);
        component = pc;
    }
    component.setInstanceId(currentInstanceId);
    component.setActionName(getActionName());
    component.setProcessId(currentProcessId);
    // to the dom nodes.
    if (component instanceof IParameterResolver) {
        component.setActionDefinition(ActionFactory.getActionDefinition((Element) actionDefinition.getNode(), new ActionSequenceParameterMgr(this, currentSession, (IParameterResolver) component)));
    } else {
        component.setActionDefinition(ActionFactory.getActionDefinition((Element) actionDefinition.getNode(), new ActionSequenceParameterMgr(this, currentSession)));
    }
    // create a map of the top level component definition nodes and their text
    Map<String, String> componentDefinitionMap = new HashMap<String, String>();
    List elements = componentDefinition.elements();
    Element element;
    String name;
    String value;
    String customXsl = null;
    for (int idx = 0; idx < elements.size(); idx++) {
        element = (Element) elements.get(idx);
        name = element.getName();
        value = element.getText();
        // see if we have a target window for the output
        if ("target".equals(name)) {
            // $NON-NLS-1$
            setParameterTarget(value);
        } else if ("xsl".equals(name)) {
            // $NON-NLS-1$
            // setParameterXsl(value);
            customXsl = value;
        }
        componentDefinitionMap.put(element.getName(), element.getText());
    }
    if (customXsl != null) {
        setParameterXsl(customXsl);
    }
    component.setComponentDefinitionMap(componentDefinitionMap);
    component.setComponentDefinition(componentDefinition);
    component.setRuntimeContext(this);
    component.setSession(currentSession);
    component.setLoggingLevel(getLoggingLevel());
    component.setMessages(getMessages());
    return component;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) IComponent(org.pentaho.platform.api.engine.IComponent) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) Element(org.dom4j.Element) ActionDelegate(org.pentaho.platform.engine.services.solution.ActionDelegate) IParameterResolver(org.pentaho.platform.api.engine.IParameterResolver) List(java.util.List) ArrayList(java.util.ArrayList) ActionSequenceParameterMgr(org.pentaho.platform.engine.services.actionsequence.ActionSequenceParameterMgr) PojoComponent(org.pentaho.platform.engine.services.solution.PojoComponent)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 IComponent (org.pentaho.platform.api.engine.IComponent)3 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Element (org.dom4j.Element)1 ActionDefinition (org.pentaho.actionsequence.dom.actions.ActionDefinition)1 IAction (org.pentaho.platform.api.action.IAction)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)1 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IParameterResolver (org.pentaho.platform.api.engine.IParameterResolver)1 ISolutionActionDefinition (org.pentaho.platform.api.engine.ISolutionActionDefinition)1 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)1 IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)1 ActionSequenceParameterMgr (org.pentaho.platform.engine.services.actionsequence.ActionSequenceParameterMgr)1 ActionDelegate (org.pentaho.platform.engine.services.solution.ActionDelegate)1 PojoComponent (org.pentaho.platform.engine.services.solution.PojoComponent)1