Skip to content

Commit

Permalink
feat(run): add invoice example option
Browse files Browse the repository at this point in the history
* adds integration code for the invoice example
* adds CLI option to enable the invoice example

related to CAM-13394
  • Loading branch information
tmetzke committed Sep 14, 2021
1 parent 445fcf3 commit dbb0609
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 29 deletions.
7 changes: 7 additions & 0 deletions distro/run/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
</includes>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
<dependencySet>
<outputDirectory>internal/example/</outputDirectory>
<includes>
<include>org.camunda.bpm.run:camunda-bpm-run-modules-example-invoice</include>
</includes>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
<dependencySet>
<outputDirectory />
<includes>
Expand Down
14 changes: 14 additions & 0 deletions distro/run/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.camunda.bpm.run</groupId>
<artifactId>camunda-bpm-run-modules-example-invoice</artifactId>
<version>${project.version}</version>
<type>jar</type>
<exclusions>
<!-- do not add transitive dependencies to generated dependency list -->
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.camunda.bpm.run</groupId>
<artifactId>camunda-bpm-run-core</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions distro/run/assembly/resources/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ camunda.bpm:
cors:
enabled: true
allowed-origins: "*"
# https://docs.camunda.org/manual/latest/user-guide/camunda-bpm-run/#example-application
example:
enabled: true

# datasource configuration is required
spring.datasource:
Expand Down
13 changes: 11 additions & 2 deletions distro/run/assembly/resources/start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ REM set environment parameters
SET webappsPath=%BASEDIR%internal\webapps
SET restPath=%BASEDIR%internal\rest
SET swaggerPath=%BASEDIR%internal\swaggerui
SET examplePath=%BASEDIR%internal\example
SET classPath=%BASEDIR%configuration\userlib,%BASEDIR%configuration\keystore
SET optionalComponentChosen=false
SET restChosen=false
Expand Down Expand Up @@ -62,6 +63,12 @@ IF [%~1]==[--swaggerui] (
ECHO Swagger UI enabled
)

IF [%~1]==[--example] (
SET optionalComponentChosen=true
SET classPath=%examplePath%,%classPath%
ECHO Invoice Example included - needs to be enabled in application configuration as well
)

IF [%~1]==[--production] (
SET productionChosen=true
SET configuration=%BASEDIR%configuration\production.yml
Expand All @@ -71,7 +78,8 @@ SHIFT
GOTO Loop
:Continue

REM if neither REST nor Webapps are chosen, enable both as well as Swagger UI if production mode is not chosen
REM If no optional component is chosen, enable REST and Webapps.
REM If production mode is not chosen, also enable Swagger UI and the example application.
setlocal enabledelayedexpansion
IF [%optionalComponentChosen%]==[false] (
SET restChosen=true
Expand All @@ -80,7 +88,8 @@ IF [%optionalComponentChosen%]==[false] (
IF [%productionChosen%]==[false] (
SET swaggeruiChosen=true
ECHO Swagger UI enabled
SET classPath=%swaggerPath%,%classPath%
ECHO Invoice Example included - needs to be enabled in application configuration as well
SET classPath=%swaggerPath%,%examplePath%,%classPath%
)
SET classPath=%webappsPath%,%restPath%,!classPath!
)
Expand Down
11 changes: 9 additions & 2 deletions distro/run/assembly/resources/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fi
webappsPath=$BASEDIR/internal/webapps/
restPath=$BASEDIR/internal/rest/
swaggerPath=$BASEDIR/internal/swaggerui
examplePath=$BASEDIR/internal/example
classPath=$BASEDIR/configuration/userlib/,$BASEDIR/configuration/keystore/
optionalComponentChosen=false
restChosen=false
Expand All @@ -48,6 +49,10 @@ while [ "$1" != "" ]; do
classPath=$swaggerPath,$classPath
echo Swagger UI enabled
;;
--example ) optionalComponentChosen=true
classPath=$examplePath,$classPath
echo Invoice Example included - needs to be enabled in application configuration as well
;;
--production ) configuration=$BASEDIR/configuration/production.yml
productionChosen=true
;;
Expand All @@ -56,15 +61,17 @@ while [ "$1" != "" ]; do
shift
done

# if neither REST nor Webapps are chosen, enable both as well as Swagger UI if production mode is not chosen
# If no optional component is chosen, enable REST and Webapps.
# If production mode is not chosen, also enable Swagger UI and the example application.
if [ "$optionalComponentChosen" = "false" ]; then
restChosen=true
echo REST API enabled
echo WebApps enabled
if [ "$productionChosen" = "false" ]; then
swaggeruiChosen=true
echo Swagger UI enabled
classPath=$swaggerPath,$classPath
echo Invoice Example included - needs to be enabled in application configuration as well
classPath=$swaggerPath,$examplePath,$classPath
fi
classPath=$webappsPath,$restPath,$classPath
fi
Expand Down
79 changes: 79 additions & 0 deletions distro/run/modules/example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.camunda.bpm.run</groupId>
<artifactId>camunda-bpm-run-modules</artifactId>
<version>7.16.0-SNAPSHOT</version>
</parent>

<artifactId>camunda-bpm-run-modules-example-invoice</artifactId>
<name>Camunda Platform - Run - Module Example Invoice</name>

<properties>
<!-- generate a bom of compile time dependencies for the license book.
Note: Every compile time dependency will end up in the license book. Please
declare only dependencies that are actually needed -->
<skip-third-party-bom>false</skip-third-party-bom>
</properties>

