first commit
This commit is contained in:
commit
d3e7922e38
|
|
@ -0,0 +1,2 @@
|
|||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### 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/
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
# 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
|
||||
#
|
||||
# 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.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
#!/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
|
||||
#
|
||||
# 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.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
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"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
distributionUrlNameMain="${distributionUrlName%.*}"
|
||||
distributionUrlNameMain="${distributionUrlNameMain%-bin}"
|
||||
MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}"
|
||||
MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")"
|
||||
|
||||
exec_maven() {
|
||||
unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || :
|
||||
exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD"
|
||||
}
|
||||
|
||||
if [ -d "$MAVEN_HOME" ]; then
|
||||
verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
exec_maven "$@"
|
||||
fi
|
||||
|
||||
case "${distributionUrl-}" in
|
||||
*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;;
|
||||
*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;;
|
||||
esac
|
||||
|
||||
# prepare tmp dir
|
||||
if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then
|
||||
clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; }
|
||||
trap clean HUP INT TERM EXIT
|
||||
else
|
||||
die "cannot create temp dir"
|
||||
fi
|
||||
|
||||
mkdir -p -- "${MAVEN_HOME%/*}"
|
||||
|
||||
# Download and Install Apache Maven
|
||||
verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
verbose "Downloading from: $distributionUrl"
|
||||
verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
# select .zip or .tar.gz
|
||||
if ! command -v unzip >/dev/null; then
|
||||
distributionUrl="${distributionUrl%.zip}.tar.gz"
|
||||
distributionUrlName="${distributionUrl##*/}"
|
||||
fi
|
||||
|
||||
# verbose opt
|
||||
__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR=''
|
||||
[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v
|
||||
|
||||
# normalize http auth
|
||||
case "${MVNW_PASSWORD:+has-password}" in
|
||||
'') MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;;
|
||||
esac
|
||||
|
||||
if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then
|
||||
verbose "Found wget ... using wget"
|
||||
wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl"
|
||||
elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then
|
||||
verbose "Found curl ... using curl"
|
||||
curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl"
|
||||
elif set_java_home; then
|
||||
verbose "Falling back to use Java to download"
|
||||
javaSource="$TMP_DOWNLOAD_DIR/Downloader.java"
|
||||
targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
cat >"$javaSource" <<-END
|
||||
public class Downloader extends java.net.Authenticator
|
||||
{
|
||||
protected java.net.PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() );
|
||||
}
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
setDefault( new Downloader() );
|
||||
java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() );
|
||||
}
|
||||
}
|
||||
END
|
||||
# For Cygwin/MinGW, switch paths to Windows format before running javac and java
|
||||
verbose " - Compiling Downloader.java ..."
|
||||
"$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java"
|
||||
verbose " - Running Downloader.java ..."
|
||||
"$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")"
|
||||
fi
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
if [ -n "${distributionSha256Sum-}" ]; then
|
||||
distributionSha256Result=false
|
||||
if [ "$MVN_CMD" = mvnd.sh ]; then
|
||||
echo "Checksum validation is not supported for maven-mvnd." >&2
|
||||
echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
elif command -v sha256sum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
elif command -v shasum >/dev/null; then
|
||||
if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then
|
||||
distributionSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2
|
||||
echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ $distributionSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# unzip and move
|
||||
if command -v unzip >/dev/null; then
|
||||
unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip"
|
||||
else
|
||||
tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar"
|
||||
fi
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
<# : batch portion
|
||||
@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 http://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 Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>it.cnr.isti</groupId>
|
||||
<artifactId>workflow-manager</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>workflow-manager</name>
|
||||
<description>Workflow server project</description>
|
||||
<url />
|
||||
<licenses>
|
||||
<license />
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer />
|
||||
</developers>
|
||||
<scm>
|
||||
<connection />
|
||||
<developerConnection />
|
||||
<tag />
|
||||
<url />
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<!-- PostgreSQL database -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.json/json -->
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20250107</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package it.cnr.isti.workflow.manager;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(WorkflowManagerApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package it.cnr.isti.workflow.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.ExecutionObject;
|
||||
import it.cnr.isti.workflow.manager.executors.Executor;
|
||||
import it.cnr.isti.workflow.manager.model.ExecutionStep;
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.ui.Connection;
|
||||
import it.cnr.isti.workflow.manager.model.ui.Flow;
|
||||
import it.cnr.isti.workflow.manager.model.ui.IOModel;
|
||||
import it.cnr.isti.workflow.manager.model.ui.Node;
|
||||
import it.cnr.isti.workflow.manager.repositories.NodeDefinitionRepository;
|
||||
|
||||
@Service
|
||||
public class TransformerService {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(TransformerService.class);
|
||||
|
||||
@Autowired
|
||||
Map<String, Executor> executors;
|
||||
|
||||
@Autowired
|
||||
NodeDefinitionRepository nodeDefinitionRepository;
|
||||
|
||||
private ExecutionObject execObject;
|
||||
|
||||
ExecutionObject transform(Flow flow) {
|
||||
execObject = new ExecutionObject();
|
||||
execObject.setStartStep(createStep(flow, null, flow.getStartNode(), null));
|
||||
return execObject;
|
||||
}
|
||||
|
||||
private ExecutionStep createStep(Flow flow, ExecutionStep parent, String nodeId, Map<String, String> mappingNodeOutputNameToChildInputName ) {
|
||||
//TODO: cosa succede se ho input da più nodi in un solo nodo ? devo tenere traccia dei nodi già visitati e non ricreare lo step ma aggiungerlo solamente ai previous steps
|
||||
|
||||
|
||||
Node node = flow.getNodes().stream().filter(n -> n.getKey().equals(nodeId)).findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("node "+nodeId+" not found"));
|
||||
|
||||
// prendo tutte le gli id in uscita dal nodo
|
||||
List<IOModel> outputs = node.getOutputs();
|
||||
|
||||
|
||||
//prende l'executor per il tipo di nodo
|
||||
NodeDefinition nodeDefinition = nodeDefinitionRepository.findById(node.getType()).orElseThrow(() -> new RuntimeException("Node definition not found for node type: " + node.getType()));
|
||||
|
||||
if (!executors.containsKey(nodeDefinition.getExecutor()))
|
||||
throw new IllegalArgumentException("Executor not found for node type: " + node.getType());
|
||||
|
||||
ExecutionStep step = ExecutionStep.builder().id(node.getKey()).executor(executors.get(nodeDefinition.getExecutor()))
|
||||
.runtimeParameters(node.getParameters()).nodeDefinition(nodeDefinition).build();
|
||||
|
||||
if (parent == null){ // se è il primo step devo settare il mapping degli input
|
||||
Map<String, String> mappingInputName = new HashMap<>();
|
||||
nodeDefinition.getInputs().forEach((k,v) -> mappingInputName.put(k, k));
|
||||
log.debug("setting {} to step {}", mappingInputName, step.getId());
|
||||
step.setParentOutputsToInputMapping(mappingInputName);
|
||||
} else {
|
||||
step.setParentOutputsToInputMapping(mappingNodeOutputNameToChildInputName);
|
||||
}
|
||||
|
||||
if (!nodeId.equals(flow.getEndNode())) {
|
||||
|
||||
|
||||
// mantiene il mapping tra nome output del nodo inviante e nome input del nodo ricevente
|
||||
Map<String, String> currentMappingNodeOutputNameToChildInputName = new HashMap<>();
|
||||
|
||||
List<Node> childNodes = new ArrayList<>();
|
||||
|
||||
for (IOModel output : outputs){
|
||||
for (Connection connection : flow.getConnections()){
|
||||
if (!connection.getFrom().equals(output.getKey())) continue;
|
||||
String inputId = connection.getTo();
|
||||
Node nodeFound = flow.getNodes().stream().filter(n -> n.getInputs().stream().anyMatch(i -> i.getKey().equals(inputId))).findFirst().orElseThrow(() -> new RuntimeException("node "+inputId+" not found"));
|
||||
|
||||
//prendo il nome dell'input e lo mappo con l'output
|
||||
IOModel input = nodeFound.getInputs().stream().filter(i -> i.getKey().equals(inputId)).findFirst().orElseThrow(() -> new RuntimeException("input "+inputId+" not found"));
|
||||
currentMappingNodeOutputNameToChildInputName.put(output.getName(), input.getName());
|
||||
childNodes.add(nodeFound);
|
||||
}
|
||||
}
|
||||
//creo ricorsivamente i prossimi step
|
||||
step.getNextSteps().addAll(childNodes.stream().map(n -> createStep(flow, step, n.getKey(), currentMappingNodeOutputNameToChildInputName)).toList());
|
||||
} else
|
||||
execObject.setEndStep(step);
|
||||
|
||||
return step;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package it.cnr.isti.workflow.manager;
|
||||
|
||||
import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.types.Key;
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.types.ParameterDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.types.ParameterType;
|
||||
import it.cnr.isti.workflow.manager.model.types.Translator;
|
||||
import it.cnr.isti.workflow.manager.model.types.Validation;
|
||||
import it.cnr.isti.workflow.manager.repositories.NodeDefinitionRepository;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WorkflowManagerApplication {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WorkflowManagerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "app", name = "db.init.enabled", havingValue = "true")
|
||||
CommandLineRunner init(NodeDefinitionRepository repository) {
|
||||
return args -> {
|
||||
NodeDefinition defectDetection = NodeDefinition.builder().type("DefectDetection").name("defect detection")
|
||||
.executor("GENERIC-AI").category("DefectDetection").input("file","CSV").output("file","CSV")
|
||||
.build();
|
||||
|
||||
JSONObject rPars = new JSONObject().put("options",
|
||||
List.of(new JSONObject().put("key", "1").put("value", "ChatGpt"),
|
||||
new JSONObject().put("key", "2").put("value", "LLama")));
|
||||
|
||||
ParameterDefinition rgParams = ParameterDefinition.builder().name("LLM").type(ParameterType.Select)
|
||||
.label("Select the LLM to use").description("The LLM to use for generating requirements")
|
||||
.validation(Validation.builder().name("required").validator("required").build())
|
||||
.specificAttributes(rPars).build();
|
||||
|
||||
NodeDefinition requirementGeneration = NodeDefinition.builder().type("RequirementGeneration")
|
||||
.executor("GENERIC-AI").name("requirement generation").category("RequirementGeneration")
|
||||
.input("file","CSV").output("file","CSV")
|
||||
.runtimeParameter("LLM", rgParams).build();
|
||||
|
||||
/*ParameterDefinition phraseParam = ParameterDefinition.builder().name("phrase").type(ParameterType.Input)
|
||||
.label("Phrase").description("The prhase to translate")
|
||||
.validation(Validation.builder().name("required").validator("required").build())
|
||||
.build(); */
|
||||
|
||||
JSONObject languageOptions = new JSONObject().put("options",
|
||||
List.of(new JSONObject().put("key", "1").put("value", "French"),
|
||||
new JSONObject().put("key", "2").put("value", "English")));
|
||||
|
||||
ParameterDefinition langParam = ParameterDefinition.builder().name("language").type(ParameterType.Select)
|
||||
.label("Language").description("The language to translate to")
|
||||
.validation(Validation.builder().name("required").validator("required").build())
|
||||
.specificAttributes(languageOptions).build();
|
||||
|
||||
|
||||
Translator inputTranslator = Translator.builder().usedKey(Key.inputKey("phrase")).usedKey(Key.runtimeKey("language"))
|
||||
.translation("translate the following phrase ${{phrase}} to ${{language}} returning only the translated").build();
|
||||
|
||||
NodeDefinition translator = NodeDefinition.builder().type("Translator")
|
||||
.executor("GENERIC-AI").name("translator").category("TRANSLATOR")
|
||||
.input("phrase","Text").output("translated","Text")
|
||||
.runtimeParameter("LLM", rgParams).runtimeParameter("language", langParam)
|
||||
.executorToOutputTraslationMapping("response", "translated")
|
||||
.inputTranslator("prompt", inputTranslator).build();
|
||||
|
||||
|
||||
repository.save(defectDetection);
|
||||
repository.save(requirementGeneration);
|
||||
repository.save(translator);
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package it.cnr.isti.workflow.manager.controllers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import it.cnr.isti.workflow.manager.model.ui.Flow;
|
||||
import it.cnr.isti.workflow.manager.model.ui.FlowEntity;
|
||||
import it.cnr.isti.workflow.manager.repositories.FlowRepository;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "http://localhost:4200")
|
||||
@RequestMapping("/flows")
|
||||
public class FlowsController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(FlowsController.class);
|
||||
|
||||
@Autowired
|
||||
FlowRepository flowRepository;
|
||||
|
||||
|
||||
@PostMapping(consumes = "application/json")
|
||||
public Flow createFlow(@RequestBody Flow flow) {
|
||||
FlowEntity flowEntity = FlowEntity.builder().flow(flow).build();
|
||||
FlowEntity savedFlow = flowRepository.save(flowEntity);
|
||||
savedFlow.getFlow().setId(savedFlow.getId());
|
||||
flowRepository.save(flowEntity);
|
||||
logger.info("flow created {}", savedFlow.getId());
|
||||
return savedFlow.getFlow();
|
||||
}
|
||||
|
||||
@PutMapping(path = "{id}", consumes = "application/json")
|
||||
public Flow saveFlow(@PathVariable String id, @RequestBody Flow flow) {
|
||||
if (!id.equals(flow.getId()))
|
||||
throw new IllegalArgumentException("Flow id does not match");
|
||||
FlowEntity savedFlow = flowRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Flow not found"));
|
||||
savedFlow.setFlow(flow);
|
||||
savedFlow = flowRepository.save(savedFlow);
|
||||
logger.info("Flow saved: {} ",savedFlow.getId());
|
||||
return savedFlow.getFlow();
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
public List<Flow> getAllFlows() {
|
||||
Iterable<FlowEntity> flowEntities = flowRepository.findAll();
|
||||
return StreamSupport.stream(flowEntities.spliterator(), false).map(FlowEntity::getFlow).toList();
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
public Flow getFlow(@PathVariable String id) {
|
||||
FlowEntity flowEntity = flowRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Flow not found"));
|
||||
return flowEntity.getFlow();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package it.cnr.isti.workflow.manager.controllers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
import it.cnr.isti.workflow.manager.repositories.NodeDefinitionRepository;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(origins = "http://localhost:4200")
|
||||
@RequestMapping("/types")
|
||||
public class NodeDefinitionController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private NodeDefinitionRepository repository;
|
||||
|
||||
@GetMapping("/nodes")
|
||||
public List<NodeDefinition> getNodes() {
|
||||
return (List<NodeDefinition>) repository.findAll();
|
||||
}
|
||||
|
||||
@PostMapping("/nodes")
|
||||
void addNode(@RequestBody NodeDefinition node) {
|
||||
repository.save(node);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package it.cnr.isti.workflow.manager.executors;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.ExecutionStep;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ExecutionObject {
|
||||
|
||||
ExecutionStep startStep;
|
||||
ExecutionStep endStep;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package it.cnr.isti.workflow.manager.executors;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface Executor {
|
||||
|
||||
Map<String,Object> execute(Map<String, Object> userParameters, Map<String,Object> preExecutionParameters, Map<String, Object> inputsFromParent);
|
||||
|
||||
Map<String, Class<?>> getRequiredPreExecutionParameters(Map<String, Object> userParameters);
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package it.cnr.isti.workflow.manager.executors.ai;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AIModel {
|
||||
|
||||
String getName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String executePrompt(Map<String, Object> parameters, String prompt);
|
||||
|
||||
public Map<String, Class<?>> getRequiredPreExecutionParameters();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package it.cnr.isti.workflow.manager.executors.ai;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.ai.services.GeminiService;
|
||||
|
||||
@Service("google-gemini")
|
||||
public class GeminiModel implements AIModel {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(GeminiModel.class);
|
||||
|
||||
private GeminiService geminiService;
|
||||
|
||||
GeminiModel(@Autowired GeminiService geminiService) {
|
||||
this.geminiService = geminiService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Gemini";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Gemini is an LLM model provided by Google";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String executePrompt(Map<String, Object> parameters, String prompt) {
|
||||
geminiService.setApiKey("***REMOVED-API-KEY***");
|
||||
String result = geminiService.getResponse(prompt).block();
|
||||
log.debug("google gemini called with result {}",result);
|
||||
result = parseResponse(result);
|
||||
log.debug("post parsing: {}",result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private String parseResponse(String response) {
|
||||
Pattern pattern = Pattern.compile("\"text\"\\s*:\\s*\"(.*?)\"");
|
||||
Matcher matcher = pattern.matcher(response);
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1); // Estratto il testo
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getRequiredPreExecutionParameters() {
|
||||
return Map.of("API-KEY", String.class);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> userParameters, Map<String, Object> preExecutionParameters,
|
||||
Map<String, Object> inputsFromParent) {
|
||||
String returnString = (String)executePrompt(preExecutionParameters, (String) inputsFromParent.get("prompt"));
|
||||
return Map.of("response", returnString);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package it.cnr.isti.workflow.manager.executors.ai;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.Executor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Service("GENERIC-AI")
|
||||
@ToString(of = {"name"})
|
||||
public class GenericAIExecutor implements Executor {
|
||||
|
||||
//EVERY executor in ai model must return a Map<String, Object> with the key "response" and the value of the response
|
||||
|
||||
private static final String name = "Generic AI Executor";
|
||||
|
||||
@Autowired
|
||||
private Map<String,AIModel> aiModels;
|
||||
|
||||
public Map<String,AIModel> getAvaiableAIModels() {
|
||||
return aiModels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(Map<String, Object> userParameters, Map<String, Object> preExecutionParameters,
|
||||
Map<String, Object> inputsFromParent) {
|
||||
Objects.requireNonNull(userParameters.get("LLM"), "'LLM' parameter is required for 'GENERIC-AI' executor");
|
||||
Objects.requireNonNull(aiModels.get(userParameters.get("LLM")), "AI model not found: " + userParameters.get("LLM"));
|
||||
AIModel aiModel = aiModels.get(userParameters.get("LLM"));
|
||||
String prompt = (String) inputsFromParent.get("prompt");
|
||||
String result = aiModel.executePrompt(userParameters, prompt);
|
||||
return Map.of("response", result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getRequiredPreExecutionParameters(Map<String, Object> userParameters) {
|
||||
Objects.requireNonNull(userParameters.get("LLM"), "'LLM' parameter is required for 'GENERIC-AI' executor");
|
||||
Objects.requireNonNull(aiModels.get(userParameters.get("LLM")), "AI model not found: " + userParameters.get("LLM"));
|
||||
return aiModels.get(userParameters.get("LLM")).getRequiredPreExecutionParameters();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public String onExecute(Map<String, Object> parameters, Map<String, Object> executorSpecificParameters,
|
||||
String payload) {
|
||||
return "AI Executor: " + payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areParametersValid(Map<String, Object> parameters) {
|
||||
return parameters != null && parameters.containsKey("model") && aiModels.containsKey(parameters.get("model"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapsGenericInputsToPayload(Map<String, Object> parameters) {
|
||||
return (String) parameters.get("prompt");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getExecutorSpecificParametersName() {
|
||||
return Map.of("model", String.class);
|
||||
} */
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package it.cnr.isti.workflow.manager.executors.ai.services;
|
||||
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class GeminiService {
|
||||
|
||||
private final WebClient.Builder webClientBuilder;
|
||||
private String apiKey;
|
||||
private static final String GEMINI_URL = "https://generativelanguage.googleapis.com/";
|
||||
|
||||
public GeminiService(WebClient.Builder webClientBuilder) {
|
||||
this.webClientBuilder = webClientBuilder;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public Mono<String> getResponse(String prompt) {
|
||||
Objects.requireNonNull(prompt, "Il prompt non può essere null");
|
||||
Map<String, Object> requestBody = Map.of(
|
||||
"contents", List.of( // Usa List.of invece di new Object[]
|
||||
Map.of(
|
||||
"role", "user",
|
||||
"parts", List.of(Map.of("text", prompt)) // Usa List.of per "parts"
|
||||
)));
|
||||
|
||||
WebClient webClient = webClientBuilder.baseUrl(GEMINI_URL).build();
|
||||
Mono<String> result = webClient.post()
|
||||
.uri(uriBuilder -> uriBuilder.path("v1beta/models/gemini-2.0-flash:generateContent")
|
||||
.queryParam("key", apiKey)
|
||||
.build())
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(requestBody)
|
||||
.retrieve()
|
||||
.bodyToMono(String.class);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package it.cnr.isti.workflow.manager.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.Executor;
|
||||
import it.cnr.isti.workflow.manager.model.types.Key;
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.types.Translator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class ExecutionStep implements InputReadyListener {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(ExecutionStep.class);
|
||||
|
||||
String id;
|
||||
Map<String, Object> runtimeParameters;
|
||||
Map<String, Object> fixedParameters;
|
||||
Executor executor;
|
||||
Map<String, String> parentOutputsToInputMapping;
|
||||
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
|
||||
List<InputReadyListener> nextSteps = new ArrayList<>();
|
||||
|
||||
List<ExecutionStep> previouSteps = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
NodeDefinition nodeDefinition;
|
||||
|
||||
@Builder
|
||||
public ExecutionStep(String id, Map<String, Object> runtimeParameters, Map<String, Object> fixedParameters,
|
||||
NodeDefinition nodeDefinition,
|
||||
Executor executor) {
|
||||
this.id = id;
|
||||
this.runtimeParameters = runtimeParameters;
|
||||
this.fixedParameters = fixedParameters;
|
||||
this.executor = executor;
|
||||
this.nodeDefinition = nodeDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inputReady(String inputKey, Object inputValue) {
|
||||
log.debug("Input ready for step {} with key {} and value {}", id, inputKey, inputValue);
|
||||
parentOutputsToInputMapping.forEach((k,v) -> log.debug("mapping {} -> {}", k, v));
|
||||
if (parentOutputsToInputMapping.containsKey(inputKey)) {
|
||||
inputs.put(parentOutputsToInputMapping.get(inputKey), inputValue);
|
||||
if (areAllInputsReady()) {
|
||||
log.debug("all inputs ready for step {}", id);
|
||||
Map<String, Object> realInputs = new HashMap<>();
|
||||
Set<String> keys = new HashSet<>(inputs.keySet());
|
||||
if (nodeDefinition.getInputTranslators() != null) {
|
||||
log.debug("translators {}", nodeDefinition.getInputTranslators().size());
|
||||
for (Map.Entry<String, Translator> entry : nodeDefinition.getInputTranslators().entrySet()) {
|
||||
String translation = entry.getValue().getTranslation();
|
||||
|
||||
for (Key usedKey : entry.getValue().getUsedKeys()) {
|
||||
String valueToReplace = "";
|
||||
switch (usedKey.getType()) {
|
||||
case Key.Type.RUNTIME:
|
||||
valueToReplace = (String) this.runtimeParameters.get(usedKey.getKey());
|
||||
break;
|
||||
default:
|
||||
valueToReplace = (String) inputs.get(usedKey.getKey());
|
||||
keys.remove(usedKey.getKey());
|
||||
break;
|
||||
}
|
||||
translation = translation.replace(String.format("${{%s}}", usedKey.getKey()), valueToReplace);
|
||||
log.debug("replacing used key {} value {}", usedKey.getKey(), valueToReplace);
|
||||
}
|
||||
realInputs.put(entry.getKey(), translation);
|
||||
}
|
||||
keys.forEach(k -> realInputs.put(k, inputs.get(k)));
|
||||
} else
|
||||
realInputs.putAll(inputs);
|
||||
|
||||
log.debug("input translation for step {} is {}", id, realInputs);
|
||||
Map<String, Object> returned = executor.execute(this.runtimeParameters, null, realInputs);
|
||||
for (InputReadyListener nextStep : nextSteps)
|
||||
for (Map.Entry<String, Object> entry : returned.entrySet())
|
||||
nextStep.inputReady(!nodeDefinition.getExecutorToOutputTraslationMappings().isEmpty()
|
||||
? nodeDefinition.getExecutorToOutputTraslationMappings().get(entry.getKey())
|
||||
: entry.getKey(), entry.getValue());
|
||||
} else {
|
||||
log.debug("inputs not ready for step {}", id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
boolean areAllInputsReady() {
|
||||
return inputs.size() == parentOutputsToInputMapping.size();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package it.cnr.isti.workflow.manager.model;
|
||||
|
||||
public interface InputReadyListener {
|
||||
|
||||
void inputReady(String key, Object value);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Key {
|
||||
|
||||
public static Key runtimeKey(String key){
|
||||
return new Key(key, Type.RUNTIME);
|
||||
}
|
||||
|
||||
public static Key inputKey(String key){
|
||||
return new Key(key, Type.STANDARD);
|
||||
}
|
||||
|
||||
String key;
|
||||
Type type;
|
||||
|
||||
public enum Type {
|
||||
RUNTIME,
|
||||
STANDARD
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import it.cnr.isti.workflow.manager.repositories.InputTranslatorConverter;
|
||||
import it.cnr.isti.workflow.manager.repositories.MapsConverter;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Embedded;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Singular;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class NodeDefinition {
|
||||
|
||||
@Id
|
||||
@NonNull
|
||||
private String type;
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
|
||||
@NonNull
|
||||
private String category;
|
||||
|
||||
@NonNull
|
||||
private String executor;
|
||||
|
||||
@Singular
|
||||
@Convert(converter = MapsConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, ParameterDefinition> fixedParameters;
|
||||
|
||||
@Singular
|
||||
@Convert(converter = MapsConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, ParameterDefinition> runtimeParameters;
|
||||
|
||||
|
||||
@Singular
|
||||
@Convert(converter = MapsConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, String> inputs;
|
||||
@Singular
|
||||
@Convert(converter = MapsConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, String> outputs;
|
||||
|
||||
//contains the mapping of the result of the execution with the output of the node
|
||||
@Singular
|
||||
@Convert(converter = MapsConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, String> executorToOutputTraslationMappings;
|
||||
|
||||
@Singular
|
||||
@Convert(converter = InputTranslatorConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private Map<String, Translator> inputTranslators;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.core.JacksonException;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Singular;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ParameterDefinition {
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
|
||||
@NonNull
|
||||
private String label;
|
||||
|
||||
private String description;
|
||||
|
||||
@NonNull
|
||||
private ParameterType type;
|
||||
|
||||
@Singular
|
||||
private List<Validation> validations;
|
||||
|
||||
@JsonDeserialize(using = JsonObjectDeserializer.class)
|
||||
@JsonSerialize(using = JsonObjectSerializer.class)
|
||||
private JSONObject specificAttributes;
|
||||
}
|
||||
|
||||
class JsonObjectDeserializer extends JsonDeserializer<JSONObject> {
|
||||
|
||||
@Override
|
||||
public JSONObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||
return new JSONObject(p.readValueAsTree().toString());
|
||||
}
|
||||
}
|
||||
|
||||
class JsonObjectSerializer extends JsonSerializer<JSONObject> {
|
||||
|
||||
@Override
|
||||
public void serialize(JSONObject value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeRawValue(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
public enum ParameterType {
|
||||
|
||||
Select,
|
||||
Input
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.Singular;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Translator {
|
||||
|
||||
@Singular
|
||||
@NonNull
|
||||
List<Key> usedKeys;
|
||||
|
||||
@NonNull
|
||||
String translation;
|
||||
|
||||
public String toString() {
|
||||
return "Translator(usedKeys=" + this.getUsedKeys() + ", translation=" + this.getTranslation() + ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package it.cnr.isti.workflow.manager.model.types;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class Validation {
|
||||
|
||||
@NonNull
|
||||
private String name;
|
||||
|
||||
@NonNull
|
||||
private String validator;
|
||||
|
||||
private String message;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package it.cnr.isti.workflow.manager.model.ui;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class Connection {
|
||||
|
||||
String key;
|
||||
String from;
|
||||
String to;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package it.cnr.isti.workflow.manager.model.ui;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@ToString
|
||||
public class Flow {
|
||||
|
||||
String id;
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
@Builder.Default
|
||||
List<Node> nodes = List.of();
|
||||
|
||||
@Builder.Default
|
||||
List<Connection> connections = List.of();
|
||||
|
||||
String startNode;
|
||||
String endNode;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package it.cnr.isti.workflow.manager.model.ui;
|
||||
|
||||
import org.hibernate.annotations.UuidGenerator;
|
||||
|
||||
import it.cnr.isti.workflow.manager.repositories.FlowConverter;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FlowEntity {
|
||||
|
||||
@Id
|
||||
@UuidGenerator
|
||||
String id;
|
||||
|
||||
@Convert(converter = FlowConverter.class)
|
||||
@Column(columnDefinition = "TEXT")
|
||||
Flow flow;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package it.cnr.isti.workflow.manager.model.ui;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class IOModel {
|
||||
String key;
|
||||
String type;
|
||||
String name;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package it.cnr.isti.workflow.manager.model.ui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class Node {
|
||||
|
||||
String key;
|
||||
String name;
|
||||
|
||||
List<IOModel> outputs;
|
||||
List<IOModel> inputs;
|
||||
|
||||
String color;
|
||||
Point position;
|
||||
|
||||
Map<String, Object> parameters;
|
||||
|
||||
String description;
|
||||
|
||||
String type;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
class Point {
|
||||
int x;
|
||||
int y;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.ui.Flow;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter
|
||||
public class FlowConverter implements AttributeConverter<Flow, String> {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(Flow flow) {
|
||||
try {
|
||||
return mapper.writeValueAsString(flow);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flow convertToEntityAttribute(String dbData) {
|
||||
try {
|
||||
return mapper.readValue(dbData, Flow.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.ui.FlowEntity;
|
||||
|
||||
@Repository
|
||||
public interface FlowRepository extends JpaRepository<FlowEntity, String> {}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.types.Translator;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter
|
||||
public class InputTranslatorConverter implements
|
||||
AttributeConverter<Map<String, Translator>, String> {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(Map<String, Translator> param) {
|
||||
if (param == null)
|
||||
return null;
|
||||
try {
|
||||
return mapper.writeValueAsString(param);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Translator> convertToEntityAttribute(String paramAsJson) {
|
||||
if (paramAsJson == null)
|
||||
return null;
|
||||
|
||||
TypeReference<HashMap<String, Translator>> typeRef = new TypeReference<HashMap<String, Translator>>() {
|
||||
};
|
||||
try {
|
||||
Map<String,Translator> result = mapper.readValue(paramAsJson, typeRef);
|
||||
return result;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter
|
||||
public class MapsConverter<T> implements
|
||||
AttributeConverter<Map<String, T>, String> {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(Map<String, T> param) {
|
||||
if (param == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
return mapper.writeValueAsString(param);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, T> convertToEntityAttribute(String paramAsJson) {
|
||||
if (paramAsJson == null)
|
||||
return null;
|
||||
|
||||
TypeReference<HashMap<String, T>> typeRef = new TypeReference<HashMap<String, T>>() {
|
||||
};
|
||||
try {
|
||||
Map<String,T> result = mapper.readValue(paramAsJson, typeRef);
|
||||
return result;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalArgumentException("Error converting map to JSON", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
|
||||
@Repository
|
||||
public interface NodeDefinitionRepository extends CrudRepository<NodeDefinition, String> {}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
spring.application.name=workflow-manager
|
||||
|
||||
#postgresql details
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
|
||||
spring.datasource.username=lucio
|
||||
spring.datasource.password=password
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
|
||||
# create and drop table, good for testing, production set to none or comment it
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
app.db.init.enabled=true
|
||||
|
||||
logging.level.it.cnr.isti.workflow.manager=DEBUG
|
||||
logging.level.root=ERROR
|
||||
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package it.cnr.isti.workflow.manager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.ExecutionObject;
|
||||
import it.cnr.isti.workflow.manager.model.ExecutionStep;
|
||||
import it.cnr.isti.workflow.manager.model.InputReadyListener;
|
||||
import it.cnr.isti.workflow.manager.model.ui.Flow;
|
||||
import it.cnr.isti.workflow.manager.model.ui.FlowEntity;
|
||||
import it.cnr.isti.workflow.manager.repositories.FlowRepository;
|
||||
|
||||
@SpringBootTest
|
||||
public class FlowTest {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(FlowTest.class);
|
||||
|
||||
@Autowired
|
||||
FlowRepository flowRepository;
|
||||
|
||||
@Autowired
|
||||
TransformerService transformerService;
|
||||
|
||||
private static final String FLOW = """
|
||||
{
|
||||
"id": "bc940838-b390-4a43-8f71-759b57d61580",
|
||||
"name": "italian to english (passing from french)",
|
||||
"description": null,
|
||||
"nodes": [
|
||||
{
|
||||
"key": "c3d4ede7-96c6-4400-9d69-3210f8512b35",
|
||||
"name": "newNode",
|
||||
"outputs": [
|
||||
{
|
||||
"name" : "translated",
|
||||
"key": "bbd8a7ac-404d-4f4b-9e16-3e12354e19c9",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"name" : "phrase",
|
||||
"key": "4fc0c364-250f-4402-b469-512b8dc54c1a",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 162,
|
||||
"y": 52
|
||||
},
|
||||
"parameters": {
|
||||
"language": "French",
|
||||
"LLM": "google-gemini"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Translator"
|
||||
},
|
||||
{
|
||||
"key": "5ff7bfbe-d71d-43d3-addf-9b70beab026d",
|
||||
"name": "newNode",
|
||||
"outputs": [
|
||||
{
|
||||
"name" : "translated",
|
||||
"key": "6adfc7f2-b26b-4cdb-85b4-c9121f0726c7",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"name" : "phrase",
|
||||
"key": "f9751a63-75fd-4a33-8592-c516abbb6574",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"color": "#A8E6CF",
|
||||
"position": {
|
||||
"x": 582,
|
||||
"y": 181
|
||||
},
|
||||
"parameters": {
|
||||
"language": "English",
|
||||
"LLM": "google-gemini"
|
||||
},
|
||||
"description": null,
|
||||
"type": "Translator"
|
||||
}
|
||||
],
|
||||
"connections": [
|
||||
{
|
||||
"key": "9267a8d1-4bdf-4c50-8876-1a78baf25636",
|
||||
"from": "bbd8a7ac-404d-4f4b-9e16-3e12354e19c9",
|
||||
"to": "f9751a63-75fd-4a33-8592-c516abbb6574"
|
||||
}
|
||||
],
|
||||
"startNode": "c3d4ede7-96c6-4400-9d69-3210f8512b35",
|
||||
"endNode": "5ff7bfbe-d71d-43d3-addf-9b70beab026d"
|
||||
}
|
||||
""";
|
||||
|
||||
@Test
|
||||
void testFlowSerialization() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
assertNotNull(flow);
|
||||
FlowEntity flowEntity = FlowEntity.builder().flow(flow).build();
|
||||
flowRepository.save(flowEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void transform() throws Exception {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Flow flow = objectMapper.readValue(FLOW, Flow.class);
|
||||
ExecutionObject execution = transformerService.transform(flow);
|
||||
assertNotNull(execution.getStartStep());
|
||||
|
||||
InputReadyListener resuListener = new InputReadyListener() {
|
||||
@Override
|
||||
public void inputReady(String key, Object value) {
|
||||
log.debug("Received result: {} -> {}", key, value);
|
||||
}
|
||||
};
|
||||
|
||||
execution.getEndStep().setNextSteps(List.of(resuListener));
|
||||
|
||||
execution.getStartStep().inputReady("phrase", "Ciao come stai?");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package it.cnr.isti.workflow.manager;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class NodeDefinitionControllerTest {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
void shouldReturnEmpty() throws Exception {
|
||||
/*NodeDefinition node = new NodeDefinition("DefectDetection","defect detection",
|
||||
"DefectDetection", null, null);
|
||||
List<NodeDefinition> nodes = Collections.singletonList(node);
|
||||
when(service.findAll()).thenReturn(nodes);
|
||||
assertThat(service.findAll()).isEqualTo(nodes);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package it.cnr.isti.workflow.manager.executors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import it.cnr.isti.workflow.manager.executors.ai.GenericAIExecutor;
|
||||
|
||||
@SpringBootTest
|
||||
public class GenericAIExecutorTest {
|
||||
|
||||
@Autowired
|
||||
private GenericAIExecutor genericAIExecutor;
|
||||
|
||||
@Test
|
||||
public void testOnExecute() {
|
||||
//String argument = "test";
|
||||
//String result = (String) genericAIExecutor.get(Map.of("model", "google-gemini")).execute(null, null, argument);
|
||||
//assertEquals("AI Executor: test", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvaiableAIModels() {
|
||||
assertTrue(genericAIExecutor.getAvaiableAIModels().size()>0);
|
||||
assertEquals(genericAIExecutor.getAvaiableAIModels().keySet().stream().findFirst().orElse(""), "google-gemini");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package it.cnr.isti.workflow.manager.repositories;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import it.cnr.isti.workflow.manager.model.types.NodeDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.types.ParameterDefinition;
|
||||
import it.cnr.isti.workflow.manager.model.types.ParameterType;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
class NodeDefRepoTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
private NodeDefinitionRepository nodeRepository;
|
||||
|
||||
@Test
|
||||
void testStoreAndFindNode() {
|
||||
NodeDefinition node = NodeDefinition.builder().type("DefectDetection").name("defect detection").executor("GENERIC-AI").category("DefectDetection").input("file","CSV")
|
||||
.fixedParameter("LLM", ParameterDefinition.builder().name("param").label("param").type(ParameterType.Input).build()) .output("file","CSV").build();
|
||||
nodeRepository.save(node);
|
||||
NodeDefinition foundNode = nodeRepository.findById(node.getType()).orElse(null);
|
||||
assertNotNull(foundNode);
|
||||
assertFalse(foundNode.getFixedParameters().isEmpty());
|
||||
assertTrue(foundNode.getRuntimeParameters().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStoreAndFindAll() {
|
||||
NodeDefinition node = NodeDefinition.builder().type("DefectDetection").name("defect detection").executor("GENERIC-AI").category("DefectDetection").input("file","CSV") .output("file","CSV").build();
|
||||
nodeRepository.save(node);
|
||||
NodeDefinition returnNode = StreamSupport.stream(nodeRepository.findAll().spliterator(), false).filter(n->n.getType().equals(node.getType())).findFirst().orElse(null) ;
|
||||
assertNotNull(returnNode);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue