1
0

增加配置文件

This commit is contained in:
2025-01-03 11:57:30 +08:00
parent 53ab0d731c
commit eff6d6be02
9 changed files with 99 additions and 27 deletions

7
.idea/jpa.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="defaultUnitInitialized" value="true" />
<option name="renamerInitialized" value="true" />
</component>
</project>

3
.idea/misc.xml generated
View File

@@ -11,4 +11,7 @@
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="temurin-1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>

View File

@@ -23,6 +23,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>

View File

@@ -0,0 +1,18 @@
package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* 配置类
*
* @author lanyuanxiaoyao
* @version 20250103
*/
@ToString(callSuper = true)
@Configuration
@ConfigurationProperties("flowable")
public class SpringFlowableConfiguration extends FlowableConfiguration {
}

View File

@@ -1,5 +1,6 @@
package com.lanyuanxiaoyao.flowable.jpa;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import com.lanyuanxiaoyao.flowable.core.repository.FlowableRepository;
import java.util.UUID;
@@ -17,8 +18,9 @@ import org.springframework.stereotype.Service;
public class SpringFlowableManager extends FlowableManager {
private final ApplicationContext applicationContext;
public SpringFlowableManager(FlowableRepository flowableRepository, ApplicationContext applicationContext) {
super(flowableRepository, () -> UUID.randomUUID().toString());
public SpringFlowableManager(FlowableConfiguration configuration, FlowableRepository repository, ApplicationContext applicationContext) {
super(configuration, repository);
log.info("Configuration: {}", configuration);
this.applicationContext = applicationContext;
}
@@ -38,4 +40,9 @@ public class SpringFlowableManager extends FlowableManager {
}
return targetObject;
}
@Override
protected String createId() {
return UUID.randomUUID().toString();
}
}

View File

@@ -0,0 +1,28 @@
package com.lanyuanxiaoyao.flowable.core.manager;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 配置项
*
* @author lanyuanxiaoyao
* @version 20250103
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FlowableConfiguration {
/**
* 在上下文中查询权限的key
*/
@Builder.Default
private String accessorKey = Constants.DEFAULT_ACCESSOR_KEY;
public interface Constants {
String DEFAULT_ACCESSOR_KEY = "accessor";
}
}

View File

@@ -25,40 +25,40 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
public abstract class FlowableManager {
private final FlowableRepository flowableRepository;
private final IdGenerator idGenerator;
private final FlowableConfiguration configuration;
private final FlowableRepository repository;
public FlowableManager(FlowableRepository flowableRepository, IdGenerator idGenerator) {
this.flowableRepository = flowableRepository;
this.idGenerator = idGenerator;
public FlowableManager(FlowableConfiguration configuration, FlowableRepository repository) {
this.configuration = configuration;
this.repository = repository;
}
public List<FlowableNode> listNodes() {
return flowableRepository.listNodes();
return repository.listNodes();
}
public FlowableNode getNode(String nodeId) {
return flowableRepository.getNode(nodeId);
return repository.getNode(nodeId);
}
public List<FlowableInstance> listInstances() {
return flowableRepository.listInstances();
return repository.listInstances();
}
public FlowableInstance getInstance(String instantId) {
return flowableRepository.getInstance(instantId);
return repository.getInstance(instantId);
}
public List<FlowableHistory> listHistories(String instanceId) {
return flowableRepository.listHistories(instanceId);
return repository.listHistories(instanceId);
}
public FlowableHistory getHistory(String historyId) {
return flowableRepository.getHistory(historyId);
return repository.getHistory(historyId);
}
public void create(FlowableNode... node) {
flowableRepository.saveNode(ListHelper.of(node));
repository.saveNode(ListHelper.of(node));
}
public String start(String nodeId) {
@@ -66,9 +66,9 @@ public abstract class FlowableManager {
}
public String start(String nodeId, Map<String, Object> metadata) {
FlowableNode node = flowableRepository.getNode(nodeId);
FlowableInstance instance = new FlowableInstance(idGenerator.createId(), node.getNodeId(), metadata);
flowableRepository.saveInstance(instance);
FlowableNode node = repository.getNode(nodeId);
FlowableInstance instance = new FlowableInstance(createId(), node.getNodeId(), metadata);
repository.saveInstance(instance);
if (FlowableNode.Type.AUTOMATIC.equals(node.getType())) {
autoAction(instance, node, MapHelper.empty());
@@ -109,8 +109,8 @@ public abstract class FlowableManager {
}
private void action(String instanceId, FlowableAction action, String comment, Map<String, Object> metadata) {
FlowableInstance instance = flowableRepository.getInstance(instanceId);
FlowableNode node = flowableRepository.getNode(instance.getCurrentNodeId());
FlowableInstance instance = repository.getInstance(instanceId);
FlowableNode node = repository.getNode(instance.getCurrentNodeId());
action(instance, node, action, comment, metadata);
}
@@ -137,7 +137,7 @@ public abstract class FlowableManager {
return;
}
String nextNodeId = node.getTargets().get(action);
FlowableNode nextNode = flowableRepository.getNode(nextNodeId);
FlowableNode nextNode = repository.getNode(nextNodeId);
instance.setCurrentNodeId(nextNode.getNodeId());
saveInstance(instance, FlowableInstance.Status.RUNNING, metadata, action, comment);
@@ -153,8 +153,8 @@ public abstract class FlowableManager {
}
instance.setUpdatedTime(LocalDateTime.now());
FlowableHistory history = new FlowableHistory(idGenerator.createId(), instance.getInstanceId(), action, comment);
flowableRepository.saveInstanceAndHistory(instance, history);
FlowableHistory history = new FlowableHistory(createId(), instance.getInstanceId(), action, comment);
repository.saveInstanceAndHistory(instance, history);
}
private void callListeners(List<FlowableListener> listeners, Consumer<FlowableListener> handler) {
@@ -165,7 +165,5 @@ public abstract class FlowableManager {
protected abstract <T> T createBean(String classpath);
public interface IdGenerator {
String createId();
}
protected abstract String createId();
}

View File

@@ -7,5 +7,5 @@ package com.lanyuanxiaoyao.flowable.core.model;
* @version 20241231
*/
public interface FlowableAccessor {
void access(String accessor);
void access(Object accessor);
}

View File

@@ -1,5 +1,6 @@
package com.lanyuanxiaoyao.flowable.test;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableConfiguration;
import com.lanyuanxiaoyao.flowable.core.manager.FlowableManager;
import java.util.UUID;
import lombok.SneakyThrows;
@@ -10,7 +11,7 @@ import lombok.SneakyThrows;
*/
public class SimpleFlowableManager extends FlowableManager {
public SimpleFlowableManager() {
super(new InMemoryFlowableRepository(), () -> UUID.randomUUID().toString());
super(FlowableConfiguration.builder().build(), new InMemoryFlowableRepository());
}
@SneakyThrows
@@ -18,4 +19,9 @@ public class SimpleFlowableManager extends FlowableManager {
protected <T> T createBean(String classpath) {
return (T) Class.forName(classpath).newInstance();
}
@Override
protected String createId() {
return UUID.randomUUID().toString();
}
}