|
4 | 4 | package systems.rajshah.service;
|
5 | 5 |
|
6 | 6 | import java.io.ByteArrayInputStream;
|
| 7 | +import java.io.ByteArrayOutputStream; |
7 | 8 | import java.util.Calendar;
|
8 | 9 | import java.util.Date;
|
| 10 | +import java.util.Map; |
9 | 11 | import java.util.concurrent.ExecutionException;
|
10 | 12 |
|
11 | 13 | import org.slf4j.Logger;
|
|
16 | 18 | import com.google.cloud.firestore.Firestore;
|
17 | 19 | import com.google.firebase.auth.FirebaseAuth;
|
18 | 20 | import com.google.firebase.auth.FirebaseAuthException;
|
| 21 | +import com.itextpdf.text.Chunk; |
| 22 | +import com.itextpdf.text.Document; |
19 | 23 | 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; |
20 | 29 |
|
21 |
| - |
| 30 | +import HeaderFooterPageEvent.HeaderFooterUtils; |
22 | 31 | import systems.rajshah.model.QueryObjectDetails;
|
| 32 | +import systems.rajshah.model.ReportGenObject; |
| 33 | +import systems.rajshah.model.UserInfo; |
23 | 34 |
|
24 | 35 | /**
|
25 | 36 | * @author RAJ SHAH
|
26 | 37 | *
|
27 | 38 | */
|
28 | 39 | @Service
|
29 |
| -public class FirebaseUserOperation implements IFirebaseUserOperartions{ |
| 40 | +public class FirebaseUserOperation implements IFirebaseUserOperartions { |
30 | 41 | @Autowired
|
31 | 42 | private Firestore firestore;
|
32 | 43 |
|
33 | 44 | @Autowired
|
34 | 45 | private FirebaseAuth firebaseAuth;
|
35 |
| - |
| 46 | + |
36 | 47 | @Autowired
|
37 | 48 | IfirebaseUser firebaseUserImpl;
|
38 |
| - |
| 49 | + |
| 50 | + // Create a Class Object |
| 51 | + // FirebaseUserImpl firebaseUserImplObject =new FirebaseUserImpl(); |
| 52 | + |
39 | 53 | private static final Logger logger = LoggerFactory.getLogger(FirebaseUserOperation.class);
|
| 54 | + |
40 | 55 | @Override
|
41 | 56 | public ByteArrayInputStream generateManagementReport(QueryObjectDetails queyObject, String currentUid)
|
42 | 57 | throws FirebaseAuthException, InterruptedException, ExecutionException, DocumentException {
|
43 | 58 | // 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()); |
45 | 124 | }
|
46 | 125 |
|
47 | 126 | @Override
|
48 | 127 | public ByteArrayInputStream generateFullReportByFamilyCode(String familyCode, String currentUid)
|
49 | 128 | throws FirebaseAuthException, InterruptedException, ExecutionException, DocumentException {
|
50 | 129 | // TODO Auto-generated method stub
|
51 |
| - |
52 |
| - |
53 |
| - Calendar cal=Calendar.getInstance(); |
| 130 | + |
| 131 | + Calendar cal = Calendar.getInstance(); |
54 | 132 | 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(); |
58 | 136 | 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(); |
62 | 140 | queryObj.setInitialDate(cal1.getTime());
|
63 | 141 | queryObj.setLastDate(cal.getTime());
|
64 | 142 | 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 |
| - } |
71 | 143 |
|
72 |
| - |
| 144 | + // logger.debug("In Geerate fullstatByClientID "+queryObj.toString()); |
| 145 | + ByteArrayInputStream fullInfoResp = firebaseUserImpl.generateCustomerIntimationReport(familyCode, queryObj, |
| 146 | + currentUid); |
| 147 | + |
| 148 | + return fullInfoResp; |
| 149 | + } |
73 | 150 |
|
74 | 151 | }
|
0 commit comments