1
0

调整核心类的创建方式

This commit is contained in:
2025-01-03 16:10:37 +08:00
parent 45ce5a2615
commit 743e2db17d
8 changed files with 76 additions and 91 deletions

View File

@@ -79,13 +79,13 @@ public class FlowableInstance {
@SneakyThrows
public com.lanyuanxiaoyao.flowable.core.model.FlowableInstance toFlowableInstance() {
return new com.lanyuanxiaoyao.flowable.core.model.FlowableInstance(
instanceId,
currentNodeId,
(FlowableMetadata) bytesToObject(this.metadata),
status,
createdTime,
updatedTime
);
return com.lanyuanxiaoyao.flowable.core.model.FlowableInstance.builder()
.instanceId(instanceId)
.currentNodeId(currentNodeId)
.metadata((FlowableMetadata) bytesToObject(this.metadata))
.status(status)
.createdTime(createdTime)
.updatedTime(updatedTime)
.build();
}
}

View File

@@ -66,8 +66,15 @@ public class FlowableNode {
}
public com.lanyuanxiaoyao.flowable.core.model.FlowableNode toFlowableNode() {
com.lanyuanxiaoyao.flowable.core.model.FlowableNode node = new com.lanyuanxiaoyao.flowable.core.model.FlowableNode(nodeId, name, description, type, handler, targets, null, createdTime);
node.setUpdatedTime(updateTime);
return node;
return com.lanyuanxiaoyao.flowable.core.model.FlowableNode.builder()
.nodeId(nodeId)
.name(name)
.description(description)
.type(type)
.handler(handler)
.targets(targets)
.createdTime(createdTime)
.updatedTime(updateTime)
.build();
}
}

View File

