Skip to content

Commit

Permalink
Renaming + port of async executor PR #44
Browse files Browse the repository at this point in the history
  • Loading branch information
tijsrademakers committed Dec 15, 2016
1 parent 00dd0da commit 3c22315
Show file tree
Hide file tree
Showing 231 changed files with 1,280 additions and 1,506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DatabaseConfiguration {
@Bean
public DataSource dataSource() {

String jdbcUrl = environment.getProperty("datasource.url", "jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000");
String jdbcUrl = environment.getProperty("datasource.url", "jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000");
String jdbcDriver = environment.getProperty("datasource.driver", "org.h2.Driver");
String jdbcUsername = environment.getProperty("datasource.username", "sa");
String jdbcPassword = environment.getProperty("datasource.password", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ protected void createGroup(String groupId, String type) {
}

protected void initDemoUsers() {
createUser("kermit", "Kermit", "The Frog", "kermit", "kermit@activiti.org", null, Arrays.asList("management", "sales", "marketing", "engineering", "user", "admin"),
Arrays.asList("birthDate", "10-10-1955", "jobTitle", "Muppet", "location", "Hollywoord", "phone", "+123456789", "twitterName", "alfresco", "skype", "activiti_kermit_frog"));
createUser("kermit", "Kermit", "The Frog", "kermit", "kermit@flowable.org", null, Arrays.asList("management", "sales", "marketing", "engineering", "user", "admin"),
Arrays.asList("birthDate", "10-10-1955", "jobTitle", "Muppet", "location", "Hollywoord", "phone", "+123456789", "twitterName", "alfresco", "skype", "flowable_kermit_frog"));

createUser("gonzo", "Gonzo", "The Great", "gonzo", "gonzo@activiti.org", null, Arrays.asList("management", "sales", "marketing", "user"), null);
createUser("fozzie", "Fozzie", "Bear", "fozzie", "fozzie@activiti.org", null, Arrays.asList("marketing", "engineering", "user"), null);
createUser("gonzo", "Gonzo", "The Great", "gonzo", "gonzo@flowable.org", null, Arrays.asList("management", "sales", "marketing", "user"), null);
createUser("fozzie", "Fozzie", "Bear", "fozzie", "fozzie@flowable.org", null, Arrays.asList("marketing", "engineering", "user"), null);
}

protected void createUser(String userId, String firstName, String lastName, String password, String email, String imageResource, List<String> groups, List<String> userInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class UserTaskXMLConverter extends BaseBpmnXMLConverter {

protected Map<String, BaseChildElementParser> childParserMap = new HashMap<String, BaseChildElementParser>();

/** default attributes taken from bpmn spec and from activiti extension */
/** default attributes taken from bpmn spec and from extension namespace */
protected static final List<ExtensionAttribute> defaultUserTaskAttributes = Arrays.asList(
new ExtensionAttribute(ATTRIBUTE_FORM_FORMKEY),
new ExtensionAttribute(ATTRIBUTE_TASK_USER_DUEDATE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@

/**
* This abstract class takes the place of the now-deprecated CamelBehaviour class (which can still be used for legacy compatibility) and significantly improves on its flexibility. Additional
* implementations can be created that change the way in which Activiti interacts with Camel per your specific needs.
* implementations can be created that change the way in which Flowable interacts with Camel per your specific needs.
*
* Three out-of-the-box implementations of CamelBehavior are provided: (1) CamelBehaviorDefaultImpl: Works just like CamelBehaviour does; copies variables into and out of Camel as or from properties.
* (2) CamelBehaviorBodyAsMapImpl: Works by copying variables into and out of Camel using a Map<String,Object> object in the body. (3) CamelBehaviorCamelBodyImpl: Works by copying a single variable
* value into Camel as a String body and copying the Camel body into that same Activiti variable. The variable in Activiti must be named "camelBody".
* value into Camel as a String body and copying the Camel body into that same variable. The process variable in must be named "camelBody".
*
* The chosen implementation should be set within your ProcessEngineConfiguration. To specify the implementation using Spring, include the following line in your configuration file as part of the
* properties for "org.flowable.spring.SpringProcessEngineConfiguration":
*
* <property name="camelBehaviorClass" value="org.flowable.camel.impl.CamelBehaviorCamelBodyImpl"/>
*
* Note also that the manner in which variables are copied to Activiti from Camel has changed. It will always copy Camel properties to the Activiti variable set; they can safely be ignored, of course,
* if not required. It will conditionally copy the Camel body to the "camelBody" variable if it is of type java.lang.String, OR it will copy the Camel body to individual variables within Activiti if
* Note also that the manner in which variables are copied to the process engine from Camel has changed. It will always copy Camel properties to the process variables set; they can safely be ignored, of course,
* if not required. It will conditionally copy the Camel body to the "camelBody" variable if it is of type java.lang.String, OR it will copy the Camel body to individual variables within the process engine if
* it is of type Map<String,Object>.
*
* @author Ryan Johnston (@rjfsu), Tijs Rademakers, Saeid Mirzaei
Expand Down Expand Up @@ -115,17 +115,17 @@ public void execute(DelegateExecution execution) {
}
execution.setVariables(ExchangeUtils.prepareVariables(exchange, endpoint));

boolean isActiviti5Execution = false;
boolean isV5Execution = false;
if ((Context.getCommandContext() != null && Flowable5Util.isFlowable5ProcessDefinitionId(Context.getCommandContext(), execution.getProcessDefinitionId())) ||
(Context.getCommandContext() == null && Flowable5Util.getFlowable5CompatibilityHandler() != null)) {

isActiviti5Execution = true;
isV5Execution = true;
}

if (!handleCamelException(exchange, execution, isActiviti5Execution)) {
if (isActiviti5Execution) {
Flowable5CompatibilityHandler activiti5CompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
activiti5CompatibilityHandler.leaveExecution(execution);
if (!handleCamelException(exchange, execution, isV5Execution)) {
if (isV5Execution) {
Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
compatibilityHandler.leaveExecution(execution);
return;
}
leave(execution);
Expand All @@ -143,7 +143,7 @@ protected FlowableEndpoint getEndpoint(String key) {
return (FlowableEndpoint) e;
}
}
throw new FlowableException("Activiti endpoint not defined for " + key);
throw new FlowableException("Endpoint not defined for " + key);
}

protected Exchange createExchange(DelegateExecution activityExecution, FlowableEndpoint endpoint) {
Expand All @@ -156,22 +156,22 @@ protected Exchange createExchange(DelegateExecution activityExecution, FlowableE
return ex;
}

protected boolean handleCamelException(Exchange exchange, DelegateExecution execution, boolean isActiviti5Execution) {
protected boolean handleCamelException(Exchange exchange, DelegateExecution execution, boolean isV5Execution) {
Exception camelException = exchange.getException();
boolean notHandledByCamel = exchange.isFailed() && camelException != null;
if (notHandledByCamel) {
if (camelException instanceof BpmnError) {
if (isActiviti5Execution) {
Flowable5CompatibilityHandler activiti5CompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
activiti5CompatibilityHandler.propagateError((BpmnError) camelException, execution);
if (isV5Execution) {
Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
compatibilityHandler.propagateError((BpmnError) camelException, execution);
return true;
}
ErrorPropagation.propagateError((BpmnError) camelException, execution);
return true;
} else {
if (isActiviti5Execution) {
Flowable5CompatibilityHandler activiti5CompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
if (activiti5CompatibilityHandler.mapException(camelException, execution, mapExceptions)) {
if (isV5Execution) {
Flowable5CompatibilityHandler ompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
if (ompatibilityHandler.mapException(camelException, execution, mapExceptions)) {
return true;
} else {
throw new FlowableException("Unhandled exception on camel route", camelException);
Expand Down Expand Up @@ -233,11 +233,11 @@ protected void setAppropriateCamelContext(DelegateExecution execution) {
if ((Context.getCommandContext() != null && Flowable5Util.isFlowable5ProcessDefinitionId(Context.getCommandContext(), execution.getProcessDefinitionId())) ||
(Context.getCommandContext() == null && Flowable5Util.getFlowable5CompatibilityHandler() != null)) {

Flowable5CompatibilityHandler activiti5CompatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
camelContextObj = (CamelContext) activiti5CompatibilityHandler.getCamelContextObject(camelContextValue);
Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
camelContextObj = (CamelContext) compatibilityHandler.getCamelContextObject(camelContextValue);

} else {
// Convert it to a SpringProcessEngineConfiguration. If this doesn't work, throw a RuntimeException. (ActivitiException extends RuntimeException.)
// Convert it to a SpringProcessEngineConfiguration. If this doesn't work, throw a RuntimeException.
try {
SpringProcessEngineConfiguration springConfiguration = (SpringProcessEngineConfiguration) engineConfiguration;
if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
Expand All @@ -252,7 +252,7 @@ protected void setAppropriateCamelContext(DelegateExecution execution) {
camelContextObj = (CamelContext) ctx;

} catch (Exception e) {
throw new FlowableException("Expecting a SpringProcessEngineConfiguration for the Activiti Camel module.", e);
throw new FlowableException("Expecting a SpringProcessEngineConfiguration for the Camel module.", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/**
* This class contains one method - prepareVariables - that is used to copy variables from Camel into Activiti.
* This class contains one method - prepareVariables - that is used to copy variables from Camel into the process engine.
*
* @author Ryan Johnston (@rjfsu), Tijs Rademakers, Arnold Schrijver
* @author Saeid Mirzaei
Expand All @@ -35,20 +35,17 @@ public class ExchangeUtils {
static Map<String, Pattern> patternsCache = new HashMap<String, Pattern >();

/**
* Copies variables from Camel into Activiti.
* Copies variables from Camel into the process engine.
*
* This method will copy the Camel body to the "camelBody" variable. It will copy the Camel body to individual variables within Activiti if it is of type
* This method will copy the Camel body to the "camelBody" variable. It will copy the Camel body to individual variables within Flowable if it is of type
* Map&lt;String, Object&gt; or it will copy the Object as it comes.
* <ul>
* <li>If the copyVariablesFromProperties parameter is set on the endpoint, the properties are copied instead</li>
* <li>If the copyCamelBodyToBodyAsString parameter is set on the endpoint, the camelBody is converted to java.lang.String and added as a camelBody variable,
* unless it is a Map&lt;String, Object&gt;</li>
* <li>If the copyVariablesFromHeader parameter is set on the endpoint, each Camel Header will be copied to an individual variable within Activiti.</li>
* <li>If the copyVariablesFromHeader parameter is set on the endpoint, each Camel Header will be copied to an individual process variable.</li>
* </ul>
*
* @param exchange The Camel Exchange object
* @param activitiEndpoint The ActivitiEndpoint implementation
* @return A Map&lt;String, Object&gt; containing all of the variables to be used in Activiti
*/

private static Pattern createPattern(String propertyString, boolean asBoolean) {
Expand All @@ -73,10 +70,10 @@ private static boolean isBoolean(String booleanString) {
return lower.equals("true") || lower.equals("false");
}

public static Map<String, Object> prepareVariables(Exchange exchange, FlowableEndpoint activitiEndpoint) {
public static Map<String, Object> prepareVariables(Exchange exchange, FlowableEndpoint endpoint) {
Map<String, Object> camelVarMap = new HashMap<String, Object>();

String copyProperties = activitiEndpoint.getCopyVariablesFromProperties();
String copyProperties = endpoint.getCopyVariablesFromProperties();
// don't other if the property is null, or is a false
if (StringUtils.isNotEmpty(copyProperties)
&& (!isBoolean(copyProperties) || Boolean.parseBoolean(copyProperties))) {
Expand All @@ -94,17 +91,17 @@ public static Map<String, Object> prepareVariables(Exchange exchange, FlowableEn
}
}

String copyHeader = activitiEndpoint.getCopyVariablesFromHeader();
String copyHeader = endpoint.getCopyVariablesFromHeader();
if (!StringUtils.isEmpty(copyHeader) &&
(!isBoolean(copyHeader) || Boolean.parseBoolean(copyHeader))) {

Pattern pattern = createPattern(copyHeader, Boolean.parseBoolean(copyHeader));

boolean isSetProcessInitiator = activitiEndpoint.isSetProcessInitiator();
boolean isSetProcessInitiator = endpoint.isSetProcessInitiator();
for (Map.Entry<String, Object> header : exchange.getIn().getHeaders().entrySet()) {
// Don't pass the process initiator header as a variable.

if ((!isSetProcessInitiator || activitiEndpoint.getProcessInitiatorHeaderName().equals(header.getKey()))
if ((!isSetProcessInitiator || endpoint.getProcessInitiatorHeaderName().equals(header.getKey()))
&& (pattern == null || pattern.matcher(header.getKey()).matches())) {
camelVarMap.put(header.getKey(), header.getValue());
}
Expand All @@ -126,7 +123,7 @@ public static Map<String, Object> prepareVariables(Exchange exchange, FlowableEn
}
}
} else {
if (activitiEndpoint.isCopyCamelBodyToBodyAsString() && !(camelBody instanceof String)) {
if (endpoint.isCopyCamelBodyToBodyAsString() && !(camelBody instanceof String)) {
camelBody = exchange.getContext().getTypeConverter().convertTo(String.class, exchange, camelBody);
}
if (camelBody != null) {
Expand All @@ -144,24 +141,24 @@ public static Map<String, Object> prepareVariables(Exchange exchange, FlowableEn
* Returns null if no header name was specified on the Camel route.
*
* @param exchange The Camel Exchange object
* @param activitiEndpoint The ActivitiEndpoint implementation
* @param endPoint The endPoint implementation
* @return The userId of the user to be set as the process initiator
*/
public static String prepareInitiator(Exchange exchange, FlowableEndpoint activitiEndpoint) {
public static String prepareInitiator(Exchange exchange, FlowableEndpoint endpoint) {

String initiator = null;
if (activitiEndpoint.isSetProcessInitiator()) {
if (endpoint.isSetProcessInitiator()) {
try {
initiator = exchange.getIn().getHeader(activitiEndpoint.getProcessInitiatorHeaderName(), String.class);
initiator = exchange.getIn().getHeader(endpoint.getProcessInitiatorHeaderName(), String.class);
}
catch (TypeConversionException e) {
throw new FlowableException("Initiator header '" +
activitiEndpoint.getProcessInitiatorHeaderName() + "': Value must be of type String.", e);
endpoint.getProcessInitiatorHeaderName() + "': Value must be of type String.", e);
}

if (StringUtils.isEmpty(initiator)) {
throw new FlowableException("Initiator header '" +
activitiEndpoint.getProcessInitiatorHeaderName() + "': Value must be provided");
endpoint.getProcessInitiatorHeaderName() + "': Value must be provided");
}
}
return initiator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class FlowableEndpoint extends DefaultEndpoint {

protected RepositoryService repositoryService;

protected FlowableConsumer activitiConsumer;
protected FlowableConsumer flowableConsumer;

protected boolean copyVariablesToProperties;

Expand Down Expand Up @@ -73,10 +73,10 @@ public FlowableEndpoint(String uri, CamelContext camelContext) {
}

public void process(Exchange ex) throws Exception {
if (activitiConsumer == null) {
throw new FlowableException("Activiti consumer not defined for " + getEndpointUri());
if (flowableConsumer == null) {
throw new FlowableException("Consumer not defined for " + getEndpointUri());
}
activitiConsumer.getProcessor().process(ex);
flowableConsumer.getProcessor().process(ex);
}

public Producer createProducer() throws Exception {
Expand All @@ -92,14 +92,14 @@ public Consumer createConsumer(Processor processor) throws Exception {
}

protected void addConsumer(FlowableConsumer consumer) {
if (activitiConsumer != null) {
throw new FlowableException("Activiti consumer already defined for " + getEndpointUri() + "!");
if (flowableConsumer != null) {
throw new FlowableException("Consumer already defined for " + getEndpointUri() + "!");
}
activitiConsumer = consumer;
flowableConsumer = consumer;
}

protected void removeConsumer() {
activitiConsumer = null;
flowableConsumer = null;
}

public boolean isSingleton() {
Expand Down
Loading

0 comments on commit 3c22315

Please sign in to comment.