cancel
Showing results for 
Search instead for 
Did you mean: 

UserTask + ServiceTask

vire7777
Champ in-the-making
Champ in-the-making
Hi dear Activiti members

I'm searching for a way to solve one of my problem.
I would love to create a task that would be a mix of a userTask and a serviceTask
In fact I want to find a solution to let my workflow ask some parameters to the user with an interface and, when the parameters are in and the user is ok, then launch a java class treatment.

I know this is possible with 2 tasks but is that possible too with one ?

Further, could it be possible to create a task like that in the palette.
I need it for my company as we want to let the clients create their own workflow with our own palette tasks. And all these tasks need to launch a java treatment with some informations the user has to enter first.

Can you help me ?

Vivien
12 REPLIES 12

jbarrez
Star Contributor
Star Contributor
No Java, doesn't have multiple inheritance. What I mean you have two fields, like the javadelegate field you now have. But dont worry about it, it's only a suggestion.

Now, to customize the palette, thats quite a different beast, which is described here: http://activiti.org/userguide/index.html#eclipseDesignerCustomizingPalette

vire7777
Champ in-the-making
Champ in-the-making
Yes i did it first with my last classes extending AbstractCustomServiceTask
But with the new one, i tried it but without success… i can t see it in the palette

Here my new Abstract class code :
<code>
public abstract class EffiTaskActivitiBehavior extends UserTaskActivityBehavior implements CustomServiceTask, ActivityBehavior, ExecutionListener {

protected TaskDefinition taskDefinition;
protected JavaDelegate javaDelegate;
private static final String DEFAULT_EXTENSIONS_DRAWER_NAME = "Extensions";

public String contributeToPaletteDrawer() {
  return DEFAULT_EXTENSIONS_DRAWER_NAME;
}

public final String getId() {
  return getClass().getCanonicalName();
}

public final DelegateType getDelegateType() {
  return getDelegateType(getRuntimeAnnotation());
}

private DelegateType getDelegateType(final Runtime annotation) {

  DelegateType result = DelegateType.NONE;

  if (annotation != null) {
   if (isDelegateDefined(annotation.javaDelegateClass())) {
    result = DelegateType.JAVA_DELEGATE_CLASS;
   } else if (isDelegateDefined(annotation.expression())) {
    result = DelegateType.EXPRESSION;
   } else if (isDelegateDefined(annotation.javaDelegateExpression())) {
    result = DelegateType.JAVA_DELEGATE_EXPRESSION;
   }
  }

  return result;
}

private boolean isDelegateDefined(final String definition) {
  return definition != null && !definition.isEmpty() && !"".equals(definition);
}

public final String getDelegateSpecification() {

  String result = "";

  final DelegateType delegateType = getDelegateType();

  if (!DelegateType.NONE.equals(delegateType)) {

   Runtime runtimeAnnotation = getRuntimeAnnotation();
   if (runtimeAnnotation != null) {
    switch (delegateType) {
    case JAVA_DELEGATE_CLASS:
     result = runtimeAnnotation.javaDelegateClass();
     break;
    case EXPRESSION:
     result = runtimeAnnotation.expression();
     break;
    case JAVA_DELEGATE_EXPRESSION:
     result = runtimeAnnotation.javaDelegateExpression();
     break;
    default:
     break;
    }
   }

  }

  return result;
}

private Runtime getRuntimeAnnotation() {

  Runtime result = null;

  final Annotation annotation = this.getClass().getAnnotation(Runtime.class);

  if (annotation != null && Runtime.class.isAssignableFrom(annotation.getClass())) {
   result = ((Runtime) annotation);
  }

  return result;
}

public abstract String getName();

public String getDescription() {
  return getName();
}

public String getSmallIconPath() {
  return null;
}

public String getLargeIconPath() {
  return getSmallIconPath();
}

public String getShapeIconPath() {
  return getSmallIconPath();
}

public DiagramBaseShape getDiagramBaseShape() {
  return DiagramBaseShape.ACTIVITY;
}

public Integer getOrder() {
  return 1;
}

@SuppressWarnings("rawtypes")
public String toString() {
  StringBuilder builder = new StringBuilder();

  final Class clazz = this.getClass();
  final Field[] fields = clazz.getDeclaredFields();

  builder.append("Custom Service Task ").append(this.getClass().getSimpleName()).append("\n\tID:\t").append(this.getId()).append("\n\tProvider class:\t").append(this.getClass().getCanonicalName()).append("\n\tPalette drawer:\t").append(contributeToPaletteDrawer()).append("\n\tProperties:\n");

  for (final Field field : fields) {
   final Annotation[] annotations = field.getAnnotations();
   for (final Annotation annotation : annotations) {
    if (annotation instanceof Property) {
     builder.append("\t\t").append(field.getName()).append(" (").append(((Property) annotation).type().name()).append(")\n");
    }
   }
  }

  boolean hierarchyOpen = true;
  Class currentClass = clazz;
  while (hierarchyOpen) {
   currentClass = currentClass.getSuperclass();
   if (CustomServiceTask.class.isAssignableFrom(currentClass)) {
    for (Field currentSuperclassField : currentClass.getDeclaredFields()) {
     final Annotation[] currentSuperclassFieldAnnotations = currentSuperclassField.getAnnotations();
     for (final Annotation currentSuperclassFieldAnnotation : currentSuperclassFieldAnnotations) {
      if (currentSuperclassFieldAnnotation instanceof Property) {
       builder.append("\t\t").append(currentSuperclassField.getName()).append(" (").append(((Property) currentSuperclassFieldAnnotation).type().name()).append(") (inherited from ").append(currentClass.getSimpleName()).append(")\n");
      }
     }
    }
   } else {
    hierarchyOpen = false;
   }
  }

  return builder.toString();
}

public EffiTaskActivitiBehavior(ExpressionManager expressionManager, TaskDefinition taskDefinition) {
  super(expressionManager, taskDefinition);
}

public EffiTaskActivitiBehavior(ExpressionManager expressionManager, TaskDefinition taskDefinition, JavaDelegate javaDelegate) {
  super(expressionManager, taskDefinition);
  this.javaDelegate = javaDelegate;
}

public void execute(ActivityExecution execution) throws Exception {
  execute(execution);
  execute((DelegateExecution) execution);
  leave(execution);
}

public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
  leave(execution);
}

