Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feature: Return a wrapper object for flows instead of a plain array/list
Browse files Browse the repository at this point in the history
of flows
  • Loading branch information
Delawen committed May 8, 2023
1 parent deb6798 commit efa5105
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.kaoto.backend.api.resource.model;

import io.kaoto.backend.api.resource.v1.model.Integration;
import java.util.List;
import java.util.Map;

/**
* 🐱class FlowsWrapper
*
* Used by the API to pass flows back and forth.
*
*/
public record FlowsWrapper(List<Integration> flows, Map<String, Object> properties) {

public FlowsWrapper(List<Integration> flows) {
this(flows, null);
}

public FlowsWrapper(List<Integration> flows, Map<String, Object> properties) {
this.flows = flows;
this.properties = properties;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kaoto.backend.api.resource.v2;

import io.kaoto.backend.api.resource.model.FlowsWrapper;
import io.kaoto.backend.api.resource.v1.model.Integration;
import io.kaoto.backend.api.service.deployment.DeploymentService;
import io.kaoto.backend.api.service.step.parser.StepParserService;
Expand All @@ -19,6 +20,7 @@
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* 🐱class IntegrationsResource
Expand Down Expand Up @@ -62,10 +64,10 @@ public void setStepParserServices(final Instance<StepParserService<Step>> stepPa
@Operation(summary = "Get CRDs",
description = "Returns the associated custom resource definitions. This is an idempotent operation.")
public String crds(
final @RequestBody List<Integration> request,
final @RequestBody FlowsWrapper request,
final @Parameter(description = "DSL to use. For example: 'Kamelet Binding'.")
@QueryParam("dsl") String dsl) {
return deploymentService.crds(request, dsl);
return deploymentService.crds(request.flows(), dsl);
}

/*
Expand All @@ -84,10 +86,9 @@ public String crds(
@Operation(summary = "Get Integration Object",
description = "Given the associated custom resource definition, returns the JSON object."
+ " This is an idempotent operation.")
public List<Integration> integration(
public FlowsWrapper integration(
final @RequestBody String crd,
final @Parameter(description = "DSL to use. For example: "
+ "'Kamelet Binding'.")
final @Parameter(description = "DSL to use. For example: 'Kamelet Binding'.")
@QueryParam("dsl") String dsl) {
List<Integration> integrations = new ArrayList<>();

Expand Down Expand Up @@ -123,7 +124,7 @@ public List<Integration> integration(
}
}

return integrations;
return new FlowsWrapper(integrations, Map.of());
}

private void decorateIntegration(String dsl, List<Integration> integrations,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kaoto.backend.api.resource.v2;

import io.kaoto.backend.api.resource.model.FlowsWrapper;
import io.kaoto.backend.api.resource.v1.model.Integration;
import io.kaoto.backend.api.service.deployment.generator.kamelet.KameletRepresenter;
import io.kaoto.backend.model.deployment.kamelet.KameletBinding;
Expand Down Expand Up @@ -45,7 +46,7 @@ void amqAmq() throws Exception {
.then()
.statusCode(Response.Status.OK.getStatusCode());

var flows = Arrays.asList(res.extract().body().as(Integration[].class));
var flows = res.extract().body().as(FlowsWrapper.class).flows();
assertTrue(!flows.isEmpty());
var flow = flows.get(0);
assertEquals(2, flow.getSteps().size());
Expand Down Expand Up @@ -105,7 +106,7 @@ void amqAmqFromJson() throws Exception {
.then()
.statusCode(Response.Status.OK.getStatusCode());

var flows = Arrays.asList(res.extract().body().as(Integration[].class));
var flows = res.extract().body().as(FlowsWrapper.class).flows();
assertTrue(!flows.isEmpty());
var flow = flows.get(0);
assertEquals(2, flow.getSteps().size());
Expand Down Expand Up @@ -168,7 +169,7 @@ void scriptStep() throws Exception {
.then()
.statusCode(Response.Status.OK.getStatusCode());

var flows = Arrays.asList(res.extract().body().as(Integration[].class));
var flows = res.extract().body().as(FlowsWrapper.class).flows();
assertTrue(!flows.isEmpty());
var flow = flows.get(0);
assertEquals(2, flow.getSteps().size());
Expand Down Expand Up @@ -295,7 +296,7 @@ void uriLogStop() throws Exception {
.then()
.statusCode(Response.Status.OK.getStatusCode());

var flows = Arrays.asList(res.extract().body().as(Integration[].class));
var flows = res.extract().body().as(FlowsWrapper.class).flows();
assertTrue(!flows.isEmpty());
var flow = flows.get(0);
var filter = flow.getSteps().get(1);
Expand Down Expand Up @@ -363,7 +364,7 @@ void roundTrip(String file) throws IOException {

assertEquals(res0.extract().body().asString(), res1.extract().body().asString());

var flows = Arrays.asList(res1.extract().body().as(Integration[].class));
var flows = res1.extract().body().as(FlowsWrapper.class);

//Now let's try to recreate the source code
var res2 = given()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{ "flows": [
{
"dsl": "Camel Route",
"metadata": {
Expand Down Expand Up @@ -2795,4 +2795,5 @@
"params": [],
"parameters": null
}
]
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{ "flows": [
{
"dsl": "Camel Route",
"metadata": {
Expand Down Expand Up @@ -144,4 +144,4 @@
],
"params": []
}
]
]}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{ "flows": [
{
"dsl": "Camel Route",
"metadata": {
Expand Down Expand Up @@ -456,4 +456,4 @@
],
"params": []
}
]
]}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{ "flows": [
{
"dsl": "Camel Route",
"metadata": {
Expand Down Expand Up @@ -287,4 +287,4 @@
],
"params": []
}
]
]}

0 comments on commit efa5105

Please sign in to comment.