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

com.fivefaces.structureclient.service.statemachine.impl.ScaffoldSubtask 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 ScaffoldSubtask {

    private final ScaffoldUtils scaffoldUtils;

    public String scaffold(String line, ScaffoldStateMachineResult result, String[] lines, int counter, String stateMachine, String arn) throws Exception {
        final Map subtaskParameters = scaffoldUtils.getParameters(line, "name", "next", "task", "entity", "property", "exclude", "embedded");

        String query;
        if (subtaskParameters.containsKey("entity")) {
            query = scaffoldUtils.getEntity(result, subtaskParameters);
        } else {
            final StringBuilder querys = new StringBuilder();
            subtaskParameters.keySet().stream().filter(s -> s.startsWith("property")).forEach(s -> {
                String[] parameters = subtaskParameters.get(s).split(" ");
                final String field = parameters[0];
                // check if a straight parameter
                if (parameters.length == 1) {
                    querys.append("            \"").append(field).append(".$\": \"$.query.").append(field).append("\",\n");
                } else {
                    StringBuilder val = scaffoldUtils.getChoiceParams(parameters);
                    String dynamic = "";
                    if (val.toString().startsWith("$")) {
                        dynamic = ".$";
                    }
                    querys.append("            \"").append(field).append(dynamic).append("\": \"").append(val.toString().trim()).append("\",\n");
                }
            });
            query = querys + "            \"username.$\": \"$.query.authorization.username\",";
        }
        query = query + "\n            \"authorization.$\": \"$.query.authorization\"";
        return scaffoldUtils.getSubtaskStep(stateMachine, arn, subtaskParameters, query, scaffoldUtils.addNextStep(result, lines, counter, subtaskParameters), subtaskParameters.get("task"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy