diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..2420d088bcd222758a4ef51d1d6858afbce172d4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM openjdk:8 +MAINTAINER haridas <haridas.kakunje@tarento.com> +ADD target/aurora-0.0.1-SNAPSHOT.jar aurora-0.0.1-SNAPSHOT.jar +ADD public/emails emails +ENTRYPOINT ["java", "-jar", "/aurora-0.0.1-SNAPSHOT.jar"] +EXPOSE 8081 + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..2bbb9c1a47c232c08de5359eee10e3dd6b6a7e23 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,4 @@ +@Library("centralized-jenkins") _ + springboot_with_encryption_build { + + } diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2e75a32f5113b7c56668aac28e7305134e17884 --- /dev/null +++ b/pom.xml @@ -0,0 +1,291 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.upsmf</groupId> + <artifactId>grievance</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>Grievance Desk</name> + <description>Grievance Helpdesk managing and resolving the Service Requests and Feedbacks</description> + + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.3.4.RELEASE</version> + <relativePath /> <!-- lookup parent from repository --> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.version> + <cxf.version>3.0.1</cxf.version> + <log4j2.version>2.16.0</log4j2.version> + + <base>frolvlad/alpine-oraclejdk8:slim</base> + <tomcat.port>9081</tomcat.port> + <tomcat.ip>127.0.0.1</tomcat.ip> + <file>readme</file> + + </properties> + + <dependencies> + <dependency> + <groupId>com.sun.mail</groupId> + <artifactId>javax.mail</artifactId> + <version>1.6.0</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + <version>3.1.2</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <scope>runtime</scope> + </dependency> + + <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk --> + <dependency> + <groupId>com.amazonaws</groupId> + <artifactId>aws-java-sdk</artifactId> + <version>1.11.170</version> + </dependency> + + + <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> + <dependency> + <groupId>org.apache.poi</groupId> + <artifactId>poi</artifactId> + <version>3.9</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-jwt --> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-jwt</artifactId> + <version>1.1.0.RELEASE</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 --> + <dependency> + <groupId>org.springframework.security.oauth</groupId> + <artifactId>spring-security-oauth2</artifactId> + <version>2.5.0.RELEASE</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>1.7.1</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>1.7.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + <version>1.1.1</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxws</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-transports-http</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-tools-java2ws</artifactId> + <version>${cxf.version}</version> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + </dependency> + <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + <dependency> + <groupId>io.jsonwebtoken</groupId> + <artifactId>jjwt</artifactId> + <version>0.6.0</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 --> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-dbcp2</artifactId> + <version>2.9.0</version> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.3</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.7</version> + </dependency> + <!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client --> + <dependency> + <groupId>com.google.api-client</groupId> + <artifactId>google-api-client</artifactId> + <version>1.22.0</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz --> + <dependency> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> + <version>2.1.5</version> + </dependency> + + <!-- https://mvnrepository.com/artifact/com.taskadapter/redmine-java-api --> + <dependency> + <groupId>com.taskadapter</groupId> + <artifactId>redmine-java-api</artifactId> + <version>3.0.0</version> + </dependency> + <dependency> + <groupId>org.elasticsearch</groupId> + <artifactId>elasticsearch</artifactId> + <version>6.0.0</version> + </dependency> + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + <version>6.2.4</version> + </dependency> + <dependency> + <groupId>org.scala-lang</groupId> + <artifactId>scala-library</artifactId> + <version>2.11.0</version> + </dependency> + <dependency> + <groupId>com.bazaarvoice.jolt</groupId> + <artifactId>jolt-core</artifactId> + <version>0.0.24</version> + </dependency> + <dependency> + <groupId>com.bazaarvoice.jolt</groupId> + <artifactId>json-utils</artifactId> + <version>0.0.24</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <executable>true</executable> + <addResources>true</addResources> + </configuration> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>docker-maven-plugin</artifactId> + <extensions>true</extensions> + + <configuration> + <images> + <image> + <name>springboot-jwt</name> + <alias>springboot-jwt</alias> + <build> + <filter>@</filter> + <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir> + <assembly> + <descriptorRef>artifact</descriptorRef> + </assembly> + </build> + <run> + <namingStrategy>alias</namingStrategy> + <ports> + <port>${tomcat.port}:8080</port> + </ports> + <wait> + <http> + <url>http://${tomcat.ip}:${tomcat.port}/health</url> + </http> + <time>90000</time> + </wait> + </run> + </image> + </images> + </configuration> + + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file diff --git a/public/emails/add-admin-aurora.vm b/public/emails/add-admin-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..7690b73a03dcb756aee6dc4669cb99b47d629113 --- /dev/null +++ b/public/emails/add-admin-aurora.vm @@ -0,0 +1,318 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + + .content-padding { + padding: 5px 5px 5px 10px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td valign="top" width="100%" style="background-color: #f7f7f7;text-align:left" class="content-padding"> + <center> + <p><b> Hi $firstName,<br> + You are designated as Org Admin for $CompName. You may access Aurora web using <a href="https://aurora-desk.idc.tarento.com/"> this link </a>.<br> + Thank you!</b> + </center> + </td> + </tr> + </table> + + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</body> +</html> diff --git a/public/emails/add-helpdeskadmin-aurora.vm b/public/emails/add-helpdeskadmin-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..7a6d95ed107ff4d8c7cab8e409010197b476e01d --- /dev/null +++ b/public/emails/add-helpdeskadmin-aurora.vm @@ -0,0 +1,318 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + + .content-padding { + padding: 5px 5px 5px 10px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td valign="top" width="100%" style="background-color: #f7f7f7;text-align:left" class="content-padding"> + <center> + <p><b> Hi $firstName,<br> + You are designated as Helpdesk Admin for $HelpdeskName. You may access Aurora web using <a href="https://aurora-desk.idc.tarento.com/"> this link </a>.<br> + Thank you!</b> + </center> + </td> + </tr> + </table> + + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</body> +</html> diff --git a/public/emails/copied-to-ticket-aurora.vm b/public/emails/copied-to-ticket-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..b68bbd5a7f34f79b54f9d87e7b8b72a74448acdb --- /dev/null +++ b/public/emails/copied-to-ticket-aurora.vm @@ -0,0 +1,331 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 20px 0 5px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- <table cellpadding="0" cellspacing="0" width="600" class="w320"> + <tr> + #if ($logo_url) --> + <!-- <td class="pull-left mobile-header-padding-left" style="vertical-align: middle;"> + <a href=""><img height="47" src='$logo_url' alt="logo"></a> + </td> + #end + </tr> + </table> --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding"> + <center> + <p> Hi $firstName,</p> + <p>You are copied to ticket <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets/"> $id </a> on helpdesk $HelpdeskName. You may access ticket details using <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets"> this link </a>.</p> + <p>Thank you!</p> + + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</div> +</body> +</html> diff --git a/public/emails/email_template.vm b/public/emails/email_template.vm new file mode 100644 index 0000000000000000000000000000000000000000..5770e3b2a762e53a6f10009e5be4f6a3075d195d --- /dev/null +++ b/public/emails/email_template.vm @@ -0,0 +1,444 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #ff6f6f; + font-weight: bold; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 20px 0 30px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .block-rounded { + border-radius: 5px; + border: 1px solid #e5e5e5; + vertical-align: top; + } + + .button { + padding: 30px 0 0; + } + + .info-block { + padding: 0 20px; + width: 260px; + } + + .mini-block-container { + padding: 30px 50px; + width: 500px; + } + + .mini-block { + background-color: #ffffff; + width: 498px; + border: 1px solid #cccccc; + border-radius: 5px; + padding: 45px 75px; + } + + .block-rounded { + width: 260px; + } + + .info-img { + width: 258px; + border-radius: 5px 5px 0 0; + } + + .force-width-img { + width: 480px; + height: 1px !important; + } + + .force-width-full { + width: 600px; + height: 1px !important; + } + + .user-img img { + width: 130px; + border-radius: 5px; + border: 1px solid #cccccc; + } + + .user-img { + text-align: center; + border-radius: 100px; + color: #ff6f6f; + font-weight: 700; + } + + .user-msg { + padding-top: 10px; + font-size: 14px; + text-align: center; + font-style: italic; + } + + .mini-img { + padding: 5px; + width: 140px; + } + + .mini-img img { + border-radius: 5px; + width: 140px; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + .mini-imgs { + padding: 10px 0 20px; + } + + div.center { + display: table; + } + ul { + text-align: left; + list-style-type:none; + } + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + div.center { + margin-right: 1rem; + } + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + table[class="w320"] { + width: 320px !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="mobile-block"] { + display: block !important; + } + + td[class="mini-img"], + td[class="mini-img"] img{ + width: 150px !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="header-md"] { + font-size: 18px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 30px !important; + } + + td[class="button"] { + padding: 5px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + img[class="force-width-img"], + img[class="force-width-full"] { + display: none !important; + } + + td[class="info-block"] { + display: block !important; + width: 280px !important; + padding-bottom: 40px !important; + } + + td[class="info-img"], + img[class="info-img"] { + width: 278px !important; + } + + td[class="mini-block-container"] { + padding: 8px 20px !important; + width: 280px !important; + } + + td[class="mini-block"] { + padding: 20px !important; + } + + td[class="user-img"] { + display: block !important; + text-align: center !important; + width: 100% !important; + padding-bottom: 10px; + } + + td[class="user-msg"] { + display: block !important; + padding-bottom: 20px; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td class="header-lg"> + You've received an invitation! + </td> + </tr> + <tr> + </tr> + <tr> + <td class="mini-block-container"> + <table cellspacing="0" cellpadding="0" width="100%" style="border-collapse:separate !important;"> + <tr> + <td class="mini-block"> + <table cellpadding="0" cellspacing="0" width="100%"> + <tr> + <td> + <table cellspacing="0" cellpadding="0" width="100%"> + + <tr> + <td class="header-lg"> + Hi, $firstName <br> + $mail_subject + </td> + </tr> + <tr> + <td class="user-msg"> + <div id="wrapper" class="center"> + <div id="content" class="center"> + <div id="listDiv" class="center"> + <ul> + <li>Your username is: $username + </li> + <li>Your password is: $password + </li> + </ul> + </div> + </div> + </div> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <td class="button"> + <div><!--[if mso]> + <v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://" style="height:45px;v-text-anchor:middle;width:155px;" arcsize="15%" strokecolor="#ffffff" fillcolor="#ff6f6f"> + <w:anchorlock/> + <center style="color:#ffffff;font-family:Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;">Sign Up</center> + </v:roundrect> + <![endif]--><a href="#" + style="background-color:#ff6f6f;border-radius:5px;color:#ffffff;display:inline-block;font-family:'Cabin', Helvetica, Arial, sans-serif;font-size:14px;font-weight:regular;line-height:45px;text-align:center;text-decoration:none;width:155px;-webkit-text-size-adjust:none;mso-hide:all;">Sign In</a></div> + </td> + </tr> + </table> + </td> + </tr> + </table> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #ffffff; border-top: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5;"> + <center> + <table cellpadding="0" cellspacing="0" width="600" class="w320"> + <tr> + <td class="header-md" style="text-align:center;"> + Welcome aboard! + </td> + </tr> + <tr> + <td class="mini-imgs"> + + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + <!-- 1234 Awesome St <br /> + Wonderland <br /><br /> --> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</body> +</html> diff --git a/public/emails/forgot-password.vm b/public/emails/forgot-password.vm new file mode 100644 index 0000000000000000000000000000000000000000..584063e802830fcd3c16baf979b92633bdd8d9f7 --- /dev/null +++ b/public/emails/forgot-password.vm @@ -0,0 +1,330 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 20px 0 5px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- <table cellpadding="0" cellspacing="0" width="600" class="w320"> + <tr> + #if ($logo_url) --> + <!-- <td class="pull-left mobile-header-padding-left" style="vertical-align: middle;"> + <a href=""><img height="47" src='$logo_url' alt="logo"></a> + </td> + #end + </tr> + </table> --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding"> + <center> + <h2>Here is your new password!</h2> + <p>Your password is: $password</p> + <p>You can change your password from the website <a href="websiteurl">https://aurora-desk.idc.tarento.com/login</a></p> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</div> +</body> +</html> diff --git a/public/emails/new-ticket-createdby-aurora.vm b/public/emails/new-ticket-createdby-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..8a7c65fd74e48d1ca575a86c1394d9f027a9c4fc --- /dev/null +++ b/public/emails/new-ticket-createdby-aurora.vm @@ -0,0 +1,331 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 20px 0 5px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- <table cellpadding="0" cellspacing="0" width="600" class="w320"> + <tr> + #if ($logo_url) --> + <!-- <td class="pull-left mobile-header-padding-left" style="vertical-align: middle;"> + <a href=""><img height="47" src='$logo_url' alt="logo"></a> + </td> + #end + </tr> + </table> --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding"> + <center> + <p> Hi $firstName,</p> + <p>You have added a new ticket <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets/"> $id </a> on helpdesk $HelpdeskName. You may access ticket details using <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets"> this link </a>.</p> + <p>Thank you!</p> + + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</div> +</body> +</html> diff --git a/public/emails/remove-copied-to-ticket-aurora.vm b/public/emails/remove-copied-to-ticket-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..7c7bb1494447a0c958d8bfa9c69ea3aa2cbffc1d --- /dev/null +++ b/public/emails/remove-copied-to-ticket-aurora.vm @@ -0,0 +1,333 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + + .content-padding { + padding: 5px 5px 5px 10px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td valign="top" width="100%" style="background-color: #f7f7f7;text-align:left" class="content-padding"> + <center> + <p> Hi $firstName,<br> + You are removed from ticket <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets/"> $id </a> on helpdesk $HelpdeskName. You may access ticket details using <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets"> this link </a>.<br> + Thank you! + </center> + </td> + </tr> + </table> + + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + </td> + </tr> + </table> + </center> + </td> + </tr> + + </table> + </center> + </td> + </tr> +</table> +</body> +</html> + \ No newline at end of file diff --git a/public/emails/remove_admin.vm b/public/emails/remove_admin.vm new file mode 100644 index 0000000000000000000000000000000000000000..df42ce07636a5e3e6a149262744a73ca830fb7ed --- /dev/null +++ b/public/emails/remove_admin.vm @@ -0,0 +1,316 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 5px 5px 5px 10px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td valign="top" width="100%" style="background-color: #f7f7f7; text-align:left" class="content-padding"> + <center> + <p><b> Hi $firstName, <br> + You have been revoked with Organization Admin access for $CompName. Please contact your respective admin for further details.<br> + Thank you! </p></b> + </center> + </td> + </tr> + </table> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</body> +</html> diff --git a/public/emails/remove_helpdeskadmin.vm b/public/emails/remove_helpdeskadmin.vm new file mode 100644 index 0000000000000000000000000000000000000000..d3eadd1b3fc6f79309dc28f8c3ec941544db47bb --- /dev/null +++ b/public/emails/remove_helpdeskadmin.vm @@ -0,0 +1,316 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 5px 5px 5px 10px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- #if ($logo_url) --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + <!-- #end --> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td valign="top" width="100%" style="background-color: #f7f7f7; text-align:left" class="content-padding"> + <center> + <p><b> Hi $firstName, <br> + You have been revoked with Helpdesk Admin access for $HelpdeskName. Please contact your respective admin for further details.<br> + Thank you! </p></b> + </center> + </td> + </tr> + </table> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</body> +</html> diff --git a/public/emails/ticket-status-update-aurora.vm b/public/emails/ticket-status-update-aurora.vm new file mode 100644 index 0000000000000000000000000000000000000000..dee3a3f23a2b0141f16902ea1767aaf3fe6f6904 --- /dev/null +++ b/public/emails/ticket-status-update-aurora.vm @@ -0,0 +1,331 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <title>Aurora Helpdesk</title> + + <style type="text/css"> + /* Take care of image borders and formatting, client hacks */ + img { max-width: 600px; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;} + a img { border: none; } + table { border-collapse: collapse !important;} + #outlook a { padding:0; } + .ReadMsgBody { width: 100%; } + .ExternalClass { width: 100%; } + .backgroundTable { margin: 0 auto; padding: 0; width: 100% !important; } + table td { border-collapse: collapse; } + .ExternalClass * { line-height: 115%; } + .container-for-gmail-android { min-width: 600px; } + + + /* General styling */ + * { + font-family: Helvetica, Arial, sans-serif; + } + + body { + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: none; + width: 100% !important; + margin: 0 !important; + height: 100%; + color: #676767; + } + + td { + font-family: Helvetica, Arial, sans-serif; + font-size: 14px; + color: #777777; + text-align: center; + line-height: 21px; + } + + a { + color: #676767; + text-decoration: none !important; + } + + .pull-left { + text-align: left; + } + + .pull-right { + text-align: right; + } + + .header-lg, + .header-md, + .header-sm { + font-size: 32px; + font-weight: 700; + line-height: normal; + padding: 35px 0 0; + color: #4d4d4d; + } + + .header-md { + font-size: 24px; + } + + .header-sm { + padding: 5px 0; + font-size: 18px; + line-height: 1.3; + } + + .content-padding { + padding: 20px 0 5px; + } + + .mobile-header-padding-right { + width: 290px; + text-align: right; + padding-left: 10px; + } + + .mobile-header-padding-left { + width: 290px; + text-align: left; + padding-left: 10px; + } + + .free-text { + width: 100% !important; + padding: 10px 60px 0px; + } + + .button { + padding: 30px 0; + } + + + .mini-block { + border: 1px solid #e5e5e5; + border-radius: 5px; + background-color: #ffffff; + padding: 12px 15px 15px; + text-align: left; + width: 253px; + } + + .mini-container-left { + width: 278px; + padding: 10px 0 10px 15px; + } + + .mini-container-right { + width: 278px; + padding: 10px 14px 10px 15px; + } + + .product { + text-align: left; + vertical-align: top; + width: 175px; + } + + .total-space { + padding-bottom: 8px; + display: inline-block; + } + + .item-table { + padding: 50px 20px; + width: 560px; + } + + .item { + width: 300px; + } + + .mobile-hide-img { + text-align: left; + width: 125px; + } + + .mobile-hide-img img { + border: 1px solid #e6e6e6; + border-radius: 4px; + } + + .title-dark { + text-align: left; + border-bottom: 1px solid #cccccc; + color: #4d4d4d; + font-weight: 700; + padding-bottom: 5px; + } + + .item-col { + padding-top: 20px; + text-align: left; + vertical-align: top; + } + + .force-width-gmail { + min-width:600px; + height: 0px !important; + line-height: 1px !important; + font-size: 1px !important; + } + + </style> + + <style type="text/css" media="screen"> + @import url(http://fonts.googleapis.com/css?family=Oxygen:400,700); + </style> + + <style type="text/css" media="screen"> + @media screen { + /* Thanks Outlook 2013! */ + * { + font-family: 'Oxygen', 'Helvetica Neue', 'Arial', 'sans-serif' !important; + } + } + </style> + + <style type="text/css" media="only screen and (max-width: 480px)"> + /* Mobile styles */ + @media only screen and (max-width: 480px) { + + table[class*="container-for-gmail-android"] { + min-width: 290px !important; + width: 100% !important; + } + + img[class="force-width-gmail"] { + display: none !important; + width: 0 !important; + height: 0 !important; + } + + table[class="w320"] { + width: 320px !important; + } + + + td[class*="mobile-header-padding-left"] { + width: 160px !important; + padding-left: 0 !important; + } + + td[class*="mobile-header-padding-right"] { + width: 160px !important; + padding-right: 0 !important; + } + + td[class="header-lg"] { + font-size: 24px !important; + padding-bottom: 5px !important; + } + + td[class="content-padding"] { + padding: 5px 0 5px !important; + } + + td[class="button"] { + padding: 5px 5px 30px !important; + } + + td[class*="free-text"] { + padding: 10px 18px 30px !important; + } + + td[class~="mobile-hide-img"] { + display: none !important; + height: 0 !important; + width: 0 !important; + line-height: 0 !important; + } + + td[class~="item"] { + width: 140px !important; + vertical-align: top !important; + } + + td[class~="quantity"] { + width: 50px !important; + } + + td[class~="price"] { + width: 90px !important; + } + + td[class="item-table"] { + padding: 30px 20px !important; + } + + td[class="mini-container-left"], + td[class="mini-container-right"] { + padding: 0 15px 15px !important; + display: block !important; + width: 290px !important; + } + } + </style> +</head> + +<body bgcolor="#f7f7f7"> +<table align="center" cellpadding="0" cellspacing="0" class="container-for-gmail-android" width="100%"> + <tr> + <td align="left" valign="top" width="100%" style="background:repeat-x url(http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg) #ffffff;"> + <center> + <img src="http://s3.amazonaws.com/swu-filepicker/SBb2fQPrQ5ezxmqUTgCr_transparent.png" class="force-width-gmail"> + <table cellspacing="0" cellpadding="0" width="100%" bgcolor="#ffffff" background="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" style="background-color:transparent"> + <tr> + <td width="100%" height="80" valign="top" style="text-align: center; vertical-align:middle;"> + <!--[if gte mso 9]> + <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;height:80px; v-text-anchor:middle;"> + <v:fill type="tile" src="http://s3.amazonaws.com/swu-filepicker/4E687TRe69Ld95IDWyEg_bg_top_02.jpg" color="#ffffff" /> + <v:textbox inset="0,0,0,0"> + <![endif]--> + <center> + <!-- <table cellpadding="0" cellspacing="0" width="600" class="w320"> + <tr> + #if ($logo_url) --> + <!-- <td class="pull-left mobile-header-padding-left" style="vertical-align: middle;"> + <a href=""><img height="47" src='$logo_url' alt="logo"></a> + </td> + #end + </tr> + </table> --> + <a href="https://aurora-desk.idc.tarento.com/"><img width="50" height="60" src="https://aurora-desk-dev.s3.ap-south-1.amazonaws.com/aurora.png" alt="logo"></a> + </center> + <!--[if gte mso 9]> + </v:textbox> + </v:rect> + <![endif]--> + </td> + </tr> + </table> + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7;" class="content-padding"> + <center> + <p> Hi $firstName,</p> + <p>Status of your ticket <a href="https://aurora-desk.idc.tarento.com/desks/$HelpdeskId/tickets/"> $id </a> on helpdesk $helpdeskName is changed from $oldStatus to $newStatus. You may access ticket details using <a href="https://aurora-desk.idc.tarento.com/desks/$helpdeskId/tickets"> this link </a>.</p> + <p>Thank you!</p> + + </center> + </td> + </tr> + <tr> + <td align="center" valign="top" width="100%" style="background-color: #f7f7f7; height: 100px;"> + <center> + <table cellspacing="0" cellpadding="0" width="600" class="w320"> + <tr> + <td style="padding: 25px 0 25px"> + <strong>Aurora Helpdesk</strong><br /> + </td> + </tr> + </table> + </center> + </td> + </tr> +</table> +</div> +</body> +</html> diff --git a/public/images/9_IMG_5920.jpg b/public/images/9_IMG_5920.jpg new file mode 100644 index 0000000000000000000000000000000000000000..eb172585a2b99eaaa6cef55ffc0672e17f8f2343 Binary files /dev/null and b/public/images/9_IMG_5920.jpg differ diff --git a/src/main/java/org/upsmf/grievance/Application.java b/src/main/java/org/upsmf/grievance/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..1d4700e58df2c9fae1e1a014a704054ba0635333 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/Application.java @@ -0,0 +1,67 @@ +package org.upsmf.grievance; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +import org.upsmf.grievance.config.JwtAuthenticationFilter; +import org.upsmf.grievance.util.Constants; + +import javax.sql.DataSource; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurerAdapter() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods(Constants.GET, Constants.POST, Constants.PUT, + Constants.DELETE, Constants.OPTIONS).allowedOrigins("*").allowedHeaders("*"); + } + }; + } + + @Bean + public JwtAuthenticationFilter authenticationTokenFilterBean() { + return new JwtAuthenticationFilter(); + } + + @Bean + public BCryptPasswordEncoder encoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + @Bean + public TokenStore tokenStore() { + return new InMemoryTokenStore(); + } + + //@Bean + /*public JdbcTemplate jdbcTemplate(DataSource dataSource) { + return new JdbcTemplate(dataSource); + }*/ + +} diff --git a/src/main/java/org/upsmf/grievance/config/CORSFilter.java b/src/main/java/org/upsmf/grievance/config/CORSFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..4a1b018fa6fa4ce3cf58df118b2e61966f9db78b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/CORSFilter.java @@ -0,0 +1,46 @@ +package org.upsmf.grievance.config; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(0) +public class CORSFilter implements Filter { + + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) + throws IOException, ServletException { + HttpServletRequest request = (HttpServletRequest) req; + HttpServletResponse response = (HttpServletResponse) res; + response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); + response.setHeader("Access-Control-Allow-Credentials", "true"); + response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", + "X-Requested-With, Content-Type, Authorization, Origin, Accept, Access-Control-Request-Method, Access-Control-Request-Headers"); + + chain.doFilter(req, res); + } + + @Override + public void init(FilterConfig filterConfig) { + + } + + @Override + public void destroy() { + + } + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/config/JwtAuthenticationEntryPoint.java b/src/main/java/org/upsmf/grievance/config/JwtAuthenticationEntryPoint.java new file mode 100644 index 0000000000000000000000000000000000000000..ed1f266527671dbc85061d9ad5ca6e45ce971e12 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/JwtAuthenticationEntryPoint.java @@ -0,0 +1,31 @@ +package org.upsmf.grievance.config; + +import java.io.IOException; +import java.io.Serializable; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.stereotype.Component; + +@Component +public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public void commence(javax.servlet.http.HttpServletRequest httpServletRequest, + HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { + ServletContext ctx = httpServletRequest.getServletContext(); + if (!(Boolean) ctx.getAttribute("WhiteList")) { + httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/config/JwtAuthenticationFilter.java b/src/main/java/org/upsmf/grievance/config/JwtAuthenticationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..996f7da16fec331a51fa29c6f6d418c436d74501 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/JwtAuthenticationFilter.java @@ -0,0 +1,152 @@ +package org.upsmf.grievance.config; + +import static org.upsmf.grievance.util.Constants.HEADER_STRING; +import static org.upsmf.grievance.util.Constants.TOKEN_PREFIX; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.FilterChain; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.UserService; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.ResponseMessages; + +import io.jsonwebtoken.ExpiredJwtException; +import io.jsonwebtoken.SignatureException; + +public class JwtAuthenticationFilter extends OncePerRequestFilter { + + @Autowired + private UserService userService; + + @Autowired + private JwtTokenUtil jwtTokenUtil; + + @Value("${urls.whitelist}") + private String whitelistUrls; + + @Override + protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) + throws IOException, ServletException { + + + List<String> whitelistUrlList = Arrays.asList(whitelistUrls.split(",")); + + ServletContext ctx = req.getServletContext(); + Boolean whiteListed; + Boolean authorized = Boolean.FALSE; + String username = null; + String authToken = null; + UserDetails userDetails = null; + Map<String, Object> userInfoObectMap = new HashMap<>(); + + if (whitelistUrlList.contains(req.getRequestURI())) { + whiteListed = Boolean.TRUE; + } else { + whiteListed = Boolean.FALSE; + String header = req.getHeader(HEADER_STRING); + if (StringUtils.isBlank(header)) { + res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + res.getWriter() + .write(ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.UNAUTHORIZED_ACCESS)); + res.setContentType("application/json"); + res.getWriter().flush(); + return; + } + if (header.startsWith(TOKEN_PREFIX)) { + authToken = header.replace(TOKEN_PREFIX, ""); + username = getUserName(username, authToken); + } else { + logger.warn("couldn't find bearer string, will ignore the header"); + } + if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) { + userInfoObectMap = userService.getUserInfoObjects(username); + userDetails = (UserDetails) userInfoObectMap.get("UserDetails"); + if (jwtTokenUtil.validateToken(authToken, userDetails)) { + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( + userDetails, null, Arrays.asList(new SimpleGrantedAuthority("ROLE_ADMIN"))); + authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(req)); + logger.info("authenticated user " + username + ", setting security context"); + SecurityContextHolder.getContext().setAuthentication(authentication); + } + } + + + Boolean userTokenAvailable = userService.findUserByToken(authToken); + authorized = checkForAuthorization(req, ctx, authorized, userDetails, userInfoObectMap, userTokenAvailable); + } + + if (!authorized && !whiteListed) { + res.setStatus(HttpServletResponse.SC_FORBIDDEN); + res.getWriter() + .write(ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.INVALID_ACCESS_ROLE)); + res.setContentType("application/json"); + res.getWriter().flush(); + return; + } + + chain.doFilter(req, res); + } + + public String getUserName(String username, String authToken) { + try { + username = jwtTokenUtil.getUsernameFromToken(authToken); + } catch (IllegalArgumentException e) { + logger.error("an error occured during getting username from token", e); + } catch (ExpiredJwtException e) { + logger.warn("the token is expired and not valid anymore", e); + } catch (SignatureException e) { + logger.error("Authentication Failed. Username or Password not valid."); + } + return username; + } + + public Boolean checkForAuthorization(HttpServletRequest req, ServletContext ctx, Boolean authorized, + UserDetails userDetails, Map<String, Object> userInfoObectMap, Boolean userTokenAvailable) { + if (userTokenAvailable) { + try { + if (userDetails != null) { + User user = (User) userInfoObectMap.get("User"); + req.setAttribute("UserInfo", user); + ctx.setAttribute("UserInfo", user); + List<Long> roleIds = MasterDataManager.getRoleIdsForUserId(user.getId()); + for (Long roleId : roleIds) { + List<String> actionUrlList = MasterDataManager.getActionUrlsForRoleId(roleId); + if (actionUrlList.contains(req.getRequestURI())) { + ctx.setAttribute("Authorized", Boolean.TRUE); + authorized = Boolean.TRUE; + break; + } + } + } + } catch (UsernameNotFoundException e) { + e.getMessage(); + } + } + return authorized; + } +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/config/JwtTokenUtil.java b/src/main/java/org/upsmf/grievance/config/JwtTokenUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..9c3e54622bb4163ef977c7cfacefd74e80d6c22f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/JwtTokenUtil.java @@ -0,0 +1,109 @@ +package org.upsmf.grievance.config; + +import static org.upsmf.grievance.util.Constants.ACCESS_TOKEN_VALIDITY_SECONDS; +import static org.upsmf.grievance.util.Constants.JWT_GRANTED_AUTHORITY; +import static org.upsmf.grievance.util.Constants.JWT_ISSUER; +import static org.upsmf.grievance.util.Constants.SIGNING_KEY; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.function.Function; + +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.upsmf.grievance.dto.UserDto; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +@Component +public class JwtTokenUtil implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + public static final String CLAIMS_KEY = "scopes"; + public static final String USER_REF = "userReference"; + public static final String ORG_REF = "orgReference"; + + public String getUsernameFromToken(String token) { + return getClaimFromToken(token, Claims::getSubject); + } + + public Long getUserIdFromToken(String token) { + final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, + false); + MyCustomJwtClaims customClaims = null; + try { + customClaims = mapper.convertValue(getAllClaimsFromToken(token), MyCustomJwtClaims.class); + } catch (Exception e) { + e.getMessage(); + } + if (customClaims != null && customClaims.getUserReference() != null) { + return customClaims.getUserReference(); + } + return null; + } + + public Long getOrgIdFromToken(String token) { + final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, + false); + MyCustomJwtClaims customClaims = null; + try { + customClaims = mapper.convertValue(getAllClaimsFromToken(token), MyCustomJwtClaims.class); + } catch (Exception e) { + e.getMessage(); + } + if (customClaims != null && customClaims.getOrgReference() != null) { + return customClaims.getOrgReference(); + } + return null; + } + + public Date getExpirationDateFromToken(String token) { + return getClaimFromToken(token, Claims::getExpiration); + } + + public <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) { + final Claims claims = getAllClaimsFromToken(token); + return claimsResolver.apply(claims); + } + + private Claims getAllClaimsFromToken(String token) { + return Jwts.parser().setSigningKey(SIGNING_KEY).parseClaimsJws(token).getBody(); + } + + private Boolean isTokenExpired(String token) { + final Date expiration = getExpirationDateFromToken(token); + return expiration.before(new Date()); + } + + public String generateToken(UserDto user) { + return doGenerateToken(user.getUsername(), user.getId(), user.getOrgId()); + } + + private String doGenerateToken(String subject, Long userId, Long orgId) { + + Claims claims = Jwts.claims().setSubject(subject); + claims.put(CLAIMS_KEY, Arrays.asList(new SimpleGrantedAuthority(JWT_GRANTED_AUTHORITY))); + claims.put(USER_REF, userId); + claims.put(ORG_REF, orgId); + + return Jwts.builder().setClaims(claims).setIssuer(JWT_ISSUER).setIssuedAt(new Date(System.currentTimeMillis())) + .setExpiration(new Date(System.currentTimeMillis() + ACCESS_TOKEN_VALIDITY_SECONDS * 1000)) + .signWith(SignatureAlgorithm.HS256, SIGNING_KEY).compact(); + } + + public Boolean validateToken(String token, UserDetails userDetails) { + final String username = getUsernameFromToken(token); + return (username.equals(userDetails.getUsername()) && !isTokenExpired(token)); + } + +} diff --git a/src/main/java/org/upsmf/grievance/config/MyCustomJwtClaims.java b/src/main/java/org/upsmf/grievance/config/MyCustomJwtClaims.java new file mode 100644 index 0000000000000000000000000000000000000000..4c305b56c8154e130e462899e22e2ca547682347 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/MyCustomJwtClaims.java @@ -0,0 +1,32 @@ +package org.upsmf.grievance.config; + +public class MyCustomJwtClaims { + private String sub; + private Long userReference; + private Long orgReference; + + public String getSub() { + return sub; + } + + public void setSub(String sub) { + this.sub = sub; + } + + public Long getUserReference() { + return userReference; + } + + public void setUserReference(Long userReference) { + this.userReference = userReference; + } + + public Long getOrgReference() { + return orgReference; + } + + public void setOrgReference(Long orgReference) { + this.orgReference = orgReference; + } + +} diff --git a/src/main/java/org/upsmf/grievance/config/SwaggerConfig.java b/src/main/java/org/upsmf/grievance/config/SwaggerConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..8b4e39cc6b297a93ba13a8d1487895fb02809e30 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/SwaggerConfig.java @@ -0,0 +1 @@ +package org.upsmf.grievance.config; \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/config/WebSecurityConfig.java b/src/main/java/org/upsmf/grievance/config/WebSecurityConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..c74d33cf7247f5862b564c2ae516f0aa5c5bfddc --- /dev/null +++ b/src/main/java/org/upsmf/grievance/config/WebSecurityConfig.java @@ -0,0 +1,63 @@ +package org.upsmf.grievance.config; + +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Resource(name = "userService") + private UserDetailsService userDetailsService; + + @Autowired + private JwtAuthenticationEntryPoint unauthorizedHandler; + + @Value("${urls.whitelist}") + private String whiteListUrls; + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Autowired + public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService).passwordEncoder(encoder()); + } + + @Bean + public JwtAuthenticationFilter authenticationTokenFilterBean() { + return new JwtAuthenticationFilter(); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.cors().and().csrf().disable().authorizeRequests().antMatchers("/**").permitAll().anyRequest() + .authenticated().and().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); + http.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); + } + + @Bean + public BCryptPasswordEncoder encoder() { + return new BCryptPasswordEncoder(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/constants/RequestContextConstants.java b/src/main/java/org/upsmf/grievance/constants/RequestContextConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..55d5dc5168a20d544131ac65968e835dc1313997 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/constants/RequestContextConstants.java @@ -0,0 +1,25 @@ +package org.upsmf.grievance.constants; + +public class RequestContextConstants { + public static final String AUTH_BOOLEAN_FLAG_NAME = "shouldDoAuth"; + public static final String AUTH_TOKEN_KEY = "authToken"; + public static final String ERROR_MESSAGE_KEY = "error.message"; + public static final String ERROR_CODE_KEY = "error.status_code"; + public static final String GET = "GET"; + public static final String POST = "POST"; + public static final String FILESTORE_REGEX = "^/filestore/.*"; + public static final String REQUEST_INFO_FIELD_NAME_PASCAL_CASE = "RequestInfo"; + public static final String REQUEST_INFO_FIELD_NAME_CAMEL_CASE = "requestInfo"; + public static final String USER_INFO_FIELD_NAME = "userInfo"; + public static final String USER_INFO_KEY = "USER_INFO"; + public static final String CORRELATION_ID_FIELD_NAME = "correlationId"; + public static final String CORRELATION_ID_HEADER_NAME = "x-correlation-id"; + public static final String CORRELATION_ID_KEY = "CORRELATION_ID"; + public static final String RBAC_BOOLEAN_FLAG_NAME = "shouldDoRbac"; + public static final String SKIP_RBAC = "RBAC check skipped"; + public static final String RBAC_AVAILABLE = "RbacAvailable"; + + private RequestContextConstants() { + super(); + } +} diff --git a/src/main/java/org/upsmf/grievance/constants/package-info.java b/src/main/java/org/upsmf/grievance/constants/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..524b9897f2e3233967d2f970466da44e84da93bb --- /dev/null +++ b/src/main/java/org/upsmf/grievance/constants/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Juhi Agarwal + * + */ +package org.upsmf.grievance.constants; \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/controller/ApplicationController.java b/src/main/java/org/upsmf/grievance/controller/ApplicationController.java new file mode 100644 index 0000000000000000000000000000000000000000..76f633e7566859de6706905ef7cfa0b45d1b2e59 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/ApplicationController.java @@ -0,0 +1,132 @@ +package org.upsmf.grievance.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.ApplicationService; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.ResponseMessages; + +@RestController +@RequestMapping(PathRoutes.APPS_ACTIONS_URL) +public class ApplicationController { + + private static final String KEYWORD = "keyword"; + private static final String ID = "id"; + private static final String ORG_ID = "orgId"; + private static final String USER_INFO = "UserInfo"; + + public static final Logger LOGGER = LoggerFactory.getLogger(ApplicationController.class); + + @Autowired + private ApplicationService applicationService; + + @PostMapping(value = PathRoutes.AppsRoutes.CREATE_APP) + public String createUpdateApp(@RequestAttribute(value = USER_INFO) User user, @RequestBody App app, + BindingResult result) throws JsonProcessingException { + if (result.hasErrors()) { + return ResponseGenerator.failureResponse(HttpStatus.UNPROCESSABLE_ENTITY.toString()); + } + + if (app != null) { + if (StringUtils.isBlank(app.getName())) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_NAME_UNAVAILABLE); + } + } else { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_DETAILS_UNAVAILABLE); + } + user.setOrgId(app.getOrgId()); + App savedApp = applicationService.createApp(app, user); + if (savedApp != null) { + List<Object> savedApps = new ArrayList<>(); + savedApps.add(savedApp); + MasterDataManager.getAppObjectFromAppName(); + return ResponseGenerator.successResponse(savedApps); + } else { + return ResponseGenerator.failureResponse(HttpStatus.SERVICE_UNAVAILABLE.toString()); + } + } + + /** + * This method will return List of applications + * + * @param id + * Long + * @param keyword + * @param user + * User + * @return String + * @throws JsonProcessingException + */ + @GetMapping(value = PathRoutes.AppsRoutes.GET_APP) + public String getApp(@RequestParam(value = ID, required = false) Long id, + @RequestParam(value = KEYWORD, required = false) String keyword, + @RequestParam(value = ORG_ID, required = false) Long orgId, @RequestAttribute(value = USER_INFO) User user) + throws JsonProcessingException { + if (orgId != null) { + user.setOrgId(orgId); + } else { + user.setOrgId(null); + } + return ResponseGenerator.successResponse(applicationService.getApp(id, "", user)); + } + + @GetMapping(value = PathRoutes.AppsRoutes.GET_APP_BY_ORG_ID) + public String getAppByOrgId(@RequestParam(value = ORG_ID, required = false) Long orgId) + throws JsonProcessingException { + return ResponseGenerator.successResponse(applicationService.getApp(orgId)); + } + + /** + * This method will map an application to a helpdesk + * + * @param statusIdMap + * StatusIdMap + * @return String + * @throws JsonProcessingException + */ + @PostMapping(PathRoutes.AppsRoutes.MAP_APP_TO_HELPDESK) + public String mapAppsToHelpdesk(@RequestBody StatusIdMap statusIdMap) throws JsonProcessingException { + + boolean response = applicationService.mapAppsToHelpdesk(statusIdMap); + + if (response) { + return ResponseGenerator.successResponse(response); + } + + return ResponseGenerator.failureResponse(); + } + + /** + * This API will get the Master Data which has been maintained for the Service + * Request types available in the application + * + * @param user + * @return + * @throws JsonProcessingException + */ + @GetMapping(value = PathRoutes.AppsRoutes.GET_SERVICE_REQUEST) + public String getServiceRequests(@RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + return ResponseGenerator.successResponse(applicationService.getServiceRequests()); + } +} diff --git a/src/main/java/org/upsmf/grievance/controller/ControllerRequestValidator.java b/src/main/java/org/upsmf/grievance/controller/ControllerRequestValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..96dc0474942960c0012d2819e94dadeedd0313ea --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/ControllerRequestValidator.java @@ -0,0 +1,149 @@ + +package org.upsmf.grievance.controller; + +import java.util.List; + +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.exceptions.RequestDataMissingException; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.ProjectUtil; + +/** + * @author Juhi This class will validate controller request. + */ +public class ControllerRequestValidator { + /** + * This method will parse user registration data. + * + * @param user + * UserDto + * @return boolean + * @throws RequestDataMissingException + */ + public static boolean validateRegistrationData(User user) { + boolean response = true; + if (ProjectUtil.isStringNullOrEmpty(user.getUsername())) { + throw new RequestDataMissingException(Constants.USER_NAME_MISSING); + } else if (ProjectUtil.isStringNullOrEmpty(user.getName())) { + throw new RequestDataMissingException(Constants.PHONE_NUMBER_MISSING); + } + return response; + } + + /** + * This method will validate change password data + * + * @param passwordDto + * ChangePasswordDto + * @return boolean + * @throws RequestDataMissingException + */ + public static boolean changePassword(ChangePasswordDto passwordDto) { + boolean response = true; + if (ProjectUtil.isStringNullOrEmpty(passwordDto.getOldPass())) { + throw new RequestDataMissingException(Constants.PSWRD_MISSING); + } else if (ProjectUtil.isStringNullOrEmpty(passwordDto.getNewPass())) { + throw new RequestDataMissingException(Constants.PSWRD_MISSING); + } else if (!passwordDto.getNewPass().equals(passwordDto.getConfirmNewPass())) { + throw new RequestDataMissingException(Constants.PSWRD_MISMATCH); + } else if (passwordDto.getNewPass().equals(passwordDto.getOldPass())) { + throw new RequestDataMissingException(Constants.PSWRD_SAME); + } + return response; + } + + /** + * This method will validate incoming login request data + * + * @param userDto + * ChangePasswordDto + * @return boolean + * @throws RequestDataMissingException + */ + public static boolean login(UserDto userDto) { + boolean response = true; + if (ProjectUtil.isStringNullOrEmpty(userDto.getUsername())) { + throw new RequestDataMissingException(Constants.USER_NAME_MISSING); + } else if (ProjectUtil.isStringNullOrEmpty(userDto.getPassword())) { + throw new RequestDataMissingException(Constants.PSWRD_MISSING); + } + return response; + } + + public static boolean forgotPassword(UserDto userDto) { + boolean response = true; + if (ProjectUtil.isStringNullOrEmpty(userDto.getUsername())) { + throw new RequestDataMissingException(Constants.USER_NAME_MISSING); + } + return response; + } + + /** + * This method validates the user id. + * + * @param userDto + * UserDto + * @return UserDto + * @throws RequestDataMissingException + */ + public static UserDto validateInputId(UserDto userDto) { + if (userDto.getId() == 0L) { + throw new RequestDataMissingException(Constants.USER_NAME_MISSING); + } + return userDto; + } + + /** + * This method validates primary details of the user + * + * @param userDto + * UserDto + * @return boolean + * @throws RequestDataMissingException + */ + public static boolean validateUserPrimaryDetails(UserDto userDto) { + boolean response = true; + if (userDto.getId() == 0L) { + throw new RequestDataMissingException(Constants.ID_MISSING); + } + + User user = new User(); + user.setName(userDto.getName()); + user.setUsername(userDto.getUsername()); + validateRegistrationData(user); + + return response; + } + + /** + * This method validates primary details of the user + * + * @param userDto + * UserDto + * @return boolean + * @throws RequestDataMissingException + */ + public static boolean validateConfigureHelpdeskData(HelpdeskDto helpdeskDto) { + boolean response = true; + if (helpdeskDto.getTypes() != null && !helpdeskDto.getTypes().isEmpty()) { + List<HelpdeskTypeDto> typeDtoList = helpdeskDto.getTypes(); + for (HelpdeskTypeDto dto : typeDtoList) { + if (dto.getWorkflowStages() == null) { + throw new RequestDataMissingException(Constants.HELPDESKTYPE_WITHOUTWORKFLOW); + } else if (dto.getWorkflowStages().isEmpty()) { + throw new RequestDataMissingException(Constants.HELPDESKTYPE_WORKFLOW_EMPTY); + } + } + } + return response; + } + + private ControllerRequestValidator() { + super(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java b/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java new file mode 100644 index 0000000000000000000000000000000000000000..fabb171cea728b338984633612dc309b8a65b6e6 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/HelpdeskController.java @@ -0,0 +1,170 @@ +package org.upsmf.grievance.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.HelpdeskService; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.Sql; + +/** + * This controller will handle all the helpdesk related API's + * + * @author nivetha + * + */ +@RestController +@RequestMapping(PathRoutes.HELPDESK_URL) +public class HelpdeskController { + + private static final String ID = "id"; + private static final String USER_INFO = "UserInfo"; + private static final String USER_ID = "userId"; + @Autowired + private HelpdeskService helpdeskService; + + /** + * This method will add or update helpdesk of an organization + * + * @param helpdesk + * Helpdesk + * @param user + * User + * @return String + * @throws JsonProcessingException + */ + @PostMapping(PathRoutes.HelpdeskRoutes.CREATE_UPDATE_HELPDESK) + public String createUpdateHelpdesk(@RequestBody HelpdeskDto helpdeskDto, + @RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + + boolean response = helpdeskService.createUpdateHelpdesk(helpdeskDto, user); + + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + } + + /** + * This method gives all the active helpdesk of an organization + * + * @param user + * User + * @return String + * @throws JsonProcessingException + */ + @GetMapping(PathRoutes.HelpdeskRoutes.GET_HELPDESK) + public String getHelpdesk(@RequestParam(value = "orgId", required = true) Long orgId, + @RequestParam(value = USER_ID, required = false) Long userId, + @RequestAttribute(value = USER_INFO) User user, @RequestParam(value = ID, required = false) Long id) + throws JsonProcessingException { + List<HelpdeskDto> helpdesks; + List<HelpdeskDto> newHelpdesks = new ArrayList<>(); + if (id != null && id > 0) { + helpdesks = helpdeskService.getHelpdeskById(orgId, id); + return ResponseGenerator.successResponse(helpdesks); + } else { + helpdesks = helpdeskService.getHelpdesk(orgId); + } + try { + if (!ProjectUtil.isObjectNull(userId)) { + if (MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(userId)).getName() + .equalsIgnoreCase(Sql.Common.SUPER_ADMIN) + || MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(userId)).getName() + .equalsIgnoreCase(Sql.Common.ORGADMIN)) { + return ResponseGenerator.successResponse(helpdesks); + } else { + return ResponseGenerator.successResponse(checkIfHelpdeskEmpty(user, helpdesks, newHelpdesks)); + } + } else { + return ResponseGenerator.successResponse(checkIfHelpdeskEmpty(user, helpdesks, newHelpdesks)); + } + } catch (Exception e) { + return ResponseGenerator.failureResponse(); + } + } + + private List<HelpdeskDto> checkIfHelpdeskEmpty(User user, List<HelpdeskDto> helpdesks, + List<HelpdeskDto> newHelpdesks) { + helpdeskService.getHelpdeskAdminUser(helpdesks); + for (int i = 0; i < helpdesks.size(); i++) { + HelpdeskDto helpdeskDto = helpdesks.get(i); + List<Long> user2 = helpdeskDto.getAdmins().stream().map(User::getId).collect(Collectors.toList()); + List<Long> user3 = helpdeskDto.getUsers().stream().map(User::getId).collect(Collectors.toList()); + List<Long> combinedList = Stream.of(user2, user3).flatMap(x -> x.stream()).collect(Collectors.toList()); + for (Long u : combinedList) { + if (u.equals(user.getId()) && !newHelpdesks.contains(helpdeskDto)) { + newHelpdesks.add(helpdeskDto); + } + } + } + return newHelpdesks; + } + + /** + * This method sets up the configuration for a helpdesk + * + * @param user + * User + * @return String + * @throws JsonProcessingException + */ + @PostMapping(PathRoutes.HelpdeskRoutes.CONFIGURE_HELPDESK) + public String configureHelpdesk(@RequestBody HelpdeskDto helpdeskDto, + @RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + ControllerRequestValidator.validateConfigureHelpdeskData(helpdeskDto); + boolean response = helpdeskService.configureHelpdesk(helpdeskDto, user); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.HelpdeskRoutes.ADD_UPDATE_HELPDESK_ADMINS) + public String addUpdateHelpdeskAdmins(@RequestBody Helpdesk helpdesk, + @RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + boolean response = helpdeskService.addUpdateHelpdeskAdmins(helpdesk, user); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + } + + @GetMapping(PathRoutes.HelpdeskRoutes.GET_HELPDESK_ADMINS) + public String getHelpdeskAdmins(@RequestParam(value = ID, required = true) Long id) throws JsonProcessingException { + + List<Long> admins = helpdeskService.getHelpdeskAdmins(id); + + return ResponseGenerator.successResponse(admins); + } + + @GetMapping(PathRoutes.HelpdeskRoutes.GET_PERFORMANCE_WITH_ACCESSCONTROL) + public String getPerformanceApiWithAccessControl() throws JsonProcessingException { + return ResponseGenerator.successResponse("getPerformanceApiWithAccessControl"); + } + + @GetMapping(PathRoutes.HelpdeskRoutes.GET_PERFORMANCE_WITHOUT_ACCESSCONTROL) + public String getPerformanceApiWithoutAccessControl() throws JsonProcessingException { + return ResponseGenerator.successResponse("getPerformanceApiWithoutAccessControl"); + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/RoleActionController.java b/src/main/java/org/upsmf/grievance/controller/RoleActionController.java new file mode 100644 index 0000000000000000000000000000000000000000..3bbc218c01f4fdb21175aa19fa551d78050d0609 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/RoleActionController.java @@ -0,0 +1,123 @@ +package org.upsmf.grievance.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.RoleActionService; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.ResponseMessages; + +@RestController +@RequestMapping(PathRoutes.ROLE_ACTIONS_URL) +public class RoleActionController { + + private static final String ORG_ID = "orgId"; + private static final String USER_ID = "userId"; + private static final String USER_INFO = "UserInfo"; + + public static final Logger LOGGER = LoggerFactory.getLogger(RoleActionController.class); + + @Autowired + private RoleActionService roleActionService; + + @GetMapping(value = PathRoutes.RoleActionRoutes.LIST_ROLES_GET) + public String listRoles(@RequestParam(value = ORG_ID, required = true) Long orgId) throws JsonProcessingException { + List<Role> data = roleActionService.getAllRoles(orgId); + if (data != null) { + return ResponseGenerator.successResponse(data); + } else { + return ResponseGenerator.failureResponse(); + } + } + + @PostMapping(value = PathRoutes.RoleActionRoutes.ADD_ROLE_POST) + public String saveRole(@RequestAttribute(value = USER_INFO) User user, @RequestBody Role role, BindingResult result) + throws JsonProcessingException { + if (result.hasErrors()) { + return ResponseGenerator.failureResponse(HttpStatus.UNPROCESSABLE_ENTITY.toString()); + } + + if (role != null) { + if (StringUtils.isBlank(role.getName())) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_NAME_UNAVAILABLE); + } + } else { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_DETAILS_UNAVAILABLE); + } + role.setOrgId(user.getOrgId()); + Role savedRole = roleActionService.saveRole(role); + if (savedRole != null) { + List<Object> savedRoles = new ArrayList<>(); + savedRoles.add(savedRole); + return ResponseGenerator.successResponse(savedRoles); + } else { + return ResponseGenerator.failureResponse(HttpStatus.SERVICE_UNAVAILABLE.toString()); + } + } + + @PostMapping(value = PathRoutes.RoleActionRoutes.ROLE_BY_ID_GET) + public String getOne(@RequestAttribute(value = USER_INFO) User user, @RequestBody Role role, BindingResult result) + throws JsonProcessingException { + role.setOrgId(user.getOrgId()); + String roles = roleActionService.findById(role); + if (roles != null) { + return ResponseGenerator.successResponse(roles); + } else { + return ResponseGenerator.failureResponse("Couldn't fetch this role"); + } + } + + @PostMapping(value = PathRoutes.RoleActionRoutes.UPDATE_ROLE_POST) + public String update(@RequestAttribute(value = USER_INFO) User user, @RequestBody Role role, BindingResult result) + throws JsonProcessingException { + if (result.hasErrors()) { + return ResponseGenerator.failureResponse(HttpStatus.UNPROCESSABLE_ENTITY.toString()); + } + + if (role != null) { + if (role.getId() == null) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_ID_UNAVAILABLE); + } + if (StringUtils.isBlank(role.getName())) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_NAME_UNAVAILABLE); + } + if (role.getId() <= 0) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_ID_INVALID); + } + role.setOrgId(user.getOrgId()); + Role savedRole = roleActionService.updateRole(role); + if (savedRole != null) { + List<Object> savedRoles = new ArrayList<>(); + savedRoles.add(savedRole); + return ResponseGenerator.successResponse(savedRoles); + } + } + return ResponseGenerator.failureResponse(HttpStatus.SERVICE_UNAVAILABLE.toString()); + } + + @GetMapping(value = PathRoutes.RoleActionRoutes.MDM_CHECK) + public String mdmCheck(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = USER_ID, required = false) Long userId) { + return MasterDataManager.getRoleForUser(userId).toString(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/SuperAdminController.java b/src/main/java/org/upsmf/grievance/controller/SuperAdminController.java new file mode 100644 index 0000000000000000000000000000000000000000..a67e79963c92c68a287de60bd9f397d4df6c3945 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/SuperAdminController.java @@ -0,0 +1,140 @@ +package org.upsmf.grievance.controller; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.enums.AuthTypes; +import org.upsmf.grievance.service.SuperAdminService; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.ResponseMessages; + +@RestController +@RequestMapping(PathRoutes.SUPERADMIN_ACTIONS_URL) +public class SuperAdminController { + + private static final String USER_ID = "userId"; + private static final String ID = "id"; + private static final String USER_INFO = "UserInfo"; + @Autowired + private SuperAdminService superAdminService; + + @GetMapping(value = PathRoutes.SuperAdminRoutes.GET_ALL_ORG) + public String getAllOrganization(@RequestParam(value = ID, required = false) Long id, + @RequestParam(value = USER_ID, required = false) Long userId) throws JsonProcessingException { + List<Organization> orgList = new ArrayList<>(); + if (id != null && id > 0) { + Organization response = superAdminService.getOrganizationById(id); + orgList.add(response); + } else if (userId != null) { + List<Organization> response = superAdminService.getOrganizationByUserId(userId); + orgList = response; + } else { + orgList = superAdminService.getAllOrganization(); + } + if (!orgList.isEmpty()) { + return ResponseGenerator.successResponse(orgList); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.GETALLORG_FAILED); + } + + @PostMapping(value = PathRoutes.SuperAdminRoutes.ADD_ORGANIZATION) + public String addOrganization(@RequestBody Organization organization) throws JsonProcessingException { + Organization response = superAdminService.addOrganization(organization); + if (response != null) { + MasterDataManager.getAllOrgRoles(); + MasterDataManager.getUserIdAndUserName(); + MasterDataManager.getAllOrgUsers(); + MasterDataManager.getAllUserRoles(); + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ADD_ORG_FAILED); + } + + @PostMapping(value = PathRoutes.SuperAdminRoutes.DELETE_ORGANIZATION) + public String deleteOrganization(@RequestAttribute(value = USER_INFO) User user, + @RequestBody Organization organization) throws JsonProcessingException { + organization.setUserId(user.getId()); + boolean response = superAdminService.deleteOrganization(organization); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.DELETE_ORG_FAILED); + } + + @PostMapping(value = PathRoutes.SuperAdminRoutes.UPDATE_ORG_BY_ID) + public String updateOrganizationById(@RequestAttribute(value = USER_INFO) User user, + @RequestBody Organization organization) throws JsonProcessingException { + organization.setUserId(user.getId()); + boolean response = superAdminService.updateOrganizationById(organization); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.UPDATE_ORG_FAILED); + } + + @PostMapping(value = PathRoutes.SuperAdminRoutes.ADD_ADMIN) + public String addAdmin(@RequestAttribute(value = USER_INFO) User user, @RequestBody CommonDataModel commonDataModel) + throws JsonProcessingException { + boolean response = superAdminService.addAdmin(commonDataModel.getUserId()); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.UPDATE_ORG_FAILED); + } + + @PostMapping(value = PathRoutes.SuperAdminRoutes.REMOVE_ADMIN) + public String removeAdmin(@RequestAttribute(value = USER_INFO) User user, + @RequestBody CommonDataModel commonDataModel) throws JsonProcessingException { + boolean response = superAdminService.removeAdmin(commonDataModel.getUserId()); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.UPDATE_ORG_FAILED); + } + + /** + * This method will map an application to an organization + * + * @param statusIdMap + * StatusIdMap + * @return String + * @throws JsonProcessingException + */ + @PostMapping(PathRoutes.SuperAdminRoutes.MAP_APPS_TO_ORG) + public String mapAppsToOrg(@RequestBody StatusIdMap statusIdMap) throws JsonProcessingException { + + boolean response = superAdminService.mapAppsToOrg(statusIdMap); + + if (response) { + return ResponseGenerator.successResponse(response); + } + + return ResponseGenerator.failureResponse(); + } + + @GetMapping(value = PathRoutes.SuperAdminRoutes.GET_AUTH_TYPES) + public String getAuthTypes() throws JsonProcessingException { + final List<CommonDataModel> authTypes = new ArrayList<>(); + for (final AuthTypes key : AuthTypes.values()) { + authTypes.add(new CommonDataModel(key)); + } + return ResponseGenerator.successResponse(authTypes); + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/TagController.java b/src/main/java/org/upsmf/grievance/controller/TagController.java new file mode 100644 index 0000000000000000000000000000000000000000..ee6e26ea4a576985154762be39e7c94dcaf426d8 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/TagController.java @@ -0,0 +1,79 @@ +package org.upsmf.grievance.controller; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.dto.TicketTagDto; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.TicketsTagsList; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.TagService; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ResponseGenerator; + +@RestController +@RequestMapping(PathRoutes.TAGS_URL) +public class TagController { + + private static final String ID = "id"; + private static final String ORG_ID = "orgId"; + private static final String USER_INFO = "UserInfo"; + + public static final Logger LOGGER = LoggerFactory.getLogger(TagController.class); + + @Autowired + private TagService tagService; + + @PostMapping(value = PathRoutes.TagRoutes.CREATE_TAG) + public String createUpdateTag(@RequestAttribute(value = USER_INFO) User user, + @RequestBody TicketTagDto ticketTagDto) throws JsonProcessingException { + boolean saved = tagService.saveTags(ticketTagDto, user.getId()); + if (saved) { + return ResponseGenerator.successResponse(saved); + } + return ResponseGenerator.failureResponse(); + + } + + @GetMapping(value = PathRoutes.TagRoutes.GET_TAG_BY_ORG_ID) + public String getOrgTags(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = ORG_ID, required = true) Long orgId) throws JsonProcessingException { + TicketsTagsList tags = tagService.getAllOrgTags(orgId); + if (tags != null) { + return ResponseGenerator.successResponse(tags); + } + return ResponseGenerator.failureResponse(); + } + + @GetMapping(value = PathRoutes.TagRoutes.GET_TAG_BY_HELPDESK_ID) + public String getHelpdeskTags(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = ID, required = true) Long id) throws JsonProcessingException { + TicketsTagsList tags = tagService.getHelpdeskTags(id, user.getId()); + if (tags.getTags() != null) { + return ResponseGenerator.successResponse(tags); + } + return ResponseGenerator.failureResponse(); + } + + @GetMapping(value = PathRoutes.TagRoutes.GET_ALL_TICKET_TAGS) + public String getAllTicketTags(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = ID, required = true) Long id) throws JsonProcessingException { + List<Tags> response = tagService.getAllTicketTags(id); + if (response != null) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/TicketController.java b/src/main/java/org/upsmf/grievance/controller/TicketController.java new file mode 100644 index 0000000000000000000000000000000000000000..ecad792709c9f719bd3d6362bd21e59968769f23 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/TicketController.java @@ -0,0 +1,319 @@ +package org.upsmf.grievance.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Analytics; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.TemplateVersion; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketCount; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.enums.PriorityLevels; +import org.upsmf.grievance.service.TicketService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ResponseGenerator; + +/** + * This controller contains all the ticket related methods + * + * @author Juhi Agarwal + * + */ +@RestController +@RequestMapping(PathRoutes.TICKET_ACTIONS_URL) +public class TicketController { + + private static final String ID = "id"; + + private static final String USER_INFO = "UserInfo"; + + @Autowired + private TicketService ticketService; + + @Autowired + private HelpdeskDao helpdeskDao; + + @PostMapping(PathRoutes.TicketRoutes.ADD_TICKET) + public String addTicket(@RequestAttribute(value = USER_INFO) User user, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket = ticketService.addTicket(ticket); + if (ticket != null) { + return ResponseGenerator.successResponse(ticket); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.UPLOAD_ATTACHMENT) + public String uploadAttachment(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = "file", required = false) MultipartFile file, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setUserId(user.getId()); + ticket.setOrgId(user.getOrgId()); + boolean response = ticketService.attachmentUpload(file, ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.UPDATE_TICKET_BASIC) + public String updateTicketBasic(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = "file", required = false) MultipartFile file, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setOrgId(user.getOrgId()); + ticket.setUserId(user.getId()); + boolean response = false; + response = ticketService.updateTicketBasic(file, ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.PINNED_TICKET) + public String pinTicket(@RequestAttribute(value = USER_INFO) User user, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setOrgId(user.getOrgId()); + ticket.setUserId(user.getId()); + boolean response = false; + response = ticketService.pinTicket(ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.UPDATE_TICKET_TYPE) + public String updateTicketType(@RequestAttribute(value = USER_INFO) User user, + @RequestBody TicketTypeDto ticketTypeDto) throws JsonProcessingException { + ticketTypeDto.setOrgId(user.getOrgId()); + boolean response = ticketService.updateTicketType(ticketTypeDto, user.getId()); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.UPDATE_TICKET_STATUS) + public String updateTicketStatus(@RequestAttribute(value = USER_INFO) User user, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setRequestedBy(user.getId()); + ticket.setOrgId(user.getOrgId()); + boolean response = ticketService.updateTicketStatus(ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.UPDATE_TICKET_CHECKLIST) + public String updateTicketChecklist(@RequestAttribute(value = USER_INFO) User user, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setOrgId(user.getOrgId()); + boolean response = ticketService.updateTicketChecklist(ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @GetMapping(PathRoutes.TicketRoutes.GET_ALL_TICKETS) + public String getTickets(@RequestAttribute(value = Constants.RequestParams.USER_INFO) User user, + @RequestParam(value = Constants.RequestParams.ID, required = false) Long id, + @RequestParam(value = Constants.RequestParams.APP_ID, required = false) Long appId) + throws JsonProcessingException { + if (id != null && id > 0) { + Ticket tickets = ticketService.getTicketsById(user, id); + return ResponseGenerator.successResponse(tickets); + } else if (appId != null && appId > 0) { + List<Ticket> tickets = ticketService.getAllTicketsByAppId(appId); + return ResponseGenerator.successResponse(tickets); + } else { + List<Ticket> tickets = ticketService.getAllTicketsByUserId(user.getId()); + return ResponseGenerator.successResponse(tickets); + } + } + + @PostMapping(PathRoutes.TicketRoutes.GET_ALL_TICKETS) + public String getTicketDetailsByHelpdeskId(@RequestAttribute(value = USER_INFO) User user, + @RequestBody Ticket ticket) throws JsonProcessingException { + ticket.setUserId(user.getId()); + if (ticket.getHelpdeskId() != null && ticket.getHelpdeskId() > 0) { + List<TicketElastic> data = ticketService.getTicketDetailsByHelpdeskId(ticket); + return ResponseGenerator.successResponse(data); + } + return ResponseGenerator.failureResponse(); + } + + @PostMapping(PathRoutes.TicketRoutes.GET_TICKET_COUNT_PER_MONTH_PER_USER) + public String getTicketsCountPerMonthPerUser(@RequestAttribute(value = USER_INFO) User user, + @RequestBody Analytics analytics) throws JsonProcessingException { + analytics.setUserId(user.getId()); + if (analytics.getStartDate() != null && analytics.getEndDate() != null && !analytics.getStartDate().isEmpty() + && !analytics.getEndDate().isEmpty()) { + Map<String, Long> data = ticketService.getTicketsCountPerMonthPerUser(analytics); + return ResponseGenerator.successResponse(data); + } + return ResponseGenerator.failureResponse(); + } + + @PostMapping(PathRoutes.TicketRoutes.GET_FEEDBACK_FROM_AURORA_SDK) + public String getFeedBacksFromAuroraSdk(@RequestAttribute(value = USER_INFO) User user) + throws JsonProcessingException { + List<Ticket> tickets = ticketService.getFeedBacksFromAuroraSdk(); + if (tickets != null) { + return ResponseGenerator.successResponse(tickets); + } + return ResponseGenerator.failureResponse(); + + } + + @GetMapping(PathRoutes.TicketRoutes.GET_ACTIVITY_LOGS) + public String getActivityLogsPerTicket(@RequestParam(value = ID, required = true) Long id) + throws JsonProcessingException { + List<ActivityLog> activityLog = ticketService.getActivityLogsPerTicket(id); + if (activityLog != null) { + return ResponseGenerator.successResponse(activityLog); + } + return ResponseGenerator.failureResponse(); + } + + @GetMapping(PathRoutes.TicketRoutes.GET_ACTIVITY_LOGS_PER_USER) + public String getActivityLogsPerUser(@RequestAttribute(value = USER_INFO) User user) + throws JsonProcessingException { + List<ActivityLog> activityLog = ticketService.getActivityLogsPerUser(user.getId()); + if (activityLog != null) { + return ResponseGenerator.successResponse(activityLog); + } + return ResponseGenerator.failureResponse(); + } + + @PostMapping(PathRoutes.TicketRoutes.ADD_NOTES) + public String updateNotesToTicket(@RequestAttribute(value = USER_INFO) User user, @RequestBody Ticket ticket) + throws JsonProcessingException { + ticket.setRequestedBy(user.getId()); + boolean response = ticketService.updateNotesToTicket(ticket); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + + @PostMapping(PathRoutes.TicketRoutes.ADD_UPDATE_UPDATES) + public String addUpdateUpdatesToTicket(@RequestAttribute(value = USER_INFO) User user, @RequestBody Updates updates) + throws JsonProcessingException { + Long id = user.getId(); + updates.setCreatedBy(id); + List<Ticket> ticketList = new ArrayList<>(); + Ticket ticket = ticketService.getTicketsById(user, updates.getTicketId()); + List<Long> admins = helpdeskDao.getHelpdeskAdmins(ticket.getHelpdeskId()); + Boolean admin = false; + if (admins.contains(id)) { + admin = true; + } + ticketList.add(ticket); + List<Ticket> tickets = ticketService.keepOnlyCreatedAndCopiedToTickets(id, ticketList); + if (tickets != null && !tickets.isEmpty() || admin) { + boolean response = ticketService.addUpdateUpdatesToTicket(updates); + if (response) { + return ResponseGenerator.successResponse(response); + } + } + return ResponseGenerator.failureResponse(); + + } + + @GetMapping(PathRoutes.TicketRoutes.GET_UPDATES) + public String getUpdatesForTicket(@RequestParam(value = ID, required = true) Long id) + throws JsonProcessingException { + List<Updates> update = ticketService.getUpdatesForTicket(id); + if (update != null) { + return ResponseGenerator.successResponse(update); + } + return ResponseGenerator.failureResponse(); + } + + @GetMapping(value = PathRoutes.TicketRoutes.GET_PRIORITY_LEVELS) + public String getPriorityLevels(@RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + final List<CommonDataModel> priorityList = new ArrayList<>(); + for (final PriorityLevels key : PriorityLevels.values()) { + priorityList.add(new CommonDataModel(key)); + } + return ResponseGenerator.successResponse(priorityList); + } + + @GetMapping(value = PathRoutes.TicketRoutes.GET_TEMPLATES_VERSION) + public String getTemplatesVersion(@RequestAttribute(value = USER_INFO, required = false) User user) + throws JsonProcessingException { + Long version = ticketService.getTemplatesVersion(); + TemplateVersion templateVersion = new TemplateVersion(); + templateVersion.setTemplates(null); + templateVersion.setVersion(version); + return ResponseGenerator.successResponse(templateVersion); + } + + @GetMapping(value = PathRoutes.TicketRoutes.GET_TEMPLATES) + public String getTemplates(@RequestAttribute(value = USER_INFO, required = false) User user) + throws JsonProcessingException { + TemplateVersion templateVersion = ticketService.getTemplates(); + return ResponseGenerator.successResponse(templateVersion); + } + + @GetMapping(value = PathRoutes.TicketRoutes.GET_NO_OF_TICKETS) + public String getNoOfTicketsPerUser(@RequestAttribute(value = USER_INFO, required = false) User user) + throws JsonProcessingException { + TicketCount tc = ticketService.getNoOfTickets(user.getId()); + return ResponseGenerator.successResponse(tc); + } + + @PostMapping(PathRoutes.TicketRoutes.CONFIGURE_TEMPLATE) + public String configureTemplates(@RequestBody TemplateVersion templateVersion, + @RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + boolean response = ticketService.configureTemplates(templateVersion); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + } + + @PostMapping(PathRoutes.TicketRoutes.SEND_REPLY_TO_REVIEWS) + public String sendRepliesToReviews(@RequestAttribute(value = USER_INFO) User user, @RequestBody Updates updates) + throws JsonProcessingException { + Long id = user.getId(); + updates.setCreatedBy(id); + boolean response = ticketService.sendRepliesToReviews(updates); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(); + + } + +} diff --git a/src/main/java/org/upsmf/grievance/controller/UserController.java b/src/main/java/org/upsmf/grievance/controller/UserController.java new file mode 100644 index 0000000000000000000000000000000000000000..7529be751e95975e5222630456fb2c967e4eb9be --- /dev/null +++ b/src/main/java/org/upsmf/grievance/controller/UserController.java @@ -0,0 +1,194 @@ +package org.upsmf.grievance.controller; + +import java.io.IOException; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.LoginDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.RolesDto; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.UserService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.PathRoutes; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.ResponseGenerator; +import org.upsmf.grievance.util.ResponseMessages; +import org.upsmf.grievance.util.Sql; + +@RestController +@RequestMapping(PathRoutes.USER_ACTIONS_URL) +public class UserController { + + private static final String BEARER = "Bearer "; + private static final String FILE2 = "file"; + private static final String ID = "id"; + private static final String ORG_ID = "orgId"; + private static final String USER_INFO = "UserInfo"; + + public static final Logger LOGGER = LoggerFactory.getLogger(UserController.class); + + @Autowired + private UserService userService; + + @PostMapping(value = PathRoutes.UserRoutes.USER_ACTIONS_POST) + public String getActions(@RequestBody RolesDto roles) throws JsonProcessingException { + List<Action> actions = userService.findAllActionsByRoleID(roles.getIds()); + return ResponseGenerator.successResponse(actions); + } + + @PostMapping(value = PathRoutes.UserRoutes.NUMBER_OF_USERS_GET) + public String getNumberOfUsers(@RequestBody RolesDto roles) throws JsonProcessingException { + return ResponseGenerator.successResponse(userService.getNumberOfUsers(roles.getId(), roles.isActive())); + } + + @GetMapping(value = PathRoutes.UserRoutes.NUMBER_OF_ROLES_GET) + public String getNumberOfRoles() throws JsonProcessingException { + return ResponseGenerator.successResponse(userService.getNumberOfRoles()); + } + + @GetMapping(value = PathRoutes.UserRoutes.USER_BY_ID_GET) + public String getOne(@RequestParam(value = ID, required = true) Long id) throws JsonProcessingException { + return ResponseGenerator.successResponse(userService.findById(id)); + } + + @GetMapping(value = PathRoutes.UserRoutes.LIST_USER_GET) + public String listUser(@RequestParam(value = ORG_ID, required = true) Long orgId) throws JsonProcessingException { + return ResponseGenerator.successResponse(userService.findAll(orgId)); + } + + @GetMapping(value = PathRoutes.UserRoutes.UPLOAD_PROFILE_PICTURE) + public String uploadProfilePicture(@RequestParam(value = FILE2, required = true) MultipartFile file, + @RequestAttribute(value = USER_INFO) User user) throws JsonProcessingException { + return ResponseGenerator.successResponse(userService.uploadFile(file, user.getId())); + } + + @GetMapping(value = PathRoutes.UserRoutes.GET_PROFILE_PICTURE) + public String getProfilePicture(@RequestAttribute(value = USER_INFO) User user) throws IOException { + return ResponseGenerator.successResponse(userService.getFile(user.getId())); + } + + @PostMapping(value = PathRoutes.UserRoutes.CREATE_UPDATE_USER_POST) + public String saveUser(@RequestAttribute(value = USER_INFO) User user, + @RequestParam(value = FILE2, required = false) MultipartFile file, @RequestBody User profile) + throws JsonProcessingException { + if (!StringUtils.isNotBlank(profile.getUsername())) { + ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.EMAIL_MANDATORY); + } + ControllerRequestValidator.validateRegistrationData(profile); + Long userId = userService.checkUserNameExists(profile.getUsername()); + if (!ProjectUtil.isObjectNull(profile.getId())) { + if (userId.equals(profile.getId())) { + return ResponseGenerator.successResponse(userService.update(file, profile)); + } else { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.EMAIL_PHONE_ALREADY_EXISTS); + } + } else if (userId > 0) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.EMAIL_PHONE_ALREADY_EXISTS); + } + String name = MasterDataManager.getRoleMap().get(MasterDataManager.getUserRoleMap().get(user.getId())) + .getName(); + if (userId == 0 + && (name.equalsIgnoreCase(Sql.Common.SUPER_ADMIN) || name.equalsIgnoreCase(Sql.Common.ORGADMIN))) { + User isAdded = userService.save(file, user.getId(), profile); + if (isAdded != null) { + MasterDataManager.getAllOrgUsers(); + MasterDataManager.getAllUserRoles(); + return ResponseGenerator.successResponse(isAdded); + } + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.USER_PROFILE_SAVE_FAILURE); + } + + @PostMapping(value = PathRoutes.UserRoutes.LOGIN) + public String login(@RequestBody UserDto userDto) throws JsonProcessingException { + ControllerRequestValidator.login(userDto); + LoginDto response = userService.login(userDto); + if (response != null) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.LOGIN_FAILED); + } + + @PostMapping(value = PathRoutes.UserRoutes.FORGOT_PSWRD) + public String forgotPassword(@RequestBody UserDto userDto) throws JsonProcessingException { + ControllerRequestValidator.forgotPassword(userDto); + boolean forgotPasswordResponse = userService.forgotPassword(userDto); + + if (forgotPasswordResponse) { + return ResponseGenerator.successResponse(forgotPasswordResponse); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.FORGOT_PSWRD_FAILED); + } + + @PostMapping(value = PathRoutes.UserRoutes.CHANGE_PSWRD) + public String changePassword(@RequestAttribute(value = USER_INFO) User user, + @RequestBody ChangePasswordDto changePasswordDto) throws JsonProcessingException { + ControllerRequestValidator.changePassword(changePasswordDto); + changePasswordDto.setUserId(user.getId()); + boolean response = userService.changePassword(changePasswordDto); + if (response) { + return ResponseGenerator.successResponse(response); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.CHANGE_PSWRD_FAILED); + } + + @PostMapping(value = PathRoutes.UserRoutes.USER_ROLE_MAPPING_POST) + public String mapUserToRole(@RequestBody User user) throws JsonProcessingException { + if (user != null && user.getRoles() != null) { + if (user.getRoles().isEmpty()) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_ID_UNAVAILABLE); + } + if (user.getId() == null) { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.USER_ID_UNAVAILABLE); + } + } else { + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.ROLE_DETAILS_UNAVAILABLE); + } + Boolean mappingStatus = userService.mapUserToRole(user); + if (mappingStatus) { + return ResponseGenerator.successResponse(ResponseMessages.SuccessMessages.USER_ROLE_MAPPED); + } else { + return ResponseGenerator.failureResponse(HttpStatus.SERVICE_UNAVAILABLE.toString()); + } + } + + @GetMapping(value = PathRoutes.UserRoutes.LOGOUT_GET) + public String invalidateToken(@RequestHeader(value = Constants.AUTH_HEADER) String authToken) + throws JsonProcessingException { + Boolean status = false; + if (authToken != null) { + authToken = authToken.replace(BEARER, ""); + status = userService.invalidateToken(authToken); + } + if (status) { + return ResponseGenerator.successResponse(ResponseMessages.SuccessMessages.LOGOUT_SUCCESS); + } + return ResponseGenerator.failureResponse(ResponseMessages.ErrorMessages.LOGOUT_FAILED); + } + + @GetMapping(value = PathRoutes.UserRoutes.GET_REVIEWS) + public String getReviews(@RequestAttribute(value = USER_INFO) User user) throws IOException { + userService.getReviews(); + return ResponseGenerator.successResponse(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/dao/ApplicationDao.java b/src/main/java/org/upsmf/grievance/dao/ApplicationDao.java new file mode 100644 index 0000000000000000000000000000000000000000..5ea2ec70bd63d8777c63241ba91c5d0b6c0625e9 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/ApplicationDao.java @@ -0,0 +1,64 @@ +package org.upsmf.grievance.dao; + +import java.util.List; + +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; + +public interface ApplicationDao { + + public App createApp(App app, User user); + + /** + * This method will return an application information + * + * @param id + * Long + * @param orgId + * Long + * @return List<App> + */ + public List<App> getApp(Long id); + + /** + * This method will return all the applications + * + * @return List<App> + */ + public List<App> getAllApps(); + + /** + * This method will return applications assigned to an org + * + * @param orgId + * Long + * @return List<App> + */ + public List<App> getAppsByOrgId(Long orgId); + + /** + * This method will map an application to a helpdesk + * + * @param statusIdMap + * StatusIdMap + * @return boolean + */ + public boolean mapAppsToHelpdesk(StatusIdMap statusIdMap); + + /** + * This method will fetch the available Service Requests from the database and + * map it to a list of Service Request Objects and returns to the Service Layer + * + * @return List<ServiceRequest> + */ + public List<ServiceRequest> getServiceRequests(); + + public List<App> getAppIdAndAppObject(); + + App updateApp(App app, User user); + + List<String> getDistinctAppNames(Long orgId); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/HelpdeskDao.java b/src/main/java/org/upsmf/grievance/dao/HelpdeskDao.java new file mode 100644 index 0000000000000000000000000000000000000000..b412dd7b33281310ea1d3e128f5e88ca23cef8fe --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/HelpdeskDao.java @@ -0,0 +1,66 @@ +package org.upsmf.grievance.dao; + +import java.util.List; + +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; + +public interface HelpdeskDao { + + /** + * This method will add or update helpdesk of an organization + * + * @param helpdesk + * Helpdesk + * @return boolean + */ + boolean createUpdateHelpdesk(Helpdesk app); + + /** + * This method gives all the active helpdesk of an organization + * + * @param orgId + * Long + * @return List<Helpdesk> + */ + Boolean deleteWorkflowForHelpdeskType(Long typeId); + + Boolean deleteChecklistForHelpdeskType(Long helpdeskId, Long typeId); + + Boolean deleteTypeForHelpdesk(Long helpdeskId); + + Boolean addTypeForHelpdesk(HelpdeskTypeDto helpdeskTypeDto, Long helpdeskId); + + Boolean addChecklistForHelpdeskType(HelpdeskTypeDto helpdeskTypeDto, Long helpdeskId); + + Boolean addWorkflowForHelpdeskType(HelpdeskTypeDto helpdeskTypeDto); + + List<Long> getHelpdeskAdmins(Long id); + + boolean addUpdateHelpdeskAdmins(Helpdesk helpdesk); + + List<HelpdeskDto> getAllHelpdesks(Long orgId); + + HelpdeskRowRecordMapper getHelpdeskForId(Long orgId, Long id); + + List<ChecklistItem> getChecklistItemsForHelpdesk(Long helpdeskId, Long typeId); + + List<HelpDeskApp> getAppIdAndHelpDeskId(); + + public List<Helpdesk> getHelpdeskObjectFromHelpdeskId(); + + boolean addUpdateHelpdeskUsers(Helpdesk helpdesk); + + List<User> getAdminForHelpeskId(Long helpdeskId); + + List<User> getUsersForHelpeskId(Long helpdeskId); + + List<HelpdeskDto> getHelpdeskAdminUser(List<HelpdeskDto> helpdeskList); + + List<Helpdesk> getHelpdeskByUserId(Long userId); +} diff --git a/src/main/java/org/upsmf/grievance/dao/RoleDao.java b/src/main/java/org/upsmf/grievance/dao/RoleDao.java new file mode 100644 index 0000000000000000000000000000000000000000..8a39342e6a55dc8826054a320777d2eaec1a10ab --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/RoleDao.java @@ -0,0 +1,51 @@ +package org.upsmf.grievance.dao; + +import java.util.List; +import java.util.Map; + +import org.upsmf.grievance.model.Role; + +public interface RoleDao { + /** + * This method hits the DB and fetches all the available active roles + * + * @param fetchData + * @return + */ + public List<Role> getAllRoles(Long orgId); + + /** + * This method is used to save the Role Details in the Database + * + * @param role + * @return + */ + public Role saveRole(Role role); + + /** + * This method is used to update the Role Details based on the Role ID passed in + * the Role Object + * + * @param role + * @return + */ + public Role updateRole(Role role); + + /** + * This method supplies the ID to Database and fetches the Role for the ID and + * returns the Role Object + * + * @param role + * @return + */ + public String findById(Role role); + + public List<Role> getAllOrgRoles(); + + public void initializeActions(); + + public void intializeRolesAndActions(); + + public Map<Long, List<String>> getAllActionsForRoles(List<Long> roleIds); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/SuperAdminDao.java b/src/main/java/org/upsmf/grievance/dao/SuperAdminDao.java new file mode 100644 index 0000000000000000000000000000000000000000..054269ff119132e4f287b5d1162d37952f3e9fac --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/SuperAdminDao.java @@ -0,0 +1,38 @@ +package org.upsmf.grievance.dao; + +import java.util.List; + +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; + +public interface SuperAdminDao { + + List<Organization> getAllOrganization(); + + Organization addOrganization(Organization organization); + + boolean updateOrganizationById(Organization organization); + + boolean deleteOrganization(Organization organization); + + int getOrganizationByUserId(long authUserId); + + boolean mapUserToOrg(long userId, int organisationId); + + boolean addAdmin(long userId); + + boolean removeAdmin(long userId); + + User userDetailsByUserId(long userId); + + boolean mapAppsToOrg(StatusIdMap statusIdMap); + + List<Organization> getOrganizationByUser(Long userId); + + S3Config getS3Access(); + + Organization getOrganizationByIdV2(Long id); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/TagDao.java b/src/main/java/org/upsmf/grievance/dao/TagDao.java new file mode 100644 index 0000000000000000000000000000000000000000..4f4ff68ecce1642816b479299ca90ca6fb8f41bb --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/TagDao.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.dao; + +import java.util.List; + +import org.upsmf.grievance.model.Tags; + +public interface TagDao { + + List<Tags> getAllTags(Long orgId); + + Tags getTagByName(String trim, Long id); + + Long addTag(Long id, Tags tag); + + boolean addTicketTags(Long id, List<Tags> tags); + + List<Tags> getAllTicketTags(Long id); + + List<Tags> getHelpdeskTags(Long id, Long userId); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/TicketDao.java b/src/main/java/org/upsmf/grievance/dao/TicketDao.java new file mode 100644 index 0000000000000000000000000000000000000000..dfed0c3168f5ffc5739211621d6a835ea81e713a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/TicketDao.java @@ -0,0 +1,84 @@ +package org.upsmf.grievance.dao; + +import java.util.List; +import java.util.Map; + +import org.springframework.web.multipart.MultipartFile; + +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.dto.TicketWorkflowDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Analytics; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketCount; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; + +/** + * This interface contains all the ticket related dao + * + * @author Juhi Agarwal + * + */ +public interface TicketDao { + + Ticket addTicket(Ticket ticket); + + Long getTemplatesVersion(); + + boolean updateTemplateVersion(Long versionTimeStamp); + + Boolean updateNotesToTicket(Long requestedBy, Long ticketId, String notes); + + Boolean addUpdateUpdatesToTicket(Updates update); + + Boolean deleteWorkflowForTicketType(Long typeId); + + Boolean addChecklistForTicketType(TicketTypeDto ticketTypeDto); + + boolean updateTicketBasic(MultipartFile file, Ticket ticket); + + Ticket getTicketsById(Long userId, Long id); + + List<ChecklistItem> getChecklistItemsForTicket(Long ticketId); + + List<Ticket> getAllTicketsByAppId(Long appId); + + List<TicketWorkflowDto> getWorkflowForTicket(Long ticketId); + + List<Updates> getUpdatesForTicket(Long id); + + boolean updateTicketType(TicketTypeDto ticketTypeDto, Long userId); + + boolean updateTicketStatus(Ticket ticket); + + boolean updateTicketChecklist(Ticket ticket); + + Boolean deleteChecklistForTicketType(TicketTypeDto ticketTypeDto); + + String addDefaultWorkflowForTicketType(TicketTypeDto ticketTypeDto); + + List<ActivityLog> getActivityLogsPerTicket(Long id); + + List<Ticket> getAllTicketsByUserId(Long id); + + List<TicketElastic> getTicketDetailsByHelpdeskId(Ticket ticket); + + boolean pinTicket(Ticket ticket); + + TicketCount getNoOfTickets(Long userId); + + List<ActivityLog> getActivityLogsPerUser(Long id); + + Map<String, Long> getTicketsCountPerMonthPerUser(Analytics analytics); + + boolean attachmentUpload(MultipartFile file, Ticket ticket); + + List<Ticket> keepOnlyCreatedAndCopiedToTickets(Long userId, List<Ticket> ticketList); + + List<Ticket> getFeedBacksFromAuroraSdk(); + + boolean sendRepliesToReviews(Updates updates); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/UserDao.java b/src/main/java/org/upsmf/grievance/dao/UserDao.java new file mode 100644 index 0000000000000000000000000000000000000000..0dc95d6c70ea977c99c76578530d53b831cd369f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/UserDao.java @@ -0,0 +1,188 @@ +package org.upsmf.grievance.dao; + +import java.io.IOException; +import java.util.List; + +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.LoginDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.UserAuthentication; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserDetailsMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserRoleMapper; + +public interface UserDao { + + /** + * This method is used to fetch the User high level Object from the database + * based on the username parameter which is being passed + * + * @param username + * @return + */ + public User findByUsername(String username, Boolean withRoles, Boolean withActions); + + /** + * This method is used to fetch the User Detailed object from the database based + * on the User ID which is being passed + * + * @param id + * @return + */ + public List<User> findOne(Long id); + + /** + * This method receives the User ID and the List of Roles which are associated + * with the user Save the same to database for further Role Based Access + * + * @param list + * @param userId + * + * @param userRole + * @return + */ + public Boolean mapUserToRole(long userId, List<Role> list); + + /** + * This method receives the User Profile Object with updated Image URL and + * updates the same against the User ID + * + * @param profile + * @return + */ + public User updateUserImage(User profile); + + /** + * While adding a new user to the system, this method is called with Email ID + * and Phone Number to verify whether there already exists a user with same + * username as that of the Email ID and Phone Number This method responds with a + * long value of the User ID if exists and returns 0 in the case of negative + * scenario + * + * @param emailId + * @param phoneNo + * @return + */ + public Long checkUserNameExists(String username); + + /** + * On receiving the Role ID, this method fetches the Actions which are mapped to + * that role + * + * @param roleID + * @return + */ + public List<Action> findAllActionsByRoleID(Integer roleID); + + /** + * In order to show the count of Users available in the system, this method is + * invoked The method responds with the count of users available in the system + * + * @return + */ + public Long getNumberOfUsers(Long role, Boolean active); + + /** + * In order to show the count of Roles available in the system, this method is + * invoked The method responds with the count of roles available in the system + * + * @return + */ + public Long getNumberOfRoles(); + + /** + * This method receives the JWT Auth Token and invalidates the token from the + * Jwt Token Store and also removes the entry of the Token from the Database + * + * @param authToken + * @return + */ + public Boolean invalidateToken(String authToken); + + /** + * This method receives the Auth Token and finds out whether there is an active + * user for that Authentication Token Auth Token in this method is the JWT Token + * + * @param authToken + * @return + */ + public Boolean findUserByToken(String authToken); + + /** + * This method receives the Auth Token of the FCM and verifies whether the token + * is already registered against any User ID or not. + * + * @param userId + * @param deviceToken + * @return + */ + public Boolean checkUserTokenExists(Long userId, String deviceToken); + + /** + * This method receives the Device Token and the User ID and updates it against + * the record which is already available in the system database + * + * @param userId + * @param deviceToken + * @return + */ + + public UserAuthentication findOneUserAuthentication(Long id); + + public UserDetailsMapper findListOfUsers(List<Long> userIdList); + + public User update(User user); + + public UserRoleMapper findAllRolesByUser(Long userId); + + public Long fetchAuthTokenReference(String authToken); + + int insertIntoPassword(Long id, String password); + + int getAuthId(Long userId); + + boolean customAuth(UserDto userDto); + + User insertIntoUser(final User user); + + Long insertAnonymousUser(User user); + + public boolean changePassword(ChangePasswordDto changePasswordDto); + + public long forgotPassword(UserDto userDto); + + boolean saveForgotPassword(long userId, String password); + + public User getUserDetailsByEmail(String username); + + public LoginDto login(UserDto userDto); + + public CommonDataModel getAuthDomain(UserDto userDto); + + public boolean getFirstAdminsOfOrg(Long id); + + public Boolean onBoardingCheck(Long orgId, Long id); + + boolean isPasswordMatch(long userId, String password); + + List<User> findAll(Long orgId); + + List<OrgUserRoleDto> getAllOrgUsers(); + + List<OrgUserRoleDto> getAllUserRoles(); + + public List<HelpDeskApp> getAppIdAndHelpDeskId(); + + public List<User> getUserIdAndUserName(); + + public void getReviews() throws IOException; + + Access getReviewConfig(Long orgId); + +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..8639e275f09d7b68cd0961e8eec18bb9388fe38e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/ApplicationDaoImpl.java @@ -0,0 +1,238 @@ +package org.upsmf.grievance.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import org.upsmf.grievance.dao.ApplicationDao; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.DateUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.Sql; +import org.upsmf.grievance.util.Sql.Apps; + +@Repository(Constants.APP_DAO) +public class ApplicationDaoImpl implements ApplicationDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_CREATING_APP_S = "Encountered an Exception while creating App : %s"; + private static final String ENCOUNTERED_AN_EXCEPTION_GET_ORGANIZATION_APP_DAO_IMPL_S = "Encountered an exception getOrganizationApp daoImpl : %s"; + private static final String QUERY_TO_EXECUTE = "Query to execute : "; + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + public static final Logger LOGGER = LoggerFactory.getLogger(ApplicationDaoImpl.class); + @Autowired + JdbcTemplate jdbcTemplate; + + @Override + public App createApp(App app, User user) { + Long id = (long) 0; + try { + app.setAppKey(UUID.randomUUID().toString()); + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Apps.INSERT_NEW_APP, returnValColumn); + statement.setString(1, app.getName()); + statement.setString(2, app.getAppUrl()); + statement.setString(3, app.getLogo()); + statement.setLong(4, app.getSourceId()); + statement.setLong(5, user.getId()); + statement.setBoolean(6, Boolean.TRUE); + statement.setString(7, app.getClientName()); + statement.setString(8, app.getVersion()); + statement.setString(9, app.getAppKey()); + statement.setString(10, app.getDescription()); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + app.setId(id); + Long orgAppId = jdbcTemplate.queryForObject(Sql.Apps.GET_ID_FROM_ORG_APP, + new Object[] { id, user.getOrgId() }, Long.class); + if (orgAppId < 1) { + jdbcTemplate.update(Apps.MAP_APP_TO_ORG, new Object[] { id, user.getOrgId() }); + } + MasterDataManager.getAppObjectFromAppName(); + } catch (InvalidDataAccessApiUsageException e) { + LOGGER.error(String.format( + "Encountered an Exception while creating App : InvalidDataAccessApiUsageException : %s", + e.getMessage())); + } catch (DataAccessException e) { + LOGGER.error(String.format("Encountered an Exception while creating App : DataAccessException : %s", + e.getMessage())); + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_CREATING_APP_S, e.getMessage())); + } + return app; + } + + @Override + public App updateApp(App app, User user) { + try { + + jdbcTemplate.update(Apps.UPDATE_APP, new Object[] { app.getName(), app.getAppUrl(), app.getLogo(), + app.getSourceId(), app.getActiveStatus(), app.getClientName(), app.getVersion(), user.getId(), + DateUtil.getFormattedDateInUTC(new Date()), app.getAppKey(), app.getDescription(), app.getId() }); + if (app.getActiveStatus()) { + jdbcTemplate.update(Sql.Apps.DELETE_ORG_APP, new Object[] { app.getId(), user.getOrgId() }); + } + MasterDataManager.getAppObjectFromAppName(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_CREATING_APP_S, e.getMessage())); + } + return app; + } + + @Override + public List<App> getApp(Long id) { + List<App> appList = null; + try { + LOGGER.info(QUERY_TO_EXECUTE + Apps.GET_APP + Sql.Common.WHERE_CLAUSE + Apps.ID_CONDITION); + appList = jdbcTemplate.query(Apps.GET_APP + Sql.Common.WHERE_CLAUSE + Apps.ID_CONDITION, + new Object[] { id }, MasterDataManager.rowMapApp); + appList = getLogo(appList); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles : %s", e.getMessage())); + } + return appList; + } + + public List<App> getLogo(List<App> appList) { + try { + for (int i = 0; i < appList.size(); i++) { + String url = getAppLogo(appList.get(i)); + appList.get(i).setLogo(url); + } + return appList; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return appList; + } + + public String getAppLogo(App app) { + if (app.getLogo() != null && !app.getLogo().isEmpty()) { + try { + List<S3Config> s3 = jdbcTemplate.query(Sql.GET_S3_ACCESS, MasterDataManager.rowMapS3Config); + S3Config s3values; + if (!s3.isEmpty()) { + s3values = s3.get(0); + String url = null; + url = S3FileManager.getPreSignedURL(s3values, app.getLogo()); + return url; + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + return null; + } + + @Override + public List<App> getAllApps() { + List<App> appList = null; + + try { + LOGGER.info(QUERY_TO_EXECUTE + Apps.GET_APP); + appList = jdbcTemplate.query(Apps.GET_APP, new Object[] {}, MasterDataManager.rowMapApp); + if (appList != null && !appList.isEmpty()) { + appList = getLogo(appList); + } + } catch (Exception e) { + LOGGER.error(String.format("Exception in getAllApplications daoImpl : %s", e.getMessage())); + } + + return appList; + } + + @Override + public List<App> getAppsByOrgId(Long orgId) { + try { + LOGGER.info(QUERY_TO_EXECUTE + Apps.GET_ORG_APPS); + List<App> apps = jdbcTemplate.query(Apps.GET_ORG_APPS, new Object[] { orgId }, MasterDataManager.rowMapApp); + if (apps != null && !apps.isEmpty()) { + apps = getLogo(apps); + } + return apps; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_GET_ORGANIZATION_APP_DAO_IMPL_S, e.getMessage())); + return new ArrayList<>(); + } + } + + @Override + public List<String> getDistinctAppNames(Long orgId) { + try { + LOGGER.info(QUERY_TO_EXECUTE + Apps.GET_APP_URLS); + return jdbcTemplate.queryForList(Apps.GET_APP_URLS, new Object[] { orgId }, String.class); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_GET_ORGANIZATION_APP_DAO_IMPL_S, e.getMessage())); + return new ArrayList<>(); + } + } + + @Override + public boolean mapAppsToHelpdesk(StatusIdMap statusIdMap) { + try { + Long id = jdbcTemplate.queryForObject(Apps.GET_HELPDESK_ID, + new Object[] { statusIdMap.getHelpdeskId(), statusIdMap.getAppId() }, Long.class); + if (id == 0) { + LOGGER.info(QUERY_TO_EXECUTE + Apps.MAP_HELPDESK_APP); + jdbcTemplate.update(Apps.MAP_HELPDESK_APP, + new Object[] { statusIdMap.getHelpdeskId(), statusIdMap.getAppId() }); + MasterDataManager.getHelpdeskIdFromAppId(); + return true; + } + } catch (Exception e) { + LOGGER.error(String.format("Exception in mapAppToOrg daoImpl : %s", e.getMessage())); + } + return false; + } + + @Override + public List<ServiceRequest> getServiceRequests() { + List<ServiceRequest> serviceRequests = null; + try { + LOGGER.info(QUERY_TO_EXECUTE + Apps.GET_SOURCE); + serviceRequests = jdbcTemplate.query(Apps.GET_SOURCE, MasterDataManager.rowMapServiceRequest); + return serviceRequests; + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception getOrganizationApp daoImpl %s", e.getMessage())); + return serviceRequests; + } + } + + @Override + public List<App> getAppIdAndAppObject() { + List<App> app = null; + try { + app = jdbcTemplate.query(Sql.UserQueries.GET_APP_ID_APP_OBJECT, MasterDataManager.rowMapApp); + return app; + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles %s", e.getMessage())); + return app; + } + } + +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..195c24d3d2644c0cbda229ccac3a286bd2632af7 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImpl.java @@ -0,0 +1,485 @@ +package org.upsmf.grievance.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import org.upsmf.grievance.dao.ApplicationDao; +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.dto.HelpdeskWorkflowDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.DateUtil; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.SendMail; +import org.upsmf.grievance.util.Sql; + +@Repository +public class HelpdeskDaoImpl implements HelpdeskDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_USERS_FOR_HELPDESK_S = "Encountered an exception while fetching Users for Helpdesk : : %s"; + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE_S = "Encountered an Exception while deleting Workflow Stages for a Helpdesk Type : : %s"; + + public static final Logger LOGGER = LoggerFactory.getLogger(HelpdeskDaoImpl.class); + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private ApplicationDao appDao; + + @Autowired + private SuperAdminDao superAdminDao; + + @Override + public boolean createUpdateHelpdesk(Helpdesk helpdesk) { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + if (ProjectUtil.isObjectNull(helpdesk.getId())) { + try { + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Sql.Helpdesk.CREATE_HELPDESK, + returnValColumn); + statement.setString(1, helpdesk.getName()); + statement.setLong(2, helpdesk.getOrgId()); + statement.setLong(3, helpdesk.getCreatedBy()); + statement.setString(4, DateUtil.getFormattedDateInUTC(new Date())); + statement.setBoolean(5, helpdesk.getIsActive()); + statement.setString(6, helpdesk.getColor()); + statement.setString(7, helpdesk.getDescription()); + return statement; + } + }, keyHolder); + helpdesk.setId((Long) keyHolder.getKey()); + setHelpdeskChannels(helpdesk); + return true; + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in create daoImpl : %s", e.getMessage())); + } + } else { + try { + jdbcTemplate.update(Sql.Helpdesk.UPDATE_HELPDESK, + new Object[] { helpdesk.getName(), helpdesk.getUpdatedBy(), + DateUtil.getFormattedDateInUTC(new Date()), helpdesk.getIsActive(), helpdesk.getColor(), + helpdesk.getDescription(), helpdesk.getId(), helpdesk.getOrgId() }); + setHelpdeskChannels(helpdesk); + return true; + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in updating Helpdesk daoImpl : %s", e.getMessage())); + } + } + return false; + } + + private void setHelpdeskChannels(Helpdesk helpdesk) { + if (updateAdminAndAppIds(helpdesk) && helpdesk.getDirect() != null && helpdesk.getPlaystore() != null + && helpdesk.getAppstore() != null && helpdesk.getAurora_sdk() != null) { + jdbcTemplate.update(Sql.Helpdesk.UPDATE_HELPDESK_CHANNELS, + new Object[] { helpdesk.getDirect(), helpdesk.getPlaystore(), helpdesk.getAppstore(), + helpdesk.getAurora_sdk(), helpdesk.getId(), helpdesk.getOrgId() }); + } + } + + private boolean updateAdminAndAppIds(Helpdesk helpdesk) { + + if (helpdesk != null) { + // jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_HELPDESK_SOURCE, new Object[] + // { helpdesk.getId() }); + // for (int i = 0; i < helpdesk.getSourceId().size(); i++) { + // jdbcTemplate.update(Sql.Ticket.ADD_SOURCE_TO_HELPDESK, + // new Object[] { helpdesk.getId(), helpdesk.getSourceId().get(i) }); + // } + boolean value = addUpdateHelpdeskAdmins(helpdesk); + boolean values = addUpdateHelpdeskUsers(helpdesk); + if (value && values) { + for (int i = 0; i < helpdesk.getAppIds().size(); i++) { + StatusIdMap statusIdMap = new StatusIdMap(); + statusIdMap.setHelpdeskId(helpdesk.getId()); + statusIdMap.setHelpdeskAppStatus(true); + statusIdMap.setAppId(helpdesk.getAppIds().get(i)); + appDao.mapAppsToHelpdesk(statusIdMap); + } + MasterDataManager.getHelpdeskObjectFromHelpdeskId(); + } + return true; + } + return false; + } + + @Override + public List<HelpdeskDto> getAllHelpdesks(Long orgId) { + try { + return jdbcTemplate.query(Sql.Helpdesk.GET_ORG_HELPDESK, new Object[] { orgId, true }, + MasterDataManager.rowMapHelpdeskDto); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in getOrgHelpdesk daoImpl : %s", e.getMessage())); + return new ArrayList<>(); + } + + } + + @Override + public HelpdeskRowRecordMapper getHelpdeskForId(Long orgId, Long id) { + HelpdeskRowRecordMapper rowMapper = new SqlDataMapper().new HelpdeskRowRecordMapper(); + try { + jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_FOR_ID, new Object[] { id, orgId }, rowMapper); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in getHelpdeskForId daoImpl : %s", e.getMessage())); + } + return rowMapper; + } + + @Override + public List<ChecklistItem> getChecklistItemsForHelpdesk(Long helpdeskId, Long typeId) { + List<ChecklistItem> checklistItems = new ArrayList<>(); + try { + checklistItems = jdbcTemplate.query(Sql.Helpdesk.GET_CHECKLIST_FOR_HELPDESK, + new Object[] { helpdeskId, typeId }, new SqlDataMapper().new ChecklistItemMapper()); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in getHelpdeskForId daoImpl : %s", e.getMessage())); + } + return checklistItems; + } + + @Override + public List<Long> getHelpdeskAdmins(Long id) { + List<Long> list = null; + try { + list = jdbcTemplate.queryForList(Sql.UserQueries.GET_HELPDESK_ADMINS, new Object[] { id }, Long.class); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception : : %s", e.getMessage())); + } + return list; + + } + + @Override + public boolean addUpdateHelpdeskAdmins(Helpdesk helpdesk) { + try { + List<Long> oldAdmins = getHelpdeskAdmins(helpdesk.getId()); + for (Long admin : helpdesk.getAdminIds()) { + if (oldAdmins.contains(admin)) { + oldAdmins.remove(admin); + } + } + for (int i = 0; i < oldAdmins.size(); i++) { + User user = superAdminDao.userDetailsByUserId(oldAdmins.get(i)); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.HELPDESKNAME, helpdesk.getName()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.DELETE_HELPDESK_ADMIN, "remove_helpdeskadmin.vm"); + } + jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_HELPDESK_ADMIN, new Object[] { helpdesk.getId() }); + if (helpdesk != null && helpdesk.getAdminIds() != null) { + for (int i = 0; i < helpdesk.getAdminIds().size(); i++) { + jdbcTemplate.update(Sql.UserQueries.ADD_ADMINS_TO_HELPDESK, + new Object[] { helpdesk.getId(), helpdesk.getAdminIds().get(i) }); + User user = superAdminDao.userDetailsByUserId(helpdesk.getAdminIds().get(i)); + user.setOrgId(MasterDataManager.getUserOrgMap().get(helpdesk.getAdminIds().get(i))); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.HELPDESKNAME, helpdesk.getName()); + LOGGER.info(helpdesk.getName()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.NEW_HELPDESK_ADMIN, "add-helpdeskadmin-aurora.vm"); + } + } + return true; + } catch (DataAccessException e) { + LOGGER.error( + String.format("Encountered an Exception while adding admins to helpdesk : : %s", e.getMessage())); + } catch (Exception ex) { + LOGGER.error( + String.format("Encountered an Exception while adding admins to helpdesk : : %s", ex.getMessage())); + } + return false; + } + + @Override + public Boolean addTypeForHelpdesk(HelpdeskTypeDto dto, Long helpdeskId) { + Long id = 0l; + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Sql.Helpdesk.INSERT_TYPE_FOR_HELPDESK, + returnValColumn); + statement.setLong(1, helpdeskId); + statement.setString(2, dto.getName()); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + dto.setId(id); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while adding type for a Helpdesk : : %s", e.getMessage())); + } + return true; + } + + @Override + public Boolean addWorkflowForHelpdeskType(HelpdeskTypeDto helpdeskTypeDto) { + int[] values = null; + try { + values = jdbcTemplate.batchUpdate(Sql.Helpdesk.INSERT_WORKFLOW_FOR_HELPDESK_TYPE, + new BatchPreparedStatementSetter() { + @Override + public void setValues(java.sql.PreparedStatement statement, int i) throws SQLException { + HelpdeskWorkflowDto workflowDto = helpdeskTypeDto.getWorkflowStages().get(i); + statement.setString(1, workflowDto.getName()); + statement.setLong(2, helpdeskTypeDto.getId()); + } + + @Override + public int getBatchSize() { + return helpdeskTypeDto.getWorkflowStages().size(); + } + }); + } catch (Exception e) { + LOGGER.error(String.format("Exception Occured while mapping Products to Order : %s", e.getMessage())); + + } + return (values != null && values.length > 0); + + } + + @Override + public Boolean addChecklistForHelpdeskType(HelpdeskTypeDto helpdeskTypeDto, Long helpdeskId) { + Long id = 0l; + try { + for (ChecklistItem item : helpdeskTypeDto.getChecklistItems()) { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Sql.Helpdesk.INSERT_CHECKLIST_FOR_HDTYPE, + returnValColumn); + statement.setString(1, item.getItem()); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + item.setId(id); + jdbcTemplate.update(Sql.Helpdesk.MAP_CHECKLIST_HDTYPE, + new Object[] { helpdeskId, item.getId(), helpdeskTypeDto.getId() }); + } + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while adding checklist type for a Helpsedk : : %s", + e.getMessage())); + } + return true; + } + + @Override + public boolean addUpdateHelpdeskUsers(Helpdesk helpdesk) { + try { + if (helpdesk.getAllowAllUsers()) { + jdbcTemplate.update(Sql.UserQueries.UPDATE_ALLOW_ALL_USERS, + new Object[] { helpdesk.getAllowAllUsers(), helpdesk.getId() }); + jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_USERS_FROM_HELPDESK, new Object[] { helpdesk.getId() }); + } else { + jdbcTemplate.update(Sql.UserQueries.UPDATE_ALLOW_ALL_USERS, + new Object[] { helpdesk.getAllowAllUsers(), helpdesk.getId() }); + jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_USERS_FROM_HELPDESK, new Object[] { helpdesk.getId() }); + for (int i = 0; i < helpdesk.getUserIds().size(); i++) { + jdbcTemplate.update(Sql.UserQueries.ADD_USERS_TO_HELPDESK, + new Object[] { helpdesk.getId(), helpdesk.getUserIds().get(i) }); + } + } + return true; + } catch (Exception ex) { + LOGGER.error( + String.format("Encountered an Exception while adding users to helpdesk : : %s", ex.getMessage())); + } + return false; + } + + @Override + public Boolean deleteTypeForHelpdesk(Long helpdeskId) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Helpdesk.DELETE_TYPE_FOR_HELPDESK, new Object[] { helpdeskId }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE_S, + e.getMessage())); + return false; + } + + return (status > 0); + } + + @Override + public Boolean deleteWorkflowForHelpdeskType(Long typeId) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Helpdesk.DELETE_WORKFLOW_FOR_HELPDESKTYPE, new Object[] { typeId }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE_S, + e.getMessage())); + return false; + } + + return (status > 0); + } + + @Override + public Boolean deleteChecklistForHelpdeskType(Long helpdeskId, Long typeId) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Helpdesk.DELETE_CHECKLIST_FOR_HDTYPE, new Object[] { helpdeskId, typeId }); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while deleting Workflow Stages for a Helpdesk Type : : %s ", + e.getMessage())); + return false; + } + + return (status > 0); + } + + @Override + public List<HelpDeskApp> getAppIdAndHelpDeskId() { + List<HelpDeskApp> helpdeskApp = null; + try { + helpdeskApp = jdbcTemplate.query(Sql.UserQueries.GET_APP_ID_HELPDESK_ID, + MasterDataManager.rowMapHelpDeskApp); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles : %s", e.getMessage())); + } + return helpdeskApp; + } + + @Override + public List<Helpdesk> getHelpdeskObjectFromHelpdeskId() { + List<Helpdesk> helpdesk = null; + try { + helpdesk = jdbcTemplate.query(Sql.UserQueries.GET_HELPDESK_ID_HELPDESK_OBJECT, + MasterDataManager.rowMapHelpdesk); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles : %s", e.getMessage())); + } + return helpdesk; + } + + @Override + public List<User> getAdminForHelpeskId(Long helpdeskId) { + List<User> helpdeskUsers = null; + try { + helpdeskUsers = jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_ADMIN_BY_ID, new Object[] { helpdeskId }, + new SqlDataMapper().new HelpdeskUserMapper()); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_USERS_FOR_HELPDESK_S, e.getMessage())); + } + return helpdeskUsers; + } + + @Override + public List<User> getUsersForHelpeskId(Long helpdeskId) { + List<User> helpdeskUsers = new ArrayList<>(); + List<HelpdeskDto> data = new ArrayList<>(); + try { + data = jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_BY_ID, new Object[] { helpdeskId }, + MasterDataManager.rowMapHelpdeskDto); + if (!data.isEmpty()) { + HelpdeskDto helpdesk = data.get(0); + if (helpdesk.getAllowAllUsers()) { + helpdeskUsers = jdbcTemplate.query(Sql.Helpdesk.GET_USER_DETAILS_FOR_HELPDESK, + new Object[] { helpdesk.getOrgId() }, new SqlDataMapper().new HelpdeskUserMapper()); + } else { + helpdeskUsers = jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_USER_BY_ID, + new Object[] { helpdeskId }, new SqlDataMapper().new HelpdeskUserMapper()); + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_USERS_FOR_HELPDESK_S, e.getMessage())); + } + return helpdeskUsers; + } + + @Override + public List<HelpdeskDto> getHelpdeskAdminUser(List<HelpdeskDto> helpdeskList) { + try { + for (int i = 0; i < helpdeskList.size(); i++) { + HelpdeskDto dto = helpdeskList.get(i); + List<User> admins = jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_ADMIN_USER, + new Object[] { dto.getId() }, MasterDataManager.rowMapUser); + dto.setUsers(getUsersForHelpeskId(dto.getId())); + admins = getImageUrl(admins); + dto.setAdmins(admins); + } + + return helpdeskList; + + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception in getHelpdeskAdminUser : : %s", e.getMessage())); + return new ArrayList<>(); + } + + } + + private List<User> getImageUrl(List<User> userList) { + S3Config s3values = superAdminDao.getS3Access(); + for (int i = 0; i < userList.size(); i++) { + if (userList.get(i).getImagePath() != null && !userList.get(i).getImagePath().isEmpty() + && userList.get(i).getImagePath().contains("userprofile")) { + String url = null; + url = S3FileManager.getPreSignedURL(s3values, userList.get(i).getImagePath()); + userList.get(i).setImagePath(url); + } + } + return userList; + + } + + @Override + public List<Helpdesk> getHelpdeskByUserId(Long userId) { + List<Helpdesk> helpdeskUsers = null; + Long orgId = MasterDataManager.getUserOrgMap().get(userId); + try { + helpdeskUsers = jdbcTemplate.query(Sql.Helpdesk.GET_HELPDESK_BY_USER_ID, + new Object[] { userId, userId, orgId }, new SqlDataMapper().new UserHelpdeskMapper()); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_USERS_FOR_HELPDESK_S, e.getMessage())); + } + return helpdeskUsers; + } +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..03b6583136edd1f6dacc43ebc60bbc6311faae41 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/RoleDaoImpl.java @@ -0,0 +1,204 @@ +package org.upsmf.grievance.dao.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import org.upsmf.grievance.dao.RoleDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.RoleActionMapper; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.Sql; +import org.upsmf.grievance.util.Sql.Common; +import org.upsmf.grievance.util.Sql.RoleAction; + +@Repository(Constants.ROLE_DAO) +public class RoleDaoImpl implements RoleDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_SAVING_THE_ROLE_DETAILS_S = "Encountered an exception while saving the Role Details : %s"; + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_ROLES_S = "Encountered an exception while fetching all roles %s"; + + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + + public static final Logger LOGGER = LoggerFactory.getLogger(RoleDaoImpl.class); + + @Autowired + JdbcTemplate jdbcTemplate; + + @Autowired + private SuperAdminDao superAdminDao; + + @Override + public Role saveRole(Role role) { + int saveRole = 0; + try { + saveRole = jdbcTemplate.update(RoleAction.SAVE_NEW_ROLE, new Object[] { role.getName(), role.getOrgId() }); + } catch (Exception ex) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_SAVING_THE_ROLE_DETAILS_S, ex.getMessage())); + } + if (saveRole > 0) { + return role; + } + return null; + } + + @Override + public Role updateRole(Role role) { + int updateRole = 0; + try { + updateRole = jdbcTemplate.update(RoleAction.UPDATE_ROLE, + new Object[] { role.getName(), role.getId(), role.getOrgId() }); + } catch (Exception ex) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_SAVING_THE_ROLE_DETAILS_S, ex.getMessage())); + } + if (updateRole > 0) { + return role; + } + return null; + } + + @Override + public List<Role> getAllRoles(Long orgId) { + List<Role> roleList = null; + String query = RoleAction.GET_ALL_ROLES + Common.WHERE_CLAUSE + RoleAction.ORG_ID_CONDITION; + try { + roleList = jdbcTemplate.query(query, new Object[] { orgId }, MasterDataManager.rowMapRole); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_ROLES_S, e.getMessage())); + } + return roleList; + } + + @Override + public String findById(Role role) { + String roleList = null; + try { + roleList = jdbcTemplate.queryForObject(RoleAction.SELECT_ROLES_ON_ID, + new Object[] { role.getId(), role.getOrgId() }, String.class); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_ROLES_S, e.getMessage())); + } + if (roleList != null) { + return roleList; + } + return null; + } + + @Override + public List<Role> getAllOrgRoles() { + List<Role> roleList = null; + try { + roleList = jdbcTemplate.query(RoleAction.GET_ALL_ROLES, MasterDataManager.rowMapRole); + return roleList; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_ROLES_S, e.getMessage())); + } + return new ArrayList<>(); + } + + @Override + public void initializeActions() { + + try { + Iterator<Entry<Integer, List<String>>> it = Constants.getActions().entrySet().iterator(); + while (it.hasNext()) { + Entry<Integer, List<String>> pair = it.next(); + Boolean value = jdbcTemplate.queryForObject(Sql.Organization.CHECK_IF_ACTION_EXISTS, + new Object[] { pair.getKey() }, Boolean.class); + if (!value) { + if (!ProjectUtil.isObjectListNullOrEmpty(Constants.getActions().get(pair.getKey())) + && Constants.getActions().get(pair.getKey()).size() == 3) { + jdbcTemplate.update(Sql.UserQueries.INSERT_ACTION, + new Object[] { pair.getKey(), Constants.getActions().get(pair.getKey()).get(0), + Constants.getActions().get(pair.getKey()).get(1), + Constants.getActions().get(pair.getKey()).get(2) }); + } + } else if (!ProjectUtil.isObjectListNullOrEmpty(Constants.getActions().get(pair.getKey())) + && Constants.getActions().get(pair.getKey()).size() == 3) { + jdbcTemplate.update(Sql.UserQueries.UPDATE_ACTION, + new Object[] { Constants.getActions().get(pair.getKey()).get(0), + Constants.getActions().get(pair.getKey()).get(1), + Constants.getActions().get(pair.getKey()).get(2), pair.getKey() }); + } + + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + + } + + @Override + public void intializeRolesAndActions() { + Long roleId = null; + List<Organization> organizations = superAdminDao.getAllOrganization(); + for (int i = 0; i < organizations.size(); i++) { + for (Constants.userRole roleName : Constants.userRole.values()) { + try { + roleId = jdbcTemplate.queryForObject(Sql.Organization.GET_ROLE_ID_FROM_ORG, + new Object[] { String.valueOf(roleName), organizations.get(i).getId() }, Long.class); + jdbcTemplate.update(Sql.Organization.DELETE_ACTION, new Object[] { roleId }); + List<Integer> actions; + switch (String.valueOf(roleName)) { + case Common.SUPER_ADMIN: + actions = Constants.getSuperadminactions(); + break; + case Common.ORGADMIN: + actions = Constants.getOrgadminactions(); + break; + case Common.ENDUSER: + actions = Constants.getEnduseractions(); + break; + default: + actions = new ArrayList<>(); + } + for (int j = 0; j < actions.size(); j++) { + jdbcTemplate.update(Sql.Organization.ADD_ROLE_PERMISSION, + new Object[] { roleId, actions.get(j) }); + } + } catch (Exception e) { + LOGGER.info(String.format("Role Doesn't exist as per mapped, Please check. %s", roleId.toString())); + } + } + } + + } + + @Override + public Map<Long, List<String>> getAllActionsForRoles(List<Long> roleIds) { + RoleActionMapper mapper = new SqlDataMapper().new RoleActionMapper(); + String queryToExecute = RoleAction.GET_ALL_ACTIONS_FOR_ROLES + getIdQuery(roleIds); + try { + jdbcTemplate.query(queryToExecute, mapper); + return mapper.getRoleActionsMap(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_ROLES_S, e.getMessage())); + } + return null; + } + + private static String getIdQuery(final List<Long> idList) { + final StringBuilder query = new StringBuilder("("); + if (!idList.isEmpty()) { + query.append(idList.get(0).toString()); + for (int i = 1; i < idList.size(); i++) { + query.append(", " + idList.get(i)); + } + } + return query.append(")").toString(); + } +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..1f99fef57d83a4624d1c7bf62ceb8b5a012a4bc8 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImpl.java @@ -0,0 +1,391 @@ +package org.upsmf.grievance.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.velocity.VelocityContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.OrgMapper; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.DateUtil; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.OneWayHashing; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.SendMail; +import org.upsmf.grievance.util.Sql; +import org.upsmf.grievance.util.Sql.Apps; +import org.upsmf.grievance.util.Sql.Common; + +@Repository(Constants.SUPER_ADMIN_DAO) +public class SuperAdminDaoImpl implements SuperAdminDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + + public static final Logger LOGGER = LoggerFactory.getLogger(SuperAdminDaoImpl.class); + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override + public List<Organization> getAllOrganization() { + List<Organization> list = new ArrayList<>(); + try { + list = jdbcTemplate.query(Sql.Organization.GET_ALL_ORG, new Object[] {}, + MasterDataManager.rowMapOrganizationModel); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return list; + } + + @Override + public boolean addAdmin(long userId) { + try { + MasterDataManager.getUserOrgMap().get(userId); + int orgId = getOrganizationByUserId(userId); + Long roleId = jdbcTemplate.queryForObject(Sql.UserQueries.GET_ROLE_ID_BY_ORG, + new Object[] { orgId, Sql.Common.ORGADMIN }, Long.class); + + Integer response = jdbcTemplate.update(Sql.UserQueries.ADD_ADMIN, + new Object[] { roleId.intValue(), userId }); + if (response > 0) { + MasterDataManager.getUserRoleMap().put(userId, roleId); + return true; + } + return false; + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while Adding an Admin : %s", e.getMessage())); + return false; + } + + } + + @Override + public boolean removeAdmin(long userId) { + try { + int orgId = getOrganizationByUserId(userId); + MasterDataManager.getUserOrgMap().get(userId); + Long roleId = jdbcTemplate.queryForObject(Sql.UserQueries.GET_ROLE_ID_BY_ORG, + new Object[] { orgId, Sql.Common.ENDUSER }, Long.class); + Integer response = jdbcTemplate.update(Sql.UserQueries.DELETE_ADMIN, + new Object[] { roleId.intValue(), userId }); + if (response > 0) { + MasterDataManager.getUserRoleMap().put(userId, roleId); + return true; + } + return false; + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while removing an Admin : %s", e.getMessage())); + return false; + } + + } + + @Override + public Organization addOrganization(Organization organization) { + int insertSuccessful = 0; + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + List<Organization> list = jdbcTemplate.query(Sql.Organization.GET_ORG_BY_NAME, + new Object[] { organization.getOrgName() }, MasterDataManager.rowMapOrganizationModel); + if (list == null || list.isEmpty()) { + Long userId = newOrgCreateAdmin(organization); + if (userId == null) { + return null; + } + try { + insertSuccessful = jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Sql.Organization.ADD_NEW_ORG, + returnValColumn); + statement.setString(1, organization.getOrgName()); + statement.setString(2, organization.getUrl()); + statement.setString(3, organization.getLogo()); + statement.setLong(4, userId); + statement.setLong(5, userId); + statement.setString(6, organization.getOrgDescription()); + statement.setString(7, organization.getOrgColor()); + statement.setString(8, organization.getEmailDomain()); + return statement; + } + }, keyHolder); + organization.setId((Long) keyHolder.getKey()); + MasterDataManager.getOrgIdAndOrgNameMap().put(organization.getId(), organization.getOrgName()); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while Adding an Organization : %s", e.getMessage())); + } + if (insertSuccessful > 0) { + jdbcTemplate.update(Sql.UserQueries.NEW_ORG_AUTH, new Object[] { organization.getId(), + organization.getAuthId(), organization.getUrl(), organization.getEmailDomain() }); + orgSetup(organization, userId); + return organization; + } + } + return null; + } + + public Long newOrgCreateAdmin(final Organization org) { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + try { + Long list = jdbcTemplate.queryForObject(Sql.UserQueries.USER_DATA, + new Object[] { org.getAdminDetails().get(0).getUsername() }, Long.class); + if (list == 0) { + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = connection.prepareStatement(Sql.Organization.NEW_ORG_ADMIN_USER, + returnValColumn); + statement.setString(1, org.getAdminDetails().get(0).getName()); + statement.setString(2, org.getAdminDetails().get(0).getUsername()); + statement.setString(3, org.getAdminDetails().get(0).getPhone()); + statement.setString(4, org.getAdminDetails().get(0).getImagePath()); + return statement; + } + }, keyHolder); + return keyHolder.getKey().longValue(); + } + MasterDataManager.getAllUserRoles(); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while Adding an Admin for New Org : %s", e.getMessage())); + } + + return null; + } + + public void orgSetup(final Organization org, Long newOrgAdminUserId) { + Long id = org.getId(); + if (id > 0) { + LOGGER.info("Org Id: {}", id); + } + if (newOrgAdminUserId > 0) { + LOGGER.info("User Id : {}", newOrgAdminUserId); + } + String password = null; + int adminRoleId = 0; + try { + for (Constants.userRole roleName : Constants.userRole.values()) { + Boolean value = jdbcTemplate.queryForObject(Sql.Organization.CHECK_IF_ROLE_EXISTS, + new Object[] { String.valueOf(roleName), id }, Boolean.class); + if (!value) { + jdbcTemplate.update(Sql.Organization.ADD_ORG_ROLES, new Object[] { String.valueOf(roleName), id }); + } + List<Integer> actions = new ArrayList<>(); + Integer roleId = jdbcTemplate.queryForObject(Sql.Organization.GET_ROLE_ID_BY_ORG, + new Object[] { id, String.valueOf(roleName) }, Integer.class); + if (String.valueOf(roleName).equals(Common.ORGADMIN)) { + adminRoleId = roleId; + actions = Constants.getOrgadminactions(); + } + if (String.valueOf(roleName).equals(Common.ENDUSER)) { + actions = Constants.getEnduseractions(); + } + for (int i = 0; i < actions.size(); i++) { + jdbcTemplate.update(Sql.Organization.ADD_ROLE_PERMISSION, new Object[] { roleId, actions.get(i) }); + } + } + jdbcTemplate.update(Sql.Organization.NEW_ORG_ADMIN_ROLE, new Object[] { newOrgAdminUserId, adminRoleId }); + MasterDataManager.getAllUserRoles(); + jdbcTemplate.update(Sql.Organization.FIRST_ADMIN_COMP, new Object[] { id, newOrgAdminUserId }); + MasterDataManager.getUserOrgMap().put(newOrgAdminUserId, id); + password = ProjectUtil.getRandomStringVal().trim(); + if (!StringUtils.isBlank(password)) { + LOGGER.info("New Admin Password : {}", password); + } + String encodedPwd = OneWayHashing.encryptVal(password); + jdbcTemplate.update(Sql.Organization.NEW_ORG_ADMIN_PSWRD, new Object[] { encodedPwd, newOrgAdminUserId }); + if (!StringUtils.isBlank(password)) { + LOGGER.info("Password : {}", password); + } + sendAdminMail(org.getAdminDetails().get(0).getUsername(), org.getAdminDetails().get(0).getName(), password); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while setting up an Organization : %s", e.getMessage())); + } + + } + + private void sendAdminMail(String email, String firstName, String password) { + VelocityContext context = new VelocityContext(); + try { + context.put(JsonKey.MAIL_SUBJECT, "Welcome to Aurora-Desk!"); + context.put(JsonKey.MAIL_BODY, "You have been successfully added as the Org Admin to the system" + + " Please find your username and password"); + context.put(JsonKey.PSWRD, password); + context.put(JsonKey.USER_NAME, email); + context.put(JsonKey.FIRST_NAME, firstName); + + SendMail.sendMail(new String[] { email }, "Welcome To Aurora-Desk", context, "email_template.vm"); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while sending an Admin Mail : %s", e.getMessage())); + } + } + + @Override + public S3Config getS3Access() { + S3Config exp = null; + try { + exp = jdbcTemplate.query(Sql.GET_S3_ACCESS, MasterDataManager.rowMapS3Config).get(0); + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } + return exp; + } + + @Override + public boolean updateOrganizationById(Organization org) { + int value = 0; + try { + value = jdbcTemplate.update(Sql.Organization.UPDATE_ORG, + new Object[] { org.getOrgName(), org.getLogo(), DateUtil.getFormattedDateInUTC(new Date()), + org.getUserId(), org.getUrl(), org.getOrgDescription(), org.getOrgColor(), + org.getEmailDomain(), org.getId() }); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while updating Organization by ID : %s", e.getMessage())); + } + return (value > 0); + } + + private String getOrgLogo(Organization org) { + if (org.getLogo() != null) { + try { + S3Config s3values = jdbcTemplate.query(Sql.GET_S3_ACCESS, MasterDataManager.rowMapS3Config).get(0); + String url = null; + url = S3FileManager.getPreSignedURL(s3values, org.getLogo()); + return url; + } catch (Exception e) { + return ""; + } + } + return ""; + } + + @Override + public boolean deleteOrganization(Organization organization) { + try { + int value = jdbcTemplate.update(Sql.Organization.DELETE_ORG, new Object[] { organization.getUserId(), + DateUtil.getFormattedDateInUTC(new Date()), organization.getId() }); + return (value > 0); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + @Override + public int getOrganizationByUserId(long authUserId) { + try { + return jdbcTemplate.query(Sql.Organization.GET_ORG_BY_USERID, new Object[] { authUserId }, + MasterDataManager.rowMapOrganizationModel).get(0).getId().intValue(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return 0; + } + + @Override + public boolean mapUserToOrg(long userId, int organisationId) { + try { + Integer response = jdbcTemplate.update(Sql.UserQueries.MAP_USER_TO_ORG, + new Object[] { userId, organisationId }); + return (response > 0); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + @Override + public User userDetailsByUserId(long userId) { + try { + List<User> list = jdbcTemplate.query(Sql.UserQueries.USER, new Object[] { userId }, + MasterDataManager.rowMapUser); + return list.get(0); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return null; + } + + @Override + public boolean mapAppsToOrg(StatusIdMap statusIdMap) { + + try { + LOGGER.debug("Query to execute : " + Apps.DELETE_ORG_APP); + Integer response1 = jdbcTemplate.update(Sql.Apps.DELETE_ORG_APP, + new Object[] { statusIdMap.getAppId(), statusIdMap.getOrgId() }); + Integer response = jdbcTemplate.update(Sql.Apps.MAP_APP_TO_ORG, + new Object[] { statusIdMap.getAppId(), statusIdMap.getOrgId() }); + return (response > 0 && response1 > 0); + } catch (Exception e) { + LOGGER.error(String.format("Exception in mapAppToOrg daoImpl %s", e.getMessage())); + return false; + + } + } + + @Override + public List<Organization> getOrganizationByUser(Long userId) { + try { + List<Organization> org = jdbcTemplate.query(Sql.Organization.GET_ORG_BY_USERID, new Object[] { userId }, + MasterDataManager.rowMapOrganizationModel); + for (int i = 0; i < org.size(); i++) { + String url = getOrgLogo(org.get(i)); + if (!url.isEmpty()) { + org.get(i).setLogo(url); + } else { + org.get(i).setLogo(null); + } + } + return org; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + return new ArrayList<>(); + } + } + + @Override + public Organization getOrganizationByIdV2(Long id) { + try { + OrgMapper orgMapper = new SqlDataMapper().new OrgMapper(); + jdbcTemplate.query(Sql.Organization.ORG_BY_ID, new Object[] { true, true, id, id, Sql.Common.ORGADMIN }, + orgMapper); + String url = getOrgLogo(orgMapper.getOrg()); + if (!url.isEmpty()) { + orgMapper.getOrg().setLogo(url); + } else { + orgMapper.getOrg().setLogo(null); + } + return orgMapper.getOrg(); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception in getOrganizationByIdV2 : %s", e.getMessage())); + } + return null; + } + +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/TagDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/TagDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..443f6ca9d54c4e3a4dd9ffdaf7f945fb87fa420b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/TagDaoImpl.java @@ -0,0 +1,139 @@ +package org.upsmf.grievance.dao.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dao.TagDao; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.interceptor.TicketsRequestInterceptor; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.Sql; + +@Repository(Constants.TAG_DAO) +public class TagDaoImpl implements TagDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_TAGS_BY_ORG_S = "Encountered an Exception while fetching all tags by org : %s"; + + public static final Logger LOGGER = LoggerFactory.getLogger(TagDaoImpl.class); + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private HelpdeskDao helpdeskDao; + + @Autowired + private TicketsRequestInterceptor ticketsRequestInterceptor; + + @Override + public List<Tags> getAllTags(Long orgId) { + try { + return jdbcTemplate.query(Sql.Tags.GET_ALL_TAG_BY_ORGANISATION, new Object[] { orgId }, + MasterDataManager.rowMapTags); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_TAGS_BY_ORG_S, e.getMessage())); + } + return new ArrayList<>(); + } + + @Override + public Tags getTagByName(String name, Long id) { + Tags tag = null; + try { + tag = jdbcTemplate.queryForObject(Sql.Tags.GET_TAG_BY_NAME, new Object[] { name, id }, + MasterDataManager.rowMapTags); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching tag by name : %s", e.getMessage())); + } + return tag; + } + + @Override + public Long addTag(Long id, Tags tag) { + KeyHolder keyHolderForTag = new GeneratedKeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + + @Override + public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { + String[] returnCol = new String[] { Sql.Tags.TAG_ID }; + PreparedStatement preparedStatement = conn.prepareStatement(Sql.Tags.SAVE_TAG, returnCol); + preparedStatement.setString(1, tag.getName().trim()); + preparedStatement.setLong(2, id); + preparedStatement.setLong(3, MasterDataManager.getOrgForUser(id)); + return preparedStatement; + } + }, keyHolderForTag); + return keyHolderForTag.getKey().longValue(); + } + + @Override + public boolean addTicketTags(Long id, List<Tags> tags) { + jdbcTemplate.update(Sql.Tags.DELETE_TICKET_TAGS, new Object[] { id }); + int[][] added; + added = jdbcTemplate.batchUpdate(Sql.Tags.SAVE_TICKET_TAG, tags, tags.size(), + new ParameterizedPreparedStatementSetter<Tags>() { + @Override + public void setValues(PreparedStatement ps, Tags tag) throws SQLException { + ps.setLong(1, id); + ps.setLong(2, tag.getId()); + + } + }); + if (added.length > 0) { + Ticket ticket = new Ticket(); + ticket.setOperation("update"); + ticket.setId(id); + ticket.setTags(tags); + ticketsRequestInterceptor.addData(ticket); + return true; + } + return false; + } + + @Override + public List<Tags> getAllTicketTags(Long id) { + try { + return jdbcTemplate.query(Sql.Tags.GET_ALL_TICKET_TAGS, new Object[] { id }, MasterDataManager.rowMapTags); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_TAGS_BY_ORG_S, e.getMessage())); + } + return new ArrayList<>(); + } + + @Override + public List<Tags> getHelpdeskTags(Long id, Long userId) { + List<Long> admins = helpdeskDao.getHelpdeskAdmins(id); + List<User> user = helpdeskDao.getUsersForHelpeskId(id); + List<Long> userIds = user.stream().map(User::getId).collect(Collectors.toList()); + if (admins.contains(userId) || userIds.contains(userId)) { + try { + return jdbcTemplate.query(Sql.Tags.GET_ALL_TAG_BY_HELPDESK, new Object[] { id }, + MasterDataManager.rowMapTags); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_FETCHING_ALL_TAGS_BY_ORG_S, e.getMessage())); + } + } else { + LOGGER.info("This user is not a part of this helpdesk:"); + } + return new ArrayList<>(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..b030b395d1c9f487971424774d5a59f475ea8a50 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/TicketDaoImpl.java @@ -0,0 +1,1595 @@ +package org.upsmf.grievance.dao.impl; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; + +import com.bazaarvoice.jolt.Chainr; +import com.bazaarvoice.jolt.JsonUtils; +import com.google.gson.Gson; +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.dao.TagDao; +import org.upsmf.grievance.dao.TicketDao; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.dto.HelpdeskWorkflowDto; +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.dto.TicketWorkflowDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.interceptor.TicketsRequestInterceptor; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.AccessResponse; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Analytics; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketCount; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.TicketWorkFlowMapperV2; +import org.upsmf.grievance.service.HelpdeskService; +import org.upsmf.grievance.service.UserService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.DateUtil; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.SendMail; +import org.upsmf.grievance.util.Sql; +import org.upsmf.grievance.util.Sql.Apps; + +@Repository(Constants.TICKET_DAO) +public class TicketDaoImpl implements TicketDao { + private static final String EL_STIC123 = "El@stic123"; + + private static final String ELASTIC = "elastic"; + + private static final String T = "T"; + + private static final String COUNT = "count"; + + private static final String CREATED_TIME = "createdTime"; + + private static final String EVENT = "event"; + + private static final String FEEDBACK_D1 = "feedback-d1"; + + private static final String REPLY = ":reply"; + + private static final String REVIEWS = "/reviews/"; + + private static final String REPLY_TEXT = "replyText"; + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_UPDATING_TICKET_S = "Encountered an Exception while updating ticket : %s"; + + private static final String UPDATE = "update"; + + private static final String ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE = "Encountered an Exception while deleting Workflow Stages for a Helpdesk Type : %s"; + + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + + public static final Logger LOGGER = LoggerFactory.getLogger(TicketDaoImpl.class); + + private Boolean attachmentSource; + @Value("${elk.data.up}") + private boolean elkDataUp; + + @Value("${elasticsearch.url}") + private String elasticsearchUrl; + + @Value("${elasticsearch.index}") + private String elasticsearchIndex; + + @Value("${elasticsearch.type}") + private String elasticsearchType; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private HelpdeskDao helpdeskDao; + + @Autowired + private HelpdeskService helpdeskService; + + @Autowired + private SuperAdminDao superAdminDao; + + @Autowired + private UserService userService; + + @Autowired + private TagDao tagDao; + + @Autowired + private TicketsRequestInterceptor ticketsRequestInterceptor; + + public TicketDaoImpl(@Value("${image.source.attachment.aws}") Boolean attachmentSource, JdbcTemplate jdbcTemplate, + HelpdeskDao helpdeskDao, HelpdeskService helpdeskService, SuperAdminDao superAdminDao) { + this.attachmentSource = attachmentSource; + this.jdbcTemplate = jdbcTemplate; + this.helpdeskDao = helpdeskDao; + this.helpdeskService = helpdeskService; + this.superAdminDao = superAdminDao; + } + + @Override + public Ticket addTicket(Ticket ticket) { + if (ProjectUtil.isObjectNull(intializeAddTicket(ticket))) { + return null; + } + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + try { + if (ProjectUtil.isObjectNull(getApps(ticket))) { + return null; + } + Long orgId = jdbcTemplate.queryForObject(Apps.GET_ORG_ID_FROM_APP_ID, new Object[] { ticket.getAppId() }, + Long.class); + ticket.setOrgId(orgId); + if (ticket.getHelpdeskId() == null) { + Long helpdeskId = jdbcTemplate.queryForObject(Apps.GET_HELPDESK_ID_FROM_APP_ID, + new Object[] { ticket.getAppId() }, Long.class); + ticket.setHelpdeskId(helpdeskId); + } + if (sourceId(ticket)) { + ticket.setSourceId(3L); + } + if (ticket.getHelpdeskId() != null) { + Helpdesk helpdesk = jdbcTemplate.query(Sql.UserQueries.GET_HELPDESK_CHANNELS, + new Object[] { ticket.getHelpdeskId() }, MasterDataManager.rowMapHelpdesk).get(0); + boolean val = val(ticket, helpdesk); + if (val) { + return null; + } + } + if (ticket.getRequestedBy() == null) { + setUsername(ticket); + } + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = connection.prepareStatement(Sql.Ticket.ADD_TICKET, returnValColumn); + ticket.setCreatedTime(DateUtil.getFormattedDateInUTC(new Date())); + ticket.setUpdatedTime(DateUtil.getFormattedDateInUTC(new Date())); + ticket.setCreatedTimeTS(new Date().getTime()); + ticket.setUpdatedTimeTS(new Date().getTime()); + statement.setString(1, ticket.getCreatedTime()); + if (!StringUtils.isBlank(String.valueOf(ticket.getRate()))) { + statement.setLong(2, ticket.getRate()); + } else { + statement.setLong(2, 0L); + } + if (!StringUtils.isBlank(String.valueOf(ticket.getMaxRating()))) { + statement.setLong(3, ticket.getMaxRating()); + } else { + statement.setLong(3, 0L); + } + if (!StringUtils.isBlank(ticket.getPriority())) { + statement.setString(4, ticket.getPriority()); + } else { + statement.setString(4, "p3"); + } + if (ticket.getRequestedBy() != null) { + statement.setLong(5, ticket.getRequestedBy()); + } + if (ticket.getDescription() != null) { + statement.setString(6, ticket.getDescription()); + } else if (ticket.getFeedback() != null) { + ticket.setDescription(ticket.getFeedback()); + statement.setString(6, ticket.getFeedback()); + } else { + statement.setString(6, ""); + } + if (ticket.getType() != null) { + statement.setLong(7, ticket.getType()); + } else { + Long id = jdbcTemplate.queryForObject(Sql.Ticket.GET_DEFAULT_TICKET_TYPE, + new Object[] { ticket.getHelpdeskId() }, Long.class); + ticket.setType(id); + if (id > 0) { + statement.setLong(7, id); + } + } + statement.setString(8, ticket.getUpdatedTime()); + statement.setBoolean(9, false); + return statement; + } + }, keyHolder); + ticket.setId(keyHolder.getKey().longValue()); + if (ticket.getReviewId() != null) { + jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_REVIEW_ID, + new Object[] { ticket.getReviewId(), ticket.getId() }); + boolean v = value(ticket); + if (v) { + jdbcTemplate.update(Sql.Ticket.ADD_UPDATES, + new Object[] { ticket.getDeveloperComment(), ticket.getRequestedBy(), ticket.getId(), + convertFromTimestampToUTC(ticket.getDeveloperTimestamp()) }); + } + } + ticket.setSourceId(ticket.getSourceId()); + mapTicketToHelpdesk(ticket); + addCc(ticket); + TicketTypeDto ticketTypeDto = new TicketTypeDto(ticket); + String value = addDefaultWorkflowForTicketType(ticketTypeDto); + Boolean value1 = addChecklistForTicketType(ticketTypeDto); + ticket.setActive(true); + ticket.setOperation("save"); + ticket.setStatus(value); + if (ticket.getSourceId().equals(3L)) { + sendTicketEmail(ticket); + ticketsRequestInterceptor.addData(ticket); + } + if (!value1) { + return null; + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + return null; + } + addTicketActivityLog(ticket.getId(), "New ticket has been created", ticket.getRequestedBy()); + return ticket; + } + + public void setUsername(Ticket ticket) { + User user = new User(); + if (!StringUtils.isBlank(ticket.getUserName())) { + user.setUsername(ticket.getUserName()); + } else { + user.setUsername("anonymous" + genText() + "@mail.com"); + } + user.setOrgId(ticket.getOrgId()); + ticket.setRequestedBy(userService.saveAnonymousUser(user)); + } + + public boolean sourceId(Ticket ticket) { + return ticket.getSourceId() == null || ticket.getSourceId().toString().isEmpty(); + } + + public boolean value(Ticket ticket) { + return ticket.getDeveloperComment() != null && ticket.getDeveloperTimestamp() != null; + } + + public boolean val(Ticket ticket, Helpdesk helpdesk) { + return !((helpdesk.getDirect() && ticket.getSourceId() == 3L) + || (helpdesk.getPlaystore() && ticket.getSourceId() == 4L) + || (helpdesk.getAppstore() && ticket.getSourceId() == 5L) + || (helpdesk.getAurora_sdk() && ticket.getSourceId() == 1L)); + } + + private Ticket getApps(Ticket ticket) { + if (ticket.getAppId() == null && ticket.getAppName() != null) { + Long id = jdbcTemplate.queryForObject(Apps.CHECK_IF_APP_NAME_EXISTS, new Object[] { ticket.getAppName() }, + Long.class); + if (id > 0) { + id = jdbcTemplate.queryForObject(Apps.GET_APP_ID_APP_KEY, new Object[] { ticket.getAppName() }, + Long.class); + ticket.setAppId(id); + } else { + LOGGER.info("There is no app Url in the system as sent in the feedback, therefore no ticket is created " + + ticket.getAppName()); + return null; + } + } else if (ticket.getAppId() == null && ticket.getAppKey() != null) { + Long id = jdbcTemplate.queryForObject(Apps.CHECK_GET_APP_ID_FROM_APP_KEY, + new Object[] { ticket.getAppName() }, Long.class); + if (id != 0) { + id = jdbcTemplate.queryForObject(Apps.GET_APP_ID_FROM_APP_KEY, new Object[] { ticket.getAppKey() }, + Long.class); + ticket.setAppId(id); + } else { + LOGGER.info( + "There is no app related to the app key sent in the feedback, therefore no ticket is created " + + ticket.getAppKey()); + return null; + } + } + return ticket; + } + + private Ticket intializeAddTicket(Ticket ticket) { + if (!StringUtils.isBlank(ticket.getFeedback()) && !StringUtils.isBlank(ticket.getUserName())) { + if (jdbcTemplate.queryForObject(Apps.CHECK_IF_TICKET_EXIST, + new Object[] { ticket.getFeedback(), ticket.getUserName() }, Long.class) != 0) { + if (ticket.getSourceId() == 4L && ticket.getReviewId() != null) { + if (jdbcTemplate.queryForObject(Apps.CHECK_IF_TICKET_EXISTS, + new Object[] { ticket.getReviewId(), ticket.getUserName() }, Long.class) != 0) { + if (value(ticket) + && jdbcTemplate.queryForObject(Apps.CHECK_IF_UPDATE_EXISTS, + new Object[] { ticket.getDeveloperComment(), + convertFromTimestampToUTC(ticket.getDeveloperTimestamp()) }, + Long.class) == 0) { + jdbcTemplate.update(Sql.Ticket.ADD_UPDATES, + new Object[] { ticket.getDeveloperComment(), ticket.getRequestedBy(), + ticket.getId(), + convertFromTimestampToUTC(ticket.getDeveloperTimestamp()) }); + } + return null; + } else { + return null; + } + } + } else if (ticket.getSourceId() == 4L && ticket.getReviewId() != null + && jdbcTemplate.queryForObject(Apps.CHECK_IF_TICKET_EXISTS, + new Object[] { ticket.getReviewId(), ticket.getUserName() }, Long.class) != 0) { + if (ticket.getUserTimestamp() != null && jdbcTemplate.queryForObject(Apps.CHECK_IF_UPDATE_EXISTS, + new Object[] { ticket.getFeedback(), convertFromTimestampToUTC(ticket.getUserTimestamp()) }, + Long.class) == 0) { + jdbcTemplate.update(Sql.Ticket.ADD_UPDATES, + new Object[] { ticket.getFeedback(), ticket.getUserName(), ticket.getId(), + convertFromTimestampToUTC(ticket.getUserTimestamp()) }); + } + if (value(ticket) + && jdbcTemplate + .queryForObject(Apps.CHECK_IF_UPDATE_EXISTS, + new Object[] { ticket.getDeveloperComment(), + convertFromTimestampToUTC(ticket.getDeveloperTimestamp()) }, + Long.class) == 0) { + jdbcTemplate.update(Sql.Ticket.ADD_UPDATES, + new Object[] { ticket.getDeveloperComment(), ticket.getRequestedBy(), ticket.getId(), + convertFromTimestampToUTC(ticket.getDeveloperTimestamp()) }); + } + return null; + } + } + return ticket; + } + + public String genText() { + String randomText = "abcdefghijklmnopqrstuvwxyz123456789"; + int length = 5; + return RandomStringUtils.random(length, randomText); + } + + private void sendTicketEmail(Ticket ticket) { + try { + User user = superAdminDao.userDetailsByUserId(ticket.getRequestedBy()); + user.setOrgId(MasterDataManager.getUserOrgMap().get(ticket.getRequestedBy())); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ID, ticket.getId().toString()); + keyValue.put(JsonKey.HELPDESKID, ticket.getHelpdeskId().toString()); + keyValue.put(JsonKey.HELPDESKNAME, + MasterDataManager.getHelpdeskIdHelpdeskObjectMapping().get(ticket.getHelpdeskId()).getName()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.TICKETCREATION, "new-ticket-createdby-aurora.vm"); + } catch (ResourceNotFoundException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + private void mapTicketToHelpdesk(Ticket ticket) { + if (ticket.getAppId() != null) { + jdbcTemplate.update(Sql.Ticket.ADD_TICKET_TO_HELPDESK, + new Object[] { ticket.getId(), ticket.getSourceId(), ticket.getHelpdeskId(), ticket.getAppId() }); + } + + } + + @Override + public boolean attachmentUpload(MultipartFile file, Ticket ticket) { + List<Long> ticketIds = jdbcTemplate.queryForList(Sql.Ticket.GET_CREATED_AND_COPIED_TO_TICKET_IDS, + new Object[] { ticket.getUserId(), ticket.getUserId() }, Long.class); + Long helpdeskId = jdbcTemplate.queryForObject(Sql.Ticket.GET_HELPDESK_ID_FOR_TICKET, + new Object[] { ticket.getId() }, Long.class); + List<User> admins = new ArrayList<>(); + if (helpdeskId != null) { + admins = helpdeskDao.getAdminForHelpeskId(helpdeskId); + } + List<Long> userIdList = admins.stream().map(User::getId).collect(Collectors.toList()); + if (ticketIds.contains(ticket.getId()) || userIdList.contains(ticket.getUserId())) { + if (attachmentSource) { + return fetchAttach(ticket); + } else if (file != null) { + return fetchAtt(file, ticket); + } + } + return false; + } + + public boolean fetchAttach(Ticket ticket) { + try { + if (ticket.getAttachmentUrl() != null) { + jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_TICKET_ATTACHMENT, new Object[] { ticket.getId() }); + for (int i = 0; i < ticket.getAttachmentUrl().size(); i++) { + String val = getImagePathValue(ticket, ticket.getAttachmentUrl().get(i)); + addAttachmentToTicket(ticket, val); + } + return true; + } else { + return false; + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + return false; + } + } + + public boolean fetchAtt(MultipartFile file, Ticket ticket) { + try { + String val = uploadFile(file, ticket.getId()); + Long attachmentId = getLastInsertId(val); + if (attachmentId > 0) { + jdbcTemplate.update(Sql.ADD_ATTACHMENT_TO_TICKET, new Object[] { ticket.getId(), attachmentId }); + } + return true; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + return false; + } + } + + private void addAttachmentToTicket(Ticket ticket, String val) { + try { + Long attachmentId = getLastInsertId(val); + if (attachmentId > 0) { + jdbcTemplate.update(Sql.ADD_ATTACHMENT_TO_TICKET, new Object[] { ticket.getId(), attachmentId }); + } + } catch (Exception e) { + LOGGER.error("Erorr while uploading the attachment"); + } + } + + public Long getLastInsertId(String val) { + Long id = (long) 0; + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(Sql.INSERT_ATTACHMENT, returnValColumn); + statement.setString(1, val); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return id; + } + + public String getImagePathValue(Ticket ticket, String url) { + String value = null; + try { + Long organization = MasterDataManager.getUserOrgMap().get(ticket.getUserId()); + value = S3FileManager.attachementfilePath(url, "attachment", ticket.getId(), organization); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return value; + } + + public void addCc(Ticket ticket) { + try { + if (ticket.getCc() != null) { + Long id = ticket.getId(); + Long helpdeskId = ticket.getHelpdeskId(); + List<Long> oldCC = getTicketCC(id); + for (Long admin : ticket.getCc()) { + if (oldCC.contains(admin)) { + oldCC.remove(admin); + } + } + for (int i = 0; i < oldCC.size(); i++) { + User user = superAdminDao.userDetailsByUserId(oldCC.get(i)); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ID, id.toString()); + keyValue.put(JsonKey.HELPDESKID, helpdeskId.toString()); + keyValue.put(JsonKey.HELPDESKNAME, + MasterDataManager.getHelpdeskIdHelpdeskObjectMapping().get(helpdeskId).getName()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.REMOVEDFROMCOPIEDTO, + "remove-copied-to-ticket-aurora.vm"); + } + jdbcTemplate.update(Sql.UserQueries.REMOVE_ALL_TICKET_CC, new Object[] { id }); + for (int i = 0; i < ticket.getCc().size(); i++) { + jdbcTemplate.update(Sql.UserQueries.ADD_CC_TO_TICKET, new Object[] { id, ticket.getCc().get(i) }); + User user = superAdminDao.userDetailsByUserId(ticket.getCc().get(i)); + user.setOrgId(MasterDataManager.getUserOrgMap().get(ticket.getCc().get(i))); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ID, id.toString()); + keyValue.put(JsonKey.HELPDESKID, helpdeskId.toString()); + keyValue.put(JsonKey.HELPDESKNAME, + MasterDataManager.getHelpdeskIdHelpdeskObjectMapping().get(helpdeskId).getName()); + LOGGER.info(MasterDataManager.getHelpdeskIdHelpdeskObjectMapping().get(helpdeskId).getName()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.COPIEDTO, "copied-to-ticket-aurora.vm"); + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + public List<Ticket> addTicketActivityLog(Long ticketId, String activity, Long changesBy) { + List<Ticket> ticketList = null; + try { + jdbcTemplate.update(Sql.Ticket.ADD_ACTIVITY_LOG, + new Object[] { activity, ticketId, DateUtil.getFormattedDateInUTC(new Date()), changesBy }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return ticketList; + } + + @Override + public List<Ticket> getAllTicketsByUserId(Long id) { + List<Ticket> ticketList = new ArrayList<>(); + try { + ticketList = jdbcTemplate.query(Sql.Ticket.GET_ALL_TICKETS, new Object[] { id }, + MasterDataManager.rowMapTicket); + setUserNamesAndWorkflow(ticketList); + for (int i = 0; i < ticketList.size(); i++) { + setTicketCCAndStatus(ticketList, i); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return ticketList; + } + + @Override + public List<Ticket> keepOnlyCreatedAndCopiedToTickets(Long userId, List<Ticket> ticketList) { + List<Long> ticketIds = jdbcTemplate.queryForList(Sql.Ticket.GET_CREATED_AND_COPIED_TO_TICKET_IDS, + new Object[] { userId, userId }, Long.class); + Iterator<Ticket> itr = ticketList.iterator(); + while (itr.hasNext()) { + Ticket ticket = itr.next(); + if (!ticketIds.contains(ticket.getId())) { + itr.remove(); + } + } + return ticketList; + } + + @Override + public List<ChecklistItem> getChecklistItemsForTicket(Long ticketId) { + List<ChecklistItem> checklistItems = new ArrayList<>(); + try { + checklistItems = jdbcTemplate.query(Sql.Helpdesk.GET_CHECKLIST_FOR_TICKET, new Object[] { ticketId }, + new SqlDataMapper().new TicketsChecklistItemMapper()); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in get Checklist for ticket %s", e.getMessage())); + } + return checklistItems; + } + + @Override + public String addDefaultWorkflowForTicketType(TicketTypeDto ticketTypeDto) { + HelpdeskRowRecordMapper helpdesk = helpdeskDao.getHelpdeskForId(ticketTypeDto.getOrgId(), + ticketTypeDto.getHelpdeskId()); + List<Long> workFlowIds = new ArrayList<>(helpdesk.getHelpdeskWorkflowMap().keySet()); + int[] values = null; + String name = ""; + try { + values = jdbcTemplate.batchUpdate(Sql.Ticket.INSERT_WORKFLOW_FOR_TICKET_TYPE, + new BatchPreparedStatementSetter() { + @Override + public void setValues(java.sql.PreparedStatement statement, int i) throws SQLException { + statement.setLong(1, workFlowIds.get(i)); + statement.setLong(2, ticketTypeDto.getId()); + } + + @Override + public int getBatchSize() { + return workFlowIds.size(); + } + }); + name = updateTicketWorkFlowinDB(ticketTypeDto, workFlowIds, values, name); + } catch (Exception ex) { + LOGGER.error(String.format("Exception Occured while mapping Products to Order : %s", ex.getMessage())); + } + return name; + + } + + private String updateTicketWorkFlowinDB(TicketTypeDto ticketTypeDto, List<Long> workFlowIds, int[] values, + String name) { + if (values != null && values.length > 0) { + jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_WORKFLOW, new Object[] { true, + DateUtil.getFormattedDateInUTC(new Date()), workFlowIds.get(0), ticketTypeDto.getId() }); + name = jdbcTemplate.queryForObject(Sql.Ticket.GET_WORKFLOW_NAME, new Object[] { workFlowIds.get(0) }, + String.class); + } + return name; + } + + @Override + public Boolean addChecklistForTicketType(TicketTypeDto ticketTypeDto) { + List<ChecklistItem> helpdesk = helpdeskDao.getChecklistItemsForHelpdesk(ticketTypeDto.getHelpdeskId(), + ticketTypeDto.getTypeId()); + int[] values = null; + try { + values = jdbcTemplate.batchUpdate(Sql.Ticket.INSERT_CHECKLIST_FOR_TICKET_TYPE, + new BatchPreparedStatementSetter() { + @Override + public void setValues(java.sql.PreparedStatement statement, int i) throws SQLException { + statement.setLong(1, ticketTypeDto.getId()); + statement.setLong(2, helpdesk.get(i).getId()); + } + + @Override + public int getBatchSize() { + return helpdesk.size(); + } + }); + return (values != null && values.length > 0); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while adding checklist type for a ticket : %s", + e.getMessage())); + return false; + } + } + + @Override + public Boolean deleteWorkflowForTicketType(Long ticketId) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Ticket.DELETE_WORKFLOW_FOR_TICKET_TYPE, new Object[] { ticketId }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE, + e.getMessage())); + return false; + } + return (status > 0); + } + + @Override + public Boolean deleteChecklistForTicketType(TicketTypeDto ticketTypeDto) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Helpdesk.DELETE_CHECKLIST_FOR_TICKET, + new Object[] { ticketTypeDto.getId() }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE, + e.getMessage())); + return false; + } + return (status > 0); + } + + @Override + public List<TicketWorkflowDto> getWorkflowForTicket(Long ticketId) { + List<TicketWorkflowDto> ticketWorkFlow = new ArrayList<>(); + try { + ticketWorkFlow = jdbcTemplate.query(Sql.Helpdesk.GET_WORKFLOW_FOR_TICKET, new Object[] { ticketId }, + new SqlDataMapper().new TicketWorkFlowMapper()); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in getchecklist for ticket %s", e.getMessage())); + } + return ticketWorkFlow; + } + + public Map<Long, List<TicketWorkflowDto>> getWorkflowForTicketList(List<Long> ticketIdList) { + TicketWorkFlowMapperV2 mapper = new SqlDataMapper().new TicketWorkFlowMapperV2(); + if (!ticketIdList.isEmpty()) { + String queryAppend = getIdQuery(ticketIdList); + try { + jdbcTemplate.query(Sql.Helpdesk.GET_WORKFLOW_FOR_TICKET_LIST + queryAppend, new Object[] {}, mapper); + } catch (Exception e) { + LOGGER.error(String.format("Encountered exception in getchecklist for ticket %s", e.getMessage())); + } + } + return mapper.getTicketWorkflowMap(); + } + + private static String getIdQuery(final List<Long> idList) { + final StringBuilder query = new StringBuilder("("); + if (!idList.isEmpty()) { + query.append(idList.get(0).toString()); + for (int i = 1; i < idList.size(); i++) { + query.append(", " + idList.get(i)); + } + } + return query.append(")").toString(); + } + + @Override + public Boolean updateNotesToTicket(Long requestedBy, Long ticketId, String notes) { + try { + jdbcTemplate.update(Sql.Ticket.UPDATE_NOTES_TO_TICKETS, new Object[] { notes, ticketId }); + addTicketActivityLog(ticketId, "Ticket Notes has been updated", requestedBy); + return true; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + @Override + public Boolean addUpdateUpdatesToTicket(Updates update) { + + try { + if (update.getId() != null) { + sendRepliesToReviews(update); + jdbcTemplate.update(Sql.Ticket.UPDATE_UPDATES, new Object[] { update.getUpds(), update.isActive(), + DateUtil.getFormattedDateInUTC(new Date()), update.getId() }); + } else { + sendRepliesToReviews(update); + List<Long> ccList = getTicketCC(update.getTicketId()); + Long requestedBy = jdbcTemplate.queryForObject(Apps.GET_REQUESTED_BY, + new Object[] { update.getTicketId() }, Long.class); + ccList.add(requestedBy); + ccList.remove(update.getCreatedBy()); + jdbcTemplate.update(Sql.Ticket.ADD_UPDATES, new Object[] { update.getUpds(), update.getCreatedBy(), + update.getTicketId(), DateUtil.getFormattedDateInUTC(new Date()) }); + for (int i = 0; i < ccList.size(); i++) { + sendMailToCC(update, ccList, i); + } + } + return true; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + private void sendMailToCC(Updates update, List<Long> ccList, int i) { + try { + User user = superAdminDao.userDetailsByUserId(ccList.get(i)); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ID, update.getTicketId().toString()); + keyValue.put(JsonKey.UPDATE, update.getUpds()); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.UPDATES, "ticket-status-update-aurora.vm"); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + @Override + public List<Updates> getUpdatesForTicket(Long id) { + List<Updates> update = null; + try { + update = jdbcTemplate.query(Sql.Ticket.GET_UPDATES, new Object[] { id }, MasterDataManager.rowMapUpdate); + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return update; + } + + @Override + public Long getTemplatesVersion() { + Long version = 0l; + try { + version = jdbcTemplate.queryForObject(Sql.Ticket.GET_VERSION_FOR_TEMPLATES, Long.class); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_DELETING_WORKFLOW_STAGES_FOR_A_HELPDESK_TYPE, + e.getMessage())); + } + return version; + } + + @Override + public boolean updateTemplateVersion(Long versionTimeStamp) { + LOGGER.info("Updating the Template Version Timestamp"); + try { + jdbcTemplate.update(Sql.Ticket.UPDATE_VERSION_TIMESTAMP, new Object[] { versionTimeStamp }); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while updating the Version TimeStamp : %s", + e.getMessage())); + return false; + } + return true; + } + + @Override + public Ticket getTicketsById(Long userId, Long id) { + List<Ticket> ticketList = null; + try { + ticketList = jdbcTemplate.query(Sql.Ticket.GET_TICKET_BY_ID, new Object[] { id }, + MasterDataManager.rowMapTicket); + for (int i = 0; i < ticketList.size(); i++) { + List<Long> cc = getTicketCC(ticketList.get(i).getId()); + ticketList.get(i).setCc(cc); + List<String> attachment = getTicketAttachment(ticketList.get(i).getId()); + ticketList.get(i).setAttachmentUrl(attachment); + } + + if (!ticketList.isEmpty()) { + List<ChecklistItem> checklist = getChecklistItemsForTicket(id); + ticketList.get(0).setChecklist(checklist); + ticketList = setUserNamesAndWorkflow(ticketList); + List<TicketWorkflowDto> data = ticketList.get(0).getWorkflowStages(); + for (int i = 0; i < data.size(); i++) { + if (data.get(i).getStatus()) { + ticketList.get(0).setStatus(data.get(i).getName()); + } + } + List<String> att = fetchAtt(ticketList); + ticketList.get(0).setAttachmentUrl(att); + ticketList.get(0).setTags(tagDao.getAllTicketTags(id)); + return ticketList.get(0); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return null; + } + + private List<String> fetchAtt(List<Ticket> ticketList) { + List<String> att = null; + try { + att = new ArrayList<>(); + S3Config s3values = superAdminDao.getS3Access(); + if (ticketList.get(0).getAttachmentUrl() != null) { + for (int i = 0; i < ticketList.get(0).getAttachmentUrl().size(); i++) { + if (ticketList.get(0).getAttachmentUrl() != null) { + fetchAttachment(ticketList, att, s3values, i); + } + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return att; + } + + private void fetchAttachment(List<Ticket> ticketList, List<String> att, S3Config s3values, int i) { + try { + String url = null; + url = S3FileManager.getPreSignedURL(s3values, ticketList.get(0).getAttachmentUrl().get(i)); + att.add(url); + } catch (Exception e) { + fetchFile(ticketList, i, e); + } + } + + private void fetchFile(List<Ticket> ticketList, int i, Exception e) { + try { + byte[] file = getFile(ticketList.get(0).getAttachmentUrl().get(i)); + ticketList.get(0).setImg(file); + } catch (Exception e1) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + public byte[] getFile(String attachmentUrl) { + try { + byte[] content = null; + if (!StringUtils.isBlank(attachmentUrl)) { + Path path = Paths.get(Constants.ATTACHMENT_FOLDER + attachmentUrl); + content = readBytes(content, path); + } + return content; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return new byte[0]; + } + + private byte[] readBytes(byte[] content, Path path) { + try { + content = Files.readAllBytes(path); + } catch (final IOException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return content; + } + + private List<Ticket> setUserNamesAndWorkflow(List<Ticket> newTicketList) { + List<Long> ticketIdList = newTicketList.stream().map(Ticket::getId).collect(Collectors.toList()); + Map<Long, List<TicketWorkflowDto>> ticketWorkflowMap = getWorkflowForTicketList(ticketIdList); + for (Ticket ticket : newTicketList) { + if (ticket.getRequestedBy() != null && StringUtils + .isNotBlank(MasterDataManager.getUserIdAndUserNameMap().get(ticket.getRequestedBy()))) { + ticket.setRequestedByName(MasterDataManager.getUserIdAndUserNameMap().get(ticket.getRequestedBy())); + } + if (ticketWorkflowMap.get(ticket.getId()) != null && !ticketWorkflowMap.get(ticket.getId()).isEmpty()) { + ticket.setWorkflowStages(ticketWorkflowMap.get(ticket.getId())); + } + } + return newTicketList; + } + + @Override + public TicketCount getNoOfTickets(Long userId) { + try { + TicketCount ticketCount = new TicketCount(); + List<Ticket> tickets = getAllTicketsByUserId(userId); + Long pinnedTicketCount = 0L; + Long closedTicketCount = 0L; + if (!tickets.isEmpty()) { + for (int i = 0; i < tickets.size(); i++) { + if (getPinnedTicket(tickets, i)) { + pinnedTicketCount = pinnedTicketCount + 1; + } + List<TicketWorkflowDto> workflow = getWorkflowForTicket(tickets.get(i).getId()); + for (int j = 0; j < workflow.size(); j++) { + if (workflow.get(j).getStatus() && workflow.get(j).getName().equals("Closed")) { + closedTicketCount = closedTicketCount + 1; + } + } + + } + } + ticketCount.setCreatedTicketCount(Long.valueOf(tickets.size())); + ticketCount.setPinnedTicketCount(pinnedTicketCount); + ticketCount.setClosedTicketCount(closedTicketCount); + return ticketCount; + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return null; + + } + + public boolean getPinnedTicket(List<Ticket> tickets, int i) { + return !ProjectUtil.isObjectNull(tickets.get(i).getPinnedTicket()) && tickets.get(i).getPinnedTicket(); + } + + public List<Long> getTicketCC(Long id) { + try { + return jdbcTemplate.queryForList(Sql.UserQueries.GET_TICKET_CC, new Object[] { id }, Long.class); + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return new ArrayList<>(); + + } + + public List<String> getTicketAttachment(Long id) { + try { + return jdbcTemplate.queryForList(Sql.UserQueries.GET_TICKET_ATTACHMENT, new Object[] { id }, String.class); + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return new ArrayList<>(); + + } + + @Override + public List<Ticket> getAllTicketsByAppId(Long appId) { + List<Ticket> ticketList = null; + try { + ticketList = jdbcTemplate.query(Sql.Ticket.GET_ALL_TICKETS_BY_APP_ID, new Object[] { appId }, + MasterDataManager.rowMapTicket); + for (int i = 0; i < ticketList.size(); i++) { + setTicketCCAndStatus(ticketList, i); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return ticketList; + } + + private void setTicketCCAndStatus(List<Ticket> ticketList, int i) { + List<Long> cc = getTicketCC(ticketList.get(i).getId()); + ticketList.get(i).setCc(cc); + List<TicketWorkflowDto> workFlow = getWorkflowForTicket(ticketList.get(i).getId()); + for (int j = 0; j < workFlow.size(); j++) { + if (workFlow.get(j).getStatus()) { + ticketList.get(i).setStatus(workFlow.get(j).getName()); + } + } + } + + @Override + public boolean updateTicketBasic(MultipartFile file, Ticket ticket) { + ticket.setUpdatedTime(DateUtil.getFormattedDateInUTC(new Date())); + Long loggedInUserId = ticket.getUserId(); + int status = 0; + Long id = ticket.getId(); + Ticket oldticket = getTicketsById(loggedInUserId, id); + List<Long> admins = helpdeskDao.getHelpdeskAdmins(oldticket.getHelpdeskId()); + Ticket oldestTicket = oldticket; + try { + if (!admins.contains(loggedInUserId)) { + List<Ticket> ticketList = new ArrayList<>(); + ticketList.add(oldticket); + List<Ticket> t = keepOnlyCreatedAndCopiedToTickets(loggedInUserId, ticketList); + if (!t.isEmpty()) { + oldticket = t.get(0); + oldestTicket = oldticket; + } + } else { + status = jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET, new Object[] { ticket.getPriority(), + ticket.getNotes(), ticket.getActive(), ticket.getUpdatedTime(), id }); + } + if (checkIfLoggedInUserIsTheCreatorOfTheTicket(loggedInUserId, oldticket, admins)) { + ticket.setHelpdeskId(oldticket.getHelpdeskId()); + addCc(ticket); + status = jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_DESCRIPTION, + new Object[] { ticket.getDescription(), id }); + } + Ticket newticket = getTicketsById(loggedInUserId, id); + Ticket t = new Ticket(); + t.setId(id); + if (newticket != null) { + if (!oldestTicket.getDescription().equals(newticket.getDescription())) { + addTicketActivityLog(id, "Ticket Description has been updated to " + newticket.getDescription(), + loggedInUserId); + t.setDescription(newticket.getDescription()); + } + if (!oldestTicket.getPriority().equals(newticket.getPriority())) { + addTicketActivityLog(id, "Ticket priority has been updated to " + newticket.getPriority(), + loggedInUserId); + t.setPriority(newticket.getPriority()); + } + if (newticket.getNotes() != null && oldestTicket.getNotes() != null + && !oldestTicket.getNotes().equals(newticket.getNotes())) { + addTicketActivityLog(id, "Ticket Notes has been updated to " + newticket.getNotes(), + loggedInUserId); + } + } else { + addTicketActivityLog(id, "Ticket Status has been updated to " + ticket.getActive(), loggedInUserId); + t.setActive(ticket.getActive()); + } + + t.setCc(ticket.getCc()); + t.setOperation(UPDATE); + t.setUpdatedTimeTS(new Date().getTime()); + t.setUpdatedTime(ticket.getUpdatedTime()); + ticketsRequestInterceptor.addData(t); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_UPDATING_TICKET_S, e.getMessage())); + return false; + } + return (status > 0); + } + + public boolean checkIfLoggedInUserIsTheCreatorOfTheTicket(Long loggedInUserId, Ticket oldticket, + List<Long> admins) { + return oldticket.getRequestedBy().equals(loggedInUserId) || admins.contains(loggedInUserId); + } + + public String convertFromTimestampToUTC(Long timestamp) { + try { + Date d = new Date(timestamp * 1000); + DateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + return f.format(d); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return ""; + } + + public String uploadFile(MultipartFile file, long ticketId) { + try { + if (!new File(Constants.ATTACHMENT_FOLDER).exists()) { + if (new File(Constants.ATTACHMENT_FOLDER).mkdir()) { + LOGGER.info("Directory is created!"); + } else { + LOGGER.error("Failed to create directory!"); + } + } else { + LOGGER.info("Folder exist"); + } + User user = new User(); + byte[] bytes = file.getBytes(); + String newFileName = ticketId + "." + file.getOriginalFilename().split(".")[1]; + String val = "\\" + ticketId + "\\" + newFileName; + Path path = Paths.get(Constants.ATTACHMENT_FOLDER + val); + if (!StringUtils.isBlank(path.toString())) { + LOGGER.info("Path before write: {}", path); + } + Path path1 = Files.write(path, bytes); + if (!StringUtils.isBlank(path1.toString())) { + LOGGER.info("Path after write : {}", path1); + } + Long attachmentId = getLastInsertId(val); + if (attachmentId > 0) { + jdbcTemplate.update(Sql.ADD_ATTACHMENT_TO_TICKET, new Object[] { ticketId, attachmentId }); + } + jdbcTemplate.update(Sql.INSERT_ATTACHMENT, new Object[] { val, ticketId }); + user.setImagePath(val); + return user.getImagePath(); + } catch (IOException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return null; + } + + @Override + public boolean updateTicketType(TicketTypeDto ticketTypeDto, Long userId) { + int status = 0; + try { + status = jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_TYPE, + new Object[] { ticketTypeDto.getTypeId(), ticketTypeDto.getId() }); + deleteWorkflowForTicketType(ticketTypeDto.getId()); + String stat = addWorkFlowForTicketType(ticketTypeDto); + deleteChecklistForTicketType(ticketTypeDto); + addChecklistForTicketType(ticketTypeDto); + addTicketActivityLog(ticketTypeDto.getId(), + "Ticket Type has been updated to" + ticketTypeDto.getTypeId().toString(), userId); + Ticket newticket = new Ticket(); + newticket.setType(ticketTypeDto.getTypeId()); + newticket.setOperation(UPDATE); + newticket.setStatus(stat); + newticket.setUpdatedTime(DateUtil.getFormattedDateInUTC(new Date())); + newticket.setUpdatedTimeTS(new Date().getTime()); + ticketsRequestInterceptor.addData(newticket); + + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while updating ticket type : %s", e.getMessage())); + return false; + } + return (status > 0); + } + + private String addWorkFlowForTicketType(TicketTypeDto ticketTypeDto) { + List<HelpdeskDto> helpdesk = helpdeskService.getHelpdeskById(ticketTypeDto.getOrgId(), + ticketTypeDto.getHelpdeskId()); + List<HelpdeskWorkflowDto> workFlowStages = new ArrayList<>(); + List<HelpdeskTypeDto> helpdeskTypes = helpdesk.get(0).getTypes(); + for (int i = 0; i < helpdeskTypes.size(); i++) { + if (helpdeskTypes.get(i).getId().equals(ticketTypeDto.getTypeId())) { + workFlowStages = helpdeskTypes.get(i).getWorkflowStages(); + } + } + List<Long> workFlowIds = workFlowStages.stream().map(HelpdeskWorkflowDto::getId).collect(Collectors.toList()); + int[] values = null; + String name = ""; + try { + values = jdbcTemplate.batchUpdate(Sql.Ticket.INSERT_WORKFLOW_FOR_TICKET_TYPE, + new BatchPreparedStatementSetter() { + @Override + public void setValues(java.sql.PreparedStatement statement, int i) throws SQLException { + statement.setLong(1, workFlowIds.get(i)); + statement.setLong(2, ticketTypeDto.getId()); + } + + @Override + public int getBatchSize() { + return workFlowIds.size(); + } + }); + if (values != null && values.length > 0) { + jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_WORKFLOW, + new Object[] { true, DateUtil.getFormattedDateInUTC(new Date()), workFlowStages.get(0).getId(), + ticketTypeDto.getId() }); + name = jdbcTemplate.queryForObject(Sql.Ticket.GET_WORKFLOW_NAME, new Object[] { workFlowIds.get(0) }, + String.class); + } + } catch (Exception ex) { + LOGGER.error(String.format("Exception Occured while mapping the new workflow : %s", ex.getMessage())); + } + return name; + } + + @Override + public boolean updateTicketStatus(Ticket ticket) { + int status = 0; + List<TicketWorkflowDto> oldWorkFlow = getWorkflowForTicket(ticket.getId()); + String oldStatus = ""; + String newStatus = ""; + for (int i = 0; i < oldWorkFlow.size(); i++) { + if (oldWorkFlow.get(i).getStatus()) { + oldStatus = oldWorkFlow.get(i).getName(); + } + } + try { + for (int i = 0; i < ticket.getWorkflowStages().size(); i++) { + status = jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_WORKFLOW, + new Object[] { ticket.getWorkflowStages().get(i).getStatus(), + DateUtil.getFormattedDateInUTC(new Date()), + ticket.getWorkflowStages().get(i).getWorkFlowId(), ticket.getId() }); + } + List<TicketWorkflowDto> workFlow = getWorkflowForTicket(ticket.getId()); + for (int i = 0; i < workFlow.size(); i++) { + if (workFlow.get(i).getStatus()) { + newStatus = workFlow.get(i).getName(); + } + } + addTicketActivityLog(ticket.getId(), + "Ticket Request Status has been updated from " + oldStatus + " to " + newStatus, + ticket.getRequestedBy()); + Ticket newticket = new Ticket(); + newticket.setId(ticket.getId()); + newticket.setOperation(UPDATE); + newticket.setStatus(newStatus); + newticket.setUpdatedTime(DateUtil.getFormattedDateInUTC(new Date())); + newticket.setUpdatedTimeTS(new Date().getTime()); + User user = superAdminDao.userDetailsByUserId(ticket.getRequestedBy()); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ID, ticket.getId().toString()); + keyValue.put(JsonKey.HELPDESKID, ticket.getHelpdeskId().toString()); + keyValue.put(JsonKey.HELPDESK_NAME, + MasterDataManager.getHelpdeskIdHelpdeskObjectMapping().get(ticket.getHelpdeskId()).getName()); + keyValue.put(JsonKey.OLDSTATUS, oldStatus); + keyValue.put(JsonKey.NEWSTATUS, newStatus); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.STATUS_CHANGE, "ticket-status-update-aurora.vm"); + ticketsRequestInterceptor.addData(newticket); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_UPDATING_TICKET_S, e.getMessage())); + return false; + } + return (status > 0); + } + + @Override + public List<TicketElastic> getTicketDetailsByHelpdeskId(Ticket ticket) { + RestHighLevelClient client = connectToElasticSearch(); + SearchResponse searchResponse = null; + List<TicketElastic> mapper = new ArrayList<>(); + List<Long> admins = helpdeskDao.getHelpdeskAdmins(ticket.getHelpdeskId()); + List<User> user = helpdeskDao.getUsersForHelpeskId(ticket.getHelpdeskId()); + Long userId = ticket.getUserId(); + ticket.setCc(new ArrayList<>(Arrays.asList(userId))); + List<Long> userIds = user.stream().map(User::getId).collect(Collectors.toList()); + if (userId > 0) { + try { + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + setBoolQuery(ticket, admins, userId, userIds, boolQuery); + searchSourceBuilder.query(boolQuery); + commonQuery(ticket, searchSourceBuilder); + if (!searchSourceBuilder.toString().equals("{}")) { + searchResponse = searchFromTicketElasticData(client, searchSourceBuilder); + SearchHit[] hit = searchResponse.getHits().getHits(); + long total = searchResponse.getHits().getTotalHits(); + for (SearchHit hits : hit) { + String sourceAsMap = hits.getSourceAsString(); + Gson g = new Gson(); + TicketElastic ticketElastic = g.fromJson(sourceAsMap, TicketElastic.class); + ticketElastic.setTotal(total); + mapper.add(ticketElastic); + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + return mapper; + } + + public void setBoolQuery(Ticket ticket, List<Long> admins, Long userId, List<Long> userIds, + BoolQueryBuilder boolQuery) { + if (admins.contains(userId)) { + boolQuery.must(QueryBuilders.matchQuery("helpdeskId", ticket.getHelpdeskId())); + boolQuery.must(QueryBuilders.matchQuery("active", "true")); + } else if (userIds.contains(userId)) { + boolQuery.must(QueryBuilders.matchQuery("helpdeskId", ticket.getHelpdeskId())); + boolQuery.must(QueryBuilders.matchQuery("active", "true")); + BoolQueryBuilder newBoolQuery = QueryBuilders.boolQuery(); + newBoolQuery.should(QueryBuilders.termsQuery(Sql.Ticket.CC, ticket.getCc())); + newBoolQuery.should(QueryBuilders.matchQuery("requestedBy", ticket.getUserId())); + boolQuery.must(newBoolQuery); + } + if (ticket.getSourceId() != null) { + boolQuery.filter(QueryBuilders.termQuery(Sql.Ticket.SOURCE_ID, ticket.getSourceId())); + } + if (StringUtils.isNotBlank(ticket.getSearchKeyword())) { + boolQuery + .filter(QueryBuilders.wildcardQuery(Sql.Ticket.DESCRIPTION, "*" + ticket.getSearchKeyword() + "*")); + } + if (!ProjectUtil.isObjectListNullOrEmpty(ticket.getFilterStatus()) && !ticket.getFilterStatus().isEmpty()) { + boolQuery.filter(QueryBuilders.termsQuery(Sql.Ticket.STATUS, ticket.getFilterStatus())); + } + if (!ProjectUtil.isObjectListNullOrEmpty(ticket.getSelectedTags()) && !ticket.getSelectedTags().isEmpty()) { + boolQuery.filter(QueryBuilders.termsQuery(Sql.Ticket.TAGS, ticket.getSelectedTags())); + } + } + + public static <T, U> List<U> convertIntListToStringList(List<T> listOfInteger, Function<T, U> function) { + return listOfInteger.stream().map(function).collect(Collectors.toList()); + } + + private void commonQuery(Ticket ticket, SearchSourceBuilder searchSourceBuilder) { + if (!StringUtils.isBlank(ticket.getFilterCTUT())) { + searchSourceBuilder.sort(ticket.getFilterCTUT(), org.elasticsearch.search.sort.SortOrder.DESC); + } else { + searchSourceBuilder.sort("createdTimeTS", org.elasticsearch.search.sort.SortOrder.DESC); + } + if (!StringUtils.isBlank(String.valueOf(ticket.getFrom())) && ticket.getFrom() >= 0) { + searchSourceBuilder.from(ticket.getFrom()); + } + if (!StringUtils.isBlank(String.valueOf(ticket.getSize())) && ticket.getSize() >= 0) { + searchSourceBuilder.size(ticket.getSize()); + } else { + searchSourceBuilder.size(25); + } + searchSourceBuilder.fetchSource(Constants.getIncludeFields(), Constants.getExcludeFields()); + } + + @Override + public List<Ticket> getFeedBacksFromAuroraSdk() { + RestHighLevelClient client = connectToElasticSearch(); + SearchResponse searchResponse = null; + List<Ticket> mapper = new ArrayList<>(); + try { + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() + .query(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery())).size(700); + searchResponse = searchFromAuroraSdkData(client, searchSourceBuilder); + SearchHit[] hit = searchResponse.getHits().getHits(); + long total = searchResponse.getHits().getTotalHits(); + for (SearchHit hits : hit) { + String sourceAsMap = hits.getSourceAsString(); + Gson g = new Gson(); + Ticket t = g.fromJson(sourceAsMap, Ticket.class); + mapper.add(t); + } + BulkRequest request = new BulkRequest(); + for (int i = 0; i < total; i++) { + mapper.get(i).setSourceId(1L); + Ticket tkt = addTicket(mapper.get(i)); + if (tkt != null) { + Map<String, Object> jsonMap = ticketsRequestInterceptor.createJsonMap(tkt); + request.add(new IndexRequest(elasticsearchIndex, elasticsearchType, tkt.getId().toString()) + .source(jsonMap)); + } + } + client.bulk(request); + client.close(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return mapper; + } + + @Override + public Map<String, Long> getTicketsCountPerMonthPerUser(Analytics analytics) { + RestHighLevelClient client = connectToElasticSearch(); + SearchResponse searchResponse = null; + Map<String, Long> monthCountMap = new HashMap<>(); + try { + DateHistogramInterval dateHistogramInterval = DateHistogramInterval.MONTH; + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() + .query(QueryBuilders.boolQuery() + .must(QueryBuilders.rangeQuery(CREATED_TIME).gte(analytics.getStartDate()) + .lte(analytics.getEndDate())) + .filter(QueryBuilders.termQuery(Sql.Ticket.REQUESTEDBY, analytics.getUserId()))) + .aggregation(AggregationBuilders.dateHistogram(COUNT).field(CREATED_TIME) + .dateHistogramInterval(dateHistogramInterval)) + .size(0); + searchResponse = searchFromTicketElasticData(client, searchSourceBuilder); + Histogram hist = searchResponse.getAggregations().get(COUNT); + for (Histogram.Bucket bucket : hist.getBuckets()) { + monthCountMap.put(bucket.getKeyAsString().split(T)[0], bucket.getDocCount()); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return monthCountMap; + } + + private RestHighLevelClient connectToElasticSearch() { + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTIC, EL_STIC123)); + HttpClientConfigCallback r = new RestClientBuilder.HttpClientConfigCallback() { + @Override + public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } + }; + return new RestHighLevelClient( + RestClient.builder(new HttpHost(elasticsearchUrl)).setHttpClientConfigCallback(r)); + } + + private SearchResponse searchFromTicketElasticData(RestHighLevelClient client, + SearchSourceBuilder searchSourceBuilder) throws IOException { + SearchRequest searchRequest = new SearchRequest(elasticsearchIndex).types(elasticsearchType) + .source(searchSourceBuilder); + SearchResponse searchResponse = client.search(searchRequest); + client.close(); + return searchResponse; + } + + private SearchResponse searchFromAuroraSdkData(RestHighLevelClient client, SearchSourceBuilder searchSourceBuilder) + throws IOException { + SearchRequest searchRequest = new SearchRequest(FEEDBACK_D1).types(EVENT).source(searchSourceBuilder); + SearchResponse searchResponse = client.search(searchRequest); + client.close(); + return searchResponse; + } + + @Override + public boolean updateTicketChecklist(Ticket ticket) { + int status = 0; + try { + for (int i = 0; i < ticket.getChecklist().size(); i++) { + status = jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_CHECKLIST, + new Object[] { ticket.getChecklist().get(i).getChecked(), ticket.getChecklist().get(i).getId(), + ticket.getId() }); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_WHILE_UPDATING_TICKET_S, e.getMessage())); + return false; + } + return (status > 0); + } + + @Override + public List<ActivityLog> getActivityLogsPerTicket(Long id) { + List<ActivityLog> activityLogs = null; + try { + activityLogs = jdbcTemplate.query(Sql.Ticket.GET_ACTIVITY_LOGS, new Object[] { id }, + MasterDataManager.rowMapActivityLogs); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return activityLogs; + } + + @Override + public List<ActivityLog> getActivityLogsPerUser(Long id) { + List<ActivityLog> activities = new ArrayList<>(); + try { + activities = jdbcTemplate.query(Sql.Ticket.GET_ACTIVITY_LOGS_PER_USER, new Object[] { id, id }, + MasterDataManager.rowMapActivityLogs); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return activities; + } + + @Override + public boolean pinTicket(Ticket ticket) { + try { + if (ticket.getPinnedTicket() != null) { + jdbcTemplate.update(Sql.Ticket.UPDATE_TICKET_PIN, + new Object[] { ticket.getPinnedTicket(), ticket.getId() }); + Ticket newticket = new Ticket(); + newticket.setId(ticket.getId()); + newticket.setPinnedTicket(ticket.getPinnedTicket()); + newticket.setOperation(UPDATE); + newticket.setUpdatedTime(DateUtil.getFormattedDateInUTC(new Date())); + newticket.setUpdatedTimeTS(new Date().getTime()); + ticketsRequestInterceptor.addData(newticket); + } + return true; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + @Override + public boolean sendRepliesToReviews(Updates updates) { + try { + String reviewId = jdbcTemplate.queryForObject(Sql.Ticket.GET_REVIEW_ID, + new Object[] { updates.getTicketId() }, String.class); + if (reviewId != null) { + Long id = jdbcTemplate.queryForObject(Sql.Ticket.GET_ORG_ID_FROM_TICKET_ID, + new Object[] { updates.getTicketId() }, Long.class); + String appName = jdbcTemplate.queryForObject(Sql.Ticket.GET_APP_URL_FROM_TICKET_ID, + new Object[] { updates.getTicketId() }, String.class); + if (checkIfIDAndAppNameIsNotNull(id, appName)) { + RestTemplate restTemplate = new RestTemplate(); + Access exp = userService.getReviewConfig(id); + AccessResponse accessResponse = new AccessResponse(); + accessResponse = transformTOJSONString(restTemplate, exp, accessResponse); + final String uri = Constants.HTTPS_WWW_GOOGLEAPIS_COM_ANDROIDPUBLISHER_V3_APPLICATIONS + appName + + REVIEWS + reviewId + REPLY; + HttpHeaders header = new HttpHeaders(); + header.setContentType(MediaType.APPLICATION_JSON); + header.set(Constants.HEADER_STRING, Constants.TOKEN_PREFIX + accessResponse.getAccessToken()); + JSONObject request = new JSONObject(); + if (extractUpdates(updates)) { + request.put(REPLY_TEXT, updates.getUpds()); + } else { + return false; + } + HttpEntity<String> entity = new HttpEntity<>(request.toString(), header); + ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class); + if (matchStatus(result)) { + return true; + } + } + + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + public boolean checkIfIDAndAppNameIsNotNull(Long id, String appName) { + return id != null && appName != null; + } + + public AccessResponse transformTOJSONString(RestTemplate restTemplate, Access exp, AccessResponse accessResponse) { + if (!ProjectUtil.isObjectNull(exp)) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + Map<String, Object> map = new HashMap<>(); + map.put(Constants.GRANT_TYPE, Constants.REFRESH_TOKEN); + map.put(Constants.CLIENT_ID, exp.getClientId()); + map.put(Constants.CLIENT_SECRET, exp.getClientSecret()); + map.put(Constants.REFRESH_TOKEN, exp.getRefreshToken()); + HttpEntity<Map<String, Object>> request = new HttpEntity<>(map, headers); + ResponseEntity<String> response = restTemplate + .postForEntity(Constants.HTTPS_ACCOUNTS_GOOGLE_COM_O_OAUTH2_TOKEN, request, String.class); + if (!StringUtils.isEmpty(response.getBody())) { + List<Object> chainrSpecJSON = JsonUtils.classpathToList(Constants.ACCESSTOKENSPEC_JSON); + Chainr chainr = Chainr.fromSpec(chainrSpecJSON); + Object transformedOutput = chainr.transform(JsonUtils.jsonToObject(response.getBody())); + Gson g = new Gson(); + accessResponse = g.fromJson(JsonUtils.toJsonString(transformedOutput), AccessResponse.class); + } + } + return accessResponse; + } + + public boolean extractUpdates(Updates updates) { + return updates.getUpds() != null && !updates.getUpds().isEmpty(); + } + + public boolean matchStatus(ResponseEntity<String> result) { + return result.getStatusCode() == HttpStatus.OK; + } + +} diff --git a/src/main/java/org/upsmf/grievance/dao/impl/UserDaoImpl.java b/src/main/java/org/upsmf/grievance/dao/impl/UserDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..1f2b581986184410f2cedb1a8254ce518e54a7e7 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dao/impl/UserDaoImpl.java @@ -0,0 +1,912 @@ +package org.upsmf.grievance.dao.impl; + +import static org.upsmf.grievance.util.Constants.TOKEN_PREFIX; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.velocity.VelocityContext; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; +import org.elasticsearch.client.RestHighLevelClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import com.bazaarvoice.jolt.Chainr; +import com.bazaarvoice.jolt.JsonUtils; +import com.google.gson.Gson; +import org.upsmf.grievance.config.JwtTokenUtil; +import org.upsmf.grievance.dao.ApplicationDao; +import org.upsmf.grievance.dao.RoleDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.dao.TicketDao; +import org.upsmf.grievance.dao.UserDao; +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.LoginDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.interceptor.TicketsRequestInterceptor; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.AccessResponse; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.Rev; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.UserAuthentication; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.RolesUserMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserDetailsMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserRoleMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserRolesActionsMapper; +import org.upsmf.grievance.service.UserService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.DateUtil; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.OneWayHashing; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.SendMail; +import org.upsmf.grievance.util.Sql; +import org.upsmf.grievance.util.Sql.UserQueries; + +@Repository(Constants.USER_DAO) +public class UserDaoImpl implements UserDao { + + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + + private static final String EL_STIC123 = "El@stic123"; + + private static final String ELASTIC = "elastic"; + + public static final Logger LOGGER = LoggerFactory.getLogger(UserDaoImpl.class); + + @Value("${elk.data.up}") + private boolean elkDataUp; + + @Value("${elasticsearch.url}") + private String elasticsearchUrl; + + @Value("${elasticsearch.index}") + private String elasticsearchIndex; + + @Value("${elasticsearch.type}") + private String elasticsearchType; + + @Autowired + private TicketsRequestInterceptor ticketsRequestInterceptor; + + @Autowired + JdbcTemplate jdbcTemplate; + + @Autowired + RoleDao roleDao; + + @Autowired + JwtTokenUtil jwtTokenUtil; + + @Autowired + UserService userService; + + @Autowired + SuperAdminDao superAdminDao; + + @Autowired + TicketDao ticketDao; + + @Autowired + ApplicationDao applicationDao; + + public UserDaoImpl(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public List<Action> findAllActionsByRoleID(Integer roleID) { + List<Action> actions = new ArrayList<>(); + try { + actions = jdbcTemplate.query(UserQueries.GET_USER_ACTIONS, new Object[] { roleID }, + MasterDataManager.rowMapAction); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching all the actions by Role ID %s", + e.getMessage())); + } + return actions; + } + + @Override + public User findByUsername(String username, Boolean withRoles, Boolean withActions) { + User user = null; + try { + if (withRoles && withActions) { + UserRolesActionsMapper mapper = new SqlDataMapper().new UserRolesActionsMapper(); + user = jdbcTemplate + .query(UserQueries.SELECT_USER_ROLES_ACTIONS_ON_USERNAME, new Object[] { username }, mapper) + .get(0); + user.setRoles(mapper.getRoleMap().values().stream().collect(Collectors.toList())); + user.setActions(mapper.getActionMap().values().stream().collect(Collectors.toList())); + } else if (withRoles) { + user = jdbcTemplate.query(UserQueries.SELECT_USER_ROLES_ON_USERNAME, new Object[] { username }, + new SqlDataMapper().new UserRolesMapper()).get(0); + user.setRoles(new SqlDataMapper().new UserRolesMapper().getRoleMap().values().stream() + .collect(Collectors.toList())); + } else { + user = jdbcTemplate.query(UserQueries.SELECT_USER_ON_USERNAME, new Object[] { username }, + new SqlDataMapper().new UserMapper()).get(0); + } + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching the User by Username : %s", + e.getMessage())); + } + return user; + } + + @Override + public List<User> findOne(Long id) { + List<User> data = new ArrayList<>(); + try { + data = jdbcTemplate.query(UserQueries.USER_PROFILE_FETCH, new Object[] { id }, + new SqlDataMapper().new UserDetailsMapper()); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching the User By ID : %s", e.getMessage())); + } + return data; + } + + @Override + public UserAuthentication findOneUserAuthentication(Long id) { + UserAuthentication user = null; + try { + user = jdbcTemplate.query(UserQueries.GET_USER_AUTH_DETAILS, new Object[] { id }, + new SqlDataMapper().new UserAuthenticationMapper()).get(0); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching the Users Auth Details : %s", + e.getMessage())); + } + return user; + } + + @Override + public User insertIntoUser(final User user) { + Long id = (long) 0; + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(UserQueries.SAVE_USER, returnValColumn); + statement.setString(1, user.getName()); + statement.setString(2, user.getUsername()); + statement.setString(3, user.getPhone()); + statement.setString(4, user.getImagePath()); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + user.setId(id); + MasterDataManager.getUserIdAndUserNameMap().put(id, user.getName()); + } catch (InvalidDataAccessApiUsageException e) { + LOGGER.error(String.format("Encountered an Invalid Data Access Exception while creating a new User: %s", + e.getMessage())); + } catch (DataAccessException e) { + LOGGER.error(String.format("Encountered a Data Access Exception while creating a new User : %s", + e.getMessage())); + } catch (Exception e) { + LOGGER.error(String.format("Encountered a Exception while creating a new User : %s", e.getMessage())); + } + return user; + } + + @Override + public Long insertAnonymousUser(final User user) { + Long id = (long) 0; + String anonymous = "Anonymous"; + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(UserQueries.SAVE_ANONYMOUS_USER, + returnValColumn); + statement.setString(1, anonymous); + statement.setString(2, user.getUsername()); + statement.setString(3, ""); + statement.setString(4, ""); + statement.setBoolean(5, true); + return statement; + } + }, keyHolder); + id = keyHolder.getKey().longValue(); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered a Exception while creating a Anonymous User : %s", e.getMessage())); + } + return id; + } + + @Override + public boolean customAuth(UserDto user) { + int row = 0; + VelocityContext context = new VelocityContext(); + try { + String password = ProjectUtil.getRandomStringVal(); + if (!StringUtils.isBlank(password)) { + LOGGER.info("Password : " + password); + } + String encodedPwd = OneWayHashing.encryptVal(password); + user.setPassword(encodedPwd); + row = insertIntoPassword(user.getId(), encodedPwd); + if (row > 0) { + context.put(JsonKey.MAIL_SUBJECT, "You're a Aurora-Desk User now!"); + context.put(JsonKey.MAIL_BODY, "You have been successfully added as the user to the system" + + " Please find your username and password"); + context.put(JsonKey.PSWRD, password); + context.put(JsonKey.USER_NAME, user.getUsername()); + context.put(JsonKey.FIRST_NAME, user.getName()); + SendMail.sendMail(new String[] { user.getUsername() }, "User Added, Password Generated", context, + "email_template.vm"); + } + return true; + } catch (Exception e) { + LOGGER.error(String.format("Password insertion failed for user: %s", user.getId())); + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return false; + } + + private UserAuthentication save(final UserAuthentication user) { + UserAuthentication user1 = new UserAuthentication(); + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(UserQueries.SAVE_USER_AUTHENTICATION, + returnValColumn); + statement.setLong(1, user.getUserId()); + statement.setString(2, user.getAuthToken()); + return statement; + } + }, keyHolder); + Long id = keyHolder.getKey().longValue(); + user1 = this.findOneUserAuthentication(id); + + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an exception while saving User Authentication : %s", e.getMessage())); + } + return user1; + } + + @Override + public int getAuthId(Long userId) { + int orgId = 0; + orgId = superAdminDao.getOrganizationByUserId(userId); + if (orgId > 0) { + try { + return jdbcTemplate.queryForObject(Sql.UserQueries.GET_AUTH_TYPE_ID, new Object[] { orgId }, + Integer.class); + } catch (Exception e) { + LOGGER.error(String.format("Encountered a Exception while getting an Authentication ID: %s", + e.getMessage())); + } + } + return 0; + } + + @Override + public int insertIntoPassword(Long id, String password) { + return jdbcTemplate.update(Sql.UserQueries.INSERT_PD, new Object[] { password, id.longValue() }); + } + + @Override + public User update(final User user) { + try { + if (user.getImagePath() != null) { + updateProfilePic(user.getId(), user.getImagePath()); + } + } catch (Exception e) { + LOGGER.error(String.format("error while updating profile pic %s", e.getMessage())); + } + try { + jdbcTemplate.update(UserQueries.UPDATE_USER, new Object[] { user.getName(), user.getUsername(), + user.getPhone(), user.getIsActive(), user.getImagePath(), user.getId() }); + MasterDataManager.getUserIdAndUserName(); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an error while updating User Object : %s", e.getMessage())); + } + return user; + } + + private String updateProfilePic(Long id, String imagePath) { + if (imagePath != null) { + Long organization = MasterDataManager.getUserOrgMap().get(id); + String profilePicPath = null; + profilePicPath = S3FileManager.filePath(imagePath, "userprofile", id, organization); + jdbcTemplate.update(Sql.INSERT_PROFILE_PICTURE, new Object[] { profilePicPath, id }); + return profilePicPath; + } + return null; + } + + @Override + public UserRoleMapper findAllRolesByUser(Long userId) { + UserRoleMapper mapper = new SqlDataMapper().new UserRoleMapper(); + try { + jdbcTemplate.query(UserQueries.GET_ROLES_FOR_USER, new Object[] { userId }, mapper); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching the Roles for a User : %s", + e.getMessage())); + } + + return mapper; + } + + @Override + public Boolean mapUserToRole(long userId, List<Role> roleList) { + try { + jdbcTemplate.update(UserQueries.REMOVE_USER_ROLE_MAP, new Object[] { userId }); + } catch (Exception ex) { + LOGGER.error(String.format("Encountered an exception while removing the User Role mapping : %s", + ex.getMessage())); + } + + try { + jdbcTemplate.batchUpdate(UserQueries.MAP_USER_TO_ROLE, new BatchPreparedStatementSetter() { + @Override + public void setValues(java.sql.PreparedStatement statement, int i) throws SQLException { + Role role = roleList.get(i); + statement.setLong(1, userId); + statement.setLong(2, role.getId()); + } + + @Override + public int getBatchSize() { + return roleList.size(); + } + }); + MasterDataManager.getUserRoleMap().clear(); + MasterDataManager.getRoleUserMap().clear(); + MasterDataManager.getAllUserRoles(); + return true; + + } catch (Exception ex) { + LOGGER.error("Exception Occured while adding Roles to User : %s", ex); + return false; + } + + } + + @Override + public User updateUserImage(User profile) { + try { + KeyHolder keyHolder = KeyFactory.getkeyHolder(); + jdbcTemplate.update(new PreparedStatementCreator() { + @Override + public PreparedStatement createPreparedStatement(Connection con) throws SQLException { + String[] returnValColumn = new String[] { "id" }; + PreparedStatement statement = con.prepareStatement(UserQueries.UPDATE_USER_PROFILE_PROFILE_IMAGE, + returnValColumn); + statement.setString(1, profile.getImagePath()); + statement.setLong(2, profile.getId()); + return statement; + } + }, keyHolder); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an error while updating User Profile image %s", e.getMessage())); + } + return profile; + } + + @Override + public Long checkUserNameExists(String username) { + Long userId; + try { + userId = jdbcTemplate.queryForObject("SELECT id FROM user WHERE username = ?", new Object[] { username }, + Long.class); + } catch (Exception e) { + return 0l; + } + return userId; + } + + @Override + public UserDetailsMapper findListOfUsers(List<Long> userIdList) { + UserDetailsMapper mapper = new SqlDataMapper().new UserDetailsMapper(); + String query = buildMyQuery(userIdList); + LOGGER.info(String.format("Query to execute for fetching the User Profile : %s", query)); + try { + jdbcTemplate.query(query, new Object[] {}, mapper); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching the User By ID : %s", e.getMessage())); + } + return mapper; + } + + private String buildMyQuery(List<Long> userIdList) { + StringBuilder builder = new StringBuilder(UserQueries.USER_PROFILE_FETCH); + if (!userIdList.isEmpty()) { + builder.append("("); + for (int i = 0; i < userIdList.size(); i++) { + if (i == 0 && i == userIdList.size() - 1) { + builder.append(userIdList.get(i)); + } else if (i == userIdList.size() - 1) { + builder.append(userIdList.get(i)); + } else { + builder.append(userIdList.get(i) + ","); + } + } + builder.append(")"); + } + return builder.toString(); + } + + @Override + public List<User> findAll(Long orgId) { + List<User> user = null; + try { + if (orgId > 0) { + user = jdbcTemplate.query(Sql.Common.GET_ALL_USERS_BY_ORG, new Object[] { orgId }, + new SqlDataMapper().new UserDetailsMapper()); + } + setImageUrlFromImagePath(user); + MasterDataManager.getAllUserRoles(); + for (int i = 0; i < user.size(); i++) { + List<Long> roles = MasterDataManager.getUserRoleListMap().get(user.get(i).getId()); + List<Role> roleList = new ArrayList<>(); + for (int j = 0; j < roles.size(); j++) { + roleList.add(MasterDataManager.getRoleMap().get(roles.get(j))); + } + user.get(i).setRoles(roleList); + } + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an exception while fetching the User Profile : %s", e.getMessage())); + } + return user; + } + + private void setImageUrlFromImagePath(List<User> user) { + for (int i = 0; i < user.size(); i++) { + if (user.get(i).getImagePath() != null) { + S3Config s3values = superAdminDao.getS3Access(); + String url = null; + url = S3FileManager.getPreSignedURL(s3values, user.get(i).getImagePath()); + user.get(i).setImagePath(url); + } + } + } + + @Override + public Long getNumberOfUsers(Long role, Boolean active) { + Long numberOfUsers = 0L; + try { + if (role != null) { + numberOfUsers = jdbcTemplate.queryForObject(UserQueries.GET_USER_COUNT_FOR_ROLE, new Object[] { role }, + Long.class); + } else if (active != null) { + numberOfUsers = jdbcTemplate.queryForObject(UserQueries.GET_USER_COUNT_ON_ACTIVE_STATUS, + new Object[] { active }, Long.class); + } else { + numberOfUsers = jdbcTemplate.queryForObject(UserQueries.GET_USER_COUNT, Long.class); + } + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching count of Users : %s", e.getMessage())); + } + return numberOfUsers; + } + + @Override + public Long getNumberOfRoles() { + Long numberOfRoles = 0L; + try { + numberOfRoles = jdbcTemplate.queryForObject(UserQueries.GET_ROLE_COUNT, Long.class); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching count of Roles : %s", e.getMessage())); + } + return numberOfRoles; + } + + @Override + public Boolean invalidateToken(String authToken) { + try { + jdbcTemplate.update(UserQueries.INVALIDATE_TOKEN, new Object[] { authToken }); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an error while invalidating Auth Token : %s", e.getMessage())); + return false; + } + return true; + } + + @Override + public Boolean findUserByToken(String authToken) { + Long countOfUsers = 0L; + authToken = authToken.replace(TOKEN_PREFIX, ""); + try { + countOfUsers = jdbcTemplate.queryForObject(UserQueries.SELECT_USER_BY_TOKEN, new Object[] { authToken }, + Long.class); + } catch (Exception e) { + LOGGER.error( + String.format("Encountered an Exception while fetching User by auth token: %s", e.getMessage())); + } + return (countOfUsers > 0); + } + + @Override + public Boolean checkUserTokenExists(Long userId, String deviceToken) { + Long available = 0L; + try { + available = jdbcTemplate.queryForObject(UserQueries.CHECK_USER_DEVICE_TOKEN, + new Object[] { userId, deviceToken }, Long.class); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching User Device by Device token: %s", + e.getMessage())); + } + return (available > 0); + } + + @Override + public Long fetchAuthTokenReference(String authToken) { + authToken = authToken.split(" ")[1]; + Long authTokenRef = 0L; + try { + authTokenRef = jdbcTemplate.queryForObject(UserQueries.FETCH_AUTH_TOKEN_REF, new Object[] { authToken }, + Long.class); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an Exception while fetching User Device by Device token: %s", + e.getMessage())); + } + return authTokenRef; + } + + @Override + public boolean changePassword(ChangePasswordDto changePasswordDto) { + boolean resposne = false; + if (isPasswordMatch(changePasswordDto.getUserId(), changePasswordDto.getOldPass())) { + int count = jdbcTemplate.update(Sql.Common.UPDATE_PSWRD, + new Object[] { OneWayHashing.encryptVal(changePasswordDto.getNewPass()), + DateUtil.getFormattedDateInUTC(new Date()), changePasswordDto.getUserId(), + OneWayHashing.encryptVal(changePasswordDto.getOldPass()) }); + if (count > 0) { + resposne = true; + } + } + return resposne; + } + + @Override + public boolean isPasswordMatch(long userId, String password) { + boolean response = false; + String storedPassword = ""; //$NON-NLS-1$ + try { + storedPassword = jdbcTemplate.queryForObject(Sql.Common.CHECK_OLD_PSWRD, new Object[] { userId }, + String.class); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + if (storedPassword.equals(OneWayHashing.encryptVal(password))) { + response = true; + } + return response; + } + + @Override + public long forgotPassword(UserDto userDto) { + long userId = 0; + try { + userId = jdbcTemplate.queryForObject(Sql.Common.CHECK_USER_BY_USERNAME, + new Object[] { userDto.getUsername() }, Long.class); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + + return userId; + } + + @Override + public boolean saveForgotPassword(long userId, String password) { + boolean response = false; + int count = 0; + try { + String encryptVal = OneWayHashing.encryptVal(password); + count = jdbcTemplate.update(Sql.Common.SAVE_FORGOT_PSWRD, + new Object[] { encryptVal, DateUtil.getFormattedDateInUTC(new Date()), userId }); + LOGGER.info("Password : {}", encryptVal); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + if (count > 0) { + response = true; + } + return response; + } + + @Override + public User getUserDetailsByEmail(String username) { + User user = null; + try { + user = jdbcTemplate + .query(Sql.Common.GET_USER_DETAIL_BY_EMAIL, new Object[] { username }, MasterDataManager.rowMapUser) + .get(0); + user.setOrgId(jdbcTemplate.queryForObject(Sql.Common.GET_ORG_ID_BY_USER_ID, new Object[] { user.getId() }, + Long.class)); + } catch (Exception e) { + LOGGER.error(String.format("getUserDetailsByEmail method : %s", e.getMessage())); //$NON-NLS-1$ + } + return user; + } + + @Override + public LoginDto login(UserDto userDto) { + final String token = jwtTokenUtil.generateToken(userDto); + UserAuthentication userAuthentication = new UserAuthentication(); + userAuthentication.setUserId(userDto.getId()); + userAuthentication.setAuthToken(token); + save(userAuthentication); + LoginDto loginDto = new LoginDto(); + loginDto.setAuthToken(token); + loginDto.setUserId(userDto.getId()); + List<Role> roles = userService.findAllRolesByUser(userDto.getId()); + loginDto.setRoles(roles); + return loginDto; + + } + + @Override + public CommonDataModel getAuthDomain(UserDto userDto) { + CommonDataModel authDomain = null; + try { + authDomain = jdbcTemplate + .query(createSqlForAuth(userDto.getOrgId()), MasterDataManager.rowMapCommonDataModel).get(0); + } catch (DataAccessException e) { + LOGGER.error(String.format("Encountered an Exception while getting Auth Domain : %s", e.getMessage())); + } + return authDomain; + } + + private final String createSqlForAuth(long orgId) { + StringBuilder queryBuilder = new StringBuilder( + UserQueries.QUERY1 + UserQueries.QUERY2 + orgId + UserQueries.QUERY3); + return queryBuilder.toString(); + } + + @Override + public boolean getFirstAdminsOfOrg(Long id) { + try { + Long value = null; + value = jdbcTemplate.queryForObject(Sql.UserQueries.CHECK_FIRST_ADMIN, Long.class, new Object[] { id }); + return (value != null); + } catch (Exception e) { + LOGGER.error(String.format("Error while check first admin %s", e.getMessage())); //$NON-NLS-1$ + return false; + } + } + + @Override + public Boolean onBoardingCheck(Long orgId, Long userId) { + try { + Long check = jdbcTemplate.queryForObject(Sql.UserQueries.GET_MASTER_DATA_CHECK, new Object[] { orgId }, + Long.class); + if (check > 0) { + User user = getUserProfile(userId); + return (user.getUsername() != null && user.getName() != null); + } + } catch (Exception e) { + LOGGER.error(String.format("Error while check master Data %s", e.getMessage())); //$NON-NLS-1$ + } + return false; + } + + public User getUserProfile(Long userId) { + return jdbcTemplate + .query(Sql.UserQueries.USER_PROFILE_FETCH, new Object[] { userId }, MasterDataManager.rowMapUser) + .get(0); + } + + @Override + public List<OrgUserRoleDto> getAllOrgUsers() { + List<OrgUserRoleDto> orgUserList = null; + try { + orgUserList = jdbcTemplate.query(Sql.UserQueries.GET_USER_ORG_MAP, new SqlDataMapper().new UserOrgMapper()); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles %s", e.getMessage())); + } + return orgUserList; + } + + @Override + public List<OrgUserRoleDto> getAllUserRoles() { + RolesUserMapper mapper = new SqlDataMapper().new RolesUserMapper(); + List<OrgUserRoleDto> userRoleList = new ArrayList<>(); + try { + jdbcTemplate.query(Sql.UserQueries.GET_USER_ROLE_MAP, mapper); + } catch (Exception e) { + LOGGER.error(String.format("Encountered an exception while fetching all roles %s", e.getMessage())); + } + + for (Map.Entry<Long, OrgUserRoleDto> entry : mapper.getUserMap().entrySet()) { + userRoleList.add(entry.getValue()); + } + return userRoleList; + } + + @Override + public List<HelpDeskApp> getAppIdAndHelpDeskId() { + List<HelpDeskApp> helpdeskApp = null; + try { + helpdeskApp = jdbcTemplate.query(Sql.UserQueries.GET_APP_ID_HELPDESK_ID, + new SqlDataMapper().new HelpDeskAppMapper()); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return helpdeskApp; + } + + @Override + public List<User> getUserIdAndUserName() { + try { + return jdbcTemplate.query(Sql.UserQueries.GET_USER_ID_AND_USER_NAME, new Object[] {}, + MasterDataManager.rowMapUser); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + return new ArrayList<>(); + } + } + + @Override + public Access getReviewConfig(Long orgId) { + Access exp = null; + try { + exp = jdbcTemplate.query(Sql.GET_CONFIG, new Object[] { orgId }, MasterDataManager.rowMapAccess).get(0); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return exp; + } + + @Override + public void getReviews() throws IOException { + try { + for (int i = 0; i < superAdminDao.getAllOrganization().size(); i++) { + Long id = superAdminDao.getAllOrganization().get(i).getId(); + Access exp = getReviewConfig(id); + AccessResponse accessResponse = new AccessResponse(); + if (!ProjectUtil.isObjectNull(exp)) { + HttpHeaders headers = new HttpHeaders(); + RestTemplate restTemplate = new RestTemplate(); + headers.setContentType(MediaType.APPLICATION_JSON); + Map<String, Object> map = new HashMap<>(); + map.put(Constants.GRANT_TYPE, Constants.REFRESH_TOKEN); + map.put(Constants.CLIENT_ID, exp.getClientId()); + map.put(Constants.CLIENT_SECRET, exp.getClientSecret()); + map.put(Constants.REFRESH_TOKEN, exp.getRefreshToken()); + HttpEntity<Map<String, Object>> request = new HttpEntity<>(map, headers); + ResponseEntity<String> response = restTemplate + .postForEntity(Constants.HTTPS_ACCOUNTS_GOOGLE_COM_O_OAUTH2_TOKEN, request, String.class); + if (!StringUtils.isBlank(response.getBody())) { + List<Object> chainrSpecJSON = JsonUtils.classpathToList(Constants.ACCESSTOKENSPEC_JSON); + Chainr chainr = Chainr.fromSpec(chainrSpecJSON); + Object transformedOutput = chainr.transform(JsonUtils.jsonToObject(response.getBody())); + Gson g = new Gson(); + accessResponse = g.fromJson(JsonUtils.toJsonString(transformedOutput), AccessResponse.class); + } + if (!StringUtils.isBlank(accessResponse.getAccessToken())) { + List<String> distinctAppNames = applicationDao.getDistinctAppNames(id); + for (int j = 0; j < distinctAppNames.size(); j++) { + Rev reviews = new Rev(); + String appName = distinctAppNames.get(j); + integrateReviews(accessResponse, restTemplate, reviews, appName); + } + } + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + private void integrateReviews(AccessResponse accessResponse, RestTemplate restTemplate, Rev reviews, String appName) + throws ParseException, IOException { + try { + final String uri = Constants.HTTPS_WWW_GOOGLEAPIS_COM_ANDROIDPUBLISHER_V3_APPLICATIONS + appName + + Constants.REVIEWS2; + HttpHeaders header = new HttpHeaders(); + header.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); + header.set(Constants.HEADER_STRING, Constants.TOKEN_PREFIX + accessResponse.getAccessToken()); + HttpEntity<String> entity = new HttpEntity<>(Constants.PARAMETERS, header); + ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class); + if (!StringUtils.isBlank(result.getBody())) { + Gson g = new Gson(); + reviews = g.fromJson(result.getBody(), Rev.class); + } + if (!reviews.getReviews().isEmpty()) { + Ticket t; + List<Ticket> mapper = new ArrayList<>(); + RestHighLevelClient client = connectToElasticSearch(); + for (int k = 0; k < reviews.getReviews().size(); k++) { + List<Object> chainrSpecJSON = JsonUtils.classpathToList(Constants.REVIEWSPEC_JSON); + Chainr chainr = Chainr.fromSpec(chainrSpecJSON); + Gson gson = new Gson(); + String inputJSON = gson.toJson(reviews.getReviews().get(k)); + Object transformedOutput = chainr.transform(JsonUtils.jsonToObject(inputJSON)); + Gson g = new Gson(); + t = g.fromJson(JsonUtils.toJsonString(transformedOutput), Ticket.class); + t.setAppName(appName); + mapper.add(t); + } + BulkRequest req = new BulkRequest(); + for (int l = 0; l < mapper.size(); l++) { + Ticket tkt = ticketDao.addTicket(mapper.get(l)); + if (tkt != null) { + Map<String, Object> jsonMap = ticketsRequestInterceptor.createJsonMap(tkt); + req.add(new IndexRequest(elasticsearchIndex, elasticsearchType, tkt.getId().toString()) + .source(jsonMap)); + } + } + client.bulk(req); + client.close(); + } + } catch (RestClientException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + } + + private RestHighLevelClient connectToElasticSearch() { + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTIC, EL_STIC123)); + + HttpClientConfigCallback httpClientConfigCallback = new RestClientBuilder.HttpClientConfigCallback() { + @Override + public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } + }; + return new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchUrl)) + .setHttpClientConfigCallback(httpClientConfigCallback)); + } + +} diff --git a/src/main/java/org/upsmf/grievance/dto/ChangePasswordDto.java b/src/main/java/org/upsmf/grievance/dto/ChangePasswordDto.java new file mode 100644 index 0000000000000000000000000000000000000000..0a87e201a5732470de790ea9554db544a3ca00b5 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/ChangePasswordDto.java @@ -0,0 +1,54 @@ +/** + * + */ +package org.upsmf.grievance.dto; + +/** + * @author Manzarul + * + */ +public class ChangePasswordDto { + private Long userId; + private String oldPass; + private String newPass; + private String confirmNewPass; + + public String getOldPass() { + return oldPass; + } + + public void setOldPass(String oldPass) { + this.oldPass = oldPass; + } + + public String getNewPass() { + return newPass; + } + + public void setNewPass(String newPass) { + this.newPass = newPass; + } + + public String getConfirmNewPass() { + return confirmNewPass; + } + + public void setConfirmNewPass(String confirmNewPass) { + this.confirmNewPass = confirmNewPass; + } + + @Override + public String toString() { + return "ChangePasswordDto [oldPass=" + oldPass + ", newPass=" + newPass + ", confirmNewPass=" + confirmNewPass + + "]"; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + +} diff --git a/src/main/java/org/upsmf/grievance/dto/HelpdeskDto.java b/src/main/java/org/upsmf/grievance/dto/HelpdeskDto.java new file mode 100644 index 0000000000000000000000000000000000000000..f09532470ee258884e19d585e498d6f323834cdb --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/HelpdeskDto.java @@ -0,0 +1,44 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.User; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class HelpdeskDto { + + private Long id; + private String name; + private Long orgId; + private Long createdBy; + private String createdDate; + private Long updatedBy; + private String updatedDate; + private Boolean isActive; + private List<HelpdeskTypeDto> types; + private List<App> apps; + private List<User> admins; + private List<User> users; + private String description; + private String color; + private List<Long> adminIds; + private List<Long> appIds; + private List<Long> sourceId; + private List<Long> userIds; + private Boolean allowAllUsers; + private Boolean direct; + private Boolean playstore; + private Boolean appstore; + private Boolean auroraSdk; +} diff --git a/src/main/java/org/upsmf/grievance/dto/HelpdeskTypeDto.java b/src/main/java/org/upsmf/grievance/dto/HelpdeskTypeDto.java new file mode 100644 index 0000000000000000000000000000000000000000..363c71fbf49941edcd6170a1a09171bada8bc81b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/HelpdeskTypeDto.java @@ -0,0 +1,25 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +import org.upsmf.grievance.model.ChecklistItem; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class HelpdeskTypeDto { + + private Long id; + private Long helpdeskId; + private String name; + private List<HelpdeskWorkflowDto> workflowStages; + private List<ChecklistItem> checklistItems; +} diff --git a/src/main/java/org/upsmf/grievance/dto/HelpdeskWorkflowDto.java b/src/main/java/org/upsmf/grievance/dto/HelpdeskWorkflowDto.java new file mode 100644 index 0000000000000000000000000000000000000000..3ffb4035832dab10fde6396cb9dc0f814ba3d439 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/HelpdeskWorkflowDto.java @@ -0,0 +1,19 @@ +package org.upsmf.grievance.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class HelpdeskWorkflowDto { + + private Long id; + private Long typeId; + private String name; +} diff --git a/src/main/java/org/upsmf/grievance/dto/LoginDto.java b/src/main/java/org/upsmf/grievance/dto/LoginDto.java new file mode 100644 index 0000000000000000000000000000000000000000..cf3057f897dea083f588482a9854cbfc3cb8fcce --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/LoginDto.java @@ -0,0 +1,48 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +import org.upsmf.grievance.model.Role; + +public class LoginDto { + + private String authToken; + + private Long userId; + + private List<Role> roles; + + private String imageUrl; + + public String getAuthToken() { + return authToken; + } + + public void setAuthToken(String authToken) { + this.authToken = authToken; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public List<Role> getRoles() { + return roles; + } + + public void setRoles(List<Role> roles) { + this.roles = roles; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } +} diff --git a/src/main/java/org/upsmf/grievance/dto/OrgUserRoleDto.java b/src/main/java/org/upsmf/grievance/dto/OrgUserRoleDto.java new file mode 100644 index 0000000000000000000000000000000000000000..d7b5f6c752b68e4e2d3b5f0afb7684f5329f153e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/OrgUserRoleDto.java @@ -0,0 +1,52 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +public class OrgUserRoleDto { + + private Long id; + private Long userId; + private Long orgId; + private Long roleId; + private List<Long> roleIds; + + public List<Long> getRoleIds() { + return roleIds; + } + + public void setRoleIds(List<Long> roleIds) { + this.roleIds = roleIds; + } + + public Long getRoleId() { + return roleId; + } + + public void setRoleId(Long roleId) { + this.roleId = roleId; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getOrgId() { + return orgId; + } + + public void setOrgId(Long orgId) { + this.orgId = orgId; + } +} diff --git a/src/main/java/org/upsmf/grievance/dto/TicketTagDto.java b/src/main/java/org/upsmf/grievance/dto/TicketTagDto.java new file mode 100644 index 0000000000000000000000000000000000000000..554c8595f3562bef5fce671a159d1ed333bb98ed --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/TicketTagDto.java @@ -0,0 +1,74 @@ +package org.upsmf.grievance.dto; + +import java.util.ArrayList; +import java.util.List; + +import org.upsmf.grievance.model.Tags; + +public class TicketTagDto { + + private Long id; + private String url; + private int typeId; + private String description; + private boolean isDeleted = false; + private Long orgId; + private List<Tags> tags = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getTypeId() { + return typeId; + } + + public void setTypeId(int typeId) { + this.typeId = typeId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isDeleted() { + return isDeleted; + } + + public void setDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } + + public Long getOrgId() { + return orgId; + } + + public void setOrgId(Long orgId) { + this.orgId = orgId; + } + + public List<Tags> getTags() { + return tags; + } + + public void setTags(List<Tags> tags) { + this.tags = tags; + } + +} diff --git a/src/main/java/org/upsmf/grievance/dto/TicketTypeDto.java b/src/main/java/org/upsmf/grievance/dto/TicketTypeDto.java new file mode 100644 index 0000000000000000000000000000000000000000..eb71228d349c339a1c55fb93cb497e62daea9314 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/TicketTypeDto.java @@ -0,0 +1,35 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.Ticket; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TicketTypeDto { + + private Long id; + private Long helpdeskId; + private String name; + private Long orgId; + private Long typeId; + private List<TicketWorkflowDto> workflowStages; + private List<ChecklistItem> checklistItems; + + public TicketTypeDto(Ticket ticket) { + this.id = ticket.getId(); + this.orgId = ticket.getOrgId(); + this.helpdeskId = ticket.getHelpdeskId(); + this.typeId = ticket.getType(); + } +} diff --git a/src/main/java/org/upsmf/grievance/dto/TicketWorkflowDto.java b/src/main/java/org/upsmf/grievance/dto/TicketWorkflowDto.java new file mode 100644 index 0000000000000000000000000000000000000000..e82d6a7725d7a1792968377296ea080f1ea38b10 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/TicketWorkflowDto.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TicketWorkflowDto { + + private Long id; + private Long workFlowId; + private Long typeId; + private String name; + private String time; + private Boolean status; +} diff --git a/src/main/java/org/upsmf/grievance/dto/UserDto.java b/src/main/java/org/upsmf/grievance/dto/UserDto.java new file mode 100644 index 0000000000000000000000000000000000000000..8f53220255a404b0e182f15d455997428deb7667 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/UserDto.java @@ -0,0 +1,144 @@ +package org.upsmf.grievance.dto; + +import java.util.List; +import java.util.Set; + +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.Role; + +/** + * Data Transfer Object which carries the User Information to the Data Access + * Layers + * + * @author Juhi Agarwal + * + */ +public class UserDto { + + private long id; + + private String name; + + private String username; + + private String password; + + private Long orgId; + + private List<Role> roles; + + private Set<Action> actions; + + private String statusMsg; + + private String googleEmail; + private String googleClientId; + private String portal; + private String authType; + private String googleIdToken; + + public Long getOrgId() { + return orgId; + } + + public void setOrgId(Long orgId) { + this.orgId = orgId; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public List<Role> getRoles() { + return roles; + } + + public void setRoles(List<Role> roles) { + this.roles = roles; + } + + public Set<Action> getActions() { + return actions; + } + + public void setActions(Set<Action> actions) { + this.actions = actions; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getStatusMsg() { + return statusMsg; + } + + public void setStatusMsg(String statusMsg) { + this.statusMsg = statusMsg; + } + + public String getGoogleEmail() { + return googleEmail; + } + + public void setGoogleEmail(String googleEmail) { + this.googleEmail = googleEmail; + } + + public String getGoogleClientId() { + return googleClientId; + } + + public void setGoogleClientId(String googleClientId) { + this.googleClientId = googleClientId; + } + + public String getPortal() { + return portal; + } + + public void setPortal(String portal) { + this.portal = portal; + } + + public String getAuthType() { + return authType; + } + + public void setAuthType(String authType) { + this.authType = authType; + } + + public String getGoogleIdToken() { + return googleIdToken; + } + + public void setGoogleIdToken(String googleIdToken) { + this.googleIdToken = googleIdToken; + } + +} diff --git a/src/main/java/org/upsmf/grievance/dto/UserProfileDto.java b/src/main/java/org/upsmf/grievance/dto/UserProfileDto.java new file mode 100644 index 0000000000000000000000000000000000000000..f404fcf12165eb1977ef6dc569798454156af3c7 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/UserProfileDto.java @@ -0,0 +1,49 @@ +package org.upsmf.grievance.dto; + +import java.util.Date; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * This Data Transfer Object will carry the information related to the User + * Profile to update the User Profile Information in the API + * + * @author Darshan Nagesh + * + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class UserProfileDto { + + private Long id; + private Long userId; + private String firstName; + private String lastName; + private int age; + private String emailId; + private String phoneNumber; + private String dob; + private String gender; + private String avatarUrl; + private Date startDate; + private Date endDate; + private Long salary; + private String address; + private Boolean isActive; + private Boolean isDeleted; + private Date registrationDate; + private Date createdDate; + private Long createdBy; + private Date updatedDate; + private Long updatedBy; + private String employmentType; +} diff --git a/src/main/java/org/upsmf/grievance/dto/UserRoleDto.java b/src/main/java/org/upsmf/grievance/dto/UserRoleDto.java new file mode 100644 index 0000000000000000000000000000000000000000..e5213282bd17801ea455068e792a6cf4c926ca10 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/dto/UserRoleDto.java @@ -0,0 +1,34 @@ +package org.upsmf.grievance.dto; + +import java.util.List; + +import org.upsmf.grievance.model.Role; + +/** + * Data Transfer Object which carries the User ID and the Roles associated. + * + * @author Darshan Nagesh + * + */ +public class UserRoleDto { + + private Long userId; + private List<Role> roles; + + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public List<Role> getRoles() { + return roles; + } + + public void setRoles(List<Role> roles) { + this.roles = roles; + } + +} diff --git a/src/main/java/org/upsmf/grievance/exceptions/RbacException.java b/src/main/java/org/upsmf/grievance/exceptions/RbacException.java new file mode 100644 index 0000000000000000000000000000000000000000..b93b4dfd1b51d0f43e274678f30a3266ce21ca2d --- /dev/null +++ b/src/main/java/org/upsmf/grievance/exceptions/RbacException.java @@ -0,0 +1,188 @@ +package org.upsmf.grievance.exceptions; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +@SuppressWarnings("all") +public class RbacException extends Exception { + + private static final long serialVersionUID = 1L; + /** + * The primary message for the exception + */ + private String message; + /** + * designated error code of the error + */ + private String errorCode; + /** + * Server timestamp when error occured + */ + private long timeStamp; + /** + * Additional parameters + */ + private Map<String, Object> params; + /** + * root Exception object + */ + private Exception ex; + /** + * root throwable object + */ + private Throwable t; + /** + * variable determining the error been logged to file or not + */ + private boolean logged; + + private String originalStackTrace; + + public RbacException(Exception e) { + super(e); + initializeException(e.getMessage()); + processOriginalStackTrace(e.getStackTrace()); + } + + public RbacException(Throwable t) { + super(t); + initializeException(t.getMessage()); + processOriginalStackTrace(t.getStackTrace()); + } + + public RbacException(String msg) { + super(msg); + initializeException(msg); + } + + public RbacException(String msg, Throwable t) { + super(msg, t); + initializeException(msg); + processOriginalStackTrace(t.getStackTrace()); + } + + public RbacException withParam(String name, Object value) { + if (params == null) { + params = new HashMap<>(); + } + params.put(name, value); + return this; + } + + public RbacException withErrorCode(String errorCode) { + this.errorCode = errorCode; + return this; + } + + private void initializeException(String msg) { + this.timeStamp = System.currentTimeMillis(); + this.message = msg; + } + + public String prepareFullErrorDescription() { + StringBuilder stackBuilder = new StringBuilder(); + stackBuilder.append("Exception Message : ").append(this.message).append(" \n"); + stackBuilder.append("Exception Time : ").append(new Date(this.timeStamp)).append(" \n"); + stackBuilder.append("Error code : ").append(this.errorCode).append(" \n "); + if (this.params != null && !this.params.isEmpty()) { + stackBuilder.append(" Parameters : "); + for (Entry<String, Object> entry : params.entrySet()) { + stackBuilder.append("\n\t ").append(entry.getKey()).append(" : ").append(entry.getValue()); + } + } + if (originalStackTrace != null) { + stackBuilder.append("\n stacktrace : ").append(originalStackTrace); + return stackBuilder.toString(); + } + StackTraceElement[] stack; + if (this.ex != null) { + stack = ex.getStackTrace(); + } else if (this.t != null) { + stack = t.getStackTrace(); + } else { + stack = super.getStackTrace(); + } + if (stack == null) { + return stackBuilder.toString(); + } + stackBuilder.append("\n stacktrace : "); + for (StackTraceElement s : stack) { + stackBuilder.append(" \n ").append(s); + } + return stackBuilder.toString(); + } + + private void processOriginalStackTrace(StackTraceElement[] stack) { + if (stack == null || stack.length == 0) { + return; + } + StringBuilder stackBuilder = new StringBuilder(); + for (StackTraceElement trace : stack) { + stackBuilder.append(trace).append("\n "); + } + originalStackTrace = stackBuilder.toString(); + } + + public boolean isLogged() { + return logged; + } + + public void setLogged(boolean logged) { + this.logged = logged; + } + + public RbacException logToFile(String prependingMessage) { + if (!logged) { + if (prependingMessage != null) { + + } + + logged = true; + } + return this; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public long getTimeStamp() { + return timeStamp; + } + + public Map<String, Object> getParams() { + return params; + } + + public void addParamsToMessage() { + if (params == null) { + return; + } + StringBuilder message = new StringBuilder("{ "); + int i = params.size(); + for (Entry<String, Object> entry : params.entrySet()) { + message.append(entry.getKey()).append(" : ").append(entry.getValue()); + i--; + if (i > 0) { + message.append(", "); + } + } + message.append(" } , ").append(getMessage()); + this.message = message.toString(); + } +} diff --git a/src/main/java/org/upsmf/grievance/exceptions/RequestDataMissingException.java b/src/main/java/org/upsmf/grievance/exceptions/RequestDataMissingException.java new file mode 100644 index 0000000000000000000000000000000000000000..0aae454b0cd5640be59537f4875da2291be6cbb1 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/exceptions/RequestDataMissingException.java @@ -0,0 +1,34 @@ +/** + * + */ +package org.upsmf.grievance.exceptions; + +/** + * @author Juhi Agarwal This exception will capture missing data and will create + * message according to missing data field + */ +public class RequestDataMissingException extends RuntimeException { + /** + * serialVersionUID + */ + private static final long serialVersionUID = 1L; + private final String message; + + /** + * @param code + * the code to set + */ + @Override + public String getMessage() { + return message; + } + + /** + * + * @param message + */ + public RequestDataMissingException(String message) { + this.message = message; + } + +} diff --git a/src/main/java/org/upsmf/grievance/exceptions/package-info.java b/src/main/java/org/upsmf/grievance/exceptions/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..3b9f2dc14a7facdf3279a20a2b902ed34b14d458 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/exceptions/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Juhi Agarwal + * + */ +package org.upsmf.grievance.exceptions; \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/executor/MasterDataManager.java b/src/main/java/org/upsmf/grievance/executor/MasterDataManager.java new file mode 100644 index 0000000000000000000000000000000000000000..381faedb7d605631c483fa19addd2c627b9ae0eb --- /dev/null +++ b/src/main/java/org/upsmf/grievance/executor/MasterDataManager.java @@ -0,0 +1,513 @@ +package org.upsmf.grievance.executor; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.stereotype.Component; + +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketTags; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.ApplicationService; +import org.upsmf.grievance.service.HelpdeskService; +import org.upsmf.grievance.service.RoleActionService; +import org.upsmf.grievance.service.SuperAdminService; +import org.upsmf.grievance.service.UserService; + +@Component +public class MasterDataManager implements ApplicationRunner { + + public static final Logger LOGGER = LoggerFactory.getLogger(MasterDataManager.class); + + + protected static ConcurrentMap<Long, Role> roleMap = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, List<Role>> orgRoleMap = new ConcurrentHashMap<>(); + + + protected static ConcurrentMap<Long, List<Long>> orgUserMap = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, Long> userOrgMap = new ConcurrentHashMap<>(); + + + protected static ConcurrentMap<Long, Long> userRoleMap = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, List<Long>> userRoleListMap = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, Long> roleUserMap = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, List<String>> roleActionsListMap = new ConcurrentHashMap<>(); + + protected static ConcurrentMap<Long, Long> appIdHelpdeskIdMapping = new ConcurrentHashMap<>(); + protected static ConcurrentMap<String, App> appNameAppObjectMapping = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, App> appIdAppObjectMapping = new ConcurrentHashMap<>(); + + + protected static ConcurrentMap<Long, String> orgIdAndOrgNameMap = new ConcurrentHashMap<>(); + + + protected static ConcurrentMap<Long, Helpdesk> helpdeskIdHelpdeskObjectMapping = new ConcurrentHashMap<>(); + protected static ConcurrentMap<Long, List<Long>> helpdeskIdAppIdsMapping = new ConcurrentHashMap<>(); + + protected static ConcurrentMap<Long, String> userIdAndUserNameMap = new ConcurrentHashMap<>(); + + + public static final BeanPropertyRowMapper<User> rowMapUser = new BeanPropertyRowMapper<>(User.class); + public static final BeanPropertyRowMapper<CommonDataModel> rowMapCommonDataModel = new BeanPropertyRowMapper<>( + CommonDataModel.class); + public static final BeanPropertyRowMapper<Organization> rowMapOrganizationModel = new BeanPropertyRowMapper<>( + Organization.class); + public static final BeanPropertyRowMapper<HelpdeskDto> rowMapHelpdeskDto = new BeanPropertyRowMapper<>( + HelpdeskDto.class); + public static final BeanPropertyRowMapper<App> rowMapApp = new BeanPropertyRowMapper<>(App.class); + public static final BeanPropertyRowMapper<ServiceRequest> rowMapServiceRequest = new BeanPropertyRowMapper<>( + ServiceRequest.class); + public static final BeanPropertyRowMapper<Ticket> rowMapTicket = new BeanPropertyRowMapper<>(Ticket.class); + public static final BeanPropertyRowMapper<Updates> rowMapUpdate = new BeanPropertyRowMapper<>(Updates.class); + public static final BeanPropertyRowMapper<ActivityLog> rowMapActivityLogs = new BeanPropertyRowMapper<>( + ActivityLog.class); + public static final BeanPropertyRowMapper<S3Config> rowMapS3Config = new BeanPropertyRowMapper<>(S3Config.class); + public static final BeanPropertyRowMapper<Access> rowMapAccess = new BeanPropertyRowMapper<>(Access.class); + public static final BeanPropertyRowMapper<Tags> rowMapTags = new BeanPropertyRowMapper<>(Tags.class); + public static final BeanPropertyRowMapper<TicketTags> rowMapTicketTags = new BeanPropertyRowMapper<>( + TicketTags.class); + public static final BeanPropertyRowMapper<Role> rowMapRole = new BeanPropertyRowMapper<>(Role.class); + public static final BeanPropertyRowMapper<OrgUserRoleDto> rowMapOrgUserRoleDto = new BeanPropertyRowMapper<>( + OrgUserRoleDto.class); + public static final BeanPropertyRowMapper<HelpDeskApp> rowMapHelpDeskApp = new BeanPropertyRowMapper<>( + HelpDeskApp.class); + public static final BeanPropertyRowMapper<Helpdesk> rowMapHelpdesk = new BeanPropertyRowMapper<>(Helpdesk.class); + public static final BeanPropertyRowMapper<Action> rowMapAction = new BeanPropertyRowMapper<>(Action.class); + + private static RoleActionService roleActionService; + + private static UserService userService; + + private static ApplicationService applicationService; + + private static HelpdeskService helpdeskService; + + private static SuperAdminService superAdminService; + + @Autowired + public void setApplicationService(ApplicationService applicationService) { + MasterDataManager.applicationService = applicationService; + } + + @Autowired + public void setUserService(HelpdeskService helpdeskService) { + MasterDataManager.helpdeskService = helpdeskService; + } + + @Autowired + public void setRoleActionService(RoleActionService roleActionService) { + MasterDataManager.roleActionService = roleActionService; + } + + @Autowired + public void setUserService(UserService userService) { + MasterDataManager.userService = userService; + } + + @Autowired + public void setSuperAdminService(SuperAdminService superAdminService) { + MasterDataManager.superAdminService = superAdminService; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + getAllOrgRoles(); + getAllOrg(); + getAllOrgUsers(); + getAllUserRoles(); + getAppObjectFromAppName(); + getHelpdeskIdFromAppId(); + getHelpdeskObjectFromHelpdeskId(); + getUserIdAndUserName(); + initializeActions(); + intializeRolesAndActions(); + getAllActionsForRoles(); + } + + private static void intializeRolesAndActions() { + roleActionService.intializeRolesAndActions(); + + } + + private static void initializeActions() { + LOGGER.info("#MasterDataManager :: Initializing Actions : "); + roleActionService.initializeActions(); + + } + + public static void flushMasterData() { + orgRoleMap.clear(); + orgUserMap.clear(); + getUserOrgMap().clear(); + getRoleMap().clear(); + getUserRoleMap().clear(); + getRoleUserMap().clear(); + appIdHelpdeskIdMapping.clear(); + appNameAppObjectMapping.clear(); + appIdAppObjectMapping.clear(); + getOrgIdAndOrgNameMap().clear(); + getHelpdeskIdHelpdeskObjectMapping().clear(); + helpdeskIdAppIdsMapping.clear(); + getUserIdAndUserNameMap().clear(); + } + + public static void reloadMasterData() { + getAllOrgRoles(); + getAllOrg(); + getUserIdAndUserName(); + getAllOrgUsers(); + getAllUserRoles(); + getAppObjectFromAppName(); + getHelpdeskIdFromAppId(); + getHelpdeskObjectFromHelpdeskId(); + } + + + + public static void getAllOrgRoles() { + getRoleMap().clear(); + orgRoleMap.clear(); + + List<Role> roleList = roleActionService.getAllOrgRoles(); + for (Role role : roleList) { + getRoleMap().put(role.getId(), role); + if (orgRoleMap.containsKey(role.getOrgId())) { + List<Role> orgRoleList = orgRoleMap.get(role.getOrgId()); + orgRoleList.add(role); + } else { + List<Role> orgRoleList = new ArrayList<>(); + orgRoleList.add(role); + orgRoleMap.put(role.getOrgId(), orgRoleList); + } + } + } + + public static void getAllOrg() { + getOrgIdAndOrgNameMap().clear(); + + try { + List<Organization> orgs = superAdminService.getAllOrganization(); + for (Organization org : orgs) { + getOrgIdAndOrgNameMap().put(org.getId(), org.getOrgName()); + } + } catch (Exception e) { + LOGGER.error(String.format("Error : %s", e.getMessage())); + } + } + + public static void getAllOrgUsers() { + orgUserMap.clear(); + getUserOrgMap().clear(); + + List<OrgUserRoleDto> orgUserList = userService.getAllOrgUsers(); + for (OrgUserRoleDto dto : orgUserList) { + if (orgUserMap.containsKey(dto.getOrgId())) { + List<Long> userList = orgUserMap.get(dto.getOrgId()); + userList.add(dto.getUserId()); + } else { + List<Long> userList = new ArrayList<>(); + userList.add(dto.getUserId()); + orgUserMap.put(dto.getOrgId(), userList); + } + getUserOrgMap().put(dto.getUserId(), dto.getOrgId()); + } + } + + public static void getAllUserRoles() { + getUserRoleMap().clear(); + getRoleUserMap().clear(); + getUserRoleListMap().clear(); + + List<OrgUserRoleDto> userRoleList = userService.getAllUserRoles(); + for (OrgUserRoleDto dto : userRoleList) { + if (!getUserRoleMap().containsKey(dto.getUserId())) { + getUserRoleMap().put(dto.getUserId(), dto.getRoleId()); + } + + if (!getRoleUserMap().containsKey(dto.getRoleId())) { + getRoleUserMap().put(dto.getRoleId(), dto.getUserId()); + } + + if (!getUserRoleListMap().containsKey(dto.getUserId())) { + getUserRoleListMap().put(dto.getUserId(), dto.getRoleIds()); + } + } + } + + public static void getAllActionsForRoles() { + roleActionsListMap.clear(); + List<Long> roleIds = new ArrayList<>(); + for (Map.Entry<Long, Role> entry : getRoleMap().entrySet()) { + roleIds.add(entry.getKey()); + } + Map<Long, List<String>> fetchedMap = roleActionService.getAllActionsForRoles(roleIds); + roleActionsListMap.putAll(fetchedMap); + } + + public static void getHelpdeskIdFromAppId() { + helpdeskIdAppIdsMapping.clear(); + appIdHelpdeskIdMapping.clear(); + + List<HelpDeskApp> appIdHelpdeskId = helpdeskService.getAppIdAndHelpDeskId(); + for (HelpDeskApp dto : appIdHelpdeskId) { + appIdHelpdeskIdMapping.put(dto.getAppId(), dto.getHelpDeskId()); + List<Long> appIds = new ArrayList<>(); + if (helpdeskIdAppIdsMapping.get(dto.getHelpDeskId()) != null) { + appIds = helpdeskIdAppIdsMapping.get(dto.getHelpDeskId()); + } + appIds.add(dto.getAppId()); + helpdeskIdAppIdsMapping.put(dto.getHelpDeskId(), appIds); + } + } + + public static void getAppObjectFromAppName() { + appIdAppObjectMapping.clear(); + appNameAppObjectMapping.clear(); + + List<App> app = applicationService.getAppIdAndAppObject(); + for (App dto : app) { + appNameAppObjectMapping.put(dto.getName(), dto); + appIdAppObjectMapping.put(dto.getId(), dto); + } + + } + + public static void getHelpdeskObjectFromHelpdeskId() { + getHelpdeskIdHelpdeskObjectMapping().clear(); + + List<Helpdesk> helpdesk = helpdeskService.getHelpdeskObjectFromHelpdeskId(); + for (Helpdesk dto : helpdesk) { + getHelpdeskIdHelpdeskObjectMapping().put(dto.getId(), dto); + } + } + + public static void getUserIdAndUserName() { + getUserIdAndUserNameMap().clear(); + List<User> users = userService.getUserIdAndUserName(); + for (User usr : users) { + getUserIdAndUserNameMap().put(usr.getId(), usr.getName()); + } + } + + + + public static List<Role> getRolesByOrg(Long orgId) { + if (orgRoleMap.containsKey(orgId)) { + return orgRoleMap.get(orgId); + } else { + getAllOrgRoles(); + if (orgRoleMap.containsKey(orgId)) { + return orgRoleMap.get(orgId); + } else { + return new ArrayList<>(); + } + } + } + + public static Role getRoleById(Long roleId) { + if (getRoleMap().containsKey(roleId)) { + return getRoleMap().get(roleId); + } else { + getAllOrgRoles(); + if (getRoleMap().containsKey(roleId)) { + return getRoleMap().get(roleId); + } else { + return new Role(); + } + } + } + + public static Long getOrgForUser(Long userId) { + if (getUserOrgMap().containsKey(userId)) { + return getUserOrgMap().get(userId); + } else { + getAllOrgUsers(); + if (getUserOrgMap().containsKey(userId)) { + return getUserOrgMap().get(userId); + } else { + return 0L; + } + } + } + + public static List<Long> getUsersForOrg(Long orgId) { + if (orgUserMap.containsKey(orgId)) { + return orgUserMap.get(orgId); + } else { + getAllOrgUsers(); + if (orgUserMap.containsKey(orgId)) { + return orgUserMap.get(orgId); + } else { + return new ArrayList<>(); + } + } + } + + public static Long getRoleForUser(Long userId) { + if (getUserRoleMap().containsKey(userId)) { + return getUserRoleMap().get(userId); + } else { + getAllUserRoles(); + if (getUserRoleMap().containsKey(userId)) { + return getUserRoleMap().get(userId); + } else { + return 0l; + } + } + } + + public static Long getUserForRole(Long roleId) { + if (getRoleUserMap().containsKey(roleId)) { + return getRoleUserMap().get(roleId); + } else { + getAllUserRoles(); + if (getRoleUserMap().containsKey(roleId)) { + return getRoleUserMap().get(roleId); + } else { + return 0l; + } + } + } + + public static List<Long> getAppIdsForHelpdesk(Long helpdeskId) { + if (helpdeskIdAppIdsMapping.containsKey(helpdeskId)) { + return helpdeskIdAppIdsMapping.get(helpdeskId); + } else { + getHelpdeskIdFromAppId(); + if (helpdeskIdAppIdsMapping.containsKey(helpdeskId)) { + return helpdeskIdAppIdsMapping.get(helpdeskId); + } else { + return new ArrayList<>(); + } + } + } + + public static App getAppFromAppId(Long appId) { + if (appIdAppObjectMapping.containsKey(appId)) { + return appIdAppObjectMapping.get(appId); + } else { + getAppObjectFromAppName(); + if (appIdAppObjectMapping.containsKey(appId)) { + return appIdAppObjectMapping.get(appId); + } else { + return null; + } + } + } + + public static List<Long> getRoleIdsForUserId(Long userId) { + if (getUserRoleListMap().containsKey(userId)) { + return getUserRoleListMap().get(userId); + } else { + getAllUserRoles(); + if (getUserRoleListMap().containsKey(userId)) { + return getUserRoleListMap().get(userId); + } else { + return new ArrayList<>(); + } + } + } + + public static List<String> getActionUrlsForRoleId(Long roleId) { + if (roleActionsListMap.containsKey(roleId)) { + return roleActionsListMap.get(roleId); + } else { + getAllUserRoles(); + if (roleActionsListMap.containsKey(roleId)) { + return roleActionsListMap.get(roleId); + } else { + return new ArrayList<>(); + } + } + } + + public static ConcurrentMap<Long, Long> getUserOrgMap() { + return userOrgMap; + } + + public static void setUserOrgMap(ConcurrentMap<Long, Long> userOrgMap) { + MasterDataManager.userOrgMap = userOrgMap; + } + + public static ConcurrentMap<Long, String> getOrgIdAndOrgNameMap() { + return orgIdAndOrgNameMap; + } + + public static void setOrgIdAndOrgNameMap(ConcurrentMap<Long, String> orgIdAndOrgNameMap) { + MasterDataManager.orgIdAndOrgNameMap = orgIdAndOrgNameMap; + } + + public static ConcurrentMap<Long, Role> getRoleMap() { + return roleMap; + } + + public static void setRoleMap(ConcurrentMap<Long, Role> roleMap) { + MasterDataManager.roleMap = roleMap; + } + + public static ConcurrentMap<Long, Long> getUserRoleMap() { + return userRoleMap; + } + + public static void setUserRoleMap(ConcurrentMap<Long, Long> userRoleMap) { + MasterDataManager.userRoleMap = userRoleMap; + } + + public static ConcurrentMap<Long, Helpdesk> getHelpdeskIdHelpdeskObjectMapping() { + return helpdeskIdHelpdeskObjectMapping; + } + + public static void setHelpdeskIdHelpdeskObjectMapping( + ConcurrentMap<Long, Helpdesk> helpdeskIdHelpdeskObjectMapping) { + MasterDataManager.helpdeskIdHelpdeskObjectMapping = helpdeskIdHelpdeskObjectMapping; + } + + public static ConcurrentMap<Long, String> getUserIdAndUserNameMap() { + return userIdAndUserNameMap; + } + + public static void setUserIdAndUserNameMap(ConcurrentMap<Long, String> userIdAndUserNameMap) { + MasterDataManager.userIdAndUserNameMap = userIdAndUserNameMap; + } + + public static ConcurrentMap<Long, Long> getRoleUserMap() { + return roleUserMap; + } + + public static void setRoleUserMap(ConcurrentMap<Long, Long> roleUserMap) { + MasterDataManager.roleUserMap = roleUserMap; + } + + public static ConcurrentMap<Long, List<Long>> getUserRoleListMap() { + return userRoleListMap; + } + + public static void setUserRoleListMap(ConcurrentMap<Long, List<Long>> userRoleListMap) { + MasterDataManager.userRoleListMap = userRoleListMap; + } + +} diff --git a/src/main/java/org/upsmf/grievance/interceptor/TicketsRequestInterceptor.java b/src/main/java/org/upsmf/grievance/interceptor/TicketsRequestInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..fb690d791ce3cae0aad99c67e83f78861081ea23 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/interceptor/TicketsRequestInterceptor.java @@ -0,0 +1,498 @@ +package org.upsmf.grievance.interceptor; + +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.stream.Collectors; + +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.elasticsearch.action.delete.DeleteRequest; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.update.UpdateRequest; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback; +import org.elasticsearch.client.RestHighLevelClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import org.upsmf.grievance.dao.impl.ApplicationDaoImpl; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.ProjectUtil; + +@Component +public class TicketsRequestInterceptor { + + private static final String EL_STIC123 = "El@stic123"; + private static final String ELASTIC = "elastic"; + private static final String ENCOUNTERED_AN_EXCEPTION_S = "Encountered an Exception : %s"; + private static final String CLASSNAME = TicketsRequestInterceptor.class.getName(); + private static BlockingQueue<Ticket> queue = new ArrayBlockingQueue<>(Constants.CAPACITY); + public static final Logger LOGGER = LoggerFactory.getLogger(ApplicationDaoImpl.class); + + @Value("${elk.data.up}") + private boolean elkDataUp; + + @Value("${elasticsearch.url}") + private String elasticsearchUrl; + + @Value("${elasticsearch.index}") + private String elasticsearchIndex; + + @Value("${elasticsearch.type}") + private String elasticsearchType; + + public void addData(Ticket data) { + try { + if (elkDataUp) { + queue.add(data); + processData(); + } else { + LOGGER.info("ELK data insertion is not allowed %s"); + } + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } + } + + public void processData() { + Runnable task1 = new Runnable() { + @Override + public void run() { + try { + Thread.sleep(1000); + Ticket data = queue.take(); + if (data != null) { + if (Constants.ELK_OPERATION.SAVE.toString().equalsIgnoreCase(data.getOperation())) { + addTicketDataToElastic(data); + } else if (Constants.ELK_OPERATION.UPDATE.toString().equalsIgnoreCase(data.getOperation())) { + updateTicketDataInElastic(data); + } else if (Constants.ELK_OPERATION.DELETE.toString().equalsIgnoreCase(data.getOperation())) { + deleteTicketDataFromElastic(data); + } + } else { + LOGGER.error(String.format("unable to get value %s", CLASSNAME)); + } + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } + } + }; + Thread thread1 = new Thread(task1); + thread1.start(); + } + + private Map<String, Object> addTicketDataToElastic(Ticket value) throws ParseException, IOException { + Map<String, Object> jsonMap = createJsonMap(value); + writeDatatoElastic(jsonMap, String.valueOf(value.getId())); + return jsonMap; + } + + private Map<String, Object> updateTicketDataInElastic(Ticket value) throws ParseException, IOException { + Map<String, Object> jsonMap = updateJsonMap(value); + updateDataInElastic(jsonMap, String.valueOf(value.getId())); + return jsonMap; + } + + private Map<String, Object> updateJsonMap(Ticket value) throws ParseException { + Map<String, Object> jsonMap = new HashMap<>(); + setValuesOnUpdate(value, jsonMap); + setValuesOnUpdate2(value, jsonMap); + if (!StringUtils.isBlank(value.getOsVersion())) { + jsonMap.put(Constants.OS_VERSION, value.getOsVersion()); + } + if (!StringUtils.isBlank(value.getOsType())) { + jsonMap.put(Constants.OS_TYPE, value.getOsType()); + } + if (!StringUtils.isBlank(value.getDeviceType())) { + jsonMap.put(Constants.DEVICE_TYPE, value.getDeviceType()); + } + if (!StringUtils.isBlank(value.getIp())) { + jsonMap.put(Constants.IP, value.getIp()); + } + if (!StringUtils.isBlank(value.getCountry())) { + jsonMap.put(Constants.COUNTRY, value.getCountry()); + } + if (!StringUtils.isBlank(value.getDeviceName())) { + jsonMap.put(Constants.DEVICE_NAME, value.getDeviceName()); + } + if (!StringUtils.isBlank(value.getDeviceManufacture())) { + jsonMap.put(Constants.DEVICE_MANUFACTURE, value.getDeviceManufacture()); + } + if (!StringUtils.isBlank(value.getDeviceLocale())) { + jsonMap.put(Constants.DEVICE_LOCALE, value.getDeviceLocale()); + } + if (!StringUtils.isBlank(value.getDeviceScreenResolution())) { + jsonMap.put(Constants.DEVICE_SCREEN_RESOLUTION, value.getDeviceScreenResolution()); + } + if (!StringUtils.isBlank(value.getUserEvent())) { + jsonMap.put(Constants.USER_EVENT, value.getUserEvent()); + } + if (!ProjectUtil.isObjectListNullOrEmpty(value.getTags())) { + jsonMap.put(Constants.TAGS2, value.getTags().stream().map(Tags::getName).collect(Collectors.toList())); + } + if (!ProjectUtil.isObjectListNullOrEmpty(value.getCc())) { + jsonMap.put(Constants.CC, value.getCc()); + } + return jsonMap; + } + + public void setValuesOnUpdate2(Ticket value, Map<String, Object> jsonMap) { + if (value.getPinnedTicket() != null) { + jsonMap.put(Constants.PINNED_TICKET, value.getPinnedTicket()); + } + jsonMap.put(Constants.OPR, Constants.UPDATE); + if (value.getAppId() != null) { + jsonMap.put(Constants.APP_ID, value.getAppId()); + } + if (value.getHelpdeskId() != null) { + jsonMap.put(Constants.HELPDESK_ID, value.getHelpdeskId()); + } + if (value.getSourceId() != null) { + jsonMap.put(Constants.SOURCE_ID, value.getSourceId()); + } + if (value.getType() != null) { + jsonMap.put(Constants.TYPE_ID, value.getType()); + } + if (!StringUtils.isBlank(value.getPriority())) { + jsonMap.put(Constants.PRIORITY, value.getPriority()); + } + if (!StringUtils.isBlank(value.getStatus())) { + jsonMap.put(Constants.STATUS, value.getStatus()); + } + } + + public void setValuesOnUpdate(Ticket value, Map<String, Object> jsonMap) throws ParseException { + setValuesOnUpdate3(value, jsonMap); + if (value.getUpdatedTime() != null) { + jsonMap.put(Constants.U_T, value.getUpdatedTime().split(" ")[1]); + } + if (value.getCreatedTimeTS() != null) { + jsonMap.put(Constants.CREATED_TIME_TS, value.getCreatedTimeTS()); + } else if (value.getCreatedTime() != null) { + jsonMap.put(Constants.CREATED_TIME_TS, timestampconvertor(value.getCreatedTime())); + } + if (value.getUpdatedTimeTS() != null) { + jsonMap.put(Constants.UPDATED_TIME_TS, value.getUpdatedTimeTS()); + } + if (value.getRequestedBy() != null) { + jsonMap.put(Constants.REQUESTED_BY, value.getRequestedBy()); + } + if (!StringUtils.isBlank(value.getAppVersion())) { + jsonMap.put(Constants.APP_VERSION, value.getAppVersion()); + } + if (!StringUtils.isBlank(value.getAppName())) { + jsonMap.put(Constants.APP_NAME, value.getAppName()); + } + if (value.getActive() != null) { + jsonMap.put(Constants.ACTIVE, value.getActive()); + } + } + + public void setValuesOnUpdate3(Ticket value, Map<String, Object> jsonMap) { + if (!StringUtils.isBlank(value.getDescription())) { + jsonMap.put(Constants.DESCRIPTION, value.getDescription()); + } + if (!StringUtils.isBlank(value.getReviewId())) { + jsonMap.put(Constants.REVIEW_ID, value.getReviewId()); + } + if (!StringUtils.isBlank(String.valueOf(value.getRate())) && value.getRate() > 0) { + jsonMap.put(Constants.RATE, value.getRate()); + } + if (!StringUtils.isBlank(String.valueOf(value.getMaxRating())) && value.getMaxRating() > 0) { + jsonMap.put(Constants.MAX_RATING, value.getMaxRating()); + } + if (value.getCreatedTime() != null) { + jsonMap.put(Constants.CREATED_TIME, value.getCreatedTime().split(" ")[0]); + } + if (value.getUpdatedTime() != null) { + jsonMap.put(Constants.UPDATED_TIME, value.getUpdatedTime().split(" ")[0]); + } + if (value.getCreatedTime() != null) { + jsonMap.put(Constants.C_T, value.getCreatedTime().split(" ")[1]); + } + } + + public Map<String, Object> createJsonMap(Ticket value) throws ParseException { + Map<String, Object> jsonMap = new HashMap<>(); + setValuesOnCreate(value, jsonMap); + setValuesOnCreate2(value, jsonMap); + setValuesOnCreate3(value, jsonMap); + setValuesOnCreate4(value, jsonMap); + setValuesOnCreate5(value, jsonMap); + return jsonMap; + } + + public void setValuesOnCreate5(Ticket value, Map<String, Object> jsonMap) { + if (!StringUtils.isBlank(value.getDeviceScreenResolution())) { + jsonMap.put(Constants.DEVICE_SCREEN_RESOLUTION, value.getDeviceScreenResolution()); + } else { + jsonMap.put(Constants.DEVICE_SCREEN_RESOLUTION, null); + } + if (!StringUtils.isBlank(value.getUserEvent())) { + jsonMap.put(Constants.USER_EVENT, value.getUserEvent()); + } else { + jsonMap.put(Constants.USER_EVENT, null); + } + if (!ProjectUtil.isObjectListNullOrEmpty(value.getTags())) { + jsonMap.put(Constants.TAGS2, value.getTags().stream().map(Tags::getName).collect(Collectors.toList())); + } else { + jsonMap.put(Constants.TAGS2, null); + } + if (!ProjectUtil.isObjectListNullOrEmpty(value.getCc())) { + jsonMap.put(Constants.CC, value.getCc()); + } else { + jsonMap.put(Constants.CC, null); + } + } + + public void setValuesOnCreate4(Ticket value, Map<String, Object> jsonMap) { + setValuesOnCreate6(value, jsonMap); + if (!StringUtils.isBlank(value.getCountry())) { + jsonMap.put(Constants.COUNTRY, value.getCountry()); + } else { + jsonMap.put(Constants.COUNTRY, null); + } + if (!StringUtils.isBlank(value.getDeviceName())) { + jsonMap.put(Constants.DEVICE_NAME, value.getDeviceName()); + } else { + jsonMap.put(Constants.DEVICE_NAME, null); + } + if (!StringUtils.isBlank(value.getDeviceManufacture())) { + jsonMap.put(Constants.DEVICE_MANUFACTURE, value.getDeviceManufacture()); + } else { + jsonMap.put(Constants.DEVICE_MANUFACTURE, null); + } + if (!StringUtils.isBlank(value.getDeviceLocale())) { + jsonMap.put(Constants.DEVICE_LOCALE, value.getDeviceLocale()); + } else { + jsonMap.put(Constants.DEVICE_LOCALE, null); + } + } + + public void setValuesOnCreate6(Ticket value, Map<String, Object> jsonMap) { + if (!StringUtils.isBlank(value.getOsVersion())) { + jsonMap.put(Constants.OS_VERSION, value.getOsVersion()); + } else { + jsonMap.put(Constants.OS_VERSION, null); + } + if (!StringUtils.isBlank(value.getOsType())) { + jsonMap.put(Constants.OS_TYPE, value.getOsType()); + } else { + jsonMap.put(Constants.OS_TYPE, null); + } + if (!StringUtils.isBlank(value.getDeviceType())) { + jsonMap.put(Constants.DEVICE_TYPE, value.getDeviceType()); + } else { + jsonMap.put(Constants.DEVICE_TYPE, null); + } + jsonMap.put(Constants.SV, Constants.A_1_0); + if (!StringUtils.isBlank(value.getIp())) { + jsonMap.put(Constants.IP, value.getIp()); + } else { + jsonMap.put(Constants.IP, null); + } + } + + public void setValuesOnCreate3(Ticket value, Map<String, Object> jsonMap) { + setValuesOnCreate7(value, jsonMap); + if (!StringUtils.isBlank(String.valueOf(value.getHelpdeskId()))) { + jsonMap.put(Constants.HELPDESK_ID, value.getHelpdeskId()); + } else { + jsonMap.put(Constants.HELPDESK_ID, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getSourceId()))) { + jsonMap.put(Constants.SOURCE_ID, value.getSourceId()); + } else { + jsonMap.put(Constants.SOURCE_ID, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getType()))) { + jsonMap.put(Constants.TYPE_ID, value.getType()); + } else { + jsonMap.put(Constants.TYPE_ID, null); + } + if (!StringUtils.isBlank(value.getPriority())) { + jsonMap.put(Constants.PRIORITY, value.getPriority()); + } else { + jsonMap.put(Constants.PRIORITY, null); + } + if (!StringUtils.isBlank(value.getStatus())) { + jsonMap.put(Constants.STATUS, value.getStatus()); + } else { + jsonMap.put(Constants.STATUS, null); + } + } + + public void setValuesOnCreate7(Ticket value, Map<String, Object> jsonMap) { + if (!StringUtils.isBlank(value.getAppName())) { + jsonMap.put(Constants.APP_NAME, value.getAppName()); + } else { + jsonMap.put(Constants.APP_NAME, null); + } + jsonMap.put(Constants.ACTIVE, value.getActive()); + jsonMap.put(Constants.PINNED_TICKET, value.getPinnedTicket()); + if (value.getOperation().equalsIgnoreCase(Constants.SAVE)) { + jsonMap.put(Constants.OPR, Constants.SAVE); + } else { + jsonMap.put(Constants.OPR, Constants.UPDATE); + } + if (!StringUtils.isBlank(String.valueOf(value.getAppId()))) { + jsonMap.put(Constants.APP_ID, value.getAppId()); + } else { + jsonMap.put(Constants.APP_ID, null); + } + } + + public void setValuesOnCreate2(Ticket value, Map<String, Object> jsonMap) throws ParseException { + if (!StringUtils.isBlank(String.valueOf(value.getCreatedTime()))) { + jsonMap.put(Constants.C_T, value.getCreatedTime().split(" ")[1]); + } else { + jsonMap.put(Constants.C_T, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getUpdatedTime()))) { + jsonMap.put(Constants.U_T, value.getUpdatedTime().split(" ")[1]); + } else { + jsonMap.put(Constants.U_T, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getCreatedTimeTS()))) { + jsonMap.put(Constants.CREATED_TIME_TS, value.getCreatedTimeTS()); + } else if (!StringUtils.isBlank(String.valueOf(value.getCreatedTime()))) { + jsonMap.put(Constants.CREATED_TIME_TS, timestampconvertor(value.getCreatedTime())); + } else { + jsonMap.put(Constants.CREATED_TIME_TS, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getUpdatedTimeTS()))) { + jsonMap.put(Constants.UPDATED_TIME_TS, value.getUpdatedTimeTS()); + } else { + jsonMap.put(Constants.UPDATED_TIME_TS, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getRequestedBy()))) { + jsonMap.put(Constants.REQUESTED_BY, value.getRequestedBy()); + } else { + jsonMap.put(Constants.REQUESTED_BY, null); + } + if (!StringUtils.isBlank(value.getAppVersion())) { + jsonMap.put(Constants.APP_VERSION, value.getAppVersion()); + } else { + jsonMap.put(Constants.APP_VERSION, null); + } + } + + public void setValuesOnCreate(Ticket value, Map<String, Object> jsonMap) { + if (!StringUtils.isBlank(String.valueOf(value.getId()))) { + jsonMap.put(Constants.ID, value.getId()); + } else { + jsonMap.put(Constants.ID, 0); + } + if (!StringUtils.isBlank(value.getDescription())) { + jsonMap.put(Constants.DESCRIPTION, value.getDescription()); + } else { + jsonMap.put(Constants.DESCRIPTION, null); + } + if (!StringUtils.isBlank(value.getReviewId())) { + jsonMap.put(Constants.REVIEW_ID, value.getReviewId()); + } else { + jsonMap.put(Constants.REVIEW_ID, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getRate()))) { + jsonMap.put(Constants.RATE, value.getRate()); + } else { + jsonMap.put(Constants.RATE, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getMaxRating()))) { + jsonMap.put(Constants.MAX_RATING, value.getMaxRating()); + } else { + jsonMap.put(Constants.MAX_RATING, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getCreatedTime()))) { + jsonMap.put(Constants.CREATED_TIME, value.getCreatedTime().split(" ")[0]); + } else { + jsonMap.put(Constants.CREATED_TIME, null); + } + if (!StringUtils.isBlank(String.valueOf(value.getUpdatedTime()))) { + jsonMap.put(Constants.UPDATED_TIME, value.getUpdatedTime().split(" ")[0]); + } else { + jsonMap.put(Constants.UPDATED_TIME, null); + } + } + + private void deleteTicketDataFromElastic(Ticket data) throws IOException { + RestHighLevelClient rc = new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchUrl))); + try { + DeleteRequest request = new DeleteRequest(elasticsearchIndex, "doc", String.valueOf(data.getId())); + rc.delete(request); + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } finally { + rc.close(); + } + } + + public Long timestampconvertor(String createdDate) throws ParseException { + try { + DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); + Date date = dateFormat.parse(createdDate); + return date.getTime() / 1000; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION_S, e.getMessage())); + } + return null; + } + + private RestHighLevelClient connectToElasticSearch() { + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTIC, EL_STIC123)); + + HttpClientConfigCallback httpClientConfigCallback = new HttpClientConfigCallback() { + @Override + public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) { + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + } + }; + return new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchUrl)) + .setHttpClientConfigCallback(httpClientConfigCallback)); + } + + private void writeDatatoElastic(Map<String, Object> jsonMap, String id) throws IOException { + RestHighLevelClient rc = connectToElasticSearch(); + try { + IndexRequest indexRequest = new IndexRequest(elasticsearchIndex, elasticsearchType, id).source(jsonMap); + IndexResponse response = rc.index(indexRequest); + if (!StringUtils.isBlank(response.toString())) { + LOGGER.info("Response : {}", response); + } + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } finally { + rc.close(); + } + } + + private void updateDataInElastic(Map<String, Object> jsonMap, String id) throws IOException { + RestHighLevelClient rc = connectToElasticSearch(); + try { + UpdateRequest updateRequest = new UpdateRequest(elasticsearchIndex, elasticsearchType, id).doc(jsonMap); + rc.update(updateRequest); + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } finally { + rc.close(); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/interceptor/package-info.java b/src/main/java/org/upsmf/grievance/interceptor/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..01a6f3a7f9655bd3507019b22587c1a2c03f20c9 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/interceptor/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Juhi Agarwal + * + */ +package org.upsmf.grievance.interceptor; \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/Access.java b/src/main/java/org/upsmf/grievance/model/Access.java new file mode 100644 index 0000000000000000000000000000000000000000..e5c4fc861176880a77305167438ce6c7aae9dbde --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Access.java @@ -0,0 +1,25 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Access { + + private Long orgId; + private String grantType; + private String code; + private String clientId; + private String clientSecret; + private String refreshToken; + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/AccessResponse.java b/src/main/java/org/upsmf/grievance/model/AccessResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..4ba5b176ad51a831ec07d66854bda794c2b4160a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/AccessResponse.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class AccessResponse { + + private String accessToken; + private Long expiresIn; + private String scope; + private String tokenType; +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/Action.java b/src/main/java/org/upsmf/grievance/model/Action.java new file mode 100644 index 0000000000000000000000000000000000000000..14f1d85f4d56fa443ceb6d1d68b9eb29b5253c8d --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Action.java @@ -0,0 +1,24 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@AllArgsConstructor +@EqualsAndHashCode +@NoArgsConstructor +@ToString +public class Action { + + private Long id; + private String name; + private String displayName; + private String url; + private String queryParams; + private String serviceCode; +} diff --git a/src/main/java/org/upsmf/grievance/model/ActionRole.java b/src/main/java/org/upsmf/grievance/model/ActionRole.java new file mode 100644 index 0000000000000000000000000000000000000000..71839de1d65502d72dccf41ef5fe5fd3384a0636 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/ActionRole.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class ActionRole { + + private long actionId; + private long roleId; +} diff --git a/src/main/java/org/upsmf/grievance/model/ActivityLog.java b/src/main/java/org/upsmf/grievance/model/ActivityLog.java new file mode 100644 index 0000000000000000000000000000000000000000..f2cbdaf8987dfa9fa3ee871a2d5c6d51c56822e3 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/ActivityLog.java @@ -0,0 +1,29 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class ActivityLog implements Comparable<ActivityLog> { + + private Long id; + private String activity; + private Long ticketId; + private String timestamp; + private Long changesBy; + private Long helpdeskId; + + @Override + public int compareTo(ActivityLog o) { + return this.getId().compareTo(o.getId()); + } +} diff --git a/src/main/java/org/upsmf/grievance/model/Analytics.java b/src/main/java/org/upsmf/grievance/model/Analytics.java new file mode 100644 index 0000000000000000000000000000000000000000..b66365357ce55cfa26b4dac3a02fb6197451ea8f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Analytics.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Analytics { + + private Long userId; + private String startDate; + private String endDate; + +} diff --git a/src/main/java/org/upsmf/grievance/model/App.java b/src/main/java/org/upsmf/grievance/model/App.java new file mode 100644 index 0000000000000000000000000000000000000000..b1690674546e7b80738e1f9b4bfbaffaeaa8d01f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/App.java @@ -0,0 +1,35 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class App { + + private Long id; + private String name; + private String code; + private String description; + private String clientName; + private String version; + private String appUrl; + private String logo; + private Long sourceId; + private Boolean activeStatus; + private Long orgId; + private String createdDate; + private Long createdBy; + private String updatedDate; + private Long updatedBy; + private String appKey; + +} diff --git a/src/main/java/org/upsmf/grievance/model/ChecklistItem.java b/src/main/java/org/upsmf/grievance/model/ChecklistItem.java new file mode 100644 index 0000000000000000000000000000000000000000..73b73587473ba166d95da6d2a50c3069bd810872 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/ChecklistItem.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class ChecklistItem { + + private Long id; + private String item; + private Boolean checked; +} diff --git a/src/main/java/org/upsmf/grievance/model/Comment.java b/src/main/java/org/upsmf/grievance/model/Comment.java new file mode 100644 index 0000000000000000000000000000000000000000..ab702b440c76c385ffe2ed9dcb5fe2f0a6529b0b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Comment.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Comment { + + private UserComment userComment; + private DeveloperComment developerComment; +} diff --git a/src/main/java/org/upsmf/grievance/model/CommonDataModel.java b/src/main/java/org/upsmf/grievance/model/CommonDataModel.java new file mode 100644 index 0000000000000000000000000000000000000000..c16e622e23d6cfe332bde773ab7519e2bddb9bd3 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/CommonDataModel.java @@ -0,0 +1,79 @@ +package org.upsmf.grievance.model; + +import org.upsmf.grievance.model.enums.AuthTypes; +import org.upsmf.grievance.model.enums.PriorityLevels; + +public class CommonDataModel { + private int id; + private String name; + private String description; + private long userId; + private boolean active; + private long orgId; + + public long getOrgId() { + return orgId; + } + + public void setOrgId(long orgId) { + this.orgId = orgId; + } + + public CommonDataModel() { + } + + public CommonDataModel(PriorityLevels priorityLevels) { + this.name = String.valueOf(priorityLevels); + } + + public CommonDataModel(AuthTypes authTypes) { + this.id = authTypes.ordinal() + 1; + this.name = String.valueOf(authTypes); + } + + public CommonDataModel(int id, String name) { + this.id = id; + this.name = name; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public long getUserId() { + return userId; + } + + public void setUserId(long userId) { + this.userId = userId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/DeveloperComment.java b/src/main/java/org/upsmf/grievance/model/DeveloperComment.java new file mode 100644 index 0000000000000000000000000000000000000000..161cbf8276b145e5748f0bd076d087abbd463229 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/DeveloperComment.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class DeveloperComment { + + private String text; + private LastModified lastModified; + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/DeviceMetadata.java b/src/main/java/org/upsmf/grievance/model/DeviceMetadata.java new file mode 100644 index 0000000000000000000000000000000000000000..fd587962619c4004485b34889bc80521606a8ae7 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/DeviceMetadata.java @@ -0,0 +1,30 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class DeviceMetadata { + + private String productName; + private String manufacturer; + private String deviceClass; + private Long screenWidthPx; + private Long screenHeightPx; + private String nativePlatform; + private Long screenDensityDpi; + private Long glEsVersion; + private String cpuModel; + private String cpuMake; + private Long ramMb; + +} diff --git a/src/main/java/org/upsmf/grievance/model/HelpDeskApp.java b/src/main/java/org/upsmf/grievance/model/HelpDeskApp.java new file mode 100644 index 0000000000000000000000000000000000000000..93faa0a7d4f655c9591eb20de26571d4c5b317a5 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/HelpDeskApp.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class HelpDeskApp { + + private Long helpDeskId; + private Long appId; + +} diff --git a/src/main/java/org/upsmf/grievance/model/Helpdesk.java b/src/main/java/org/upsmf/grievance/model/Helpdesk.java new file mode 100644 index 0000000000000000000000000000000000000000..a70c316cee39f9d5a560d3ceb4e28434f3847d2c --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Helpdesk.java @@ -0,0 +1,67 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.upsmf.grievance.dto.HelpdeskDto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Helpdesk { + + private Long id; + private String name; + private Long orgId; + private Long createdBy; + private String createdDate; + private Long updatedBy; + private String updatedDate; + private List<Long> adminIds; + private List<User> adminDetails; + private String description; + private String color; + private List<Long> appIds; + private List<Long> sourceId; + private List<Long> userIds; + private Boolean allowAllUsers; + private List<User> admins; + private Boolean direct; + private Boolean playstore; + private Boolean appstore; + private Boolean aurora_sdk; + + public Helpdesk(HelpdeskDto helpdeskDto) { + this.id = helpdeskDto.getId(); + this.name = helpdeskDto.getName(); + this.orgId = helpdeskDto.getOrgId(); + this.createdBy = helpdeskDto.getCreatedBy(); + this.createdDate = helpdeskDto.getCreatedDate(); + this.updatedBy = helpdeskDto.getUpdatedBy(); + this.updatedDate = helpdeskDto.getUpdatedDate(); + this.isActive = helpdeskDto.getIsActive(); + this.color = helpdeskDto.getColor(); + this.description = helpdeskDto.getDescription(); + this.adminIds = helpdeskDto.getAdminIds(); + this.appIds = helpdeskDto.getAppIds(); + this.sourceId = helpdeskDto.getSourceId(); + this.userIds = helpdeskDto.getUserIds(); + this.allowAllUsers = helpdeskDto.getAllowAllUsers(); + this.admins = helpdeskDto.getAdmins(); + this.direct = helpdeskDto.getDirect(); + this.playstore = helpdeskDto.getPlaystore(); + this.appstore = helpdeskDto.getAppstore(); + this.aurora_sdk = helpdeskDto.getAuroraSdk(); + } + + @JsonProperty("isActive") + private Boolean isActive; +} diff --git a/src/main/java/org/upsmf/grievance/model/HelpdeskType.java b/src/main/java/org/upsmf/grievance/model/HelpdeskType.java new file mode 100644 index 0000000000000000000000000000000000000000..7c44f6a7c70ceb757597a28b99ff1cfe49273635 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/HelpdeskType.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class HelpdeskType { + private Long id; + private Long helpdeskId; + private String name; + private List<ChecklistItem> checklistItems; +} diff --git a/src/main/java/org/upsmf/grievance/model/HelpdeskWorkflow.java b/src/main/java/org/upsmf/grievance/model/HelpdeskWorkflow.java new file mode 100644 index 0000000000000000000000000000000000000000..6e19aaa1c740b26aea16e5d7a88d938e6292132f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/HelpdeskWorkflow.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class HelpdeskWorkflow { + + private Long id; + private Long typeId; + private String name; + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/KeyFactory.java b/src/main/java/org/upsmf/grievance/model/KeyFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..47a52de1806c05d392692fbff8bd0967fbfe7e83 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/KeyFactory.java @@ -0,0 +1,18 @@ +package org.upsmf.grievance.model; + +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Component; + +@Component +public class KeyFactory { + + private KeyFactory() { + super(); + } + + public static KeyHolder getkeyHolder() { + return new GeneratedKeyHolder(); + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/LastModified.java b/src/main/java/org/upsmf/grievance/model/LastModified.java new file mode 100644 index 0000000000000000000000000000000000000000..7cec582cbb0997bf5b75ee6ab6f3f48db1a30f30 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/LastModified.java @@ -0,0 +1,19 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class LastModified { + + private String seconds; + private Long nanos; + +} diff --git a/src/main/java/org/upsmf/grievance/model/LoginUser.java b/src/main/java/org/upsmf/grievance/model/LoginUser.java new file mode 100644 index 0000000000000000000000000000000000000000..88e435015671c905876c2da4cf2893de89f16c15 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/LoginUser.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class LoginUser { + + private String username; + private String password; + private String email; +} diff --git a/src/main/java/org/upsmf/grievance/model/MasterData.java b/src/main/java/org/upsmf/grievance/model/MasterData.java new file mode 100644 index 0000000000000000000000000000000000000000..7b6f5e3731f146e943007774081a94fecbf7f85c --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/MasterData.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class MasterData { + + private String field; + private Long count; +} diff --git a/src/main/java/org/upsmf/grievance/model/Organization.java b/src/main/java/org/upsmf/grievance/model/Organization.java new file mode 100644 index 0000000000000000000000000000000000000000..d6df849a29adbdb26021fbeb2ba5810a32d2b41c --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Organization.java @@ -0,0 +1,34 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class Organization { + private Long id; + private Long userId; + private String orgName; + private String url; + private String logo; + private Long createdBy; + private String createdDate; + private Long updatedBy; + private String updatedDate; + private Boolean isActive; + private List<User> adminDetails; + private String authId; + private String emailDomain; + private String orgDescription; + private String orgColor; + private String baseUrl; + +} diff --git a/src/main/java/org/upsmf/grievance/model/ReplyToReviews.java b/src/main/java/org/upsmf/grievance/model/ReplyToReviews.java new file mode 100644 index 0000000000000000000000000000000000000000..b4180e46d8268c87b9ffef957c0d866552766e43 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/ReplyToReviews.java @@ -0,0 +1,19 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class ReplyToReviews { + + private String reply; +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/Rev.java b/src/main/java/org/upsmf/grievance/model/Rev.java new file mode 100644 index 0000000000000000000000000000000000000000..a1b266667551e718dae8a877822afa2a6ac2e69a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Rev.java @@ -0,0 +1,19 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class Rev { + + private List<Review> reviews = null; +} diff --git a/src/main/java/org/upsmf/grievance/model/Review.java b/src/main/java/org/upsmf/grievance/model/Review.java new file mode 100644 index 0000000000000000000000000000000000000000..542a1747eda97391d51382250a1f9da19627533d --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Review.java @@ -0,0 +1,23 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class Review { + + private String reviewId; + + private String authorName; + private List<Comment> comments = null; + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/Role.java b/src/main/java/org/upsmf/grievance/model/Role.java new file mode 100644 index 0000000000000000000000000000000000000000..f08e0b0923882cefdde8b7fe3e603d9872742225 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Role.java @@ -0,0 +1,18 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Role { + private Long id; + private String name; + private Long orgId; +} diff --git a/src/main/java/org/upsmf/grievance/model/RolesDto.java b/src/main/java/org/upsmf/grievance/model/RolesDto.java new file mode 100644 index 0000000000000000000000000000000000000000..6a85aad461bd8f9d3f4d9de31a9ad64cd5ad512a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/RolesDto.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class RolesDto { + + private List<Integer> ids; + private Long id; + private boolean active; + +} diff --git a/src/main/java/org/upsmf/grievance/model/S3Config.java b/src/main/java/org/upsmf/grievance/model/S3Config.java new file mode 100644 index 0000000000000000000000000000000000000000..82c39c283eae0b009515d3a799c4d2ed320c2307 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/S3Config.java @@ -0,0 +1,46 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class S3Config { + + private String secretKey; + private String accessKey; + private String bucketName; + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getBucketName() { + return bucketName; + } + + public void setBucketName(String bucketName) { + this.bucketName = bucketName; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/ServiceRequest.java b/src/main/java/org/upsmf/grievance/model/ServiceRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..1230eb2e2269633112c815dd307a2b7c644b3211 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/ServiceRequest.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class ServiceRequest { + private Long id; + private String name; + +} diff --git a/src/main/java/org/upsmf/grievance/model/StatusIdMap.java b/src/main/java/org/upsmf/grievance/model/StatusIdMap.java new file mode 100644 index 0000000000000000000000000000000000000000..8b913fe07e860f9479a1548d50039e4f6b8b538a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/StatusIdMap.java @@ -0,0 +1,26 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class StatusIdMap { + + private Long orgId; + private Long appId; + private Long helpdeskId; + private boolean orgAppStatus; + private boolean helpdeskAppStatus; + private Long orgAppMapId; + private Long helpdeskAppMapId; + +} diff --git a/src/main/java/org/upsmf/grievance/model/Tags.java b/src/main/java/org/upsmf/grievance/model/Tags.java new file mode 100644 index 0000000000000000000000000000000000000000..0faa4b7459c5d191de18897cc2364b9c2f7f79c6 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Tags.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Tags { + + private Long id; + private String name; + private Long createdBy; +} diff --git a/src/main/java/org/upsmf/grievance/model/Task.java b/src/main/java/org/upsmf/grievance/model/Task.java new file mode 100644 index 0000000000000000000000000000000000000000..f5d6eadba24b70a4b5e778926296bc55165e9164 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Task.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Task { + private Long id; + private String name; + private String description; +} diff --git a/src/main/java/org/upsmf/grievance/model/Template.java b/src/main/java/org/upsmf/grievance/model/Template.java new file mode 100644 index 0000000000000000000000000000000000000000..c16ceb4947f034f1119a193d5f62e779271090de --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Template.java @@ -0,0 +1,22 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class Template { + + private String name; + private Long id; + private Long helpdeskId; + private List<Task> tasks; +} diff --git a/src/main/java/org/upsmf/grievance/model/TemplateVersion.java b/src/main/java/org/upsmf/grievance/model/TemplateVersion.java new file mode 100644 index 0000000000000000000000000000000000000000..90791b185f97dd782106ab74a5567f4977d3b80b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/TemplateVersion.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class TemplateVersion { + + private Long version; + private List<Template> templates; +} diff --git a/src/main/java/org/upsmf/grievance/model/Ticket.java b/src/main/java/org/upsmf/grievance/model/Ticket.java new file mode 100644 index 0000000000000000000000000000000000000000..f081766422951cb1e03cec903ea87510e3a62a6b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Ticket.java @@ -0,0 +1,82 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import org.upsmf.grievance.dto.TicketWorkflowDto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class Ticket { + + private Long userId; + private Long id; + private String description; + private String feedback; + private String reviewId; + private String developerComment; + private int rate; + private int maxRating; + private String createdTime; + private String updatedTime; + private Long createdTimeTS; + private Long updatedTimeTS; + private String userName; + private Long requestedBy; + private String operation; + private Long ts; + private Long total; + private Long userTimestamp; + private Long developerTimestamp; + + private String appName; + private String appVersion; + private String country; + private String feedbackByName; + private String sv; + private String userEvent; + private String ip; + private String deviceName; + private String deviceManufacture; + private String deviceScreenResolution; + private String deviceLocale; + private String deviceType; + private String osType; + private String osVersion; + + private String requestedByName; + private String priority; + private List<String> filterStatus; + private String notes; + private List<ChecklistItem> checklist; + + private Long appId; + private String appKey; + private Long helpdeskId; + private Long sourceId; + private Long type; + private List<Updates> updates; + private Long orgId; + private Boolean active; + private Boolean pinnedTicket = false; + private List<TicketWorkflowDto> workflowStages; + private List<Long> cc; + private String filterCTUT; + private int from; + private int size; + private String searchKeyword; + private String status; + private byte[] img; + private List<String> attachmentUrl; + private List<String> selectedTags; + private List<Tags> tags; + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/TicketCount.java b/src/main/java/org/upsmf/grievance/model/TicketCount.java new file mode 100644 index 0000000000000000000000000000000000000000..49b4ef8d69d99adb537cbeb1b10e6443b7dc388a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/TicketCount.java @@ -0,0 +1,23 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class TicketCount { + + private Long userId; + private Long id; + private Long createdTicketCount; + private Long pinnedTicketCount; + private Long closedTicketCount; +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/TicketElastic.java b/src/main/java/org/upsmf/grievance/model/TicketElastic.java new file mode 100644 index 0000000000000000000000000000000000000000..94f6c4724fd1637ef6fb864da65e3a2bce30de04 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/TicketElastic.java @@ -0,0 +1,31 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class TicketElastic { + + private String updatedTime; + private String description; + private Long helpdeskId; + private Long requestedBy; + private String createdTime; + private Long id; + private String status; + private Long total; + private Boolean pinnedTicket; + private String uT; + private String cT; + private String[] cc; + private String[] tags; +} diff --git a/src/main/java/org/upsmf/grievance/model/TicketTags.java b/src/main/java/org/upsmf/grievance/model/TicketTags.java new file mode 100644 index 0000000000000000000000000000000000000000..b9f1098788e39c98f90344178c805017c42c45c0 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/TicketTags.java @@ -0,0 +1,24 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class TicketTags { + + private Long id; + private List<Long> tag; + private Long userId; + private boolean isActive = true; + private Long orgId; + +} diff --git a/src/main/java/org/upsmf/grievance/model/TicketsTagsList.java b/src/main/java/org/upsmf/grievance/model/TicketsTagsList.java new file mode 100644 index 0000000000000000000000000000000000000000..6d64d8ce98941da69da3b2fb40bca2565978460f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/TicketsTagsList.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class TicketsTagsList { + private List<Ticket> ticket = new ArrayList<>(); + private List<Tags> tags = new ArrayList<>(); +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/Updates.java b/src/main/java/org/upsmf/grievance/model/Updates.java new file mode 100644 index 0000000000000000000000000000000000000000..aac9b62819df36324001c3fa433db2eb64b88c8e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/Updates.java @@ -0,0 +1,24 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class Updates { + + private Long ticketId; + private Long id; + private String upds; + private String createdDate; + private Long createdBy; + private boolean active; +} diff --git a/src/main/java/org/upsmf/grievance/model/User.java b/src/main/java/org/upsmf/grievance/model/User.java new file mode 100644 index 0000000000000000000000000000000000000000..7ac16811422f89525dc1b2d59fe4a03679e99057 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/User.java @@ -0,0 +1,77 @@ +package org.upsmf.grievance.model; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * This class holds the information about the User's basic authentication along + * with Mail ID. + * + * @author Darshan Nagesh + * + */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +public class User { + + private Long id; + + private String username; + private byte[] img; + @JsonInclude(Include.NON_NULL) + private String password; + @JsonInclude(Include.NON_NULL) + private String phone; + + @JsonInclude(Include.NON_NULL) + private Long orgId; + + private String name; + private String imagePath; + + @JsonInclude(Include.NON_NULL) + private Boolean isActive; + + @JsonInclude(Include.NON_NULL) + private String authType; + + @JsonProperty("authToken") + @JsonInclude(Include.NON_NULL) + private String authToken; + + @JsonInclude(Include.NON_NULL) + private String createdDate; + + @JsonInclude(Include.NON_NULL) + private Long createdBy; + + @JsonInclude(Include.NON_NULL) + private String updatedDate; + + @JsonInclude(Include.NON_NULL) + private Long updatedBy; + + @JsonInclude(Include.NON_NULL) + private List<Role> roles; + + @JsonInclude(Include.NON_NULL) + private List<Action> actions; + + private List<Organization> organization; + private List<Helpdesk> helpdesk; + + private Boolean isAnonymous; + +} diff --git a/src/main/java/org/upsmf/grievance/model/UserAuthentication.java b/src/main/java/org/upsmf/grievance/model/UserAuthentication.java new file mode 100644 index 0000000000000000000000000000000000000000..90dcb02545dd1f25d6f9c953a920347f696fe9ac --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/UserAuthentication.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class UserAuthentication { + + private long id; + private long userId; + private String authToken; +} diff --git a/src/main/java/org/upsmf/grievance/model/UserComment.java b/src/main/java/org/upsmf/grievance/model/UserComment.java new file mode 100644 index 0000000000000000000000000000000000000000..bdfd70212e9001fa48477b85d93002621c9945c7 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/UserComment.java @@ -0,0 +1,29 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class UserComment { + + private String text; + private LastModified lastModified; + private Long starRating; + private String reviewerLanguage; + private String device; + private Long androidOsVersion; + private Long appVersionCode; + private String appVersionName; + private Long thumbsUpCount; + private Long thumbsDownCount; + private DeviceMetadata deviceMetadata; +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/model/UserIdAndUserName.java b/src/main/java/org/upsmf/grievance/model/UserIdAndUserName.java new file mode 100644 index 0000000000000000000000000000000000000000..e5b1f37d9f7fd9e486479c3a9f7034b820205934 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/UserIdAndUserName.java @@ -0,0 +1,20 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class UserIdAndUserName { + + private Long id; + private String name; +} diff --git a/src/main/java/org/upsmf/grievance/model/UserRole.java b/src/main/java/org/upsmf/grievance/model/UserRole.java new file mode 100644 index 0000000000000000000000000000000000000000..abd5bf7fd764352b34e6f0bbd5017b03e8364cce --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/UserRole.java @@ -0,0 +1,21 @@ +package org.upsmf.grievance.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString(includeFieldNames = true) +@Builder +public class UserRole { + + private long userId; + private long roleId; + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/RequestInfo.java b/src/main/java/org/upsmf/grievance/model/contract/RequestInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..b36203484f99215f0f2935ab926c91642da826c0 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/RequestInfo.java @@ -0,0 +1,44 @@ +package org.upsmf.grievance.model.contract; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * RequestInfo should be used to carry meta information about the requests to + * the server as described in the fields below. Some of this information will be + * returned back from the server as part of the ResponseInfo in the response + * body to ensure correlation + */ +@AllArgsConstructor +@EqualsAndHashCode +@Getter +@NoArgsConstructor +@Setter +@ToString +public class RequestInfo { + + private String apiId; + + private String ver; + + private Long ts; + + private String action; + + private String did; + + private String key; + + private String msgId; + + private String requesterId; + + private String authToken; + + private String correlationId; + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/RoleActionRequest.java b/src/main/java/org/upsmf/grievance/model/contract/RoleActionRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..f766592c46fca87a2a637d1084f130002f6ba97f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/RoleActionRequest.java @@ -0,0 +1,45 @@ +/* + * Musti Backend API - User + * All services for User service + * + * OpenAPI spec version: 1.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +package org.upsmf.grievance.model.contract; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * RoleActionRequest + */ + +public class RoleActionRequest { + + @JsonProperty("RequestInfo") + private RequestInfo requestInfo; + + @JsonProperty("RoleRequest") + private RoleRequest roleRequest; + + public RequestInfo getRequestInfo() { + return requestInfo; + } + + public void setRequestInfo(RequestInfo requestInfo) { + this.requestInfo = requestInfo; + } + + public RoleRequest getRoleRequest() { + return roleRequest; + } + + public void setRoleRequest(RoleRequest roleRequest) { + this.roleRequest = roleRequest; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/RoleActionResponseInfo.java b/src/main/java/org/upsmf/grievance/model/contract/RoleActionResponseInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..4c54a52b79a1531678b7bc28d12c12fe0a5ba685 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/RoleActionResponseInfo.java @@ -0,0 +1,26 @@ +package org.upsmf.grievance.model.contract; + +import java.util.List; + +import org.upsmf.grievance.model.Action; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * ResponseInfo should be used to carry metadata information about the response + * from the server along with the requested data. + */ +@AllArgsConstructor +@Getter +@NoArgsConstructor +@Setter +public class RoleActionResponseInfo { + + private StatusInfo statusInfo; + + private List<Action> actions; + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/RoleRequest.java b/src/main/java/org/upsmf/grievance/model/contract/RoleRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..f33413dd231683ae60a20ebd997f00d4aa8a1cef --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/RoleRequest.java @@ -0,0 +1,39 @@ +package org.upsmf.grievance.model.contract; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * RoleRequest + */ +@AllArgsConstructor +@EqualsAndHashCode +@NoArgsConstructor +@ToString +public class RoleRequest { + + private Boolean enabled; + private List<Integer> roles = new ArrayList<>(); + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public List<Integer> getRoles() { + return roles; + } + + public void setRoles(List<Integer> roles) { + this.roles = roles; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/StatusInfo.java b/src/main/java/org/upsmf/grievance/model/contract/StatusInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..0c7d063fa38cc0d7a7a6f88eab8e04fae6d856bf --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/StatusInfo.java @@ -0,0 +1,30 @@ +package org.upsmf.grievance.model.contract; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * Status Information object will hold the run time status and the live response + * obtained from the server for the respective API Call. + */ +@AllArgsConstructor +@EqualsAndHashCode +@Getter +@NoArgsConstructor +@Setter +@ToString +public class StatusInfo { + + private Integer statusCode; + + private String statusMessage; + + private Long errorCode; + + private String errorMessage; + +} diff --git a/src/main/java/org/upsmf/grievance/model/contract/UserGetRequest.java b/src/main/java/org/upsmf/grievance/model/contract/UserGetRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..579f1184e66070e9e01c880366ac3cb4ec114d2e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/contract/UserGetRequest.java @@ -0,0 +1,23 @@ +package org.upsmf.grievance.model.contract; + +import java.util.List; + +/** + * + * @author Darshan Nagesh + * + */ + +public class UserGetRequest { + + private List<Long> userIdList; + + public List<Long> getUserIdList() { + return userIdList; + } + + public void setUserIdList(List<Long> userIdList) { + this.userIdList = userIdList; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/enums/AuthTypes.java b/src/main/java/org/upsmf/grievance/model/enums/AuthTypes.java new file mode 100644 index 0000000000000000000000000000000000000000..f4ff2653a185dd7f2e5c6aa53668b86247a1e73e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/enums/AuthTypes.java @@ -0,0 +1,34 @@ +package org.upsmf.grievance.model.enums; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public enum AuthTypes { + + GOOGLE("1"), CUSTOM("2"); + + private String value; + + AuthTypes(final String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return StringUtils.capitalize(name()); + } + + @JsonCreator + public static AuthTypes fromValue(final String passedValue) { + for (final AuthTypes obj : AuthTypes.values()) { + if (String.valueOf(obj.value).equalsIgnoreCase(passedValue)) { + return obj; + } + } + return null; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/enums/PriorityLevels.java b/src/main/java/org/upsmf/grievance/model/enums/PriorityLevels.java new file mode 100644 index 0000000000000000000000000000000000000000..2d269f3b62bed38666da222af1a5c7dbc8ea7694 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/enums/PriorityLevels.java @@ -0,0 +1,34 @@ +package org.upsmf.grievance.model.enums; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public enum PriorityLevels { + + LOW("LOW"), MOD("MODERATE"), HIGH("HIGH"); + + private String value; + + PriorityLevels(final String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return StringUtils.capitalize(name()); + } + + @JsonCreator + public static PriorityLevels fromValue(final String passedValue) { + for (final PriorityLevels obj : PriorityLevels.values()) { + if (String.valueOf(obj.value).equalsIgnoreCase(passedValue)) { + return obj; + } + } + return null; + } + +} diff --git a/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java b/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..d8e0ca009b01aacd581b1b4d65e0db2f3e353d6f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/model/mapper/SqlDataMapper.java @@ -0,0 +1,576 @@ +package org.upsmf.grievance.model.mapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.dto.HelpdeskWorkflowDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.TicketWorkflowDto; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.UserAuthentication; +import org.upsmf.grievance.util.SqlConstants; + +public class SqlDataMapper { + + public static final Logger LOGGER = LoggerFactory.getLogger(SqlDataMapper.class); + public static final String ERROR_LOG_FOREWORD = "Encountered an Exception while "; + + public User buildUserObjectFromResultSet(ResultSet rs) { + User user = new User(); + try { + user.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + user.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); + user.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + user.setOrgId(rs.getLong(SqlConstants.DbAttributes.ORGID)); + user.setIsActive(rs.getBoolean(SqlConstants.DbAttributes.ISACTIVE)); + user.setPassword(rs.getString(SqlConstants.DbAttributes.PSWRD)); + } catch (Exception e) { + + } + return user; + } + + public class UserMapper implements RowMapper<User> { + + @Override + public User mapRow(ResultSet rs, int rowNum) throws SQLException { + return buildUserObjectFromResultSet(rs); + } + + } + + public class UserRolesMapper implements RowMapper<User> { + private Map<Long, Role> roleMap = new HashMap<>(); + + public Map<Long, Role> getRoleMap() { + return roleMap; + } + + public void setRoleMap(Map<Long, Role> roleMap) { + this.roleMap = roleMap; + } + + @Override + public User mapRow(ResultSet rs, int rowNum) throws SQLException { + User user = buildUserObjectFromResultSet(rs); + if (!roleMap.containsKey(rs.getLong(SqlConstants.DbAttributes.ROLEID))) { + roleMap.put(rs.getLong(SqlConstants.DbAttributes.ROLEID), buildRoleObjectFromResultSet(rs)); + } + return user; + } + + } + + public class UserRolesActionsMapper implements RowMapper<User> { + private Map<Long, Role> roleMap = new HashMap<>(); + private Map<Long, Action> actionMap = new HashMap<>(); + + @Override + public User mapRow(ResultSet rs, int rowNum) throws SQLException { + User user = buildUserObjectFromResultSet(rs); + if (!getRoleMap().containsKey(rs.getLong(SqlConstants.DbAttributes.ROLEID))) { + getRoleMap().put(rs.getLong(SqlConstants.DbAttributes.ROLEID), buildRoleObjectFromResultSet(rs)); + } + if (!getActionMap().containsKey(rs.getLong(SqlConstants.DbAttributes.ACTIONID))) { + getActionMap().put(rs.getLong(SqlConstants.DbAttributes.ACTIONID), buildActionObjectFromResultSet(rs)); + } + return user; + } + + private Action buildActionObjectFromResultSet(ResultSet rs) { + Action action = new Action(); + try { + action.setId(rs.getLong(SqlConstants.DbAttributes.ACTIONID)); + action.setName(rs.getString(SqlConstants.DbAttributes.ACTIONNAME)); + action.setDisplayName(rs.getString(SqlConstants.DbAttributes.ACTIONDISPLAYNAME)); + action.setQueryParams(rs.getString(SqlConstants.DbAttributes.ACTIONQUERYPARAMS)); + action.setServiceCode(rs.getString(SqlConstants.DbAttributes.ACTIONSERVICECODE)); + action.setUrl(rs.getString(SqlConstants.DbAttributes.ACTIONURL)); + } catch (Exception e) { + + } + return action; + } + + public Map<Long, Role> getRoleMap() { + return roleMap; + } + + public void setRoleMap(Map<Long, Role> roleMap) { + this.roleMap = roleMap; + } + + public Map<Long, Action> getActionMap() { + return actionMap; + } + + public void setActionMap(Map<Long, Action> actionMap) { + this.actionMap = actionMap; + } + + } + + private Role buildRoleObjectFromResultSet(ResultSet rs) { + Role role = new Role(); + try { + role.setId(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + role.setName(rs.getString(SqlConstants.DbAttributes.ROLENAME)); + role.setOrgId(rs.getLong(SqlConstants.DbAttributes.ROLEORGID)); + } catch (Exception e) { + + } + return role; + } + + public class UserDetailsMapper implements RowMapper<User> { + @Override + public User mapRow(ResultSet rs, int rowNum) throws SQLException { + User user = new User(); + user.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + user.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); + user.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + user.setPhone(rs.getString(SqlConstants.DbAttributes.PHONE)); + user.setImagePath(rs.getString(SqlConstants.DbAttributes.IMAGE_PATH)); + user.setIsActive(rs.getBoolean(SqlConstants.DbAttributes.IS_ACTIVE)); + user.setCreatedDate(rs.getString(SqlConstants.DbAttributes.CREATED_DATE)); + user.setUpdatedDate(rs.getString(SqlConstants.DbAttributes.UPDATED_DATE)); + return user; + } + } + + public class UserAuthenticationMapper implements RowMapper<UserAuthentication> { + @Override + public UserAuthentication mapRow(ResultSet rs, int rowNum) throws SQLException { + UserAuthentication userAuthentication = new UserAuthentication(); + userAuthentication.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + userAuthentication.setUserId(rs.getLong(SqlConstants.DbAttributes.USERID)); + userAuthentication.setAuthToken(rs.getString(SqlConstants.DbAttributes.AUTH_TOKEN)); + return userAuthentication; + } + } + + public class UserRoleMapper implements RowMapper<Role> { + private Map<Long, Role> roleMap = new HashMap<>(); + + @Override + public Role mapRow(ResultSet rs, int rowNum) throws SQLException { + if (!getRoleMap().containsKey(rs.getLong(SqlConstants.DbAttributes.ROLEID))) { + Role role = new Role(); + role.setId(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + role.setName(rs.getString(SqlConstants.DbAttributes.ROLENAME)); + getRoleMap().put(rs.getLong(SqlConstants.DbAttributes.ROLEID), role); + } + return null; + } + + public Map<Long, Role> getRoleMap() { + return roleMap; + } + + public void setRoleMap(Map<Long, Role> roleMap) { + this.roleMap = roleMap; + } + } + + public class RoleActionMapper implements RowMapper<Long> { + private Map<Long, List<String>> roleActionsMap = new HashMap<>(); + + @Override + public Long mapRow(ResultSet rs, int rowNum) throws SQLException { + if (getRoleActionsMap().containsKey(rs.getLong(SqlConstants.DbAttributes.ROLEID))) { + List<String> actionsList = getRoleActionsMap().get(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + actionsList.add(rs.getString(SqlConstants.DbAttributes.ACTIONURL)); + } else { + List<String> actionsList = new ArrayList<>(); + actionsList.add(rs.getString(SqlConstants.DbAttributes.ACTIONURL)); + getRoleActionsMap().put(rs.getLong(SqlConstants.DbAttributes.ROLEID), actionsList); + } + return null; + } + + public Map<Long, List<String>> getRoleActionsMap() { + return roleActionsMap; + } + + public void setRoleActionsMap(Map<Long, List<String>> roleActionsMap) { + this.roleActionsMap = roleActionsMap; + } + } + + public class UserOrgMapper implements RowMapper<OrgUserRoleDto> { + @Override + public OrgUserRoleDto mapRow(ResultSet rs, int rowNum) throws SQLException { + OrgUserRoleDto dto = new OrgUserRoleDto(); + dto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + dto.setOrgId(rs.getLong(SqlConstants.DbAttributes.ORGID)); + dto.setUserId(rs.getLong(SqlConstants.DbAttributes.USERID)); + return dto; + } + } + + public class RolesUserMapper implements RowMapper<OrgUserRoleDto> { + private Map<Long, OrgUserRoleDto> userMap = new HashMap<>(); + Map<Long, List<Long>> userRolesMap = new HashMap<>(); + + @Override + public OrgUserRoleDto mapRow(ResultSet rs, int rowNum) throws SQLException { + if (userRolesMap.containsKey(rs.getLong(SqlConstants.DbAttributes.USERID))) { + List<Long> roleIds = userRolesMap.get(rs.getLong(SqlConstants.DbAttributes.USERID)); + roleIds.add(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + } else { + OrgUserRoleDto dto = new OrgUserRoleDto(); + dto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + dto.setRoleId(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + dto.setUserId(rs.getLong(SqlConstants.DbAttributes.USERID)); + List<Long> roleIds = new ArrayList<>(); + roleIds.add(rs.getLong(SqlConstants.DbAttributes.ROLEID)); + userRolesMap.put(rs.getLong(SqlConstants.DbAttributes.USERID), roleIds); + dto.setRoleIds(userRolesMap.get(rs.getLong(SqlConstants.DbAttributes.USERID))); + getUserMap().put(rs.getLong(SqlConstants.DbAttributes.USERID), dto); + } + return null; + } + + public Map<Long, OrgUserRoleDto> getUserMap() { + return userMap; + } + + public void setUserMap(Map<Long, OrgUserRoleDto> userMap) { + this.userMap = userMap; + } + } + + public class HelpDeskAppMapper implements RowMapper<HelpDeskApp> { + @Override + public HelpDeskApp mapRow(ResultSet rs, int rowNum) throws SQLException { + HelpDeskApp app = new HelpDeskApp(); + app.setAppId(rs.getLong(SqlConstants.DbAttributes.APPID)); + app.setHelpDeskId(rs.getLong(SqlConstants.DbAttributes.HELPDESKID)); + return app; + } + } + + public class HelpdeskUserMapper implements RowMapper<User> { + @Override + public User mapRow(ResultSet rs, int rowNum) throws SQLException { + User user = new User(); + user.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + user.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + user.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); + user.setImagePath(rs.getString(SqlConstants.DbAttributes.IMAGE_PATH)); + return user; + } + } + + public class UserHelpdeskMapper implements RowMapper<Helpdesk> { + @Override + public Helpdesk mapRow(ResultSet rs, int rowNum) throws SQLException { + Helpdesk helpdesk = new Helpdesk(); + helpdesk.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + helpdesk.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + helpdesk.setIsActive(rs.getBoolean(SqlConstants.DbAttributes.ISACTIVE)); + helpdesk.setColor(rs.getString(SqlConstants.DbAttributes.COLOR)); + return helpdesk; + } + } + + public class ChecklistItemMapper implements RowMapper<ChecklistItem> { + @Override + public ChecklistItem mapRow(ResultSet rs, int rowNum) throws SQLException { + ChecklistItem item = new ChecklistItem(); + item.setId(rs.getLong(SqlConstants.DbAttributes.CHECKLISTID)); + item.setItem(rs.getString(SqlConstants.DbAttributes.ITEMNAME)); + return item; + } + } + + public class TicketsChecklistItemMapper implements RowMapper<ChecklistItem> { + @Override + public ChecklistItem mapRow(ResultSet rs, int rowNum) throws SQLException { + ChecklistItem item = new ChecklistItem(); + item.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + item.setItem(rs.getString(SqlConstants.DbAttributes.NAME)); + item.setChecked(rs.getBoolean(SqlConstants.DbAttributes.CHECKED)); + return item; + } + } + + public class TicketWorkFlowMapper implements RowMapper<TicketWorkflowDto> { + @Override + public TicketWorkflowDto mapRow(ResultSet rs, int rowNum) throws SQLException { + TicketWorkflowDto ticketWorkflowDto = new TicketWorkflowDto(); + ticketWorkflowDto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + ticketWorkflowDto.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + ticketWorkflowDto.setStatus(rs.getBoolean(SqlConstants.DbAttributes.STATUS)); + ticketWorkflowDto.setTime(rs.getString(SqlConstants.DbAttributes.TIME)); + ticketWorkflowDto.setWorkFlowId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWID)); + return ticketWorkflowDto; + } + } + + public class TicketWorkFlowMapperV2 implements RowMapper<TicketWorkflowDto> { + private Map<Long, List<TicketWorkflowDto>> ticketWorkflowMap = new HashMap<>(); + + @Override + public TicketWorkflowDto mapRow(ResultSet rs, int rowNum) throws SQLException { + if (getTicketWorkflowMap().containsKey(rs.getLong(SqlConstants.DbAttributes.TICKET_ID))) { + TicketWorkflowDto ticketWorkflowDto = new TicketWorkflowDto(); + ticketWorkflowDto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + ticketWorkflowDto.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + ticketWorkflowDto.setStatus(rs.getBoolean(SqlConstants.DbAttributes.STATUS)); + ticketWorkflowDto.setTime(rs.getString(SqlConstants.DbAttributes.TIME)); + ticketWorkflowDto.setWorkFlowId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWID)); + List<TicketWorkflowDto> ticketWorkflowList = getTicketWorkflowMap() + .get(rs.getLong(SqlConstants.DbAttributes.TICKET_ID)); + ticketWorkflowList.add(ticketWorkflowDto); + } else { + TicketWorkflowDto ticketWorkflowDto = new TicketWorkflowDto(); + ticketWorkflowDto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + ticketWorkflowDto.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + ticketWorkflowDto.setStatus(rs.getBoolean(SqlConstants.DbAttributes.STATUS)); + ticketWorkflowDto.setTime(rs.getString(SqlConstants.DbAttributes.TIME)); + ticketWorkflowDto.setWorkFlowId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWID)); + List<TicketWorkflowDto> ticketWorkflowList = new ArrayList<>(); + ticketWorkflowList.add(ticketWorkflowDto); + getTicketWorkflowMap().put(rs.getLong(SqlConstants.DbAttributes.TICKET_ID), ticketWorkflowList); + } + return null; + } + + public Map<Long, List<TicketWorkflowDto>> getTicketWorkflowMap() { + return ticketWorkflowMap; + } + + public void setTicketWorkflowMap(Map<Long, List<TicketWorkflowDto>> ticketWorkflowMap) { + this.ticketWorkflowMap = ticketWorkflowMap; + } + } + + public class HelpdeskRowRecordMapper implements RowMapper<HelpdeskDto> { + private Map<Long, HelpdeskDto> helpdeskMap = new HashMap<>(); + private Map<Long, List<Long>> helpdeskTypeMapping = new HashMap<>(); + private Map<Long, HelpdeskTypeDto> helpdeskTypeMap = new HashMap<>(); + private Map<Long, List<Long>> typeWorkflowMapping = new HashMap<>(); + private Map<Long, HelpdeskWorkflowDto> helpdeskWorkflowMap = new HashMap<>(); + + @Override + public HelpdeskDto mapRow(ResultSet rs, int rowNum) throws SQLException { + if (getHelpdeskMap().containsKey(rs.getLong(SqlConstants.DbAttributes.ID))) { + if (getHelpdeskTypeMap().containsKey(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID))) { + if (!getHelpdeskWorkflowMap().containsKey(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID))) { + HelpdeskWorkflowDto workflowDto = new HelpdeskWorkflowDto(); + workflowDto.setId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID)); + workflowDto.setName(rs.getString(SqlConstants.DbAttributes.WORKFLOWSTAGE)); + workflowDto.setTypeId(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + getHelpdeskWorkflowMap().put(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID), + workflowDto); + + List<Long> workflowStageIds = getTypeWorkflowMapping() + .get(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + workflowStageIds.add(workflowDto.getId()); + getTypeWorkflowMapping().put(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID), + workflowStageIds); + } + } else { + HelpdeskWorkflowDto workflowDto = new HelpdeskWorkflowDto(); + workflowDto.setId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID)); + workflowDto.setName(rs.getString(SqlConstants.DbAttributes.WORKFLOWSTAGE)); + workflowDto.setTypeId(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + getHelpdeskWorkflowMap().put(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID), workflowDto); + + HelpdeskTypeDto typeDto = new HelpdeskTypeDto(); + typeDto.setId(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + typeDto.setName(rs.getString(SqlConstants.DbAttributes.HELPDESKTYPE)); + typeDto.setHelpdeskId(rs.getLong(SqlConstants.DbAttributes.ID)); + getHelpdeskTypeMap().put(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID), typeDto); + + List<Long> workflowStageIds = new ArrayList<>(); + workflowStageIds.add(workflowDto.getId()); + getTypeWorkflowMapping().put(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID), + workflowStageIds); + + List<Long> typeIds = getHelpdeskTypeMapping().get(rs.getLong(SqlConstants.DbAttributes.ID)); + typeIds.add(typeDto.getId()); + getHelpdeskTypeMapping().put(rs.getLong(SqlConstants.DbAttributes.ID), typeIds); + + } + } else { + HelpdeskWorkflowDto workflowDto = new HelpdeskWorkflowDto(); + workflowDto.setId(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID)); + workflowDto.setName(rs.getString(SqlConstants.DbAttributes.WORKFLOWSTAGE)); + workflowDto.setTypeId(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + getHelpdeskWorkflowMap().put(rs.getLong(SqlConstants.DbAttributes.WORKFLOWSTAGEID), workflowDto); + + HelpdeskTypeDto typeDto = new HelpdeskTypeDto(); + typeDto.setId(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID)); + typeDto.setName(rs.getString(SqlConstants.DbAttributes.HELPDESKTYPE)); + typeDto.setHelpdeskId(rs.getLong(SqlConstants.DbAttributes.ID)); + getHelpdeskTypeMap().put(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID), typeDto); + + HelpdeskDto dto = new HelpdeskDto(); + dto.setId(rs.getLong(SqlConstants.DbAttributes.ID)); + dto.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + dto.setIsActive(rs.getBoolean(SqlConstants.DbAttributes.ISACTIVE)); + dto.setOrgId(rs.getLong(SqlConstants.DbAttributes.ORGID)); + dto.setAllowAllUsers(rs.getBoolean(SqlConstants.DbAttributes.ALLOW_ALL_USERS)); + getHelpdeskMap().put(rs.getLong(SqlConstants.DbAttributes.ID), dto); + dto.setColor(rs.getString(SqlConstants.DbAttributes.COLOR)); + dto.setDescription(rs.getString(SqlConstants.DbAttributes.DESCRIPTION)); + + List<Long> workflowStageIds = new ArrayList<>(); + workflowStageIds.add(workflowDto.getId()); + getTypeWorkflowMapping().put(rs.getLong(SqlConstants.DbAttributes.HELPDESKTYPEID), workflowStageIds); + + List<Long> typeIds = new ArrayList<>(); + typeIds.add(typeDto.getId()); + getHelpdeskTypeMapping().put(rs.getLong(SqlConstants.DbAttributes.ID), typeIds); + } + return null; + } + + public Map<Long, HelpdeskWorkflowDto> getHelpdeskWorkflowMap() { + return helpdeskWorkflowMap; + } + + public void setHelpdeskWorkflowMap(Map<Long, HelpdeskWorkflowDto> helpdeskWorkflowMap) { + this.helpdeskWorkflowMap = helpdeskWorkflowMap; + } + + public Map<Long, List<Long>> getHelpdeskTypeMapping() { + return helpdeskTypeMapping; + } + + public void setHelpdeskTypeMapping(Map<Long, List<Long>> helpdeskTypeMapping) { + this.helpdeskTypeMapping = helpdeskTypeMapping; + } + + public Map<Long, HelpdeskTypeDto> getHelpdeskTypeMap() { + return helpdeskTypeMap; + } + + public void setHelpdeskTypeMap(Map<Long, HelpdeskTypeDto> helpdeskTypeMap) { + this.helpdeskTypeMap = helpdeskTypeMap; + } + + public Map<Long, List<Long>> getTypeWorkflowMapping() { + return typeWorkflowMapping; + } + + public void setTypeWorkflowMapping(Map<Long, List<Long>> typeWorkflowMapping) { + this.typeWorkflowMapping = typeWorkflowMapping; + } + + public Map<Long, HelpdeskDto> getHelpdeskMap() { + return helpdeskMap; + } + + public void setHelpdeskMap(Map<Long, HelpdeskDto> helpdeskMap) { + this.helpdeskMap = helpdeskMap; + } + } + + public class TicketDetailsMapper implements RowMapper<Ticket> { + Map<Long, Ticket> ticketMap = new HashMap<>(); + + @Override + public Ticket mapRow(ResultSet rs, int rowNum) throws SQLException { + if (ticketMap.containsKey(rs.getLong(SqlConstants.DbAttributes.TICKETID))) { + Ticket ticket = ticketMap.get(rs.getLong(SqlConstants.DbAttributes.TICKETID)); + ticket.getCc().add(rs.getLong(SqlConstants.DbAttributes.TKTCCUSERID)); + List<ChecklistItem> checklistList = ticket.getChecklist(); + ChecklistItem checklistItem = new ChecklistItem(); + checklistItem.setId(rs.getLong(SqlConstants.DbAttributes.CHECKLISTID)); + checklistItem.setItem(rs.getString(SqlConstants.DbAttributes.CHECKLISTNAME)); + checklistItem.setChecked(rs.getBoolean(SqlConstants.DbAttributes.TCLCHECKED)); + checklistList.add(checklistItem); + } else { + Ticket ticket = new Ticket(); + ticket.setId(rs.getLong(SqlConstants.DbAttributes.TICKETID)); + ticket.setAppId(rs.getLong(SqlConstants.DbAttributes.APPID)); + ticket.setPinnedTicket(rs.getBoolean(SqlConstants.DbAttributes.PINNEDTICKET)); + ticket.setUpdatedTime(rs.getString(SqlConstants.DbAttributes.UPDATEDTIME)); + ticket.setUpdatedTimeTS(rs.getDate(SqlConstants.DbAttributes.UPDATEDTIME).getTime()); + ticket.setCreatedTime(rs.getString(SqlConstants.DbAttributes.CREATEDTIME)); + ticket.setCreatedTimeTS(rs.getDate(SqlConstants.DbAttributes.CREATEDTIME).getTime()); + ticket.setRate(rs.getInt(SqlConstants.DbAttributes.RATING)); + ticket.setMaxRating(rs.getInt(SqlConstants.DbAttributes.MAXRATING)); + ticket.setPriority(rs.getString(SqlConstants.DbAttributes.PRIORITY)); + ticket.setRequestedBy(rs.getLong(SqlConstants.DbAttributes.REQUESTEDBY)); + ticket.setDescription(rs.getString(SqlConstants.DbAttributes.DESCRIPTION)); + ticket.setNotes(rs.getString(SqlConstants.DbAttributes.NOTES)); + ticket.setActive(rs.getBoolean(SqlConstants.DbAttributes.ACTIVE)); + ticket.setSourceId(rs.getLong(SqlConstants.DbAttributes.SOURCEID)); + ticket.setHelpdeskId(rs.getLong(SqlConstants.DbAttributes.HELPDESKID)); + List<Long> ccList = new ArrayList<>(); + ccList.add(rs.getLong(SqlConstants.DbAttributes.TKTCCUSERID)); + ticket.setCc(ccList); + List<ChecklistItem> checklistList = new ArrayList<>(); + ChecklistItem checklistItem = new ChecklistItem(); + checklistItem.setId(rs.getLong(SqlConstants.DbAttributes.CHECKLISTID)); + checklistItem.setItem(rs.getString(SqlConstants.DbAttributes.CHECKLISTNAME)); + checklistItem.setChecked(rs.getBoolean(SqlConstants.DbAttributes.TCLCHECKED)); + checklistList.add(checklistItem); + ticket.setChecklist(checklistList); + ticketMap.put(rs.getLong(SqlConstants.DbAttributes.TICKETID), ticket); + } + return null; + } + } + + public class OrgMapper implements RowMapper<Organization> { + private Organization org = new Organization(); + List<User> adminList = new ArrayList<>(); + + @Override + public Organization mapRow(ResultSet rs, int rowNum) throws SQLException { + User orgAdmin = new User(); + if (rowNum == 0) { + getOrg().setId(rs.getLong(SqlConstants.DbAttributes.ID)); + getOrg().setOrgName(rs.getString(SqlConstants.DbAttributes.ORGNAME)); + getOrg().setUrl(rs.getString(SqlConstants.DbAttributes.URL)); + getOrg().setLogo(rs.getString(SqlConstants.DbAttributes.LOGO)); + getOrg().setEmailDomain(rs.getString(SqlConstants.DbAttributes.DOMAIN)); + getOrg().setOrgColor(rs.getString(SqlConstants.DbAttributes.COLOR)); + getOrg().setCreatedBy(rs.getLong(SqlConstants.DbAttributes.CREATEDBY)); + getOrg().setCreatedDate(rs.getString(SqlConstants.DbAttributes.CREATEDDATE)); + getOrg().setIsActive(rs.getBoolean(SqlConstants.DbAttributes.ISACTIVE)); + getOrg().setOrgDescription(rs.getString(SqlConstants.DbAttributes.DESCRIPTION)); + } + + orgAdmin.setId(rs.getLong(SqlConstants.DbAttributes.USERID)); + orgAdmin.setName(rs.getString(SqlConstants.DbAttributes.NAME)); + orgAdmin.setUsername(rs.getString(SqlConstants.DbAttributes.USERNAME)); + orgAdmin.setPhone(rs.getString(SqlConstants.DbAttributes.PHONE)); + adminList.add(orgAdmin); + getOrg().setAdminDetails(adminList); + return null; + + } + + public Organization getOrg() { + return org; + } + + public void setOrg(Organization org) { + this.org = org; + } + } + +} diff --git a/src/main/java/org/upsmf/grievance/repository/ElasticSearchRepository.java b/src/main/java/org/upsmf/grievance/repository/ElasticSearchRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..77d86fef43d78ba61e09d316205f5404cbbc196f --- /dev/null +++ b/src/main/java/org/upsmf/grievance/repository/ElasticSearchRepository.java @@ -0,0 +1,95 @@ +package org.upsmf.grievance.repository; + +import java.io.IOException; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpHost; +import org.elasticsearch.action.search.MultiSearchRequest; +import org.elasticsearch.action.search.MultiSearchResponse; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.RestTemplate; + +import org.upsmf.grievance.model.TemplateVersion; + +/** + * This Repository Class is used to perform the transactions of storing the data + * into the Elastic Search Repository + * + * @author Darshan Nagesh + * + */ +@Service +public class ElasticSearchRepository { + + private static final String ERROR = "Error : %s"; + String daoImplMarker = "AuroraESRepoMarker"; + Marker marker = MarkerFactory.getMarker(daoImplMarker); + + public static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchRepository.class); + + private final RestTemplate restTemplate; + private RestHighLevelClient client; + private String elasticHost; + private int elasticPort; + private static final String REST_SCHEME = "http"; + + public ElasticSearchRepository(RestTemplate restTemplate, + @Value("${services.esindexer.host.name}") String elasticHost, + @Value("${services.esindexer.host.port}") int elasticPort) { + this.elasticHost = elasticHost; + this.elasticPort = elasticPort; + this.restTemplate = restTemplate; + this.client = getClientForElastic(); + } + + private RestHighLevelClient getClientForElastic() { + return new RestHighLevelClient(RestClient.builder(new HttpHost(elasticHost, elasticPort, REST_SCHEME))); + } + + public Boolean saveTemplate(TemplateVersion templateVersion, String url, HttpHeaders headers) { + ResponseEntity<Map> map = null; + try { + map = restTemplate.exchange(url, HttpMethod.PUT, new HttpEntity<>(templateVersion, headers), Map.class); + } catch (final HttpClientErrorException httpClientErrorException) { + LOGGER.error(String.format(ERROR, httpClientErrorException)); + } catch (HttpServerErrorException httpServerErrorException) { + LOGGER.error(String.format(ERROR, httpServerErrorException)); + } catch (Exception e) { + LOGGER.error(String.format(ERROR, e.getMessage())); + } + return (map != null && map.getStatusCode() != null + && ((map.getStatusCode() == HttpStatus.OK) || (map.getStatusCode() == HttpStatus.CREATED))); + } + + public MultiSearchResponse executeMultiSearchRequest(SearchRequest searchRequest) { + MultiSearchRequest multiRequest = new MultiSearchRequest(); + MultiSearchResponse response = null; + if (!StringUtils.isBlank(marker.toString()) && !StringUtils.isBlank(searchRequest.source().toString())) { + LOGGER.info("ES Query is : {}", searchRequest.source()); + } + multiRequest.add(searchRequest); + try { + response = client.multiSearch(multiRequest); + } catch (IOException e) { + LOGGER.error(String.format(marker.toString(), " Encountered an error while connecting : %s", e)); + LOGGER.error(String.format(marker.toString(), " Error Message to report : %s", e.getMessage())); + } + return response; + } +} diff --git a/src/main/java/org/upsmf/grievance/service/ApplicationService.java b/src/main/java/org/upsmf/grievance/service/ApplicationService.java new file mode 100644 index 0000000000000000000000000000000000000000..318305310209177e28c651328032b0163493298e --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/ApplicationService.java @@ -0,0 +1,53 @@ +package org.upsmf.grievance.service; + +import java.util.List; + +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; + +/** + * @author Darshan Nagesh + * + */ +public interface ApplicationService { + + public App createApp(App app, User user); + + /** + * This method will return List of applications + * + * @param id + * Long + * @param keyword + * String + * @param user + * User + * @return List<App> + */ + public List<App> getApp(Long id, String keyword, User user); + + /** + * This method will map an application to a helpdesk + * + * @param statusIdMap + * StatusIdMap + * @return boolean + */ + public boolean mapAppsToHelpdesk(StatusIdMap statusIdMap); + + /** + * This method will invoke the DAO method to fetch the master data of Service + * Request types available in the application + * + * @return List<ServiceRequest> + * + */ + public List<ServiceRequest> getServiceRequests(); + + public List<App> getAppIdAndAppObject(); + + public Object getApp(Long orgId); + +} diff --git a/src/main/java/org/upsmf/grievance/service/HelpdeskService.java b/src/main/java/org/upsmf/grievance/service/HelpdeskService.java new file mode 100644 index 0000000000000000000000000000000000000000..b293c8f96c4b359dbdc2a5dc665dec9d40a815e2 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/HelpdeskService.java @@ -0,0 +1,45 @@ +package org.upsmf.grievance.service; + +import java.util.List; + +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.User; + +public interface HelpdeskService { + + /** + * This method will add or update helpdesk of an organization + * + * @param helpdesk + * Helpdesk + * @return boolean + */ + boolean createUpdateHelpdesk(HelpdeskDto helpdeskDto, User user); + + /** + * This method gives all the active helpdesk of an organization + * + * @param orgId + * Long + * @return List<Helpdesk> + */ + List<HelpdeskDto> getHelpdesk(Long orgId); + + List<HelpdeskDto> getHelpdeskById(Long orgId, Long id); + + boolean configureHelpdesk(HelpdeskDto helpdeskDto, User user); + + List<Long> getHelpdeskAdmins(Long id); + + boolean addUpdateHelpdeskAdmins(Helpdesk helpdesk, User user); + + List<HelpDeskApp> getAppIdAndHelpDeskId(); + + public List<Helpdesk> getHelpdeskObjectFromHelpdeskId(); + + List<User> getUsersForHelpeskId(Long id); + + void getHelpdeskAdminUser(List<HelpdeskDto> helpdeskList); +} diff --git a/src/main/java/org/upsmf/grievance/service/RoleActionService.java b/src/main/java/org/upsmf/grievance/service/RoleActionService.java new file mode 100644 index 0000000000000000000000000000000000000000..b5328207630970d58234492419ae278e71fe9292 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/RoleActionService.java @@ -0,0 +1,61 @@ +package org.upsmf.grievance.service; + +import java.util.List; +import java.util.Map; + +import org.upsmf.grievance.model.Role; + +/** + * This interface handles the service layer of business operation logic + * implementation for all the Role and its Action related transactions + * + * @author Darshan Nagesh + * + */ +public interface RoleActionService { + + /** + * This method receives the request with details related to a new role and + * passes on to the DAO layer to save in DB + * + * @param role + * @return + */ + Role saveRole(Role role); + + /** + * This method receives the request with details related to a new role and + * passes on to the DAO layer to update the role information in DB + * + * @param role + * @return + */ + Role updateRole(Role role); + + /** + * This method fetches all the Roles available in the system + * + * @param fetchData + * @return + */ + List<Role> getAllRoles(Long orgId); + + /** + * This method receives the ID from Controller to pass on the same to DAO to + * fetch the Role Object from Database This returns the Role Object for the + * respective Role ID + * + * @param role + * @return + */ + String findById(Role role); + + List<Role> getAllOrgRoles(); + + void initializeActions(); + + void intializeRolesAndActions(); + + Map<Long, List<String>> getAllActionsForRoles(List<Long> roleIds); + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/service/SuperAdminService.java b/src/main/java/org/upsmf/grievance/service/SuperAdminService.java new file mode 100644 index 0000000000000000000000000000000000000000..8b8d4cb3d327d0643611b998d9a12f785ac85948 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/SuperAdminService.java @@ -0,0 +1,34 @@ +package org.upsmf.grievance.service; + +import java.util.List; + +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.StatusIdMap; + +public interface SuperAdminService { + + List<Organization> getAllOrganization(); + + Organization addOrganization(Organization organization); + + boolean updateOrganizationById(Organization organization); + + Organization getOrganizationById(Long id); + + boolean deleteOrganization(Organization organization); + + boolean addAdmin(long userId); + + boolean removeAdmin(long userId); + + /** + * This method will map an application to an organization + * + * @param statusIdMap + * @return + */ + boolean mapAppsToOrg(StatusIdMap statusIdMap); + + List<Organization> getOrganizationByUserId(Long userId); + +} diff --git a/src/main/java/org/upsmf/grievance/service/TagService.java b/src/main/java/org/upsmf/grievance/service/TagService.java new file mode 100644 index 0000000000000000000000000000000000000000..13a0b9f2a942cb006e91445c33b32985b47bb997 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/TagService.java @@ -0,0 +1,19 @@ +package org.upsmf.grievance.service; + +import java.util.List; + +import org.upsmf.grievance.dto.TicketTagDto; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.TicketsTagsList; + +public interface TagService { + + public boolean saveTags(TicketTagDto ticketTagDto, Long id); + + public TicketsTagsList getAllOrgTags(Long orgId); + + public List<Tags> getAllTicketTags(Long id); + + public TicketsTagsList getHelpdeskTags(Long id, Long userId); + +} diff --git a/src/main/java/org/upsmf/grievance/service/TicketService.java b/src/main/java/org/upsmf/grievance/service/TicketService.java new file mode 100644 index 0000000000000000000000000000000000000000..4cf25d731ca97d80a91d4d63d8d1a59fd3234326 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/TicketService.java @@ -0,0 +1,82 @@ +package org.upsmf.grievance.service; + +import java.util.List; +import java.util.Map; + +import org.springframework.web.multipart.MultipartFile; + +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Analytics; +import org.upsmf.grievance.model.TemplateVersion; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketCount; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; + +/** + * This interface contains all the ticket related service + * + * @author Juhi Agarwal + * + */ +public interface TicketService { + + Ticket addTicket(Ticket ticket); + + Long getTemplatesVersion(); + + TemplateVersion getTemplates(); + + boolean configureTemplates(TemplateVersion templateVersion); + + boolean updateTicketBasic(MultipartFile file, Ticket ticket); + + /** + * Get Method which receives the User Object and the Ticket ID from the + * Controller and calls the respective DAO Method to get the Ticket Response for + * the specific Ticket which is being requested for + * + * @param user + * @param id + * @return + */ + Ticket getTicketsById(User user, Long id); + + List<Ticket> getAllTicketsByAppId(Long appId); + + Boolean updateNotesToTicket(Ticket ticket); + + Boolean addUpdateUpdatesToTicket(Updates update); + + List<Updates> getUpdatesForTicket(Long id); + + boolean updateTicketType(TicketTypeDto ticketTypeDto, Long userId); + + boolean updateTicketStatus(Ticket ticket); + + boolean updateTicketChecklist(Ticket ticket); + + boolean sendRepliesToReviews(Updates updates); + + List<ActivityLog> getActivityLogsPerTicket(Long id); + + List<Ticket> getFeedBacksFromAuroraSdk(); + + List<Ticket> keepOnlyCreatedAndCopiedToTickets(Long userId, List<Ticket> ticketList); + + Map<String, Long> getTicketsCountPerMonthPerUser(Analytics analytics); + + List<ActivityLog> getActivityLogsPerUser(Long id); + + List<TicketElastic> getTicketDetailsByHelpdeskId(Ticket ticket); + + List<Ticket> getAllTicketsByUserId(Long id); + + boolean attachmentUpload(MultipartFile file, Ticket ticket); + + TicketCount getNoOfTickets(Long userId); + + boolean pinTicket(Ticket ticket); +} diff --git a/src/main/java/org/upsmf/grievance/service/UserService.java b/src/main/java/org/upsmf/grievance/service/UserService.java new file mode 100644 index 0000000000000000000000000000000000000000..1791c07cffaccc6c6d42e488c4ff3cf05a92d258 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/UserService.java @@ -0,0 +1,147 @@ +package org.upsmf.grievance.service; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.LoginDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.User; + + +public interface UserService { + + /** + * This method receives the List of Role IDs from the controller and passes the + * same to DAO to fetch the List of Actions allowed and configured for the Role + * ID + * + * @param roleID + * @return + */ + public List<Action> findAllActionsByRoleID(List<Integer> roleID); + + /** + * This method receives the existing User object to update the details in the + * Database for the respective User + * + * @param file + * + * @param user + * @return + */ + User update(MultipartFile file, User user); + + /** + * This method supports pagination and fetches the User Profiles for the + * respective search criteria Search can happen based on Page Number, Number of + * Records, Active status of the user Keyword to search the user and also based + * on the Roles Assigned to the User + * + * @param pageNumber + * @param numberOfRecords + * @param orgId + * @param roles + * @return + */ + List<User> findAll(Long orgId); + + /** + * This method receives the String Username to fetch the respective User record + * from the Database + * + * @param username + * @return + */ + User findOne(String username, Boolean withRoles, Boolean withActions); + + /** + * This method receives the Long ID to fetch the respective User Profile from + * the database + * + * @param id + * @return + */ + User findById(Long id); + + /** + * This method receives the User ID and find the corresponding roles for the + * User ID and lists out the Roles as a response + * + * @param userId + * @return + */ + public List<Role> findAllRolesByUser(Long userId); + + /** + * This method receives the User ID and then fetches the Role ID for the same + * With the help of Role ID, it fetches the corresponding Actions which are + * allowed and mapped. As a result, this responds Action object + * + * @param userId + * @return + */ + + /** + * This method receives the User Role Object. For a User ID and each Role ID in + * the list, this method creates a mapping so that User Role Mapping is added + * + * @param userRole + * @return + */ + Boolean mapUserToRole(User user); + + Long checkUserNameExists(String username); + + String uploadFile(MultipartFile file, long userId); + + Long getNumberOfUsers(Long role, Boolean active); + + Long getNumberOfRoles(); + + Boolean invalidateToken(String authToken); + + Boolean findUserByToken(String authToken); + + Long fetchAuthTokenReference(String authToken); + + Boolean checkUserTokenExists(Long userId, String deviceToken); + + User updateUserImage(User profile); + + public LoginDto login(UserDto userDto); + + public boolean forgotPassword(UserDto userDto); + + public boolean changePassword(ChangePasswordDto changePasswordDto); + + User save(MultipartFile file, long authUserId, User user); + + public List<OrgUserRoleDto> getAllOrgUsers(); + + public List<OrgUserRoleDto> getAllUserRoles(); + + List<HelpDeskApp> getAppIdAndHelpDeskId(); + + public List<User> getUserIdAndUserName(); + + String getFile(Long userId) throws IOException; + + public Map<String, Object> getUserInfoObjects(String userId); + + Long saveAnonymousUser(User user); + + public void getReviews() throws IOException; + + public Access getReviewConfig(Long id); + +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/ApplicationServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/ApplicationServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..21d39cab3ed5ab3b5168d7086910c75ef9e4c817 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/ApplicationServiceImpl.java @@ -0,0 +1,69 @@ +package org.upsmf.grievance.service.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.upsmf.grievance.dao.ApplicationDao; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.ApplicationService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.Sql; + +@Service(value = Constants.APP_SERVICE) +public class ApplicationServiceImpl implements ApplicationService { + + @Autowired + private ApplicationDao applicationDao; + + @Override + public App createApp(App app, User user) { + if (app.getId() != null) { + return applicationDao.updateApp(app, user); + } + return applicationDao.createApp(app, user); + } + + @Override + public List<App> getApp(Long id, String keyword, User user) { + List<App> app = new ArrayList<>(); + if (id != null) { + return applicationDao.getApp(id); + } else if (!ProjectUtil.isObjectNull(user.getRoles()) && user.getOrgId() == null) { + if (user.getRoles().get(0).getName().equalsIgnoreCase(Sql.Common.SUPER_ADMIN)) { + return applicationDao.getAllApps(); + } + + } else if (user.getOrgId() != null) { + return applicationDao.getAppsByOrgId(user.getOrgId()); + } + return app; + } + + @Override + public boolean mapAppsToHelpdesk(StatusIdMap statusIdMap) { + return applicationDao.mapAppsToHelpdesk(statusIdMap); + } + + @Override + public List<ServiceRequest> getServiceRequests() { + return applicationDao.getServiceRequests(); + } + + @Override + public List<App> getAppIdAndAppObject() { + return applicationDao.getAppIdAndAppObject(); + } + + @Override + public List<App> getApp(Long orgId) { + return applicationDao.getAppsByOrgId(orgId); + } + +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/HelpdeskServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/HelpdeskServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..9cbcca53615e03734c54abfb8405bc7ed3d5ded6 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/HelpdeskServiceImpl.java @@ -0,0 +1,213 @@ +package org.upsmf.grievance.service.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.dto.HelpdeskWorkflowDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; +import org.upsmf.grievance.service.HelpdeskService; +import org.upsmf.grievance.util.S3FileManager; + +@Service +public class HelpdeskServiceImpl implements HelpdeskService { + + private static final String ENCOUNTERED_AN_EXCEPTION = "Encountered an Exception : %s"; + + private static final String USERPROFILE = "userprofile"; + + public static final Logger LOGGER = LoggerFactory.getLogger(HelpdeskServiceImpl.class); + + @Autowired + private HelpdeskDao helpdeskDao; + + @Autowired + private SuperAdminDao superAdminDao; + + @Override + public boolean createUpdateHelpdesk(HelpdeskDto helpdeskDto, User user) { + Helpdesk helpdesk = new Helpdesk(helpdeskDto); + helpdesk.setOrgId(helpdesk.getOrgId()); + helpdesk.setCreatedBy(user.getId()); + helpdesk.setUpdatedBy(user.getId()); + Boolean status = helpdeskDao.createUpdateHelpdesk(helpdesk); + if (status && helpdeskDto.getId() == null) { + helpdeskDto.setId(helpdesk.getId()); + configureHelpdesk(helpdeskDto, user); + } + return status; + } + + @Override + public List<HelpdeskDto> getHelpdesk(Long orgId) { + return helpdeskDao.getAllHelpdesks(orgId); + } + + @Override + public List<HelpdeskDto> getHelpdeskById(Long orgId, Long id) { + List<HelpdeskDto> helpdeskList = new ArrayList<>(); + try { + HelpdeskRowRecordMapper mapper = helpdeskDao.getHelpdeskForId(orgId, id); + createHelpdeskListFromRowRecords(mapper, helpdeskList); + getAppsForHelpdesk(helpdeskList); + helpdeskList = helpdeskDao.getHelpdeskAdminUser(helpdeskList); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return helpdeskList; + } + + public void getAppsForHelpdesk(List<HelpdeskDto> helpdeskList) { + MasterDataManager.getHelpdeskIdFromAppId(); + try { + for (HelpdeskDto dto : helpdeskList) { + List<App> appList = new ArrayList<>(); + dto.setApps(appList); + List<Long> appIds = MasterDataManager.getAppIdsForHelpdesk(dto.getId()); + if (!appIds.isEmpty()) { + LOGGER.info("app idis : {}", appIds); + } + for (Long appId : appIds) { + App app = MasterDataManager.getAppFromAppId(appId); + if (appId > 0) { + LOGGER.info("app idis : {}", appIds); + } + if (app != null) { + dto.getApps().add(app); + } + } + } + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + public void getUsersForHelpdesk(List<HelpdeskDto> helpdeskList) { + try { + for (HelpdeskDto dto : helpdeskList) { + List<User> userList = helpdeskDao.getUsersForHelpeskId(dto.getId()); + userList = getImageUrl(userList); + dto.setUsers(userList); + } + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + public void getAdminForHelpdesk(List<HelpdeskDto> helpdeskList) { + try { + for (HelpdeskDto dto : helpdeskList) { + List<User> userList = helpdeskDao.getAdminForHelpeskId(dto.getId()); + userList = getImageUrl(userList); + dto.setAdmins(userList); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + private List<User> getImageUrl(List<User> userList) { + S3Config s3values = superAdminDao.getS3Access(); + for (int i = 0; i < userList.size(); i++) { + if (userList.get(i).getImagePath() != null && !userList.get(i).getImagePath().isEmpty() + && userList.get(i).getImagePath().contains(USERPROFILE)) { + String url = null; + url = S3FileManager.getPreSignedURL(s3values, userList.get(i).getImagePath()); + userList.get(i).setImagePath(url); + } + } + return userList; + } + + public void createHelpdeskListFromRowRecords(HelpdeskRowRecordMapper mapper, List<HelpdeskDto> helpdeskList) { + Iterator<Entry<Long, HelpdeskDto>> itr = mapper.getHelpdeskMap().entrySet().iterator(); + while (itr.hasNext()) { + Entry<Long, HelpdeskDto> entry = itr.next(); + Long helpdeskId = entry.getKey(); + HelpdeskDto helpdeskDto = entry.getValue(); + List<Long> typeIds = mapper.getHelpdeskTypeMapping().get(helpdeskId); + List<HelpdeskTypeDto> helpdeskTypes = new ArrayList<>(); + for (Long typeId : typeIds) { + List<HelpdeskWorkflowDto> workflowStages = new ArrayList<>(); + HelpdeskTypeDto helpdeskTypeDto = mapper.getHelpdeskTypeMap().get(typeId); + List<Long> workflowStageIds = mapper.getTypeWorkflowMapping().get(helpdeskTypeDto.getId()); + for (Long workflowStageId : workflowStageIds) { + HelpdeskWorkflowDto workflowStageDto = mapper.getHelpdeskWorkflowMap().get(workflowStageId); + workflowStages.add(workflowStageDto); + } + helpdeskTypeDto.setWorkflowStages(workflowStages); + List<ChecklistItem> checklistItems = helpdeskDao.getChecklistItemsForHelpdesk(helpdeskDto.getId(), + helpdeskTypeDto.getId()); + helpdeskTypeDto.setChecklistItems(checklistItems); + helpdeskTypes.add(helpdeskTypeDto); + } + helpdeskDto.setTypes(helpdeskTypes); + helpdeskList.add(helpdeskDto); + } + } + + @Override + public boolean configureHelpdesk(HelpdeskDto helpdeskDto, User user) { + if (helpdeskDto.getId() != null) { + helpdeskDao.deleteTypeForHelpdesk(helpdeskDto.getId()); + List<HelpdeskTypeDto> typeDtoList = helpdeskDto.getTypes(); + for (HelpdeskTypeDto typeDto : typeDtoList) { + helpdeskDao.deleteWorkflowForHelpdeskType(typeDto.getId()); + helpdeskDao.deleteChecklistForHelpdeskType(helpdeskDto.getId(), typeDto.getId()); + helpdeskDao.addTypeForHelpdesk(typeDto, helpdeskDto.getId()); + helpdeskDao.addWorkflowForHelpdeskType(typeDto); + helpdeskDao.addChecklistForHelpdeskType(typeDto, helpdeskDto.getId()); + } + } + return true; + } + + @Override + public List<Long> getHelpdeskAdmins(Long id) { + return helpdeskDao.getHelpdeskAdmins(id); + } + + @Override + public boolean addUpdateHelpdeskAdmins(Helpdesk helpdesk, User user) { + return helpdeskDao.addUpdateHelpdeskAdmins(helpdesk); + } + + @Override + public List<HelpDeskApp> getAppIdAndHelpDeskId() { + return helpdeskDao.getAppIdAndHelpDeskId(); + } + + @Override + public List<Helpdesk> getHelpdeskObjectFromHelpdeskId() { + return helpdeskDao.getHelpdeskObjectFromHelpdeskId(); + } + + @Override + public List<User> getUsersForHelpeskId(Long id) { + return helpdeskDao.getUsersForHelpeskId(id); + } + + @Override + public void getHelpdeskAdminUser(List<HelpdeskDto> helpdeskList) { + helpdeskDao.getHelpdeskAdminUser(helpdeskList); + } +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/RoleActionServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/RoleActionServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..cfd4af8d3414f9b506a3a7121253038a250d117b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/RoleActionServiceImpl.java @@ -0,0 +1,62 @@ +package org.upsmf.grievance.service.impl; + +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.upsmf.grievance.dao.RoleDao; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.service.RoleActionService; +import org.upsmf.grievance.util.Constants; + +@Service(value = Constants.ROLE_ACTION_SERVICE) +public class RoleActionServiceImpl implements RoleActionService { + + @Autowired + private RoleDao roleDao; + + @Override + public Role saveRole(Role role) { + return roleDao.saveRole(role); + } + + @Override + public Role updateRole(Role role) { + return roleDao.updateRole(role); + } + + @Override + public List<Role> getAllRoles(Long orgId) { + return roleDao.getAllRoles(orgId); + } + + @Override + public String findById(Role role) { + return roleDao.findById(role); + } + + @Override + public List<Role> getAllOrgRoles() { + return roleDao.getAllOrgRoles(); + } + + @Override + public void initializeActions() { + roleDao.initializeActions(); + + } + + @Override + public void intializeRolesAndActions() { + roleDao.intializeRolesAndActions(); + + } + + @Override + public Map<Long, List<String>> getAllActionsForRoles(List<Long> roleIds) { + return roleDao.getAllActionsForRoles(roleIds); + } + +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/SuperAdminServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/SuperAdminServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..3f4ea370c0c7681c9f6d9ab98ff038e9bcab88fd --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/SuperAdminServiceImpl.java @@ -0,0 +1,102 @@ +package org.upsmf.grievance.service.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.service.SuperAdminService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.SendMail; + +@Service(value = Constants.SUPER_ADMIN_SERVICE) +public class SuperAdminServiceImpl implements SuperAdminService { + public static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class); + + @Autowired + private SuperAdminDao superAdminDao; + + @Override + public List<Organization> getAllOrganization() { + return superAdminDao.getAllOrganization(); + } + + @Override + public Organization addOrganization(Organization organization) { + return superAdminDao.addOrganization(organization); + } + + @Override + public boolean updateOrganizationById(Organization organization) { + + return superAdminDao.updateOrganizationById(organization); + } + + @Override + public Organization getOrganizationById(Long id) { + return superAdminDao.getOrganizationByIdV2(id); + } + + @Override + public boolean deleteOrganization(Organization organization) { + + return superAdminDao.deleteOrganization(organization); + } + + @Override + public boolean addAdmin(long userId) { + boolean value = superAdminDao.addAdmin(userId); + if (value) { + User user = superAdminDao.userDetailsByUserId(userId); + user.setOrgId(MasterDataManager.getUserOrgMap().get(userId)); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.LAST_NAME, user.getUsername()); + keyValue.put(JsonKey.ORGNAME, MasterDataManager.getOrgIdAndOrgNameMap().get(user.getOrgId())); + LOGGER.info(MasterDataManager.getOrgIdAndOrgNameMap().get(user.getOrgId())); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.NEW_ADMIN, Constants.ADD_ADMIN_VM_FILE); + } + return value; + } + + @Override + public boolean removeAdmin(long userId) { + boolean value = superAdminDao.removeAdmin(userId); + if (value) { + User user = superAdminDao.userDetailsByUserId(userId); + user.setOrgId(MasterDataManager.getUserOrgMap().get(userId)); + String email = user.getUsername(); + Map<String, String> keyValue = new HashMap<>(); + keyValue.put(JsonKey.FIRST_NAME, user.getName()); + keyValue.put(JsonKey.ORGNAME, MasterDataManager.getOrgIdAndOrgNameMap().get(user.getOrgId())); + LOGGER.info(MasterDataManager.getOrgIdAndOrgNameMap().get(user.getOrgId())); + String[] emails = email.split(","); + SendMail.sendMail(keyValue, emails, Constants.DELETE_ADMIN, Constants.DELETE_ADMIN_VM_FILE); + } + return value; + } + + @Override + public boolean mapAppsToOrg(StatusIdMap statusIdMap) { + return superAdminDao.mapAppsToOrg(statusIdMap); + + } + + @Override + public List<Organization> getOrganizationByUserId(Long userId) { + + return superAdminDao.getOrganizationByUser(userId); + } +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/TagServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/TagServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..fa3a4a751219bc0fae8462bf9f34334aec3d8435 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/TagServiceImpl.java @@ -0,0 +1,53 @@ +package org.upsmf.grievance.service.impl; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.upsmf.grievance.dao.TagDao; +import org.upsmf.grievance.dto.TicketTagDto; +import org.upsmf.grievance.model.Tags; +import org.upsmf.grievance.model.TicketsTagsList; +import org.upsmf.grievance.service.TagService; +import org.upsmf.grievance.util.Constants; + +@Service(value = Constants.TAG_SERVICE) +public class TagServiceImpl implements TagService { + + @Autowired + private TagDao tagDao; + + @Override + public boolean saveTags(TicketTagDto ticketTagDto, Long id) { + for (Tags tag : ticketTagDto.getTags()) { + Tags savedTag = tagDao.getTagByName(tag.getName().trim(), id); + if (savedTag == null) { + tag.setId(tagDao.addTag(id, tag)); + } else { + tag.setId(savedTag.getId()); + } + } + return tagDao.addTicketTags(ticketTagDto.getId(), ticketTagDto.getTags()); + } + + @Override + public TicketsTagsList getAllOrgTags(Long orgId) { + TicketsTagsList list = new TicketsTagsList(); + list.setTags(tagDao.getAllTags(orgId)); + return list; + } + + @Override + public List<Tags> getAllTicketTags(Long id) { + return tagDao.getAllTicketTags(id); + } + + @Override + public TicketsTagsList getHelpdeskTags(Long id, Long userId) { + TicketsTagsList list = new TicketsTagsList(); + list.setTags(tagDao.getHelpdeskTags(id, userId)); + return list; + } + +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/TicketServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/TicketServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..3925cd5233a1a42c85de0095f1310e4adecea3fd --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/TicketServiceImpl.java @@ -0,0 +1,262 @@ +package org.upsmf.grievance.service.impl; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.tomcat.util.codec.binary.Base64; +import org.elasticsearch.action.search.MultiSearchResponse; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import com.google.gson.Gson; +import org.upsmf.grievance.dao.TicketDao; +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Analytics; +import org.upsmf.grievance.model.TemplateVersion; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketCount; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.repository.ElasticSearchRepository; +import org.upsmf.grievance.service.TicketService; +import org.upsmf.grievance.util.Constants; + +@Service(value = Constants.TICKET_SERVICE) +public class TicketServiceImpl implements TicketService { + + @Autowired + private TicketDao ticketDao; + + private final String indexServiceHost; + private final String userName; + private final String password; + private final String templatesIndexName; + private final String templatesDocumentType; + private static final String AUTHORIZATION = "Authorization"; + private static final String BASIC_AUTH = "Basic %s"; + public static final Logger LOGGER = LoggerFactory.getLogger(TicketServiceImpl.class); + Gson gson = new Gson(); + + public TicketServiceImpl(@Value("${services.esindexer.host}") String indexServiceHost, + @Value("${services.esindexer.username}") String userName, + @Value("${services.esindexer.password}") String password, + @Value("${es.templates.index.name}") String templatesIndexName, + @Value("${es.templates.document.type}") String templatesDocumentType, TicketDao ticketDao) { + this.indexServiceHost = indexServiceHost; + this.userName = userName; + this.password = password; + this.templatesIndexName = templatesIndexName; + this.templatesDocumentType = templatesDocumentType; + this.ticketDao = ticketDao; + + } + + @Autowired + private ElasticSearchRepository elasticRepository; + + @Override + public Ticket addTicket(Ticket ticket) { + return ticketDao.addTicket(ticket); + } + + @Override + public Long getTemplatesVersion() { + return ticketDao.getTemplatesVersion(); + } + + @Override + public boolean configureTemplates(TemplateVersion templateVersion) { + Long versionOfTemplate = new Date().getTime(); + if (versionOfTemplate > 0) { + LOGGER.info("New Version of the Template : {}", versionOfTemplate); + } + if (null == templateVersion.getVersion()) { + templateVersion.setVersion(versionOfTemplate); + } + String url = String.format("%s%s/%s/%s", this.indexServiceHost, templatesIndexName, templatesDocumentType, + templateVersion.getVersion()); + HttpHeaders headers = getHttpHeaders(); + if (templateVersion.getVersion() > 0) { + LOGGER.info("Template Version to be added to ES : {}", templateVersion.getVersion()); + } + if (!StringUtils.isBlank(url)) { + LOGGER.info("URL to invoke : {}", url); + } + Boolean saveStatus = elasticRepository.saveTemplate(templateVersion, url, headers); + ticketDao.updateTemplateVersion(versionOfTemplate); + return saveStatus; + } + + @Override + public TemplateVersion getTemplates() { + MultiSearchResponse response = executeTemplatesElasticQuery(); + return templateResponseTranslator(response); + } + + private MultiSearchResponse executeTemplatesElasticQuery() { + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(1000); + return elasticRepository.executeMultiSearchRequest( + new SearchRequest(templatesIndexName).types(templatesDocumentType).source(searchSourceBuilder)); + } + + private TemplateVersion templateResponseTranslator(MultiSearchResponse templateResponse) { + + SearchResponse searchResponse = templateResponse.getResponses()[0].getResponse(); + List<TemplateVersion> templateVersionList = new ArrayList<>(); + if (searchResponse != null) { + for (SearchHit hit : searchResponse.getHits()) { + TemplateVersion templateVersion = gson.fromJson(hit.getSourceAsString(), TemplateVersion.class); + templateVersionList.add(templateVersion); + } + } + return Collections.max(templateVersionList, Comparator.comparing(template -> template.getVersion())); + } + + /** + * A helper method to create the headers for Rest Connection with UserName and + * Password + * + * @return HttpHeaders + */ + private HttpHeaders getHttpHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.add(AUTHORIZATION, getBase64Value(userName, password)); + headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + + /** + * Helper Method to create the Base64Value for headers + * + * @param userName + * @param password + * @return + */ + public String getBase64Value(String userName, String password) { + String authString = String.format("%s:%s", userName, password); + byte[] encodedAuthString = Base64.encodeBase64(authString.getBytes(StandardCharsets.US_ASCII)); + return String.format(BASIC_AUTH, new String(encodedAuthString)); + } + + @Override + public boolean updateTicketBasic(MultipartFile file, Ticket ticket) { + + return ticketDao.updateTicketBasic(file, ticket); + } + + @Override + public Ticket getTicketsById(User user, Long id) { + return ticketDao.getTicketsById(user.getId(), id); + } + + @Override + public List<Ticket> getAllTicketsByAppId(Long appId) { + return ticketDao.getAllTicketsByAppId(appId); + } + + @Override + public Boolean updateNotesToTicket(Ticket ticket) { + return ticketDao.updateNotesToTicket(ticket.getRequestedBy(), ticket.getId(), ticket.getNotes()); + } + + @Override + public Boolean addUpdateUpdatesToTicket(Updates update) { + return ticketDao.addUpdateUpdatesToTicket(update); + } + + @Override + public List<Updates> getUpdatesForTicket(Long id) { + return ticketDao.getUpdatesForTicket(id); + } + + @Override + public boolean updateTicketType(TicketTypeDto ticketTypeDto, Long userId) { + return ticketDao.updateTicketType(ticketTypeDto, userId); + } + + @Override + public boolean updateTicketStatus(Ticket ticket) { + return ticketDao.updateTicketStatus(ticket); + } + + @Override + public boolean updateTicketChecklist(Ticket ticket) { + return ticketDao.updateTicketChecklist(ticket); + } + + @Override + public List<ActivityLog> getActivityLogsPerTicket(Long id) { + return ticketDao.getActivityLogsPerTicket(id); + } + + @Override + public List<ActivityLog> getActivityLogsPerUser(Long id) { + + return ticketDao.getActivityLogsPerUser(id); + } + + @Override + public List<Ticket> getAllTicketsByUserId(Long id) { + return new ArrayList<>(); + } + + @Override + public List<TicketElastic> getTicketDetailsByHelpdeskId(Ticket ticket) { + return ticketDao.getTicketDetailsByHelpdeskId(ticket); + } + + @Override + public List<Ticket> keepOnlyCreatedAndCopiedToTickets(Long userId, List<Ticket> ticketList) { + return ticketDao.keepOnlyCreatedAndCopiedToTickets(userId, ticketList); + } + + @Override + public boolean pinTicket(Ticket ticket) { + return ticketDao.pinTicket(ticket); + } + + @Override + public TicketCount getNoOfTickets(Long userId) { + return ticketDao.getNoOfTickets(userId); + } + + @Override + public Map<String, Long> getTicketsCountPerMonthPerUser(Analytics analytics) { + return ticketDao.getTicketsCountPerMonthPerUser(analytics); + } + + @Override + public boolean attachmentUpload(MultipartFile file, Ticket ticket) { + return ticketDao.attachmentUpload(file, ticket); + } + + @Override + public List<Ticket> getFeedBacksFromAuroraSdk() { + return ticketDao.getFeedBacksFromAuroraSdk(); + } + + @Override + public boolean sendRepliesToReviews(Updates updates) { + return ticketDao.sendRepliesToReviews(updates); + } + +} diff --git a/src/main/java/org/upsmf/grievance/service/impl/UserServiceImpl.java b/src/main/java/org/upsmf/grievance/service/impl/UserServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..32153becc79c1da71abe87fb8ad893de1f447100 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/service/impl/UserServiceImpl.java @@ -0,0 +1,522 @@ +package org.upsmf.grievance.service.impl; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken; +import com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload; +import com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dao.RoleDao; +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.dao.UserDao; +import org.upsmf.grievance.dto.ChangePasswordDto; +import org.upsmf.grievance.dto.LoginDto; +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.executor.MasterDataManager; +import org.upsmf.grievance.model.Access; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.CommonDataModel; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.S3Config; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserRoleMapper; +import org.upsmf.grievance.service.UserService; +import org.upsmf.grievance.util.Constants; +import org.upsmf.grievance.util.JsonKey; +import org.upsmf.grievance.util.ProjectUtil; +import org.upsmf.grievance.util.S3FileManager; +import org.upsmf.grievance.util.SendMail; +import org.upsmf.grievance.util.Sql; + +@Service(value = Constants.USER_SERVICE) +public class UserServiceImpl implements UserDetailsService, UserService { + private static final String ENCOUNTERED_AN_EXCEPTION = "Encountered an Exception : %s"; + + private static final String USERPROFILE = "userprofile"; + + public static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class); + + @Autowired + private UserDao userDao; + + @Autowired + JdbcTemplate jdbcTemplate; + + @Autowired + RoleDao roleDao; + + @Autowired + SuperAdminDao superAdminDao; + + @Autowired + HelpdeskDao helpdeskDao; + + @Value("${image.source.aws}") + private Boolean imageSource; + + @Override + public List<Action> findAllActionsByRoleID(List<Integer> roleID) { + List<Action> completeActions = new ArrayList<>(); + for (int roleid : roleID) { + completeActions.addAll(userDao.findAllActionsByRoleID(roleid)); + } + return completeActions; + } + + @Override + public Map<String, Object> getUserInfoObjects(String userId) { + User user = userDao.findByUsername(userId, Boolean.FALSE, Boolean.FALSE); + if (user == null) { + throw new UsernameNotFoundException("Invalid username or password."); + } + Map<String, Object> userInfoObjectMap = new HashMap<>(); + userInfoObjectMap.put("User", user); + userInfoObjectMap.put("UserDetails", new org.springframework.security.core.userdetails.User(user.getUsername(), + user.getPassword(), getAuthority())); + return userInfoObjectMap; + } + + @Override + public UserDetails loadUserByUsername(String userId) { + User user = userDao.findByUsername(userId, Boolean.FALSE, Boolean.FALSE); + if (user == null) { + throw new UsernameNotFoundException("Invalid username or password."); + } + return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), + getAuthority()); + } + + private List<SimpleGrantedAuthority> getAuthority() { + return Arrays.asList(new SimpleGrantedAuthority("ROLE_ADMIN")); + } + + @Override + public User findOne(String username, Boolean withRoles, Boolean withActions) { + return userDao.findByUsername(username, withRoles, withActions); + } + + @Override + public User findById(Long id) { + User user = new User(); + List<Role> roleList = new ArrayList<>(); + try { + List<User> mapper = userDao.findOne(id); + if (!ProjectUtil.isObjectListNullOrEmpty(mapper)) { + user = mapper.get(0); + MasterDataManager.getAllUserRoles(); + if (user != null) { + List<Long> roles = MasterDataManager.getUserRoleListMap().get(user.getId()); + for (int i = 0; i < roles.size(); i++) { + roleList.add(MasterDataManager.getRoleMap().get(roles.get(i))); + } + user.setRoles(roleList); + user.setOrgId(jdbcTemplate.queryForObject(Sql.Common.GET_ORG_ID_BY_USER_ID, new Object[] { id }, + Long.class)); + user.setOrganization(superAdminDao.getOrganizationByUser(id)); + user.setHelpdesk(helpdeskDao.getHelpdeskByUserId(id)); + String image = jdbcTemplate.queryForObject(Sql.Common.GET_IMAGE_PATH, new Object[] { id }, + String.class); + user.setImagePath(image); + setUserImage(user); + return user; + } + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return null; + } + + private void setUserImage(User user) { + if (!StringUtils.isBlank(user.getImagePath())) { + try { + if (user.getImagePath().contains(USERPROFILE)) { + S3Config s3values = superAdminDao.getS3Access(); + String url = null; + url = S3FileManager.getPreSignedURL(s3values, user.getImagePath()); + user.setImagePath(url); + } else { + String data = getFile(user.getId()); + user.setImagePath(data); + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + } + + @Override + public User save(MultipartFile file, long authUserId, User user) { + user.setUpdatedBy(authUserId); + user = userDao.insertIntoUser(user); + if (user.getId() == 0) { + return null; + } else { + LOGGER.info("userId: {}", user.getId()); + } + UserDto userDto = new UserDto(); + userDto.setName(user.getName()); + userDto.setUsername(user.getUsername()); + userDto.setId(user.getId()); + userDao.customAuth(userDto); + + boolean userRoleInsert = userDao.mapUserToRole(user.getId(), user.getRoles()); + if (!userRoleInsert && user.getId() > 0 && user.getId() != null) { + LOGGER.info("Inserting into tt_user_role FAILED for user: {}", user.getId()); + } + + if (user.getOrgId() != null) { + boolean userCompInsert = superAdminDao.mapUserToOrg(user.getId(), user.getOrgId().intValue()); + if (!userCompInsert && user.getId() > 0 && user.getId() != null) { + LOGGER.info("Inserting into tt_user_comp FAILED for user: {}", user.getId()); + } else { + MasterDataManager.getUserOrgMap().put(user.getId(), user.getOrgId()); + } + } + + insertProfilePicture(file, user); + return user; + } + + @Override + public Long saveAnonymousUser(User user) { + Long userId = checkUserNameExists(user.getUsername()); + if (userId == 0) { + userId = userDao.insertAnonymousUser(user); + if (userId == 0) { + return null; + } else if (userId > 0 && userId != null) { + LOGGER.info("userId: {}", userId); + } + if (user.getOrgId() != null) { + boolean userCompInsert = superAdminDao.mapUserToOrg(userId, user.getOrgId().intValue()); + if (!userCompInsert && userId > 0 && userId != null) { + LOGGER.info("Inserting into tt_user_comp FAILED for user: {}", userId); + } + } + } + return userId; + } + + private void insertProfilePicture(MultipartFile file, User user) { + try { + if (imageSource) { + if (user.getImagePath() != null) { + String value = getImagePathValue(user); + pathValue(user, value); + } + } else { + String value = null; + if (!file.isEmpty()) { + value = uploadFile(file, user.getId()); + } + jdbcTemplate.update(Sql.INSERT_PROFILE_PICTURE, new Object[] { value, user.getId() }); + } + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + private void pathValue(User user, String value) { + try { + jdbcTemplate.update(Sql.INSERT_PROFILE_PICTURE, new Object[] { value, user.getId() }); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + @Override + public User update(MultipartFile file, User user) { + try { + if (imageSource) { + if (user.getImagePath() != null) { + String value = null; + value = getImagePathValue(user); + user.setImagePath(value); + } + } else if (!file.isEmpty()) { + String value = uploadFile(file, user.getId()); + user.setImagePath(value); + } + } catch (Exception e) { + + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return userDao.update(user); + } + + private String getImagePathValue(User user) { + String value = null; + try { + Long organization = MasterDataManager.getUserOrgMap().get(user.getId()); + value = S3FileManager.filePath(user.getImagePath(), USERPROFILE, user.getId(), organization); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return value; + } + + @Override + public List<Role> findAllRolesByUser(Long userId) { + UserRoleMapper mapper = userDao.findAllRolesByUser(userId); + List<Role> roleList = new ArrayList<>(); + Iterator<Entry<Long, Role>> itr = mapper.getRoleMap().entrySet().iterator(); + while (itr.hasNext()) { + roleList.add(itr.next().getValue()); + } + return roleList; + } + + @Override + public Boolean mapUserToRole(User user) { + return userDao.mapUserToRole(user.getId(), user.getRoles()); + } + + @Override + public User updateUserImage(User profile) { + return userDao.updateUserImage(profile); + } + + @Override + public Long checkUserNameExists(String username) { + return userDao.checkUserNameExists(username); + } + + @Override + public boolean changePassword(ChangePasswordDto changePasswordDto) { + if (changePasswordDto.getOldPass().equals(changePasswordDto.getNewPass())) { + + return true; + } + LOGGER.info("Entering Dao from service"); + return userDao.changePassword(changePasswordDto); + } + + @Override + public boolean forgotPassword(UserDto userDto) { + Map<String, String> keyValue = new HashMap<>(); + boolean response = false; + long userId = userDao.forgotPassword(userDto); + if (userId > 0) { + response = true; + String[] emails = { userDto.getUsername() }; + String randomPassword = ProjectUtil.getRandomStringVal(); + LOGGER.info(randomPassword); + userDao.saveForgotPassword(userId, randomPassword); + keyValue.put(JsonKey.PSWRD, randomPassword); + SendMail.sendMail(keyValue, emails, Constants.PSWORD_REGENERATED, Constants.FORGOT_PSWORD_VM_FILE); + } + return response; + } + + @Override + public String uploadFile(MultipartFile file, long userId) { + return null; + } + + @Override + public String getFile(Long userId) throws IOException { + try { + String imagePath = null; + List<User> u = userDao.findOne(userId); + if (!ProjectUtil.isObjectNull(u.get(0))) { + imagePath = u.get(0).getImagePath(); + } + if (!ProjectUtil.isStringNullOrEmpty(imagePath)) { + Path path = Paths.get(Constants.UPLOADED_FOLDER + imagePath); + readb(path); + } + return "http://aurora-images.tarento.com/images" + imagePath; + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return null; + } + + private void readb(Path path) { + try { + Files.readAllBytes(path); + } catch (final IOException e) { + + } + } + + @Override + public Long getNumberOfUsers(Long role, Boolean active) { + return userDao.getNumberOfUsers(role, active); + } + + @Override + public Long getNumberOfRoles() { + return userDao.getNumberOfRoles(); + } + + @Override + public Boolean invalidateToken(String authToken) { + return userDao.invalidateToken(authToken); + } + + @Override + public Boolean findUserByToken(String authToken) { + return userDao.findUserByToken(authToken); + } + + @Override + public Boolean checkUserTokenExists(Long userId, String deviceToken) { + return userDao.checkUserTokenExists(userId, deviceToken); + } + + @Override + public Long fetchAuthTokenReference(String authToken) { + return userDao.fetchAuthTokenReference(authToken); + } + + @Override + public LoginDto login(UserDto userDto) { + User userObject = userDao.getUserDetailsByEmail(userDto.getUsername()); + if (userObject == null) { + LOGGER.info("getUserDetailsByEmail method is returning Null"); + return null; + } + userDto.setUsername(userObject.getUsername()); + userDto.setOrgId(userObject.getOrgId()); + userDto.setAuthType(userObject.getAuthType()); + userDto.setId(userObject.getId()); + userDao.getAuthDomain(userDto); + if (authenticate(userDto)) { + LoginDto loginData = userDao.login(userDto); + if (!StringUtils.isBlank(userObject.getImagePath()) && userObject.getImagePath().contains(USERPROFILE)) { + S3Config s3values = superAdminDao.getS3Access(); + String url = S3FileManager.getPreSignedURL(s3values, userObject.getImagePath()); + loginData.setImageUrl(url); + } + for (int i = 0; i < loginData.getRoles().size(); i++) { + if (loginData.getRoles().get(i).getId() == Constants.ADMIN_ID) { + boolean check = userDao.getFirstAdminsOfOrg(userObject.getId()); + if (check && userDao.onBoardingCheck(userObject.getOrgId(), userObject.getId())) { + return loginData; + } + break; + } + } + return loginData; + } + return null; + + } + + private boolean authenticate(UserDto userDto) { + if (userDto.getGoogleEmail() != null) { + return googleAuth(userDto); + } + CommonDataModel authDomainMap; + authDomainMap = userDao.getAuthDomain(userDto); + if (authDomainMap == null) { + LOGGER.error("Method Name: authenticate, Message: authDomainMap is Null"); + return false; + } + switch (authDomainMap.getDescription()) { + case Constants.GOOGLE_AUTH: + return googleAuth(userDto); + case Constants.CUSTOM_AUTH: + return customAuth(userDto); + default: + return false; + } + } + + private boolean customAuth(UserDto userDto) { + return userDao.isPasswordMatch(userDto.getId(), userDto.getPassword()); + } + + private boolean googleAuth(UserDto userDto) { + try { + final HttpTransport transport = new NetHttpTransport(); + final JsonFactory jsonFactory = new JacksonFactory(); + String email = null; + GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(transport, jsonFactory) + .setAudience(Collections.singletonList(userDto.getGoogleClientId())).build(); + + GoogleIdToken idToken = verifier.verify(userDto.getGoogleIdToken()); + if (idToken != null) { + Payload payload = idToken.getPayload(); + email = payload.getEmail(); + } + if (StringUtils.isNotBlank(email) && email.trim().equalsIgnoreCase(userDto.getGoogleEmail())) { + return true; + } + } catch (Exception e) { + LOGGER.error(e.getMessage()); + } + return false; + + } + + @Override + public List<User> findAll(Long orgId) { + return userDao.findAll(orgId); + } + + @Override + public List<OrgUserRoleDto> getAllOrgUsers() { + return userDao.getAllOrgUsers(); + } + + @Override + public List<OrgUserRoleDto> getAllUserRoles() { + return userDao.getAllUserRoles(); + } + + @Override + public List<HelpDeskApp> getAppIdAndHelpDeskId() { + return userDao.getAppIdAndHelpDeskId(); + } + + @Override + public List<User> getUserIdAndUserName() { + return userDao.getUserIdAndUserName(); + } + + @Override + public void getReviews() throws IOException { + userDao.getReviews(); + } + + @Override + public Access getReviewConfig(Long id) { + return userDao.getReviewConfig(id); + } + +} \ No newline at end of file diff --git a/src/main/java/org/upsmf/grievance/util/Constants.java b/src/main/java/org/upsmf/grievance/util/Constants.java new file mode 100644 index 0000000000000000000000000000000000000000..29744f140e4cb9ff8c787e99f3d1209df751cd51 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/Constants.java @@ -0,0 +1,342 @@ +package org.upsmf.grievance.util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Constants { + + private static final String FEEDBACK_BY_NAME = "feedbackByName"; + private static final String TYPE = "type"; + private static final String TOTAL = "total"; + /** + * Header and Request Parameters + */ + public static final long ACCESS_TOKEN_VALIDITY_SECONDS = (long) 30 * 24 * 60 * 60; + public static final String REVIEWS2 = "/reviews?translationLanguage=en"; + public static final String HTTPS_WWW_GOOGLEAPIS_COM_ANDROIDPUBLISHER_V3_APPLICATIONS = "https://www.googleapis.com/androidpublisher/v3/applications/"; + public static final String REVIEWSPEC_JSON = "/reviewspec.json"; + public static final String ACCESSTOKENSPEC_JSON = "/accesstokenspec.json"; + public static final String SIGNING_KEY = "devglan123r"; + public static final String JWT_ISSUER = "http://devglan.com"; + public static final String JWT_GRANTED_AUTHORITY = "ROLE_ADMIN"; + public static final String TOKEN_PREFIX = "Bearer "; + public static final String HEADER_STRING = "Authorization"; + public static final String HEADER_APPLICATION_JSON = "application/json"; + public static final String ERROR_CODE = "errorCode"; + public static final String ERROR_FIELD = "errorField"; + public static final String ERROR_MESSAGE_CODE = "errorMessageCode"; + public static final String ERROR_MESSAGE_VALUE = "common.error."; + public static final String SUCCESS_CODE = "successCode"; + public static final String ERROR_MESSAGE = "errorMessage"; + public static final String SUCCESS_MESSAGE = "successMessage"; + public static final String AUTH_HEADER = "Authorization"; + public static final String PARAMETERS = "parameters"; + + public enum ELK_OPERATION { + SAVE, UPDATE, DELETE; + } + + public final class RequestParams { + private RequestParams() { + super(); + } + + public static final String USER_INFO = "UserInfo"; + public static final String ID = "id"; + public static final String HELPDESK_ID = "helpdeskId"; + public static final String APP_ID = "appId"; + } + + /** + * Query Parameters and Response Parameters + */ + public static final String USER_INFO_HEADER = "x-user-info"; + public static final String SUCCESS = "success"; + public static final String ASC = "asc"; + public static final String DESC = "desc"; + public static final String TRUE = "true"; + public static final String FALSE = "false"; + public static final String STRING_BLANK = ""; + public static final String COMMA_SPACE_SEPARATOR = ", "; + public static final String DATE = "date"; + public static final String QUERY_ALERT_SUBJECT = "Query Alert!!"; + public static final String SCHEDULER_ALERT_SUBJECT = "Scheduler Alert!!"; + public static final String STRING_SPACE = " "; + public static final String STRING_HYPEN = "-"; + public static final String NEW_MESSAGE = "New"; + public static final String READ_MESSAGE = "Read"; + public static final String DELETE_MESSAGE = "Delete"; + public static final String SEND_MESSAGE = "Send"; + public static final String FILE_TYPE = "PDF,DOC,TXT,JPG,JPEG,PNG,GIF,AAC,MP3,MP4"; + public static final String IMAGE_FILE_TYPE = "JPG,JPEG,PNG,GIF"; + public static final String FCM_API_URL = "fcm.api.url"; + public static final String FCM_API_KEY = "fcm.api.key"; + + /** + * URLs and Paths + */ + public static final String UPLOADED_FOLDER = "/usr/grievance"; + public static final String ATTACHMENT_FOLDER = "C:\\Users\\Juhi Agarwal\\git\\grievance-desk-core\\public\\attachments"; + + /** + * Status Code and Messages + */ + public static final int UNAUTHORIZED_ID = 401; + public static final int SUCCESS_ID = 200; + public static final int FAILURE_ID = 320; + public static final String UNAUTHORIZED = "Invalid credentials. Please try again."; + public static final String PROCESS_FAIL = "Process failed, Please try again."; + + public enum userRole { + SUPERADMIN, ORGADMIN, ENDUSER; + } + + /** + * Indicators or Classifiers + */ + public static final String ROLE = "ROLE"; + public static final String ORG = "ORG"; + + /** + * Allowed Origins for CORS Bean + */ + public static final String GET = "GET"; + public static final String POST = "POST"; + public static final String PUT = "PUT"; + public static final String DELETE = "DELETE"; + public static final String OPTIONS = "OPTIONS"; + + /** + * Qualifiers and Services + */ + public static final String USER_SERVICE = "userService"; + public static final String USER_DAO = "userDao"; + public static final String SUPER_ADMIN_SERVICE = "superAdminService"; + public static final String SUPER_ADMIN_DAO = "superAdminDao"; + public static final String TICKET_SERVICE = "ticketService"; + public static final String TICKET_DAO = "ticketDao"; + public static final String ROLE_ACTION_SERVICE = "roleActionService"; + public static final String APP_SERVICE = "appService"; + public static final String TAG_SERVICE = "tagService"; + public static final String ROLE_DAO = "roleDao"; + public static final String APP_DAO = "appDao"; + public static final String TAG_DAO = "tagDao"; + public static final String TIME_ZONE = "UTC"; + public static final String APPEND_SECONDS = ":00"; + public static final String HTTPS_ACCOUNTS_GOOGLE_COM_O_OAUTH2_TOKEN = "https://accounts.google.com/o/oauth2/token"; + public static final String CLIENT_SECRET = "client_secret"; + public static final String CLIENT_ID = "client_id"; + public static final String REFRESH_TOKEN = "refresh_token"; + public static final String GRANT_TYPE = "grant_type"; + + private static final List<Integer> superAdminActions = new ArrayList<>(Arrays.asList(1, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61)); + private static final List<Integer> orgAdminActions = new ArrayList<>( + Arrays.asList(3, 4, 5, 6, 9, 11, 12, 15, 18, 23, 24, 25, 29, 30, 33, 34, 36, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61)); + private static final List<Integer> endUserActions = new ArrayList<>(Arrays.asList(11, 12, 23, 24, 29, 30, 33, 34, + 36, 38, 39, 40, 41, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61)); + + private static Map<Integer, List<String>> actions = createMap(); + + protected static Map<Integer, List<String>> createMap() { + Map<Integer, List<String>> actions = new HashMap<>(); + actions.put(1, Arrays.asList("Get Apps", "Get All Applications", "/app/getAllApps")); + actions.put(3, Arrays.asList("Get Roles", "Get All Roles", "/roles/getAllRoles")); + actions.put(4, Arrays.asList("Add Update Apps", "Add Or Update App", "/apps/addUpdateApp")); + actions.put(5, Arrays.asList("Get Apps", "Get Applications", "/apps/getApp")); + actions.put(6, Arrays.asList("Create Update Helpdesk", "Create or Update a new Helpdesk", + "/helpdesk/createUpdateHelpdesk")); + actions.put(7, Arrays.asList("Fetch Helpdesk", "Get Helpdesk", "/helpdesk/getOrgHelpdesk")); + actions.put(8, Arrays.asList("Check MDM", "Check MDM", "/roles/mdmCheck")); + actions.put(9, Arrays.asList("Get Service Request", "Fetch Service Requests", "/apps/getServiceRequests")); + actions.put(10, + Arrays.asList("Get Priority Levels", "Get All Ticket Priority Levels", "/tickets/getPriorityLevels")); + actions.put(11, Arrays.asList("Get Helpdesk", "Fetch Helpdesks", "/helpdesk/getHelpdesk")); + actions.put(12, Arrays.asList("Add Update User", "Add Or Update User Details", "/user/createOrUpdate")); + actions.put(15, Arrays.asList("Update Organization", "Update Organization", "/superadmin/updateOrgById")); + actions.put(16, Arrays.asList("Add Org", "Add Organization", "/superadmin/addOrganization")); + actions.put(17, Arrays.asList("Get Org By ID", "Get Org By ID", "/superadmin/getOrgById")); + actions.put(18, Arrays.asList("Delete Org", "Delete Organization", "/superadmin/deleteOrganization")); + actions.put(20, + Arrays.asList("Get Template Version", "Get Version of Template", "/tickets/getTemplatesVersion")); + actions.put(21, Arrays.asList("Configure Templates", "Configure Templates", "/tickets/configureTemplates")); + actions.put(22, Arrays.asList("Get Templates", "Get Templates", "/tickets/getTemplates")); + actions.put(23, Arrays.asList("Get All Users", "getAllUsers", "/user/getAllUsers")); + actions.put(24, Arrays.asList("Get User By Id", "getUserById", "/user/getUser")); + actions.put(25, Arrays.asList("Get Apps By Org", "getAppByOrgId", "/apps/getAppByOrgId")); + actions.put(26, Arrays.asList("Add or Update Helpdesk Admins", "addOrUpdateHelpdeskAdmins", + "/helpdesk/addUpdateHelpdeskAdmins")); + actions.put(27, Arrays.asList("Get Helpdesk Admins", "getHelpdeskAdmins", "/helpdesk/getHelpdeskAdmins")); + actions.put(28, Arrays.asList("Map Apps To Helpdesk", "mappAppsToHelpdesk", "/apps/mapAppToHelpdesk")); + actions.put(29, Arrays.asList("Add Ticket", "addTicket", "/tickets/addTicket")); + actions.put(30, Arrays.asList("Get Tickets", "getAllTickets", "/tickets/getAllTickets")); + actions.put(32, Arrays.asList("Add Notes", "addNotes", "/tickets/addNotes")); + actions.put(33, Arrays.asList("Add Update Updates", "addUpdateUpdates", "/tickets/addUpdateUpdates")); + actions.put(34, Arrays.asList("Get Updates", "getUpdates", "/tickets/getUpdates")); + actions.put(35, Arrays.asList("add admin", "addAdmin", "/superadmin/addAdmin")); + actions.put(36, Arrays.asList("Update Ticket Basic", "updateTicketBasic", "/tickets/updateTicketBasic")); + actions.put(37, Arrays.asList("Update Ticket Type", "updateTicketType", "/tickets/updateTicketType")); + actions.put(38, Arrays.asList("Update Ticket Status", "updateTicketStatus", "/tickets/updateTicketStatus")); + actions.put(39, + Arrays.asList("Update Ticket Checklist", "updateTicketChecklist", "/tickets/updateTicketChecklist")); + actions.put(40, Arrays.asList("Get Activity Logs Per Ticket", "getActivityLogs", "/tickets/getActivityLogs")); + actions.put(41, Arrays.asList("Change Password", "changePassword", "/user/changePassword")); + actions.put(42, Arrays.asList("Add Admin", "addAdmin", "/superadmin/addAdmin")); + actions.put(43, Arrays.asList("Remove Admin", "removeAdmin", "/superadmin/removeAdmin")); + actions.put(44, Arrays.asList("Upload Profile Picture", "uploadProfilePicture", "/user/uploadProfilePicture")); + actions.put(45, Arrays.asList("Pin Ticket", "pinTicket", "/tickets/pinTicket")); + actions.put(46, Arrays.asList("Get No Of Tickets", "getNoOfTickets", "/tickets/getNoOfTickets")); + actions.put(47, Arrays.asList("Get Activity Logs Per User", "getActivityLogsPerUser", + "/tickets/getActivityLogsPerUser")); + actions.put(48, Arrays.asList("Get Tickets Count Per Month Per User", "getTicketsCountPerMonthPerUser", + "/tickets/getTicketsCountPerMonthPerUser")); + actions.put(49, Arrays.asList("Upload Ticket Attachments", "uploadAttachment", "/tickets/uploadAttachment")); + actions.put(51, Arrays.asList("Add Update Tag", "addorUpdateTags", "/tags/addUpdateTag")); + actions.put(52, Arrays.asList("Get All Ticket Tags", "getAllTicketTags", "/tags/getAllTicketTags")); + actions.put(53, Arrays.asList("Get All Tags By Org Id", "getTagByOrgId", "/tags/getTagByOrgId")); + actions.put(54, Arrays.asList("Get All Tags By Helpdesk Id", "getTagByHelpdeskId", "/tags/getTagByHelpdeskId")); + actions.put(55, Arrays.asList("Get Feedback From grievance Sdk", "getFeedbackFromAuroraSdk", + "/tickets/getFeedbackFromAuroraSdk")); + actions.put(56, Arrays.asList("Get All Tickets V2", "getAllTicketsV2", "/tickets/getAllTicketsV2")); + actions.put(57, Arrays.asList("Get All Org", "getAllOrg", "/superadmin/getAllOrg")); + actions.put(58, Arrays.asList("Forgot Password", "forgotPassword", "/user/forgotPassword")); + actions.put(59, Arrays.asList("Map Apps To Org", "mapAppsToOrg", "/superadmin/mapAppsToOrg")); + actions.put(60, Arrays.asList("Get Reviews", "getReviews", "/user/getReviews")); + actions.put(61, Arrays.asList("Send Reply To Reviews", "sendReplyToReviews", "/tickets/sendRepliesToReviews")); + return actions; + } + + public static List<Integer> getOrgadminactions() { + return orgAdminActions; + } + + public static List<Integer> getEnduseractions() { + return endUserActions; + } + + public static Map<Integer, List<String>> getActions() { + return actions; + } + + public static void setActions(Map<Integer, List<String>> actions) { + Constants.actions = actions; + } + + public static List<Integer> getSuperadminactions() { + return superAdminActions; + } + + public static String[] getExcludeFields() { + return EXCLUDE_FIELDS; + } + + public static String[] getIncludeFields() { + return INCLUDE_FIELDS; + } + + public class SMTP { + private SMTP() { + super(); + } + + public static final String HOST = "smtp.sendgrid.net"; + public static final int PORT = 465; + public static final boolean SSL = true; + public static final String USER = "apikey"; + public static final String PSWRD = "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"; + public static final String EMAIL = "shishir.suman@tarento.com"; + public static final String ALIAS = "grievance-desk.support"; + } + + public static final String HOST = "smtp.sendgrid.net"; + public static final String FROM = "shishir.suman@tarento.com"; + public static final String USER = "apikey"; + public static final String PSWRD = "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"; + public static final String LOGO_URL = "https://cabhound-static.s3.amazonaws.com/insuranceDoc/claim/tarento_logo.png"; + public static final String ALIAS = "auroradesk.support"; + + public static final int MAX_EXECUTOR_THREAD = 10; + public static final String HTTPHEADERANDSECURITY = null; + public static final String USER_NAME_MISSING = "User name is mandatory."; + public static final String NAME_MISSING = " Oops ! Name is mandatory."; + public static final String PHONE_NUMBER_MISSING = "Phone number is mandatory."; + public static final String ID_MISSING = " Oops ! Id is mandatory."; + public static final String PSWRD_MISSING = "Oops! Password is Missing"; + public static final String PSWRD_MISMATCH = "New and Confirm passwords don't match."; + public static final String PSWRD_SAME = "New and Old passwords cannot be same."; + public static final int AUTH_TYPE = 1; + public static final String PSWRD_REGENERATED = "Password regenerated"; + public static final String FORGOT_PSWRD_VM_FILE = "forgot-password.vm"; + public static final String NOT_A_CUSTOM_PSWRD = "Please visit GreenPine for Forgot Password Link"; + public static final int ADMIN_ID = 2; + public static final String USERS = "user"; + public static final String GOOGLE_AUTH = "google"; + public static final String CUSTOM_AUTH = "custom"; + public static final String ADD_ADMIN_VM_FILE = "add-admin-grievance.vm"; + public static final String NEW_ADMIN = "You are added as an admin in grievance-Desk"; + public static final String NEW_HELPDESK_ADMIN = "You are added as a helpdesk admin in grievance-Desk"; + public static final String DELETE_HELPDESK_ADMIN = "Revoke of helpdesk admin access in grievance-Desk"; + public static final String COPIEDTO = "You are copied to a ticket in grievance-Desk"; + public static final String TICKETCREATION = "You have created a new ticket in grievance-Desk"; + public static final String REMOVEDFROMCOPIEDTO = "You are removed from a ticket in grievance-Desk"; + public static final String DELETE_ADMIN_VM_FILE = "remove_admin.vm"; + public static final String DELETE_ADMIN = "Revoke of admin access in grievance-Desk"; + public static final String HELPDESKTYPE_WITHOUTWORKFLOW = "Helpdesk Type cannot be created without workflow. Please add workflow and try again"; + public static final String HELPDESKTYPE_WORKFLOW_EMPTY = "Helpdesk Type Workflow cannot be empty. Please add valid workflow and try again"; + public static final int CAPACITY = 1024; + public static final String PSWORD_REGENERATED = "Password regenerated"; + public static final String FORGOT_PSWORD_VM_FILE = "forgot-password.vm"; + public static final String STATUS_CHANGE = "Ticket Status Change!"; + public static final String UPDATES = "Here's what you missed while you were away!"; + public static final String A_1_0 = "1.0"; + public static final String SV = "sv"; + public static final String SAVE = "save"; + public static final String ID = "id"; + public static final String CC = "cc"; + public static final String TAGS2 = "tags"; + public static final String USER_EVENT = "userEvent"; + public static final String DEVICE_SCREEN_RESOLUTION = "deviceScreenResolution"; + public static final String DEVICE_LOCALE = "deviceLocale"; + public static final String DEVICE_MANUFACTURE = "deviceManufacture"; + public static final String REVIEW_ID = "reviewId"; + public static final String DEVICE_NAME = "deviceName"; + public static final String COUNTRY = "country"; + public static final String IP = "ip"; + public static final String DEVICE_TYPE = "deviceType"; + public static final String OS_TYPE = "osType"; + public static final String OS_VERSION = "osVersion"; + public static final String STATUS = "status"; + public static final String PRIORITY = "priority"; + public static final String TYPE_ID = "typeId"; + public static final String SOURCE_ID = "sourceId"; + public static final String HELPDESK_ID = "helpdeskId"; + public static final String APP_ID = "appId"; + public static final String UPDATE = "update"; + public static final String OPR = "opr"; + public static final String PINNED_TICKET = "pinnedTicket"; + public static final String ACTIVE = "active"; + public static final String APP_NAME = "appName"; + public static final String APP_VERSION = "appVersion"; + public static final String REQUESTED_BY = "requestedBy"; + public static final String UPDATED_TIME_TS = "updatedTimeTS"; + public static final String CREATED_TIME_TS = "createdTimeTS"; + public static final String U_T = "uT"; + public static final String C_T = "cT"; + public static final String UPDATED_TIME = "updatedTime"; + public static final String CREATED_TIME = "createdTime"; + public static final String MAX_RATING = "max-rating"; + public static final String RATE = "rate"; + public static final String DESCRIPTION = "description"; + + private static final String[] INCLUDE_FIELDS = new String[] { ID, STATUS, TOTAL, DESCRIPTION, PINNED_TICKET, + REQUESTED_BY, HELPDESK_ID, UPDATED_TIME, CREATED_TIME, U_T, C_T }; + private static final String[] EXCLUDE_FIELDS = new String[] { OS_VERSION, OS_TYPE, DEVICE_TYPE, DEVICE_LOCALE, + DEVICE_SCREEN_RESOLUTION, DEVICE_MANUFACTURE, DEVICE_NAME, IP, USER_EVENT, SV, COUNTRY, SOURCE_ID, TYPE_ID, + TYPE, PRIORITY, RATE, MAX_RATING, APP_VERSION, APP_NAME, APP_ID, FEEDBACK_BY_NAME, ACTIVE, CREATED_TIME_TS, + UPDATED_TIME_TS }; +} diff --git a/src/main/java/org/upsmf/grievance/util/CustomException.java b/src/main/java/org/upsmf/grievance/util/CustomException.java new file mode 100644 index 0000000000000000000000000000000000000000..a53ec563f2e222d8e564fe1d5f857e80f9f70d0b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/CustomException.java @@ -0,0 +1,52 @@ +package org.upsmf.grievance.util; + +public class CustomException { + public CustomException() { + } + + public CustomException(Integer errorCode, String errorMessage, String errorMessageCode, CustomResponse response) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.errorMessageCode = errorMessageCode; + this.response = response; + } + + protected Integer errorCode; + protected String errorMessage; + protected String errorMessageCode; + protected CustomResponse response; + + public Integer getErrorCode() { + return errorCode; + } + + public void setErrorCode(Integer errorCode) { + this.errorCode = errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessageCode() { + return errorMessageCode; + } + + public void setErrorMessageCode(String errorMessageCode) { + this.errorMessageCode = errorMessageCode; + } + + public void setResponse(CustomResponse response) { + this.response = response; + } + + public CustomException(int errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.errorMessageCode = Constants.ERROR_MESSAGE_VALUE + errorCode; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/CustomListResponse.java b/src/main/java/org/upsmf/grievance/util/CustomListResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..f816bedbdb8e44f208d8f99807b9add11ea4b68a --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/CustomListResponse.java @@ -0,0 +1,31 @@ +package org.upsmf.grievance.util; + +public class CustomListResponse { + private int page; + private int pageSize; + private int count; + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/CustomResponse.java b/src/main/java/org/upsmf/grievance/util/CustomResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..8025dbba9e910fc13d5baca3e6b891ea2cf64952 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/CustomResponse.java @@ -0,0 +1,44 @@ +package org.upsmf.grievance.util; + +import java.util.ArrayList; +import java.util.List; + +public class CustomResponse { + private String status; + private String success; + private List<Object> data = new ArrayList<>(); + + public CustomResponse() { + } + + public CustomResponse(String status, String success, List<Object> data) { + this.status = status; + this.success = success; + this.data = data; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public List<Object> getData() { + return data; + } + + public void setData(List<Object> data) { + this.data = data; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/CustomSuccess.java b/src/main/java/org/upsmf/grievance/util/CustomSuccess.java new file mode 100644 index 0000000000000000000000000000000000000000..83a7b09834978165e73e7eb39d26cd5d66168df2 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/CustomSuccess.java @@ -0,0 +1,102 @@ +package org.upsmf.grievance.util; + +import java.util.HashMap; +import java.util.List; + +public class CustomSuccess { + protected Integer successCode; + protected String successMessage; + protected Object data; + protected List<Object> dataList; + protected CustomResponse customResponse = null; + + public CustomSuccess(int successCode, String successMessage) { + this.successCode = successCode; + this.successMessage = successMessage; + } + + public CustomSuccess(Object data) { + if (data instanceof List) { + this.dataList = (List) data; + } else { + this.data = data; + } + } + + public Integer getSuccessCode() { + return successCode; + } + + public void setSuccessCode(Integer successCode) { + this.successCode = successCode; + } + + public String getSuccessMessage() { + return successMessage; + } + + public void setSuccessMessage(String successMessage) { + this.successMessage = successMessage; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public List<Object> getDataList() { + return dataList; + } + + public void setDataList(List<Object> dataList) { + this.dataList = dataList; + } + + public CustomResponse getCustomResponse() { + if (customResponse != null) { + return customResponse; + } + customResponse = new CustomResponse(); + customResponse.setSuccess(Constants.SUCCESS); + if (data != null) { + customResponse.getData().add(data); + } else if (dataList != null) { + customResponse.getData().addAll(dataList); + } else if (successCode != null) { + HashMap<String, Object> responseData = new HashMap<>(); + responseData.put(Constants.SUCCESS_CODE, successCode); + responseData.put(Constants.SUCCESS_MESSAGE, successMessage); + customResponse.getData().add(responseData); + } + return customResponse; + } + + public CustomResponse getCustomResponse(Object object) { + if (customResponse != null) { + return customResponse; + } + customResponse = new CustomResponse(); + customResponse.setSuccess(Constants.SUCCESS); + customResponse.setStatus("200"); + if (data != null) { + customResponse.getData().add(data); + } else if (dataList != null) { + customResponse.getData().addAll(dataList); + } else if (successCode != null) { + HashMap<String, Object> responseData = new HashMap<>(); + responseData.put(Constants.SUCCESS_CODE, successCode); + responseData.put(Constants.SUCCESS_MESSAGE, successMessage); + responseData.put("responseData", object); + customResponse.getData().add(responseData); + } + return customResponse; + } + + public void setCustomResponse(CustomResponse customResponse) { + this.customResponse = customResponse; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/DateUtil.java b/src/main/java/org/upsmf/grievance/util/DateUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..f6f72a9a309980b4d6bc28d76fcba1579e38a413 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/DateUtil.java @@ -0,0 +1,391 @@ +package org.upsmf.grievance.util; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class DateUtil { + + private static final String ENCOUNTERED_AN_EXCEPTION = "Encountered an Exception : %s"; + public static final Logger LOGGER = LoggerFactory.getLogger(DateUtil.class); + + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String INVOICE_DATE_FORMATTER = "EEEE, MMMM d, yyyy"; + public static final String YYYYMMDD_FORMATTER = "yyyy-MM-dd"; + public static final String DATE_MONTH_YEAR_FORMAT = "dd-MMMM-yyyy"; + + /** + * this method take date object and format the date with time zone UTC. + * + * @param date + * date object + * @return formatted date as String in "yyyy-MM-dd HH:mm:ss" + */ + public static String getFormattedDateInUTC(Date date) { + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + format.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + return format.format(date); + } + + /** + * this method take date object and time zone ,and format date object with + * incoming time zone. + * + * @param date + * date object + * @param timeZone + * @return formatted date as String in "yyyy-MM-dd HH:mm:ss" + */ + public static String getFormattedDateWithTimeZone(Date date, String timeZone) { + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + return format.format(date); + } + + /** + * this method will format current date object with incoming formatter + * + * @param format + * date formatter + * @return String formatted date object. + */ + public static String getCurrentDate(String format) { + SimpleDateFormat dateFormat = new SimpleDateFormat(format); + return dateFormat.format(new Date()); + } + + /** + * this method will format long time value to given time zone with MM-dd-yyyy + * HH:mm:ss + * + * @param timeZone + * @param time + * @return String + */ + public static String convertLongToStringAsDateTime(String timeZone, long time) { + SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + Date date = new Date(time); + return format.format(date); + } + + /** + * this method will format long time value to given time zone with MM-dd-yyyy + * HH:mm:ss + * + * @param timeZone + * @param date + * @param incomingDateFormat + * @return String + */ + public static String dateFormatter(String timeZone, String date, String incomingDateFormat) { + SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + SimpleDateFormat incomingFormatter = new SimpleDateFormat(incomingDateFormat); + incomingFormatter.setTimeZone(TimeZone.getDefault()); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + String response = ""; + try { + Date defaultFormattedDate = incomingFormatter.parse(date); + response = format.format(defaultFormattedDate); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return response; + } // + + /** + * this method will format long time value to given time zone with MMMMM d + * EEEEEEEEE,hh:mm a + * + * @param timeZone + * @param date + * @param incomingDateFormat + * @return String + */ + public static String ormatterInMMMMdEEE(String timeZone, String date, String incomingDateFormat) { + SimpleDateFormat format = new SimpleDateFormat("EEEEEEEEE, MMMMM d @hh:mm a"); + SimpleDateFormat incomingFormatter = new SimpleDateFormat(incomingDateFormat); + incomingFormatter.setTimeZone(TimeZone.getDefault()); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + String response = ""; + try { + Date defaultFormattedDate = incomingFormatter.parse(date); + response = format.format(defaultFormattedDate); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return response; + } + + /** + * this method will format long time value to given time zone with MMMMM d + * EEEEEEEEE,hh:mm a + * + * @param timeZone + * @param time + * @return String + */ + public static String convertLongToStringAsMMMMEEEE(String timeZone, long time) { + SimpleDateFormat format = new SimpleDateFormat("EEEEEEEEE, MMMMM d @hh:mm a"); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + Date date = new Date(time); + return format.format(date); + } + + /** + * this method will format date object with time zone + * + * @param date + * date object + * @param timeZone + * String + * @return String + */ + public static String getSqlTimeStamp(Date date, String... timeZone) { + + DateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + if (timeZone != null && timeZone.length > 0) { + format.setTimeZone(TimeZone.getTimeZone(timeZone[0])); + } + return format.format(date); + } + + /** + * this method will convert long value to date object and provide formatted date + * object in "yyyy-MM-dd HH:mm:ss" this form + * + * @param time + * @return String + */ + public static String getSqlTimeStamp(Long time) { + return getSqlTimeStamp(new Date(time)); + } + + /** + * + * @param date + * @param timeZone + * @return Date + * @throws Exception + */ + public static Date getDateInDefaultTimeZone(String date, String timeZone) throws Exception { + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + SimpleDateFormat formatterWithDefaultTimeZone = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + Date reservationTimeWithTimeZone = format.parse(date + ":00"); + String reservationTimeWithDefaultTimeZone = formatterWithDefaultTimeZone.format(reservationTimeWithTimeZone); + return formatterWithDefaultTimeZone.parse(reservationTimeWithDefaultTimeZone); + } + + /** + * + * @return Date + * @throws Exception + */ + public static Date getCurrentDate() throws Exception { + SimpleDateFormat formatterWithDefaultTimeZone = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + Date currDate = new Date(); + String currTimeWithTimeZone = formatterWithDefaultTimeZone.format(currDate); + return formatterWithDefaultTimeZone.parse(currTimeWithTimeZone); + } + + /** + * This method will convert String date time with UTC time Zone in "yyyy-MM-dd + * HH:mm:ss" format + * + * @param date + * String + * @return Date jave.util Date object + */ + public static Date convertStringToDateWithTime(String date) { + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + format.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + Date afterFormat = null; + try { + afterFormat = format.parse(date); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return afterFormat; + } + + /** + * this method will provide current data in GMT. + * + * @return Date Object + */ + public static Date getCurrentDateInGmt() { + Calendar c = Calendar.getInstance(); + TimeZone z = c.getTimeZone(); + int offset = z.getRawOffset(); + if (z.inDaylightTime(new Date())) { + offset = offset + z.getDSTSavings(); + } + int offsetHrs = offset / 1000 / 60 / 60; + int offsetMints = offset / 1000 / 60 % 60; + c.add(Calendar.HOUR_OF_DAY, (-offsetHrs)); + c.add(Calendar.MINUTE, (-offsetMints)); + return c.getTime(); + } + + /** + * this method is used to take system current time and return time with time + * zone. + * + * @param date + * current date + * @param timezone + * time + * @return String + */ + public static String convertDateWithTimeZone(Date date, String timezone) { + SimpleDateFormat dateFormatGmt = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + dateFormatGmt.setTimeZone(TimeZone.getTimeZone(timezone)); + return dateFormatGmt.format(date); + + } + + /** + * this method will convert String to date object with system time zone. + * + * @param date + * String + * @return Date + */ + public static Date convertStringToDate(String date) { + SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + Date afterFormat = null; + try { + afterFormat = format.parse(date); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return afterFormat; + } + + /** + * this will format incoming date with MM/dd/yyyy + * + * @param date + * String + * @return String + */ + public static String formateWithMMddyyyy(String date) { + SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy"); + String formattedDate = ""; + try { + formattedDate = format.format(dateFormat.parse(date)); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + + return formattedDate; + } + + /** + * This method will return reservation time and current time difference in + * minutes. + * + * @param date + * String reservation time + * @return int + */ + public static int getDateDifferenceInMinutes(String date) { + int diffDate = 0; + SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); + dateFormat.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + try { + Date requestedDate = dateFormat.parse(date); + Date currentDate = new Date(); + currentDate = dateFormat.parse(dateFormat.format(currentDate)); + diffDate = (int) ((requestedDate.getTime() - currentDate.getTime()) / 60000); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return diffDate; + } + + /** + * This method will formate incoming String to time zone and format. + * + * @param date + * @param timZone + * @param format + * @return + */ + public static String formatStringToTimeZone(String date, String timZone, String format) { + SimpleDateFormat dateFormat = new SimpleDateFormat(format); + dateFormat.setTimeZone(TimeZone.getTimeZone(timZone)); + SimpleDateFormat dateFormat1 = new SimpleDateFormat(format); + dateFormat1.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + String formattedDate = date; + try { + Date parseDate = dateFormat.parse(date); + formattedDate = dateFormat1.format(parseDate); + formattedDate = dateFormat1.format(dateFormat1.parse(formattedDate)); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return formattedDate; + } + + /** + * This method will provide current date in UTC format in YYYY_MM_DD format. + * + * @return String + */ + public static String getYyyyMmDdInUTC() { + SimpleDateFormat format = new SimpleDateFormat(YYYYMMDD_FORMATTER); + format.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + return format.format(new Date()); + } + + /** + * this method will convert String to date object in UTC + * + * @param date + * String + * @return Date + */ + public static Date convertStringToDateUTC(String date) { + SimpleDateFormat format = new SimpleDateFormat(YYYYMMDD_FORMATTER); + format.setTimeZone(TimeZone.getTimeZone(Constants.TIME_ZONE)); + Date afterFormat = null; + try { + afterFormat = format.parse(date); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return afterFormat; + } + + public static String getTimeWithHHMMSSFormat() { + + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + return sdf.format(cal.getTime()); + + } + + public static Date convertPorjectUploadDate(String date) { + SimpleDateFormat format = new SimpleDateFormat(DATE_MONTH_YEAR_FORMAT); + Date formatDate = null; + try { + formatDate = format.parse(date); + } catch (ParseException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return formatDate; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/ExecutorManager.java b/src/main/java/org/upsmf/grievance/util/ExecutorManager.java new file mode 100644 index 0000000000000000000000000000000000000000..9050fc563926b1c5ac7893c0f73445d1f4474024 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ExecutorManager.java @@ -0,0 +1,32 @@ +package org.upsmf.grievance.util; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import lombok.NoArgsConstructor; + +/** + * This class will manage execute service thread. + * + * @author Manzarul.Haque + * + */ +@NoArgsConstructor +public class ExecutorManager { + /* + * service ScheduledExecutorService object + */ + private static ScheduledExecutorService service = null; + static { + service = Executors.newScheduledThreadPool(Constants.MAX_EXECUTOR_THREAD); + } + + /** + * This method will send executor service object. + * + * @return + */ + public static ScheduledExecutorService getExecutorService() { + return service; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/GMailAuthenticator.java b/src/main/java/org/upsmf/grievance/util/GMailAuthenticator.java new file mode 100644 index 0000000000000000000000000000000000000000..1bb989045e8f81aed0430fc345fc77ec4bc57a12 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/GMailAuthenticator.java @@ -0,0 +1,36 @@ +/** + * + */ +package org.upsmf.grievance.util; + +import javax.mail.Authenticator; +import javax.mail.PasswordAuthentication; + +/** + * @author Manzarul.Haque + * + */ +public class GMailAuthenticator extends Authenticator { + String user; + String pw; + + /** + * this method is used to authenticate gmail user name and password. + * + * @param username + * @param password + */ + public GMailAuthenticator(String username, String password) { + super(); + this.user = username; + this.pw = password; + } + + /** + * + */ + @Override + public PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(this.user, this.pw); + } +} diff --git a/src/main/java/org/upsmf/grievance/util/JSONObjectUtil.java b/src/main/java/org/upsmf/grievance/util/JSONObjectUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..d5e0be9a3abc84d3c8f698b6775ea2566bea2b1c --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/JSONObjectUtil.java @@ -0,0 +1,57 @@ +package org.upsmf.grievance.util; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; + +/** + * Created by Abhishek on 10/5/2017. + */ +@Service(value = "jsonObjectUtil") +public class JSONObjectUtil { + @Autowired + public ObjectMapper mapper; + @Autowired + public Gson gson; + + /** + * @return + */ + public static String getJsonString(ObjectMapper objectMapper, Object object) throws JsonProcessingException { + + if (objectMapper != null) { + return objectMapper.writeValueAsString(object); + } + return null; + } + + public String getJsonString(Object object) throws JsonProcessingException { + + if (mapper != null) { + return mapper.writeValueAsString(object); + } + if (gson != null) { + return gson.toJson(object); + } + return null; + } + + public ObjectMapper getMapper() { + return mapper; + } + + public void setObjectMapper(ObjectMapper objectMapper) { + mapper = objectMapper; + } + + public Gson getGson() { + return gson; + } + + public void setGson(Gson gsonn) { + gson = gsonn; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/JsonKey.java b/src/main/java/org/upsmf/grievance/util/JsonKey.java new file mode 100644 index 0000000000000000000000000000000000000000..ee88bd18b4ba8cb910624cfe8eb24876a53820ab --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/JsonKey.java @@ -0,0 +1,115 @@ +/** + * + */ +package org.upsmf.grievance.util; + +import lombok.NoArgsConstructor; + +/** + * @author Abhishek + * + */ +@NoArgsConstructor +public class JsonKey { + /* + * USER_NAME contains userName as key + */ + public static final String USER_ID = "userId"; + /* + * USER_NAME contains userName as key + */ + public static final String USER_NAME = "username"; + /* + * PASSWORD contains password + */ + public static final String PSWRD = "password"; + /* + * OLD_PASSWORD + */ + public static final String OLD_PSWRD = "oldPass"; + /* + * NEW_PASSWORD + */ + public static final String NEW_PSWRD = "newPass"; + /* + * DEVICE_TYPE user device type + */ + public static final String DEVICE_TYPE = "deviceType"; + /* + * DEVICE_ID user device id. + */ + public static final String DEVICE_ID = "deviceId"; + /* + * TIMEZONE + */ + public static final String TIMEZONE = "timeZone"; + /* + * SESSION + */ + public static final String SESSION = "sessionId"; + /* + * FIRST_NAME + */ + public static final String FIRST_NAME = "firstName"; + /* + * LAST_NAME + */ + public static final String LAST_NAME = "lastName"; + + public static final String URL = "url"; + + public static final String USERNAME = "username"; + + public static final String LINK = "link"; + + public static final String ROLE_IDS = "roleIds"; + + public static final String ROLENAME = "roleName"; + /* + * EMAIL + */ + public static final String EMAIL = "email"; + public static final String STATUS_CODE = "statusCode"; + public static final String STATUS = "statusInfo"; + public static final String STATUS_MESSAGE = "statusMessage"; + public static final String ERROR_MESSAGE = "errorMessage"; + /** + * RESPONSE. + */ + public static final String RESPONSE = "response"; + public static final String RESPONSE_DATA = "responseData"; + + /** + * IS_ACTIVE. + */ + public static final String IS_ACTIVE = "isActive"; + /** + * IS_DELETED. + */ + public static final String IS_DELETED = "isDeleted"; + + public static final String TIME = "time"; + + public static final String SUBSCRIPTION_NAME = "subscriptionName"; + + public static final String ASSET_TYPE = "assetType"; + public static final String ASSET_NAME = "assetName"; + public static final String FROM_USER = "fromUser"; + public static final String MAIL_SUBJECT = "mail_subject"; + public static final String MAIL_BODY = "mail_body"; + public static final String LOGO_URL = "logo_url"; + public static final String TYPE = "type"; + public static final String TICKET_ID = "ticketId"; + public static final String SEVERITY = "severity"; + public static final String CREATED_BY = "createdBy"; + public static final String OWNER = "owner"; + public static final String SUMMARY = "summary"; + public static final String ORGNAME = "CompName"; + public static final String HELPDESKNAME = "HelpdeskName"; + public static final String HELPDESK_NAME = "helpdeskName"; + public static final String OLDSTATUS = "oldStatus"; + public static final String UPDATE = "update"; + public static final String NEWSTATUS = "newStatus"; + public static final String ID = "id"; + public static final String HELPDESKID = "helpdeskId"; +} diff --git a/src/main/java/org/upsmf/grievance/util/OneWayHashing.java b/src/main/java/org/upsmf/grievance/util/OneWayHashing.java new file mode 100644 index 0000000000000000000000000000000000000000..4067c016eaa63fef1bbdad1a0b998b629ed5f033 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/OneWayHashing.java @@ -0,0 +1,40 @@ +package org.upsmf.grievance.util; + +import java.security.MessageDigest; + +import lombok.NoArgsConstructor; + +/** + * @author Juhi Agarwal This class will hash data only one way. once it + * encrypted you can't decrypt it. + */ +@NoArgsConstructor +public class OneWayHashing { + + /** + * This method will encrypt value using SHA-256 . it is one way encryption. + * + * @param val + * String + * @return String encrypted value or empty in case of exception + */ + + public static String encryptVal(String val) { + try { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + md.update(val.getBytes()); + byte[] byteData = md.digest(); + + StringBuilder sb = new StringBuilder(); + for (byte element : byteData) { + sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1)); + } + + + return sb.toString(); + } catch (Exception e) { + + } + return ""; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/PathRoutes.java b/src/main/java/org/upsmf/grievance/util/PathRoutes.java new file mode 100644 index 0000000000000000000000000000000000000000..98996bab72ec84b74ff4810e1cce0a13e4007f06 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/PathRoutes.java @@ -0,0 +1,158 @@ +package org.upsmf.grievance.util; + +/** + * + * @author Darshan Nagesh + * + */ + +public final class PathRoutes { + + public static final String USER_ACTIONS_URL = "/user"; + public static final String SUPERADMIN_ACTIONS_URL = "/superadmin"; + public static final String TICKET_ACTIONS_URL = "/tickets"; + public static final String ROLE_ACTIONS_URL = "/roles"; + public static final String HELPDESK_URL = "/helpdesk"; + public static final String APPS_ACTIONS_URL = "/apps"; + public static final String TAGS_URL = "/tags"; + + public final class UserRoutes { + private UserRoutes() { + super(); + } + + public static final String USER_ACTIONS_POST = "/getAllActions"; + public static final String EMPLOYMENT_TYPES_GET = "/getEmploymentTypes"; + public static final String NUMBER_OF_USERS_GET = "/getNumberOfUsers"; + public static final String NUMBER_OF_ROLES_GET = "/getNumberOfRoles"; + public static final String LIST_USER_GET = "/getAllUsers"; + public static final String USER_BY_ID_GET = "/getUser"; + public static final String CREATE_UPDATE_USER_POST = "/createOrUpdate"; + public static final String USER_ROLE_MAPPING_POST = "/mapUserToRole"; + public static final String SINGLE_FILE_UPLOAD_POST = "/upload"; + public static final String IMAGE_GET = "/images"; + public static final String LOGOUT_GET = "/logout"; + public static final String PUBLIC = "/public"; + public static final String CHANGE_PSWRD = "/changePassword"; + public static final String FORGOT_PSWRD = "/forgotPassword"; + public static final String LOGIN = "/login"; + public static final String GET_PROFILE_PICTURE = "/getProfilePicture"; + public static final String UPLOAD_PROFILE_PICTURE = "/uploadProfilePicture"; + public static final String GET_REVIEWS = "/getReviews"; + } + + public final class SuperAdminRoutes { + private SuperAdminRoutes() { + super(); + } + + public static final String GET_ALL_ORG = "/getAllOrg"; + public static final String UPDATE_ORG_BY_ID = "/updateOrgById"; + public static final String GET_ORG_BY_ID = "/getOrgById"; + public static final String DELETE_ORGANIZATION = "/deleteOrganization"; + public static final String ADD_ORGANIZATION = "/addOrganization"; + public static final String ADD_ADMIN = "/addAdmin"; + public static final String REMOVE_ADMIN = "/removeAdmin"; + public static final String MAP_APPS_TO_ORG = "/mapAppsToOrg"; + public static final String GET_AUTH_TYPES = "/getAuthTypes"; + } + + public final class RoleActionRoutes { + private RoleActionRoutes() { + super(); + + } + + public static final String LIST_ROLES_GET = "/getAllRoles"; + public static final String ADD_ROLE_POST = "/addRole"; + public static final String ROLE_BY_ID_GET = "/getRoleById"; + public static final String UPDATE_ROLE_POST = "/updateRole"; + public static final String MDM_CHECK = "/mdmCheck"; + } + + public final class AppsRoutes { + private AppsRoutes() { + super(); + + } + + public static final String CREATE_APP = "/addUpdateApp"; + public static final String GET_APP = "/getApp"; + public static final String GET_APP_BY_ORG_ID = "/getAppByOrgId"; + public static final String MAP_APP_TO_HELPDESK = "/mapAppToHelpdesk"; + public static final String GET_SERVICE_REQUEST = "/getServiceRequests"; + } + + public final class TagRoutes { + private TagRoutes() { + super(); + + } + + public static final String CREATE_TAG = "/addUpdateTag"; + public static final String GET_TAG = "/getTag"; + public static final String GET_ALL_TAGS = "/getAllTags"; + public static final String GET_TAG_BY_ORG_ID = "/getTagByOrgId"; + public static final String GET_TAG_BY_HELPDESK_ID = "/getTagByHelpdeskId"; + public static final String REMOVE_TAG = "/removeTag"; + public static final String ADD_TICKET_TAG = "/addTicketTag"; + public static final String GET_ALL_TICKET_TAGS = "/getAllTicketTags"; + public static final String DELETE_TICKET_TAG = "/deleteTicketTag"; + } + + public final class TicketRoutes { + + private TicketRoutes() { + super(); + + } + + public static final String ADD_TICKET = "/addTicket"; + public static final String GET_ALL_TICKETS_BY_ORG = "/getAllTicketsByOrg"; + public static final String UPDATE_TICKET_BASIC = "/updateTicketBasic"; + public static final String UPDATE_TICKET_TYPE = "/updateTicketType"; + public static final String UPDATE_TICKET_STATUS = "/updateTicketStatus"; + public static final String UPDATE_TICKET_CHECKLIST = "/updateTicketChecklist"; + public static final String GET_ALL_TICKETS = "/getAllTickets"; + public static final String GET_ALL_TICKETS_PER_USER = "/getAllTicketsPerUser"; + public static final String GET_ALL_TICKETS_ASSIGNED_TO_ME = "/getAllTicketsAssignedToMe"; + public static final String GET_ALL_TICKETS_TO_BE_APPROVED = "/getAllTicketsToBeApproved"; + public static final String GET_TICKET_DETAILS_PER_TICKET = "/getTicketDetailsPerTicket"; + public static final String GET_PRIORITY_LEVELS = "/getPriorityLevels"; + public static final String GET_TEMPLATES_VERSION = "/getTemplatesVersion"; + public static final String GET_TEMPLATES = "/getTemplates"; + public static final String GET_NO_OF_TICKETS = "/getNoOfTickets"; + public static final String CONFIGURE_TEMPLATE = "/configureTemplates"; + public static final String ADD_NOTES = "/addNotes"; + public static final String ADD_UPDATE_UPDATES = "/addUpdateUpdates"; + public static final String GET_UPDATES = "/getUpdates"; + public static final String GET_ACTIVITY_LOGS = "/getActivityLogs"; + public static final String GET_ACTIVITY_LOGS_PER_USER = "/getActivityLogsPerUser"; + public static final String PINNED_TICKET = "/pinTicket"; + public static final String GET_TICKET_COUNT_PER_MONTH_PER_USER = "/getTicketsCountPerMonthPerUser"; + public static final String GET_FEEDBACK_FROM_AURORA_SDK = "/getFeedbackFromAuroraSdk"; + public static final String UPLOAD_ATTACHMENT = "/uploadAttachment"; + public static final String SEND_REPLY_TO_REVIEWS = "/sendRepliesToReviews"; + + } + + public final class HelpdeskRoutes { + + private HelpdeskRoutes() { + super(); + + } + + public static final String CREATE_UPDATE_HELPDESK = "/createUpdateHelpdesk"; + public static final String GET_ORG_HELPDESK = "/getOrgHelpdesk"; + public static final String CREATE_UPDATE_HELPDESK_TYPE = "/createUpdateHelpdeskType"; + public static final String ADD_UPDATE_HELPDESK_ADMINS = "/addUpdateHelpdeskAdmins"; + public static final String GET_HELPDESK_ADMINS = "/getHelpdeskAdmins"; + public static final String GET_HELPDESK = "/getHelpdesk"; + public static final String CONFIGURE_HELPDESK = "/configureHelpdesk"; + + public static final String GET_PERFORMANCE_WITH_ACCESSCONTROL = "/getPerformanceWithAccessControl"; + public static final String GET_PERFORMANCE_WITHOUT_ACCESSCONTROL = "/getPerformanceWithoutAccessControl"; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/ProjectUtil.java b/src/main/java/org/upsmf/grievance/util/ProjectUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c96cde766946b7b26e647dc95b5b3197bd177d9b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ProjectUtil.java @@ -0,0 +1,451 @@ +/** + * + */ +package org.upsmf.grievance.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Random; +import java.util.regex.Pattern; + +import javax.mail.internet.InternetAddress; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; + +public class ProjectUtil { + /* + * projectUtil ProjectUtil instance + */ + public static final Logger LOGGER = LoggerFactory.getLogger(ProjectUtil.class); + private static ProjectUtil projectUtil = null; + private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + private static final Random random = new Random(); + private static final String ENCOUNTERED_AN_EXCEPTION = "Encountered an Exception : %s"; + + /** + * Default constructor + * + * @throws Exception + */ + private ProjectUtil() throws Exception { + if (projectUtil != null) { + throw new Exception(); + } + } + + static { + try { + projectUtil = getProjectUtilInstance(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + Pattern.compile(EMAIL_PATTERN); + } + + /** + * + * @return + * @throws Exception + * @throws RuntimeException + */ + public static synchronized ProjectUtil getProjectUtilInstance() throws Exception { + if (projectUtil == null) { + projectUtil = new ProjectUtil(); + } + return projectUtil; + } + + /** + * this method is used to print class name and line number + * + * @param object + * @return + */ + public String getClassNameAndLineNo(Object object) { + String message = ""; + message = " " + object.getClass().getName() + "********" + + Thread.currentThread().getStackTrace()[2].getLineNumber(); + return message; + } + + /** + * this method will generate some random password. which is dog name and is + * suggested by client. + * + * @return String password. + */ + public static String generatePassword() { + String[] passwords = new String[] { "" }; + + int index = random.nextInt(passwords.length); + + return passwords[index]; + } + + /** + * this method is used to add fare and tip amount + * + * @param fare + * fare amount + * @param tip + * tip amount + * @return result + */ + public static double addDoubles(String fare, String tip) { + double fareAmount = 0; + double tipAmount = 0; + if (fare != null && !"".equals(fare)) { + fareAmount = Double.parseDouble(fare.trim()); + } + if (tip != null && !"".equals(tip)) { + tipAmount = Double.parseDouble(tip); + } + return fareAmount + tipAmount; + } + + /** + * this method is used to subtract fare and tip amount + * + * @param fare + * fare amount + * @param tip + * tip amount + * @return result + */ + public static double substractDoubles(String fare, String tip) { + + double fareAmount = Double.parseDouble(fare); + double tipAmount = Double.parseDouble(tip); + boolean order = fareAmount - tipAmount > 0; + + String bigger = fareAmount - tipAmount > 0 ? fare : tip; + String smaller = fareAmount - tipAmount < 0 ? fare : tip; + + int bigDollars = bigger.contains(".") ? Integer.parseInt(bigger.split("\\.")[0]) : Integer.parseInt(bigger); + int smallDollars = smaller.contains(".") ? Integer.parseInt(smaller.split("\\.")[0]) + : Integer.parseInt(smaller); + + int bigCents = bigger.contains(".") ? Integer.parseInt(bigger.split("\\.")[1]) : 0; + int smallCents = smaller.contains(".") ? Integer.parseInt(smaller.split("\\.")[1]) : 0; + if (smallCents < 10 && smallCents != 0) { + smallCents = smallCents * 10; + } + int totalCents = bigCents - smallCents; + int extraDollar = 0; + int cents = totalCents; + + if (totalCents < 0) { + extraDollar = -1; + cents = 100 + bigCents - smallCents; + } + int dollars = bigDollars - smallDollars + extraDollar; + if (!order) { + dollars = dollars * -1; + } + + String totalAmount = dollars + "." + cents; + if (cents < 10) { + totalAmount = dollars + ".0" + cents; + } + return Double.parseDouble(totalAmount); + } + + /** + * this method is used to generate user session id. + * + * @param email + * user email id. + * @param roleId + * user role id. + * @param source + * String + * @return String session id value. + */ + public static String getUniqueId(String email, long roleId, String source) { + email = email.replace('.', 'D'); + email = email.replace('@', 'L'); + email = email.replace("com", "se"); + email = email.replace("in", "xp"); + StringBuilder builder = new StringBuilder(); + String str = System.currentTimeMillis() + random.nextInt() + ""; + byte[] data = { '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '4', 'i', 'j', 'k', '5', 'l', 'm', 'n', 'o', 'p', + 'q', '6', 'A', 'B', 'C', 'D', '9', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', '8', 'M', 'N', 'O', 'P', 'Q', + 'R', '7', 'S', 'T', 't', 'u', 'U', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '1', '2', '3' }; + String value = random.nextInt() + ""; + builder.append(value.substring(1, value.length() / 2)); + builder.append(email.substring(3, email.length() / 2)); + builder.append(str.substring(str.length() - 2) + "" + str.substring(0, str.length() - 2)); + builder.append(email.substring(email.length() - 4)); + for (int i = 0; i < 4; i++) { + builder.append(random.nextInt(data.length)); + } + builder.append("#" + source + "#" + roleId * random.nextInt(random.nextInt(data.length))); + return builder.toString(); + } + + /** + * This method will check incoming request data contains that key or not. + * + * @param requestData + * requested data. + * @param key + * String + * @return true/false + */ + public static boolean isKeyFound(JsonNode requestData, String key) { + return (requestData.has(key)); + } + + public static String formatPhoneNumber(String phone) { + String phoneNumber = phone; + StringBuilder builder = new StringBuilder(phone); + if (phone != null && phone.trim().length() == 10) { + phoneNumber = "(" + builder.substring(0, 3) + ") " + builder.substring(3, 6) + "-" + builder.substring(6); + } + return phoneNumber; + } + + /** + * This method will remove user phone number format from (xxx) xxx-xxxx to + * xxxxxxxxxx format. + * + * @param phone + * String + * @return String + */ + public static String removePhoneNumberFormat(String phone) { + if (phone != null && phone.trim().length() > 10) { + phone = phone.replace("(", "").replace(") ", "").trim().replace("-", ""); + } + return (phone != null) ? phone.trim() : ""; + + } + + /** + * This method will check user phone number it should not empty , null and + * length should be 10 digits and it should contain all numeric value. + * + * @param phoneNumber + * @return + */ + public static boolean isPhoneNumbervalid(String phoneNumber) { + boolean response = true; + if (phoneNumber == null || "".equals(phoneNumber) || phoneNumber.trim().length() < 10 + || "0000000000".equals(phoneNumber.trim())) { + response = false; + } else { + try { + Long.parseLong(phoneNumber.trim()); + } catch (Exception e) { + response = false; + } + } + return response; + } + + /** + * This method will check provided string is null or empty if string is null or + * empty then it will provide true other wise false. + * + * @param value + * String + * @return boolean + */ + public static boolean isStringNullOrEmpty(String value) { + return (value == null || "".equals(value.trim()) || "null".equals(value.trim())); + } + + public static boolean isEmailValid(String email) { + boolean response = false; + if (ProjectUtil.isStringNullOrEmpty(email)) { + return response; + } + String[] emails = email.split("@"); + try { + String[] splitedVal = emails[1].split("[.]"); + if ("gmail".equalsIgnoreCase(splitedVal[0]) || "yahoo".equalsIgnoreCase(splitedVal[0]) + || "rediffmail".equalsIgnoreCase(splitedVal[0]) || "hotmail".equalsIgnoreCase(splitedVal[0]) + || "AOL".equalsIgnoreCase(splitedVal[0])) { + if ("com".equalsIgnoreCase(splitedVal[1])) { + response = true; + } + } else { + response = true; + } + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return response; + } + + /** + * This method will calculate percentage(4.75) of provided amount. + * + * @param amount + * double + * @param charge + * doubel + * @return double + */ + public static double calculatePercentage(double amount, double charge) { + return ((amount * charge) / 100); + } + + /** + * This method will crate sub string of provided String based on count. + * + * @param val + * String + * @param count + * int + * @return String + */ + public static String cutOffStringSize(String val, int count) { + if (val == null) { + return val; + } + val = val.trim(); + if (val.length() > count) { + val = val.substring(0, count); + val = val + "..."; + } + return val; + } + + public static String getRandomStringVal() { + String ALPHA_NUMERIC_STRING = "abcdefghijklmnopqrstuvwxyz0123456789"; + StringBuilder builder = new StringBuilder(); + for (int i = 0; i <= 8; i++) { + int character = (int) (Math.random() * ALPHA_NUMERIC_STRING.length()); + builder.append(ALPHA_NUMERIC_STRING.charAt(character)); + } + return builder.toString(); + + } + + /** + * This method will return random int value. + * + * @param lower + * int + * @param upper + * int + * @return int + */ + private static int getRandom(int lower, int upper) { + return (random.nextInt() * (upper - lower)) + lower; + } + + /** + * This method receives the minutes and converts it into hours in 00H:00M format + * + * @param minutes + * @return String + */ + public static String convertMinutesToHours(long minutes) { + String startTime = "00:00"; + long h = minutes / 60 + Integer.parseInt(startTime.substring(0, 1)); + long m = minutes % 60 + Integer.parseInt(startTime.substring(3, 4)); + return h + "H:" + m + "M"; + } + + public static String[] getStartAndEndDatForMonth(String date) { + String startDate = date + "-01"; + String[] ymd = startDate.split("-"); + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.DATE, 1); + cal.set(Calendar.MONTH, Integer.parseInt(ymd[1])); + cal.set(Calendar.YEAR, Integer.parseInt(ymd[0])); + cal.set(Calendar.DATE, cal.get(Calendar.DATE) - 1); + String endDate = date + "-" + cal.get(Calendar.DATE); + String[] dates = new String[2]; + dates[0] = startDate; + dates[1] = endDate; + return dates; + + } + + public static int[] getMonthAndYearFromDate(String dateString) { + int[] calender = new int[2]; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); + try { + Date date = formatter.parse(dateString); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + calender[0] = month + 1; + calender[1] = year; + + } catch (ParseException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return calender; + } + + public static Date getFullDate(String dateString) { + Date date = null; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + try { + date = formatter.parse(dateString); + } catch (ParseException e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + return date; + } + + /** + * This method gets the complete file name + * + * @param fileName + * @return + */ + + public static String getAppendedDocumentName(String fileName) { + long timestamp = System.currentTimeMillis(); + String[] splitFileName = fileName.split("\\."); + String fileExtenstion = splitFileName[(splitFileName.length) - 1]; + splitFileName[splitFileName.length - 1] = ""; + StringBuilder builder = new StringBuilder(); + for (String stringPart : splitFileName) { + builder.append(stringPart); + } + return builder.toString() + "_" + Long.toString(timestamp) + "." + fileExtenstion; + + } + + public static boolean validateEmail(String email) { + boolean result = true; + try { + InternetAddress emailAddr = new InternetAddress(email); + emailAddr.validate(); + } catch (Exception ex) { + result = false; + } + return result; + } + + public static boolean validateDateFormat(String date) { + try { + return (date.matches("((?:19|20)\\d\\d)-(0?[1-9]|1[012])-([12][0-9]|3[01]|0?[1-9])")); + } catch (Exception ex) { + return false; + } + } + + public static boolean isObjectListNullOrEmpty(List<? extends Object> objectList) { + return (objectList == null) || (objectList.isEmpty()); + } + + public static boolean isObjectNull(Object object) { + return (object == null); + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/ResponseCode.java b/src/main/java/org/upsmf/grievance/util/ResponseCode.java new file mode 100644 index 0000000000000000000000000000000000000000..bcd7b40420e13deccb6f8b71b63946aec6d32fe9 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ResponseCode.java @@ -0,0 +1,84 @@ +package org.upsmf.grievance.util; + +/** + * + * @author Abhishek + * + */ +public enum ResponseCode { + UNAUTHORIZED(Constants.UNAUTHORIZED_ID, Constants.UNAUTHORIZED), SUCCESS(Constants.SUCCESS_ID, + Constants.SUCCESS), FAILURE(Constants.FAILURE_ID, Constants.PROCESS_FAIL); + private static final String STRING = ""; + /** + * error code contains int value + */ + private int errorCode; + /** + * errorMessage contains proper error message. + */ + private String errorMessage; + + /** + * @param errorCode + * @param errorMessage + */ + private ResponseCode(int errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + /** + * + * @param errorCode + * @return + */ + public String getMessage(int errorCode) { + this.errorCode = errorCode; + return STRING; + } + + /** + * @return + */ + public int getErrorCode() { + return errorCode; + } + + /** + * @param errorCode + */ + void setErrorCode(int errorCode) { + this.errorCode = errorCode; + } + + /** + * @return + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * @param errorMessage + */ + void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + /** + * This method will provide status message based on code + * + * @param code + * @return String + */ + public static String getResponseMessage(int code) { + String value = STRING; + ResponseCode[] responseCodes = ResponseCode.values(); + for (ResponseCode actionState : responseCodes) { + if (actionState.getErrorCode() == code) { + value = actionState.getErrorMessage(); + } + } + return value; + } +} diff --git a/src/main/java/org/upsmf/grievance/util/ResponseGenerator.java b/src/main/java/org/upsmf/grievance/util/ResponseGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..dabe0766f02a17b9b176b2b12bd11d227f195c2c --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ResponseGenerator.java @@ -0,0 +1,73 @@ +package org.upsmf.grievance.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import lombok.NoArgsConstructor; +@NoArgsConstructor +public class ResponseGenerator { + + private static ObjectMapper objectMapper = new ObjectMapper(); + + public static String failureResponse() throws JsonProcessingException { + ObjectNode actualResponse = objectMapper.createObjectNode(); + ObjectNode response = objectMapper.createObjectNode(); + response.put(JsonKey.STATUS_CODE, ResponseCode.FAILURE.getErrorCode()); + response.put(JsonKey.STATUS_MESSAGE, ResponseCode.FAILURE.getErrorMessage()); + response.put(JsonKey.ERROR_MESSAGE, ResponseCode.FAILURE.getErrorMessage()); + actualResponse.putPOJO(JsonKey.STATUS, response); + return JSONObjectUtil.getJsonString(objectMapper, actualResponse); + } + + public static String failureResponse(String message) throws JsonProcessingException { + ObjectNode actualResponse = objectMapper.createObjectNode(); + + ObjectNode response = objectMapper.createObjectNode(); + response.put(JsonKey.STATUS_CODE, ResponseCode.FAILURE.getErrorCode()); + response.put(JsonKey.STATUS_MESSAGE, ResponseCode.FAILURE.getErrorMessage()); + response.put(JsonKey.ERROR_MESSAGE, message); + actualResponse.putPOJO(JsonKey.STATUS, response); + + return JSONObjectUtil.getJsonString(objectMapper, actualResponse); + } + + /** + * this method will crate success response and send to controller. + * + * @param obj + * Object + * @return ObjectNode object. + */ + public static String successResponse(Object obj) throws JsonProcessingException { + ObjectNode actualResponse = objectMapper.createObjectNode(); + + ObjectNode response = objectMapper.createObjectNode(); + response.put(JsonKey.STATUS_CODE, ResponseCode.SUCCESS.getErrorCode()); + response.put(JsonKey.STATUS_MESSAGE, ResponseCode.SUCCESS.getErrorMessage()); + response.put(JsonKey.ERROR_MESSAGE, ""); + actualResponse.putPOJO(JsonKey.STATUS, response); + if (obj != null) { + actualResponse.putPOJO(JsonKey.RESPONSE_DATA, obj); + } + + return JSONObjectUtil.getJsonString(objectMapper, actualResponse); + } + + /** + * this method will crate success response and send to controller. + * + * @return ObjectNode object. + */ + public static String successResponse() throws JsonProcessingException { + ObjectNode actualResponse = objectMapper.createObjectNode(); + + ObjectNode response = objectMapper.createObjectNode(); + response.put(JsonKey.STATUS_CODE, ResponseCode.SUCCESS.getErrorCode()); + response.put(JsonKey.STATUS_MESSAGE, ResponseCode.SUCCESS.getErrorMessage()); + response.put(JsonKey.ERROR_MESSAGE, ""); + actualResponse.putPOJO(JsonKey.STATUS, response); + + return JSONObjectUtil.getJsonString(objectMapper, actualResponse); + } +} diff --git a/src/main/java/org/upsmf/grievance/util/ResponseMessages.java b/src/main/java/org/upsmf/grievance/util/ResponseMessages.java new file mode 100644 index 0000000000000000000000000000000000000000..16099d09797fe69a4f2a57a2543128aa0bbf5ed3 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ResponseMessages.java @@ -0,0 +1,58 @@ +package org.upsmf.grievance.util; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class ResponseMessages { + + public static final String UNAVAILABLE = "UNAVAILABLE"; + public static final String INVALID = "INVALID"; + public static final String ALREADY_EXISITS = "ALREADYEXISTS"; + public static final String INTERNAL_ERROR = "INTERNALERROR"; + + public class ErrorMessages { + final Integer CUSTOM_ERROR_ID = 9999; + public static final String ROLE_NAME_UNAVAILABLE = "Role Name is mandatory. Please add and try again"; + public static final String ROLE_ID_UNAVAILABLE = "Role ID is mandatory. Please add and try again"; + public static final String ROLE_DETAILS_UNAVAILABLE = "Role Details are not available. Please check"; + public static final String ROLE_DETAILS_NOTSAVED = "Unable to save the Role Details. Please try again later"; + public static final String USER_ROLE_MAPPING_NOTSAVED = "Unable to save the User Role mapping"; + public static final String USER_ID_UNAVAILABLE = "User ID is mandatory. Please add and try again"; + public static final String ROLE_ID_INVALID = "Role ID cannot be Zero. Please check and try again!"; + public static final String FEATURE_NAME_UNAVAILABLE = "Feature Name is mandatory. Please add and try again"; + public static final String FEATURE_CODE_UNAVAILABLE = "Feature Code is mandatory. Please add and try again"; + public static final String FEATURE_URL_UNAVAILABLE = "Feature URL is mandatory. Please add and try again"; + public static final String FEATURE_DETAILS_UNAVAILABLE = "Feature Details are not available. Please check"; + public static final String FEATURE_DETAILS_NOTSAVED = "Unable to save the Feature Details. Please try again later"; + public static final String USER_PROFILE_UNAVAILABLE = "User Profile Details are not found. Please check"; + public static final String USER_NAME_ALREADY_EXISTS = "UserName already exists. Please try with a different input"; + public static final String USER_PROFILE_ID_MANDATORY = "User Profile ID is mandatory. Please check"; + public static final String USER_PROFILE_SAVE_FAILURE = "Could not save the User Profile. Please check"; + public static final String EMAIL_PHONE_ALREADY_EXISTS = "This email or phone number already exists. Please reenter and check "; + public static final String EMAIL_MANDATORY = "Email Address is mandatory. Please enter and try again"; + public static final String LOGOUT_FAILED = "User Log Out action has failed. Please try again"; + public static final String GETALLORG_FAILED = "Couldn't fetch all the organization. Please try again later"; + public static final String UPDATE_ORG_FAILED = "Couldn't update the organization. Please check"; + public static final String GET_ORG_BY_ID_FAILED = "Couldn't fetch this organization. Please try again later"; + public static final String ADD_ORG_FAILED = "Couldn't create new organization. Please try with a different email address"; + public static final String DELETE_ORG_FAILED = "Couldn't delete this organization. Please check."; + public static final String ADDTICKET_FAILED = "Couldn't create this Ticket. Please check."; + public static final String GETALLTICKET_FAILED = "Could't fetch the tickets. Please try again later"; + public static final String UPDATETICKET_FAILED = "Couldn't update this ticket at the moment. Please check"; + public static final String GETTICKETDETAILS_FAILED = "Couldn't fetch ticket details. Please try again later"; + public static final String LOGIN_FAILED = "We couldn't log you in. Please try again later with right credentials"; + public static final String FORGOT_PSWRD_FAILED = "Something went wrong. Please enter your correct username"; + public static final String CHANGE_PSWRD_FAILED = "Couldn't change your password. Please try again with the correct passwords"; + public static final String INVALID_ACCESS_ROLE = "Role does not have access to this URL"; + public static final String UNAUTHORIZED_ACCESS = "Unauthorized Access. Please login again and try!!"; + } + + public class SuccessMessages { + public static final String ROLE_CREATED = "Role has been added successfully!"; + public static final String ROLE_UPDATED = "Role has been updated successfully!"; + public static final String USER_ROLE_MAPPED = "User has been mapped to Role"; + public static final String ACTION_ADDED = "Feature has been added successfully!"; + public static final String LOGOUT_SUCCESS = "User Logged out successfully"; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/ResponseUtil.java b/src/main/java/org/upsmf/grievance/util/ResponseUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..fc6da31b7d2762b68717e9888877024ef0c82bc5 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/ResponseUtil.java @@ -0,0 +1,95 @@ +package org.upsmf.grievance.util; + +import java.io.IOException; + +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; + +import org.apache.cxf.jaxrs.ext.MessageContext; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import lombok.NoArgsConstructor; +@NoArgsConstructor +public class ResponseUtil { + + /** + * Method to throw bad request with error message + * + * @param errorDescription + */ + public static void sendBadRequest(String errorDescription) { + ResponseBuilder resp = Response.status(Response.Status.BAD_REQUEST); + resp.entity(errorDescription); + throw new WebApplicationException(resp.build()); + } + + /** + * Method to throw Unauthorized request with error message + * + * @param errorDescription + */ + public static Response sendUnauthorized(String errorDescription) throws JsonProcessingException { + ResponseBuilder resp = Response.status(Response.Status.UNAUTHORIZED); + resp.entity(ResponseGenerator.failureResponse(errorDescription)); + return resp.build(); + } + + /** + * Method to throw Internal server error + * + * @param errorDescription + */ + public static Response sendServerError(String errorDescription) { + ResponseBuilder resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR); + resp.entity(errorDescription); + return resp.build(); + } + + /** + * Method to throw Unauthorized request with error message + * + * @param errorDescription + */ + public static void unauthorizedResponse(HttpServletResponse response, String errorDescription) throws IOException { + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + response.setContentType("application/json"); + response.getWriter().write(errorDescription); + } + + public static Response sendOK(ObjectNode obj) { + ResponseBuilder resp = Response.status(Response.Status.OK); + resp.entity(obj); + return resp.build(); + } + + public static Response sendOK(String obj) { + ResponseBuilder resp = Response.status(Response.Status.OK); + resp.entity(obj); + return resp.build(); + } + + public static void sendRedirect(MessageContext context, String path) { + try { + HttpServletResponse response = context.getHttpServletResponse(); + response.sendRedirect(path); + } catch (Exception e) { + sendServerError("Unable to redirect"); + } + } + + public static void sendInternalError(String errorDescription) throws JsonProcessingException { + ResponseBuilder resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR); + resp.entity(ResponseGenerator.failureResponse(errorDescription)); + throw new WebApplicationException(resp.build()); + } + + public static void sendInternalError() throws JsonProcessingException { + ResponseBuilder resp = Response.status(Response.Status.INTERNAL_SERVER_ERROR); + resp.entity(ResponseGenerator.failureResponse()); + throw new WebApplicationException(resp.build()); + } +} diff --git a/src/main/java/org/upsmf/grievance/util/S3FileManager.java b/src/main/java/org/upsmf/grievance/util/S3FileManager.java new file mode 100644 index 0000000000000000000000000000000000000000..2ff07418321ec799b53bb9336f66bf915de95596 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/S3FileManager.java @@ -0,0 +1,77 @@ +package org.upsmf.grievance.util; + +import java.net.URL; +import java.util.Calendar; +import java.util.TimeZone; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.amazonaws.HttpMethod; +import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AWSCredentialsProviderChain; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; +import org.upsmf.grievance.dao.impl.SuperAdminDaoImpl; +import org.upsmf.grievance.model.S3Config; + +public class S3FileManager { + + private S3FileManager() { + super(); + } + + public static final Logger LOGGER = LoggerFactory.getLogger(SuperAdminDaoImpl.class); + + /** + * This method will remove particular file form given bucket name. + * + * @param fileName + * String + * @param bucketLocation + * String + * @return boolean + */ + + private static AmazonS3 getS3(S3Config s3Config) { + AWSCredentialsProvider provider = new AWSCredentialsProviderChain(new AWSStaticCredentialsProvider( + new BasicAWSCredentials(s3Config.getAccessKey(), s3Config.getSecretKey()))); + return AmazonS3ClientBuilder.standard().withRegion(Regions.fromName("ap-south-1")).withCredentials(provider) + .enablePathStyleAccess().build(); + } + + public static String filePath(String fileName, String folder, Long userId, Long compId) { + String key = null; + key = compId + "/" + folder + "/" + userId + "/" + fileName; + return key; + + } + + public static String attachementfilePath(String fileName, String folder, Long ticketId, Long compId) { + String key = null; + key = compId + "/" + folder + "/" + ticketId + "/" + fileName; + return key; + + } + + public static String getPreSignedURL(S3Config s3values, String path) { + try { + GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(s3values.getBucketName(), path, + HttpMethod.GET); + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta")); + cal.add(Calendar.HOUR, 100); + request.withExpiration(cal.getTime()); + URL url = getS3(s3values).generatePresignedUrl(request); + return url.toString(); + } catch (Exception e) { + LOGGER.error(String.format("S3 url for download Error %s", e.getMessage())); + } + return null; + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/SendMail.java b/src/main/java/org/upsmf/grievance/util/SendMail.java new file mode 100644 index 0000000000000000000000000000000000000000..c21fde29a3402e74db49ac3d498844df85f84e75 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/SendMail.java @@ -0,0 +1,209 @@ +package org.upsmf.grievance.util; + +import java.io.StringWriter; +import java.util.Map; +import java.util.Properties; + +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.mail.BodyPart; +import javax.mail.Message; +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 org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; + +import lombok.NoArgsConstructor; + +/** + * this api is used to sending mail. + * + * @author Manzarul.Haque + * + */ +@NoArgsConstructor +public class SendMail { + private static final String ENCOUNTERED_AN_EXCEPTION = "Encountered an Exception : %s"; + private static final String TEXT_HTML = "text/html"; + private static final String EMAILS = "/emails/"; + public static final Logger LOGGER = LoggerFactory.getLogger(SendMail.class); + private static final String CLASSNAME = SendMail.class.getName(); + private static Properties props = null; + static { + props = System.getProperties(); + props.put("mail.smtp.host", Constants.SMTP.HOST); + props.put("mail.smtp.socketFactory.port", Constants.SMTP.PORT); + props.put("mail.smtp.auth", Constants.SMTP.SSL); + props.put("mail.smtp.port", Constants.SMTP.PORT); + } + + /** + * this method is used to send email. + * + * @param receipent + * email to whom we send mail + * @param context + * VelocityContext + * @param templateName + * String + * @param subject + * subject + */ + @Async + public static void sendMail(String[] receipent, String subject, VelocityContext context, String templateName) { + try { + Session session = Session.getInstance(props, new GMailAuthenticator(Constants.USER, Constants.PSWRD)); + MimeMessage message = new MimeMessage(session); + message.setFrom(new InternetAddress(Constants.FROM, Constants.ALIAS)); + int size = receipent.length; + int i = 0; + while (size > 0) { + message.addRecipient(Message.RecipientType.TO, new InternetAddress(receipent[i])); + i++; + size--; + } + message.setSubject(subject); + VelocityEngine engine = new VelocityEngine(); + engine.init(); + String templatePath = EMAILS; + Template template = engine.getTemplate(templatePath + templateName); + StringWriter writer = new StringWriter(); + template.merge(context, writer); + message.setContent(writer.toString(), TEXT_HTML); + Transport transport = session.getTransport("smtp"); + transport.connect(Constants.HOST, Constants.USER, Constants.PSWRD); + transport.sendMessage(message, message.getAllRecipients()); + transport.close(); + } catch (Exception e) { + LOGGER.error(e.toString(), CLASSNAME); + } + } + + /** + * this method is used to send email along with CC Recipients list. + * + * @param receipent + * email to whom we send mail + * @param context + * VelocityContext + * @param templateName + * String + * @param subject + * subject + * @param ccList + * String + */ + @Async + public static void sendMail(String[] receipent, String subject, VelocityContext context, String templateName, + String[] ccList) { + try { + Session session = Session.getInstance(props, new GMailAuthenticator(Constants.USER, Constants.PSWRD)); + MimeMessage message = new MimeMessage(session); + message.setFrom(new InternetAddress(Constants.FROM, Constants.ALIAS)); + int size = receipent.length; + int i = 0; + while (size > 0) { + message.addRecipient(Message.RecipientType.TO, new InternetAddress(receipent[i])); + i++; + size--; + } + size = ccList.length; + i = 0; + while (size > 0) { + message.addRecipient(Message.RecipientType.CC, new InternetAddress(ccList[i])); + i++; + size--; + } + message.setSubject(subject); + VelocityEngine engine = new VelocityEngine(); + engine.init(); + String templatePath = EMAILS; + Template template = engine.getTemplate(templatePath + templateName); + StringWriter writer = new StringWriter(); + template.merge(context, writer); + message.setContent(writer.toString(), TEXT_HTML); + Transport transport = session.getTransport("smtp"); + transport.connect(Constants.HOST, Constants.USER, Constants.PSWRD); + transport.sendMessage(message, message.getAllRecipients()); + transport.close(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + /** + * this method is used to send email as an attachment. + * + * @param receipent + * email to whom we send mail + * @param mail + * mail body. + * @param subject + * subject + * @param filePath + * String + */ + @Async + public static void sendAttachment(String[] receipent, String mail, String subject, String filePath) { + try { + Session session = Session.getInstance(props, + new GMailAuthenticator(Constants.SMTP.USER, Constants.SMTP.PSWRD)); + MimeMessage message = new MimeMessage(session); + message.setFrom(new InternetAddress(Constants.SMTP.USER, Constants.SMTP.ALIAS)); + int size = receipent.length; + int i = 0; + while (size > 0) { + message.addRecipient(Message.RecipientType.TO, new InternetAddress(receipent[i])); + i++; + size--; + } + message.setSubject(subject); + BodyPart messageBodyPart = new MimeBodyPart(); + messageBodyPart.setContent(mail, TEXT_HTML); + + Multipart multipart = new MimeMultipart(); + multipart.addBodyPart(messageBodyPart); + DataSource source = new FileDataSource(filePath); + messageBodyPart = new MimeBodyPart(); + messageBodyPart.setDataHandler(new DataHandler(source)); + messageBodyPart.setFileName(filePath); + multipart.addBodyPart(messageBodyPart); + message.setSubject(subject); + message.setContent(multipart); + Transport transport = session.getTransport("smtp"); + transport.connect(Constants.SMTP.HOST, Constants.SMTP.USER, Constants.SMTP.PSWRD); + transport.sendMessage(message, message.getAllRecipients()); + transport.close(); + } catch (Exception e) { + LOGGER.error(String.format(ENCOUNTERED_AN_EXCEPTION, e.getMessage())); + } + } + + public static void sendMail(final Map<String, String> keyValue, final String[] emails, final String subject, + final String vmFileName) { + ExecutorManager.getExecutorService().execute(new Runnable() { + @Override + public void run() { + VelocityContext context = new VelocityContext(); + for (Map.Entry<String, String> entry : keyValue.entrySet()) { + context.put(entry.getKey(), entry.getValue()); + } + + context.put(JsonKey.LOGO_URL, Constants.LOGO_URL); + sendMail(emails, subject, context, vmFileName); + } + + }); + } +} diff --git a/src/main/java/org/upsmf/grievance/util/Sql.java b/src/main/java/org/upsmf/grievance/util/Sql.java new file mode 100644 index 0000000000000000000000000000000000000000..ef71237ea762961f833be94170a825334d19c719 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/Sql.java @@ -0,0 +1,401 @@ +package org.upsmf.grievance.util; + +/** + * This interface will hold all the SQL Queries which are being used by the + * application Internally, the inner interface will have the queries separated + * based on the functionalities that they are associated with + * + * @author Darshan Nagesh + * + */ +public final class Sql { + + public static final String ID = "id"; + + /** + * All the queries associated with the Common activities or transactions will be + * placed here + * + * @author Darshan Nagesh + * + */ + public final class Common { + private Common() { + super(); + + } + + public static final String VERIFY_PSWRD = "SELECT id FROM user WHERE password = ? AND name = ? "; + public static final String WHERE_CLAUSE = " WHERE "; + public static final String AND_CONDITION = " AND "; + public static final String OR_CONDITION = " OR "; + public static final String OPEN_BRACE = "("; + public static final String CLOSE_BRACE = ")"; + public static final String CHECK_EMAIL_IN_USE = "SELECT id FROM user WHERE username=? AND is_active IS TRUE"; + public static final String CHECK_OLD_PSWRD = "SELECT pwd FROM password WHERE user_id=?"; + public static final String UPDATE_PSWRD = "UPDATE password SET pwd=?,updated_date=? WHERE user_id=? and pwd=?"; + public static final String CHECK_USER_BY_USERNAME = "SELECT id from user where username=?"; + public static final String SAVE_FORGOT_PSWRD = "UPDATE password SET pwd=? , updated_date=? WHERE user_id= ? "; + public static final String GET_USER_DETAIL_BY_EMAIL = "Select id, name, username, phone, is_active as isActive, created_date as createdDate, updated_date as updatedDate, img_path as imagePath from user where username=?"; + public static final String GET_ORG_ID_BY_USER_ID = "SELECT org_id FROM user JOIN user_org where user.id=user_org.user_id and user.id=?"; + public static final String GET_ALL_USERS_BY_ORG = "Select user.id, name, username, phone, is_active, img_path, created_date, updated_date from user JOIN user_org where user.id=user_org.user_id and user.is_active is true and user_org.org_id=?"; + public static final String GET_IMAGE_PATH = "SELECT img_path from user where id=?;"; + public static final String ORGADMIN = "ORGADMIN"; + public static final String ENDUSER = "ENDUSER"; + public static final String SUPER_ADMIN = "SUPERADMIN"; + } + + public final class Tags { + private Tags() { + super(); + + } + + public static final String SAVE_TICKET_TAG = "INSERT INTO tag_ticket(ticket_id,tag_id) values(?,?)"; + public static final String GET_ALL_TAGS = "SELECT id as id, tag_name as name, created_by as createdBy FROM tag"; + public static final String GET_ALL_TAG_BY_ORGANISATION = "select t.id as id, t.tag_name as name from tag t where t.org_id = ?"; + public static final String GET_ALL_TAG_BY_HELPDESK = "SELECT distinct t.id as id, t.tag_name as name FROM tag t, tag_ticket tt where tt.ticket_id in (select ticket_id from ticket,helpdesk_ticket where helpdesk_id=? and ticket.id=ticket_id and active is true) and t.id=tt.tag_id order by id;"; + public static final String GET_TAG_BY_NAME = "SELECT t.id as id, t.tag_name as name FROM tag t where t.tag_name = ? and t.org_id = (select org_id from user_org where user_id = ?)"; + public static final String TAG_ID = "id"; + public static final String SAVE_TAG = "INSERT INTO tag(tag_name, created_by, org_id) values(?, ?, ?)"; + public static final String REMOVE_TAG = "DELETE FROM tag_ticket WHERE ticket_id=? AND tag_id=?"; + public static final String DELETE_TICKET_TAGS = "DELETE FROM tag_ticket WHERE ticket_id=?"; + public static final String GET_ALL_TICKET_TAGS = "select t.id as id, t.tag_name as name, created_by as createdBy from tag t, tag_ticket tt where tt.tag_id=t.id and tt.ticket_id=? "; + + } + + public static final String SAVE_LINK_TAG = "INSERT INTO tt_tag_link(link_id,tag_id) values(?,?)"; + + public final class Organization { + private Organization() { + super(); + + } + + public static final String GET_ALL_ORG = "SELECT id, org_name as orgName, url as url, logo as logo, domain as emailDomain, color as orgColor, " + + " created_by as createdBy, created_date as createdDate, is_active as isActive, description as orgDescription FROM organization where is_active is TRUE"; + public static final String GET_ORG_BY_NAME = "SELECT id FROM organization where org_name=? and is_active=1"; + public static final String GET_ORG_BY_ID = "select id, org_name as orgName, url as url, logo as logo, domain as emailDomain, color as orgColor, created_by as createdBy, created_date as createdDate, is_active as isActive, description as orgDescription FROM organization where id = ? and is_active is true"; + public static final String AND_CONDITION = " AND "; + public static final String OR_CONDITION = " OR "; + public static final String OPEN_BRACE = "("; + public static final String CLOSE_BRACE = ")"; + public static final String ADD_NEW_ORG = "INSERT INTO organization (org_name, url, logo, created_by, updated_by, description, color, domain) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + public static final String NEW_ORG_ADMIN_USER = "INSERT INTO user (name, username, phone, img_path) VALUES (?,?,?,?)"; + public static final String DELETE_ORG = "UPDATE organization SET is_active = FALSE , updated_by = ? , updated_date = ? WHERE id = ?"; + public static final String GET_ADMIN_BY_ORG = "SELECT DISTINCT a.id,a.name,a.username,a.phone FROM user a,organization b,roles c, user_org d, user_role e " + + "WHERE a.id = d.user_id AND a.id = e.user_id " + "AND c.id = ? AND b.id = ? AND a.is_active IS TRUE"; + public static final String GET_ROLE_ID_BY_ORG = "SELECT id FROM roles where org_id = ? and role_name = ?"; + public static final String ADD_ORG_ROLES = "insert into roles(role_name, org_id) values (?,?)"; + public static final String ADD_ROLE_PERMISSION = "insert into role_action(role_id, action_id) values (?,?)"; + public static final String NEW_ORG_ADMIN_ROLE = "INSERT INTO user_role(user_id,role_id) VALUES (?,?)"; + public static final String NEW_ORG_ADMIN_PSWRD = "INSERT INTO password (pwd, user_id) VALUES (?,?)"; + public static final String FIRST_ADMIN_COMP = "INSERT INTO user_org (org_id,user_id) VALUES (?,?)"; + public static final String UPDATE_ORG = "UPDATE organization SET org_name = ?,logo = ?,updated_date = ?,updated_by = ?,url = ?,description = ?,color = ?, domain = ? WHERE id = ?"; + public static final String GET_ORG_BY_USERID = "select user_org.org_id as id, logo from user, user_org, organization where user.id=user_org.user_id and user_org.org_id=organization.id and user.id= ?"; + public static final String CHECK_IF_ROLE_EXISTS = "select exists(select id from roles where role_name = ? and org_id = ?)"; + public static final String CHECK_IF_ACTION_EXISTS = "SELECT exists(select id from action where id=?);"; + public static final String GET_ROLE_ID_FROM_ORG = "select id from roles where role_name = ? and org_id = ?"; + public static final String DELETE_ACTION = "delete from role_action where role_id=?"; + + public static final String ORG_BY_ID = "select organization.id as id, organization.org_name as orgName, organization.url, organization.logo, organization.domain as domain, organization.color as color,organization.created_by as createdBy, organization.created_date as createdDate, organization.is_active as isActive, organization.description as description, user.id as userId, user.name, user.username, user.phone from organization, roles, user, user_org, user_role where user.id = user_org.user_id and user.id = user_role.user_id and user_org.org_id = organization.id and organization.id = roles.org_id and organization.is_active = ? and user.is_active = ? and organization.id = ? and roles.id = (select id from roles where org_id = ? and role_name = ?)"; + } + + public final class Helpdesk { + + private Helpdesk() { + super(); + + } + + public static final String CREATE_HELPDESK = "insert into helpdesk(helpdesk_name, org_id, created_by, created_date, is_active, color, description) values(?, ?, ?, ?,?,?,?)"; + public static final String UPDATE_HELPDESK = "update helpdesk set helpdesk_name = ?, updated_by = ?, updated_date = ?, is_active = ?, color = ?, description = ? where id = ? and org_id = ?"; + public static final String GET_ORG_HELPDESK = "select id, helpdesk_name as name, color from helpdesk where org_id = ? and is_active = ?"; + public static final String DELETE_WORKFLOW_FOR_HELPDESKTYPE = "delete FROM workflow_stage where type_id=?"; + public static final String DELETE_TYPE_FOR_HELPDESK = " update helpdesk_type set is_active=false WHERE helpdesk_id = ? "; + public static final String DELETE_CHECKLIST_FOR_HDTYPE = " Update checklist set is_active=false WHERE id in (select checklist_id from helpdesk_checklist where helpdesk_id = ? and helpdesk_type_id = ? ) "; + public static final String DELETE_CHECKLIST_HD_MAP = " DELETE from helpdesk_checklist WHERE helpdesk_id = ? "; + public static final String INSERT_TYPE_FOR_HELPDESK = " INSERT INTO helpdesk_type (helpdesk_id, name) values (?,?)"; + public static final String INSERT_WORKFLOW_FOR_HELPDESK_TYPE = " INSERT INTO workflow_stage (name, type_id) VALUES (?, ?) "; + public static final String INSERT_CHECKLIST_FOR_HDTYPE = " INSERT INTO checklist (name) values (?)"; + public static final String MAP_CHECKLIST_HDTYPE = " INSERT INTO helpdesk_checklist (helpdesk_id, checklist_id, helpdesk_type_id) values (?, ?, ?) "; + public static final String GET_HELPDESK_FOR_ID = " SELECT hlpdsk.id as id, hlpdsk.helpdesk_name as name, hlpdsk.is_active as isActive, hlpdsk.color as color, hlpdsk.allow_all_users, hlpdsk.description as description, hlpdsk.org_id as orgId, " + + " hlpdsktyp.id as helpdeskTypeId, hlpdsktyp.name as helpdeskType, " + + " ws.id as workflowStageId, ws.name as workflowStage " + + " FROM helpdesk hlpdsk LEFT JOIN helpdesk_type hlpdsktyp ON hlpdsk.id = hlpdsktyp.helpdesk_id " + + " LEFT JOIN workflow_stage ws ON hlpdsktyp.id = ws.type_id " + + " WHERE hlpdsk.id = ? AND hlpdsk.org_id = ? and hlpdsktyp.is_active is true"; + public static final String GET_HELPDESK_BY_ID = " SELECT hlpdsk.id as id, hlpdsk.allow_all_users as allowAllUsers, hlpdsk.org_id as orgId FROM helpdesk hlpdsk WHERE hlpdsk.id = ? and hlpdsk.is_active is true"; + + public static final String GET_CHECKLIST_FOR_HELPDESK = " SELECT cl.id as checklistId, cl.name as itemName, hcl.helpdesk_id as helpdeskId from helpdesk_checklist hcl " + + " LEFT JOIN checklist cl ON hcl.checklist_id= cl.id " + + " WHERE hcl.helpdesk_id = ? AND hcl.helpdesk_type_id = ? and cl.is_active is true"; + public static final String GET_CHECKLIST_FOR_TICKET = "SELECT c.id as id, name , checked from ticket_checklist tcl, checklist c where c.id=tcl.checklist_id and ticket_id=? and c.is_active is true;"; + public static final String GET_WORKFLOW_FOR_TICKET = "SELECT t.id, workflow_id as workFlowId, name, time, status FROM ticket_workflow t, workflow_stage w where ticket_id=? and w.id=t.workflow_id;"; + public static final String GET_WORKFLOW_FOR_TICKET_LIST = "SELECT t.id, ticket_id as ticketId, workflow_id as workFlowId, name, time, status FROM ticket_workflow t, workflow_stage w where w.id=t.workflow_id and ticket_id IN "; + + public static final String GET_HELPDESK_BY_USER_ID = "SELECT hlpdsk.id as id, hlpdsk.helpdesk_name as name, hlpdsk.is_active as isActive, hlpdsk.color as color from helpdesk hlpdsk where id IN (SELECT distinct id FROM helpdesk AS h LEFT JOIN helpdesk_admin AS ha ON h.id=ha.helpdesk_id LEFT JOIN helpdesk_users AS hu ON h.id = hu.helpdesk_id where is_active is true and (ha.user_id=? or hu.user_id=?)) or allow_all_users is true and is_active is true and org_id=?"; + public static final String GET_HELPDESK_USER_BY_ID = " SELECT id as id, name as name, username as userName, img_path from user where id IN (select user_id from helpdesk_users where helpdesk_id = ? ) "; + public static final String DELETE_CHECKLIST_FOR_TICKET = "DELETE from ticket_checklist WHERE ticket_id = ?"; + public static final String GET_HELPDESK_ADMIN_BY_ID = " SELECT id as id, name as name, username as userName, img_path from user where id IN (select user_id from helpdesk_admin where helpdesk_id = ? ) "; + public static final String GET_APP_ORG_ID = "SELECT org_id FROM organization_app where app_id=?;"; + public static final String GET_USER_DETAILS_FOR_HELPDESK = "SELECT user_id as id, name as name, username as userName, img_path from user, user_org where is_active is true and user.id=user_org.user_id and org_id=?"; + + public static final String GET_HELPDESK_ADMIN_USER = "select distinct user.id, name as name, username, img_path as imagePath" + + " from user, helpdesk_admin " + "where user.id = helpdesk_admin.user_id" + + " and helpdesk_admin.helpdesk_id = ? and user.is_active = true"; + public static final String UPDATE_HELPDESK_CHANNELS = "update helpdesk set direct = ?, playstore = ?, appstore = ?, aurora_sdk = ? where id = ? and org_id = ?"; + } + + public final class RoleAction { + private RoleAction() { + super(); + + } + + public static final String GET_ALL_ROLES = "SELECT id as id, role_name as name, org_id as orgId FROM roles"; + public static final String ORG_ID_CONDITION = " org_id = ? "; + public static final String SELECT_ROLES_ON_ID = "SELECT role_name FROM roles WHERE id= ? and org_id = ?"; + public static final String SELECT_ROLE_ACTIONS_ON_ROLEID = "SELECT action_id as actionId, role_id as roleId FROM role_action WHERE role_id=?"; + public static final String SELECT_ACTIONS_ON_ID = "SELECT * FROM action WHERE id=?"; + public static final String SAVE_NEW_ROLE = "INSERT INTO roles (role_name, org_id) VALUES (?,?)"; + public static final String UPDATE_ROLE = "UPDATE roles SET role_name = ? WHERE id = ? and org_id=?"; + public static final String GET_ALL_ACTIONS_FOR_ROLES = "select role.id as roleId, act.id as actionId, role.role_name as roleName, " + + "act.name as actionName, act.display_name as displayName, act.url as actionUrl " + + "from role_action ra LEFT JOIN roles role ON ra.role_id = role.id " + + "LEFT JOIN action act ON act.id = ra.action_id " + "where role.id IN "; + } + + public final class Apps { + private Apps() { + super(); + + } + + public static final String INSERT_NEW_APP = "INSERT into application (app_name, url, logo, sr_source_id, created_by, is_active, client_name, version, app_key, description) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + public static final String UPDATE_APP = "UPDATE application SET app_name=?, url=?, logo=?, sr_source_id=?, is_active=?, client_name=?, version=?," + + " updated_by=?, updated_date=?, app_key=?, description=? where id=?"; + public static final String GET_APP = "SELECT id as id, app_name as name, description, url as appUrl, logo as logo, created_by as createdBy, created_date as createdDate, " + + " is_active as activeStatus, client_name as clientName, version, sr_source_id as sourceId, app_key as appKey FROM application"; + public static final String ID_CONDITION = " id = ? "; + public static final String GET_ID_FROM_ORG_APP = "select exists (select id from organization_app where app_id = ? and org_id = ?)"; + public static final String MAP_APP_TO_ORG = "insert into organization_app(app_id, org_id) values(?,?);"; + public static final String DELETE_ORG_APP = "delete from organization_app where app_id = ? and org_id = ?"; + public static final String GET_ORG_APPS = "select application.id as id,application.app_name as name, application.url as appUrl, application.description as description, application.logo, application.client_name as clientName, application.version, application.sr_source_id as sourceId, application.app_key as appKey, application.is_active as activeStatus from organization_app, application where application.id = organization_app.app_id and organization_app.org_id = ? and application.is_active is true"; + public static final String GET_APP_URLS = "select distinct application.url as appUrl from organization_app, application where application.id = organization_app.app_id and organization_app.org_id = ? and application.is_active is true"; + + public static final String MAP_HELPDESK_APP = "insert into helpdesk_app(helpdesk_id, app_id) values (?,?)"; + public static final String UPDATE_HELPDESK_APP = "update helpdesk_app set is_active = ? where helpdesk_id = ? and app_id = ?"; + public static final String GET_SOURCE = " SELECT id, name FROM source "; + public static final String GET_HELPDESK_ID = "select exists(select id from helpdesk_app where helpdesk_id=? and app_id = ?)"; + public static final String GET_APP_ID_APP_KEY = "select id FROM application where url = ? and is_active is true;"; + public static final String CHECK_IF_APP_NAME_EXISTS = "select exists(select id FROM application where url = ? and is_active is true);"; + public static final String CHECK_IF_TICKET_EXIST = "select exists(select id from ticket where description = ? and active is true and requested_by in (select id from user where username=? and is_active is true) LIMIT 1);"; + public static final String CHECK_IF_TICKET_EXISTS = "select exists(select id from ticket where reviewId = ? and active is true and requested_by in (select id from user where username=? and is_active is true) LIMIT 1);"; + public static final String GET_APP_ID_FROM_APP_KEY = "select id FROM application where app_key = ? and is_active is true;"; + + public static final String CHECK_IF_UPDATE_EXISTS = "select exists(select id from ticket_updates where updates = ? and active is true and created_date=? limit 1);"; + public static final String GET_REQUESTED_BY = "select requested_by from ticket where id=? and active is true"; + public static final String CHECK_GET_APP_ID_FROM_APP_KEY = "select exists(select id FROM application where app_key = ? and is_active is true);"; + public static final String GET_ORG_ID_FROM_APP_ID = "SELECT org_id as orgId FROM organization_app where app_id=?;"; + public static final String GET_HELPDESK_ID_FROM_APP_ID = "select helpdesk_id from helpdesk_app where app_id = ? and is_active is true LIMIT 1"; + + } + + public final class UserQueries { + private UserQueries() { + super(); + + } + + public static final String SELECT_USER_BY_TOKEN = "SELECT \"user\".id as id FROM \"user\",\"user_authentication\" WHERE auth_token = ? and \"user\".is_active is true and \"user\".id=user_authentication.user_id;"; + public static final String SELECT_USER_ON_USERNAME = "SELECT user.id as id, user.name as name, user.username as username, user_org.org_id as orgId, " + + " user.is_active as isActive, pwd.pwd as password from user, user_org, password pwd where " + + " user.id = user_org.user_id and pwd.user_id = user.id and username = ?"; + public static final String SELECT_USER_ROLES_ON_USERNAME = "SELECT usr.id as id, usr.name as name, usr.username as username, usr.is_active as isActive, " + + " usrorg.org_id as orgId, " + " pwd.pwd as password, " + + " role.role_name as roleName, role.id as roleId, role.org_id as roleOrgId " + + " from user usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + + " LEFT JOIN password pwd ON pwd.user_id = usr.id " + + " LEFT JOIN user_role usrrole ON usr.id = usrrole.user_id " + + " LEFT JOIN roles role ON usrrole.role_id = role.id " + Common.WHERE_CLAUSE + + " role.org_id = usrorg.org_id and usr.username = ?"; + public static final String SELECT_USER_ROLES_ACTIONS_ON_USERNAME = "SELECT usr.id as id, usr.name as name, usr.username as username, usr.is_active as isActive, " + + " usrorg.org_id as orgId, " + " pwd.pwd as password, " + + " role.role_name as roleName, role.id as roleId, role.org_id as roleOrgId, " + + " actn.id as actionId, actn.name as actionName, actn.display_name as actionDisplayName, actn.query_params as actionQueryParams, " + + " actn.service_code as actionServiceCode, actn.url as actionUrl " + + " from user usr LEFT JOIN user_org usrorg ON usr.id = usrorg.user_id " + + " LEFT JOIN password pwd ON pwd.user_id = usr.id " + + " LEFT JOIN user_role usrrole ON usr.id = usrrole.user_id " + + " LEFT JOIN roles role ON usrrole.role_id = role.id " + + " LEFT JOIN role_action rolactn ON role.id = rolactn.role_id " + + " LEFT JOIN action actn ON rolactn.action_id = actn.id " + Common.WHERE_CLAUSE + + " role.org_id = usrorg.org_id and usr.username = ? "; + public static final String MAP_USER_TO_ROLE = "INSERT INTO user_role (user_id, role_id) VALUES (?, ?)"; + public static final String REMOVE_USER_ROLE_MAP = "DELETE FROM user_role WHERE user_id = ? "; + + public static final String UPDATE_USER_PROFILE_PROFILE_IMAGE = "UPDATE user SET img_path = ? WHERE id = ?"; + + public static final String GET_USER_ACTIONS = "Select action.id, action.display_name as displayName, name, url from action inner join role_action on role_action.action_id = action.id where role_action.role_id = ?"; + public static final String USER_PROFILE_FETCH = "select * from user usr where id=? "; + public static final String USER_DATA = "select COUNT(*) from user where username=?"; + public static final String USER = "select * from user where id=?"; + public static final String GET_USER_AUTH_DETAILS = "SELECT id, user_id as userId, auth_token FROM user_authentication WHERE id=?"; + public static final String SAVE_USER = "INSERT INTO user(name,username,phone,img_path) VALUES (?,?,?,?)"; + public static final String SAVE_ANONYMOUS_USER = "INSERT INTO user(name,username,phone,img_path,is_anonymous) VALUES (?,?,?,?,?)"; + public static final String SAVE_USER_AUTHENTICATION = "INSERT INTO user_authentication(user_id,auth_token) VALUES (?,?)"; + public static final String GET_USER_ROLE = "SELECT user_id, role_id FROM retail_user_role WHERE user_id=?"; + public static final String GET_ROLES_FOR_USER = "select ur.role_id as roleId, r.role_name as roleName from roles r, user_role ur where r.id = ur.role_id and ur.user_id = ?"; + public static final String USER_ACTIVE_CONDITION = " WHERE usr.is_active = ? "; + public static final String WHERE_CLAUSE = " WHERE "; + public static final String AND_CONDITION = " AND "; + public static final String OR_CONDITION = " OR "; + + public static final String UPDATE_USER = "UPDATE user SET name = ?,username = ?, phone = ?, is_active = ?, img_path = ? where id = ? "; + public static final String GET_USER_COUNT = "SELECT count(*) FROM user usr"; + public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM user usr where usr.is_active = ? "; + public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM user usr LEFT JOIN user_role ur ON usr.id = ur.user_id where ur.role_id = ? and usr.is_active IS TRUE"; + public static final String GET_ROLE_COUNT = "SELECT count(*) FROM roles"; + + public static final String INVALIDATE_TOKEN = "DELETE from user_authentication WHERE auth_token = ? "; + public static final String FETCH_AUTH_TOKEN_REF = "SELECT id FROM user_authentication WHERE auth_token = ? "; + public static final String CHECK_USER_DEVICE_TOKEN = "SELECT COUNT(*) FROM user_device WHERE user_id = ? AND device_token = ? "; + public static final String INSERT_PD = "insert into password(pwd, user_id) values(?,?)"; + public static final String INSERT_ACTION = "INSERT INTO action(`id`,`name`,`display_name`,`url`) VALUES(?,?,?,?);"; + public static final String UPDATE_ACTION = "UPDATE action set name=?, display_name=?, url=? where id=?"; + public static final String GET_AUTH_TYPE_ID = "select aut_id from organization_auth where org_id = ?"; + public static final String CHECK_FIRST_ADMIN = "SELECT org_id FROM user_org WHERE user_id=?"; + public static final String GET_MASTER_DATA_CHECK = "SELECT COUNT(user_id) as id FROM user_org WHERE org_id = ? "; + public static final String NEW_ORG_AUTH = "Insert into organization_auth(org_id, aut_id, base_url, email_domain) values (?,?,?,?)"; + public static final String GET_ROLE_ID_BY_ORG = "SELECT id FROM roles where org_id = ? and role_name = ?"; + public static final String ADD_ADMIN = "UPDATE user_role SET role_id = ? WHERE user_id = ?"; + public static final String DELETE_ADMIN = "UPDATE user_role SET role_id = ? WHERE user_id = ?"; + public static final String MAP_USER_TO_ORG = "Insert into user_org(user_id,org_id) values (?,?)"; + public static final String GET_HELPDESK_ADMINS = "select user_id from helpdesk_admin where helpdesk_id=? "; + public static final String GET_TICKET_CC = "select user_id from ticket_cc where ticket_id=? "; + public static final String GET_TICKET_ATTACHMENT = "select url from ticket_attachment,attachment_url where ticket_id=? and ticket_attachment.attachment_id=attachment_url.id;"; + public static final String REMOVE_ALL_HELPDESK_ADMIN = "DELETE FROM helpdesk_admin where helpdesk_id=?"; + public static final String REMOVE_ALL_USERS_FROM_HELPDESK = "DELETE FROM helpdesk_users where helpdesk_id=?"; + public static final String REMOVE_ALL_TICKET_CC = "DELETE FROM ticket_cc where ticket_id=?"; + public static final String REMOVE_ALL_HELPDESK_SOURCE = "DELETE FROM helpdesk_source where helpdesk_id=?"; + public static final String ADD_ADMINS_TO_HELPDESK = "insert into helpdesk_admin(helpdesk_id,user_id) values (?,?)"; + public static final String ADD_USERS_TO_HELPDESK = "insert into helpdesk_users(helpdesk_id,user_id) values (?,?)"; + public static final String ADD_CC_TO_TICKET = "insert into ticket_cc(ticket_id,user_id) values (?,?)"; + public static final String GET_USER_ORG_MAP = "SELECT user_org.id as id , user_id as userId , org_id as orgId FROM \"user\", \"user_org\" where \"user\".id=user_org.user_id and \"user\".is_anonymous is false;"; + public static final String GET_USER_ROLE_MAP = "SELECT id as id, user_id as userId, role_id as roleId FROM user_role "; + public static final String GET_APP_ID_HELPDESK_ID = "select helpdesk_id as helpdeskId,app_id as appId from helpdesk_app where is_active is true;"; + public static final String GET_APP_ID_APP_OBJECT = "SELECT id,app_name as name,logo,url FROM application;"; + public static final String GET_HELPDESK_ID_HELPDESK_OBJECT = "SELECT id,helpdesk_name as name,org_id as orgId FROM helpdesk where is_active is true "; + public static final String GET_USER_ID_AND_USER_NAME = "SELECT id,name FROM \"user\" where is_active is true;"; + public static final String UPDATE_ALLOW_ALL_USERS = "UPDATE helpdesk SET allow_all_users = ? WHERE id = ?"; + public static final String REMOVE_ALL_TICKET_ATTACHMENT = "DELETE FROM ticket_attachment where ticket_id=?"; + public static final String GET_HELPDESK_CHANNELS = "SELECT direct, playstore, appstore, aurora_sdk FROM helpdesk where id=? and is_active is true "; + + public static final String QUERY1 = "SELECT toa.aut_id as id, toa.base_url as name, auth_name as description from organization_auth toa, "; + public static final String QUERY2 = " authentication auth WHERE toa.aut_id = auth.id AND toa.org_id = "; + public static final String QUERY3 = " AND toa.is_active IS TRUE "; + } + + public final class Ticket { + private Ticket() { + super(); + + } + + public static final String ADD_SOURCE_TO_HELPDESK = "INSERT INTO helpdesk_source(helpdesk_id, source_id) VALUES (?,?);"; + public static final String ADD_TICKET = "insert into ticket(created_time, rate, max_rating, priority, requested_by, description, type, updated_time, pinned_ticket) values(?,?,?,?,?,?,?,?,?);"; + public static final String ADD_TICKET_TO_HELPDESK = "INSERT INTO helpdesk_ticket(ticket_id, sr_source_id, helpdesk_id, app_id) VALUES (?,?,?,?);"; + public static final String UPDATE_TICKET = "update ticket set priority=?, notes=?, active=?, updated_time=? where id=?"; + public static final String UPDATE_TICKET_REVIEW_ID = "update ticket set reviewId=? where id=?"; + public static final String GET_ALL_TICKETS = "SELECT t.id, t.created_time as createdTime, t.updated_time as updatedTime, t.rate, t.max_rating as maxRating, t.priority, requested_by as requestedBy, description, notes , pinned_ticket as pinnedTicket from ticket t where requested_by = ? and active is true;"; + public static final String GET_TICKET_BY_ID = "select t.id, pinned_ticket as pinnedTicket, created_time as createdTime, updated_time as updatedTime, rate, max_rating as maxRating, priority, requested_by as requestedBy, description, notes, type, sr_source_id as sourceId, helpdesk_id as helpdeskId, app_id as appId, active from ticket t, helpdesk_ticket ht where t.id = ? and t.id=ht.ticket_id and active is true;"; + public static final String GET_ALL_TICKETS_BY_HELPDESK_ID = "select t.id as id, pinned_ticket as pinnedTicket, created_time as createdTime, updated_time as updatedTime, rate, max_rating as maxRating, priority, requested_by as requestedBy, description from ticket t, helpdesk_ticket ht where t.active is true and ht.helpdesk_id=? and t.id=ht.ticket_id order by t.id desc;"; + public static final String GET_ALL_TICKETS_BY_APP_ID = "select t.id as id, pinned_ticket as pinnedTicket, created_time as createdTime, updated_time as updatedTime, rate, max_rating as maxRating, priority, requested_by as requestedBy, description from ticket t, helpdesk_ticket ht where t.active is true and ht.app_id=? and t.id=ht.ticket_id order by t.id desc;"; + public static final String UPDATE_STATUS = "update tt_ticket set status=? where id=?"; + public static final String CLOSE_TICKET = "update tt_ticket set closed_by=?,closed_time=current_timestamp,is_closed=true where id=?;"; + public static final String APPROVE_TICKET = "update tt_ticket set updated_by=?,updated_time=current_timestamp,is_approved=true where id=?;"; + public static final String GET_VERSION_FOR_TEMPLATES = "SELECT version FROM template_version "; + public static final String UPDATE_VERSION_TIMESTAMP = " UPDATE template_version SET version = ? "; + public static final String UPDATE_NOTES_TO_TICKETS = "update ticket set notes=? where id=?"; + public static final String UPDATE_UPDATES = "update ticket_updates set updates=?, active=?, created_date=? where id=?"; + public static final String ADD_UPDATES = "insert into ticket_updates(updates,created_by,ticket_id,created_date) values(?,?,?,?);"; + public static final String INSERT_TYPE_FOR_TICKETS = " INSERT INTO ticket_details (ticket_id, info_type) values (?,?)"; + public static final String INSERT_WORKFLOW_FOR_TICKET_TYPE = " INSERT INTO ticket_workflow (workflow_id, ticket_id) VALUES (?, ?) "; + public static final String INSERT_CHECKLIST_FOR_TICKET_TYPE = " INSERT INTO ticket_checklist (ticket_id, checklist_id) VALUES (?, ?)"; + public static final String DELETE_WORKFLOW_FOR_TICKET_TYPE = "delete FROM ticket_workflow where ticket_id=?"; + public static final String GET_DEFAULT_TICKET_TYPE = "SELECT min(id) as id FROM helpdesk_type where helpdesk_id=? and is_active is true;"; + public static final String GET_DEFAULT_ADMIN_ID = "SELECT user_id as id FROM helpdesk_admin where helpdesk_id=? LIMIT 1;"; + public static final String UPDATE_TICKET_WORKFLOW = "update ticket_workflow set status=?, time=? where workflow_id=? and ticket_id=?"; + public static final String GET_UPDATES = "SELECT created_by as createdBy, updates as upds, created_date as createdDate FROM ticket_updates where ticket_id=? and active is true order by id asc; "; + public static final String UPDATE_TICKET_TYPE = "update ticket set type=? where id=?;"; + public static final String UPDATE_TICKET_CHECKLIST = "update ticket_checklist set checked=? where checklist_id=? and ticket_id=?"; + public static final String ADD_ACTIVITY_LOG = "INSERT INTO activity_logs(activity, ticket_id, timestamp, changes_by) VALUES (?,?,?,?);"; + public static final String GET_ACTIVITY_LOGS = "select id,activity,ticket_id as ticketId, timestamp, changes_by as changesBy from activity_logs where ticket_id=?"; + public static final String GET_WORKFLOW_NAME = "SELECT name FROM workflow_stage where id=?;"; + public static final String UPDATE_TICKET_DESCRIPTION = "update ticket set description=? where id=?"; + public static final String UPDATE_TICKET_PIN = "update ticket set pinned_ticket=? where id=?"; + public static final String GET_REVIEW_ID = "SELECT reviewId FROM ticket where id=? and active is true;"; + public static final String GET_ORG_ID_FROM_TICKET_ID = "SELECT org_id from helpdesk where id in (select helpdesk_id FROM helpdesk_ticket where ticket_id=?) limit 1;"; + public static final String GET_APP_URL_FROM_TICKET_ID = "select url from application where id in (select app_id FROM helpdesk_ticket where ticket_id=?);"; + + public static final String GET_ACTIVITY_LOGS_PER_USER = "select activity_logs.id,activity,activity_logs.ticket_id as ticketId, timestamp, changes_by as changesBy, helpdesk_id as helpdeskId from activity_logs, helpdesk_ticket where activity_logs.ticket_id=helpdesk_ticket.ticket_id and activity_logs.ticket_id in (SELECT distinct t.id from ticket t where (requested_by = ? or (id in (select ticket_id from ticket_cc where user_id = ?))) and active is true) order by id desc;"; + + public static final String GET_CREATED_AND_COPIED_TO_TICKET_IDS = "SELECT distinct t.id from ticket t where requested_by = ? or (id in (select ticket_id from ticket_cc where user_id = ?)) and active is true;"; + public static final String GET_CREATED_AND_COPIED_TO_TICKET_IDS_BY_HELPDESK_ID = "SELECT distinct t.id from ticket t, helpdesk_ticket where (requested_by = ? or (t.id in (select ticket_id from ticket_cc where user_id = ?))) and helpdesk_ticket.ticket_id=t.id and helpdesk_ticket.helpdesk_id=? and active is true"; + public static final String GET_TICKETS_BY_TAGS = "SELECT distinct ticket_id as id FROM tag_ticket where tag_ticket.tag_id in (select id from tag where tag_name in "; + public static final String GET_HELPDESK_ID_FOR_TICKET = "select helpdesk.id from helpdesk_ticket,helpdesk where ticket_id=? and helpdesk.id=helpdesk_ticket.helpdesk_id and helpdesk.is_active is true;"; + public static final String STATUS = "status.keyword"; + public static final String ACTIVE = "active"; + public static final String DESCRIPTION = "description"; + public static final String HELPDESK_ID = "helpdeskId"; + public static final String TAGS = "tags.keyword"; + public static final String CC = "cc.keyword"; + public static final String SOURCE_ID = "sourceId"; + public static final String GET_TICKET_IDS_BY_HELPDESK_ID = "SELECT distinct t.id from ticket t, helpdesk_ticket where helpdesk_ticket.ticket_id=t.id and helpdesk_ticket.helpdesk_id=? and active is true;"; + + public static final String GET_TICKET_DETAILS_BY_HELPDESK = "select tkt.id as ticketId, tkt.pinned_ticket as pinnedTicket, tkt.created_time as createdTime, tkt.updated_time as updatedTime, " + + " tkt.rate as rate, tkt.max_rating as maxRating, tkt.priority as priority, tkt.requested_by as requestedBy, " + + " tkt.description as decription, tkt.notes as notes, tkt.type as type, tkt.active as active, " + + " ht.sr_source_id as sourceId, ht.helpdesk_id as helpdeskId, ht.app_id as appId, " + + " tcc.user_id as tktCCUserId, " + + " clist.id as clistId, clist.name as clistName, tcl.checked as tclChecked " + + " from ticket tkt LEFT JOIN helpdesk_ticket ht ON tkt.id=ht.ticket_id " + + " LEFT JOIN ticket_cc tcc ON tkt.id = tcc.ticket_id " + + " LEFT JOIN ticket_checklist tcl ON tkt.id = tcl.ticket_id " + + " LEFT JOIN checklist clist ON tcl.checklist_id = clist.id " + + " where ht.helpdesk_id = ? and active is true"; + public static final String REQUESTEDBY = "requestedBy"; + } + + public static final String GET_USER_ACTIONS = "SELECT * FROM retail_actions ma inner join retail_role_actions mra on mra.action_id = ma.id where ma.enabled = true and mra.role_id = ? order by ma.order_number"; + public static final String GET_USER_AUTH_DETAILS = "SELECT id, user_id, auth_token FROM user_authentication WHERE id=?"; + public static final String SAVE_USER = "INSERT INTO user(name,username,password) VALUES (?,?,?)"; + public static final String SAVE_USER_AUTHENTICATION = "INSERT INTO user_authentication(user_id,auth_token) VALUES (?,?)"; + public static final String GET_USER_ROLE = "SELECT user_id, role_id FROM retail_user_role WHERE user_id=?"; + public static final String GET_ROLES_FOR_USER = " select mur.user_id, mur.role_id, mr.role_name, mr.description, mr.priority from retail_user_role mur LEFT JOIN retail_role mr ON mur.role_id = mr.id " + + " WHERE mur.user_id = ? "; + public static final String USER_ACTIVE_CONDITION = " WHERE usr.is_active = ? "; + public static final String WHERE_CLAUSE = " WHERE "; + public static final String AND_CONDITION = " AND "; + public static final String OR_CONDITION = " OR "; + + public static final String UPDATE_USER = "UPDATE user SET name = ?, username = ? , is_active = ? where id = ? "; + public static final String UPDATE_USER_PROFILE = "UPDATE user_profile SET name = ?, email = ?, phone_number = ?," + + " updated_by = ? WHERE user_id = ? "; + public static final String GET_USER_COUNT = "SELECT count(*) FROM user usr"; + public static final String GET_USER_COUNT_ON_ACTIVE_STATUS = "SELECT count(*) FROM user usr where usr.is_active = ? "; + public static final String GET_USER_COUNT_FOR_ROLE = "SELECT count(*) FROM user usr LEFT JOIN retail_user_role usrrole ON usr.id = usrrole.user_id where usrrole.role_id = ? " + + "and usr.is_active IS TRUE"; + public static final String GET_ROLE_COUNT = "SELECT count(*) FROM retail_role"; + + public static final String INVALIDATE_TOKEN = "DELETE from user_authentication WHERE auth_token = ? "; + public static final String FETCH_AUTH_TOKEN_REF = "SELECT id FROM user_authentication WHERE auth_token = ? "; + public static final String CHECK_USER_DEVICE_TOKEN = "SELECT COUNT(*) FROM user_device WHERE user_id = ? AND device_token = ? "; + public static final String GET_S3_ACCESS = "SELECT access_key as accessKey,secret_key as secretKey,bucket_name as bucketName FROM s3_config WHERE id = 1"; + public static final String GET_CONFIG = "SELECT client_id as clientId,client_secret as clientSecret,refresh_token as refreshToken FROM review_config where org_id=?;"; + public static final String INSERT_PROFILE_PICTURE = "UPDATE user set img_path=? WHERE id=?"; + public static final String GET_DP = "SELECT img_path FROM user WHERE id=?"; + public static final String ADD_ATTACHMENT_TO_TICKET = "insert into ticket_attachment(ticket_id, attachment_id) values (?,?);"; + public static final String INSERT_ATTACHMENT = "insert into attachment_url(url) values (?);"; +} diff --git a/src/main/java/org/upsmf/grievance/util/SqlConstants.java b/src/main/java/org/upsmf/grievance/util/SqlConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..5452b482b95671dcf159313417aef79d30c73d7b --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/SqlConstants.java @@ -0,0 +1,86 @@ +package org.upsmf.grievance.util; + +public final class SqlConstants { + + public final class DbAttributes { + private DbAttributes() { + super(); + } + + public static final String ID = "id"; + public static final String NAME = "name"; + public static final String USERNAME = "username"; + public static final String ISACTIVE = "isActive"; + public static final String PSWRD = "password"; + public static final String ORGID = "orgId"; + public static final String USERID = "userId"; + + public static final String ROLEID = "roleId"; + public static final String ROLENAME = "roleName"; + public static final String ROLEORGID = "roleOrgId"; + + public static final String ACTIONID = "actionId"; + public static final String ACTIONNAME = "actionName"; + public static final String ACTIONDISPLAYNAME = "actionDisplayName"; + public static final String ACTIONQUERYPARAMS = "actionQueryParams"; + public static final String ACTIONSERVICECODE = "actionServiceCode"; + public static final String ACTIONURL = "actionUrl"; + + public static final String ROLEORORG = "roleOrOrg"; + + public static final String LOGO = "logo"; + public static final String URL = "url"; + + public static final String ORGNAME = "orgName"; + public static final String DOMAIN = "domain"; + public static final String COLOR = "color"; + public static final String CREATEDBY = "createdBy"; + public static final String CREATEDDATE = "createdDate"; + public static final String DESCRIPTION = "description"; + + public static final String HELPDESKTYPEID = "helpdeskTypeId"; + public static final String HELPDESKTYPE = "helpdeskType"; + public static final String WORKFLOWSTAGEID = "workflowStageId"; + public static final String WORKFLOWSTAGE = "workflowStage"; + public static final String CHECKLISTID = "checklistId"; + public static final String CHECKLISTNAME = "checklistName"; + + public static final String ITEMNAME = "itemName"; + public static final String HELPDESKID = "helpdeskId"; + + public static final String TICKETID = "ticketId"; + public static final String APPVERSION = "appVersion"; + public static final String PINNEDTICKET = "pinnedTicket"; + public static final String CREATEDTIME = "createdTime"; + public static final String UPDATEDTIME = "updatedTime"; + public static final String RATING = "rate"; + public static final String MAXRATING = "maxRating"; + public static final String PRIORITY = "priority"; + public static final String REQUESTEDBY = "requestedBy"; + public static final String ASSIGNEDTO = "assignedTo"; + public static final String NOTES = "notes"; + public static final String TYPE = "type"; + public static final String ACTIVE = "active"; + public static final String SOURCEID = "sourceId"; + public static final String APPID = "appId"; + public static final String TKTCCUSERID = "tktCCUserId"; + public static final String CLISTID = "clistId"; + public static final String CLISTNAME = "clistName"; + public static final String TCLCHECKED = "tclChecked"; + public static final String PHONE = "phone"; + public static final String IMAGE_PATH = "img_path"; + public static final String TICKET_ID = "ticketId"; + public static final String STATUS = "status"; + public static final String TIME = "time"; + public static final String WORKFLOWID = "workFlowId"; + public static final String IS_ACTIVE = "is_active"; + public static final String CREATED_DATE = "created_date"; + public static final String UPDATED_DATE = "updated_date"; + public static final String AUTH_TOKEN = "auth_token"; + public static final String DISPLAY_NAME = "display_name"; + public static final String CHECKED = "checked"; + public static final String ALLOW_ALL_USERS = "allow_all_users"; + + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/executor/FetchReviewsWeeklyJob.java b/src/main/java/org/upsmf/grievance/util/executor/FetchReviewsWeeklyJob.java new file mode 100644 index 0000000000000000000000000000000000000000..d978b6704df9428bd00bc2ac336fe5ced8aa6d56 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/executor/FetchReviewsWeeklyJob.java @@ -0,0 +1,33 @@ +package org.upsmf.grievance.util.executor; + +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import org.upsmf.grievance.dao.TicketDao; +import org.upsmf.grievance.dao.UserDao; + +public class FetchReviewsWeeklyJob implements Job { + public static final Logger LOGGER = LoggerFactory.getLogger(FetchReviewsWeeklyJob.class); + private static final String CLASSNAME = FetchReviewsWeeklyJob.class.getName(); + + @Autowired + private UserDao userDao; + + @Autowired + private TicketDao ticketDao; + + @Override + public void execute(JobExecutionContext ctx) throws JobExecutionException { + try { + userDao.getReviews(); + ticketDao.getFeedBacksFromAuroraSdk(); + } catch (Exception e) { + LOGGER.error(e.getMessage(), CLASSNAME); + } + } + +} diff --git a/src/main/java/org/upsmf/grievance/util/executor/ReviewsSchedulerManager.java b/src/main/java/org/upsmf/grievance/util/executor/ReviewsSchedulerManager.java new file mode 100644 index 0000000000000000000000000000000000000000..58c2b9ffeeaeedf32ae7e4e7410be3175582f5f8 --- /dev/null +++ b/src/main/java/org/upsmf/grievance/util/executor/ReviewsSchedulerManager.java @@ -0,0 +1,38 @@ +package org.upsmf.grievance.util.executor; + +import org.quartz.CronScheduleBuilder; +import org.quartz.JobBuilder; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.Trigger; +import org.quartz.TriggerBuilder; +import org.quartz.impl.StdSchedulerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ReviewsSchedulerManager { + private static final String CLASSNAME = ReviewsSchedulerManager.class.getName(); + public static final Logger LOGGER = LoggerFactory.getLogger(FetchReviewsWeeklyJob.class); + + /** + * scheduler job is configured here + */ + public static void schedule() { + JobDetail weeklyJob = JobBuilder.newJob(FetchReviewsWeeklyJob.class) + .withIdentity("WeeklyFetchReviews", "WeeklyFetchReviewsData").build(); + Trigger weeklyTrigger = TriggerBuilder.newTrigger().withIdentity("FetchReviewsWeekly", "FetchReviewsDataWeekly") + .withSchedule(CronScheduleBuilder.cronSchedule("0 0 8 ? * SUN *")).build(); + try { + Scheduler scheduler = new StdSchedulerFactory().getScheduler(); + scheduler.start(); + scheduler.scheduleJob(weeklyJob, weeklyTrigger); + } catch (Exception e) { + LOGGER.error(e.getMessage(), CLASSNAME); + } + + } + + private ReviewsSchedulerManager() { + super(); + } +} \ No newline at end of file diff --git a/src/main/resources/accesstokenspec.json b/src/main/resources/accesstokenspec.json new file mode 100644 index 0000000000000000000000000000000000000000..646e55ac1ecbc9b4d914025c0f78d9e0f8d52c00 --- /dev/null +++ b/src/main/resources/accesstokenspec.json @@ -0,0 +1,11 @@ +[ + { + "operation": "shift", + "spec": { + "access_token": "accessToken", + "expires_in": "expiresIn", + "scope": "scope", + "token_type": "tokenType" + } + } +] \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..a10bd9f7684b2179e7540d2bfcb928bfef0596b3 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,38 @@ +# SET CONTEXT PATH +server.port=8085 +spring.main.allow-bean-definition-overriding=true + +spring.http.multipart.max-file-size=10MB +spring.http.multipart.max-request-size=10MB + +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=mysecretpassword +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.hibernate.ddl-auto=none +spring.datasource.initialization-mode=always +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true + +urls.whitelist=/,/user/login,/user/logout,/signup,/token/validate,/upload,/user/forgotPassword,/superadmin/getAuthTypes,/tickets/getTemplateVersion,/user/updateEkstepUser,/superadmin/addOrganization,/helpdesk/getPerformanceWithoutAccessControl + +services.esindexer.host=es.rain.idc.tarento.com +services.esindexer.host.name=http://es.rain.idc.tarento.com/ +services.esindexer.host.port=9200 +services.esindexer.username=elastic +services.esindexer.password=Elastic123 +es.templates.index.name=tkt_templates +es.templates.document.type=tkt_templates +elasticsearch.url=elasticsearch-dev.idc.tarento.com +elasticsearch.index=ticket-prod +elasticsearch.type=doc + + +elk.data.up=true + +image.source.aws=true +image.source.attachment.aws=true + + + + + diff --git a/src/main/resources/application.properties.j2 b/src/main/resources/application.properties.j2 new file mode 100644 index 0000000000000000000000000000000000000000..064498f6f1d659bd5c506234f46445ecf9c73dd8 --- /dev/null +++ b/src/main/resources/application.properties.j2 @@ -0,0 +1,32 @@ +# SET CONTEXT PATH +server.port=8081 + + +spring.datasource.driver-class-name=com.mysql.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/aurora_desk?autoReconnect=true&zeroDateTimeBehavior=convertToNull +spring.datasource.username={{ datasource_user | b64decode }} +spring.datasource.password={{ datasource_pwd | b64decode }} +spring.http.multipart.max-file-size=10MB +spring.http.multipart.max-request-size=10MB + +urls.whitelist=/,/user/login,/user/logout,/signup,/token/validate,/upload,/user/forgotPassword,/superadmin/getAuthTypes,/tickets/getTemplateVersion,/user/updateEkstepUser,/superadmin/addOrganization,/helpdesk/getPerformanceWithoutAccessControl + +services.esindexer.host={{ es_host | b64decode }} +services.esindexer.host.name={{ es_host_name | b64decode }} +services.esindexer.host.port=9200 +services.esindexer.username={{ es_user | b64decode }} +services.esindexer.password={{ es_pwd | b64decode }} +es.templates.index.name=tkt_templates +es.templates.document.type=tkt_templates +elasticsearch.url=elasticsearch-dev.idc.tarento.com +elasticsearch.index=aurora-ticket +elasticsearch.type=doc + +elk.data.up=true + +image.source.aws=true +image.source.attachment.aws=true + + + + diff --git a/src/main/resources/reviewspec.json b/src/main/resources/reviewspec.json new file mode 100644 index 0000000000000000000000000000000000000000..80743ddaa5d6cbdf9ba61c02b2ee1cdae226d580 --- /dev/null +++ b/src/main/resources/reviewspec.json @@ -0,0 +1,43 @@ +[ + { + "operation": "shift", + "spec": { + "authorName": "userName", + "reviewId": "reviewId", + "comments": { + "0": { + "userComment": { + "text": "feedback", + "starRating": "rate", + "lastModified": { + "seconds": "userTimestamp" + }, + "androidOsVersion": "osVersion", + "appVersionName": "appVersion", + "deviceMetadata": { + "productName": "deviceName", + "manufacturer": "deviceManufacture", + "deviceClass": "deviceType" + } + } + }, + "*": { + "developerComment": { + "text": "developerComment", + "lastModified": { + "seconds": "developerTimestamp" + } + } + } + } + } + }, + { + "operation": "default", + "spec": { + "maxRating": "5", + "sourceId": "4", + "pinnedTicket": "false" + } + } +] diff --git a/src/test/java/org/upsmf/grievance/dao/impl/ApplicatioDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/ApplicatioDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c09980ed8396026d4dbb0403797e9dfc7a975e10 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/ApplicatioDaoImplTest.java @@ -0,0 +1,292 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; + +import java.util.ArrayList; +import java.util.List; + +import org.upsmf.grievance.dao.impl.ApplicationDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.util.S3FileManager; + +public class ApplicatioDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @InjectMocks + ApplicationDaoImpl applicationDao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Spy + private ApplicationDaoImpl appDao; + + @Spy + private S3FileManager s3; + + @SuppressWarnings("unchecked") + @Test + public void updateAppTest() { + App app = new App(); + app.setActiveStatus(false); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(app.getActiveStatus(), applicationDao.updateApp(app, new User()).getActiveStatus()); + } + + + + + + + + + + + + + + + + + + + + // + + + + + + + + + + + + + + + + + + + // + + + + + + + + + + + + + + + + + + + // + + + + + + + + + + + + + + + + + + + + @SuppressWarnings("unchecked") + @Test + public void mapAppsToHelpdeskTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(0L); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(false, applicationDao.mapAppsToHelpdesk(new StatusIdMap())); + } + + @SuppressWarnings("unchecked") + @Test + public void mapAppsToHelpdeskNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(0L); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, applicationDao.mapAppsToHelpdesk(new StatusIdMap())); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(new ArrayList<App>()); + Mockito.doReturn(new ArrayList<App>()).when(appDao).getLogo(Matchers.any()); + assertEquals(0, applicationDao.getApp(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getLogoTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + app.setLogo("p"); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(1L); + Mockito.doReturn("d").when(appDao).getAppLogo(Matchers.any()); + assertEquals(a.getClass(), applicationDao.getLogo(a).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllAppsTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(a); + Mockito.doReturn(a).when(appDao).getLogo(Matchers.any()); + assertEquals(1, applicationDao.getAllApps().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppsByOrgIdTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(a); + Mockito.doReturn(a).when(appDao).getLogo(Matchers.any()); + assertEquals(1, applicationDao.getAppsByOrgId(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getServiceRequestsTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(new ArrayList<ServiceRequest>()); + assertEquals(0, applicationDao.getServiceRequests().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndAppObjectTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(new ArrayList<App>()); + assertEquals(0, applicationDao.getAppIdAndAppObject().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void updateAppNullTest() { + App app = new App(); + app.setActiveStatus(false); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(app.getActiveStatus(), applicationDao.updateApp(app, new User()).getActiveStatus()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + Mockito.doReturn(new ArrayList<App>()).when(appDao).getLogo(Matchers.any()); + assertEquals(null, applicationDao.getApp(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getLogoNullTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + app.setLogo("p"); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + Mockito.doReturn("d").when(appDao).getAppLogo(Matchers.any()); + assertEquals(a.getClass(), applicationDao.getLogo(a).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllAppsNullTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + Mockito.doReturn(new ArrayList<App>()).when(appDao).getLogo(Matchers.any()); + assertEquals(null, applicationDao.getAllApps()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppsByOrgIdNullTest() { + List<App> a = new ArrayList<App>(); + App app = new App(); + a.add(app); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + Mockito.doReturn(new ArrayList<App>()).when(appDao).getLogo(Matchers.any()); + assertEquals(new ArrayList<>(), applicationDao.getAppsByOrgId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getServiceRequestsNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, applicationDao.getServiceRequests()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndAppObjectNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, applicationDao.getAppIdAndAppObject()); + } + +} diff --git a/src/test/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2750038a38a70b84c0aa55351a32d9f47d678d28 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/HelpdeskDaoImplTest.java @@ -0,0 +1,281 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.upsmf.grievance.dao.impl.HelpdeskDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; + +public class HelpdeskDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @InjectMocks + HelpdeskDaoImpl helpdeskDao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllHelpdesksTest() { + List<HelpdeskDto> list = new ArrayList<>(); + HelpdeskDto h = new HelpdeskDto(); + h.setId(1L); + list.add(h); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(list); + assertEquals(1, helpdeskDao.getAllHelpdesks(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskForIdTest() { + HelpdeskRowRecordMapper rowMapper = new SqlDataMapper().new HelpdeskRowRecordMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(Arrays.asList(new HelpdeskDto())); + assertEquals(rowMapper.getClass(), helpdeskDao.getHelpdeskForId(1L, 1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getChecklistItemsForHelpdeskTest() { + List<ChecklistItem> checklistItems = new ArrayList<>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(checklistItems); + assertEquals(checklistItems.getClass(), helpdeskDao.getChecklistItemsForHelpdesk(1L, 1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskAdminsTest() { + Mockito.when(jdbcTemplate.queryForList(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(Arrays.asList(1L, 2L)); + assertEquals(2, helpdeskDao.getHelpdeskAdmins(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateHelpdeskUsersTest() { + Helpdesk helpdesk = new Helpdesk(); + helpdesk.setUserIds(Arrays.asList(1L, 2L)); + helpdesk.setAllowAllUsers(false); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, helpdeskDao.addUpdateHelpdeskUsers(helpdesk)); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateHelpdeskUsersTrueTest() { + Helpdesk helpdesk = new Helpdesk(); + helpdesk.setUserIds(Arrays.asList(1L, 2L)); + helpdesk.setAllowAllUsers(true); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, helpdeskDao.addUpdateHelpdeskUsers(helpdesk)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteTypeForHelpdeskTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, helpdeskDao.deleteTypeForHelpdesk(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteWorkflowForHelpdeskTypeTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, helpdeskDao.deleteWorkflowForHelpdeskType(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteChecklistForHelpdeskTypeTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, helpdeskDao.deleteChecklistForHelpdeskType(1L, 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteChecklistForHelpdeskTypeFalseTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, helpdeskDao.deleteChecklistForHelpdeskType(1L, 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndHelpDeskIdTest() { + List<HelpDeskApp> helpdeskApp = new ArrayList<HelpDeskApp>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(helpdeskApp); + assertEquals(0, helpdeskDao.getAppIdAndHelpDeskId().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskObjectFromHelpdeskIdTest() { + List<Helpdesk> helpdesk = new ArrayList<Helpdesk>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(helpdesk); + assertEquals(0, helpdeskDao.getHelpdeskObjectFromHelpdeskId().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAdminForHelpeskIdTest() { + List<User> user = new ArrayList<User>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(user); + assertEquals(0, helpdeskDao.getAdminForHelpeskId(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllHelpdesksNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>(), helpdeskDao.getAllHelpdesks(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskForIdNullTest() { + HelpdeskRowRecordMapper rowMapper = new SqlDataMapper().new HelpdeskRowRecordMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(rowMapper.getClass(), helpdeskDao.getHelpdeskForId(1L, 1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getChecklistItemsForHelpdeskNullTest() { + List<ChecklistItem> checklistItems = new ArrayList<>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(checklistItems.getClass(), helpdeskDao.getChecklistItemsForHelpdesk(1L, 1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskAdminsNullTest() { + Mockito.when(jdbcTemplate.queryForList(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, helpdeskDao.getHelpdeskAdmins(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateHelpdeskUsersNullTest() { + Helpdesk helpdesk = new Helpdesk(); + helpdesk.setUserIds(Arrays.asList(1L, 2L)); + helpdesk.setAllowAllUsers(false); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, helpdeskDao.addUpdateHelpdeskUsers(helpdesk)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteTypeForHelpdeskNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, helpdeskDao.deleteTypeForHelpdesk(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteWorkflowForHelpdeskTypeNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, helpdeskDao.deleteWorkflowForHelpdeskType(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteChecklistForHelpdeskTypeNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, helpdeskDao.deleteChecklistForHelpdeskType(1L, 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndHelpDeskIdNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, helpdeskDao.getAppIdAndHelpDeskId()); + } + + @SuppressWarnings("unchecked") + @Test + public void getHelpdeskObjectFromHelpdeskIdNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, helpdeskDao.getHelpdeskObjectFromHelpdeskId()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAdminForHelpeskIdNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, helpdeskDao.getAdminForHelpeskId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getUsersForHelpeskIdNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>(), helpdeskDao.getUsersForHelpeskId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteTypeForHelpdeskTrueTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, helpdeskDao.deleteTypeForHelpdesk(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteWorkflowForHelpdeskTypeTrueTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, helpdeskDao.deleteWorkflowForHelpdeskType(1L)); + } + +} diff --git a/src/test/java/org/upsmf/grievance/dao/impl/RoleDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/RoleDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..825e73714433de25449dea04ab33f14aee9a4b8f --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/RoleDaoImplTest.java @@ -0,0 +1,124 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; + +import java.util.ArrayList; + +import org.upsmf.grievance.dao.impl.RoleDaoImpl; +import org.upsmf.grievance.dao.impl.SuperAdminDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.model.Role; + +public class RoleDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @InjectMocks + RoleDaoImpl roleDao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Spy + private RoleDaoImpl role; + + @Spy + private SuperAdminDaoImpl superAdmin; + + @SuppressWarnings("unchecked") + @Test + public void saveRoleTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(new Role().getClass(), roleDao.saveRole(new Role()).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void updateRoleTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(new Role().getClass(), roleDao.updateRole(new Role()).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllRolesTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(new ArrayList<Role>()); + assertEquals(0, roleDao.getAllRoles(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void findByIdTest() { + Mockito.when( + jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(String.class))) + .thenReturn("d"); + assertEquals("d", roleDao.findById(new Role())); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrgRolesTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenReturn(new ArrayList<Role>()); + assertEquals(0, roleDao.getAllOrgRoles().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void saveRoleNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(null, roleDao.saveRole(new Role())); + } + + @SuppressWarnings("unchecked") + @Test + public void updateRoleNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(null, roleDao.updateRole(new Role())); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllRolesNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, roleDao.getAllRoles(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void findByIdNullTest() { + Mockito.when( + jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(String.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, roleDao.findById(new Role())); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrgRolesNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>(), roleDao.getAllOrgRoles()); + } + +} diff --git a/src/test/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..86ab970b10a22978b3cd9755fcfe7f9fcacf4ac5 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/SuperAdminDaoImplTest.java @@ -0,0 +1,179 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.upsmf.grievance.dao.impl.SuperAdminDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; + +public class SuperAdminDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @InjectMocks + SuperAdminDaoImpl superAdminDao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrganizationTest() { + List<Organization> list = new ArrayList<>(); + Organization org = new Organization(); + org.setId(1L); + list.add(org); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(list); + assertEquals(1, superAdminDao.getAllOrganization().size()); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteOrganizationTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, superAdminDao.deleteOrganization(new Organization())); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteOrganizationFalseTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, superAdminDao.deleteOrganization(new Organization())); + } + + @SuppressWarnings("unchecked") + @Test + public void getOrganizationByUserIdTest() { + List<Organization> list = new ArrayList<>(); + Organization org = new Organization(); + org.setId(1L); + list.add(org); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(list); + assertEquals(1, superAdminDao.getOrganizationByUserId(1l)); + } + + @SuppressWarnings("unchecked") + @Test + public void mapUserToOrgTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, superAdminDao.mapUserToOrg(1L, 2)); + } + + @SuppressWarnings("unchecked") + @Test + public void mapUserToOrgFalseTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, superAdminDao.mapUserToOrg(1L, 2)); + } + + @SuppressWarnings("unchecked") + @Test + public void userDetailsByUserIdTest() { + List<User> list = new ArrayList<>(); + User user = new User(); + user.setId(4L); + list.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(list); + assertEquals(4L, superAdminDao.userDetailsByUserId(1L).getId().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void mapAppsToOrgTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, superAdminDao.mapAppsToOrg(new StatusIdMap())); + } + + @SuppressWarnings("unchecked") + @Test + public void getOrganizationByUserTest() { + List<Organization> list = new ArrayList<>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(list); + assertEquals(0, list.size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrganizationNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>(), superAdminDao.getAllOrganization()); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteOrganizationNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, superAdminDao.deleteOrganization(new Organization())); + } + + @SuppressWarnings("unchecked") + @Test + public void getOrganizationByUserIdNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(0, superAdminDao.getOrganizationByUserId(1l)); + } + + @SuppressWarnings("unchecked") + @Test + public void mapUserToOrgNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, superAdminDao.mapUserToOrg(1L, 2)); + } + + @SuppressWarnings("unchecked") + @Test + public void userDetailsByUserIdNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(null, superAdminDao.userDetailsByUserId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void mapAppsToOrgNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, superAdminDao.mapAppsToOrg(new StatusIdMap())); + } + + @SuppressWarnings("unchecked") + @Test + public void getOrganizationByUserNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>(), superAdminDao.getOrganizationByUser(1L)); + } +} diff --git a/src/test/java/org/upsmf/grievance/dao/impl/TicketDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/TicketDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1c2e54cf1bcb53c3ac53b95e9e26d0d3f46d2655 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/TicketDaoImplTest.java @@ -0,0 +1,337 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.upsmf.grievance.dao.impl.TicketDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.KeyHolder; + +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.dto.TicketWorkflowDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.ChecklistItem; +import org.upsmf.grievance.model.KeyFactory; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.Updates; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ KeyFactory.class }) +public class TicketDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @InjectMocks + TicketDaoImpl ticketdao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void deleteWorkflowForTicketTypeTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.deleteWorkflowForTicketType(1L)); + } + + @Test + public void deleteWorkflowForTicketTypeFalseTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, ticketdao.deleteWorkflowForTicketType(1L)); + } + + @Test + public void deleteChecklistForTicketTypeTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.deleteChecklistForTicketType(new TicketTypeDto())); + } + + @Test + public void deleteChecklistForTicketTypeFalseTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, ticketdao.deleteChecklistForTicketType(new TicketTypeDto())); + } + + @SuppressWarnings("unchecked") + @Test + public void getWorkflowForTicketTest() { + TicketWorkflowDto t = new TicketWorkflowDto(); + t.setId(1L); + List<TicketWorkflowDto> ticketWorkFlow = new ArrayList<>(); + ticketWorkFlow.add(t); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(ticketWorkFlow); + assertEquals(1L, ticketdao.getWorkflowForTicket(1L).get(0).getId().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateUpdatesToTicket() { + Updates u = new Updates(); + u.setId(1L); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.addUpdateUpdatesToTicket(u)); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateUpdatesToTicketNull() { + Updates u = new Updates(); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.addUpdateUpdatesToTicket(u)); + } + + @SuppressWarnings("unchecked") + @Test + public void getUpdatesForTicketTest() { + Updates u = new Updates(); + u.setId(1L); + List<Updates> update = new ArrayList<>(); + update.add(u); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(update); + assertEquals(1L, ticketdao.getUpdatesForTicket(1L).get(0).getId().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void getTemplatesVersionTest() { + Updates u = new Updates(); + u.setId(1L); + List<Updates> update = new ArrayList<>(); + update.add(u); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class))).thenReturn(1L); + assertEquals(1L, ticketdao.getTemplatesVersion().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void updateTemplateVersionTest() { + Updates u = new Updates(); + u.setId(1L); + List<Updates> update = new ArrayList<>(); + update.add(u); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.updateTemplateVersion(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getTicketCCTest() { + List<Long> l = Arrays.asList(1L, 2L, 3L); + Mockito.when(jdbcTemplate.queryForList(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(l); + assertEquals(3, ticketdao.getTicketCC(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void updateTicketChecklistFalseTest() { + Ticket ticket = new Ticket(); + List<ChecklistItem> cc = new ArrayList<>(); + ChecklistItem e = new ChecklistItem(); + e.setId(1L); + cc.add(e); + ticket.setChecklist(cc); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertEquals(true, ticketdao.updateTicketChecklist(ticket)); + } + + @SuppressWarnings("unchecked") + @Test + public void updateTicketChecklistTest() { + Ticket ticket = new Ticket(); + List<ChecklistItem> cc = new ArrayList<>(); + ChecklistItem e = new ChecklistItem(); + e.setId(1L); + cc.add(e); + ticket.setChecklist(cc); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(0); + assertEquals(false, ticketdao.updateTicketChecklist(ticket)); + } + + @SuppressWarnings("unchecked") + @Test + public void getActivityLogsPerTicketTest() { + List<ActivityLog> activityLogs = new ArrayList<>(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(activityLogs); + assertEquals(activityLogs.getClass(), ticketdao.getActivityLogsPerTicket(1L).getClass()); + } + + + + + + + + + + + + + + + + @Test + public void getLastInsertIdTest() { + KeyHolder keyHolder = mock(KeyHolder.class); + Mockito.when(keyHolder.getKey()).thenReturn(1L); + PowerMockito.mockStatic(KeyFactory.class); + PowerMockito.when(KeyFactory.getkeyHolder()).thenReturn(keyHolder); + when(jdbcTemplate.update(Matchers.any(PreparedStatementCreator.class), Matchers.any(KeyHolder.class))) + .thenReturn(1); + assertEquals(1L, ticketdao.getLastInsertId("d").longValue()); + } + + @Test + public void addTicketActivityLogTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(1); + assertNull(ticketdao.addTicketActivityLog(1L, "d", 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getChecklistItemsForTicketTest() { + ChecklistItem checklist = new ChecklistItem(); + checklist.setId(1L); + List<ChecklistItem> checklistItems = new ArrayList<>(); + checklistItems.add(checklist); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(checklistItems); + assertEquals(1L, ticketdao.getChecklistItemsForTicket(1L).get(0).getId().longValue()); + } + + @Test + public void keepOnlyCreatedAndCopiedToTicketsTest() { + Ticket ticket = new Ticket(); + ticket.setId(1L); + ticket.setRequestedBy(1L); + List<Long> cc = Arrays.asList(1L, 2L, 4L); + ticket.setCc(cc); + List<Ticket> t = new ArrayList<>(); + t.add(ticket); + assertEquals(new ArrayList<Ticket>().getClass(), ticketdao.keepOnlyCreatedAndCopiedToTickets(1L, t).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteWorkflowForTicketTypeNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, ticketdao.deleteWorkflowForTicketType(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void deleteChecklistForTicketTypeNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, ticketdao.deleteChecklistForTicketType(new TicketTypeDto())); + } + + @SuppressWarnings("unchecked") + @Test + public void getWorkflowForTicketNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(0, ticketdao.getWorkflowForTicket(1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void addUpdateUpdatesToNullTicket() { + Updates u = new Updates(); + u.setId(1L); + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, ticketdao.addUpdateUpdatesToTicket(u)); + } + + @SuppressWarnings("unchecked") + @Test + public void getUpdatesForTicketNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(ticketdao.getUpdatesForTicket(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getTemplatesVersionNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0L, ticketdao.getTemplatesVersion().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void updateTemplateVersionNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, ticketdao.updateTemplateVersion(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void updateTicketChecklistNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, ticketdao.updateTicketChecklist(new Ticket())); + } + + @SuppressWarnings("unchecked") + @Test + public void getActivityLogsPerTicketNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(ticketdao.getActivityLogsPerTicket(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void addTicketActivityLogNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertNull(ticketdao.addTicketActivityLog(1L, "d", 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getChecklistItemsForTicketNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<ChecklistItem>().getClass(), ticketdao.getChecklistItemsForTicket(1L).getClass()); + } + +} diff --git a/src/test/java/org/upsmf/grievance/dao/impl/UserDaoImplTest.java b/src/test/java/org/upsmf/grievance/dao/impl/UserDaoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1db2b3355e0b7d4bbfa75e144b015b85c9393a3f --- /dev/null +++ b/src/test/java/org/upsmf/grievance/dao/impl/UserDaoImplTest.java @@ -0,0 +1,529 @@ +package org.upsmf.grievance.dao.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.upsmf.grievance.dao.impl.SuperAdminDaoImpl; +import org.upsmf.grievance.dao.impl.UserDaoImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import org.upsmf.grievance.dto.OrgUserRoleDto; +import org.upsmf.grievance.dto.UserDto; +import org.upsmf.grievance.model.Action; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.MasterData; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.UserAuthentication; +import org.upsmf.grievance.model.mapper.SqlDataMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserDetailsMapper; +import org.upsmf.grievance.model.mapper.SqlDataMapper.UserRoleMapper; + +@RunWith(MockitoJUnitRunner.class) +public class UserDaoImplTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @Spy + private SuperAdminDaoImpl superAdminDao; + + @InjectMocks + UserDaoImpl userdao; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllActionsByRoleIdTest() { + Action action = new Action(); + action.setId(1L); + List<Action> actions = new ArrayList<>(); + actions.add(action); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(actions); + List<Action> act = userdao.findAllActionsByRoleID(1); + assertEquals(1, act.size()); + } + + @Test + public void getAuthIdTest() { + User user = new User(); + user.setId(1L); + List<User> users = new ArrayList<>(); + users.add(user); + Mockito.doReturn(2).when(superAdminDao).getOrganizationByUserId(1L); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Integer.class))) + .thenReturn(1); + assertEquals(1, userdao.getAuthId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void findOneTest() { + User user = new User(); + user.setId(1L); + user.setName("jay"); + List<User> users = new ArrayList<>(); + users.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(users); + assertEquals(new ArrayList<>().getClass(), userdao.findOne(1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findOneuserAuthenticationTest() { + UserAuthentication user = new UserAuthentication(); + user.setAuthToken("abcd"); + List<UserAuthentication> users = new ArrayList<>(); + users.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(users); + assertEquals("abcd", userdao.findOneUserAuthentication(1L).getAuthToken()); + } + + @Test + public void insertIntoPasswordTest() { + UserAuthentication user = new UserAuthentication(); + user.setAuthToken("abcd"); + List<UserAuthentication> users = new ArrayList<>(); + users.add(user); + Mockito.when(jdbcTemplate.update(anyString(), Matchers.<Object[]>anyVararg())).thenReturn(5); + assertEquals(5, userdao.insertIntoPassword(1L, "d")); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllRolesByUserTest() { + UserRoleMapper mapper = new SqlDataMapper().new UserRoleMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(null); + assertEquals(mapper.getClass(), userdao.findAllRolesByUser(1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findListOfUsersTest() { + List<Long> users = Arrays.asList(1L, 2L); + UserDetailsMapper mapper = new SqlDataMapper().new UserDetailsMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(null); + assertEquals(mapper.getClass(), userdao.findListOfUsers(users).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllTest() { + User user = new User(); + user.setId(1L); + user.setName("jay"); + List<User> users = new ArrayList<>(); + users.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenReturn(users); + assertEquals("jay", userdao.findAll(1L).get(0).getName()); + } + + @SuppressWarnings("unchecked") + @Test + public void getNumberOfUsersNTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenReturn(5L); + assertEquals(5L, userdao.getNumberOfUsers(null, false).longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void getNumberOfUsersNNTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenReturn(5L); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class))).thenReturn(5L); + assertEquals(5L, userdao.getNumberOfUsers(null, null).longValue()); + } + + @Test + public void checkUserNameExistsTest() { + UserAuthentication user = new UserAuthentication(); + user.setAuthToken("abcd"); + List<UserAuthentication> users = new ArrayList<>(); + users.add(user); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenReturn(5L); + assertEquals(5L, userdao.checkUserNameExists("d").longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void getNumberOfRolesTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class))).thenReturn(5L); + assertEquals(5L, userdao.getNumberOfRoles().longValue()); + } + + @Test + public void invalidateTokenTest() { + Mockito.when(jdbcTemplate.update(anyString(), Matchers.<Object[]>anyVararg())).thenReturn(5); + assertEquals(true, userdao.invalidateToken("d")); + } + + @Test + public void findUserByTokenTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenReturn(5L); + assertEquals(true, userdao.findUserByToken("d")); + } + + @Test + public void checkUserTokenExistsTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(5L); + assertEquals(true, userdao.checkUserTokenExists(1L, "d")); + } + + @Test + public void fetchAuthTokenReferenceTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(5L); + assertEquals(5L, userdao.fetchAuthTokenReference("d a").longValue()); + } + + @Test + public void getFirstAdminsOfOrgTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class), Matchers.<Object[]>anyVararg())) + .thenReturn(5L); + assertEquals(true, userdao.getFirstAdminsOfOrg(1L)); + } + + @Test + public void getFirstAdminsOfOrgNTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class), Matchers.<Object[]>anyVararg())) + .thenReturn(null); + assertEquals(false, userdao.getFirstAdminsOfOrg(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void onBoardingCheckTest() { + List<MasterData> masterDataCheckList = new ArrayList<>(); + MasterData m = new MasterData(); + m.setField("u"); + m.setCount(5L); + masterDataCheckList.add(m); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(masterDataCheckList); + assertEquals(false, userdao.onBoardingCheck(1L, 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getUserProfileTest() { + User user = new User(); + user.setId(1L); + user.setName("jay"); + List<User> users = new ArrayList<>(); + users.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(users); + assertEquals(user.getId(), userdao.getUserProfile(1L).getId()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrgUsersTest() { + List<OrgUserRoleDto> orgUserList = new ArrayList<>(); + OrgUserRoleDto o = new OrgUserRoleDto(); + o.setId(5L); + orgUserList.add(o); + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))).thenReturn(orgUserList); + assertEquals(1, userdao.getAllOrgUsers().size()); + } + + /* + * @SuppressWarnings("unchecked") + * + * @Test public void getAllUserRoles() { List<OrgUserRoleDto> orgUserList = new + * ArrayList<>(); OrgUserRoleDto o = new OrgUserRoleDto(); o.setId(5L); + * orgUserList.add(o); Mockito.when(jdbcTemplate.query(Mockito.anyString(), + * Mockito.any(RowMapper.class))).thenReturn(orgUserList); assertEquals(1, + * userdao.getAllUserRoles().size()); } + */ + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndHelpDeskId() { + List<HelpDeskApp> helpdeskAppList = new ArrayList<>(); + HelpDeskApp o = new HelpDeskApp(); + o.setAppId(5L); + helpdeskAppList.add(o); + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenReturn(helpdeskAppList); + assertEquals(1, userdao.getAppIdAndHelpDeskId().size()); + } + + @Test + public void isPasswordMatchTest() { + Mockito.when( + jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(String.class))) + .thenReturn("abcd"); + assertEquals(false, userdao.isPasswordMatch(1L, "d")); + } + + @Test + public void forgotPasswordTest() { + UserDto userDto = new UserDto(); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(2L); + assertEquals(2L, userdao.forgotPassword(userDto)); + } + + @Test + public void saveForgotPasswordTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())).thenReturn(2); + assertEquals(true, userdao.saveForgotPassword(1, "d")); + } + + @SuppressWarnings("unchecked") + @Test + public void getUserDetailsByEmailTest() { + User user = new User(); + user.setId(1L); + user.setName("jay"); + List<User> users = new ArrayList<>(); + users.add(user); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenReturn(users); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenReturn(2L); + assertEquals(2L, userdao.getUserDetailsByEmail("d").getOrgId().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllActionsByRoleIdNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(0, userdao.findAllActionsByRoleID(1).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getAuthIdNullTest() { + Mockito.doReturn(2).when(superAdminDao).getOrganizationByUserId(1L); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Integer.class))) + .thenThrow(NullPointerException.class); + assertEquals(0, userdao.getAuthId(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void findOneNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(new ArrayList<>().getClass(), userdao.findOne(1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findOneuserAuthenticationNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(userdao.findOneUserAuthentication(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllRolesByUserNullTest() { + UserRoleMapper mapper = new SqlDataMapper().new UserRoleMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(mapper.getClass(), userdao.findAllRolesByUser(1L).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findListOfUsersNullTest() { + List<Long> users = Arrays.asList(1L, 2L); + UserDetailsMapper mapper = new SqlDataMapper().new UserDetailsMapper(); + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(mapper.getClass(), userdao.findListOfUsers(users).getClass()); + } + + @SuppressWarnings("unchecked") + @Test + public void findAllNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(userdao.findAll(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getNumberOfUsersNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0L, userdao.getNumberOfUsers(1L, false).longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void checkUserNameExistsNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0L, userdao.checkUserNameExists("d").longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void getNumberOfRolesNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0L, userdao.getNumberOfRoles().longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void invalidateTokenNullTest() { + Mockito.when(jdbcTemplate.update(anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.invalidateToken("d")); + } + + @SuppressWarnings("unchecked") + @Test + public void findUserByTokenNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.any(Object[].class), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.findUserByToken("d")); + } + + @SuppressWarnings("unchecked") + @Test + public void checkUserTokenExistsNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.checkUserTokenExists(1L, "d")); + } + + @SuppressWarnings("unchecked") + @Test + public void fetchAuthTokenReferenceNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0L, userdao.fetchAuthTokenReference("d a").longValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void getFirstAdminsOfOrgNullTest() { + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), eq(Long.class), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.getFirstAdminsOfOrg(1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void onBoardingCheckNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.onBoardingCheck(1L, 1L)); + } + + @SuppressWarnings("unchecked") + @Test + public void getAllOrgUsersNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(userdao.getAllOrgUsers()); + } + + /* + * @SuppressWarnings("unchecked") + * + * @Test public void getAllUserRolesNullTest() { + * Mockito.when(jdbcTemplate.query(Mockito.anyString(), + * Mockito.any(RowMapper.class))) .thenThrow(NullPointerException.class); + * assertNull(userdao.getAllUserRoles()); } + */ + + @SuppressWarnings("unchecked") + @Test + public void getAppIdAndHelpDeskIdNullTest() { + Mockito.when(jdbcTemplate.query(Matchers.anyString(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + assertNull(userdao.getAppIdAndHelpDeskId()); + } + + @SuppressWarnings("unchecked") + @Test + public void isPasswordMatchNullTest() { + Mockito.when( + jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(String.class))) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.isPasswordMatch(1L, "d")); + } + + @SuppressWarnings("unchecked") + @Test + public void forgotPasswordNullTest() { + UserDto userDto = new UserDto(); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertEquals(0, userdao.forgotPassword(userDto)); + } + + @SuppressWarnings("unchecked") + @Test + public void saveForgotPasswordNullTest() { + Mockito.when(jdbcTemplate.update(Matchers.anyString(), Matchers.<Object[]>anyVararg())) + .thenThrow(NullPointerException.class); + assertEquals(false, userdao.saveForgotPassword(1, "d")); + } + + @SuppressWarnings("unchecked") + @Test + public void getUserDetailsByEmailNullTest() { + Mockito.when( + jdbcTemplate.query(Matchers.anyString(), Matchers.<Object[]>anyVararg(), Matchers.any(RowMapper.class))) + .thenThrow(NullPointerException.class); + Mockito.when(jdbcTemplate.queryForObject(Matchers.anyString(), Matchers.<Object[]>anyVararg(), eq(Long.class))) + .thenThrow(NullPointerException.class); + assertNull(userdao.getUserDetailsByEmail("d")); + } + +} diff --git a/src/test/java/org/upsmf/grievance/service/impl/ApplicationServiceImplTest.java b/src/test/java/org/upsmf/grievance/service/impl/ApplicationServiceImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1c9abd25b31e51ace19444a2dc0d40561fb33831 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/service/impl/ApplicationServiceImplTest.java @@ -0,0 +1,86 @@ +package org.upsmf.grievance.service.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.upsmf.grievance.service.impl.ApplicationServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import org.upsmf.grievance.dao.ApplicationDao; +import org.upsmf.grievance.model.App; +import org.upsmf.grievance.model.Role; +import org.upsmf.grievance.model.ServiceRequest; +import org.upsmf.grievance.model.StatusIdMap; +import org.upsmf.grievance.model.User; + +public class ApplicationServiceImplTest { + + @Mock + ApplicationDao applicationDao; + + @InjectMocks + ApplicationServiceImpl applicationService; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void createAppTest() { + Mockito.when(applicationDao.createApp(Matchers.any(App.class), Matchers.any(User.class))).thenReturn(new App()); + Mockito.when(applicationDao.updateApp(Matchers.any(App.class), Matchers.any(User.class))).thenReturn(new App()); + assertEquals(new App().getClass(), applicationService.createApp(new App(), new User()).getClass()); + App a = new App(); + a.setId(5L); + assertEquals(new App().getClass(), applicationService.createApp(a, new User()).getClass()); + } + + @Test + public void getAppTestTrue() { + Mockito.when(applicationDao.getApp(Matchers.any(Long.class))).thenReturn(new ArrayList<App>()); + Mockito.when(applicationDao.getAllApps()).thenReturn(new ArrayList<App>()); + Mockito.when(applicationDao.getAppsByOrgId(Matchers.any(Long.class))).thenReturn(new ArrayList<App>()); + assertEquals(0, applicationService.getApp(null, "a", new User()).size()); + assertEquals(0, applicationService.getApp(1L, "a", new User()).size()); + User user = new User(); + Role role = new Role(); + role.setName("SuperAdmin"); + user.setRoles(Arrays.asList(role)); + assertEquals(0, applicationService.getApp(null, "a", user).size()); + user.setOrgId(1L); + assertEquals(0, applicationService.getApp(null, "a", user).size()); + } + + @Test + public void mapAppsToHelpdeskTest() { + Mockito.when(applicationDao.mapAppsToHelpdesk(Matchers.any(StatusIdMap.class))).thenReturn(true); + assertEquals(true, applicationService.mapAppsToHelpdesk(new StatusIdMap())); + } + + @Test + public void getServiceRequestsTest() { + Mockito.when(applicationDao.getServiceRequests()).thenReturn(new ArrayList<ServiceRequest>()); + assertEquals(0, applicationService.getServiceRequests().size()); + } + + @Test + public void getAppIdAndAppObjectTest() { + Mockito.when(applicationDao.getAppIdAndAppObject()).thenReturn(new ArrayList<App>()); + assertEquals(0, applicationService.getAppIdAndAppObject().size()); + } + + @Test + public void getAppTest() { + Mockito.when(applicationDao.getAppsByOrgId(Matchers.any(Long.class))).thenReturn(new ArrayList<App>()); + assertEquals(0, applicationService.getApp(1L).size()); + } +} diff --git a/src/test/java/org/upsmf/grievance/service/impl/HelpdeskServiceImplTest.java b/src/test/java/org/upsmf/grievance/service/impl/HelpdeskServiceImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..14d861d0dfbaa9786acaa7ae7da756ca35ecf7ab --- /dev/null +++ b/src/test/java/org/upsmf/grievance/service/impl/HelpdeskServiceImplTest.java @@ -0,0 +1,116 @@ +package org.upsmf.grievance.service.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.upsmf.grievance.service.impl.HelpdeskServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; + +import org.upsmf.grievance.dao.HelpdeskDao; +import org.upsmf.grievance.dto.HelpdeskDto; +import org.upsmf.grievance.dto.HelpdeskTypeDto; +import org.upsmf.grievance.model.HelpDeskApp; +import org.upsmf.grievance.model.Helpdesk; +import org.upsmf.grievance.model.User; +import org.upsmf.grievance.model.mapper.SqlDataMapper.HelpdeskRowRecordMapper; + +public class HelpdeskServiceImplTest { + + @Mock + HelpdeskDao helpdeskDao; + + @Spy + HelpdeskServiceImpl helpdesk; + + @InjectMocks + HelpdeskServiceImpl helpdeskService; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void createUpdateHelpdeskTest() { + Mockito.when(helpdeskDao.createUpdateHelpdesk(Matchers.any(Helpdesk.class))).thenReturn(true); + Mockito.doReturn(true).when(helpdesk).configureHelpdesk(Matchers.any(HelpdeskDto.class), + Matchers.any(User.class)); + assertEquals(true, helpdeskService.createUpdateHelpdesk(new HelpdeskDto(), new User())); + } + + @Test + public void getHelpdeskByIdTest() { + Mockito.when(helpdeskDao.getHelpdeskForId(Matchers.anyLong(), Matchers.anyLong())).thenReturn(null); + Mockito.doNothing().when(helpdesk).createHelpdeskListFromRowRecords(Matchers.any(HelpdeskRowRecordMapper.class), + Matchers.anyListOf(HelpdeskDto.class)); + Mockito.doNothing().when(helpdesk).getAppsForHelpdesk(Matchers.anyListOf(HelpdeskDto.class)); + Mockito.doNothing().when(helpdesk).getAdminForHelpdesk(Matchers.anyListOf(HelpdeskDto.class)); + Mockito.doNothing().when(helpdesk).getUsersForHelpdesk(Matchers.anyListOf(HelpdeskDto.class)); + assertEquals(0, helpdeskService.getHelpdeskById(1L, 1L).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void configureHelpdeskTest() { + List<HelpdeskDto> helpdeskList = new ArrayList<>(); + HelpdeskDto helpdeskDto = new HelpdeskDto(); + helpdeskDto.setId(1L); + HelpdeskTypeDto type = new HelpdeskTypeDto(); + type.setId(1L); + List<HelpdeskTypeDto> types = new ArrayList<>(); + types.add(type); + helpdeskDto.setTypes(types); + helpdeskList.add(helpdeskDto); + Mockito.when(helpdeskDao.deleteTypeForHelpdesk(Matchers.anyLong())).thenReturn(true); + Mockito.when(helpdeskDao.deleteWorkflowForHelpdeskType(Matchers.anyLong())).thenReturn(true); + Mockito.when(helpdeskDao.deleteChecklistForHelpdeskType(Matchers.anyLong(), Matchers.anyLong())) + .thenReturn(true); + Mockito.when(helpdeskDao.addTypeForHelpdesk(Matchers.any(HelpdeskTypeDto.class), Matchers.anyLong())) + .thenReturn(true); + Mockito.when(helpdeskDao.addWorkflowForHelpdeskType(Matchers.any(HelpdeskTypeDto.class))).thenReturn(true); + Mockito.when(helpdeskDao.addChecklistForHelpdeskType(Matchers.any(HelpdeskTypeDto.class), Matchers.anyLong())) + .thenReturn(true); + assertTrue(helpdeskService.configureHelpdesk(helpdeskDto, new User())); + } + + @Test + public void getHelpdeskTest() { + Mockito.when(helpdeskDao.getAllHelpdesks(Matchers.anyLong())).thenReturn(new ArrayList<HelpdeskDto>()); + assertEquals(0, helpdeskService.getHelpdesk(1L).size()); + } + + @Test + public void addUpdateHelpdeskAdminsTest() { + Mockito.when(helpdeskDao.addUpdateHelpdeskAdmins(Matchers.any(Helpdesk.class))).thenReturn(true); + assertEquals(true, helpdeskService.addUpdateHelpdeskAdmins(new Helpdesk(), new User())); + } + + @Test + public void getHelpdeskAdminsTest() { + Mockito.when(helpdeskDao.getHelpdeskAdmins(Matchers.anyLong())).thenReturn(new ArrayList<Long>()); + assertEquals(0, helpdeskService.getHelpdeskAdmins(1L).size()); + } + + @Test + public void getAppIdAndHelpDeskIdTest() { + Mockito.when(helpdeskDao.getAppIdAndHelpDeskId()).thenReturn(new ArrayList<HelpDeskApp>()); + assertEquals(0, helpdeskService.getAppIdAndHelpDeskId().size()); + } + + @Test + public void getHelpdeskObjectFromHelpdeskIdTest() { + Mockito.when(helpdeskDao.getHelpdeskObjectFromHelpdeskId()).thenReturn(new ArrayList<Helpdesk>()); + assertEquals(0, helpdeskService.getHelpdeskObjectFromHelpdeskId().size()); + } + +} \ No newline at end of file diff --git a/src/test/java/org/upsmf/grievance/service/impl/RoleServiceImplTest.java b/src/test/java/org/upsmf/grievance/service/impl/RoleServiceImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..a0e1a8b55c8267f9de5084bb673d4190839913fe --- /dev/null +++ b/src/test/java/org/upsmf/grievance/service/impl/RoleServiceImplTest.java @@ -0,0 +1,62 @@ +package org.upsmf.grievance.service.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.upsmf.grievance.service.impl.RoleActionServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import org.upsmf.grievance.dao.RoleDao; +import org.upsmf.grievance.model.Role; + +public class RoleServiceImplTest { + + @Mock + RoleDao roleDao; + + @InjectMocks + RoleActionServiceImpl roleService; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void saveRoleTest() { + Mockito.when(roleDao.saveRole(Matchers.any(Role.class))).thenReturn(new Role()); + assertEquals(new Role().getClass(), roleService.saveRole(new Role()).getClass()); + } + + @Test + public void updateRoleTest() { + Mockito.when(roleDao.updateRole(Matchers.any(Role.class))).thenReturn(new Role()); + assertEquals(new Role().getClass(), roleService.updateRole(new Role()).getClass()); + } + + @Test + public void getAllRolesTest() { + Mockito.when(roleDao.getAllRoles(Matchers.anyLong())).thenReturn(new ArrayList<Role>()); + assertEquals(0, roleService.getAllRoles(1L).size()); + } + + @Test + public void findByIdTest() { + Mockito.when(roleDao.findById(Matchers.any(Role.class))).thenReturn("d"); + assertEquals("d", roleService.findById(new Role())); + } + + @Test + public void getAllOrgRolesTest() { + Mockito.when(roleDao.getAllOrgRoles()).thenReturn(new ArrayList<Role>()); + assertEquals(0, roleService.getAllOrgRoles().size()); + } + +} \ No newline at end of file diff --git a/src/test/java/org/upsmf/grievance/service/impl/SuperAdminImplTest.java b/src/test/java/org/upsmf/grievance/service/impl/SuperAdminImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9b1c85c578a0b32bcba36d73d1f33f6bf41dc0ed --- /dev/null +++ b/src/test/java/org/upsmf/grievance/service/impl/SuperAdminImplTest.java @@ -0,0 +1,75 @@ +package org.upsmf.grievance.service.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.upsmf.grievance.service.impl.SuperAdminServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import org.upsmf.grievance.dao.SuperAdminDao; +import org.upsmf.grievance.model.Organization; +import org.upsmf.grievance.model.StatusIdMap; + +public class SuperAdminImplTest { + + @Mock + SuperAdminDao superAdminDao; + + @InjectMocks + SuperAdminServiceImpl superAdminService; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getAllOrganizationTest() { + Mockito.when(superAdminDao.getAllOrganization()).thenReturn(new ArrayList<Organization>()); + assertEquals(0, superAdminService.getAllOrganization().size()); + } + + @Test + public void addOrganizationTest() { + Mockito.when(superAdminDao.addOrganization(Matchers.any(Organization.class))).thenReturn(new Organization()); + assertEquals(new Organization().getClass(), superAdminService.addOrganization(new Organization()).getClass()); + } + + @Test + public void updateOrganizationByIdTest() { + Mockito.when(superAdminDao.updateOrganizationById(Matchers.any(Organization.class))).thenReturn(true); + assertEquals(true, superAdminService.updateOrganizationById(new Organization())); + } + + /* + * @Test public void getOrganizationByIdTest() { + * Mockito.when(superAdminDao.getOrganizationById(Mockito.anyLong())).thenReturn + * (new Organization()); assertEquals(new Organization().getClass(), + * superAdminService.getOrganizationById(1L).getClass()); } + */ + + @Test + public void deleteOrganizationTest() { + Mockito.when(superAdminDao.deleteOrganization(Matchers.any(Organization.class))).thenReturn(true); + assertEquals(true, superAdminService.deleteOrganization(new Organization())); + } + + @Test + public void mapAppsToOrgTest() { + Mockito.when(superAdminDao.mapAppsToOrg(Matchers.any(StatusIdMap.class))).thenReturn(true); + assertEquals(true, superAdminService.mapAppsToOrg(new StatusIdMap())); + } + + @Test + public void getOrganizationByUserIdTest() { + Mockito.when(superAdminDao.getOrganizationByUser(Matchers.anyLong())).thenReturn(new ArrayList<Organization>()); + assertEquals(0, superAdminService.getOrganizationByUserId(1L).size()); + } +} diff --git a/src/test/java/org/upsmf/grievance/service/impl/TicketServiceImplTest.java b/src/test/java/org/upsmf/grievance/service/impl/TicketServiceImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..b438952450cb3efd9fac7ec3e4293e96f4fdc182 --- /dev/null +++ b/src/test/java/org/upsmf/grievance/service/impl/TicketServiceImplTest.java @@ -0,0 +1,124 @@ +package org.upsmf.grievance.service.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.upsmf.grievance.service.impl.TicketServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.springframework.web.multipart.MultipartFile; + +import org.upsmf.grievance.dao.TicketDao; +import org.upsmf.grievance.dto.TicketTypeDto; +import org.upsmf.grievance.model.ActivityLog; +import org.upsmf.grievance.model.Ticket; +import org.upsmf.grievance.model.TicketElastic; +import org.upsmf.grievance.model.Updates; +import org.upsmf.grievance.model.User; + +public class TicketServiceImplTest { + + @Mock + TicketDao ticketDao; + + @InjectMocks + TicketServiceImpl ticketService; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getTemplatesVersionTest() { + Mockito.when(ticketDao.getTemplatesVersion()).thenReturn(1L); + assertEquals(1L, ticketService.getTemplatesVersion().longValue()); + } + + @Test + public void updateTicketBasicTest() { + Mockito.when(ticketDao.updateTicketBasic(Matchers.any(MultipartFile.class), Matchers.any(Ticket.class))) + .thenReturn(true); + MultipartFile file = null; + assertEquals(true, ticketService.updateTicketBasic(file, new Ticket())); + } + + @Test + public void getTicketsByIdTest() { + Mockito.when(ticketDao.getTicketsById(Matchers.anyLong(), Matchers.anyLong())).thenReturn(new Ticket()); + assertEquals(new Ticket().getClass(), ticketService.getTicketsById(new User(), 1L).getClass()); + } + + @Test + public void getAllTicketsByAppIdTest() { + Mockito.when(ticketDao.getAllTicketsByAppId(Matchers.anyLong())).thenReturn(new ArrayList<Ticket>()); + assertEquals(0, ticketService.getAllTicketsByAppId(1L).size()); + } + + @Test + public void updateNotesToTicketTest() { + Mockito.when(ticketDao.updateNotesToTicket(Matchers.anyLong(), Matchers.anyLong(), Matchers.anyString())) + .thenReturn(true); + assertEquals(true, ticketService.updateNotesToTicket(new Ticket())); + } + + @Test + public void addUpdateUpdatesToTicketTest() { + Mockito.when(ticketDao.addUpdateUpdatesToTicket(Matchers.any(Updates.class))).thenReturn(true); + assertEquals(true, ticketService.addUpdateUpdatesToTicket(new Updates())); + } + + @Test + public void updateTicketTypeTest() { + Mockito.when(ticketDao.updateTicketType(Matchers.any(TicketTypeDto.class), Matchers.anyLong())) + .thenReturn(true); + assertEquals(true, ticketService.updateTicketType(new TicketTypeDto(), 1L)); + } + + @Test + public void getUpdatesForTicketTest() { + Mockito.when(ticketDao.getUpdatesForTicket(Matchers.anyLong())).thenReturn(new ArrayList<Updates>()); + assertEquals(0, ticketService.getUpdatesForTicket(1L).size()); + } + + @Test + public void updateTicketStatusTest() { + Mockito.when(ticketDao.updateTicketStatus(Matchers.any(Ticket.class))).thenReturn(true); + assertEquals(true, ticketService.updateTicketStatus(new Ticket())); + } + + @Test + public void updateTicketChecklistTest() { + Mockito.when(ticketDao.updateTicketStatus(Matchers.any(Ticket.class))).thenReturn(true); + assertEquals(false, ticketService.updateTicketChecklist(new Ticket())); + } + + @Test + public void getActivityLogsPerTicketTest() { + Mockito.when(ticketDao.getActivityLogsPerTicket(Matchers.anyLong())).thenReturn(new ArrayList<ActivityLog>()); + assertEquals(0, ticketService.getActivityLogsPerTicket(1L).size()); + } + + @Test + public void getTicketDetailsByHelpdeskIdTest() { + Mockito.when(ticketDao.getTicketDetailsByHelpdeskId(Matchers.any(Ticket.class))) + .thenReturn(new ArrayList<TicketElastic>()); + assertEquals(0, ticketService.getTicketDetailsByHelpdeskId(new Ticket()).size()); + } + + /* + * @Test public void keepOnlyCreatedAndCopiedToTicketsTest() { + * Mockito.when(ticketDao.keepOnlyCreatedAndCopiedToTickets(Mockito.anyLong(), + * Mockito.anyListOf(Ticket.class), + * Mockito.anyListOf(Ticket.class))).thenReturn(new ArrayList<Ticket>()); + * assertEquals(0, ticketService .keepOnlyCreatedAndCopiedToTickets(1L, new + * ArrayList<Ticket>(), new ArrayList<Ticket>()).size()); } + */ + +}