Search in sources :

Example 1 with KameletBindingSpec

use of io.kaoto.backend.model.deployment.kamelet.KameletBindingSpec in project kaoto-backend by KaotoIO.

the class KameletBindingDeploymentGeneratorService method parse.

@Override
public String parse(final List<Step> steps, final Map<String, Object> metadata) {
    if (!appliesTo(steps)) {
        return "";
    }
    KameletBindingSpec spec = new KameletBindingSpec();
    int i = 0;
    if (!steps.isEmpty()) {
        Step step = steps.get(i);
        if ("START".equalsIgnoreCase(step.getType())) {
            spec.setSource(createKameletBindingStep(steps.get(i++)));
        }
    }
    for (; i < steps.size() - 1; i++) {
        spec.getSteps().add(createKameletBindingStep(steps.get(i)));
    }
    if (spec.getSteps().isEmpty()) {
        spec.setSteps(null);
    }
    if (steps.size() > 1) {
        spec.setSink(createKameletBindingStep(steps.get(steps.size() - 1)));
    }
    KameletBinding binding = new KameletBinding(String.valueOf(metadata.getOrDefault("name", "")), spec);
    Yaml yaml = new Yaml(new Constructor(KameletBinding.class), new KameletRepresenter());
    return yaml.dumpAsMap(binding);
}
Also used : KameletBindingSpec(io.kaoto.backend.model.deployment.kamelet.KameletBindingSpec) Constructor(org.yaml.snakeyaml.constructor.Constructor) KameletBindingStep(io.kaoto.backend.model.deployment.kamelet.KameletBindingStep) Step(io.kaoto.backend.model.step.Step) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

KameletBinding (io.kaoto.backend.model.deployment.kamelet.KameletBinding)1 KameletBindingSpec (io.kaoto.backend.model.deployment.kamelet.KameletBindingSpec)1 KameletBindingStep (io.kaoto.backend.model.deployment.kamelet.KameletBindingStep)1 Step (io.kaoto.backend.model.step.Step)1 Yaml (org.yaml.snakeyaml.Yaml)1 Constructor (org.yaml.snakeyaml.constructor.Constructor)1