@@ -25,7 +25,7 @@ public class MapHelper {
return map;
}
public static Map<String, Object> empty() {
public static <K, V> Map<K, V> empty() {
return new HashMap<>(0);
}

View File

@@ -3,6 +3,7 @@ package com.lanyuanxiaoyao.flowable.core.manager;
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
import com.lanyuanxiaoyao.flowable.core.helper.StringHelper;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
import com.lanyuanxiaoyao.flowable.core.model.FlowableHistory;
@@ -68,7 +69,11 @@ public abstract class FlowableManager {
public String start(String nodeId, Map<String, Object> metadata) {
FlowableNode node = repository.getNode(nodeId);
FlowableInstance instance = new FlowableInstance(createId(), node.getNodeId(), new FlowableMetadata(metadata));
FlowableInstance instance = FlowableInstance.builder()
.instanceId(createId())
.currentNodeId(node.getNodeId())
.metadata(new FlowableMetadata(metadata))
.build();
repository.saveInstance(instance);
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {

View File

@@ -1,6 +1,8 @@
package com.lanyuanxiaoyao.flowable.core.model;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -8,6 +10,8 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableHistory {
private final String historyId;
private final String instanceId;
@@ -18,12 +22,4 @@ public class FlowableHistory {
public FlowableHistory(String historyId, String instanceId, FlowableAction action, String comment) {
this(historyId, instanceId, action, comment, LocalDateTime.now());
}
public FlowableHistory(String historyId, String instanceId, FlowableAction action, String comment, LocalDateTime createdTime) {
this.historyId = historyId;
this.instanceId = instanceId;
this.action = action;
this.comment = comment;
this.createdTime = createdTime;
}
}

View File

@@ -2,6 +2,8 @@ package com.lanyuanxiaoyao.flowable.core.model;
import java.time.LocalDateTime;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -9,31 +11,20 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableInstance {
private final String instanceId;
private final FlowableMetadata metadata;
private final LocalDateTime createdTime;
@Builder.Default
private final FlowableMetadata metadata = new FlowableMetadata();
@Builder.Default
private final LocalDateTime createdTime = LocalDateTime.now();
private String currentNodeId;
private Status status;
private LocalDateTime updatedTime;
public FlowableInstance(String instanceId, String currentNodeId) {
this(instanceId, currentNodeId, new FlowableMetadata(), Status.RUNNING, LocalDateTime.now(), LocalDateTime.now());
}
public FlowableInstance(String instanceId, String currentNodeId, FlowableMetadata metadata) {
this(instanceId, currentNodeId, metadata, Status.RUNNING, LocalDateTime.now(), LocalDateTime.now());
}
public FlowableInstance(String instanceId, String currentNodeId, FlowableMetadata metadata, Status status, LocalDateTime createdTime, LocalDateTime updatedTime) {
this.instanceId = instanceId;
this.metadata = metadata;
this.createdTime = createdTime;
this.currentNodeId = currentNodeId;
this.status = status;
this.updatedTime = updatedTime;
}
@Builder.Default
private Status status = Status.RUNNING;
@Builder.Default
private LocalDateTime updatedTime = LocalDateTime.now();
public void addMetadata(Map<String, Object> metadata) {
this.metadata.putAll(metadata);

View File

@@ -1,9 +1,11 @@
package com.lanyuanxiaoyao.flowable.core.model;
import com.lanyuanxiaoyao.flowable.core.helper.ListHelper;
import com.lanyuanxiaoyao.flowable.core.helper.MapHelper;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
/**
@@ -13,43 +15,29 @@ import lombok.Data;
* @version 20241231
*/
@Data
@AllArgsConstructor
@Builder
public class FlowableNode {
private final String nodeId;
private final String name;
private final String description;
private final Type type;
private final String handler;
private final Map<FlowableAction, String> targets;
@Builder.Default
private final Type type = Type.MANUAL;
@Builder.Default
private final String handler = FlowableHandler.DefaultFlowableHandler.class.getName();
@Builder.Default
private final Map<FlowableAction, String> targets = MapHelper.empty();
@Builder.Default
private final String accessor = FlowableAccessor.DefaultFlowableAccessor.class.getName();
private final List<String> listeners;
private final LocalDateTime createdTime;
@Builder.Default
private final LocalDateTime createdTime = LocalDateTime.now();
@Builder.Default
private LocalDateTime updatedTime = LocalDateTime.now();
public FlowableNode(String nodeId, String name, String description, Map<FlowableAction, String> targets) {
this(nodeId, name, description, Type.MANUAL, FlowableHandler.DefaultFlowableHandler.class, targets);
}
public FlowableNode(String nodeId, String name, String description, Class<? extends FlowableHandler> actionClass, Map<FlowableAction, String> targets) {
this(nodeId, name, description, Type.AUTOMATIC, actionClass, targets);
}
public FlowableNode(String nodeId, String name, String description, Type type, Class<? extends FlowableHandler> actionClass, Map<FlowableAction, String> targets) {
this(nodeId, name, description, type, actionClass.getName(), targets, ListHelper.empty(), LocalDateTime.now());
}
public FlowableNode(String nodeId, String name, String description, Type type, String handler, Map<FlowableAction, String> targets, List<String> listeners, LocalDateTime createdTime) {
this.nodeId = nodeId;
this.name = name;
this.description = description;
this.type = type;
this.handler = handler;
this.targets = targets;
this.listeners = listeners;
this.createdTime = createdTime;
}
public enum Type {
AUTOMATIC,
MANUAL,

View File

@@ -32,12 +32,12 @@ public abstract class TestFlowableManager {
}
private FlowableNode createManualNode(String nodeId, Map<FlowableAction, String> nextNodes) {
return new FlowableNode(
nodeId,
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
nextNodes
);
return FlowableNode.builder()
.nodeId(nodeId)
.name(UUID.randomUUID().toString())
.description(UUID.randomUUID().toString())
.targets(nextNodes)
.build();
}
/**
@@ -125,14 +125,12 @@ public abstract class TestFlowableManager {
@Test
public void testSuspend() {
FlowableManager manager = flowableManager();
FlowableNode node = new FlowableNode(
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
"edf1b7b0-f45b-4256-b696-ce84857f03f7",
FlowableNode.Type.MANUAL,
TwoApproveHandler.class,
null
);
FlowableNode node = FlowableNode.builder()
.nodeId("50342cb7-2029-4159-bd4c-cbfa4aebe474")
.name("50342cb7-2029-4159-bd4c-cbfa4aebe474")
.description("50342cb7-2029-4159-bd4c-cbfa4aebe474")
.handler(TwoApproveHandler.class.getName())
.build();
manager.create(node);
String instanceId = manager.start(node.getNodeId());
@@ -148,13 +146,13 @@ public abstract class TestFlowableManager {
@Test
public void testAutomaticNode() {
FlowableManager manager = flowableManager();
FlowableNode node = new FlowableNode(
"2733d930-7a4b-491e-b1ca-4d5811435e9f",
"自动节点",
"自动节点",
getAutomaticNodeClass(),
null
);
FlowableNode node = FlowableNode.builder()
.nodeId("5d60dab0-7691-4543-b753-af7ac02cb7ec")
.name("5d60dab0-7691-4543-b753-af7ac02cb7ec")
.description("5d60dab0-7691-4543-b753-af7ac02cb7ec")
.type(FlowableNode.Type.AUTOMATIC)
.handler(getAutomaticNodeClass().getName())
.build();
manager.create(node);
String instanceId = manager.start(node.getNodeId());
Assertions.assertEquals(FlowableInstance.Status.COMPLETED, manager.getInstance(instanceId).getStatus());