mirror of
https://github.com/openMF/fineract-pentaho.git
synced 2026-02-06 11:17:11 +00:00
initial PentahoReportingProcessServiceImpl
inspired by https://github.com/apache/fineract/pull/1262/files see https://issues.apache.org/jira/browse/FINERACT-1127
This commit is contained in:
parent
6f2e21d73d
commit
84920337b6
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#
|
||||||
|
# https://help.github.com/articles/dealing-with-line-endings/
|
||||||
|
#
|
||||||
|
# These are explicitly windows files and should use crlf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Ignore Gradle project-specific cache directory
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# Ignore Gradle build output directory
|
||||||
|
build
|
||||||
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Pentaho Reporting Plugin for Apache Fineract
|
||||||
|
|
||||||
|
see https://issues.apache.org/jira/browse/FINERACT-1127
|
||||||
|
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
1. make it actually really build? ;)
|
||||||
|
|
||||||
|
1. add minimal documentation above (e.g. `java -jar f.jar;fineract-pentaho.jar` ?)
|
||||||
|
|
||||||
|
1. test it (functionally; does this actually work?!)
|
||||||
|
|
||||||
|
1. inherit dependency management from Fineract, so that e.g.
|
||||||
|
JAX RS & commons lang versions don't have to be repeated.
|
||||||
|
Actually, perhaps JAX RS & commons lang should be considered
|
||||||
|
part of a (future..) Fineract Plugin API, and not need to be declared at all!
|
||||||
|
|
||||||
|
1. run ClasspathDuplicateTest, on all plugins
|
||||||
|
|
||||||
|
1. run Fineract code style checks against plugin code like this
|
||||||
|
|
||||||
|
1. how to avoid files("../") ?
|
||||||
|
|
||||||
|
1. build standalone "service", not just "plugin"
|
||||||
79
build.gradle
Normal file
79
build.gradle
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
|
||||||
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'io.spring.gradle:dependency-management-plugin:1.0.10.RELEASE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'java-library'
|
||||||
|
apply plugin: 'io.spring.dependency-management'
|
||||||
|
|
||||||
|
dependencyManagement {
|
||||||
|
dependencies {
|
||||||
|
dependency 'pentaho-reporting-engine:pentaho-reporting-engine-classic-core:3.9.1.1'
|
||||||
|
|
||||||
|
dependencySet(group: 'pentaho-reporting-engine', version: '3.9.1-GA') {
|
||||||
|
entry 'pentaho-reporting-engine-classic-extensions'
|
||||||
|
entry 'pentaho-reporting-engine-classic-extensions-scripting'
|
||||||
|
entry 'pentaho-reporting-engine-wizard-core'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencySet(group: 'pentaho-report-designer', version: '3.9.1-GA') {
|
||||||
|
entry 'pentaho-reporting-engine-wizard-xul'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencySet(group: 'pentaho-library', version: '1.2.8') {
|
||||||
|
entry 'libbase'
|
||||||
|
entry 'libdocbundle'
|
||||||
|
entry 'libfonts'
|
||||||
|
entry 'libformat'
|
||||||
|
entry 'libformula'
|
||||||
|
entry 'libloader'
|
||||||
|
entry 'librepository'
|
||||||
|
entry 'libserializer'
|
||||||
|
entry 'libsparkline'
|
||||||
|
entry 'libxml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(
|
||||||
|
// Fineract!
|
||||||
|
files("../fineract/build/classes/java/main/"),
|
||||||
|
|
||||||
|
// Fineract dependencies (TODO version should *NOT* be specified here...)
|
||||||
|
'org.slf4j:slf4j-api:1.7.30',
|
||||||
|
'org.apache.openjpa:openjpa:3.1.2',
|
||||||
|
'org.apache.commons:commons-lang3:3.10',
|
||||||
|
'org.springframework:spring-context:5.2.6.RELEASE',
|
||||||
|
'org.springframework.security:spring-security-core:5.3.4.RELEASE',
|
||||||
|
'org.springframework.data:spring-data-commons:2.3.4.RELEASE',
|
||||||
|
'javax.ws.rs:jsr311-api:1.1.1',
|
||||||
|
|
||||||
|
// Pentaho..
|
||||||
|
'pentaho-reporting-engine:pentaho-reporting-engine-classic-core',
|
||||||
|
'pentaho-reporting-engine:pentaho-reporting-engine-classic-extensions',
|
||||||
|
'pentaho-reporting-engine:pentaho-reporting-engine-classic-extensions-scripting',
|
||||||
|
'pentaho-reporting-engine:pentaho-reporting-engine-wizard-core',
|
||||||
|
'pentaho-report-designer:pentaho-reporting-engine-wizard-xul',
|
||||||
|
|
||||||
|
'pentaho-library:libbase',
|
||||||
|
'pentaho-library:libdocbundle',
|
||||||
|
'pentaho-library:libfonts',
|
||||||
|
'pentaho-library:libformat',
|
||||||
|
'pentaho-library:libformula',
|
||||||
|
'pentaho-library:libloader',
|
||||||
|
'pentaho-library:librepository',
|
||||||
|
'pentaho-library:libserializer',
|
||||||
|
'pentaho-library:libsparkline',
|
||||||
|
'pentaho-library:libxml'
|
||||||
|
)
|
||||||
|
}
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
185
gradlew
vendored
Executable file
185
gradlew
vendored
Executable file
@ -0,0 +1,185 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2015 the original author or authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
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
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
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
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=`expr $i + 1`
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
0) set -- ;;
|
||||||
|
1) set -- "$args0" ;;
|
||||||
|
2) set -- "$args0" "$args1" ;;
|
||||||
|
3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save () {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=`save "$@"`
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem 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, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'fineract-pentaho'
|
||||||
@ -0,0 +1,259 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
package org.mifos.fineract.pentaho;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.fineract.infrastructure.core.api.ApiParameterHelper;
|
||||||
|
import org.apache.fineract.infrastructure.core.boot.JDBCDriverConfig;
|
||||||
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenantConnection;
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
|
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||||
|
import org.apache.fineract.infrastructure.report.annotation.ReportService;
|
||||||
|
import org.apache.fineract.infrastructure.report.service.ReportingProcessService;
|
||||||
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.DefaultReportEnvironment;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.MasterReport;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.modules.output.table.csv.CSVReportUtil;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.parameters.ReportParameterDefinition;
|
||||||
|
import org.pentaho.reporting.engine.classic.core.util.ReportParameterValues;
|
||||||
|
import org.pentaho.reporting.libraries.resourceloader.Resource;
|
||||||
|
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
|
||||||
|
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@ReportService(type = "Pentaho")
|
||||||
|
public class PentahoReportingProcessServiceImpl implements ReportingProcessService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(PentahoReportingProcessServiceImpl.class);
|
||||||
|
public static final String MIFOS_BASE_DIR = System.getProperty("user.home") + File.separator + ".mifosx";
|
||||||
|
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private boolean noPentaho = false;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JDBCDriverConfig driverConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PentahoReportingProcessServiceImpl(final PlatformSecurityContext context) {
|
||||||
|
// kick off pentaho reports server
|
||||||
|
ClassicEngineBoot.getInstance().start();
|
||||||
|
this.noPentaho = false;
|
||||||
|
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response processRequest(final String reportName, final MultivaluedMap<String, String> queryParams) {
|
||||||
|
|
||||||
|
final String outputTypeParam = queryParams.getFirst("output-type");
|
||||||
|
final Map<String, String> reportParams = getReportParams(queryParams);
|
||||||
|
final Locale locale = ApiParameterHelper.extractLocale(queryParams);
|
||||||
|
|
||||||
|
String outputType = "HTML";
|
||||||
|
if (StringUtils.isNotBlank(outputTypeParam)) {
|
||||||
|
outputType = outputTypeParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(outputType.equalsIgnoreCase("HTML") || outputType.equalsIgnoreCase("PDF") || outputType.equalsIgnoreCase("XLS")
|
||||||
|
|| outputType.equalsIgnoreCase("XLSX") || outputType.equalsIgnoreCase("CSV"))) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.invalid.outputType", "No matching Output Type: " + outputType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.noPentaho) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.no.pentaho", "Pentaho is not enabled", "Pentaho is not enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String reportPath = MIFOS_BASE_DIR + File.separator + "pentahoReports" + File.separator + reportName + ".prpt";
|
||||||
|
|
||||||
|
String outPutInfo = "Report path: " + reportPath;
|
||||||
|
logger.info("Report path: {}", outPutInfo);
|
||||||
|
|
||||||
|
// load report definition
|
||||||
|
final ResourceManager manager = new ResourceManager();
|
||||||
|
manager.registerDefaults();
|
||||||
|
Resource res;
|
||||||
|
|
||||||
|
try {
|
||||||
|
res = manager.createDirectly(reportPath, MasterReport.class);
|
||||||
|
final MasterReport masterReport = (MasterReport) res.getResource();
|
||||||
|
final DefaultReportEnvironment reportEnvironment = (DefaultReportEnvironment) masterReport.getReportEnvironment();
|
||||||
|
if (locale != null) {
|
||||||
|
reportEnvironment.setLocale(locale);
|
||||||
|
}
|
||||||
|
addParametersToReport(masterReport, reportParams);
|
||||||
|
|
||||||
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
if ("PDF".equalsIgnoreCase(outputType)) {
|
||||||
|
PdfReportUtil.createPDF(masterReport, baos);
|
||||||
|
return Response.ok().entity(baos.toByteArray()).type("application/pdf").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("XLS".equalsIgnoreCase(outputType)) {
|
||||||
|
ExcelReportUtil.createXLS(masterReport, baos);
|
||||||
|
return Response.ok().entity(baos.toByteArray()).type("application/vnd.ms-excel")
|
||||||
|
.header("Content-Disposition", "attachment;filename=" + reportName.replaceAll(" ", "") + ".xls").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("XLSX".equalsIgnoreCase(outputType)) {
|
||||||
|
ExcelReportUtil.createXLSX(masterReport, baos);
|
||||||
|
return Response.ok().entity(baos.toByteArray()).type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||||
|
.header("Content-Disposition", "attachment;filename=" + reportName.replaceAll(" ", "") + ".xlsx").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("CSV".equalsIgnoreCase(outputType)) {
|
||||||
|
CSVReportUtil.createCSV(masterReport, baos, "UTF-8");
|
||||||
|
return Response.ok().entity(baos.toByteArray()).type("text/csv")
|
||||||
|
.header("Content-Disposition", "attachment;filename=" + reportName.replaceAll(" ", "") + ".csv").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("HTML".equalsIgnoreCase(outputType)) {
|
||||||
|
HtmlReportUtil.createStreamHTML(masterReport, baos);
|
||||||
|
return Response.ok().entity(baos.toByteArray()).type("text/html").build();
|
||||||
|
}
|
||||||
|
} catch (final ResourceException e) {
|
||||||
|
// throw new PlatformDataIntegrityException("error.msg.reporting.error", e.getMessage());
|
||||||
|
logger.error("error.msg.reporting.error", e);
|
||||||
|
} catch (final ReportProcessingException e) {
|
||||||
|
// throw new PlatformDataIntegrityException("error.msg.reporting.error", e.getMessage());
|
||||||
|
logger.error("error.msg.reporting.error", e);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
// throw new PlatformDataIntegrityException("error.msg.reporting.error", e.getMessage());
|
||||||
|
logger.error("error.msg.reporting.error", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.invalid.outputType", "No matching Output Type: " + outputType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addParametersToReport(final MasterReport report, final Map<String, String> queryParams) {
|
||||||
|
|
||||||
|
final AppUser currentUser = this.context.authenticatedUser();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
final ReportParameterValues rptParamValues = report.getParameterValues();
|
||||||
|
final ReportParameterDefinition paramsDefinition = report.getParameterDefinition();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only allow integer, long, date and string parameter types and assume all mandatory - could go more
|
||||||
|
* detailed like Pawel did in Mifos later and could match incoming and pentaho parameters better...
|
||||||
|
* currently assuming they come in ok... and if not an error
|
||||||
|
*/
|
||||||
|
for (final ParameterDefinitionEntry paramDefEntry : paramsDefinition.getParameterDefinitions()) {
|
||||||
|
final String paramName = paramDefEntry.getName();
|
||||||
|
if (!(paramName.equals("tenantUrl") || (paramName.equals("userhierarchy") || paramName.equals("username")
|
||||||
|
|| (paramName.equals("password") || paramName.equals("userid"))))) {
|
||||||
|
|
||||||
|
String outPutInfo2 = "paramName:" + paramName;
|
||||||
|
logger.info("paramName: {}", outPutInfo2);
|
||||||
|
|
||||||
|
final String pValue = queryParams.get(paramName);
|
||||||
|
if (StringUtils.isBlank(pValue)) {
|
||||||
|
throw new PlatformDataIntegrityException("error.msg.reporting.error",
|
||||||
|
"Pentaho Parameter: " + paramName + " - not Provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Class<?> clazz = paramDefEntry.getValueType();
|
||||||
|
|
||||||
|
String outPutInfo3 = "addParametersToReport(" + paramName + " : " + pValue + " : " + clazz.getCanonicalName() + ")";
|
||||||
|
logger.info("outputInfo: {}", outPutInfo3);
|
||||||
|
|
||||||
|
if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Integer")) {
|
||||||
|
rptParamValues.put(paramName, Integer.parseInt(pValue));
|
||||||
|
} else if (clazz.getCanonicalName().equalsIgnoreCase("java.lang.Long")) {
|
||||||
|
rptParamValues.put(paramName, Long.parseLong(pValue));
|
||||||
|
} else if (clazz.getCanonicalName().equalsIgnoreCase("java.sql.Date")) {
|
||||||
|
rptParamValues.put(paramName, Date.valueOf(pValue));
|
||||||
|
} else {
|
||||||
|
rptParamValues.put(paramName, pValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// tenant database name and current user's office hierarchy
|
||||||
|
// passed as parameters to allow multitenant penaho reporting
|
||||||
|
// and
|
||||||
|
// data scoping
|
||||||
|
final FineractPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
|
||||||
|
final FineractPlatformTenantConnection tenantConnection = tenant.getConnection();
|
||||||
|
String tenantUrl = driverConfig.constructProtocol(tenantConnection.getSchemaServer(), tenantConnection.getSchemaServerPort(),
|
||||||
|
tenantConnection.getSchemaName());
|
||||||
|
final String userhierarchy = currentUser.getOffice().getHierarchy();
|
||||||
|
String outPutInfo4 = "db URL:" + tenantUrl + " userhierarchy:" + userhierarchy;
|
||||||
|
logger.info(outPutInfo4);
|
||||||
|
|
||||||
|
rptParamValues.put("userhierarchy", userhierarchy);
|
||||||
|
|
||||||
|
final Long userid = currentUser.getId();
|
||||||
|
String outPutInfo5 = "db URL:" + tenantUrl + " userid:" + userid;
|
||||||
|
logger.info(outPutInfo5);
|
||||||
|
|
||||||
|
rptParamValues.put("userid", userid);
|
||||||
|
|
||||||
|
rptParamValues.put("tenantUrl", tenantUrl);
|
||||||
|
rptParamValues.put("username", tenantConnection.getSchemaUsername());
|
||||||
|
rptParamValues.put("password", tenantConnection.getSchemaPassword());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// logger.error("error.msg.reporting.error:" + e.getMessage());
|
||||||
|
logger.error("error.msg.reporting.error:", e);
|
||||||
|
// throw new PlatformDataIntegrityException("error.msg.reporting.error", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> getReportParams(final MultivaluedMap<String, String> queryParams) {
|
||||||
|
|
||||||
|
final Map<String, String> reportParams = new HashMap<>();
|
||||||
|
final Set<String> keys = queryParams.keySet();
|
||||||
|
String pKey;
|
||||||
|
String pValue;
|
||||||
|
for (final String k : keys) {
|
||||||
|
|
||||||
|
if (k.startsWith("R_")) {
|
||||||
|
pKey = k.substring(2);
|
||||||
|
pValue = queryParams.get(k).get(0);
|
||||||
|
reportParams.put(pKey, pValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reportParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user