Commit 74268119 authored by Nagaraju Kattanguru's avatar Nagaraju Kattanguru

Merge branch 'main' into 'master'

Initial changes

See merge request !1
parents fcd6b5f6 4e550a1d
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/
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /usr/local/etc/mavenrc ] ; then
. /usr/local/etc/mavenrc
fi
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`\\unset -f command; \\command -v java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=`cygpath --path --windows "$javaClass"`
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%
<?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>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.nisum</groupId>
<artifactId>statisticsutils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Statistics Utils</name>
<description>Database Statistics Utils &amp; Send Mails</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-core</artifactId>
<version>3.12.7</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.12.7</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>com.j2html</groupId>
<artifactId>j2html</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<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>
package com.nisum.statisticsutils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class StatisticsUtilsApplication {
public static void main(String[] args) {
SpringApplication.run(StatisticsUtilsApplication.class, args);
}
}
package com.nisum.statisticsutils.models;
import java.util.HashMap;
public class ExcelCells {
private Integer rowNum;
private HashMap<Integer,String> hmColumnValues;
public ExcelCells(Integer rowNum, HashMap<Integer, String> hmColumnValues) {
this.rowNum = rowNum;
this.hmColumnValues = hmColumnValues;
}
public Integer getRowNum() {
return rowNum;
}
public void setRowNum(Integer rowNum) {
this.rowNum = rowNum;
}
public HashMap<Integer, String> getHmColumnValues() {
return hmColumnValues;
}
public void setHmColumnValues(HashMap<Integer, String> hmColumnValues) {
this.hmColumnValues = hmColumnValues;
}
}
package com.nisum.statisticsutils.models;
public class TaxRates {
public String taxA="";
public String taxB="";
public String taxC="";
public String taxD="";
public String taxDescription="";
public String getTaxDescription() {
return taxDescription;
}
public void setTaxDescription(String taxDescription) {
this.taxDescription = taxDescription;
}
public String getTaxA() {
if (this.taxA == null ||this.taxA.trim().equals("")) {
return "0";
}else{
return taxA;
}
}
public void setTaxA(String taxA) {
this.taxA = taxA;
}
public String getTaxB() {
if (this.taxB == null ||this.taxB.trim().equals("")) {
return "0";
}else{
return taxB;
}
}
public void setTaxB(String taxB) {
this.taxB = taxB;
}
public String getTaxC() {
if (this.taxC == null ||this.taxC.trim().equals("")) {
return "0";
}else{
return taxC;
}
}
public void setTaxC(String taxC) {
this.taxC = taxC;
}
public String getTaxD() {
if (this.taxD == null ||this.taxD.trim().equals("")) {
return "0";
}else{
return taxD;
}
}
public void setTaxD(String taxD) {
this.taxD = taxD;
}
public TaxRates(String taxA, String taxB, String taxC, String taxD, String taxDescription) {
this.taxA = taxA;
this.taxB = taxB;
this.taxC = taxC;
this.taxD = taxD;
this.taxDescription = taxDescription;
}
}
\ No newline at end of file
package com.nisum.statisticsutils.programs;
import com.nisum.statisticsutils.models.TaxRates;
import com.nisum.statisticsutils.utils.CsvUtils;
import com.nisum.statisticsutils.utils.FileUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public class CompareSimsStoreData {
public static void compareHashMaps(HashMap<String, TaxRates> hm1, HashMap<String, TaxRates> hm3)throws Exception{
FileUtils fu = new FileUtils("/Users/nisum/Downloads/FileCompare/3217/taxCompare-3217.csv");
Set<String> k = hm1.keySet();
System.out.println("UPC\tDB\tDB\tDB\tDB\tSTORE\tSTORE\tSTORE\tSTORE");
fu.writeLineToFile("UPC\tDB\tDB\tDB\tDB\tSTORE\tSTORE\tSTORE\tSTORE");
fu.writeLineToFile("UPC\tTax A\tTax B\tTax C\tTax D\tTax A\tTax B\tTax C\tTax D");
for(String s:k){
if(hm1.get(s)!=null && hm3.get(s)!=null) {
System.out.println(s + "\t" +
hm1.get(s).getTaxA() + "\t" + hm1.get(s).getTaxB() + "\t" + hm1.get(s).getTaxC() + "\t" + hm1.get(s).getTaxD() + "\t" +
hm3.get(s).getTaxA() + "\t" + hm3.get(s).getTaxB() + "\t" + hm3.get(s).getTaxC() + "\t" + hm3.get(s).getTaxD()
);
fu.writeLineToFile(s + "\t" +
hm1.get(s).getTaxA() + "\t" + hm1.get(s).getTaxB() + "\t" + hm1.get(s).getTaxC() + "\t" + hm1.get(s).getTaxD() + "\t" +
hm3.get(s).getTaxA() + "\t" + hm3.get(s).getTaxB() + "\t" + hm3.get(s).getTaxC() + "\t" + hm3.get(s).getTaxD()
);
}
}
fu.closeFileWriter();
}
public static void main(String[] args) throws Exception {
CsvUtils csvSims = new CsvUtils("/Users/nisum/Downloads/FileCompare/3217/sims-3217.csv");
ArrayList<String> lines = csvSims.readAllLines(true);
ArrayList<TaxRates> ltrDbSims = new ArrayList<TaxRates>();
HashMap<String,TaxRates> hmSims = new HashMap<String, TaxRates>();
for(String s: lines){
String fsa = csvSims.getColumnValue(s,",",11);
if(fsa.toLowerCase().contains("flex spending account") || fsa.toLowerCase().contains("sales restrict")||fsa.toLowerCase().contains("wic") || fsa.toLowerCase().contains("milk bottle deposit")){
continue;
}
String upc = csvSims.getColumnValue(s,",",1);
String taxA = csvSims.getColumnValue(s,",",12) + "";
String taxB = csvSims.getColumnValue(s,",",13) + "";
String taxC = csvSims.getColumnValue(s,",",14) + "";
String taxD = csvSims.getColumnValue(s,",",15) + "";
/*System.out.println("UPC :" + upc);
System.out.println("Tax A:" + taxA);
System.out.println("Tax B:" + taxB);
System.out.println("Tax C:" + taxC);
System.out.println("Tax D:" + taxD);*/
TaxRates tr = new TaxRates(taxA,taxB,taxC,taxD,"");
hmSims.put(String.format("%013d",(new BigDecimal(upc).toBigInteger())),tr);
}
csvSims.closeBufferedReader();
CsvUtils csvStore = new CsvUtils("/Users/nisum/Downloads/FileCompare/3217/store-3217.csv");
lines = csvStore.readAllLines(false);
HashMap<String,TaxRates> hmStore = new HashMap<String,TaxRates>();
for(String s: lines){
String upc = csvStore.getColumnValue(s,"\\|",0);
String taxA= csvStore.getColumnValue(s,"\\|",13) + "";
String taxB= csvStore.getColumnValue(s,"\\|",14) + "";
String taxC= csvStore.getColumnValue(s,"\\|",15) + "";
String taxD= csvStore.getColumnValue(s,"\\|",16) + "";
/*System.out.println("UPC :" + upc);
System.out.println("Tax A:" + taxA);
System.out.println("Tax B:" + taxB);
System.out.println("Tax C:" + taxC);
System.out.println("Tax D:" + taxD);*/
TaxRates tr = new TaxRates(taxA,taxB,taxC,taxD,"");
hmStore.put(String.format("%013d",(new BigDecimal(upc).toBigInteger())),tr);
}
csvStore.closeBufferedReader();
CompareSimsStoreData.compareHashMaps(hmSims,hmStore);
}
}
package com.nisum.statisticsutils.programs;
import com.mongodb.client.FindIterable;
import com.mongodb.client.model.Filters;
import com.nisum.statisticsutils.utils.*;
import org.bson.Document;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
public class DailyReport {
public class Mail{
private String storeNumbers;
private String reportSinceDate;
private String sendTo;
private String sendFrom;
private String smtpServer;
private int smtpPort;
public String getSendTo() {
return sendTo;
}
public void setSendTo(String sendTo) {
this.sendTo = sendTo;
}
public String getSendFrom() {
return sendFrom;
}
public void setSendFrom(String sendFrom) {
this.sendFrom = sendFrom;
}
public void setReportSinceDate(String sinceDate) {
this.reportSinceDate = sinceDate;
}
public String getSmtpServer() {
return smtpServer;
}
public void setSmtpServer(String smtpServer) {
this.smtpServer = smtpServer;
}
public int getSmtpPort() {
return smtpPort;
}
public void setSmtpPort(int smtpPort) {
this.smtpPort = smtpPort;
}
public String getReportSinceDate() {
return this.reportSinceDate;
}
public String getStoreNumbers() {
return storeNumbers;
}
public void setStoreNumbers(String storeNumbers) {
this.storeNumbers = storeNumbers;
}
}
public Mail getProperties() throws Exception {
Properties prop = new Properties();
String propFile = "config.properties";
InputStream input = getClass().getClassLoader().getResourceAsStream(propFile);
if(input==null){
throw new FileNotFoundException("config.properties file not found");
}else{
prop.load(input);
}
Mail m = new Mail();
m.setSendFrom(prop.getProperty("sendFrom"));
m.setSendTo(prop.getProperty("sendTo"));
m.setSmtpServer(prop.getProperty("smtpServer"));
m.setSmtpPort(Integer.parseInt(prop.getProperty("smtpPort")));
m.setReportSinceDate(prop.getProperty("reportSinceDate"));
m.setStoreNumbers(prop.getProperty("storeNumbers"));
return m;
}
public static void main(String[] args) throws Exception {
Mail m = new DailyReport().getProperties();
String sinceDate=m.getReportSinceDate();
String[] stores = m.getStoreNumbers().split(",");
MongoUtils mo = new MongoUtils();
JsonUtils ju = new JsonUtils();
//number of records after date
System.out.println("Fetching number of transactions since date "+ sinceDate +" for each store");
String emailBody="";
Long numOfTxns=0l ;
emailBody = emailBody + ("Report of transactions since date: " + sinceDate);
emailBody = emailBody + ("\n\nNumber of Taxation Calls for stores");
for(String store:stores) {
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.eq("storeId",store)));
emailBody = emailBody + ("\n\tStore# " + store + "\t:" + numOfTxns);
}
System.out.println("Fetching errors since date "+ sinceDate +" for all given stores");
//number of records after date with exceptions in response
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.regex("response", "exception")));
emailBody = emailBody + ("\n\nNumber of Transactions with Exceptions: " + numOfTxns);
FindIterable<Document> errors = mo.getAllMatchingDocuments(Filters.and(Filters.gte("timestamp",sinceDate),Filters.regex("response", "exception")));
for(Document d: errors) {
String error = (ju.searchJsonStringByJsonPath(d.toJson(), "$.response"));
String[] errorz = error.split(":");
String traceId = errorz[errorz.length-1].replace("\"", "").replace("}", "");
Document errorDoc = mo.getMatchingDocument(Filters.eq("_id",traceId));
emailBody = emailBody + ("\n" + ju.searchJsonStringByJsonPath(errorDoc.toJson(),"$.timestamp") + "::" + error );
}
//PRINTOUT THE ERRORS
System.out.println("Fetching error counts since date "+ sinceDate +" for all given stores");
//number of records after date with errors in response and percentage > 25.
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.gt("percentage",25)));
emailBody = emailBody + ("\n\nNumber of Erroneous Transactions with 25% or more missing UPCs: " + numOfTxns);
System.out.println("Missing UPS "+ sinceDate +" for all given stores");
//list of unique missing UPCs from the records since date
FindIterable<Document> allMissingUPCs = mo.getAllMatchingDocuments(Filters.and(Filters.gte("timestamp",sinceDate),Filters.exists("upc_bpn")));
ArrayList<String> UPCs = new ArrayList<String>();
emailBody = emailBody + ("\n\nMissing UPCs:\n");
for(Document d:allMissingUPCs) {
String upc = ju.searchJsonStringByJsonPath(d.toJson(), "$.upc_bpn");
String[] arrupc = upc.split(",");
for(String s:arrupc) {
if(!UPCs.contains(s)) {
UPCs.add(s);
emailBody = emailBody + (s + "," ) ;
}
}
}
emailBody = emailBody + ("\n\nNumber of UPCs missing product classes: " + UPCs.size());
emailBody = emailBody + ("\n\nTaxation Report generated at : " + new java.util.Date());
mo.closeConnection();
System.out.println("Generating Emails");
EmailUtils.sendMail(m.getSmtpServer(),m.getSmtpPort(),m.sendFrom,m.sendTo,"Taxation Report: " + new java.util.Date(),emailBody,"");
System.out.println("Process Complete " + new java.util.Date());
}
}
package com.nisum.statisticsutils.programs;
import com.mongodb.client.FindIterable;
import com.mongodb.client.model.Filters;
import com.nisum.statisticsutils.models.ExcelCells;
import com.nisum.statisticsutils.utils.*;
import org.bson.Document;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Properties;
public class DailyReportInExcelAndEmail {
public class Mail{
private String storeNumbers;
private String reportSinceDate;
private String sendTo;
private String sendFrom;
private String smtpServer;
private int smtpPort;
public String getSendTo() {
return sendTo;
}
public void setSendTo(String sendTo) {
this.sendTo = sendTo;
}
public String getSendFrom() {
return sendFrom;
}
public void setSendFrom(String sendFrom) {
this.sendFrom = sendFrom;
}
public void setReportSinceDate(String sinceDate) {
this.reportSinceDate = sinceDate;
}
public String getSmtpServer() {
return smtpServer;
}
public void setSmtpServer(String smtpServer) {
this.smtpServer = smtpServer;
}
public int getSmtpPort() {
return smtpPort;
}
public void setSmtpPort(int smtpPort) {
this.smtpPort = smtpPort;
}
public String getReportSinceDate() {
return this.reportSinceDate;
}
public String getStoreNumbers() {
return storeNumbers;
}
public void setStoreNumbers(String storeNumbers) {
this.storeNumbers = storeNumbers;
}
}
public Mail getProperties() throws Exception {
Properties prop = new Properties();
String propFile = "config.properties";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream input = getClass().getClassLoader().getResourceAsStream(propFile);
if(input==null){
throw new FileNotFoundException("config.properties file not found");
}else{
prop.load(input);
}
Mail m = new Mail();
m.setSendFrom(prop.getProperty("sendFrom"));
m.setSendTo(prop.getProperty("sendTo"));
m.setSmtpServer(prop.getProperty("smtpServer"));
m.setSmtpPort(Integer.parseInt(prop.getProperty("smtpPort")));
m.setReportSinceDate(prop.getProperty("reportSinceDate"));
m.setStoreNumbers(prop.getProperty("storeNumbers"));
return m;
}
public static void main(String[] args) throws Exception {
String reportPath = System.getProperty("user.dir") + "/AllStoreUPCandErrorReport.xlsx";
ExcelWriteUtils ewu = new ExcelWriteUtils();
try{
Mail m = new DailyReportInExcelAndEmail().getProperties();
String sinceDate=m.getReportSinceDate();
String[] stores = m.getStoreNumbers().split(",");
MongoUtils mo = new MongoUtils();
JsonUtils ju = new JsonUtils();
//number of records after date
System.out.println("Fetching number of transactions since date "+ sinceDate +" for each store");
String emailBody="";
Long numOfTxns=0l ;
emailBody = emailBody + ("Report of transactions since date: " + sinceDate);
emailBody = emailBody + ("\n\nNumber of Taxation Calls for stores");
for(String store:stores) {
ewu.createSheet(store);
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.eq("storeId",store)));
emailBody = emailBody + ("\n\tStore# " + store + "\t:" + numOfTxns);
}
System.out.println("Fetching errors since date "+ sinceDate +" for all given stores");
//number of records after date with exceptions in response
for(String store:stores){
ewu.setSheet(store);
HashMap<Integer,String> hm = new HashMap<Integer,String>();
hm.put(0,"Date");
hm.put(1,"Error");
ExcelCells ec = new ExcelCells(-1,hm);
ArrayList<ExcelCells> aec = new ArrayList<ExcelCells>();
aec.add(ec);
FindIterable<Document> errors = mo.getAllMatchingDocuments(Filters.and(Filters.gte("timestamp",sinceDate),Filters.regex("response", "exception"),Filters.eq("storeId",store)));
for(Document d: errors) {
String error = (ju.searchJsonStringByJsonPath(d.toJson(), "$.response"));
String[] errorz = error.split(":");
String traceId = errorz[errorz.length-1].replace("\"", "").replace("}", "");
Document errorDoc = mo.getMatchingDocument(Filters.eq("_id",traceId));
String dt = ju.searchJsonStringByJsonPath(errorDoc.toJson(),"$.timestamp");
hm = new HashMap<Integer,String>();
hm.put(0,dt);
hm.put(1,error);
ec = new ExcelCells(-1,hm);
aec.add(ec);
//emailBody = emailBody + ("\n" + dt + "::" + error );
}
ewu.populateCells(aec);
}
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.regex("response", "exception")));
emailBody = emailBody + ("\n\nNumber of Transactions with Exceptions: " + numOfTxns);
ewu.saveWorkBook(reportPath);
//PRINTOUT THE ERRORS
System.out.println("Fetching error counts since date "+ sinceDate +" for all given stores");
//number of records after date with errors in response and percentage > 25.
System.out.println("Missing UPC "+ sinceDate +" for all given stores");
numOfTxns = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp",sinceDate),Filters.gt("percentage",25)));
emailBody = emailBody + ("\n\nNumber of Erroneous Transactions with 25% or more missing UPCs: " + numOfTxns);
//list of unique missing UPCs from the records since date
System.out.println("Missing UPC "+ sinceDate +" for all given stores");
ewu.createSheet("MissingUPC");
HashMap<Integer,String> hm = new HashMap<Integer,String>();
hm.put(0,"Missing UPC");
ExcelCells ec = new ExcelCells(-1,hm);
ArrayList<ExcelCells> aec = new ArrayList<ExcelCells>();
aec.add(ec);
FindIterable<Document> allMissingUPCs = mo.getAllMatchingDocuments(Filters.and(Filters.gte("timestamp",sinceDate),Filters.exists("upc_bpn")));
ArrayList<String> UPCs = new ArrayList<String>();
//emailBody = emailBody + ("\n\nMissing UPCs:\n");
for(Document d:allMissingUPCs) {
String upc = ju.searchJsonStringByJsonPath(d.toJson(), "$.upc_bpn");
String[] arrupc = upc.split(",");
for(String s:arrupc) {
if(!UPCs.contains(s)) {
UPCs.add(s);
hm=new HashMap<Integer, String>();
hm.put(0,s);
ec = new ExcelCells(-1,hm);
aec.add(ec);
//emailBody = emailBody + (s + "," ) ;
}
}
}
ewu.populateCells(aec);
emailBody = emailBody + ("\n\nNumber of UPCs missing product classes: " + UPCs.size());
emailBody = emailBody + ("\n\nTaxation Report generated at : " + new java.util.Date());
mo.closeConnection();
//System.out.println("Generating Emails" + emailBody);
ewu.saveWorkBook(reportPath);
ewu.closeWorkBook();
EmailUtils.sendMail(m.getSmtpServer(),m.getSmtpPort(),m.sendFrom,m.sendTo,"Taxation Report: " + new java.util.Date(),emailBody,reportPath);
System.out.println("Process Complete " + new java.util.Date());
}catch(Exception e){
ewu.saveWorkBook(reportPath);
ewu.closeWorkBook();
}
}
}
package com.nisum.statisticsutils.programs;
import com.mongodb.client.FindIterable;
import com.mongodb.client.model.Filters;
import com.nisum.statisticsutils.models.ExcelCells;
import com.nisum.statisticsutils.utils.EmailUtils;
import com.nisum.statisticsutils.utils.ExcelWriteUtils;
import com.nisum.statisticsutils.utils.JsonUtils;
import com.nisum.statisticsutils.utils.MongoUtils;
import j2html.tags.ContainerTag;
import org.apache.commons.mail.EmailException;
import org.bson.Document;
import javax.mail.MessagingException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static j2html.TagCreator.body;
import static j2html.TagCreator.h2;
import static j2html.TagCreator.head;
import static j2html.TagCreator.html;
import static j2html.TagCreator.table;
import static j2html.TagCreator.td;
import static j2html.TagCreator.th;
import static j2html.TagCreator.tr;
public class DailyReportInExcelAndEmailv2 {
public class Mail{
private String storeNumbers;
private String reportSinceDate;
private String sendTo;
private String sendFrom;
private String smtpServer;
private int smtpPort;
public String getSendTo() {
return sendTo;
}
public void setSendTo(String sendTo) {
this.sendTo = sendTo;
}
public String getSendFrom() {
return sendFrom;
}
public void setSendFrom(String sendFrom) {
this.sendFrom = sendFrom;
}
public void setReportSinceDate(String sinceDate) {
this.reportSinceDate = sinceDate;
}
public String getSmtpServer() {
return smtpServer;
}
public void setSmtpServer(String smtpServer) {
this.smtpServer = smtpServer;
}
public int getSmtpPort() {
return smtpPort;
}
public void setSmtpPort(int smtpPort) {
this.smtpPort = smtpPort;
}
public String getReportSinceDate() {
return this.reportSinceDate;
}
public String getStoreNumbers() {
return storeNumbers;
}
public void setStoreNumbers(String storeNumbers) {
this.storeNumbers = storeNumbers;
}
}
ArrayList<String> txn25pc;
ArrayList<String> errors;
ArrayList<String> missingUPCs;
ExcelWriteUtils ewu;
Mail m;
MongoUtils mo;
JsonUtils ju;
String[] stores;
String emailBody;
ContainerTag emailHtml;
String sinceDate;
HashMap<String,Long> hmTxnCount;
HashMap<String,Long> hmTxnCount25pc;
HashMap<String,Long> hmErrorCount;
public DailyReportInExcelAndEmailv2() throws Exception {
txn25pc = new ArrayList<String>();
errors = new ArrayList<String>();
missingUPCs = new ArrayList<String>();
ewu = new ExcelWriteUtils();
m = getProperties();
mo = new MongoUtils();
ju = new JsonUtils();
stores = m.getStoreNumbers().split(",");
emailBody = "";
emailHtml = null;
sinceDate = m.getReportSinceDate();
hmTxnCount = new HashMap<String,Long>();
hmTxnCount25pc = new HashMap<String,Long>();
hmErrorCount = new HashMap<String,Long>();
}
public Mail getProperties() throws Exception {
Properties prop = new Properties();
String propFile = "config.properties";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream input = getClass().getClassLoader().getResourceAsStream(propFile);
if(input==null){
throw new FileNotFoundException("config.properties file not found");
}else{
prop.load(input);
}
Mail m = new Mail();
m.setSendFrom(prop.getProperty("sendFrom"));
m.setSendTo(prop.getProperty("sendTo"));
m.setSmtpServer(prop.getProperty("smtpServer"));
m.setSmtpPort(Integer.parseInt(prop.getProperty("smtpPort")));
m.setReportSinceDate(prop.getProperty("reportSinceDate"));
m.setStoreNumbers(prop.getProperty("storeNumbers"));
return m;
}
public String[] splitUPCs(String upc){
return upc.split(",");
}
public ArrayList<String> fetchErrors() throws InterruptedException {
for (String store : stores) {
long i = 0l;
FindIterable<Document> docs = mo.getAllMatchingDocuments(
Filters.or(
Filters.and(
Filters.gte("timestamp", sinceDate),
Filters.eq("storeId", store),
Filters.regex("response", "errors"),
Filters.regex("response", "lineItems")
),
Filters.and(
Filters.gte("timestamp", sinceDate),
Filters.eq("storeId", store),
Filters.regex("response", "exception"),
Filters.regex("response", "SocketException")
)
)
);
for (Document d : docs) {
errors.add(d.toJson());
i++;
}
hmErrorCount.put(store,i);
}
return errors;
}
public ArrayList<String> fetchTxnsHigherThan25PC() throws Exception{
for (String store : stores) {
Long i = 0l;
FindIterable<Document> docs = mo.getAllMatchingDocuments(
Filters.and(
Filters.gte("timestamp", sinceDate),
Filters.eq("storeId",store),
Filters.gt("percentage", 25)
)
);
for(Document d:docs){
txn25pc.add(d.toJson());
i++;
}
hmTxnCount25pc.put(store,i);
}
return txn25pc;
}
public void saveAndCloseWorkBook(String reportPath) throws IOException {
ewu.saveWorkBook(reportPath);
ewu.closeWorkBook();
}
public static String replaceGroup(String regex, String source, int groupToReplace, String replacement) throws Exception{
return replaceGroup(regex, source, groupToReplace, 1, replacement);
}
public static String replaceGroup(String regex, String source, int groupToReplace, int groupOccurrence, String replacement) throws Exception{
Matcher m = Pattern.compile(regex).matcher(source);
for (int i = 0; i < groupOccurrence; i++)
if (!m.find()) return source; // pattern not met, may also throw an exception here
return new StringBuilder(source).replace(m.start(groupToReplace), m.end(groupToReplace), replacement).toString();
}
public void populateErrorInExcel() throws Exception {
ewu.createSheet("Errors");
HashMap<Integer, String> hmCols = new HashMap<Integer,String>();
hmCols.put(0,"Store#");
hmCols.put(1,"Error Date");
hmCols.put(2,"Error Details");
ExcelCells ec = new ExcelCells(-1,hmCols);
ArrayList<ExcelCells> aec = new ArrayList<ExcelCells>();
aec.add(ec);
for(String s:this.errors){
try{
String storeId = ju.searchJsonStringByJsonPath(s,"$.storeId");
String ts = ju.searchJsonStringByJsonPath(s,"$.timestamp");
String er = ju.searchJsonStringByJsonPath(s,"$.response");
hmCols = new HashMap<Integer,String>();
hmCols.put(0,storeId);
hmCols.put(1,ts);
hmCols.put(2,er);
ec = new ExcelCells(-1,hmCols);
aec.add(ec);
}catch(Exception e){
System.out.println("Error fetching error details for the following document: \n" + s);
System.out.println("==================================================================================");
}
}
ewu.populateCells(aec);
}
public String padLeftZeros(String inputString, int length) {
if (inputString.length() >= length) {
return inputString;
}
StringBuilder sb = new StringBuilder();
while (sb.length() < length - inputString.length()) {
sb.append(' ');
}
sb.append(inputString);
return sb.toString();
}
public void populateMissingUPCsInExcel() throws Exception{
ewu.createSheet("Missing UPCs");
HashMap<Integer, String> hmCols = new HashMap<Integer,String>();
hmCols.put(0,"Missing UPC - (from Txns with 25+ percent missing UPCs)");
ExcelCells ec = new ExcelCells(-1,hmCols);
ArrayList<ExcelCells> aec = new ArrayList<ExcelCells>();
aec.add(ec);
for(String s:this.txn25pc){
try{
String missingUPCs = ju.searchJsonStringByJsonPath(s,"$.upc_bpn");
String[] arrUPC = missingUPCs.split(",");
for(String upc:arrUPC){
hmCols = new HashMap<Integer,String>();
if(!this.missingUPCs.contains(upc)){
this.missingUPCs.add(upc);
hmCols.put(0,upc);
ec = new ExcelCells(-1,hmCols);
aec.add(ec);
}
}
}catch(Exception e){
System.out.println("Error fetching txn with 25pc more missing UPCs for the following document: \n" + s);
System.out.println("==================================================================================");
}
}
ewu.populateCells(aec);
}
public HashMap<String,Long> fetchTxnCountsPerStore()throws Exception{
for(String store:stores){
Long txnCount = mo.getCountOfMatchingRecords(Filters.and(Filters.gte("timestamp", sinceDate), Filters.eq("storeId", store)));
hmTxnCount.put(store,txnCount);
}
return hmTxnCount;
}
public void appendToEmailBody(String s){
this.emailBody = emailBody + s ;
}
public void sendEmail(String reportPath) throws EmailException {
appendToEmailBody( "Taxation Report since - " + this.sinceDate);
appendToEmailBody("\n" +
padLeftZeros("Store#",6) + "|" +
padLeftZeros("Total Txn Count",15) + "|" +
padLeftZeros(">25% PrdCls Mismatch",20) + "|" +
padLeftZeros("Error Count",11) + "|" +
padLeftZeros("PrdCls Mismatch %",17) + "|" +
padLeftZeros("Error %",7));
Integer totaltxn25pc=0;
Integer totalErrors=0;
Integer totalOfTotalTxns=0;
for(String store: this.stores){
String totalTxnCnt =this.hmTxnCount.get(store)==null?"0":this.hmTxnCount.get(store).toString();
totalOfTotalTxns = totalOfTotalTxns + Integer.parseInt(totalTxnCnt);
String txn25pcCnt = this.hmTxnCount25pc.get(store)==null?"0":this.hmTxnCount25pc.get(store).toString();
totaltxn25pc = totaltxn25pc + Integer.parseInt(txn25pcCnt);
String errorCnt = this.hmErrorCount.get(store)==null?"0": this.hmErrorCount.get(store).toString();
totalErrors = totalErrors + Integer.parseInt(errorCnt);
String pcOf25pc = String.valueOf(Integer.parseInt(txn25pcCnt)*100/Integer.parseInt(totalTxnCnt)) + "%";
if(pcOf25pc.trim().equals("0%")){
pcOf25pc="<1%";
}
String pcOfErrCnt = String.valueOf(Integer.parseInt(errorCnt)*100/Integer.parseInt(totalTxnCnt)) + "%";
if(pcOfErrCnt.trim().equals("0%")){
pcOfErrCnt="<1%";
}
this.emailBody = this.emailBody + "\n"+
padLeftZeros(store,6) + "|" +
padLeftZeros(totalTxnCnt,15) + "|" +
padLeftZeros(txn25pcCnt.toString(),20) + "|" +
padLeftZeros(errorCnt,11) + "|" +
padLeftZeros(pcOf25pc,17) + "|" +
padLeftZeros(pcOfErrCnt,7);
}
String overAllPercentError = String.valueOf((totaltxn25pc*100)/totalOfTotalTxns);
if(overAllPercentError.equals("0")){
overAllPercentError = "<1";
}
this.emailBody = this.emailBody + "\n" +
padLeftZeros("Total",6) + "|" +
padLeftZeros(totalOfTotalTxns.toString(),15) + "|" +
padLeftZeros(totaltxn25pc.toString(),20) + "|" +
padLeftZeros(totalErrors.toString(),11) + "|" +
padLeftZeros(String.valueOf((totaltxn25pc*100)/totalOfTotalTxns) + "%",17) + "|" +
padLeftZeros(overAllPercentError + "%",7);
EmailUtils.sendMail(m.getSmtpServer(),m.getSmtpPort(),m.sendFrom,m.sendTo,"Taxation Report: " + new Date(),emailBody,reportPath);
}
public void sendHtmlEmail(String reportPath) throws EmailException, IOException, MessagingException {
emailHtml = table()
.withStyle("border: 1px solid black")
.withId("results").with(tr
(
th("Store#").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:50px"),
th("Total Txn Count").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:100px"),
th("Txn w:25+% Missing UPCs").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:100px"),
th("Error Count").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:100px"),
th("% of Txns w:25+% Missing UPCs").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:100px"),
th("% of Txns w:Errors").withStyle("border: 1px solid black;text-align: center;font-weight:bold;width:100px")
));
Integer totaltxn25pc=0;
Integer totalErrors=0;
Integer totalOfTotalTxns=0;
for(String store: this.stores){
String totalTxnCnt =this.hmTxnCount.get(store)==null?"0":this.hmTxnCount.get(store).toString();
totalOfTotalTxns = totalOfTotalTxns + Integer.parseInt(totalTxnCnt);
String txn25pcCnt = this.hmTxnCount25pc.get(store)==null?"0":this.hmTxnCount25pc.get(store).toString();
totaltxn25pc = totaltxn25pc + Integer.parseInt(txn25pcCnt);
String errorCnt = this.hmErrorCount.get(store)==null?"0": this.hmErrorCount.get(store).toString();
totalErrors = totalErrors + Integer.parseInt(errorCnt);
String pcOf25pc = String.valueOf(Integer.parseInt(txn25pcCnt)*100/Integer.parseInt(totalTxnCnt));
if(pcOf25pc.trim().equals("0")){
pcOf25pc="<1";
}
String pcOfErrCnt = String.valueOf(Integer.parseInt(errorCnt)*100/Integer.parseInt(totalTxnCnt));
if(pcOfErrCnt.trim().equals("0")){
pcOfErrCnt="<1";
}
this.emailHtml.with(tr(td().withStyle("border: 1px solid black;text-align: left").withText(store),td().withStyle("border: 1px solid black;text-align: right").withText(totalTxnCnt),td().withStyle("border: 1px solid black;text-align: right").withText(txn25pcCnt),td().withStyle("border: 1px solid black;text-align: right").withText(errorCnt),td().withStyle("border: 1px solid black;text-align: right").withText(pcOf25pc + "%"),td().withStyle("border: 1px solid black;text-align: right").withText(pcOfErrCnt+"%")));
}
String overAllPercentError = String.valueOf((totalErrors*100)/totalOfTotalTxns);
if(overAllPercentError.equals("0")){
overAllPercentError = "<1";
}
this.emailHtml.with(tr(td("Total").withStyle("border: 1px solid black;text-align: left;font-weight:bold"),td(totalOfTotalTxns.toString()).withStyle("border: 1px solid black;text-align: right;font-weight:bold"),td(totaltxn25pc.toString()).withStyle("border: 1px solid black;text-align: right;font-weight:bold"),td(totalErrors.toString()).withStyle("border: 1px solid black;text-align: right;font-weight:bold"),td(String.valueOf((totaltxn25pc*100)/totalOfTotalTxns) + "%").withStyle("border: 1px solid black;text-align: right;font-weight:bold"),td(overAllPercentError + "%").withStyle("border: 1px solid black;text-align: right;font-weight:bold")));
ContainerTag finalHtml = html().with(head().with(h2("Taxation Report since - " + this.sinceDate))).with(body().with(this.emailHtml));
EmailUtils.sendHtmlMail(m.getSmtpServer(),m.getSmtpPort(),m.sendFrom,m.sendTo,"Taxation Report: " + new Date(),finalHtml.render().toString(),reportPath);
}
public static void main(String[] args) throws Exception {
DailyReportInExcelAndEmailv2 dailyReport = new DailyReportInExcelAndEmailv2();
String reportPath = System.getProperty("user.dir") + "/AllStoreUPCandErrorReport.xlsx";
System.out.println("Fetching txn counts for each store");
dailyReport.fetchTxnCountsPerStore();
System.out.println("Fetching txn counts with 25% or more missing UPCs for each store");
dailyReport.fetchTxnsHigherThan25PC();
System.out.println("Fetching errors from txns for each store");
dailyReport.fetchErrors();
System.out.println("Populating errors in excel");
dailyReport.populateErrorInExcel();
System.out.println("Populating missing UPCs in excel");
dailyReport.populateMissingUPCsInExcel();
System.out.println("Saving & closing the workbook");
dailyReport.saveAndCloseWorkBook(reportPath);
//dailyReport.sendEmail(reportPath);
System.out.println("Sening Email");
dailyReport.sendHtmlEmail(reportPath);
}
}
package com.nisum.statisticsutils.programs;
import com.mongodb.client.model.Filters;
import com.nisum.statisticsutils.utils.*;
import gherkin.deps.com.google.gson.JsonArray;
import gherkin.deps.com.google.gson.JsonElement;
import org.bson.Document;
import java.util.ArrayList;
public class FindPercentageZero {
public static void main(String[] args) throws Exception {
JsonUtils ju = new JsonUtils();
MongoUtils mo = new MongoUtils();
String taxProdJson = ju.jsonFileToString("/Users/nisum/Downloads/octx-snoflake/taxprodchk.json");
JsonArray txnArray = ju.jsonFileToJsonArray(taxProdJson);
ArrayList<String> orderIds = new ArrayList<String>();
for(JsonElement je: txnArray) {
orderIds.add(ju.searchJsonStringByJsonPath(je.toString(), "$._id"));
}
for(String oId:orderIds) {
Document dc = mo.getAllMatchingDocumentsSorted(Filters.eq("orderId",oId),false,"timestamp").first();
if(Float.parseFloat(ju.searchJsonStringByJsonPath(dc.toJson(), "$.percentage"))==0.0f) {
System.out.println(oId);
}
}
mo.closeConnection();
}
}
package com.nisum.statisticsutils.utils;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class CsvUtils {
BufferedReader br=null;
public CsvUtils(String filePath) throws FileNotFoundException {
this.br = new BufferedReader(new FileReader(filePath));
}
public ArrayList<String> readAllLines(Boolean containsHeading) throws IOException{
ArrayList<String> ls = new ArrayList<String>();
String line;
while ((line = br.readLine()) != null) {
if(containsHeading) {
containsHeading=false;
continue;
}else {
ls.add(line);
}
}
return ls;
}
public String getColumnValue(String line, String delimiterRegex,Integer columnNumber) {
return line.split(delimiterRegex)[columnNumber];
}
public void closeBufferedReader() throws IOException{
br.close();
br = null;
}
public static void main(String[] args) throws IOException {
CsvUtils cu = new CsvUtils("/Users/nisum/Downloads/FileCompare/SIMS.csv");
ArrayList<String> ls = cu.readAllLines(true);
for(String s:ls) {
System.out.println(cu.getColumnValue(s, ",", 3));
System.out.println(cu.getColumnValue(s, ",", 7));
System.out.println(cu.getColumnValue(s, ",", 8));
}
cu.closeBufferedReader();
}
}
package com.nisum.statisticsutils.utils;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
public class EmailUtils {
public static void sendMail(String smtpAddress, int smtpPort, String sendFrom, String sendTo, String subject, String textBody,String attachmentPath) throws EmailException {
// Create the attachment
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(attachmentPath);
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("All Store Error And UPC Report");
attachment.setName("AllStoreReport.xlsx");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName(smtpAddress);
//email.setAuthentication(userName,"Blabla@1234");
email.setSmtpPort(smtpPort);
email.addTo(sendTo);
email.setFrom(sendTo);
email.setSubject(subject);
email.setMsg(textBody);
// add the attachment
email.attach(attachment);
// send the email
email.send();
}
public static void sendHtmlMail(String smtpAddress, int smtpPort, String sendFrom, String sendTo, String subject, String textBody, String attachmentPath) throws EmailException, MessagingException, IOException {
// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpAddress);
properties.put("mail.smtp.port", smtpPort);
//properties.put("mail.smtp.auth", "false");
//properties.put("mail.smtp.starttls.enable", "true");
//properties.put("mail.user", userName);
//properties.put("mail.password", password);
// creates a new session with an authenticator
/*Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
};*/
Session session = Session.getInstance(properties);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(sendFrom));
InternetAddress[] toAddresses = { new InternetAddress(sendTo) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
// creates message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(textBody, "text/html");
// creates multi-part
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
MimeBodyPart attachPart = new MimeBodyPart();
attachPart.attachFile(attachmentPath);
multipart.addBodyPart(attachPart);
// sets the multi-part as e-mail's content
msg.setContent(multipart);
// sends the e-mail
Transport.send(msg);
}
public static void main(String[] args) throws EmailException {
EmailUtils.sendMail("smtp.gmail.com",465,"kattanguru@gmail.com","kattanguru@gmail.com","Test Subject","TextBody",System.getProperty("user.dir")+"/TestErrorReport.xlsx");
}
}
package com.nisum.statisticsutils.utils;
import com.nisum.statisticsutils.models.ExcelCells;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
public class ExcelWriteUtils {
XSSFWorkbook workbook;
XSSFSheet sheet,readfiles;
public ExcelWriteUtils() throws Exception {
workbook = new XSSFWorkbook();
}
public void createSheet(String sheetName){
sheet = workbook.createSheet(sheetName);
}
public void setSheet(String sheetName){
sheet = workbook.getSheet(sheetName);
}
public void populateCells(ArrayList<ExcelCells> aEC) {
for(ExcelCells c: aEC){
if(c.getRowNum()==-1){
Row row = sheet.createRow(getLastRowNum());
Set<Integer> colKeys = c.getHmColumnValues().keySet();
for(Integer i:colKeys){
row.createCell(i).setCellValue(c.getHmColumnValues().get(i));
}
}
}
}
public void saveWorkBook(String FilePath) throws FileNotFoundException, IOException {
FileOutputStream fop = new FileOutputStream(new File(FilePath));
workbook.write(fop);
fop.close();
}
public void closeWorkBookWithoutSaving() throws IOException{
workbook.close();
}
public void closeWorkBook() throws IOException {
workbook.close();
}
public Integer getLastRowNum() {
return (sheet.getPhysicalNumberOfRows());
}
public Integer getLastColNum() {
int i = 0;
for (Row row : sheet) {
while(row.getCell(i)!=null) {
i++;
}
break;
}
return i;
}
public Row getRowByNumber(Integer rownum) {
return sheet.getRow(rownum);
}
public Cell getCellByRowColNumber(Row row, Integer colNum) {
return row.getCell(colNum);
}
public static void main(String[] args) throws Exception {
ExcelWriteUtils eu = new ExcelWriteUtils();
eu.createSheet("abc");
eu.createSheet("def");
eu.setSheet("abc");
HashMap<Integer, String> hmCells = new HashMap<Integer,String>();
hmCells.put(0, "cell0");
hmCells.put(1, "cell1");
ExcelCells ec = new ExcelCells(-1,hmCells);
ArrayList<ExcelCells> aec = new ArrayList<ExcelCells>();
aec.add(ec);
eu.populateCells(aec);
eu.setSheet("def");
ec = new ExcelCells(-1,hmCells);
eu.populateCells(aec);
eu.saveWorkBook("/Users/nisum/Downloads/test.xlsx");
}
}
package com.nisum.statisticsutils.utils;
import java.io.FileWriter;
import java.io.IOException;
public class FileUtils {
FileWriter fw=null;
public FileUtils(String filePath) throws IOException {
this.fw = new FileWriter(filePath);
}
public void writeLineToFile(String line) throws IOException {
fw.write(line + "\r\n");
}
public void appendLineToFile(String line) throws IOException {
fw.append(line + "\r\n");
}
public void closeFileWriter() throws IOException {
fw.close();
}
}
package com.nisum.statisticsutils.utils;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import gherkin.deps.com.google.gson.JsonArray;
import gherkin.deps.com.google.gson.JsonElement;
import gherkin.deps.com.google.gson.JsonObject;
import gherkin.deps.com.google.gson.JsonParser;
import gherkin.deps.com.google.gson.JsonSyntaxException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class JsonUtils {
public String jsonFileToString(String jsonFilePath) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(jsonFilePath));
String str = "";
String st;
while (true) {
st = br.readLine();
if(st==null) {
break;
}else {
str = str + st;
}
}
br.close();
return str;
}
public JsonArray jsonFileToJsonArray(String json) {
JsonParser jsonParser = new JsonParser();
return jsonParser.parse(json).getAsJsonArray();
}
public JsonObject jsonFileToJsonObject(String jsonFilePath) throws JsonSyntaxException, IOException {
JsonParser jp = new JsonParser();
return jp.parse(jsonFileToString(jsonFilePath)).getAsJsonObject();
}
public String modifyJsonWithJsonPathFromFile(String jsonFilePath,String jsonPath,String newValue ) throws JsonSyntaxException, IOException {
DocumentContext parsedDataContext = JsonPath.parse(jsonFileToString(jsonFilePath));
parsedDataContext.set(jsonPath, newValue);
return (parsedDataContext.jsonString());
}
public String modifyJsonWithJsonPathFromJsonString(String jsonString,String jsonPath,String newValue ) throws JsonSyntaxException, IOException {
DocumentContext parsedDataContext = JsonPath.parse(jsonString);
parsedDataContext.set(jsonPath, newValue);
return (parsedDataContext.jsonString());
}
public String searchJsonFileByJsonPath(String jsonFilePath,String jsonPath) throws JsonSyntaxException, IOException {
DocumentContext parsedDataContext = JsonPath.parse(jsonFileToString(jsonFilePath));
parsedDataContext.read(jsonPath);
return (parsedDataContext.read(jsonPath).toString());
}
public String searchJsonStringByJsonPath(String jsonString ,String jsonPath) throws JsonSyntaxException, IOException {
DocumentContext parsedDataContext = JsonPath.parse(jsonString);
parsedDataContext.read(jsonPath);
return (parsedDataContext.read(jsonPath).toString());
}
public JsonArray jsonStringtoJsonArray(String jsonFullString ,String jsonPathOfArrayNode) throws JsonSyntaxException, IOException {
jsonFullString = searchJsonStringByJsonPath(jsonFullString, jsonPathOfArrayNode);
JsonParser parser = new JsonParser();
JsonElement elements = parser.parse(jsonFullString);
JsonArray jsonArray = elements.getAsJsonArray();
return jsonArray;
}
public static void main(String[] args) throws IOException {
}
}
package com.nisum.statisticsutils.utils;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.conversions.Bson;
public class MongoUtils {
MongoClient mongoClient=null;
MongoDatabase database = null;
MongoCollection<Document> mc = null;
public MongoUtils() {
MongoClientURI mcuri = new MongoClientURI("mongodb://mongodb-octx-taxation-prod:WA3F1ZSKyq8vqLwNf06fNVmBR2UBYCMrQP5kn6VwJ6z2c6xNkcnMb0aaFoz4tRWEFoy4o35yljBzl3xir1LDEA==@mongodb-octx-taxation-prod.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@mongodb-octx-taxation-prod@");
this.mongoClient = new MongoClient(mcuri);
this.database = mongoClient.getDatabase("octx-taxation");
this.mc = database.getCollection("octx-log");
}
public FindIterable<Document> getAllMatchingDocuments(Bson filter) throws InterruptedException {
FindIterable<Document> ml = null;
try{
if(filter==null) {
ml = this.mc.find();
}else {
ml = this.mc.find(filter);
}
}catch(Exception e){
Thread.sleep(5000);
if(filter==null) {
ml = this.mc.find();
}else {
ml = this.mc.find(filter);
}
}
return ml;
}
public FindIterable<Document> getAllMatchingDocumentsSorted(Bson filter, Boolean isAscending, String SortBy) throws InterruptedException {
FindIterable<Document> ml=null;
try{
if(isAscending) {
ml = this.mc.find(filter).sort(Sorts.ascending(SortBy));
}else {
ml = this.mc.find(filter).sort(Sorts.descending(SortBy));
}
}catch(Exception e) {
Thread.sleep(5000);
if(isAscending) {
ml = this.mc.find(filter).sort(Sorts.ascending(SortBy));
}else {
ml = this.mc.find(filter).sort(Sorts.descending(SortBy));
}
}
return ml;
}
public Document getMatchingDocument(Bson filter) throws InterruptedException {
try{
return this.mc.find(filter).first();
}catch(Exception e){
Thread.sleep(5000);
return this.mc.find(filter).first();
}
}
public Long getCountOfMatchingRecords(Bson filter) throws InterruptedException {
try{
return mc.countDocuments(filter);
}catch(Exception e){
Thread.sleep(5000);
return mc.countDocuments(filter);
}
}
public void closeConnection() {
mongoClient.close();
}
public static void main( String args[] ) throws Exception {
MongoClientURI uri = new MongoClientURI("mongodb://mongodb-octx-taxation-prod:WA3F1ZSKyq8vqLwNf06fNVmBR2UBYCMrQP5kn6VwJ6z2c6xNkcnMb0aaFoz4tRWEFoy4o35yljBzl3xir1LDEA==@mongodb-octx-taxation-prod.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@mongodb-octx-taxation-prod@");
MongoClient mongoClient = new MongoClient(uri);
MongoDatabase database = mongoClient.getDatabase("octx-taxation");
MongoCollection<Document> mc = database.getCollection("octx-log");
// Document myDoc = mc.find().first();
// System.out.println(myDoc.toJson());
//
// FindIterable<Document> ml = mc.find(Filters.eq("percentage",0.0));
// for(Document d:ml) {
// System.out.println(d.toString());
// }
//
MongoUtils mo = new MongoUtils();
FindIterable<Document> ml = mo.getAllMatchingDocuments(Filters.and(Filters.eq("orderId","12715178"),Filters.eq("percentage",0.0)));
for(Document d:ml) {
System.out.println(d.toString());
}
//
// for(Document d:ml) {
// System.out.println(d.toString());
// Document myDoc = (Document) mo.getAllMatchingDocuments(Filters.and(Filters.eq("orderId", d.toString()),Filters.eq("percentage",0.0))).first();
//
// System.out.println(myDoc.toJson());
// }
}
}
reportSinceDate=12/04/2020
storeNumbers=2,90,93,101,103,118,126,130,138,145,154,155,156,159,160,161,162,164,165,166,168,169,171,176,177,180,182,184,189,193,199,212,332,460,611,1276,1470,1517,1602,1795,1970,2511,2614,2804,3174,3195,3205,3206,3337,3339,3360,3366,3489,4004,4009,4011,4139
smtpServer=smtp.gmail.com
smtpPort=465
sendTo=kattanguru@gmail.com
sendFrom=kattanguru@gmail.com
\ No newline at end of file
package com.nisum.statisticsutils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class StatisticsUtilsApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment