updated for input steps
This commit is contained in:
parent
55a0028c73
commit
083387d2ba
|
|
@ -52,7 +52,7 @@ public class TransformerService {
|
|||
.orElseThrow(() -> new IllegalArgumentException("Node definition not found for type: " + node.getType()));
|
||||
|
||||
Step step = switch (nodeDefinition) {
|
||||
case InputNodeDefinition id -> getInputStep(node);
|
||||
case InputNodeDefinition id -> getInputStep(node);
|
||||
case UserNodeDefinition ud -> getExecutionStep(node, ud, execObject.getContext());
|
||||
default -> throw new IllegalArgumentException("Node type " + node.getType() + " not supported");
|
||||
};
|
||||
|
|
@ -78,6 +78,11 @@ public class TransformerService {
|
|||
inputNode.getParentOutputsToInputMapping().put(outputPair.name, inputPair.name);
|
||||
}
|
||||
|
||||
execObject.setInputSteps(steps.values().stream()
|
||||
.filter(s -> s instanceof InputStep)
|
||||
.map(s -> (InputStep) s)
|
||||
.toList());
|
||||
|
||||
return execObject;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import org.springframework.util.ResourceUtils;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.ExecutionObject;
|
||||
import it.cnr.isti.workflow.manager.model.InputReadyListener;
|
||||
import it.cnr.isti.workflow.manager.model.flows.Flow;
|
||||
import it.cnr.isti.workflow.manager.model.flows.errors.FlowError;
|
||||
import it.cnr.isti.workflow.manager.repositories.FlowRepository;
|
||||
|
|
@ -23,202 +25,197 @@ import it.cnr.isti.workflow.manager.services.TransformerService;
|
|||
@TestPropertySource(locations = "classpath:test.properties")
|
||||
public class FlowTest {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(FlowTest.class);
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(FlowTest.class);
|
||||
|
||||
@Autowired
|
||||
FlowRepository flowRepository;
|
||||
@Autowired
|
||||
FlowRepository flowRepository;
|
||||
|
||||
@Autowired
|
||||
TransformerService transformerService;
|
||||
@Autowired
|
||||
TransformerService transformerService;
|
||||
|
||||
private static final String FLOW = """
|
||||
{
|
||||
"id": "167d8d84-f990-42e1-b247-0a6a7fabd666",
|
||||
"createdBy": "user.test",
|
||||
"name": "myFlow",
|
||||
"description": null,
|
||||
"nodes": [
|
||||
{
|
||||
"key": "e5f1f8d6-7717-4e32-ab57-f25f38f55401",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "2967ca92-3977-44ad-8e19-318b9a71d227",
|
||||
"type": "text",
|
||||
"name": "value"
|
||||
}
|
||||
],
|
||||
"inputs": [],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": -270,
|
||||
"y": -16
|
||||
},
|
||||
"parameters": {
|
||||
"name": "interview\n"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Text Input"
|
||||
},
|
||||
{
|
||||
"key": "1a4d1254-2c44-49fa-8aee-3865d1be9f95",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "f36c7ae1-78da-4d71-8b44-58a1f87f17cb",
|
||||
"type": "text",
|
||||
"name": "requirements"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "7860945a-506b-45a3-97b6-cbf08023e421",
|
||||
"type": "text",
|
||||
"name": "interview"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": -11,
|
||||
"y": -23
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "llama3.1:8b"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirement Generator"
|
||||
},
|
||||
{
|
||||
"key": "394f3a84-f8b0-4cf6-92c7-042e6be03a26",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "a73eb6d8-9010-428e-a0cd-0831fcba6c42",
|
||||
"type": "text",
|
||||
"name": "corrected-requirements"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "e83aebf3-05dd-4588-b9a3-03fd7253e5fc",
|
||||
"type": "text",
|
||||
"name": "requirement-smells"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 321,
|
||||
"y": -21
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "gemma3:12b"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirements Corrector"
|
||||
},
|
||||
{
|
||||
"key": "511a2b09-dde6-4877-97ed-92819da4b778",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "96750771-855b-4013-9959-ac8b3fd17133",
|
||||
"type": "text",
|
||||
"name": "requirement-smells"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "059dad32-a3ea-4a34-b77e-f747c2baf864",
|
||||
"type": "text",
|
||||
"name": "requirements"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 707,
|
||||
"y": -22
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "codellama:latest"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirements Analyzer"
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"key": "f8b4dbaa-a9cc-4470-89a2-7b999d905d9b",
|
||||
"from": "2967ca92-3977-44ad-8e19-318b9a71d227",
|
||||
"to": "7860945a-506b-45a3-97b6-cbf08023e421"
|
||||
},
|
||||
{
|
||||
"key": "9b2da750-f8c2-425a-a4c0-67869a60f69b",
|
||||
"from": "f36c7ae1-78da-4d71-8b44-58a1f87f17cb",
|
||||
"to": "e83aebf3-05dd-4588-b9a3-03fd7253e5fc"
|
||||
},
|
||||
{
|
||||
"key": "ec5ed95b-e546-4ee2-957b-039649f3fac4",
|
||||
"from": "a73eb6d8-9010-428e-a0cd-0831fcba6c42",
|
||||
"to": "059dad32-a3ea-4a34-b77e-f747c2baf864"
|
||||
}
|
||||
],
|
||||
"public": true
|
||||
}
|
||||
""";
|
||||
private static final String FLOW = """
|
||||
{
|
||||
"id": "167d8d84-f990-42e1-b247-0a6a7fabd666",
|
||||
"createdBy": "user.test",
|
||||
"name": "myFlow",
|
||||
"description": null,
|
||||
"nodes": [
|
||||
{
|
||||
"key": "e5f1f8d6-7717-4e32-ab57-f25f38f55401",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "2967ca92-3977-44ad-8e19-318b9a71d227",
|
||||
"type": "text",
|
||||
"name": "value"
|
||||
}
|
||||
],
|
||||
"inputs": [],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": -270,
|
||||
"y": -16
|
||||
},
|
||||
"parameters": {
|
||||
"name": "interview"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Text Input"
|
||||
},
|
||||
{
|
||||
"key": "1a4d1254-2c44-49fa-8aee-3865d1be9f95",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "f36c7ae1-78da-4d71-8b44-58a1f87f17cb",
|
||||
"type": "text",
|
||||
"name": "requirements"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "7860945a-506b-45a3-97b6-cbf08023e421",
|
||||
"type": "text",
|
||||
"name": "interview"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": -11,
|
||||
"y": -23
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "llama3.1:8b"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirement Generator"
|
||||
},
|
||||
{
|
||||
"key": "394f3a84-f8b0-4cf6-92c7-042e6be03a26",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "a73eb6d8-9010-428e-a0cd-0831fcba6c42",
|
||||
"type": "text",
|
||||
"name": "corrected-requirements"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "e83aebf3-05dd-4588-b9a3-03fd7253e5fc",
|
||||
"type": "text",
|
||||
"name": "requirement-smells"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 321,
|
||||
"y": -21
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "gemma3:12b"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirements Corrector"
|
||||
},
|
||||
{
|
||||
"key": "511a2b09-dde6-4877-97ed-92819da4b778",
|
||||
"name": "newNode",
|
||||
"createdBy": null,
|
||||
"outputs": [
|
||||
{
|
||||
"key": "96750771-855b-4013-9959-ac8b3fd17133",
|
||||
"type": "text",
|
||||
"name": "requirement-smells"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"key": "059dad32-a3ea-4a34-b77e-f747c2baf864",
|
||||
"type": "text",
|
||||
"name": "requirements"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 707,
|
||||
"y": -22
|
||||
},
|
||||
"parameters": {
|
||||
"LLM": "codellama:latest"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Requirements Analyzer"
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"key": "f8b4dbaa-a9cc-4470-89a2-7b999d905d9b",
|
||||
"from": "2967ca92-3977-44ad-8e19-318b9a71d227",
|
||||
"to": "7860945a-506b-45a3-97b6-cbf08023e421"
|
||||
},
|
||||
{
|
||||
"key": "9b2da750-f8c2-425a-a4c0-67869a60f69b",
|
||||
"from": "f36c7ae1-78da-4d71-8b44-58a1f87f17cb",
|
||||
"to": "e83aebf3-05dd-4588-b9a3-03fd7253e5fc"
|
||||
},
|
||||
{
|
||||
"key": "ec5ed95b-e546-4ee2-957b-039649f3fac4",
|
||||
"from": "a73eb6d8-9010-428e-a0cd-0831fcba6c42",
|
||||
"to": "059dad32-a3ea-4a34-b77e-f747c2baf864"
|
||||
}
|
||||
],
|
||||
"public": true
|
||||
}
|
||||
""";
|
||||
|
||||
@Test
|
||||
void testFlowSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
assertNotNull(flow);
|
||||
flowRepository.save(flow);
|
||||
}
|
||||
@Test
|
||||
void testFlowSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
assertNotNull(flow);
|
||||
flowRepository.save(flow);
|
||||
}
|
||||
|
||||
/*
|
||||
* //@Test
|
||||
* void transform() throws Exception {
|
||||
* ObjectMapper objectMapper = new ObjectMapper();
|
||||
* Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
* ExecutionObject execution = transformerService.transform(flow);
|
||||
* assertNotNull(execution.getStartStep());
|
||||
*
|
||||
* InputReadyListener resuListener = new InputReadyListener() {
|
||||
*
|
||||
* @Override
|
||||
* public void inputReady(String key, Object value) {
|
||||
* log.debug("Received result: {} -> {}", key, value);
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* //execution.getInputSteps().setNextSteps(List.of(resuListener));
|
||||
*
|
||||
* execution.getInputSteps() .inputReady("phrase", "Ciao come stai?");
|
||||
*
|
||||
* }
|
||||
*/
|
||||
@Test
|
||||
void transform() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
ExecutionObject execution = transformerService.transform(flow);
|
||||
assertNotNull(execution.getInputSteps());
|
||||
|
||||
@Test
|
||||
void testValidTrasformable() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(ResourceUtils.getFile("classpath:validFlow.json"), Flow.class);
|
||||
InputReadyListener resuListener = new InputReadyListener() {
|
||||
|
||||
List<FlowError> errors = transformerService.isTrasformableFlow(flow);
|
||||
assertNotNull(errors);
|
||||
assertTrue(errors.isEmpty());
|
||||
}
|
||||
@Override
|
||||
public void inputReady(String key, Object value) {
|
||||
log.debug("Received result: {} -> {}", key, value);
|
||||
}
|
||||
};
|
||||
|
||||
execution.getInputSteps().get(0).setFieldValue("This is a test interview input");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidTrasformable() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(ResourceUtils.getFile("classpath:invalidFlow.json"), Flow.class);
|
||||
@Test
|
||||
void testValidTrasformable() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(ResourceUtils.getFile("classpath:validFlow.json"), Flow.class);
|
||||
|
||||
List<FlowError> errors = transformerService.isTrasformableFlow(flow);
|
||||
assertNotNull(errors);
|
||||
assertTrue(!errors.isEmpty());
|
||||
}
|
||||
List<FlowError> errors = transformerService.isTrasformableFlow(flow);
|
||||
assertNotNull(errors);
|
||||
assertTrue(errors.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidTrasformable() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(ResourceUtils.getFile("classpath:invalidFlow.json"), Flow.class);
|
||||
|
||||
List<FlowError> errors = transformerService.isTrasformableFlow(flow);
|
||||
assertNotNull(errors);
|
||||
assertTrue(!errors.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue