From 9cfc9005faf1baa48e6b2dd81827ab306a9bf401 Mon Sep 17 00:00:00 2001 From: Maria Arias de Reyna Date: Thu, 1 Jun 2023 15:48:55 +0200 Subject: [PATCH] feature: Use DSL included in the body instead of param --- .../api/resource/v2/IntegrationsResource.java | 7 ++--- .../service/deployment/DeploymentService.java | 13 ++++++-- .../resource/v2/IntegrationsResourceTest.java | 30 +++++++++---------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/io/kaoto/backend/api/resource/v2/IntegrationsResource.java b/api/src/main/java/io/kaoto/backend/api/resource/v2/IntegrationsResource.java index 08b3e83c6..df1bcf403 100644 --- a/api/src/main/java/io/kaoto/backend/api/resource/v2/IntegrationsResource.java +++ b/api/src/main/java/io/kaoto/backend/api/resource/v2/IntegrationsResource.java @@ -69,11 +69,8 @@ public void setDslSpecifications(final Instance dslSpecificati @CacheResult(cacheName = "api") @Operation(summary = "Get CRDs", description = "Returns the associated custom resource definitions. This is an idempotent operation.") - public String crds( - final @RequestBody FlowsWrapper request, - final @Parameter(description = "DSL to use. For example: 'Kamelet Binding'.") - @QueryParam("dsl") String dsl) { - return deploymentService.crds(request.flows(), request.metadata(), dsl); + public String crds(final @RequestBody FlowsWrapper request) { + return deploymentService.crds(request.flows(), request.metadata()); } /* diff --git a/api/src/main/java/io/kaoto/backend/api/service/deployment/DeploymentService.java b/api/src/main/java/io/kaoto/backend/api/service/deployment/DeploymentService.java index 17dae8db7..591f01c19 100644 --- a/api/src/main/java/io/kaoto/backend/api/service/deployment/DeploymentService.java +++ b/api/src/main/java/io/kaoto/backend/api/service/deployment/DeploymentService.java @@ -111,21 +111,28 @@ public String crd(final Integration i, final String dsl) { /* * 🐱method crds: String - * 🐱param i: List + * 🐱param integrationList: List * 🐱param dsl: String * * Based on the provided steps, return a valid yaml string to deploy */ @WithSpan - public String crds(final List i, final Map metadata, final String dsl) { + public String crds(final List integrationList, final Map metadata) { List> integrations = new LinkedList<>(); + String dsl = null; - for (Integration integration : i) { + for (Integration integration : integrationList) { var parseResult = new StepParserService.ParseResult(); parseResult.setMetadata(integration.getMetadata()); parseResult.setSteps(integration.getSteps()); parseResult.setParameters(integration.getParameters()); integrations.add(parseResult); + if (integration.getDsl() != null) { + if (dsl != null && !integration.getDsl().equalsIgnoreCase(dsl)) { + log.error("We were sent a mix of DSL in the same list of flows!"); + } + dsl = integration.getDsl(); + } } if (metadata != null && !metadata.isEmpty()) { diff --git a/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java b/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java index ef2f21e94..babc17339 100644 --- a/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java +++ b/api/src/test/java/io/kaoto/backend/api/resource/v2/IntegrationsResourceTest.java @@ -74,9 +74,9 @@ void amqAmq() throws Exception { res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); @@ -90,9 +90,9 @@ void amqAmqFromJson() throws Exception { var res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); @@ -139,9 +139,9 @@ void newBranchStep() throws Exception { .toURI())); var res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); Yaml yaml = new Yaml(new Constructor(KameletBinding.class), new KameletRepresenter()); @@ -154,9 +154,9 @@ void scriptStep() throws Exception { IntegrationsResourceTest.class.getResource("../../resource/script-multi.json").toURI())); var res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); String yaml = res.extract().body().asString(); @@ -196,9 +196,9 @@ void expressionObject() throws Exception { res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); @@ -272,9 +272,9 @@ void kameletUri() throws Exception { res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); @@ -318,9 +318,9 @@ void noFrom() throws Exception { IntegrationsResourceTest.class.getResource("../../resource/no-from-multi.json").toURI())); var res = given() .when() - .contentType("application/json") + .contentType(MediaType.APPLICATION_JSON) .body(json) - .post("?dsl=Camel Route") + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); var yaml = res.extract().body().asString(); @@ -372,7 +372,7 @@ void roundTrip(String file) throws IOException { .when() .contentType(MediaType.APPLICATION_JSON) .body(flows) - .post("?dsl=" + parameters[0]) + .post() .then() .statusCode(Response.Status.OK.getStatusCode()); var sourceCode = res2.extract().body().asString();