<dependencies>

<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.camunda.bpm.example</groupId>
<artifactId>camunda-example-invoice</artifactId>
<version>${project.version}</version>
<classifier>classes</classifier>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- override version to use fileMappers -->
<version>3.2.0</version>
<executions>
<execution>
<id>unpack-invoice</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.camunda.bpm.example</groupId>
<artifactId>camunda-example-invoice</artifactId>
<version>${project.version}</version>
<type>war</type>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<excludes>
assets/**,META-INF/**,*.html,WEB-INF/*.xml,WEB-INF
</excludes>
<fileMappers>
<org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
<pattern>^\QWEB-INF/classes/\E</pattern>
<replacement>./</replacement>
</org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
</fileMappers>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; 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.camunda.bpm.run.example.invoice;

import javax.annotation.PostConstruct;

import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.example.invoice.InvoiceProcessApplication;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent;
import org.camunda.bpm.spring.boot.starter.property.CamundaBpmProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@ConditionalOnProperty(name = "enabled", havingValue = "true", prefix = CamundaBpmProperties.PREFIX + ".run.example")
@Configuration
@EnableProcessApplication("invoiceProcessApplicationSpringBoot")
public class Application implements WebMvcConfigurer {

private static final Logger LOG = LoggerFactory.getLogger(Application.class);

@Autowired
protected ProcessEngine processEngine;

protected InvoiceProcessApplication invoicePa = new InvoiceProcessApplication();

@PostConstruct
public void deployInvoice() {
LOG.info("Invoice example started, creating deployment");
invoicePa.createDeployment("invoiceProcessApplicationSpringBoot", processEngine, invoicePa.getClass().getClassLoader());
}

@EventListener
public void onPostDeploy(PostDeployEvent event) {
LOG.info("Starting invoice example instance");
invoicePa.startFirstProcess(event.getProcessEngine());
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/forms/**").addResourceLocations("classpath:/forms/");
}

}
1 change: 1 addition & 0 deletions distro/run/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<module>modules</module>
<module>modules/rest</module>
<module>modules/swaggerui</module>
<module>modules/example</module>
<module>core</module>
<module>assembly</module>
<module>qa</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void stopApp() {

public void runStartScript() throws IOException {
container = new SpringBootManagedContainer();
container.replaceConfigurationYml(SpringBootManagedContainer.APPLICATION_YML_PATH,
AutoDeploymentIT.class.getClassLoader().getResourceAsStream("example-disabled.yml"));
try {
container.start();
} catch (Exception e) {
Expand All @@ -73,7 +75,7 @@ public void runStartScript() throws IOException {
}

public void createBPMNFile(String path, String processDefinitionId) throws IOException {
Path resourcesDir = Paths.get(baseDirectory, "configuration", "resources", path);
Path resourcesDir = Paths.get(baseDirectory, SpringBootManagedContainer.RESOURCES_PATH, path);
resourcesDir.toFile().mkdirs();
File bpmnFile = Paths.get(resourcesDir.toString(), "process.bpmn").toFile();
bpmnFile.createNewFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,27 @@ public class ComponentAvailabilityIT {
public boolean webappsAvailable;
@Parameter(3)
public boolean swaggerUIAvailable;
@Parameter(4)
public boolean exampleAvailable;

@Parameters(name = "Test instance: {index}. Rest: {1}, Webapps: {2}, SwaggerUI: {3}")
@Parameters(name = "Test instance: {index}. Rest: {1}, Webapps: {2}, SwaggerUI: {3}, Example: {4}")
public static Collection<Object[]> commands() {
return Arrays.asList(new Object[][] {
{ new String[0], true, true, true },
{ new String[]{"--rest"}, true, false, false },
{ new String[]{"--rest", "--webapps"}, true, true, false },
{ new String[]{"--webapps"}, false, true, false },
{ new String[]{"--swaggerui"}, false, false, true },
{ new String[]{"--rest", "--webapps", "--swaggerui"}, true, true, true }
{ new String[0], true, true, true, true },
{ new String[]{"--rest"}, true, false, false, false },
{ new String[]{"--rest", "--webapps"}, true, true, false, false },
{ new String[]{"--rest", "--example"}, true, false, false, true },
{ new String[]{"--webapps"}, false, true, false, false },
{ new String[]{"--swaggerui"}, false, false, true, false },
{ new String[]{"--rest", "--webapps", "--swaggerui"}, true, true, true, false },
{ new String[]{"--rest", "--webapps", "--swaggerui", "--example"}, true, true, true, true }
});
}

private static SpringBootManagedContainer container;

@BeforeParam
public static void runStartScript(String[] commands, boolean restAvailable, boolean webappsAvailable, boolean swaggerUIAvailable) {
public static void runStartScript(String[] commands, boolean restAvailable, boolean webappsAvailable, boolean swaggerUIAvailable, boolean exampleAvailable) {
container = new SpringBootManagedContainer(commands);
try {
container.start();
Expand Down Expand Up @@ -124,4 +128,19 @@ public void shouldFindSwaggerUI() {
}
}

@Test
public void shouldFindExample() {
Response response = when().get(container.getBaseUrl() + "/engine-rest/process-definition");
if (exampleAvailable && restAvailable) {
response.then()
.body("size()", is(3))
.body("key[0]", is("ReviewInvoice"));
} else if (restAvailable) {
response.then()
.body("size()", is(0));
} else {
response.then()
.statusCode(404);
}
}
}
Loading

0 comments on commit dbb0609

Please sign in to comment.