增加模型工具类
This commit is contained in:
parent
bf6b26083f
commit
c44bfd42e3
@ -0,0 +1,52 @@
|
||||
package com.actionsoft.apps.coe.pal.pal.repository.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class DiagramUtil {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置画布大小
|
||||
* @param elements
|
||||
*/
|
||||
public static void setDiagramHeightWidth(JSONObject definition, JSONObject elements) {
|
||||
// 获取最大宽高,给100长度富余
|
||||
JSONObject maxHW = getMaxPositionXY(elements);
|
||||
int maxX = maxHW.getInteger("maxX") + 150;
|
||||
int maxH = maxHW.getInteger("maxY") + 150;
|
||||
JSONObject page = definition.getJSONObject("page");
|
||||
int pageW = page.getInteger("width");
|
||||
int pageH = page.getInteger("height");
|
||||
page.put("width", pageW > maxX ? pageW : maxX);
|
||||
page.put("height", pageH > maxH ? pageH : maxH);
|
||||
definition.put("page", page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JSONObject getMaxPositionXY(JSONObject elements) {
|
||||
int maxX = -99999;
|
||||
int maxY = -99999;
|
||||
Iterator<String> it = elements.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
JSONObject shape = elements.getJSONObject(key);
|
||||
String shapeName = shape.getString("name");
|
||||
if(!"linker".equals(shapeName)) {
|
||||
JSONObject props = shape.getJSONObject("props");
|
||||
int x = props.getInteger("x");
|
||||
int y = props.getInteger("y");
|
||||
maxX = maxX < x ? x : maxX;
|
||||
maxY = maxY < y ? y : maxY;
|
||||
}
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("maxX", maxX);
|
||||
result.put("maxY", maxY);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,280 @@
|
||||
package com.actionsoft.apps.coe.pal.pal.repository.util;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.datamigration.util.ProcessUtil;
|
||||
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.CoeDesignerShapeAPIManager;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ShapeUtil {
|
||||
|
||||
/**
|
||||
* BPMN图并不全部使用,给定范围
|
||||
*/
|
||||
private static List<String> bpmnShapeScope() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("startEvent");// 开始事件
|
||||
list.add("messageStartEvent");// 消息开始事件
|
||||
list.add("timerStartEvent");// 时间开始事件
|
||||
list.add("signalStartEvent");// 信号开始事件
|
||||
list.add("userTask");// 人工任务
|
||||
list.add("serviceTask");// 服务任务
|
||||
list.add("manualTask");// 手工任务
|
||||
list.add("scriptTask");// 脚本任务
|
||||
list.add("inclusiveGateway");// 包容网关
|
||||
list.add("complexGateway");// 复杂网关
|
||||
list.add("eventBasedGateway");// 事件网关
|
||||
list.add("parallelGateway");// 并行网关
|
||||
list.add("exclusiveGateway");// 排他网关
|
||||
list.add("timerIntermediateCatchEvent");// 捕获时间事件
|
||||
list.add("messageIntermediateCatchEvent");// 捕获消息事件
|
||||
list.add("signalIntermediateCatchEvent");// 捕获信号事件
|
||||
list.add("messageIntermediateThrowingEvent");// 抛出消息事件
|
||||
list.add("signalIntermediateThrowingEvent");// 抛出信号事件
|
||||
list.add("messageBoundaryInterrputingEvent");// 边界消息事件
|
||||
list.add("signalBoundaryInterrputingEvent");// 边界信号事件
|
||||
list.add("errorBoundaryInterrputingEvent");// 边界错误事件
|
||||
list.add("endEvent");// 结束事件
|
||||
list.add("terminateEndEvent");// 终止事件
|
||||
list.add("messageEndEvent");// 消息结束事件
|
||||
list.add("signalEndEvent");// 信号结束事件
|
||||
list.add("errorEndEvent");// 错误结束事件
|
||||
list.add("callActivityCallingProcess");// 调用子流程
|
||||
list.add("group");// 组
|
||||
// list.add("textAnnotation");// 注释
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取流程类别下所有模型的形状title
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, List<String>> getProcessShapeTitles() {
|
||||
Map<String, List<String>> result = new HashMap<>();
|
||||
// 获取流程类别下所有的模型分类
|
||||
List<String> methods = ProcessUtil.getProcessCategoryCategoryMehtodList();
|
||||
for (String methodId : methods) {
|
||||
List<String> list = new ArrayList<>();
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("title")) {
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name"))) {
|
||||
list.add(shapeObj.getString("title"));
|
||||
}
|
||||
} else {
|
||||
list.add(shapeObj.getString("title"));
|
||||
}
|
||||
}
|
||||
}
|
||||
result.put(methodId, list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> getProcessShapeTypeList(String methodId) {
|
||||
List<String> result = new ArrayList<>();
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("title")) {
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name"))) {
|
||||
result.add(shapeObj.getString("title"));
|
||||
}
|
||||
} else {
|
||||
result.add(shapeObj.getString("title"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JSONArray getProcessShapeTypeArr(String methodId) {
|
||||
JSONArray result = new JSONArray();
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("title")) {
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name"))) {
|
||||
result.add(shapeObj.getString("title"));
|
||||
}
|
||||
} else {
|
||||
result.add(shapeObj.getString("title"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Set<String> getProcessMethodAttrNames(String wsId, String methodId) {
|
||||
Set<String> result = new HashSet<>();
|
||||
List<PALMethodAttributeModel> attributeModelList = CoeDesignerShapeAPIManager.getInstance().getAllValidShapeAttributeModels(wsId, methodId);
|
||||
for (PALMethodAttributeModel attributeModel : attributeModelList) {
|
||||
result.add(attributeModel.getNewTitle());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getProcessShapeName(String methodId, String shapeTitle) {
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("title")) {
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name")) && shapeObj.getString("title").equals(shapeTitle)) {
|
||||
return shapeObj.getString("name");
|
||||
}
|
||||
} else {
|
||||
if (shapeObj.getString("title").equals(shapeTitle)) {
|
||||
return shapeObj.getString("name");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程节点定义
|
||||
* @param methodId 类型
|
||||
* @param shapeTitle 节点默认标题
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getProcessShapeDefinition(String methodId, String shapeTitle) {
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("title")) {
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name")) && shapeObj.getString("title").equals(shapeTitle)) {
|
||||
return shapeObj;
|
||||
}
|
||||
} else {
|
||||
if (shapeObj.getString("title").equals(shapeTitle)) {
|
||||
return shapeObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流程节点定义
|
||||
* @param methodId 类型
|
||||
* @param shapeName 节点类型
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getProcessShapeDefinitionByName(String methodId, String shapeName) {
|
||||
JSONArray shapes = CoeDesignerUtil.getShapeDefinition(methodId);
|
||||
for (Object shape : shapes) {
|
||||
JSONObject shapeObj = (JSONObject) shape;
|
||||
if (shapeObj.containsKey("name")) {
|
||||
String name = shapeObj.getString("name");
|
||||
if (methodId.contains("bpmn")) {
|
||||
if (bpmnShapeScope().contains(shapeObj.getString("name")) && name.equals(shapeName)) {
|
||||
return shapeObj;
|
||||
}
|
||||
} else {
|
||||
if (name.equals(shapeName)) {
|
||||
return shapeObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体流程类别下的扩展属性列表
|
||||
* @param methodId
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getProcessUseShapeMethodAttrByShapeName(String wsId, String shapeMethod, String methodId, String shapeName) {
|
||||
JSONObject result = new JSONObject();
|
||||
List<PALMethodAttributeModel> attributeModelList = CoeDesignerShapeAPIManager.getInstance().getValidAndUseAttributeModels(wsId, shapeMethod, shapeName, methodId);
|
||||
for (PALMethodAttributeModel attributeModel : attributeModelList) {
|
||||
String scope = attributeModel.getScope();
|
||||
if (scope.contains("*") || "*".equals(scope) || scope.contains(shapeName)) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("readonly", attributeModel.getReadonly());
|
||||
obj.put("id", attributeModel.getKey());
|
||||
obj.put("key", attributeModel.getKey());
|
||||
obj.put("scope", attributeModel.getScope());
|
||||
obj.put("name", attributeModel.getTitle());
|
||||
obj.put("title", attributeModel.getNewTitle());
|
||||
obj.put("type", attributeModel.getType());
|
||||
obj.put("ref", attributeModel.getRef());
|
||||
obj.put("groupPath", attributeModel.getGroupPath());
|
||||
result.put(attributeModel.getKey(), obj);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体流程类别下的扩展属性列表
|
||||
* @param methodId
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getProcessShapeMethodAttr(String wsId, String methodId, String shapeTitle) {
|
||||
JSONObject result = new JSONObject();
|
||||
// 获取图形名称的
|
||||
String shapeName = getProcessShapeName(methodId, shapeTitle);
|
||||
if (shapeName == null) {
|
||||
return result;
|
||||
}
|
||||
List<PALMethodAttributeModel> attributeModelList = CoeDesignerShapeAPIManager.getInstance().getAllValidShapeAttributeModels(wsId, methodId);
|
||||
for (PALMethodAttributeModel attributeModel : attributeModelList) {
|
||||
String scope = attributeModel.getScope();
|
||||
if (scope.contains("*") || "*".equals(scope) || scope.contains(shapeName)) {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("readonly", attributeModel.getReadonly());
|
||||
obj.put("id", attributeModel.getKey());
|
||||
obj.put("key", attributeModel.getKey());
|
||||
obj.put("scope", attributeModel.getScope());
|
||||
obj.put("name", attributeModel.getTitle());
|
||||
obj.put("title", attributeModel.getNewTitle());
|
||||
obj.put("type", attributeModel.getType());
|
||||
obj.put("ref", attributeModel.getRef());
|
||||
obj.put("groupPath", attributeModel.getGroupPath());
|
||||
result.put(attributeModel.getNewTitle(), obj);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 具体流程类别下的扩展属性列表
|
||||
* @param methodId
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject getProcessShapeMethodAttrById(String wsId, String methodId, String attrId) {
|
||||
JSONObject result = new JSONObject();
|
||||
List<PALMethodAttributeModel> attributeModelList = CoeDesignerShapeAPIManager.getInstance().getAllValidShapeAttributeModels(wsId, methodId);
|
||||
for (PALMethodAttributeModel attributeModel : attributeModelList) {
|
||||
if (attrId.equals(attributeModel.getKey())) {
|
||||
result.put("readonly", attributeModel.getReadonly());
|
||||
result.put("pid", attributeModel.getGroupPath());
|
||||
result.put("id", attributeModel.getKey());
|
||||
result.put("key", attributeModel.getKey());
|
||||
result.put("scope", attributeModel.getScope());
|
||||
result.put("name", attributeModel.getTitle());
|
||||
result.put("title", attributeModel.getNewTitle());
|
||||
result.put("type", attributeModel.getType());
|
||||
result.put("ref", attributeModel.getRef());
|
||||
result.put("value", attributeModel.getValue());
|
||||
result.put("groupPath", attributeModel.getGroupPath());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user