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;
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations