Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow sync engine #272

Merged
merged 20 commits into from
Jul 16, 2024
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
10 changes: 0 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,6 @@ subprojects {
}
}

apply plugin: 'maven-publish'

publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}

}

boolean isRelease(Project project) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/version.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.util.regex.Pattern

version = "2.3.24-snapshot"
version = "2.3.24"
logger.lifecycle("Project version: $version")

String detectSemVersion() {
Expand Down
1 change: 1 addition & 0 deletions xm-commons-flow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
compile project(":xm-commons-config")
compile project(":xm-commons-i18n")
compile project(":xm-commons-lep")
compile project(":xm-commons-permission")

implementation("com.github.java-json-tools:json-schema-validator:2.2.8") {
exclude group: 'javax.mail', module: 'mailapi'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.icthh.xm.commons.lep.api.BaseLepContext;

public interface Condition {
public interface Condition extends Action {
@Override
default <T extends BaseLepContext & FlowLepContextFields> Boolean execute(T lepContext) {
return test(lepContext);
}
<T extends BaseLepContext & FlowLepContextFields> Boolean test(T lepContext);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package com.icthh.xm.commons.flow.api;

import com.icthh.xm.commons.flow.context.FlowLepAdditionalContext.FlowLepAdditionalContextField;
import com.icthh.xm.commons.flow.context.StepLepAdditionalContext.StepLepAdditionalContextField;
import com.icthh.xm.commons.flow.context.StepsLepAdditionalContext.StepsLepAdditionalContextField;
import com.icthh.xm.commons.flow.context.TenantResourceLepAdditionalContext.TenantResourceLepAdditionalContextField;

public interface FlowLepContextFields extends TenantResourceLepAdditionalContextField {
public interface FlowLepContextFields extends
TenantResourceLepAdditionalContextField,
StepLepAdditionalContextField,
StepsLepAdditionalContextField,
FlowLepAdditionalContextField
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.icthh.xm.commons.flow.context;

import com.icthh.xm.commons.flow.engine.context.FlowExecutionContext;
import com.icthh.xm.commons.flow.context.FlowLepAdditionalContext.FlowContext;
import com.icthh.xm.commons.flow.service.FlowService;
import com.icthh.xm.commons.lep.TargetProceedingLep;
import com.icthh.xm.commons.lep.api.BaseLepContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContextField;
import com.icthh.xm.commons.lep.api.LepBaseKey;
import com.icthh.xm.commons.lep.api.LepEngine;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.Set;

import static com.icthh.xm.commons.flow.context.FlowLepAdditionalContext.FlowLepAdditionalContextField.FLOW;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.ACTION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.CONDITION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.FLOW_STEP_GROUP;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.STEP_CLASS_EXECUTOR;

@Component
@RequiredArgsConstructor
public class FlowLepAdditionalContext implements LepAdditionalContext<FlowContext> {

private static final Set<String> STEP_LEP = Set.of(ACTION, CONDITION, STEP_CLASS_EXECUTOR);

private final FlowService flowService;

@Override
public String additionalContextKey() {
return FLOW;
}

@Override
public FlowContext additionalContextValue() {
return null;
}

@Override
public Optional<FlowContext> additionalContextValue(BaseLepContext lepContext, LepEngine lepEngine, TargetProceedingLep lepMethod) {
LepBaseKey lepBaseKey = lepMethod.getLepBaseKey();
if (FLOW_STEP_GROUP.equals(lepBaseKey.getGroup()) && STEP_LEP.contains(lepBaseKey.getBaseKey())) {
FlowExecutionContext context = lepMethod.getParameter("context", FlowExecutionContext.class);
return Optional.of(new FlowContext(context.getInput(), flowService));
} else {
return Optional.of(new FlowContext(null, flowService));
}
}

@Override
public Class<FlowLepAdditionalContextField> fieldAccessorInterface() {
return FlowLepAdditionalContextField.class;
}

public interface FlowLepAdditionalContextField extends LepAdditionalContextField {
String FLOW = "flow";
default FlowContext getFlow() {
return (FlowContext)get(FLOW);
}
}

public static class FlowContext {
public final Object input;
public final Object context;
private final FlowService flowService;

public FlowContext(Object input, FlowService flowService) {
this.input = input;
this.context = input;
this.flowService = flowService;
}

public FlowExecutionContext executeFlow(String flowKey, Object input) {
return flowService.runFlowInternal(flowKey, input);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.icthh.xm.commons.flow.context;

import com.icthh.xm.commons.flow.context.StepLepAdditionalContext.StepContext;
import com.icthh.xm.commons.flow.domain.Step;
import com.icthh.xm.commons.flow.engine.context.FlowExecutionContext;
import com.icthh.xm.commons.flow.service.CodeSnippetExecutor;
import com.icthh.xm.commons.lep.TargetProceedingLep;
import com.icthh.xm.commons.lep.api.BaseLepContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContextField;
import com.icthh.xm.commons.lep.api.LepBaseKey;
import com.icthh.xm.commons.lep.api.LepEngine;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.icthh.xm.commons.config.client.utils.Utils.nullSafeMap;
import static com.icthh.xm.commons.flow.context.StepLepAdditionalContext.StepLepAdditionalContextField.STEP;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.ACTION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.CONDITION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.FLOW_STEP_GROUP;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.STEP_CLASS_EXECUTOR;

@Component
@RequiredArgsConstructor
public class StepLepAdditionalContext implements LepAdditionalContext<StepContext> {

private static final Set<String> STEP_LEP = Set.of(ACTION, CONDITION, STEP_CLASS_EXECUTOR);

private final CodeSnippetExecutor snippetExecutor;

@Override
public String additionalContextKey() {
return STEP;
}

@Override
public StepContext additionalContextValue() {
return null;
}

@Override
public Optional<StepContext> additionalContextValue(BaseLepContext lepContext, LepEngine lepEngine, TargetProceedingLep lepMethod) {
LepBaseKey lepBaseKey = lepMethod.getLepBaseKey();
if (FLOW_STEP_GROUP.equals(lepBaseKey.getGroup()) && STEP_LEP.contains(lepBaseKey.getBaseKey())) {
FlowExecutionContext context = lepMethod.getParameter("context", FlowExecutionContext.class);
Step step = lepMethod.getParameter("step", Step.class);
return Optional.of(new StepContext(context, step, snippetExecutor));
} else {
return Optional.empty();
}
}

@Override
public Class<StepLepAdditionalContextField> fieldAccessorInterface() {
return StepLepAdditionalContextField.class;
}

public interface StepLepAdditionalContextField extends LepAdditionalContextField {
String STEP = "step";
default StepContext getStep() {
return (StepContext)get(STEP);
}
}

public static class StepContext {
public final Object input;
public final Object context;
public final Map<String, Object> parameters;

public final Integer iteration;
public final Object iterationItem;
public final List<Object> iterationsInput;
public final List<Object> iterationsOutput;

private final String flowKey;
private final String stepKey;
private final CodeSnippetExecutor snippetExecutor;

public StepContext(FlowExecutionContext context, Step step, CodeSnippetExecutor snippetExecutor) {
var input = context.getStepInput().get(step.getKey());
this.input = input;
this.context = input;

this.iteration = context.getIteration();
this.iterationItem = context.getIterationItem();
this.iterationsInput = context.getIterationsInput();
this.iterationsOutput = context.getIterationsOutput();

this.flowKey = context.getFlowKey();
this.stepKey = step.getKey();
this.parameters = Map.copyOf(nullSafeMap(step.getParameters()));
this.snippetExecutor = snippetExecutor;
}

public Object runSnippet(String snippetKey, BaseLepContext lepContext) {
return snippetExecutor.runCodeSnippet(lepContext, List.of(flowKey, stepKey, snippetKey));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.icthh.xm.commons.flow.context;

import com.icthh.xm.commons.flow.context.StepsLepAdditionalContext.StepsContext;
import com.icthh.xm.commons.flow.engine.context.FlowExecutionContext;
import com.icthh.xm.commons.lep.TargetProceedingLep;
import com.icthh.xm.commons.lep.api.BaseLepContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContext;
import com.icthh.xm.commons.lep.api.LepAdditionalContextField;
import com.icthh.xm.commons.lep.api.LepBaseKey;
import com.icthh.xm.commons.lep.api.LepEngine;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.icthh.xm.commons.flow.context.StepsLepAdditionalContext.StepsLepAdditionalContextField.STEPS;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.ACTION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.CONDITION;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.FLOW_STEP_GROUP;
import static com.icthh.xm.commons.flow.engine.StepExecutorService.STEP_CLASS_EXECUTOR;

@Component
@RequiredArgsConstructor
public class StepsLepAdditionalContext implements LepAdditionalContext<StepsContext> {

private static final Set<String> STEP_LEP = Set.of(ACTION, CONDITION, STEP_CLASS_EXECUTOR);

@Override
public String additionalContextKey() {
return STEPS;
}

@Override
public StepsContext additionalContextValue() {
return null;
}

@Override
public Optional<StepsContext> additionalContextValue(BaseLepContext lepContext, LepEngine lepEngine, TargetProceedingLep lepMethod) {
LepBaseKey lepBaseKey = lepMethod.getLepBaseKey();
if (FLOW_STEP_GROUP.equals(lepBaseKey.getGroup()) && STEP_LEP.contains(lepBaseKey.getBaseKey())) {
FlowExecutionContext context = lepMethod.getParameter("context", FlowExecutionContext.class);
return Optional.of(new StepsContext(context));
} else {
return Optional.empty();
}
}

@Override
public Class<StepsLepAdditionalContextField> fieldAccessorInterface() {
return StepsLepAdditionalContextField.class;
}

public interface StepsLepAdditionalContextField extends LepAdditionalContextField {
String STEPS = "steps";
default StepsContext getSteps() {
return (StepsContext)get(STEPS);
}
}

public static class StepLog {
public Object input;
public Object output;
}

public static class StepsContext implements Map<String, StepLog> {
public final Map<String, StepLog> delegate;

public StepsContext(FlowExecutionContext context) {
Set<String> keys = new HashSet<>();
keys.addAll(context.getStepInput().keySet());
keys.addAll(context.getStepOutput().keySet());

Map<String, StepLog> steps = new HashMap<>();
keys.forEach(key -> {
StepLog stepLog = new StepLog();
stepLog.input = context.getStepInput().get(key);
stepLog.output = context.getStepOutput().get(key);
steps.put(key, stepLog);
});

this.delegate = Map.copyOf(steps);
}

@Override
public int size() {
return delegate.size();
}

@Override
public boolean isEmpty() {
return delegate.isEmpty();
}

@Override
public boolean containsKey(Object key) {
return delegate.containsKey(key);
}

@Override
public boolean containsValue(Object value) {
return delegate.containsValue(value);
}

@Override
public StepLog get(Object key) {
return delegate.get(key);
}

@Override
public StepLog put(String key, StepLog value) {
throw new UnsupportedOperationException();
}

@Override
public StepLog remove(Object key) {
throw new UnsupportedOperationException();
}

@Override
public void putAll(Map<? extends String, ? extends StepLog> m) {
throw new UnsupportedOperationException();
}

@Override
public void clear() {
delegate.clear();
}

@Override
public Set<String> keySet() {
return delegate.keySet();
}

@Override
public Collection<StepLog> values() {
return delegate.values();
}

@Override
public Set<Entry<String, StepLog>> entrySet() {
return delegate.entrySet();
}

}

}
Loading