Search in sources :

Example 71 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class BpmnParse method execute.

public BpmnParse execute() {
    try {
        ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
        BpmnXMLConverter converter = new BpmnXMLConverter();
        boolean enableSafeBpmnXml = false;
        String encoding = null;
        if (processEngineConfiguration != null) {
            enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
            encoding = processEngineConfiguration.getXmlEncoding();
        }
        if (encoding != null) {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
        } else {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
        }
        // XSD validation goes first, then process/semantic validation
        if (validateProcess) {
            ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
            if (processValidator == null) {
                LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
            } else {
                List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
                if (validationErrors != null && !validationErrors.isEmpty()) {
                    StringBuilder warningBuilder = new StringBuilder();
                    StringBuilder errorBuilder = new StringBuilder();
                    for (ValidationError error : validationErrors) {
                        if (error.isWarning()) {
                            warningBuilder.append(error.toString());
                            warningBuilder.append("\n");
                        } else {
                            errorBuilder.append(error.toString());
                            errorBuilder.append("\n");
                        }
                    }
                    // Throw exception if there is any error
                    if (errorBuilder.length() > 0) {
                        throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString());
                    }
                    // Write out warnings (if any)
                    if (warningBuilder.length() > 0) {
                        LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
                    }
                }
            }
        }
        bpmnModel.setSourceSystemId(sourceSystemId);
        bpmnModel.setEventSupport(new ActivitiEventSupport());
        // Validation successful (or no validation)
        // Attach logic to the processes (eg. map ActivityBehaviors to bpmn model elements)
        applyParseHandlers();
        // Finally, process the diagram interchange info
        processDI();
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        } else if (e instanceof XMLException) {
            throw (XMLException) e;
        } else {
            throw new ActivitiException("Error parsing XML", e);
        }
    }
    return this;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) ValidationError(org.activiti.validation.ValidationError) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessValidator(org.activiti.validation.ProcessValidator) ActivitiEventSupport(org.activiti.engine.delegate.event.impl.ActivitiEventSupport) ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) MalformedURLException(java.net.MalformedURLException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 72 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class TableDataManagerImpl method getTableMetaData.

@Override
public TableMetaData getTableMetaData(String tableName) {
    TableMetaData result = new TableMetaData();
    try {
        result.setTableName(tableName);
        DatabaseMetaData metaData = getDbSqlSession().getSqlSession().getConnection().getMetaData();
        if ("postgres".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
            tableName = tableName.toLowerCase();
        }
        String catalog = null;
        if (getProcessEngineConfiguration().getDatabaseCatalog() != null && getProcessEngineConfiguration().getDatabaseCatalog().length() > 0) {
            catalog = getProcessEngineConfiguration().getDatabaseCatalog();
        }
        String schema = null;
        if (getProcessEngineConfiguration().getDatabaseSchema() != null && getProcessEngineConfiguration().getDatabaseSchema().length() > 0) {
            if ("oracle".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                schema = getProcessEngineConfiguration().getDatabaseSchema().toUpperCase();
            } else {
                schema = getProcessEngineConfiguration().getDatabaseSchema();
            }
        }
        ResultSet resultSet = metaData.getColumns(catalog, schema, tableName, null);
        while (resultSet.next()) {
            boolean wrongSchema = false;
            if (schema != null && schema.length() > 0) {
                for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
                    String columnName = resultSet.getMetaData().getColumnName(i + 1);
                    if ("TABLE_SCHEM".equalsIgnoreCase(columnName) || "TABLE_SCHEMA".equalsIgnoreCase(columnName)) {
                        if (!schema.equalsIgnoreCase(resultSet.getString(resultSet.getMetaData().getColumnName(i + 1)))) {
                            wrongSchema = true;
                        }
                        break;
                    }
                }
            }
            if (!wrongSchema) {
                String name = resultSet.getString("COLUMN_NAME").toUpperCase();
                String type = resultSet.getString("TYPE_NAME").toUpperCase();
                result.addColumnMetaData(name, type);
            }
        }
    } catch (SQLException e) {
        throw new ActivitiException("Could not retrieve database metadata: " + e.getMessage());
    }
    if (result.getColumnNames().isEmpty()) {
        // According to API, when a table doesn't exist, null should be returned
        result = null;
    }
    return result;
}
Also used : TableMetaData(org.activiti.engine.management.TableMetaData) ActivitiException(org.activiti.engine.ActivitiException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 73 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class TableDataManagerImpl method getTablesPresentInDatabase.

@Override
public List<String> getTablesPresentInDatabase() {
    List<String> tableNames = new ArrayList<String>();
    Connection connection = null;
    try {
        connection = getDbSqlSession().getSqlSession().getConnection();
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        ResultSet tables = null;
        try {
            log.debug("retrieving activiti tables from jdbc metadata");
            String databaseTablePrefix = getDbSqlSession().getDbSqlSessionFactory().getDatabaseTablePrefix();
            String tableNameFilter = databaseTablePrefix + "ACT_%";
            if ("postgres".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                tableNameFilter = databaseTablePrefix + "act_%";
            }
            if ("oracle".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                tableNameFilter = databaseTablePrefix + "ACT" + databaseMetaData.getSearchStringEscape() + "_%";
            }
            String catalog = null;
            if (getProcessEngineConfiguration().getDatabaseCatalog() != null && getProcessEngineConfiguration().getDatabaseCatalog().length() > 0) {
                catalog = getProcessEngineConfiguration().getDatabaseCatalog();
            }
            String schema = null;
            if (getProcessEngineConfiguration().getDatabaseSchema() != null && getProcessEngineConfiguration().getDatabaseSchema().length() > 0) {
                if ("oracle".equals(getDbSqlSession().getDbSqlSessionFactory().getDatabaseType())) {
                    schema = getProcessEngineConfiguration().getDatabaseSchema().toUpperCase();
                } else {
                    schema = getProcessEngineConfiguration().getDatabaseSchema();
                }
            }
            tables = databaseMetaData.getTables(catalog, schema, tableNameFilter, DbSqlSession.JDBC_METADATA_TABLE_TYPES);
            while (tables.next()) {
                String tableName = tables.getString("TABLE_NAME");
                tableName = tableName.toUpperCase();
                tableNames.add(tableName);
                log.debug("  retrieved activiti table name {}", tableName);
            }
        } finally {
            tables.close();
        }
    } catch (Exception e) {
        throw new ActivitiException("couldn't get activiti table names using metadata: " + e.getMessage(), e);
    }
    return tableNames;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) ActivitiException(org.activiti.engine.ActivitiException) SQLException(java.sql.SQLException)

Example 74 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class TaskEntityImpl method getSpecificVariable.

// Overridden to avoid fetching *all* variables (as is the case in the super // call)
@Override
protected VariableInstanceEntity getSpecificVariable(String variableName) {
    CommandContext commandContext = Context.getCommandContext();
    if (commandContext == null) {
        throw new ActivitiException("lazy loading outside command context");
    }
    VariableInstanceEntity variableInstance = commandContext.getVariableInstanceEntityManager().findVariableInstanceByTaskAndName(id, variableName);
    return variableInstance;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext)

Example 75 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JuelScriptEngine method importFunctions.

public static void importFunctions(ScriptContext ctx, String namespace, Object obj) {
    Class<?> clazz = null;
    if (obj instanceof Class) {
        clazz = (Class<?>) obj;
    } else if (obj instanceof String) {
        try {
            clazz = ReflectUtil.loadClass((String) obj);
        } catch (ActivitiException ae) {
            throw new ELException(ae);
        }
    } else {
        throw new ELException("Class or class name is missing");
    }
    Method[] methods = clazz.getMethods();
    for (Method m : methods) {
        int mod = m.getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isPublic(mod)) {
            String name = namespace + ":" + m.getName();
            ctx.setAttribute(name, m, ScriptContext.ENGINE_SCOPE);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ELException(javax.el.ELException) Method(java.lang.reflect.Method)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10