Skip to content

Commit

Permalink
Addition of many Event Types and correction of Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoung committed Mar 19, 2018
1 parent 5c14d1d commit 2a0a15e
Show file tree
Hide file tree
Showing 33 changed files with 578 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void findSubProcessActivityInformation(List<Activity> activityList, List<

}

public void createOpenGraphInformation() {
public void createOpenGraphInformation() { //TODO: why this is needed?
for(SequenceFlow sequenceFlow : getAllSequenceFlowList()) {
StringBuffer values = new StringBuffer();

Expand All @@ -73,8 +73,8 @@ public void createOpenGraphInformation() {
}
}
sequenceFlow.getRelationView().setValue(values.toString().substring(0, values.length() - 1).replace("@", ","));
sequenceFlow.getRelationView().setGeom(createGEOM(values.toString().substring(0, values.length() - 1)));
sequenceFlow.getRelationView().setStyle(createStyle());
// sequenceFlow.getRelationView().setGeom(createGEOM(values.toString().substring(0, values.length() - 1)));
// sequenceFlow.getRelationView().setStyle(createStyle());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
package org.uengine.processpublisher.bpmn.importer;

import org.omg.spec.bpmn._20100524.model.TBoundaryEvent;
import org.omg.spec.bpmn._20100524.model.TEventDefinition;
import org.uengine.kernel.bpmn.Event;
import org.uengine.kernel.bpmn.TimerEvent;
import org.uengine.processpublisher.Adapter;
import org.uengine.processpublisher.BPMNUtil;

import javax.xml.bind.JAXBElement;
import java.util.Hashtable;

public class TBoundaryEventAdapter extends TFlowNodeAdapter<TBoundaryEvent, TimerEvent> {
public class TBoundaryEventAdapter extends TFlowNodeAdapter<TBoundaryEvent, Event> {

@Override
public TimerEvent createActivity(TBoundaryEvent src, Hashtable keyedContext){
// String eventDefinitionClassName = eventDefinition.getClass().getName();
// String eventTypeName = eventDefinitionClassName.substring(0, eventDefinitionClassName.length() - "Definition".length());
public Event createActivity(TBoundaryEvent src, Hashtable keyedContext){

for(JAXBElement<? extends TEventDefinition> element : src.getEventDefinition()){

TEventDefinition eventDefinition = element.getValue();

Adapter adapter = BPMNUtil.getAdapter(eventDefinition.getClass(), true);
keyedContext.put("eventType", "Intermediate");
keyedContext.put("catching", true);
try {
Event event = (Event) adapter.convert(eventDefinition, keyedContext);
event.setAttachedToRef(src.getAttachedToRef().getLocalPart());
return event;
} catch (Exception e) {
e.printStackTrace();
}
}

throw new RuntimeException("There's no adaptor to convert Event type: " + src.getClass());

return new TimerEvent();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class TEscalationEventDefinitionAdapter implements Adapter<TEscalationEventDefinition, Event> {
@Override
public Event convert(TEscalationEventDefinition src, Hashtable keyedContext) throws Exception {
Event event = new Event();
Event event = createEvent(keyedContext);


if(src.getEscalationRef()!=null) {
String escalationCode = src.getEscalationRef().getLocalPart();
Expand All @@ -18,4 +19,29 @@ public Event convert(TEscalationEventDefinition src, Hashtable keyedContext) thr

return event;
}

private static Event createEvent(Hashtable keyedContext) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Event event;

String eventClassName = "Escalation";

String eventType = (String) keyedContext.get("eventType");

if(eventType == null){
eventType = "Intermediate";
}

eventClassName += eventType;

if(new Boolean(true).equals(keyedContext.get("catching"))){
eventClassName += "Catch";
}else{
eventClassName += "Throw";
}

eventClassName += "Event";

event = (Event) Thread.currentThread().getContextClassLoader().loadClass("org.uengine.kernel.bpmn." + eventClassName).newInstance();
return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public Event createActivity(TEvent src, Hashtable keyedContext){
return event;
}



}
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package org.uengine.kernel.bpmn.view;

import org.metaworks.EventContext;
import org.metaworks.annotation.ServiceMethod;
import org.uengine.kernel.MessageSequenceFlow;
import org.uengine.kernel.bpmn.SequenceFlow;
import org.uengine.modeling.IRelation;
import org.uengine.modeling.RelationPropertiesView;
import org.uengine.modeling.Symbol;
import org.uengine.modeling.modeler.symbol.ConnectorSymbol;

public class MessageFlowView extends SequenceFlowView {

Expand Down
43 changes: 41 additions & 2 deletions uengine-core/src/main/java/org/uengine/kernel/AbstractFlow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
package org.uengine.kernel;

import org.metaworks.annotation.Hidden;
import org.metaworks.annotation.Id;
import org.uengine.modeling.Relation;

/**
* Created by uengine on 2018. 3. 2..
*/
public class AbstractFlow {
}
public abstract class AbstractFlow extends Relation implements java.io.Serializable {
private static final long serialVersionUID = org.uengine.kernel.GlobalContext.SERIALIZATION_UID;

private String sourceRef;

@Hidden
public String getSourceRef() {
return sourceRef;
}

public void setSourceRef(String source) {
this.sourceRef = source;
}

private String targetRef;

@Hidden
public String getTargetRef() {
return targetRef;
}

public void setTargetRef(String target) {
this.targetRef = target;
}

String tracingTag;

@Id
@Hidden
public String getTracingTag() {
return tracingTag;
}

public void setTracingTag(String tag) {
tracingTag = tag;
}
}
23 changes: 19 additions & 4 deletions uengine-core/src/main/java/org/uengine/kernel/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.lang.reflect.Method;
import java.util.*;

import org.codehaus.jackson.map.ObjectMapper;
import org.metaworks.ContextAware;
import org.metaworks.MetaworksContext;
import org.metaworks.annotation.Face;
Expand Down Expand Up @@ -90,6 +91,7 @@ public abstract class Activity implements IElement, Validatable, java.io.Seriali
final public static String PVKEY_LOOPBACK_CNT = "_loopBackCnt";

public static final String STATUS_RESERVED = "Reserved";
static ObjectMapper objectMapper = new ObjectMapper();


transient MetaworksContext metaworksContext;
Expand Down Expand Up @@ -573,8 +575,6 @@ protected void afterComplete(ProcessInstance instance) throws Exception{
instance.getProcessTransactionContext().addExecutedActivityInstanceContext(new ActivityInstanceContext(this, instance));
//

if(!(this instanceof ProcessDefinition))
instance.getActivityCompletionHistory().add(getTracingTag());
}

/**
Expand Down Expand Up @@ -738,6 +738,10 @@ protected void onChanged(ProcessInstance instance) throws Exception{
* In the other hand, if you implement a asynchronous job of activity, you calls this fireComplete() after done (or after receiving the result).
*/
public void fireComplete(ProcessInstance instance) throws Exception{
//This must be before than the onEvent since connected activity would not recognize this is completed.
if(!(this instanceof ProcessDefinition))
instance.getActivityCompletionHistory().add(getTracingTag());

setTokenCount(instance, 0);
onEvent(ACTIVITY_DONE, instance, this);
}
Expand Down Expand Up @@ -1256,6 +1260,7 @@ private int evaluateContent_(ProcessInstance instance, String expression, Valida
int pos;
int endpos;
String key;

while((pos = expression.indexOf(starter, oldpos)) > -1){
pos += starter.length();
endpos = expression.indexOf(ending, pos);
Expand All @@ -1272,8 +1277,18 @@ private int evaluateContent_(ProcessInstance instance, String expression, Valida
System.out.println("Activity:: evaluateContent: key="+key);
Object val = Activity.getSpecialKeyValues(this, instance, key, validationContext);
// System.out.println("EMailActivity:: parseContent: val:"+val);
if(val!=null)
generating.append("" + val);

if(val!=null) {
if(val instanceof Map) {
try {
generating.append(objectMapper.writeValueAsString(val));
} catch (IOException e) {
throw new RuntimeException("failed to convert to JSON", e);
}
}else

generating.append("" + val);
}
}
oldpos = endpos + ending.length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.jayway.jsonpath.JsonPath;
import org.codehaus.jackson.JsonNode;
import org.uengine.kernel.bpmn.Event;
import org.uengine.kernel.bpmn.ServiceTask;
import org.uengine.processdesigner.mapper.TransformerMapping;
import org.uengine.uml.model.ObjectInstance;

Expand All @@ -22,7 +23,7 @@ public CatchingMessageEvent(){

@Override
protected void executeActivity(ProcessInstance instance) throws Exception {
//start listens...
if(checkLocalCall(instance)) return;

System.out.print("inside " + getClass().getName());
}
Expand All @@ -44,6 +45,48 @@ public void setDataOutputMapping(ParameterContext[] dataOutputMapping) {
this.dataOutputMapping = dataOutputMapping;
}

private boolean checkLocalCall(ProcessInstance instance) throws Exception {

ProcessDefinition processDefinition = getProcessDefinition();

Activity localCallSource = null;

if(processDefinition.getMessageFlows()!=null && processDefinition.getMessageFlows().size() > 0)
for(MessageFlow messageFlow : processDefinition.getMessageFlows()){

if(getTracingTag().equals(messageFlow.getTargetRef()) && messageFlow.isLocalCall()){
//this is local call
localCallSource = processDefinition.getActivity(messageFlow.getSourceRef());

break;
}
}

if(localCallSource!=null){

// only when the execution token has been triggered by the source activity of message flow
if(instance.getActivityCompletionHistory().contains(localCallSource.getTracingTag())) {

//if the message has been consumed already in this thread, pass this request: preventing recursive loop
if(instance.getProcessTransactionContext().getSharedContext("_messageConsumed_" + getTracingTag())!=null){
return true;
}

if (localCallSource instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) localCallSource;
String data = serviceTask.getInputPayloadTemplate();
}

instance.getProcessTransactionContext().setSharedContext("_messageConsumed_" + getTracingTag(), new Boolean(true));

onMessage(instance, null /* TODO: must be calculated from source activity and parameter input */);

return true;
}
}

return false;
}

public boolean onMessage(ProcessInstance instance, Object payload) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.uengine.kernel;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.uengine.processmanager.ProcessTransactionContext;
import org.uengine.processmanager.SimulatorTransactionContext;
import org.uengine.util.ActivityForLoop;
Expand All @@ -8,6 +10,7 @@
import org.uengine.webservices.worklist.WorkList;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.*;

/**
Expand Down Expand Up @@ -256,8 +259,9 @@ public void setSourceValue(String scopeByTracingTag, String key, Serializable va
// .append("key: " + key)
// .append("val: " + val)
// .append("instance id: " + getInstanceId());
//
// jh
// System.out.println(sb);
val = formatValue(key, val);

String fullKeyName = createFullKey(scopeByTracingTag, key, false);
if(val==null)
Expand All @@ -267,6 +271,29 @@ public void setSourceValue(String scopeByTracingTag, String key, Serializable va
//repository.put(getInstanceId()+":"+scopeByTracingTag+":"+key, val);
}

private Serializable formatValue(String key, Serializable val) throws Exception {

ProcessDefinition definition = getProcessDefinition();
ProcessVariable variable = definition.getProcessVariable(key);

if(variable!=null && variable.getTypeClassName()!=null){
if(variable.getTypeClassName().startsWith("java.lang.")){
Class type = Thread.currentThread().getContextClassLoader().loadClass(variable.getTypeClassName());

if(!val.getClass().isAssignableFrom(type)) { //need to convert

try {
val = (Serializable) ConvertUtils.convert(val, type);
}catch (Exception e){

}
}
}
}

return val;
}

public Serializable get(String scopeByTracingTag, String key) throws Exception{
String firstPart = key;

Expand Down Expand Up @@ -309,11 +336,15 @@ protected Serializable resolveParts(Serializable sourceValue, String key) throws

try {
int indexOfDot = key.indexOf(".");
if (indexOfDot > 0 && sourceValue instanceof BeanPropertyResolver) {

if (indexOfDot > 0){
String beanPath = key.substring(indexOfDot + 1);

return (Serializable) ((BeanPropertyResolver) sourceValue).getBeanProperty(beanPath);
if(sourceValue instanceof BeanPropertyResolver) {

return (Serializable) ((BeanPropertyResolver) sourceValue).getBeanProperty(beanPath);
}else{
return (Serializable) PropertyUtils.getProperty(sourceValue, beanPath);
}
}
}catch(ClassCastException e){
throw new Exception("Process variable's property value must be serializable", e);
Expand All @@ -335,6 +366,8 @@ protected Serializable resolveParts(Serializable sourceValue, String key) throws
}
}
}



return sourceValue;
}
Expand Down
Loading

0 comments on commit 2a0a15e

Please sign in to comment.