All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fivefaces.structureclient.service.statemachine.impl.ScaffoldPass Maven / Gradle / Ivy

The newest version!
package com.fivefaces.structureclient.service.statemachine.impl;

import com.fivefaces.structureclient.service.statemachine.ScaffoldStateMachineResult;
import com.fivefaces.structureclient.service.statemachine.ScaffoldUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@AllArgsConstructor
public class ScaffoldPass {

    private final ScaffoldUtils scaffoldUtils;

    public String scaffold(String line, ScaffoldStateMachineResult result, String[] lines, int counter, String stateMachine) throws Exception {
        final Map passParameters = scaffoldUtils.getParameters(line, "name");
        String next = "      \"End\": true";
        if (passParameters.containsKey("next")) {
            next = String.format("      \"Next\": \"%s\"", passParameters.get("next"));
            if (!scaffoldUtils.getSteps(lines).contains(passParameters.get("next"))) {
                result.getWarnings().add(String.format("Next value of %s is not valid for step %s",
                        passParameters.get("next"), passParameters.get("name")));
            }
        } else {
            if (counter + 1 < lines.length) {
                next = String.format("      \"Next\": \"%s\"", scaffoldUtils.getStepName(lines[counter + 1]));
            }
        }
        return stateMachine.replace("***" + passParameters.get("name") + "***", String.format("  \"Type\": \"Pass\",\n%s", next));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy