Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.codingapi.flow.gateway.FlowOperatorGateway;
import com.codingapi.flow.register.FlowRepositoryRegister;
import com.codingapi.flow.register.FlowScriptContextRegister;
import com.codingapi.flow.repository.*;
import com.codingapi.flow.runner.FlowDelayTaskRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -15,6 +17,15 @@ public FlowDelayTaskRunner delayTaskRunner() {
return new FlowDelayTaskRunner();
}

@Bean
public FlowScriptContextRegister flowScriptContextRegister(
ApplicationContext spring,
FlowOperatorGateway flowOperatorGateway,
FlowRecordRepository flowRecordRepository
) {
return new FlowScriptContextRegister(spring, flowOperatorGateway,flowRecordRepository);
}

@Bean
public FlowRepositoryRegister flowRepositoryRegister(
WorkflowRepository workflowRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.codingapi.flow.register;

import com.codingapi.flow.gateway.FlowOperatorGateway;
import com.codingapi.flow.operator.IFlowOperator;
import com.codingapi.flow.record.FlowRecord;
import com.codingapi.flow.repository.FlowRecordRepository;
import com.codingapi.flow.script.runtime.FlowScriptContext;
import com.codingapi.flow.script.runtime.IBeanFactory;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;

import java.util.List;
import java.util.Map;

@AllArgsConstructor
public class FlowScriptContextRegister implements InitializingBean {

private final ApplicationContext spring;
private final FlowOperatorGateway flowOperatorGateway;
private final FlowRecordRepository flowRecordRepository;

@Override
public void afterPropertiesSet() throws Exception {
FlowScriptContext.getInstance().setBeanFactory(new IBeanFactory() {
@Override
public <T> T getBean(Class<T> clazz) {
return spring.getBean(clazz);
}

@Override
public <T> T getBean(String name, Class<T> clazz) {
return spring.getBean(name, clazz);
}

@Override
public <T> List<T> getBeans(Class<T> clazz) {
Map<String, T> beans = spring.getBeansOfType(clazz);
return beans.values().stream().toList();
}

@Override
public FlowRecord getRecordById(long id) {
return flowRecordRepository.get(id);
}

@Override
public IFlowOperator getOperatorById(long userId) {
return flowOperatorGateway.get(userId);
}

@Override
public List<IFlowOperator> findOperatorsByIds(List<Long> ids) {
return flowOperatorGateway.findByIds(ids);
}
});
}
}