Skip to content

Commit

Permalink
Removing feature toggle for spring api
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagodolphine committed Nov 16, 2020
1 parent ffc0c0c commit 764d797
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,49 +26,49 @@
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
Processes processes;

@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<? extends ProcessInstance<?>> processInstanceFound = process.instances().findById(processInstanceId);

return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
Optional<? extends ProcessInstance<?>> 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();
});


}


}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)));
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,7 +39,6 @@ public class TemplatedGenerator {

private DependencyInjectionAnnotator annotator;
private final String targetTypeName;
private FeatureToggle featureToggle;

public TemplatedGenerator(
String packageName,
Expand All @@ -64,7 +62,6 @@ public TemplatedGenerator(
this.resourceCdi = resourceCdi;
this.resourceSpring = resourceSpring;
this.resourceDefault = resourceDefault;
this.featureToggle = new FeatureToggle();
}

public TemplatedGenerator(
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -193,10 +191,7 @@ public ProcessCodegen(Collection<? extends Process> 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) {
Expand Down
13 changes: 2 additions & 11 deletions kogito-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@
</dependencyManagement>

<dependencies>
<!-- FIXME: spring-boot-starter-web should be the default, it should be removed the resteasy-spring-boot-starter
after all the Endpoint generation are completed to use Spring Web API -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->

<!-- this should be removed when all endpoints for spring have been migrated to spring-web apis -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-api</artifactId>
Expand Down

0 comments on commit 764d797

Please sign in to comment.