activity modeler 默认的节点属性是无法满足目前项目的使用需求的,所以需要设置个性化的属性,目前来看,前端改动较大,后端改动相对较小。

这里需求是 userTask 需要增加自定义属性

如:

1、stencilset.json

此文件定义了所有的节点属性,添加自定义属性:
{
 "name" : "url_package",
 "properties" : [ {
   "id" : "task_url",
   "type" : "String",
   "title" : "URL",
   "value" : "",
   "description" : "没卵用",
   "popular" : true
 } ]
},
{
    "name" : "message_package",
    "properties" : [ {
      "id" : "message_select",
      "type" : "bpm-select",
      "title" : "是否发送短信",
      "value" : "",
      "options" : "",
      "description" : "没卵用",
      "popular" : true,
      "refToView" : "multiinstance"
    } ]
  },
{
    "name" : "email_package",
    "properties" : [ {
      "id" : "email_select",
      "type" : "bpm-select",
      "title" : "是否发送邮件",
      "value" : "",
      "options" : "",
      "description" : "没卵用",
      "popular" : true,
      "refToView" : "multiinstance"
    } ]
  }
并将以上属性的 name 加入到 userTaskpropertyPackages属性中
propertyPackages:[ ... ,"url_package", "message_package", "email_package"]

2、properties.js

此文件定义了 stencilset.json 所有定义的 type类型,新增自定义类型

如果使用的是已有类型,无需新增,直接跳到本教程第五步

"bpm-select" : {
        "readModeTemplateUrl": "editor-app/configuration/properties/default-value-display-template.html",
        "writeModeTemplateUrl": "editor-app/configuration/properties/multiinstance-property-select-write-template.html"
    },

3、增加 type 对应的 html 和 is

multiinstance-property-select-write-template.html
<div ng-controller="BpmSelectCtrl">
    <select ng-model="property.value" ng-change="multiInstanceSelectChanged()">
        <option ng-repeat="x in property.options track by $index"  value="{{x.value}}" >{{x.name}}</option>
    </select>
</div>
properties-multiinstance-select-controller.js
var BpmSelectCtrl = [ '$scope', function($scope) {
  
  $scope.property.options = JSON.parse('[{"name":"是","value":"1"},{"name":"否","value":"0"}]');
    
//    console.log('request url:'+KISBPM.URL.getSelect());
//    new Ajax.Request(KISBPM.URL.getSelect(), {
//        asynchronous: false,
//        method: 'get',
//        onSuccess: function(result){
//            $scope.property.options = JSON.parse(result.responseText);
//        },
//        onFailure: function(){
//            console.log("get select value error");
//        }
//    });

    if ($scope.property.value == undefined && $scope.property.value == null)
    {
        console.log('$scope.property value is null ');
        $scope.property.value = 'no';
    }

    $scope.multiInstanceSelectChanged = function() {
        console.log('$scope.property multiInstanceSelectChanged :'+$scope.property);
        $scope.updatePropertyInModel($scope.property);
    };
}];

4、modeler.html

将自定义的 js 加入 modeler.html 中
<script src="editor-app/configuration/properties-multiinstance-select-controller.js" type="text/javascript"></script>

5、保存自定义属性

继承UserTaskJsonConverter并覆盖相应的解析方法:
public class CustomUserTaskJsonConverter extends UserTaskJsonConverter {
    @Override
        protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) {
        FlowElement flowElement = super.convertJsonToElement(elementNode, modelNode, shapeMap);
                UserTask userTask = (UserTask) flowElement;
                //将自己的属性添加到activiti自带的自定义属性中
                CustomProperty customProperty = new CustomProperty();
                customProperty.setName("task_url");
                customProperty.setSimpleValue(this.getPropertyValueAsString("task_url", elementNode));
                userTask.getCustomProperties().add(customProperty);
                customProperty = new CustomProperty();
                customProperty.setName("message_select");
                customProperty.setSimpleValue(this.getPropertyValueAsString("message_select", elementNode));
                userTask.getCustomProperties().add(customProperty);
                customProperty = new CustomProperty();
                customProperty.setName("email_select");
                customProperty.setSimpleValue(this.getPropertyValueAsString("email_select", elementNode));
                userTask.getCustomProperties().add(customProperty);
                return userTask;
    }
    @Override
        protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
        super.convertElementToJson(propertiesNode, baseElement);
    }
}
还需要将自己的转换器覆盖原来的转换器,首先定义类:
public class CustomBpmnJsonConverter extends BpmnJsonConverter {
    
    //通过继承开放convertersToJsonMap的访问
    public static Map<Class<? extends BaseElement>, Class<? extends BaseBpmnJsonConverter>> getConvertersToJsonMap(){
        return convertersToJsonMap;
    }

    //通过继承开放convertersToJsonMap的访问
    public static Map<String, Class<? extends BaseBpmnJsonConverter>> getConvertersToBpmnMap(){
        return convertersToBpmnMap;
    }
}
部署代码增加一行:
CustomBpmnJsonConverter.getConvertersToBpmnMap().put("UserTask", CustomUserTaskJsonConverter.class);
// ...
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
// ...

修改之后,重启服务进行测试

执行任务

然后 debuguserTask


参考