diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7815cc64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +lib/ +logs/ +metrics/ +``` + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +.properties +.DS_Store +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..400e54e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:11 +VOLUME /tmp +EXPOSE 8080 +ADD target/flowableDemo-0.0.2.jar flowableDemo-0.0.2.jar +ENTRYPOINT ["java","-jar","/flowableDemo-0.0.2.jar"] diff --git a/README.md b/README.md new file mode 100644 index 00000000..03ff74b0 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# Protools POC - Flowable Engine 🩊 +[Demo Link 😉](https://protools.dev.insee.io/) + +This POC was build to test the Flowable Engine. It only serves as a demonstration support. + +Current WIP & experimentations can be found on the protools-wip branch. + +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + +## Installation +[Link to swagger](https://protools-flowable-demo.dev.insee.io/) + +### Installation via Docker (Recommended) + +```bash +docker pull docker pull inseefr/protools-back-office +docker run -d --name protoolsflowable -p 8080:8080 docker pull inseefr/protools-back-office:experimental +``` +### Manual Install +``` bash +git clone git@github.com:InseeFr/Protools-Back-Office.git +cd Protools-Back-Office +git checkout demo +./mvnw spring-boot:run -Dmaven.test.skip +``` + + + + + diff --git a/mvnw b/mvnw new file mode 100755 index 00000000..8a8fb228 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# https://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 00000000..1d8ab018 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..2287b6dd --- /dev/null +++ b/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.6.7 + + + com.protools + flowableDemo + 0.0.2 + flowablePOC + POC Protools using Flowable - Demo version + + 11 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + + com.h2database + h2 + runtime + + + org.postgresql + postgresql + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.flowable + flowable-spring-boot-starter-rest + 6.7.2 + + + org.flowable + flowable-form-spring-configurator + 6.7.2 + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springdoc + springdoc-openapi-ui + 1.6.8 + + + com.google.code.gson + gson + 2.9.0 + + + org.json + json + 20220320 + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + + + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + + org.apache.logging.log4j + log4j-api + ${log4j2.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + + + + + + {Protools_Flowable} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + build-info + + + + + + + + diff --git a/src/main/java/com/protools/flowableDemo/FlowablePocApplication.java b/src/main/java/com/protools/flowableDemo/FlowablePocApplication.java new file mode 100644 index 00000000..c4e296a3 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/FlowablePocApplication.java @@ -0,0 +1,13 @@ +package com.protools.flowableDemo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FlowablePocApplication { + + public static void main(String[] args) { + SpringApplication.run(FlowablePocApplication.class, args); + } + +} diff --git a/src/main/java/com/protools/flowableDemo/beans/Person.java b/src/main/java/com/protools/flowableDemo/beans/Person.java new file mode 100644 index 00000000..1ab030b7 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/beans/Person.java @@ -0,0 +1,88 @@ +package com.protools.flowableDemo.beans; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class Person { + private Long id; + private String nom; + private String prenom; + private String email; + + private Long idSurvey; + public Person() { + + } + public Person(String nom, String prenom, String email){ + this.email =email; + this.nom = nom; + this.prenom = prenom; + + } + + public Long getId() { + return id; + } + + public String getNom() { + return nom; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public String getPrenom() { + return prenom; + } + + public void setPrenom(String prenom) { + this.prenom = prenom; + } + + public Long getIdSurvey() { + return idSurvey; + } + + public void setIdSurvey(Long id_survey) { + this.idSurvey = id_survey; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return nom.equals(person.nom) && prenom.equals(person.prenom) && email.equals(person.email) ; + } + + @Override + public int hashCode() { + return Objects.hash(nom, prenom, email); + } + + @Override + public String toString() { + return "Person{" + + "nom='" + nom + '\'' + + ", prenom='" + prenom + '\'' + + ", email='" + email + '\'' + + + '}'; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/src/main/java/com/protools/flowableDemo/beans/Survey.java b/src/main/java/com/protools/flowableDemo/beans/Survey.java new file mode 100644 index 00000000..9bc6285e --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/beans/Survey.java @@ -0,0 +1,102 @@ +package com.protools.flowableDemo.beans; + +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class Survey { + private Long id; + private String name; + private String dateDeb; + private String dateEnd; + private String state_survey; + private String sampleSize; + + + public Survey(){} + + public Survey(Long id, String name, String dateDeb, String dateEnd, String state_survey) { + this.id = id; + this.name = name; + this.dateDeb = dateDeb; + this.dateEnd = dateEnd; + this.state_survey = state_survey; + } + + public String getState_survey() { + return state_survey; + } + + public void setState_survey(String state_survey) { + this.state_survey = state_survey; + } + + public String getSampleSize() { + return sampleSize; + } + + public void setSampleSize(String sampleSize) { + this.sampleSize = sampleSize; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDateDeb() { + return dateDeb; + } + + public void setDateDeb(String dateDeb) { + this.dateDeb = dateDeb; + } + + public String getDateEnd() { + return dateEnd; + } + + public void setDateEnd(String dateEnd) { + this.dateEnd = dateEnd; + } + + public Long getid() { + return id; + } + + public String getState() { + return state_survey; + } + + public void setState(String state) { + this.state_survey = state; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Survey survey = (Survey) o; + return Objects.equals(name, survey.name) && Objects.equals(dateDeb, survey.dateDeb) && Objects.equals(dateEnd, survey.dateEnd); + } + + @Override + public int hashCode() { + return Objects.hash(name, dateDeb, dateEnd); + } + + @Override + public String toString() { + return "Survey{" + + "id=" + id + + ", name='" + name + '\'' + + ", dateDeb='" + dateDeb + '\'' + + ", dateEnd='" + dateEnd + '\'' + + ", state='" + state_survey + '\'' + + '}'; + } +} diff --git a/src/main/java/com/protools/flowableDemo/beans/TaskRepresentation.java b/src/main/java/com/protools/flowableDemo/beans/TaskRepresentation.java new file mode 100644 index 00000000..f998a09c --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/beans/TaskRepresentation.java @@ -0,0 +1,55 @@ +package com.protools.flowableDemo.beans; + +public class TaskRepresentation { + private String id; + private String name; + private String getParentTaskId; + private String getProcessInstanceId; + + private String delegationState; + + public TaskRepresentation(String id, String name, String getParentTaskId, String getProcessInstanceId, String delegationState) { + this.id = id; + this.name = name; + this.getParentTaskId = getParentTaskId; + this.getProcessInstanceId = getProcessInstanceId; + this.delegationState = delegationState; + } + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public String getGetParentTaskId() { + return getParentTaskId; + } + + public void setGetParentTaskId(String getParentTaskId) { + this.getParentTaskId = getParentTaskId; + } + + public String getGetProcessInstanceId() { + return getProcessInstanceId; + } + + public void setGetProcessInstanceId(String getProcessInstanceId) { + this.getProcessInstanceId = getProcessInstanceId; + } + + public String getDelegationState() { + return delegationState; + } + + public void setDelegationState(String delegationState) { + this.delegationState = delegationState; + } +} diff --git a/src/main/java/com/protools/flowableDemo/configuration/CorsFilter.java b/src/main/java/com/protools/flowableDemo/configuration/CorsFilter.java new file mode 100644 index 00000000..4757d76a --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/configuration/CorsFilter.java @@ -0,0 +1,41 @@ +package com.protools.flowableDemo.configuration; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class CorsFilter implements Filter { + + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + HttpServletResponse response = (HttpServletResponse) res; + HttpServletRequest request = (HttpServletRequest) req; + response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader("Access-Control-Allow-Methods", "*"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", "*"); + //response.setHeader("Access-Control-Expose-Headers","yourCustomHeaderIfExist"); + + if ("OPTIONS".equalsIgnoreCase(request.getMethod())) { + response.setStatus(HttpServletResponse.SC_OK); + } else { + chain.doFilter(req, res); + } + } + + @Override + public void init(FilterConfig filterConfig) { + } + + @Override + public void destroy() { + } + +} diff --git a/src/main/java/com/protools/flowableDemo/configuration/SwaggerConfiguration.java b/src/main/java/com/protools/flowableDemo/configuration/SwaggerConfiguration.java new file mode 100644 index 00000000..a60ea41d --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/configuration/SwaggerConfiguration.java @@ -0,0 +1,28 @@ +package com.protools.flowableDemo.configuration; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.info.BuildProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfiguration { + + @Autowired + BuildProperties buildProperties; + + @Bean + public OpenAPI customOpenAPI() { + return new OpenAPI() + .components(new Components()) + .info(new Info() + .title(buildProperties.getName()) + .description("POC Protools avec Activiti Core BPMN manager") + .version(buildProperties.getVersion())); + } + + +} diff --git a/src/main/java/com/protools/flowableDemo/controllers/EventInfoController.java b/src/main/java/com/protools/flowableDemo/controllers/EventInfoController.java new file mode 100644 index 00000000..c5ed2bae --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/controllers/EventInfoController.java @@ -0,0 +1,26 @@ +package com.protools.flowableDemo.controllers; + +import com.protools.flowableDemo.services.EventInfoService; +import io.swagger.v3.oas.annotations.Operation; +import org.flowable.eventregistry.api.EventDeployment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + +@Controller +public class EventInfoController { + @Autowired + private EventInfoService eventInfoService; + + @CrossOrigin + @Operation(summary = "Get Events ") + @GetMapping(value = "/eventDeployments", produces = MediaType.APPLICATION_JSON_VALUE) + public List getEventActivity(){ + return(eventInfoService.getEventDeployments()); + } + +} diff --git a/src/main/java/com/protools/flowableDemo/controllers/HistoryInfoController.java b/src/main/java/com/protools/flowableDemo/controllers/HistoryInfoController.java new file mode 100644 index 00000000..60d85aa3 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/controllers/HistoryInfoController.java @@ -0,0 +1,64 @@ +package com.protools.flowableDemo.controllers; + +import com.protools.flowableDemo.services.HistoryInfoService; +import io.swagger.v3.oas.annotations.Operation; +import org.flowable.engine.history.HistoricActivityInstance; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.job.api.Job; +import org.flowable.task.api.history.HistoricTaskInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +@RestController +public class HistoryInfoController { + @Autowired + private HistoryInfoService historyInfoService; + + @CrossOrigin + @Operation(summary = "Get Process History") + @GetMapping(value = "/history/process", produces = MediaType.APPLICATION_JSON_VALUE) + public List getHistoryProcess(){ + return(historyInfoService.getHistoryProcess()); + } + + @CrossOrigin + @Operation(summary = "Get Tasks History by ProcessDefinitionID") + @GetMapping(value = "/history/task/{ProcessDefinitionID}", produces = MediaType.APPLICATION_JSON_VALUE) + public List getHistoryTask(@PathVariable String ProcessDefinitionID){ + return(historyInfoService.getHistoryTask(ProcessDefinitionID)); + } + + @CrossOrigin + @Operation(summary = "Get Activity History") + @GetMapping(value = "/history/activity", produces = MediaType.APPLICATION_JSON_VALUE) + public List getHistoryActivity(){ + return(historyInfoService.getHistoryActivity()); + } + + @CrossOrigin + @Operation(summary = "Get DeadLetter Jobs") + @GetMapping(value = "/history/deadLetter", produces = MediaType.APPLICATION_JSON_VALUE) + public List getDeadJobs(){ + return(historyInfoService.getFailedJobs()); + } + + @CrossOrigin + @Operation(summary = "Get Suspended Jobs") + @GetMapping(value = "/history/suspended", produces = MediaType.APPLICATION_JSON_VALUE) + public List getSuspendedJobs(){ + return(historyInfoService.getSuspendedJobs()); + } + + @CrossOrigin + @Operation(summary = "Get deleted Processes") + @GetMapping(value = "/history/deleted", produces = MediaType.APPLICATION_JSON_VALUE) + public List getDeletedProcesses(){ + return(historyInfoService.getDeletedProcess()); + } + +} diff --git a/src/main/java/com/protools/flowableDemo/controllers/ProcessController.java b/src/main/java/com/protools/flowableDemo/controllers/ProcessController.java new file mode 100644 index 00000000..e065602d --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/controllers/ProcessController.java @@ -0,0 +1,77 @@ +package com.protools.flowableDemo.controllers; + +import com.protools.flowableDemo.services.WorkflowService; +import io.swagger.v3.oas.annotations.Operation; +import org.json.JSONObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; + +@RestController +public class ProcessController { + private Logger logger =LogManager.getLogger(ProcessController.class); + @Autowired + private WorkflowService workflowService; + + @CrossOrigin + @Operation(summary = "Start process by ProcessKey") + @PostMapping(value= "/start-process/{processKey}/{businessKey}") + public String startProcessInstance(@PathVariable String processKey, @PathVariable String businessKey, @RequestBody HashMap variables){ + logger.info("> Start the process: "+ processKey); + JSONObject object = workflowService.startProcess(processKey,businessKey,variables); + logger.info(String.valueOf(object)); + return (String.valueOf(object)); + } + @CrossOrigin + @Operation(summary = "Claim all task by TaskID") + @PostMapping("/get-tasks/{assignee}/{TaskID}") + public void getTasks(@PathVariable String TaskID, @PathVariable String assignee) { + logger.info(">>> Claim assigned tasks for assignee "+ assignee+" <<<"); + workflowService.claimTasks(TaskID,assignee); + + } + @CrossOrigin + @Operation(summary = "Complete claimed task by taskID, add variables to process") + @PostMapping("/complete-task/{assignee}/{taskID}") + public void completeTaskA(@PathVariable String taskID, @RequestBody HashMap variables, @PathVariable String assignee) { + logger.info(">>> Complete assigned task for assignee "+ assignee +" <<<"); + logger.info("TaskID : "+taskID); + workflowService.completeTask(taskID,variables,assignee); + } + + @CrossOrigin + @Operation(summary = "Delete Process Instance By Process ID") + @PostMapping("/deleteProcess/{ProcessID}") + public void deleteProcess(@PathVariable String ProcessID) { + logger.info(">>> Deleting ProcessInstance :" +ProcessID+" <<<"); + workflowService.deleteProcessInstance(ProcessID); + } + + @CrossOrigin + @Operation(summary = "Suspend Process Instance By Process ID") + @PostMapping("/suspendProcess/{ProcessID}") + public void suspendProcess(@PathVariable String ProcessID) { + logger.info(">>> Suspending ProcessInstance :" +ProcessID+" <<<"); + workflowService.suspendProcessInstance(ProcessID); + } + + @CrossOrigin + @Operation(summary = "Suspend Process Instance By Process ID") + @PostMapping("/restart/{ProcessID}") + public void restartProcess(@PathVariable String ProcessID) { + logger.info(">>> Activating ProcessInstance :" +ProcessID+" <<<"); + workflowService.restartProcessInstance(ProcessID); + } + @CrossOrigin + @Operation(summary = "CancelProcess Instance By Process ID") + @PostMapping("/cancelProcess/{ProcessID}/{reason}") + public void cancelProcess(@PathVariable String ProcessID, @PathVariable String reason) { + logger.info(">>> Cancelling ProcessInstance :" +ProcessID+" <<<"); + workflowService.cancelProcessWithReason(ProcessID,reason); + } + + +} diff --git a/src/main/java/com/protools/flowableDemo/controllers/ProcessInfoController.java b/src/main/java/com/protools/flowableDemo/controllers/ProcessInfoController.java new file mode 100644 index 00000000..6625a580 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/controllers/ProcessInfoController.java @@ -0,0 +1,118 @@ +package com.protools.flowableDemo.controllers; + +import com.protools.flowableDemo.services.WorkflowInfoService; +import io.swagger.v3.oas.annotations.Operation; +import org.flowable.bpmn.model.ExtensionElement; +import org.flowable.bpmn.model.FlowElement; +import org.flowable.engine.RuntimeService; +import org.flowable.engine.TaskService; +import org.json.JSONArray; +import org.json.JSONObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@RestController +public class ProcessInfoController { + private Logger logger =LogManager.getLogger(ProcessInfoController.class); + @Autowired + private WorkflowInfoService workflowInfoService; + + @Autowired + private RuntimeService runtimeService; + + @Autowired + private TaskService taskService; + @CrossOrigin + @Operation(summary = "Get BPMN info by processDefinitionID") + @GetMapping(value = "/bpmnInfo/{processDefinitionId}", produces = MediaType.APPLICATION_JSON_VALUE) + public Map getBPMNInfo(@PathVariable String processDefinitionId){ + return(workflowInfoService.getBPMNModel(processDefinitionId)); + } + + @CrossOrigin + @Operation(summary = "Get BPMN documentation by processDefinitionID") + @GetMapping(value = "/documentation/{processDefinitionId}", produces = MediaType.APPLICATION_JSON_VALUE) + public String getBPMNModelDocumentation(@PathVariable String processDefinitionId){ + return(workflowInfoService.getBPMNModelDocumentation(processDefinitionId)); + } + + @CrossOrigin + @Operation(summary = "Get BPMN extensions elements by processDefinitionID") + @GetMapping(value = "/extensionsElement/{processDefinitionId}", produces = MediaType.APPLICATION_JSON_VALUE) + public Map> getExtensionElements(@PathVariable String processDefinitionId){ + return(workflowInfoService.getExtension(processDefinitionId)); + } + + @CrossOrigin + @Operation(summary = "Get ProcessDefinitionID (temporary endpoint)") + @GetMapping(value = "/processDefinition/{processID}", produces = MediaType.APPLICATION_JSON_VALUE) + public String getProcessDefinitionID(@PathVariable String processID){ + return(workflowInfoService.getProcessDefinitionID(processID)); + } + @CrossOrigin + @Operation(summary = "Get all processInstance") + @GetMapping(value = "/processInstances", produces = MediaType.APPLICATION_JSON_VALUE) + public String getAllProcessInstance() { + JSONObject liste = workflowInfoService.getAllProcessInstance(); + + return (String.valueOf(liste)); + } + @CrossOrigin + @Operation(summary = "Get all task by assignee") + @GetMapping(value = "/tasksAssignee/{assignee}", produces = MediaType.APPLICATION_JSON_VALUE) + public String getTasks(@PathVariable String assignee) { + JSONArray tasks = workflowInfoService.getTasks(assignee); + return String.valueOf(tasks); + } + + @CrossOrigin + @Operation(summary = "Get all task by Process ID") + @GetMapping(value = "/tasksProcessID/{processID}", produces = MediaType.APPLICATION_JSON_VALUE) + public String getTasksProcess(@PathVariable String processID) { + JSONArray tasks = workflowInfoService.getTasksProcess(processID); + return String.valueOf(tasks); + } + @CrossOrigin + @Operation(summary = "Get all tasks") + @GetMapping(value = "/tasks", produces = MediaType.APPLICATION_JSON_VALUE) + public String getAllTasks() { + JSONArray tasks = workflowInfoService.getAllTasks(); + + return String.valueOf(tasks); + } + + + @CrossOrigin + @Operation(summary = "Get error info by process Instance ID") + @GetMapping(value = "/errors/{processInstanceId}") + public String getErrors(@PathVariable String processInstanceId){ + JSONArray result = workflowInfoService.getJobs(processInstanceId); + return String.valueOf(result); + } + + @CrossOrigin + @Operation(summary = "Get Process Variables by Process Instance ID") + @GetMapping(value = "/variables/{processInstanceId}") + public String getVariables(@PathVariable String processInstanceId){ + Map result = workflowInfoService.getProcessVariables(processInstanceId); + JSONObject json = new JSONObject(result); + return String.valueOf(json); + } + + @CrossOrigin + @Operation(summary = "Get activity ID (BPMN file) from process Instance ID") + @GetMapping(value = "executionActivities/{processInstanceId}") + public List getActivityIdExecution(@PathVariable String processInstanceId){ + List result = workflowInfoService.getActivityExecution(processInstanceId); + return result; + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/AddToSurvey.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/AddToSurvey.java new file mode 100644 index 00000000..0e96d1c1 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/AddToSurvey.java @@ -0,0 +1,74 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.protools.flowableDemo.beans.Person; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.HashMap; + +@Component +public class AddToSurvey implements JavaDelegate { + private Logger logger =LogManager.getLogger(AddToSurvey.class); + @Override + public void execute(DelegateExecution delegateExecution) { + logger.info("\t >> Add unit to survey"); + HttpClient client = HttpClient.newHttpClient(); + // Recup variables + String unit = (String) delegateExecution.getVariable("unit"); + String surveyID = (String) delegateExecution.getVariable("idSurvey") ; + + Gson gson = new Gson(); + Person[] map = gson.fromJson(unit, Person[].class); + + Person person = map[0]; + logger.info(" \t \t >>> Add unit to survey : " + person.toString()); + + int statusCode = 0; + var id = person.getId(); + var values = new HashMap() {{ + put("id", id); + put("email", person.getEmail()); + put("nom", person.getNom()); + put("prenom", person.getPrenom()); + + put("id_survey",Long.parseLong(surveyID)); + }}; + var objectMapper = new ObjectMapper(); + String requestBody = null; + try { + requestBody = objectMapper + .writeValueAsString(values); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + requestBody = "[" + requestBody + "]"; + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://coleman.dev.insee.io/surveys/"+ surveyID+"/units")) + .setHeader(HttpHeaders.CONTENT_TYPE, "application/json") + .POST(HttpRequest.BodyPublishers.ofString(requestBody)) + .build(); + HttpResponse response = null; + try { + response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("\t \t https://coleman.dev.insee.io/persons/"+ id); + + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/CheckSampleSize.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/CheckSampleSize.java new file mode 100644 index 00000000..249579bb --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/CheckSampleSize.java @@ -0,0 +1,25 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + + +@Component +public class CheckSampleSize implements JavaDelegate { + private Logger logger =LogManager.getLogger(CheckSampleSize.class); + @Override + public void execute(DelegateExecution delegateExecution) { + String sampleSize = (String) delegateExecution.getVariable("sampleSize"); + int sampleSizeInt = Integer.parseInt(sampleSize); + if (sampleSizeInt<5){ + delegateExecution.setVariable("surveyValid", false); + logger.info("\t >> ERROR : Sample Size too small"); + logger.info("\t >> Process will be aborted"); + } else { + delegateExecution.setVariable("surveyValid", true); + } + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/CreateAccount.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/CreateAccount.java new file mode 100644 index 00000000..43ce822a --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/CreateAccount.java @@ -0,0 +1,75 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.protools.flowableDemo.beans.Person; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.HashMap; + +@Component +public class CreateAccount implements JavaDelegate { + private Logger logger = LogManager.getLogger(CreateAccount.class); + + public void execute (DelegateExecution delegateExecution){ + logger.info("\t >> Create account for unit"); + HttpClient client = HttpClient.newHttpClient(); + + String unit = (String) delegateExecution.getVariable("unit"); + String surveyID = (String) delegateExecution.getVariable("idSurvey") ; + int count = (int) delegateExecution.getVariable("count"); + logger.info("\t >>> Create Account for unit: " + unit + " for survey: "+ surveyID); + + Gson gson = new Gson(); + Person[] map = gson.fromJson(unit,Person[].class); + Person person = map[0]; + int statusCode = 0; + + var values = new HashMap() {{ + put("email", person.getEmail()); + put("nom", person.getNom()); + put("prenom", person.getPrenom()); + + put("id_survey",Long.parseLong(surveyID)); + }}; + var objectMapper = new ObjectMapper(); + String requestBody = null; + try { + requestBody = objectMapper + .writeValueAsString(values); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + requestBody = "[" + requestBody + "]"; + logger.info("\t >>> Create Account for unit: " + requestBody + " for survey: "+ surveyID); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://annuaire.dev.insee.io/comptes/"+surveyID)) + .setHeader(HttpHeaders.CONTENT_TYPE, "application/json") + .POST(HttpRequest.BodyPublishers.ofString(requestBody)) + .build(); + HttpResponse response = null; + try { + response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + logger.info("\t \t Response Code: " + String.valueOf(response.statusCode())); + delegateExecution.setVariable("count", count+1); + + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/DrawUnit.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/DrawUnit.java new file mode 100644 index 00000000..99987b6e --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/DrawUnit.java @@ -0,0 +1,38 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; + +@Component +public class DrawUnit implements JavaDelegate { + private Logger logger =LogManager.getLogger(DrawUnit.class); + + @Override + public void execute(DelegateExecution delegateExecution) { + HttpClient client = HttpClient.newHttpClient(); + String url = "https://crabe.dev.insee.io/persons/sample/1" ; + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create(url)) + .build(); + HttpResponse response = null; + try { + response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("\t \t Drawn unit : "+ response.body()); + delegateExecution.setVariable("unit",response.body()); + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/EndProcess.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/EndProcess.java new file mode 100644 index 00000000..610590a0 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/EndProcess.java @@ -0,0 +1,19 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class EndProcess implements JavaDelegate { + private Logger logger =LogManager.getLogger(EndProcess.class); + @Override + public void execute(DelegateExecution delegateExecution) { + logger.info("\t >> Aborting Process ... << "); + // Contenu Ă  analyser + String surveyName = (String) delegateExecution.getVariable("name"); + logger.info("\t \t >> Failed to create survey " + surveyName); + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/SaveSurvey.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/SaveSurvey.java new file mode 100644 index 00000000..37c852e9 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/SaveSurvey.java @@ -0,0 +1,71 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.json.JSONObject; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.HashMap; + +@Component +public class SaveSurvey implements JavaDelegate { + private Logger logger =LogManager.getLogger(SaveSurvey.class); + @Override + public void execute(DelegateExecution delegateExecution) { + logger.info("\t >> Service task Save Survey into Coleman"); + + // Contenu Ă  analyser + String surveyName = (String) delegateExecution.getVariable("name"); + String dateDeb = (String) delegateExecution.getVariable("dateDeb"); + String dateEnd = (String) delegateExecution.getVariable("dateEnd"); + String sampleSize = (String) delegateExecution.getVariable("sampleSize"); + + var values = new HashMap() {{ + put("name", surveyName); + put ("dateDeb", dateDeb); + put("dateEnd", dateEnd); + }}; + + var objectMapper = new ObjectMapper(); + String requestBody = null; + try { + requestBody = objectMapper + .writeValueAsString(values); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://coleman.dev.insee.io/surveys/")) + .setHeader(HttpHeaders.CONTENT_TYPE, "application/json") + .POST(HttpRequest.BodyPublishers.ofString(requestBody)) + .build(); + HttpResponse response = null; + try { + response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + JSONObject jsonResponse = new JSONObject(response.body()); + logger.info("\t \t >>> Coleman response : " +jsonResponse); + logger.info("\t >> Waiting for next step "); + int idInt = jsonResponse.getInt("id"); + String idSurvey = String.valueOf(idInt); + delegateExecution.setVariable("idSurvey",idSurvey); + delegateExecution.setVariable("count",0); + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/CasUsageService/SurveyReady.java b/src/main/java/com/protools/flowableDemo/services/CasUsageService/SurveyReady.java new file mode 100644 index 00000000..8dc798e5 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/CasUsageService/SurveyReady.java @@ -0,0 +1,40 @@ +package com.protools.flowableDemo.services.CasUsageService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.http.HttpClient; + +@Component +public class SurveyReady implements JavaDelegate { + + private Logger logger =LogManager.getLogger(SurveyReady.class); + @Override + public void execute(DelegateExecution delegateExecution) { + HttpClient client = HttpClient.newHttpClient(); + logger.info("surveyID: " + delegateExecution.getVariable("idSurvey")); + String surveyID = (String) delegateExecution.getVariable("idSurvey") ; + + URL url = null; + try { + url = new URL("https://coleman.dev.insee.io/survey/"+ String.valueOf(surveyID)+ "/ready"); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + try { + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.getInputStream(); + logger.info("\t >> Survey set state to ready : " + con.getResponseCode()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/EventInfoService.java b/src/main/java/com/protools/flowableDemo/services/EventInfoService.java new file mode 100644 index 00000000..94bd6471 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/EventInfoService.java @@ -0,0 +1,22 @@ +package com.protools.flowableDemo.services; + +import org.flowable.eventregistry.api.EventDeployment; +import org.flowable.eventregistry.api.EventRepositoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +public class EventInfoService { + @Autowired + private EventRepositoryService eventRepositoryService; + + @Transactional + public List getEventDeployments(){ + List response = eventRepositoryService.createDeploymentQuery().list(); + + return (response); + }; +} diff --git a/src/main/java/com/protools/flowableDemo/services/FamillePOCService/errorControlMessage.java b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/errorControlMessage.java new file mode 100644 index 00000000..21aa7c3c --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/errorControlMessage.java @@ -0,0 +1,19 @@ +package com.protools.flowableDemo.services.FamillePOCService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class errorControlMessage implements JavaDelegate { + private Logger logger =LogManager.getLogger(com.protools.flowableDemo.services.FamillePOCService.errorControlMessage.class); + @Override + public void execute(DelegateExecution delegateExecution) { + logger.info("\t >> Aborting Process ... << "); + // Contenu Ă  analyser + String surveyName = (String) delegateExecution.getVariable("name"); + logger.info("\t \t >> Error Sample Size control for Survey : " + surveyName + " please check the sample size"); + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/FamillePOCService/getSampleFamille.java b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/getSampleFamille.java new file mode 100644 index 00000000..87725cfa --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/getSampleFamille.java @@ -0,0 +1,112 @@ +package com.protools.flowableDemo.services.FamillePOCService; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.protools.flowableDemo.beans.Person; +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.json.JSONObject; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.ArrayList; +import java.util.HashMap; + +@Component +public class getSampleFamille implements JavaDelegate { + private Logger logger =LogManager.getLogger(com.protools.flowableDemo.services.FamillePOCService.getSampleFamille.class); + + @Override + public void execute(DelegateExecution delegateExecution) { + + // Get Context Variables + String surveyName = (String) delegateExecution.getVariable("name"); + String dateDeb = (String) delegateExecution.getVariable("dateDeb"); + String dateEnd = (String) delegateExecution.getVariable("dateEnd"); + String sampleSize = (String) delegateExecution.getVariable("sampleSize"); + + // Save Survey into Coleman + var values = new HashMap() {{ + put("name", surveyName); + put ("dateDeb", dateDeb); + put("dateEnd", dateEnd); + }}; + + var objectMapper = new ObjectMapper(); + String requestBody = null; + try { + requestBody = objectMapper + .writeValueAsString(values); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + HttpClient client = HttpClient.newHttpClient(); + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://coleman.dev.insee.io/surveys/")) + .setHeader(HttpHeaders.CONTENT_TYPE, "application/json") + .POST(HttpRequest.BodyPublishers.ofString(requestBody)) + .build(); + HttpResponse response = null; + try { + response = client.send(request, + HttpResponse.BodyHandlers.ofString()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + + JSONObject jsonResponse = new JSONObject(response.body()); + logger.info("\t \t >>> Save Survey Sample : " +jsonResponse); + int idInt = jsonResponse.getInt("id"); + String idSurvey = String.valueOf(idInt); + delegateExecution.setVariable("idSurvey",idSurvey); + + // Get Sample + HttpClient clientSample = HttpClient.newHttpClient(); + String url = "https://crabe.dev.insee.io/persons/sample/"+ sampleSize ; + HttpRequest requestSample = HttpRequest.newBuilder() + .uri(URI.create(url)) + .build(); + HttpResponse responseSample = null; + try { + responseSample = client.send(requestSample, + HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + logger.info("\t Drawn sample Famille : "+ responseSample.body()); + String sample = responseSample.body(); + Gson gson = new Gson(); + Person[] map = gson.fromJson(sample,Person[].class); + ArrayList elements = new ArrayList(); + for (Person person : map) { + logger.info("\t \t >>> Unit : " +person); + var unit = new HashMap() {{ + put("email", person.getEmail()); + put("nom", person.getNom()); + put("prenom", person.getPrenom()); + + put("id_survey",Long.parseLong(idSurvey)); + }}; + ArrayList tmp= new ArrayList(); + tmp.add(unit); + // C'est super moche mais c'est pour pas toucher au code de la dĂ©mo, on va refaire propre aprĂšs + elements.add(tmp.toString()); + } + delegateExecution.setVariable("count",0); + delegateExecution.setVariable("sample",elements); + } +} + diff --git a/src/main/java/com/protools/flowableDemo/services/FamillePOCService/sendGlobalErrorMessage.java b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/sendGlobalErrorMessage.java new file mode 100644 index 00000000..3fe76cda --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/FamillePOCService/sendGlobalErrorMessage.java @@ -0,0 +1,18 @@ +package com.protools.flowableDemo.services.FamillePOCService; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class sendGlobalErrorMessage implements JavaDelegate { + private Logger logger =LogManager.getLogger(com.protools.flowableDemo.services.FamillePOCService.sendGlobalErrorMessage.class); + @Override + public void execute(DelegateExecution delegateExecution) { + // Contenu Ă  analyser + String surveyName = (String) delegateExecution.getVariable("name"); + logger.info("\t \t >> The Sample : " + surveyName + "Has encountered an error, please contact technical support"); + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/HistoryInfoService.java b/src/main/java/com/protools/flowableDemo/services/HistoryInfoService.java new file mode 100644 index 00000000..4d1c26a7 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/HistoryInfoService.java @@ -0,0 +1,67 @@ +package com.protools.flowableDemo.services; + +import org.flowable.engine.*; +import org.flowable.engine.history.HistoricActivityInstance; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.job.api.Job; +import org.flowable.task.api.history.HistoricTaskInstance; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +@Service +public class HistoryInfoService { + private Logger logger =LogManager.getLogger(HistoryInfoService.class); + @Autowired + private HistoryService historyService; + + @Autowired + private ManagementService managementService; + + @Transactional + public List getHistoryProcess(){ + List response = historyService.createHistoricProcessInstanceQuery() + .finished().orderByProcessInstanceStartTime().desc().listPage(0,100); + + return (response); + }; + + @Transactional + public List getHistoryTask(String processDefinitionID){ + List response = historyService.createHistoricTaskInstanceQuery() + .processDefinitionId(processDefinitionID).listPage(0,100); + + return (response); + }; + + @Transactional + public List getHistoryActivity(){ + List response = historyService.createHistoricActivityInstanceQuery().orderByHistoricActivityInstanceStartTime().desc().listPage(0,100); + return response; + } + + @Transactional + public List getFailedJobs(){ + List response = managementService.createDeadLetterJobQuery().orderByJobCreateTime().desc().listPage(0,100); + return response; + + } + + @Transactional + public List getSuspendedJobs(){ + List response = managementService.createSuspendedJobQuery().orderByJobCreateTime().desc().listPage(0,100); + return response; + + } + + @Transactional + public List getDeletedProcess(){ + List response = historyService.createHistoricProcessInstanceQuery().deleted().orderByProcessInstanceStartTime().desc().listPage(0,100); + return response; + } + + +} diff --git a/src/main/java/com/protools/flowableDemo/services/Utils/SampleServiceTask.java b/src/main/java/com/protools/flowableDemo/services/Utils/SampleServiceTask.java new file mode 100644 index 00000000..f98885bc --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/Utils/SampleServiceTask.java @@ -0,0 +1,17 @@ +package com.protools.flowableDemo.services.Utils; + +import org.flowable.engine.delegate.DelegateExecution; +import org.flowable.engine.delegate.JavaDelegate; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +@Component +public class SampleServiceTask implements JavaDelegate { + private Logger logger =LogManager.getLogger(SampleServiceTask.class); + @Override + public void execute(DelegateExecution delegateExecution) { + logger.info("\t >> Sample service Task << "); + + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/Utils/VariablesServices.java b/src/main/java/com/protools/flowableDemo/services/Utils/VariablesServices.java new file mode 100644 index 00000000..d3646533 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/Utils/VariablesServices.java @@ -0,0 +1,31 @@ +package com.protools.flowableDemo.services.Utils; + +import com.google.gson.Gson; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Service; + + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; + +@Service +public class VariablesServices { + private static Logger logger =LogManager.getLogger(VariablesServices.class); + + public static Collection stringToCollectionString(String string){ + logger.info("\t >> Converting String to Collection ... << "); + Collection response = new HashSet() { + }; + Gson gson = new Gson(); + try { + String[] map = gson.fromJson(string,String[].class); + response.addAll(Arrays.asList(map)); + } catch (Exception e) { + logger.error("\t >> ERROR : String to Collection conversion failed"); + } + return response; + } + +} diff --git a/src/main/java/com/protools/flowableDemo/services/WorkflowInfoService.java b/src/main/java/com/protools/flowableDemo/services/WorkflowInfoService.java new file mode 100644 index 00000000..99824fbe --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/WorkflowInfoService.java @@ -0,0 +1,186 @@ +package com.protools.flowableDemo.services; + +import org.flowable.bpmn.model.BpmnModel; +import org.flowable.bpmn.model.ExtensionElement; +import org.flowable.bpmn.model.FlowElement; +import org.flowable.engine.*; +import org.flowable.engine.runtime.Execution; +import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.job.api.Job; +import org.flowable.job.service.JobService; +import org.flowable.task.api.Task; +import org.json.JSONArray; +import org.json.JSONObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class WorkflowInfoService { + private Logger logger =LogManager.getLogger(WorkflowInfoService.class); + @Autowired + private RuntimeService runtimeService; + + @Autowired + private TaskService taskService; + + @Autowired + private RepositoryService repositoryService; + + @Autowired + ProcessEngine processEngine; + @Transactional + public Map getBPMNModel(String processDefinitionId){ + BpmnModel response = repositoryService.getBpmnModel(processDefinitionId); + return (response.getMainProcess().getFlowElementMap()); + }; + + @Transactional + public Map> getExtension(String processDefinitionId){ + BpmnModel response = repositoryService.getBpmnModel(processDefinitionId); + return (response.getMainProcess().getExtensionElements()); + }; + + @Transactional + public String getBPMNModelDocumentation(String processDefinitionId){ + BpmnModel response = repositoryService.getBpmnModel(processDefinitionId); + + return (response.getMainProcess().getDocumentation()); + }; + @Transactional + public JSONObject getAllProcessInstance(){ + List liste = runtimeService.createProcessInstanceQuery() + .list(); + JSONObject responseDetailsJson = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + for (int i =0; i deadLetterList = processEngine.getManagementService().createDeadLetterJobQuery().processInstanceId(liste.get(i).getId()).list(); + jsonResponse.put("deadLetterList", deadLetterList.size()); + + jsonArray.put(jsonResponse); + + } + responseDetailsJson.put("processes", jsonArray); + return responseDetailsJson; + } + @Transactional + public JSONArray getTasks(String assignee) { + List response = taskService.createTaskQuery().taskAssignee(assignee).list(); + JSONArray jsonArray = new JSONArray(); + logger.info("Ceci est un test pour voir s'il prend en compte la derniĂšre version du code"); + for (int i =0; i response = taskService.createTaskQuery().processInstanceId(ProcessID).list(); + JSONArray jsonArray = new JSONArray(); + for (int i =0; i response = taskService.createTaskQuery().list(); + + JSONArray jsonArray = new JSONArray(); + for (int i =0; i jobs = jobService.createJobQuery() + .processInstanceId(processInstanceID) + .list(); + + for (int i =0; i getProcessVariables(String ProcessInstanceID){ + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(ProcessInstanceID).singleResult(); + Map variables = processInstance.getProcessVariables(); + return variables; + } + + @Transactional + public List getActivityExecution(String ProcessInstanceID){ + List executions = runtimeService.createExecutionQuery().onlyChildExecutions().processInstanceId(ProcessInstanceID).list(); + List activityIds = executions.stream().map(Execution::getActivityId).collect(Collectors.toList()); + return activityIds; + + } +} diff --git a/src/main/java/com/protools/flowableDemo/services/WorkflowService.java b/src/main/java/com/protools/flowableDemo/services/WorkflowService.java new file mode 100644 index 00000000..2a986ee6 --- /dev/null +++ b/src/main/java/com/protools/flowableDemo/services/WorkflowService.java @@ -0,0 +1,100 @@ +package com.protools.flowableDemo.services; + + +import org.flowable.engine.*; +import org.flowable.engine.runtime.ProcessInstance; +import org.flowable.engine.runtime.ProcessInstanceBuilder; +import org.flowable.task.api.Task; +import org.json.JSONObject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.List; + +@Service +public class WorkflowService { + private Logger logger =LogManager.getLogger(WorkflowService.class); + @Autowired + private RuntimeService runtimeService; + + @Autowired + private TaskService taskService; + + // Process execution and setBusinessKey + @Transactional + public JSONObject startProcess(String ProcessKey, String BusinessKey, HashMap variables){ + ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder(); + processInstanceBuilder.businessKey(BusinessKey).processDefinitionKey(ProcessKey).variables(variables).start(); + //runtimeService.startProcessInstanceByKey(ProcessKey); + List liste = runtimeService.createProcessInstanceQuery() + .processDefinitionKey(ProcessKey) + .list(); + logger.info("Process Instance ID : " + liste.get(0).getId()); + logger.info("Added businessKey to the process :"+ liste.get(0).getBusinessKey() ); + + + JSONObject jsonResponse = new JSONObject(); + jsonResponse.put("id", liste.get(0).getId()); + jsonResponse.put("name",liste.get(0).getName()); + jsonResponse.put("processKey", ProcessKey); + jsonResponse.put("startTime", liste.get(0).getStartTime()); + jsonResponse.put("businessKey", liste.get(0).getBusinessKey()); + jsonResponse.put("documentation", liste.get(0).getDescription()); + return(jsonResponse); + + } + + @Transactional + public void claimTasks(String taskID, String assignee){ + List taskInstances = taskService.createTaskQuery().taskId(taskID).taskAssignee(assignee).active().list(); + if (taskInstances.size() > 0) { + for (Task t : taskInstances) { + taskService.addCandidateGroup(t.getId(), "userTeam"); + logger.info("> Claiming task: " + t.getId()); + taskService.claim(t.getId(),assignee); + } + } else { + logger.info("\t \t >> No task found."); + } + } + + @Transactional + public void completeTask(String taskID, HashMap variables, String assignee){ + List taskInstances = taskService.createTaskQuery().taskId(taskID).taskAssignee(assignee).active().list(); + logger.info("> Completing task from process : " + taskID); + logger.info("\t > Variables : " + variables.toString()); + if (taskInstances.size() > 0) { + for (Task t : taskInstances) { + taskService.addCandidateGroup(t.getId(), "userTeam"); + logger.info("> Completing task: " + t.getId()); + taskService.complete(t.getId(),variables); + } + } else { + logger.info("\t \t >> There are no task for me to complete"); + } + } + + @Transactional + public void deleteProcessInstance( String ProcessID) { + runtimeService.deleteProcessInstance(ProcessID, null); + } + + @Transactional + public void suspendProcessInstance( String ProcessID) { + runtimeService.suspendProcessInstanceById(ProcessID); + } + + @Transactional + public void restartProcessInstance( String ProcessID) { + runtimeService.activateProcessInstanceById(ProcessID); + } + + @Transactional + public void cancelProcessWithReason( String ProcessID, String reason) { + runtimeService.deleteProcessInstance(ProcessID, reason); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 00000000..c960242e --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,21 @@ +#spring.datasource.url=jdbc:postgresql://localhost:5432/flowable +#spring.datasource.username=postgres +#spring.datasource.password=postgres +#spring.datasource.driver-class-name=org.postgresql.Driver + +spring.h2.console.enabled: true +spring.datasource.username: flowable +spring.datasource.password: flowable +spring.datasource.url: jdbc:h2:mem:flowable + +## Springdoc settings +springdoc.swagger-ui.disable-swagger-default-url=true +springdoc.swagger-ui.path=/ + +## Actuator settings +management.endpoints.web.exposure.include=* +management.endpoint.health.show-details=ALWAYS + +## JMS Configuration +flowable.task.app.jms-enabled=true +spring.activemq.broker-url=tcp://localhost:61616 diff --git a/src/main/resources/flowable.cfg.xml b/src/main/resources/flowable.cfg.xml new file mode 100644 index 00000000..b6d1c4cf --- /dev/null +++ b/src/main/resources/flowable.cfg.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 00000000..8aa67f7f --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,37 @@ + + + + + + + + + + %d %p %C{1.} [%t] %m%n + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/processes/EnqueteFamille.bpmn20.xml b/src/main/resources/processes/EnqueteFamille.bpmn20.xml new file mode 100644 index 00000000..04b81c4c --- /dev/null +++ b/src/main/resources/processes/EnqueteFamille.bpmn20.xml @@ -0,0 +1,422 @@ + + + + EnquĂȘte Web source Ă©chantillon externe en continue + + + + + + + PT100H + + + + + + + + + + + + PT5M + + + + + + + + + + + + + envoi les donnĂ©es collectĂ©es non extraites dans Kraftwerk + + + rĂ©cupĂ©ration ou (interrogation) de l'Ă©venement UE finalisĂ©e (rĂ©pondu ou date passĂ©e) + + + + + + Gateway de lancement de la phase en continue + + + + BDD Campagne + + + ContrĂŽle initial + + + BDD Operation Campagne + + + + + + + + + + + + + + + + + + + + + + + Mise Ă  jour contexte dans plateforme + + + + + + + + + + + Relance le sous processus tout les jours + + R500/PT24H + + + + + + + Intialisation du contexte du process + + + + Modifier Contexte Campagne + + + + + + tous les jours + + + facultatif + + + campagne, modĂšle de questionnaire, nomenclature, ... + + + Pour chaque UE + + + formulaire + + + contrĂŽle + + + contrĂŽle + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/processes/TestPQVWithMessages.bpmn20.xml b/src/main/resources/processes/TestPQVWithMessages.bpmn20.xml new file mode 100644 index 00000000..0a7b43d1 --- /dev/null +++ b/src/main/resources/processes/TestPQVWithMessages.bpmn20.xml @@ -0,0 +1,254 @@ + + + + + EnquĂȘte web source Ă©chantillon externe avec message (base QualitĂ© Volaille) + + + SubProcess Add to Survey + + + + + + + + Permet de stopper le process pour voir si l'execution concurrente s'est bien dĂ©roulĂ©e + + PT120S + + + + + + + + + RĂ©ception Message task finie + + + Attente de fin Test // + + + + + + User task Clore campagne + + + + + + Demande Variables de contexte (Ici que pour contrĂŽle) + + + + + + Erreur de contrĂŽle + + + + Envoi message erreurs + + + RĂ©cupere un Ă©chantillon de taille 12 + + + + + + + + + + + + + + Sub Process Triggered by error event + + + + + Envoi d'un message d'erreur global + + + + + + + + RĂ©ception d'un message pour avancer dans le processus + + + + + Pour chaque UE + + + contrĂŽle + + + Pour dire contrĂŽle non passĂ© + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/processes/TestPQVWoMessages.bpmn20.xml b/src/main/resources/processes/TestPQVWoMessages.bpmn20.xml new file mode 100644 index 00000000..4500bd60 --- /dev/null +++ b/src/main/resources/processes/TestPQVWoMessages.bpmn20.xml @@ -0,0 +1,240 @@ + + + + EnquĂȘte web source Ă©chantillon externe sans message (base QualitĂ© Volaille) + + + SubProcess Add to Survey + + sample + + + + + + + Permet de stopper le process pour voir si l'exec paralelle s'est bien dĂ©roulĂ©e + + PT120S + + + + + + + + + RĂ©ception Message task finie + + + Attente de fin Test // + + + + + + User task Clore campagne + + + + + + Demande Variables de contexte (Ici que pour contrĂŽle) + + + + + + Erreur de contrĂŽle + + + + Envoi message erreurs + + + RĂ©cupere un Ă©chantillon de taille 12 + + + + + + + + + + + + + + + Sub Process Triggered by error event + + + + + Envoi d'un message d'erreur global + + + + + + + Pour chaque UE + + + contrĂŽle + + + Pour dire contrĂŽle non passĂ© + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/processes/casUsageTest.bpmn20.xml b/src/main/resources/processes/casUsageTest.bpmn20.xml new file mode 100644 index 00000000..5bac1376 --- /dev/null +++ b/src/main/resources/processes/casUsageTest.bpmn20.xml @@ -0,0 +1,223 @@ + + + + EnquĂȘte de test - prototype stage Protools + + VĂ©rifie la taille de l'Ă©chantillon, un Ă©chantillon est dĂ©signĂ© comme valide s'il contient plus de 5 unitĂ©s d'enquĂȘte + + + + DĂ©but du sous processus pour une UE + + + Tire une unitĂ© d'enquĂȘte dans une base de donnĂ©e d'unitĂ©s + + + + CrĂ©ation de compte pour une unitĂ© d'enquĂȘte avec son adresse email + + + Ajout de l'unitĂ© sĂ©lectionnĂ©e Ă  l'enquĂȘte + + + + Fin du sous processus pour une UE + + + + + + + + + + + DĂ©clare l'enquĂȘte prĂȘte + + + + + + + + + + Sauvegarde les premiĂšres variables d'enquĂȘte + + + + + + + + + Annule l'execution du processus en cas d'erreur + + + + + + + PT60S + + + + + Demande Ă  l'utilisateur le nom de l'enquĂȘte, la taille de l'Ă©chantillon, la date de dĂ©but et de fin + + + Visualisation de l'Ă©tat final du processus avant validation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/com/protools/flowableDemo/FlowablePocApplicationTests.java b/src/test/java/com/protools/flowableDemo/FlowablePocApplicationTests.java new file mode 100644 index 00000000..aaf045bc --- /dev/null +++ b/src/test/java/com/protools/flowableDemo/FlowablePocApplicationTests.java @@ -0,0 +1,13 @@ +package com.protools.flowableDemo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FlowablePocApplicationTests { + + @Test + void contextLoads() { + } + +}