From 764d79750fc54d165a88542e03d18b3eb3d10d4b Mon Sep 17 00:00:00 2001 From: Tiago Dolphine Date: Wed, 11 Nov 2020 15:29:19 -0300 Subject: [PATCH] Removing feature toggle for spring api --- .../CallbackJobsServiceResource.java | 62 ++++++++----------- .../feature/DefaultFeatureToggleManager.java | 28 --------- .../kie/internal/feature/FeatureToggle.java | 43 ------------- .../feature/FeatureToggleManager.java | 22 ------- .../src/main/resources/application.properties | 4 -- .../persistence/application.properties | 4 -- .../integrationtests/springboot/OASTest.java | 13 ++-- .../src/main/resources/application.properties | 4 -- .../persistence/application.properties | 4 -- .../kogito/codegen/TemplatedGenerator.java | 7 +-- .../codegen/process/ProcessCodegen.java | 7 +-- kogito-springboot/pom.xml | 13 +--- 12 files changed, 34 insertions(+), 177 deletions(-) delete mode 100644 api/kogito-internal/src/main/java/org/kie/internal/feature/DefaultFeatureToggleManager.java delete mode 100644 api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggle.java delete mode 100644 api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggleManager.java diff --git a/addons/jobs/jobs-management-springboot-addon/src/main/java/org/kie/kogito/jobs/management/springboot/CallbackJobsServiceResource.java b/addons/jobs/jobs-management-springboot-addon/src/main/java/org/kie/kogito/jobs/management/springboot/CallbackJobsServiceResource.java index 5a41d4fb53f..c3b6d29b82c 100644 --- a/addons/jobs/jobs-management-springboot-addon/src/main/java/org/kie/kogito/jobs/management/springboot/CallbackJobsServiceResource.java +++ b/addons/jobs/jobs-management-springboot-addon/src/main/java/org/kie/kogito/jobs/management/springboot/CallbackJobsServiceResource.java @@ -18,16 +18,6 @@ import java.util.Optional; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; - import org.kie.kogito.Application; import org.kie.kogito.process.Process; import org.kie.kogito.process.ProcessInstance; @@ -36,8 +26,17 @@ import org.kie.kogito.services.uow.UnitOfWorkExecutor; import org.kie.kogito.timer.TimerInstance; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; -@Path("/management/jobs") +@RestController +@RequestMapping("/management/jobs") public class CallbackJobsServiceResource { @Autowired @@ -45,40 +44,31 @@ public class CallbackJobsServiceResource { @Autowired Application application; - - @POST - @Path("{processId}/instances/{processInstanceId}/timers/{timerId}") - @Consumes(MediaType.APPLICATION_JSON) - public Response triggerTimer(@PathParam("processId") String processId, - @PathParam("processInstanceId") String processInstanceId, - @PathParam("timerId") String timerId, - @QueryParam("limit") @DefaultValue("0") Integer limit) { + + @PostMapping(value = "{processId}/instances/{processInstanceId}/timers/{timerId}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity triggerTimer(@PathVariable("processId") String processId, + @PathVariable("processInstanceId") String processInstanceId, + @PathVariable("timerId") String timerId, + @RequestParam(value = "limit", defaultValue = "0", required = false) Integer limit) { if (processId == null || processInstanceId == null) { - return Response.status(Status.BAD_REQUEST).entity("Process id and Process instance id must be given").build(); + return ResponseEntity.badRequest().body("Process id and Process instance id must be given"); } - - - Process process = processes.processById(processId); + + Process process = processes.processById(processId); if (process == null) { - return Response.status(Status.NOT_FOUND).entity("Process with id " + processId + " not found").build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Process with id " + processId + " not found"); } - - return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> { - Optional> processInstanceFound = process.instances().findById(processInstanceId); + + return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> { + Optional> processInstanceFound = process.instances().findById(processInstanceId); if (processInstanceFound.isPresent()) { ProcessInstance processInstance = processInstanceFound.get(); String[] ids = timerId.split("_"); processInstance.send(Sig.of("timerTriggered", TimerInstance.with(Long.parseLong(ids[1]), timerId, limit))); } else { - return Response.status(Status.NOT_FOUND).entity("Process instance with id " + processInstanceId + " not found").build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Process instance with id " + processInstanceId + " not found"); } - - return Response.status(Status.OK).build(); - + return ResponseEntity.ok().build(); }); - - } - - -} +} \ No newline at end of file diff --git a/api/kogito-internal/src/main/java/org/kie/internal/feature/DefaultFeatureToggleManager.java b/api/kogito-internal/src/main/java/org/kie/internal/feature/DefaultFeatureToggleManager.java deleted file mode 100644 index f9059148503..00000000000 --- a/api/kogito-internal/src/main/java/org/kie/internal/feature/DefaultFeatureToggleManager.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kie.internal.feature; - -/** - * Default implementation of the {@link FeatureToggleManager} based on system properties. - */ -public class DefaultFeatureToggleManager implements FeatureToggleManager { - - @Override - public boolean isEnabled(String featureKey) { - return Boolean.parseBoolean(System.getProperty(featureKey, Boolean.FALSE.toString())); - } -} \ No newline at end of file diff --git a/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggle.java b/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggle.java deleted file mode 100644 index ecebf3b5018..00000000000 --- a/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggle.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kie.internal.feature; - -/** - * Centralize the features under development or not completed to be released, that could be enabled or disabled during - * runtime or build time. After the features are completed, the toggle could be removed along with the code checking - * this feature. - * Using this class make things easier to track the features in different points of code facilitating the removal of - * them. - */ -public class FeatureToggle { - - public static final String ENDPOINTS_SPRING_API_ENABLED = "endpoints.spring.api.enabled"; - - private final FeatureToggleManager manager; - - public FeatureToggle() { - this(new DefaultFeatureToggleManager()); - } - - public FeatureToggle(FeatureToggleManager manager) { - this.manager = manager; - } - - public boolean isEnabled(String featureKey){ - return manager.isEnabled(featureKey); - } -} \ No newline at end of file diff --git a/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggleManager.java b/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggleManager.java deleted file mode 100644 index 0a18b2d5899..00000000000 --- a/api/kogito-internal/src/main/java/org/kie/internal/feature/FeatureToggleManager.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kie.internal.feature; - -public interface FeatureToggleManager { - - boolean isEnabled(String featureKey); -} diff --git a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/main/resources/application.properties b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/main/resources/application.properties index ba90d5bc830..532b7230832 100644 --- a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/main/resources/application.properties +++ b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/main/resources/application.properties @@ -1,8 +1,4 @@ server.address=0.0.0.0 -spring.mvc.servlet.path=/docs - -resteasy.jaxrs.scan-packages=org.kie.kogito.**,http* - # for these tests, we do NOT want stronglytyped to be enabled, leave it as default disabled. # kogito.decisions.stronglytyped=false diff --git a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/extra-resources/persistence/application.properties b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/extra-resources/persistence/application.properties index f983ff1d2de..7dacfde3031 100644 --- a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/extra-resources/persistence/application.properties +++ b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/extra-resources/persistence/application.properties @@ -1,9 +1,5 @@ server.address=0.0.0.0 -spring.mvc.servlet.path=/docs - -resteasy.jaxrs.scan-packages=org.kie.kogito.**,http* - # Used for persistence profile infinispan.remote.sasl-mechanism=PLAIN infinispan.remote.auth-server-name=infinispan diff --git a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/java/org/kie/kogito/integrationtests/springboot/OASTest.java b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/java/org/kie/kogito/integrationtests/springboot/OASTest.java index 126818b60d9..9515495a406 100644 --- a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/java/org/kie/kogito/integrationtests/springboot/OASTest.java +++ b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-it/src/test/java/org/kie/kogito/integrationtests/springboot/OASTest.java @@ -32,12 +32,10 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.ContextConfiguration; - import static io.restassured.RestAssured.given; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; - import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.greaterThan; @@ -50,15 +48,12 @@ class OASTest extends BaseRestTest { RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); } - @Value("${spring.mvc.servlet.path}") - private String path; - @Test public void testOASdmnDefinitions() { RestAssured.given() - .get(path + "/dmnDefinitions.json") - .then() - .statusCode(200) - .body("definitions", aMapWithSize(greaterThan(0))); + .get("/dmnDefinitions.json") + .then() + .statusCode(200) + .body("definitions", aMapWithSize(greaterThan(0))); } } diff --git a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/main/resources/application.properties b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/main/resources/application.properties index acd82016a3d..04e4c5d1970 100644 --- a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/main/resources/application.properties +++ b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/main/resources/application.properties @@ -1,9 +1,5 @@ server.address=0.0.0.0 -spring.mvc.servlet.path=/docs - -resteasy.jaxrs.scan-packages=org.kie.kogito.**,http* - spring.kafka.consumer.group-id=kogito-group spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer diff --git a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/test/extra-resources/persistence/application.properties b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/test/extra-resources/persistence/application.properties index dbf9fa00b83..5767db05ac4 100644 --- a/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/test/extra-resources/persistence/application.properties +++ b/integration-tests/integration-tests-springboot/src/it/integration-tests-springboot-kafka-it/src/test/extra-resources/persistence/application.properties @@ -1,9 +1,5 @@ server.address=0.0.0.0 -spring.mvc.servlet.path=/docs - -resteasy.jaxrs.scan-packages=org.kie.kogito.**,http* - # Used for persistence profile infinispan.remote.sasl-mechanism=PLAIN infinispan.remote.auth-server-name=infinispan diff --git a/kogito-codegen/src/main/java/org/kie/kogito/codegen/TemplatedGenerator.java b/kogito-codegen/src/main/java/org/kie/kogito/codegen/TemplatedGenerator.java index d13e9980efa..4079131115c 100644 --- a/kogito-codegen/src/main/java/org/kie/kogito/codegen/TemplatedGenerator.java +++ b/kogito-codegen/src/main/java/org/kie/kogito/codegen/TemplatedGenerator.java @@ -25,7 +25,6 @@ import org.kie.kogito.codegen.di.CDIDependencyInjectionAnnotator; import org.kie.kogito.codegen.di.DependencyInjectionAnnotator; import org.kie.kogito.codegen.di.SpringDependencyInjectionAnnotator; -import org.kie.internal.feature.FeatureToggle; import static com.github.javaparser.StaticJavaParser.parse; @@ -40,7 +39,6 @@ public class TemplatedGenerator { private DependencyInjectionAnnotator annotator; private final String targetTypeName; - private FeatureToggle featureToggle; public TemplatedGenerator( String packageName, @@ -64,7 +62,6 @@ public TemplatedGenerator( this.resourceCdi = resourceCdi; this.resourceSpring = resourceSpring; this.resourceDefault = resourceDefault; - this.featureToggle = new FeatureToggle(); } public TemplatedGenerator( @@ -124,9 +121,7 @@ private String selectResource() { } else { return resourceDefault; } - } else if (annotator instanceof CDIDependencyInjectionAnnotator - //can be removed after spring apis are completed - || (targetTypeName.contains("Resource") && !featureToggle.isEnabled(FeatureToggle.ENDPOINTS_SPRING_API_ENABLED))) { + } else if (annotator instanceof CDIDependencyInjectionAnnotator) { return resourceCdi; } else if (annotator instanceof SpringDependencyInjectionAnnotator) { return resourceSpring; diff --git a/kogito-codegen/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java b/kogito-codegen/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java index 4274ef85033..05be2a8aa26 100644 --- a/kogito-codegen/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java +++ b/kogito-codegen/src/main/java/org/kie/kogito/codegen/process/ProcessCodegen.java @@ -51,7 +51,6 @@ import org.kie.kogito.codegen.ApplicationGenerator; import org.kie.kogito.codegen.ApplicationSection; import org.kie.kogito.codegen.ConfigGenerator; -import org.kie.kogito.codegen.DefaultResourceGeneratorFactory; import org.kie.kogito.codegen.GeneratedFile; import org.kie.kogito.codegen.GeneratedFile.Type; import org.kie.kogito.codegen.ResourceGeneratorFactory; @@ -62,7 +61,6 @@ import org.kie.kogito.codegen.process.events.CloudEventsMessageProducerGenerator; import org.kie.kogito.codegen.process.events.CloudEventsResourceGenerator; import org.kie.kogito.codegen.process.events.TopicsInformationResourceGenerator; -import org.kie.internal.feature.FeatureToggle; import org.kie.kogito.rules.units.UndefinedGeneratedRuleUnitVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -193,10 +191,7 @@ public ProcessCodegen(Collection processes) { setPackageName(ApplicationGenerator.DEFAULT_PACKAGE_NAME); contextClassLoader = Thread.currentThread().getContextClassLoader(); - //FIXME: once all endpoint generators are implemented it should be changed to ResourceGeneratorFactory, to - // consider Spring generators. - resourceGeneratorFactory = new FeatureToggle().isEnabled(FeatureToggle.ENDPOINTS_SPRING_API_ENABLED) ? - new ResourceGeneratorFactory() : new DefaultResourceGeneratorFactory(); + resourceGeneratorFactory = new ResourceGeneratorFactory(); } public static String defaultWorkItemHandlerConfigClass(String packageName) { diff --git a/kogito-springboot/pom.xml b/kogito-springboot/pom.xml index 6cb02410430..2d716a1f3d7 100644 --- a/kogito-springboot/pom.xml +++ b/kogito-springboot/pom.xml @@ -46,19 +46,10 @@ - - - - - - - - org.jboss.resteasy - resteasy-spring-boot-starter + org.springframework.boot + spring-boot-starter-web - org.kie.kogito kogito-api