public void notify(DelegateExecution execution) throws Exception {
  execute((DelegateExecution) execution);
}

public void execute(DelegateExecution execution) throws Exception {
  Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation(javaDelegate, execution));
}
}
</code>

And here my class code i want to see in the palette :

<code>
@Help(displayHelpShort = "Send a new mail to the different owners")
@Runtime(javaDelegateClass = "com.effisoft.orion.fw.workflow.MailTask2")
public class MailTask2 extends EffiTaskActivitiBehavior {

public MailTask2(ExpressionManager expressionManager, TaskDefinition taskDefinition) {
  super(expressionManager, taskDefinition);
}

public MailTask2(ExpressionManager expressionManager, TaskDefinition taskDefinition, JavaDelegate javaDelegate) {
  super(expressionManager, taskDefinition, javaDelegate);
}

@Property(type = PropertyType.TEXT, displayName = "Recipient List", required = true)
private String recipients;

@Property(type = PropertyType.TEXT, displayName = "Subject", required = true)
private String subject;

@Property(type = PropertyType.TEXT, displayName = "Body", required = true)
private String body;

@Property(type = PropertyType.TEXT, displayName = "Attachment List")
private String attachments;

@Override
public String getName() {
  return "MailTask2";
}

@Override
public String contributeToPaletteDrawer() {
  return "Effisoft Corporation";
}

@Override
public String getSmallIconPath() {
  return "icons/icon.gif";
}

}
</code>

Can you tell me where i m wrong ?
I just want to create an example to work with and implement my own class then

vire7777
Champ in-the-making
Champ in-the-making
Well i try to create the same than the human task just by copying the activiti code and i can t see it in the palette too…
Seems really strange. I think i miss something.