Search in sources :

Example 1 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeContext method createChild.

private IRuntimeElement createChild(boolean persisted) {
    IRuntimeElement childRuntimeData = null;
    IRuntimeRepository runtimeRepository = PentahoSystem.get(IRuntimeRepository.class, session);
    // the runtime repository is optional
    if (runtimeRepository != null) {
        runtimeRepository.setLoggingLevel(loggingLevel);
        // $NON-NLS-1$
        childRuntimeData = runtimeRepository.newRuntimeElement(instanceId, "instance", !persisted);
        String childInstanceId = childRuntimeData.getInstanceId();
        // audit the creation of this against the parent instance
        AuditHelper.audit(instanceId, session.getName(), getActionName(), getObjectName(), processId, MessageTypes.INSTANCE_START, childInstanceId, "", 0, // $NON-NLS-1$
        this);
    }
    return childRuntimeData;
}
Also used : IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement)

Example 2 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeContext method createNewInstance.

public String createNewInstance(final boolean persisted) {
    String childInstanceId = null;
    IRuntimeElement childRuntimeData = createChild(persisted);
    if (childRuntimeData != null) {
        childInstanceId = childRuntimeData.getInstanceId();
    }
    return childInstanceId;
}
Also used : IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement)

Example 3 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeContext method createNewInstance.

public String createNewInstance(final boolean persisted, final Map parameters, final boolean forceImmediateWrite) {
    String childInstanceId = null;
    IRuntimeElement childRuntimeData = createChild(persisted);
    if (childRuntimeData != null) {
        if (parameters != null) {
            Iterator parameterIterator = parameters.keySet().iterator();
            while (parameterIterator.hasNext()) {
                String parameterName = (String) parameterIterator.next();
                Object parameterValue = parameters.get(parameterName);
                if (parameterValue instanceof String) {
                    childRuntimeData.setStringProperty(parameterName, (String) parameterValue);
                } else if (parameterValue instanceof BigDecimal) {
                    childRuntimeData.setBigDecimalProperty(parameterName, (BigDecimal) parameterValue);
                } else if (parameterValue instanceof Date) {
                    childRuntimeData.setDateProperty(parameterName, (Date) parameterValue);
                } else if (parameterValue instanceof List) {
                    childRuntimeData.setListProperty(parameterName, (List) parameterValue);
                } else if (parameterValue instanceof Long) {
                    childRuntimeData.setLongProperty(parameterName, (Long) parameterValue);
                }
            }
        }
        childInstanceId = childRuntimeData.getInstanceId();
        if (forceImmediateWrite) {
            childRuntimeData.forceSave();
        }
    }
    return childInstanceId;
}
Also used : IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 4 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeRepository method newRuntimeElement.

/**
 * Creates a new RuntimeElement
 *
 * @param parId
 *          Parent ID of this instance
 * @param parType
 *          Parent type of the instance
 * @return the created runtime element
 */
public IRuntimeElement newRuntimeElement(final String parId, final String parType, boolean transientOnly) {
    if (RuntimeRepository.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RTREPO.DEBUG_NEW_ELEMENT_PARENT", parId, parType));
    }
    Session session = HibernateUtil.getSession();
    String instanceId = UUIDUtil.getUUIDAsString();
    if (RuntimeRepository.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RTREPO.DEBUG_CREATE_INSTANCE", instanceId));
    }
    RuntimeElement re = new RuntimeElement(instanceId, parId, parType);
    if (!transientOnly) {
        try {
            session.save(re);
        } catch (HibernateException ex) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("RTREPO.ERROR_0002_SAVING_ELEMENT"), ex);
            throw new RepositoryException(Messages.getInstance().getErrorString("RTREPO.ERROR_0002_SAVING_ELEMENT"), ex);
        }
    }
    return re;
}
Also used : IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) HibernateException(org.hibernate.HibernateException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) Session(org.hibernate.Session) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 5 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class SolutionEngine method execute.

