Skip to content

Commit a7f8807

Browse files
author
rajshah1
committed
62. Management Report Create API (Prod Ready)#9
1 parent 1ff26bf commit a7f8807

File tree

4 files changed

+156
-31
lines changed

4 files changed

+156
-31
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package HeaderFooterPageEvent;
2+
3+
import com.itextpdf.awt.geom.Rectangle;
4+
import com.itextpdf.text.Chunk;
5+
import com.itextpdf.text.Document;
6+
import com.itextpdf.text.DocumentException;
7+
8+
import com.itextpdf.text.Paragraph;
9+
import com.itextpdf.text.pdf.PdfPageEventHelper;
10+
import com.itextpdf.text.pdf.PdfWriter;
11+
12+
public class HeaderFooterUtils extends PdfPageEventHelper {
13+
14+
public void onStartPage(PdfWriter writer,Document document,String dateformatorfirst, String dateformatorlast) throws DocumentException {
15+
//com.itextpdf.text.Rectangle rect = writer.getBoxSize("art");
16+
//ColumnText.showTextAligned(writer.getDirectContent(),Element.ALIGN_CENTER, new Chunk(
17+
// "\n MANAGMENT REPORT FOR PERIOD : " + dateformatorfirst + " - " + dateformatorlast + "\n \n"), rect.getLeft(), rect.getTop(), 0);
18+
19+
20+
document.add(new Paragraph(new Chunk("\n MANAGMENT REPORT FOR PERIOD : " + dateformatorfirst + " - " + dateformatorlast + "\n \n")));
21+
22+
}
23+
24+
/*
25+
* public void onEndPage(PdfWriter writer, Document document) {
26+
* com.itextpdf.text.Rectangle rect = writer.getBoxSize("art");
27+
* ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
28+
* new Phrase("Bottom Left"), rect.getLeft(), rect.getBottom(), 0);
29+
* ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
30+
* new Phrase("Bottom Right"), rect.getRight(), rect.getBottom(), 0); }
31+
*/
32+
}

src/main/java/systems/rajshah/controller/FdProjectUserController.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import org.springframework.http.ResponseEntity;
1111
import org.springframework.web.bind.annotation.GetMapping;
1212
import org.springframework.web.bind.annotation.PathVariable;
13+
import org.springframework.web.bind.annotation.RequestBody;
1314
import org.springframework.web.bind.annotation.RestController;
1415

1516
import com.google.firebase.auth.FirebaseAuthException;
1617
import com.itextpdf.text.DocumentException;
1718

19+
import systems.rajshah.model.QueryObjectDetails;
1820
import systems.rajshah.service.IFirebaseUserOperartions;
1921

2022
@RestController
@@ -33,4 +35,18 @@ public ResponseEntity<InputStreamResource> fullstatByClientID(@PathVariable("id"
3335
return ResponseEntity.ok().headers(headers).contentType(MediaType.APPLICATION_PDF)
3436
.body(new InputStreamResource(bis));
3537
}
38+
39+
@GetMapping(value="/{currentUid}/managmentReport")
40+
public ResponseEntity<InputStreamResource> managmentReport(
41+
@PathVariable("currentUid") String currentUid,@RequestBody QueryObjectDetails queryFullDetail)
42+
throws FirebaseAuthException, InterruptedException, ExecutionException, DocumentException {
43+
44+
ByteArrayInputStream bis = ifirebaseusersOp.generateManagementReport(queryFullDetail, currentUid);
45+
HttpHeaders headers = new HttpHeaders();
46+
headers.add("Content-Disposition", "inline; filename=" + "GeneratorReport" + ".pdf");
47+
return ResponseEntity.ok().headers(headers).contentType(MediaType.APPLICATION_PDF)
48+
.body(new InputStreamResource(bis));
49+
}
50+
51+
3652
}

src/main/java/systems/rajshah/service/FirebaseUserImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class FirebaseUserImpl implements IfirebaseUser {
7171
@Override
7272
public UserInfo getCurrentUserDetails(String currentUid)
7373
throws FirebaseAuthException, InterruptedException, ExecutionException {
74-
logger.debug("In getCurrentUserDetails {}", currentUid);
74+
//logger.debug("In getCurrentUserDetails {}", currentUid);
7575
UserRecord uInfo = firebaseAuth.getUser(currentUid);
7676
/*
7777
* ONLY RUN <------ONCE------> This code will create alphacounter document in
@@ -275,15 +275,15 @@ public ByteArrayInputStream generateCustomerIntimationReport(String idVar, Query
275275

276276
}
277277

278-
private static void addMetadata(Document doc, String currentUserName) {
278+
public static void addMetadata(Document doc, String currentUserName) {
279279
doc.addCreationDate();
280280
doc.addCreator(currentUserName);
281281
doc.addAuthor("rajshah.systems");
282282
doc.addLanguage("English");
283283

284284
}
285285

286-
private static void myInfoHeader(Document doc, UserInfo uInfoVal) throws DocumentException {
286+
public static void myInfoHeader(Document doc, UserInfo uInfoVal) throws DocumentException {
287287
String contactInfo = "";
288288
if (uInfoVal.getMobileNo().length() > 12) {
289289
String[] splitval = uInfoVal.getMobileNo().split(",");
@@ -318,7 +318,7 @@ private static void myInfoHeader(Document doc, UserInfo uInfoVal) throws Documen
318318
doc.add(p1);
319319
}
320320

321-
private static void reciverInfoAddress(Document doc, InvestorInfo toWhom) throws DocumentException {
321+
public static void reciverInfoAddress(Document doc, InvestorInfo toWhom) throws DocumentException {
322322
logger.trace("Inside reciverInfoAddress" + toWhom.getFirstName());
323323
if (toWhom.getAddress().length() > 0) {
324324
String[] addressSplit = toWhom.getAddress().toUpperCase().split(",");
@@ -363,7 +363,7 @@ else if (addressSplit.length == 6)
363363
}
364364
}
365365

366-
private static void generalInfoWidrowal(Document doc, QueryObjectDetails queyObject) throws DocumentException {
366+
public static void generalInfoWidrowal(Document doc, QueryObjectDetails queyObject) throws DocumentException {
367367
Calendar cal = Calendar.getInstance();
368368
cal.setTime(queyObject.getInitialDate());
369369
Calendar cal1 = Calendar.getInstance();
@@ -390,7 +390,7 @@ private static void generalInfoWidrowal(Document doc, QueryObjectDetails queyObj
390390
doc.add(line);
391391
}
392392

393-
private static PdfPTable tablegenerator(PdfPTable table) {
393+
public static PdfPTable tablegenerator(PdfPTable table) {
394394

395395
Stream.of("SR", " MATU.DATE \n DEPO.DATE", "INVESTOR NAME", "COMPANY NAME", " DEPO. AMT \n MATU. AMT",
396396
"CERTIFICTE NO.").forEach(e -> {
@@ -583,7 +583,7 @@ public Map<String, ReportGenObject> getReportJSONService(QueryObjectDetails quey
583583
* Generates Single PDF Containing All Client's Maturity Report.<br/>
584584
* Report is evaluated based on Input Date Range for Given Customer UID. <br/>
585585
*
586-
* @implNote This is Fundamental System Requirement And Business Critical API.
586+
* @implNote This is Fundamental System Requirement And Business Critical API Function.
587587
*
588588
* @param queyObjectDetails SearchType , startDate and endDate For Search Query.
589589
* @param currentUserId Current User's 32-Char AlphaNumeric ID.
@@ -597,8 +597,8 @@ public ByteArrayInputStream generateFullClientReport(QueryObjectDetails queyObje
597597
// queyObject.toString());
598598
Map<String, ReportGenObject> reportMetaData = getReportJSONService(queyObject, currentUid);
599599

600-
// logger.debug("In generateFullClientReport reportMetadata : {}",
601-
// reportMetaData);
600+
logger.debug("In generateFullClientReport reportMetadata : {}",
601+
reportMetaData);
602602
Document doc = new Document(PageSize.A4, 10, 10, 5, 5);
603603
ByteArrayOutputStream bout = new ByteArrayOutputStream();
604604
UserInfo uInfo = getCurrentUserDetails(currentUid);
@@ -684,7 +684,7 @@ else if (addressSplit.length == 6)
684684

685685
static int fdInfoListCounterVal = 0;
686686

687-
private static void persistJSONMetadataToTable(Document doc, PdfPTable table, List<FdInfo> dataList)
687+
public static void persistJSONMetadataToTable(Document doc, PdfPTable table, List<FdInfo> dataList)
688688
throws DocumentException {
689689
dataList.parallelStream().forEach(e -> {
690690

src/main/java/systems/rajshah/service/FirebaseUserOperation.java

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package systems.rajshah.service;
55

66
import java.io.ByteArrayInputStream;
7+
import java.io.ByteArrayOutputStream;
78
import java.util.Calendar;
89
import java.util.Date;
10+
import java.util.Map;
911
import java.util.concurrent.ExecutionException;
1012

1113
import org.slf4j.Logger;
@@ -16,59 +18,134 @@
1618
import com.google.cloud.firestore.Firestore;
1719
import com.google.firebase.auth.FirebaseAuth;
1820
import com.google.firebase.auth.FirebaseAuthException;
21+
import com.itextpdf.text.Chunk;
22+
import com.itextpdf.text.Document;
1923
import com.itextpdf.text.DocumentException;
24+
import com.itextpdf.text.PageSize;
25+
import com.itextpdf.text.Paragraph;
26+
import com.itextpdf.text.pdf.PdfPTable;
27+
import com.itextpdf.text.pdf.PdfWriter;
28+
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
2029

21-
30+
import HeaderFooterPageEvent.HeaderFooterUtils;
2231
import systems.rajshah.model.QueryObjectDetails;
32+
import systems.rajshah.model.ReportGenObject;
33+
import systems.rajshah.model.UserInfo;
2334

2435
/**
2536
* @author RAJ SHAH
2637
*
2738
*/
2839
@Service
29-
public class FirebaseUserOperation implements IFirebaseUserOperartions{
40+
public class FirebaseUserOperation implements IFirebaseUserOperartions {
3041
@Autowired
3142
private Firestore firestore;
3243

3344
@Autowired
3445
private FirebaseAuth firebaseAuth;
35-
46+
3647
@Autowired
3748
IfirebaseUser firebaseUserImpl;
38-
49+
50+
// Create a Class Object
51+
// FirebaseUserImpl firebaseUserImplObject =new FirebaseUserImpl();
52+
3953
private static final Logger logger = LoggerFactory.getLogger(FirebaseUserOperation.class);
54+
4055
@Override
4156
public ByteArrayInputStream generateManagementReport(QueryObjectDetails queyObject, String currentUid)
4257
throws FirebaseAuthException, InterruptedException, ExecutionException, DocumentException {
4358
// TODO Auto-generated method stub
44-
return null;
59+
logger.debug("In Generate Managment Report Method");
60+
// Create New Document
61+
Document doc = new Document(PageSize.A4, 10, 10, 5, 5);
62+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
63+
UserInfo uInfo = firebaseUserImpl.getCurrentUserDetails(currentUid);
64+
PdfWriter pdfWrite = PdfWriter.getInstance(doc, bout);
65+
66+
doc.open();
67+
68+
HeaderFooterUtils headerEvent = new HeaderFooterUtils();
69+
Calendar cal = Calendar.getInstance();
70+
cal.setTime(queyObject.getInitialDate());
71+
Calendar cal1 = Calendar.getInstance();
72+
cal1.setTime(queyObject.getLastDate());
73+
74+
String dateformatorfirst = cal.get(Calendar.DAY_OF_MONTH) + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
75+
+ cal.get(Calendar.YEAR);
76+
String dateformatorlast = cal1.get(Calendar.DAY_OF_MONTH) + "/" + (cal1.get(Calendar.MONTH) + 1) + "/"
77+
+ cal1.get(Calendar.YEAR);
78+
headerEvent.onStartPage(pdfWrite, doc, dateformatorfirst, dateformatorlast);
79+
pdfWrite.setPageEvent(headerEvent);
80+
FirebaseUserImpl.addMetadata(doc, uInfo.getName());
81+
82+
// Generate the Data to add to table
83+
Map<String, ReportGenObject> reportMetaData = firebaseUserImpl.getReportJSONService(queyObject, currentUid);
84+
// Add Data to tables
85+
if (reportMetaData.size() == 1 && reportMetaData.containsKey("NO Inputs")) {
86+
doc.add(new Chunk(" \n \n No Data Found For Given Dates . Please Try other Dates"));
87+
doc.close();
88+
return new ByteArrayInputStream(bout.toByteArray());
89+
} else {
90+
reportMetaData.values().stream().forEach(e -> {
91+
92+
try {
93+
94+
DottedLineSeparator line = new DottedLineSeparator();
95+
96+
Paragraph p1 = new Paragraph();
97+
p1.add(new Chunk(
98+
" Family Code : " + e.getFamilyCode() + "------ Family Head : " + e.getFamilyHeadName()));
99+
100+
doc.add(line);
101+
doc.add(p1);
102+
PdfPTable table = new PdfPTable(6);
103+
table.setWidthPercentage(90);
104+
table.setSpacingBefore(8f);
105+
table.setHeaderRows(1);
106+
107+
float[] columnWidths = { 1f, 3f, 4f, 3f, 3f, 4.5f };
108+
table.setWidths(columnWidths);
109+
PdfPTable table1 = FirebaseUserImpl.tablegenerator(table);
110+
table1.setHeaderRows(1);
111+
FirebaseUserImpl.persistJSONMetadataToTable(doc, table1, e.getFdInfo());
112+
113+
doc.add(line);
114+
} catch (DocumentException e1) {
115+
// TODO Auto-generated catch block
116+
logger.error("DocumentException Occurred : {}", e1);
117+
}
118+
119+
});
120+
121+
doc.close();
122+
}
123+
return new ByteArrayInputStream(bout.toByteArray());
45124
}
46125

47126
@Override
48127
public ByteArrayInputStream generateFullReportByFamilyCode(String familyCode, String currentUid)
49128
throws FirebaseAuthException, InterruptedException, ExecutionException, DocumentException {
50129
// TODO Auto-generated method stub
51-
52-
53-
Calendar cal=Calendar.getInstance();
130+
131+
Calendar cal = Calendar.getInstance();
54132
cal.setTime(new Date());
55-
cal.add(Calendar.YEAR,50);
56-
57-
Calendar cal1=Calendar.getInstance();
133+
cal.add(Calendar.YEAR, 50);
134+
135+
Calendar cal1 = Calendar.getInstance();
58136
cal1.setTime(new Date());
59-
cal1.add(Calendar.YEAR,-50);
60-
61-
QueryObjectDetails queryObj=new QueryObjectDetails();
137+
cal1.add(Calendar.YEAR, -50);
138+
139+
QueryObjectDetails queryObj = new QueryObjectDetails();
62140
queryObj.setInitialDate(cal1.getTime());
63141
queryObj.setLastDate(cal.getTime());
64142
queryObj.setSearchField("startDate");
65-
66-
//logger.debug("In Geerate fullstatByClientID "+queryObj.toString());
67-
ByteArrayInputStream fullInfoResp=firebaseUserImpl.generateCustomerIntimationReport(familyCode, queryObj, currentUid);
68-
69-
return fullInfoResp;
70-
}
71143

72-
144+
// logger.debug("In Geerate fullstatByClientID "+queryObj.toString());
145+
ByteArrayInputStream fullInfoResp = firebaseUserImpl.generateCustomerIntimationReport(familyCode, queryObj,
146+
currentUid);
147+
148+
return fullInfoResp;
149+
}
73150

74151
}

0 commit comments

Comments
 (0)