AnsweredAssumed Answered

TaskValidators, does not follow OCP

Question asked by asyncwait on Jul 29, 2016
I am trying to implement a custom task using "serviceTask" with "type" extension. Looks like extension types are hard-coded and does not follow OCP (Open/Closed principle) pattern.

For example, below code is a bottle neck as it checks the hard-coded task types. Would be happy to provide a patch or refactor the design.


// From src/main/java/org/activiti/validation/validator/impl/
  protected void verifyType(Process process, ServiceTask serviceTask, List<ValidationError> errors) {
    if (StringUtils.isNotEmpty(serviceTask.getType())) {

      if (!serviceTask.getType().equalsIgnoreCase("mail") && !serviceTask.getType().equalsIgnoreCase("mule") && !serviceTask.getType().equalsIgnoreCase("camel")
          && !(serviceTask.getType().equalsIgnoreCase("shell"))) {
        addError(errors, Problems.SERVICE_TASK_INVALID_TYPE, process, serviceTask, "Invalid or unsupported service task type");

      if (serviceTask.getType().equalsIgnoreCase("mail")) {
        validateFieldDeclarationsForEmail(process, serviceTask, serviceTask.getFieldExtensions(), errors);
      } else if (serviceTask.getType().equalsIgnoreCase("shell")) {
        validateFieldDeclarationsForShell(process, serviceTask, serviceTask.getFieldExtensions(), errors);