protected IRuntimeContext execute(final String actionPath, final String processId, final boolean async, final boolean instanceEnds, String instanceId, final boolean isPersisted, final Map parameterProviderMap, final IOutputHandler outputHandler, final IActionCompleteListener pListener, final IPentahoUrlFactory urlFactory, final List messages, final String actionSequenceXML) {
    this.persisted = isPersisted;
    setlistener(pListener);
    setSession(session);
    setMessages(messages);
    auditStart(actionPath, instanceId);
    if (!checkParameters(actionPath, processId)) {
        return null;
    }
    session.setProcessId(processId);
    session.setActionName(actionPath);
    // create the runtime context object for this operation
    if (debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("SolutionEngine.DEBUG_GETTING_RUNTIME_CONTEXT"));
    }
    boolean newInstance = instanceId == null;
    IRuntimeRepository runtimeRepository = null;
    if (PentahoSystem.getObjectFactory().objectDefined(IRuntimeRepository.class.getSimpleName())) {
        runtimeRepository = PentahoSystem.get(IRuntimeRepository.class, session);
    }
    IRuntimeElement runtimeData;
    if (runtimeRepository == null) {
        String id = UUIDUtil.getUUIDAsString();
        runtimeData = new SimpleRuntimeElement(id, session.getId(), IParameterProvider.SCOPE_SESSION);
    } else {
        runtimeRepository.setLoggingLevel(loggingLevel);
        if (newInstance) {
            // we need to create runtime data for this execution
            try {
                runtimeData = runtimeRepository.newRuntimeElement(session.getId(), IParameterProvider.SCOPE_SESSION, !persisted);
            } catch (Throwable t) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
                status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
                return null;
            }
        } else {
            try {
                runtimeData = runtimeRepository.loadElementById(instanceId, null);
            } catch (Throwable t) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
                status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
                return null;
            }
        }
    }
    if (runtimeData == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId));
        status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
        return null;
    }
    createRuntime(runtimeData, actionPath, outputHandler, processId, urlFactory);
    runtime.setLoggingLevel(loggingLevel);
    instanceId = runtime.getInstanceId();
    genLogIdFromInfo(instanceId, SolutionEngine.LOG_NAME, actionPath);
    if (newInstance) {
        // audit the creation of this against the session
        AuditHelper.audit(session.getId(), session.getName(), actionPath, getObjectName(), processId, MessageTypes.INSTANCE_START, instanceId, "", 0, // $NON-NLS-1$
        this);
    }
    /*
     * IRuntimeElement runtimeData; if (instanceId == null) { // we need to create runtime data for this execution try {
     * runtimeRepository.setLoggingLevel(loggingLevel); runtimeData =
     * runtimeRepository.newRuntimeElement(session.getId(), IParameterProvider.SCOPE_SESSION, !persisted);
     * createRuntime(runtimeData, solutionName, outputHandler, processId, urlFactory);
     * runtime.setLoggingLevel(loggingLevel); instanceId = runtime.getInstanceId(); genLogIdFromInfo(instanceId,
     * SolutionEngine.LOG_NAME, sequenceName); // audit the creation of this against the session
     * AuditHelper.audit(session.getId(), session.getName(), sequenceName, getObjectName(), processId,
     * MessageTypes.INSTANCE_START, instanceId, "", 0, this); //$NON-NLS-1$ } catch (Throwable t) {
     * error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
     * //$NON-NLS-1$ status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL; return null; } } else { try {
     * runtimeRepository.setLoggingLevel(loggingLevel); runtimeData = runtimeRepository.loadElementById(instanceId,
     * null); createRuntime(runtimeData, solutionName, outputHandler, processId, urlFactory);
     * runtime.setLoggingLevel(loggingLevel); instanceId = runtime.getInstanceId(); genLogIdFromInfo(instanceId,
     * SolutionEngine.LOG_NAME, sequenceName); } catch (Throwable t) {
     * error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
     * //$NON-NLS-1$ status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL; return null; } }
     */
    return executeInternal(actionPath, processId, async, instanceEnds, parameterProviderMap, actionSequenceXML);
}
Also used : IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) SimpleRuntimeElement(org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)

Aggregations

IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)8 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 IRuntimeRepository (org.pentaho.platform.api.repository.IRuntimeRepository)3 HashMap (java.util.HashMap)2 List (java.util.List)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 RepositoryException (org.pentaho.platform.api.repository.RepositoryException)2 SimpleRuntimeElement (org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)1