Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
LaMartin-Webomagic
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pratik Shrivastava
LaMartin-Webomagic
Commits
76a79024
Commit
76a79024
authored
Jul 01, 2024
by
Deep Dey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add api to download admission information with list of ids
parent
acb6faa9
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
372 additions
and
1 deletion
+372
-1
lamartinBackend/pom.xml
lamartinBackend/pom.xml
+14
-0
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
...aMartin/admission/controller/AdmissionFormController.java
+52
-1
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/controller/AdmissionFormDAOController.java
.../admission/dao/controller/AdmissionFormDAOController.java
+4
-0
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/repository/AdmissionFormDataRepository.java
...admission/dao/repository/AdmissionFormDataRepository.java
+9
-0
lamartinBackend/src/main/java/com/example/LaMartin/common/service/PdfService.java
.../java/com/example/LaMartin/common/service/PdfService.java
+20
-0
lamartinBackend/src/main/java/com/example/LaMartin/common/service/TemplateService.java
.../com/example/LaMartin/common/service/TemplateService.java
+24
-0
lamartinBackend/src/main/resources/templates/AdmissionFormListTemplate.html
...c/main/resources/templates/AdmissionFormListTemplate.html
+239
-0
lamartinBackend/src/main/resources/templates/FormAutoReplyTemplate.html
...d/src/main/resources/templates/FormAutoReplyTemplate.html
+10
-0
No files found.
lamartinBackend/pom.xml
View file @
76a79024
...
@@ -131,6 +131,20 @@
...
@@ -131,6 +131,20 @@
<artifactId>
springdoc-openapi-ui
</artifactId>
<artifactId>
springdoc-openapi-ui
</artifactId>
<version>
1.7.0
</version>
<version>
1.7.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
<dependency>
<groupId>
org.xhtmlrenderer
</groupId>
<artifactId>
flying-saucer-pdf-openpdf
</artifactId>
<version>
9.1.22
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.11.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
lamartinBackend/src/main/java/com/example/LaMartin/admission/controller/AdmissionFormController.java
View file @
76a79024
...
@@ -3,11 +3,14 @@ package com.example.LaMartin.admission.controller;
...
@@ -3,11 +3,14 @@ package com.example.LaMartin.admission.controller;
import
com.example.LaMartin.admission.dao.controller.AdmissionFormDAOController
;
import
com.example.LaMartin.admission.dao.controller.AdmissionFormDAOController
;
import
com.example.LaMartin.admission.model.AdmissionFormData
;
import
com.example.LaMartin.admission.model.AdmissionFormData
;
import
com.example.LaMartin.common.model.GeneralResponse
;
import
com.example.LaMartin.common.model.GeneralResponse
;
import
com.example.LaMartin.common.service.PdfService
;
import
com.example.LaMartin.common.service.TemplateService
;
import
com.example.LaMartin.constants.AppConstants
;
import
com.example.LaMartin.constants.AppConstants
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponse
;
import
io.swagger.annotations.ApiResponses
;
import
io.swagger.annotations.ApiResponses
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
...
@@ -16,13 +19,21 @@ import org.springframework.web.bind.annotation.*;
...
@@ -16,13 +19,21 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.io.ByteArrayInputStream
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
@RestController
@RestController
@AllArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
@AllArgsConstructor
(
onConstructor
=
@__
(
@Autowired
))
public
class
AdmissionFormController
{
public
class
AdmissionFormController
{
private
final
AdmissionFormDAOController
admissionFormDAOController
;
private
final
AdmissionFormDAOController
admissionFormDAOController
;
private
final
TemplateService
templateService
;
private
final
PdfService
pdfService
;
@PostMapping
(
@PostMapping
(
value
=
"/admission-form/submit"
,
value
=
"/admission-form/submit"
,
...
@@ -73,7 +84,7 @@ public class AdmissionFormController {
...
@@ -73,7 +84,7 @@ public class AdmissionFormController {
@RequestHeader
(
"apikey"
)
String
apiKey
@RequestHeader
(
"apikey"
)
String
apiKey
)
throws
Exception
{
)
throws
Exception
{
//TODO: validation of api key using redis
//
TODO: validation of api key using redis
return
new
ResponseEntity
<>(
return
new
ResponseEntity
<>(
new
GeneralResponse
(
new
GeneralResponse
(
true
,
true
,
...
@@ -83,4 +94,44 @@ public class AdmissionFormController {
...
@@ -83,4 +94,44 @@ public class AdmissionFormController {
),
),
HttpStatus
.
OK
);
HttpStatus
.
OK
);
}
}
@GetMapping
(
value
=
"/admission-form/download-form"
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"SUCCESS"
),
@ApiResponse
(
code
=
400
,
message
=
"FAILED"
),
@ApiResponse
(
code
=
500
,
message
=
"Exception Occurred"
)
})
@ApiOperation
(
value
=
""
)
public
void
downloadAdmissionForm
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
"apikey"
)
String
apiKey
,
@RequestParam
(
"formIds"
)
String
formIds
)
throws
Exception
{
// TODO: validation of api key using redis
List
<
Long
>
formIdList
=
Stream
.
of
(
formIds
.
split
(
","
))
.
map
(
Long:
:
valueOf
)
.
collect
(
Collectors
.
toList
());
if
(
formIdList
.
isEmpty
())
{
throw
new
Exception
(
"Provide formIds to download"
);
}
List
<
AdmissionFormData
>
admissionFormDataList
=
this
.
admissionFormDAOController
.
getAdmissionFormDataListByIds
(
formIdList
);
if
(
admissionFormDataList
.
isEmpty
())
{
throw
new
Exception
(
"No Admission Data Found"
);
}
String
output
=
templateService
.
generateAdmissionFormListTemplate
(
admissionFormDataList
);
ByteArrayInputStream
pdfStream
=
pdfService
.
convertHtmlToPdf
(
output
);
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename=admission-form-list.pdf"
);
IOUtils
.
copy
(
pdfStream
,
response
.
getOutputStream
());
}
}
}
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/controller/AdmissionFormDAOController.java
View file @
76a79024
...
@@ -50,4 +50,8 @@ public class AdmissionFormDAOController {
...
@@ -50,4 +50,8 @@ public class AdmissionFormDAOController {
return
admissionFormDataRepository
.
getAdmissionFormDataList
();
return
admissionFormDataRepository
.
getAdmissionFormDataList
();
}
}
public
List
<
AdmissionFormData
>
getAdmissionFormDataListByIds
(
List
<
Long
>
idList
)
{
return
admissionFormDataRepository
.
getAdmissionFormDataListByIds
(
idList
);
}
}
}
lamartinBackend/src/main/java/com/example/LaMartin/admission/dao/repository/AdmissionFormDataRepository.java
View file @
76a79024
...
@@ -119,4 +119,13 @@ public class AdmissionFormDataRepository {
...
@@ -119,4 +119,13 @@ public class AdmissionFormDataRepository {
String
sql
=
"SELECT * FROM admission_form_data"
;
String
sql
=
"SELECT * FROM admission_form_data"
;
return
namedParameterJdbcTemplate
.
query
(
sql
,
new
AdmissionFormMapper
());
return
namedParameterJdbcTemplate
.
query
(
sql
,
new
AdmissionFormMapper
());
}
}
public
List
<
AdmissionFormData
>
getAdmissionFormDataListByIds
(
List
<
Long
>
ids
)
{
String
sql
=
"SELECT * FROM admission_form_data WHERE id IN (:ids)"
;
MapSqlParameterSource
parameters
=
new
MapSqlParameterSource
();
parameters
.
addValue
(
"ids"
,
ids
);
return
namedParameterJdbcTemplate
.
query
(
sql
,
parameters
,
new
AdmissionFormMapper
());
}
}
}
lamartinBackend/src/main/java/com/example/LaMartin/common/service/PdfService.java
0 → 100644
View file @
76a79024
package
com
.
example
.
LaMartin
.
common
.
service
;
import
org.springframework.stereotype.Service
;
import
org.xhtmlrenderer.pdf.ITextRenderer
;
import
java.io.*
;
@Service
public
class
PdfService
{
public
ByteArrayInputStream
convertHtmlToPdf
(
String
htmlContent
)
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ITextRenderer
renderer
=
new
ITextRenderer
();
renderer
.
setDocumentFromString
(
htmlContent
);
renderer
.
layout
();
renderer
.
createPDF
(
outputStream
,
false
);
renderer
.
finishPDF
();
return
new
ByteArrayInputStream
(
outputStream
.
toByteArray
());
}
}
lamartinBackend/src/main/java/com/example/LaMartin/common/service/TemplateService.java
0 → 100644
View file @
76a79024
package
com
.
example
.
LaMartin
.
common
.
service
;
import
com.example.LaMartin.admission.model.AdmissionFormData
;
import
lombok.AllArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.thymeleaf.TemplateEngine
;
import
org.thymeleaf.context.Context
;
import
java.util.List
;
@Service
@AllArgsConstructor
(
onConstructor_
=
@__
({
@Autowired
})
)
public
class
TemplateService
{
private
final
TemplateEngine
templateEngine
;
public
String
generateAdmissionFormListTemplate
(
List
<
AdmissionFormData
>
admissionFormDataList
)
{
Context
context
=
new
Context
();
context
.
setVariable
(
"admissionFormList"
,
admissionFormDataList
);
return
templateEngine
.
process
(
"AdmissionFormListTemplate"
,
context
);
}
}
lamartinBackend/src/main/resources/templates/AdmissionFormListTemplate.html
0 → 100644
View file @
76a79024
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
lang=
"en"
>
<head>
<title>
Information Table
</title>
<style>
*
{
font-family
:
Arial
,
sans-serif
;
margin
:
0
;
padding
:
0
;
}
body
{
width
:
100%
;
}
.container
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
flex-direction
:
column
;
width
:
100%
;
}
.table-container
{
width
:
100%
;
padding
:
20px
;
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
justify-content
:
center
;
}
table
{
width
:
100%
;
border-collapse
:
collapse
;
}
th
,
td
{
padding
:
10px
;
text-align
:
left
;
}
th
{
background-color
:
#4CAF50
;
color
:
white
;
font-size
:
14px
;
}
td
{
background-color
:
#f9f9f9
;
border-bottom
:
1px
solid
#ddd
;
font-size
:
12px
;
}
tr
:hover
td
{
background-color
:
#f1f1f1
;
}
tr
:nth-child
(
even
)
td
{
background-color
:
#f2f2f2
;
}
th
:first-child
,
td
:first-child
{
width
:
30%
;
}
th
:nth-child
(
2
),
td
:nth-child
(
2
)
{
width
:
70%
;
}
.title
{
/*text-align: center;*/
font-size
:
18px
;
margin-bottom
:
10px
;
color
:
#333
;
font-weight
:
bold
;
}
</style>
</head>
<body>
<div
class=
"container"
th:each=
"admissionForm : ${admissionFormList}"
>
<div
class=
"table-container"
>
<div
class=
"title"
>
Candidate Information (
<span
th:text=
"${admissionForm.fullName}"
></span>
)
</div>
<table>
<tr>
<th>
Field
</th>
<th>
Information
</th>
</tr>
<tr>
<td>
Choose your school
</td>
<td
th:text=
"${admissionForm.school}"
></td>
</tr>
<tr>
<td>
Category
</td>
<td
th:text=
"${admissionForm.category}"
></td>
</tr>
<tr>
<td>
Full Name
</td>
<td
th:text=
"${admissionForm.fullName}"
></td>
</tr>
<tr>
<td>
Class
</td>
<td
th:text=
"${admissionForm.admissionClass}"
></td>
</tr>
<tr>
<td>
Date of Birth (YYYY-MM-DD)
</td>
<td
th:text=
"${admissionForm.dateOfBirth}"
></td>
</tr>
<tr>
<td>
Nationality
</td>
<td
th:text=
"${admissionForm.nationality}"
></td>
</tr>
<tr>
<td>
Religion
</td>
<td
th:text=
"${admissionForm.religion}"
></td>
</tr>
<tr>
<td>
Mother Tongue
</td>
<td
th:text=
"${admissionForm.motherTongue}"
></td>
</tr>
<tr>
<td>
Community
</td>
<td
th:text=
"${admissionForm.community}"
></td>
</tr>
<tr>
<td>
Marital Status
</td>
<td
th:text=
"${admissionForm.maritalStatus}"
></td>
</tr>
<tr>
<td>
Father's Name
</td>
<td
th:text=
"${admissionForm.fatherName}"
></td>
</tr>
<tr>
<td>
Father's Contact Number
</td>
<td
th:text=
"${admissionForm.fatherMobile}"
></td>
</tr>
<tr>
<td>
Father's Email
</td>
<td
th:text=
"${admissionForm.fatherEmail}"
></td>
</tr>
<tr>
<td>
Father's Nationality
</td>
<td
th:text=
"${admissionForm.fatherNationality}"
></td>
</tr>
<tr>
<td>
Father's Religion
</td>
<td
th:text=
"${admissionForm.fatherReligion}"
></td>
</tr>
<tr>
<td>
Father's Mother Tongue
</td>
<td
th:text=
"${admissionForm.fatherMotherTongue}"
></td>
</tr>
<tr>
<td>
Father's Community
</td>
<td
th:text=
"${admissionForm.fatherCommunity}"
></td>
</tr>
<tr>
<td>
Father's School Info
</td>
<td
th:text=
"${admissionForm.fatherSchoolInfo}"
></td>
</tr>
<tr>
<td>
Father's College Info
</td>
<td
th:text=
"${admissionForm.fatherCollegeInfo}"
></td>
</tr>
<tr>
<td>
Father's University Info
</td>
<td
th:text=
"${admissionForm.fatherUniversityInfo}"
></td>
</tr>
<tr>
<td>
Father's Professional Qualification
</td>
<td
th:text=
"${admissionForm.fatherProfessionalQualification}"
></td>
</tr>
<tr>
<td>
Father's Occupation
</td>
<td
th:text=
"${admissionForm.fatherOccupation}"
></td>
</tr>
<tr>
<td>
Father's Monthly Income
</td>
<td
th:text=
"${admissionForm.fatherMonthlyIncome}"
></td>
</tr>
<tr>
<td>
Father's Workplace Info
</td>
<td
th:text=
"${admissionForm.fatherWorkplaceInfo}"
></td>
</tr>
<tr>
<td>
Mother's Name
</td>
<td
th:text=
"${admissionForm.motherName}"
></td>
</tr>
<tr>
<td>
Mother's Contact Number
</td>
<td
th:text=
"${admissionForm.motherMobile}"
></td>
</tr>
<tr>
<td>
Mother's Email
</td>
<td
th:text=
"${admissionForm.motherEmail}"
></td>
</tr>
<tr>
<td>
Mother's Nationality
</td>
<td
th:text=
"${admissionForm.motherNationality}"
></td>
</tr>
<tr>
<td>
Mother's Religion
</td>
<td
th:text=
"${admissionForm.motherReligion}"
></td>
</tr>
<tr>
<td>
Mother's Mother Tongue
</td>
<td
th:text=
"${admissionForm.motherMotherTongue}"
></td>
</tr>
<tr>
<td>
Mother's Community
</td>
<td
th:text=
"${admissionForm.motherCommunity}"
></td>
</tr>
<tr>
<td>
Mother's School Info
</td>
<td
th:text=
"${admissionForm.motherSchoolInfo}"
></td>
</tr>
<tr>
<td>
Mother's College Info
</td>
<td
th:text=
"${admissionForm.motherCollegeInfo}"
></td>
</tr>
<tr>
<td>
Mother's University Info
</td>
<td
th:text=
"${admissionForm.motherUniversityInfo}"
></td>
</tr>
<tr>
<td>
Mother's Professional Qualification
</td>
<td
th:text=
"${admissionForm.motherProfessionalQualification}"
></td>
</tr>
<tr>
<td>
Mother's Occupation
</td>
<td
th:text=
"${admissionForm.motherOccupation}"
></td>
</tr>
<tr>
<td>
Mother's Monthly Income
</td>
<td
th:text=
"${admissionForm.motherMonthlyIncome}"
></td>
</tr>
<tr>
<td>
Mother's Workplace Info
</td>
<td
th:text=
"${admissionForm.motherWorkplaceInfo}"
></td>
</tr>
</table>
</div>
</div>
</body>
</html>
\ No newline at end of file
lamartinBackend/src/main/resources/templates/FormAutoReplyTemplate.html
0 → 100644
View file @
76a79024
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
lang=
"en"
>
<head>
<title>
Title
</title>
</head>
<body>
<h1
th:text=
"${title}"
>
Title
</h1>
<p
th:text=
"${content}"
>
Content goes here...
</p>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment