Commit 5c7b3cf8 by Nilu

Adding pdf utils to create applicant report

Using jFreeChart to draw ring chart required for applicant report
parent 6ef88f23
package performa.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import oneit.appservices.config.ConfigMgr;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CenterTextMode;
import org.jfree.chart.plot.RingPlot;
import org.jfree.data.general.DefaultPieDataset;
public class RingChart
{
public static final String tempURLBase = ConfigMgr.getConfigString("CONFIG.GLOBAL", "DocTempURLBase");
public static final Color RED = Color.decode("#FB5D67");
public static final Color GREY = Color.decode("#E5E8EB");
public static final Color AMBER = Color.decode("#FBD44E");
public static final Color GREEN = Color.decode("#41BDB4");
private DefaultPieDataset dataset;
private final List<Color> colors = new ArrayList<>();
private final int height = 150;
private final int width = 150;
private String fileName = "ringchart.jpeg";
public RingChart()
{
this.dataset = new DefaultPieDataset();
}
public RingChart(String title, String filename)
{
this();
this.fileName = filename;
}
public RingChart addData(String cat, Number val, Color color)
{
dataset.setValue(cat, val);
colors.add(color);
return this;
}
public String getChartImage()
{
return getChartImage(width, height);
}
public String getChartImage(int width, int height)
{
JFreeChart chart = ChartFactory.createRingChart("", dataset, false, false, Locale.ENGLISH);
RingPlot plot = (RingPlot) chart.getPlot();
for (int i = 0; i < dataset.getItemCount(); i++)
{
if(i == 0)
{
plot.setCenterText(String.valueOf(dataset.getValue(i)));
}
plot.setSectionPaint(dataset.getKey(i), colors.get(i));
plot.setSectionOutlinePaint(dataset.getKey(i), Color.BLACK);
plot.setSectionOutlineStroke(dataset.getKey(i), new BasicStroke(2));
}
plot.setBackgroundPaint(null);
plot.setOutlineVisible(false);
plot.setLabelGenerator(null);
plot.setShadowPaint(null);
plot.setSectionOutlinesVisible(false);
plot.setSeparatorsVisible(false);
plot.setCenterTextColor(Color.decode("#667281"));
plot.setCenterTextMode(CenterTextMode.FIXED);
plot.setCenterTextFont(new Font("Arial", Font.PLAIN, 28));
try
{
String file = tempURLBase + "/" + fileName;
ChartUtils.saveChartAsJPEG(new File(file), chart, width, height);
return file;
}
catch (IOException ioe)
{
LogMgr.log(LoggingArea.ALL, LogLevel.PROCESSING1, ioe, "Exception occurred while creating Ring Chart.");
}
return null;
}
public static String getRingChart()
{
return new RingChart().addData("Completed", 20, GREEN).addData("Incomplete", 80, GREY).getChartImage();
}
public static void main(String[] args)
{
new RingChart().addData("Completed", 20, GREEN).addData("Incomplete", 80, GREY).getChartImage();
}
}
package performa.form;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oneit.objstore.StorageException;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.portability.FileDownloader;
import oneit.servlets.process.ORMProcessFormProcessor;
import oneit.servlets.process.ORMProcessState;
import oneit.utils.BusinessException;
import oneit.utils.RandomStringGen;
import performa.utils.PDFUtils;
public class ApplicantReportFP extends ORMProcessFormProcessor
{
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map map)
throws BusinessException,
StorageException
{
RandomStringGen rand = new RandomStringGen();
final String randFileName = rand.generateAlphaNum(16) + ".pdf";
final byte[] pdfBytes = PDFUtils.generateApplicantReportSummaryPDF(submission);
return new SuccessfulResult()
{
@Override
public void applyResult(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException
{
FileDownloader.writeData(request, response, pdfBytes, "application/pdf", randFileName, false);
}
};
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ import oneit.utils.DateDiff;
import oneit.utils.ObjectTransform;
import oneit.utils.StringUtils;
import oneit.utils.filter.*;
import performa.chart.RingChart;
import performa.utils.ExpressAnswerFilter;
......@@ -173,4 +174,9 @@ public class Candidate extends BaseCandidate
{
return isTrue(getConditionsAgreed());
}
public String getRingChart()
{
return new RingChart().addData("Completed", 20, RingChart.GREEN).addData("Incomplete", 80, RingChart.GREY).getChartImage();
}
}
\ No newline at end of file
package performa.utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import oneit.appservices.documents.HTML2PDF;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.logging.LoggingArea;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.jsp.DocumentTag;
import oneit.utils.BusinessException;
import oneit.utils.NestedException;
public class PDFUtils
{
public static byte[] generatePDF(SubmissionDetails submission, String jspPage, String jspHeadPage, String margin) throws BusinessException
{
return generatePDF(submission, jspPage, jspHeadPage, margin, new HashMap());
}
public static byte[] generatePDF(SubmissionDetails submission, String jspPage, String jspHeadPage, String margin, Map otherData)
{
final ByteArrayOutputStream out = new ByteArrayOutputStream ();
try
{
Map data = new HashMap();
Map styleMap = new HashMap();
Map marginBoxes = new HashMap();
marginBoxes.put("top-center", "element(header)");
marginBoxes.put("bottom-center", "element(centerFooter) ");
marginBoxes.put("bottom-left", "element(leftFooter) ");
marginBoxes.put("bottom-right", "element(rightFooter) ");
styleMap.put(DocumentTag.PAGE_STYLES_MARGIN_BOXES, marginBoxes);
styleMap.put(DocumentTag.PAGE_STYLES_PAGE_SIZE, "A4 portrait");
styleMap.put(DocumentTag.PAGE_STYLES_FONT_FAMILY, "Arial, Serif");
styleMap.put(DocumentTag.PAGE_STYLES_PAGE_MARGIN, margin);
data.put(DocumentTag.PAGE_STYLES, styleMap);
data.put(DocumentTag.JSP_BODY_INCLUDE, jspPage);
data.put(DocumentTag.JSP_HEAD_INCLUDE, jspHeadPage);
if(otherData != null && !otherData.isEmpty())
{
data.putAll(otherData);
}
HTML2PDF.JSP2PDF(submission, DocumentTag.DEFAULT_DOCUMENT_INCLUDE, data, out, true);
}
catch(IOException e)
{
LogMgr.log(LoggingArea.ALL, LogLevel.SYSTEMERROR1, e);
throw new NestedException(e);
}
return out.toByteArray();
}
public static byte[] generateApplicantReportSummaryPDF(SubmissionDetails submission) throws BusinessException
{
return generatePDF(submission, "/extensions/adminportal/inc/applicant_report.jsp", "/extensions/adminportal/inc/applicant_report_header.jsp", null);
}
}
\ No newline at end of file
......@@ -50,6 +50,7 @@
<FORM name="*.resendVerification" factory="Participant" class="performa.form.ResendVerificationFP">
<AccountVerificationEmailer factory="Participant" class="oneit.email.ConfigurableArticleTemplateEmailer" templateShortcut="EmailChangedMail"/>
</FORM>
<FORM name="*.downloadApplicantReport" factory="Participant" class="performa.form.ApplicantReportFP"/>
<FORM name="*.saveClient" factory="Participant" class="performa.form.SaveClientFP"/>
<FORM name="*.applyCoupon" factory="Participant" class="performa.form.ApplyCouponFP"/>
<FORM name="*.saveCompany" factory="Participant" class="performa.form.SaveCompanyFP"/>
......
<%@ page extends="oneit.servlets.jsp.JSPInclude"%>
<%@ taglib prefix="tagfile" tagdir="/WEB-INF/tags"%>
<%@ include file="/setuprequest.jsp"%>
<%@ page import="oneit.servlets.process.*"%>
<%@ page import="oneit.objstore.*"%>
<%@ page import="performa.orm.*, performa.chart.*"%>
<%
ORMProcessState process = (ORMProcessState) ProcessDecorator.getDefaultProcess(request);
ObjectTransaction objTran = process.getTransaction();
Job job = (Job) process.getAttribute("Job");
JobApplication jobApplication = (JobApplication) process.getAttribute("JobApplication");
Candidate candidate = jobApplication.getCandidate();
%>
<oneit:dynIncluded>
<div class="wrap">
<div class="header">
<div class="chief-officer">
<oneit:toString value="<%= job.getJobTitle() %>" mode="EscapeHTML" />
<%
if(job.getReferenceNumber() != null)
{
%>
&nbsp;(<oneit:toString value="<%= job.getReferenceNumber() %>" mode="EscapeHTML" />)
<%
}
%>
</div>
<div>
<span>
<%
if(job.isClientAvailable())
{
%>
<oneit:toString value="<%= job.getClient() %>" mode="EscapeHTML" />
<%
}
%>
</span> by <oneit:toString value="<%= job.getCreatedBy() %>" mode="EscapeHTML" nullValue=""/>
</div>
<div>
<oneit:toString value="<%= job.getLevel() %>" mode="EscapeHTML" />
</div>
</div>
<div>
<div class="main-appli-name">
<div class="appli-name"><oneit:toString value="<%= candidate.getToString() %>" mode="EscapeHTML"/></div>
<div class="appli-applied">
Applied <oneit:toString value="<%= jobApplication.getSubmittedDate() %>" mode="MidDate"/>
</div>
</div>
<div>
shortlisted
</div>
<div>
<div class="overall-suit">
overall rank
<oneit:toString value="<%= jobApplication.getOverallRank() %>" mode="Integer" />
</div>
</div>
<div class="contact-label">E
<a href="<%= "mailto:" + candidate.getUser().getUserName() %>">
<oneit:toString value="<%= candidate.getUser().getUserName() %>" mode="EscapeHTML" />
</a>
</div>
<div class="contact-row">
<div class="contact-label">P
<oneit:toString value="<%= candidate.getPhone() %>" mode="EscapeHTML" />
</div>
</div>
<div class="contact-row">
<div>Requirements</div>
<div>
<img src="file:///<%= candidate.getRingChart() %>" alt="Pie Chart"/>
</div>
</div>
</div>
</div>
</oneit:dynIncluded>
\ No newline at end of file
<%@ page extends="oneit.servlets.jsp.JSPInclude" %>
<%@include file="../../../setuprequest.jsp" %>
<oneit:dynIncluded>
<style type="text/css" media="print,screen" >
/*@import url("//hello.myfonts.net/count/343a83");*/
@font-face {font-family: 'Usual-Bold';src: url('../../../fonts/343A83_0_0.eot');src: url('../../../fonts/343A83_0_0.eot?#iefix') format('embedded-opentype'),url('../../../fonts/343A83_0_0.woff2') format('woff2'),url('../../../fonts/343A83_0_0.woff') format('woff'),url('../../../fonts/343A83_0_0.ttf') format('truetype');}
@font-face {font-family: 'Usual-Light';src: url('../../../fonts/343A83_1_0.eot');src: url('../../../fonts/343A83_1_0.eot?#iefix') format('embedded-opentype'),url('../../../fonts/343A83_1_0.woff2') format('woff2'),url('../../../fonts/343A83_1_0.woff') format('woff'),url('../../../fonts/343A83_1_0.ttf') format('truetype');}
@font-face {font-family: 'Usual-Medium';src: url('../../../fonts/343A83_2_0.eot');src: url('../../../fonts/343A83_2_0.eot?#iefix') format('embedded-opentype'),url('../../../fonts/343A83_2_0.woff2') format('woff2'),url('../../../fonts/343A83_2_0.woff') format('woff'),url('../../../fonts/343A83_2_0.ttf') format('truetype');}
@font-face {font-family: 'Usual-Regular';src: url('../../../fonts/343A83_3_0.eot');src: url('../../../fonts/343A83_3_0.eot?#iefix') format('embedded-opentype'),url('../../../fonts/343A83_3_0.woff2') format('woff2'),url('../../../fonts/343A83_3_0.woff') format('woff'),url('../../../fonts/343A83_3_0.ttf') format('truetype');}
div.header{background-color: #1a2531;}
.chief-officer {color: #ffffff; text-align: left; font-size: 26px; font-weight: 300; margin-bottom: 15px;}
.appli-name{color: #1A2531; text-align: left; font-size: 26px; font-weight: 300; font-family: "Usual-Light";}
.appli-applied{color: #7d7f82; text-align: left; font-size: 12px; margin-top: 6px;}
@page
{
size: A4 portrait;
@top-left { content: element(header);}
}
</style>
</oneit:dynIncluded>
\ No newline at end of file
......@@ -126,45 +126,49 @@
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job).toMap())
.mapEntry("cancelProcess", true)
.toMap() %>"/>
<oneit:button value=" " cssClass="job-edit-menu-item" name="downloadApplicantReport" skin="link" style="display:none;"
requestAttribs="<%= CollectionUtils.EMPTY_MAP %>">
EXPORT APPLICANT REPORT
</oneit:button>
<a href="#" class="rightbtn job-edit"><img src="images/dot-menu.png"> </a>
<div class="job-edit-menu">
<oneit:button value=" " cssClass="job-edit-menu-item" name="gotoPage" skin="link"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", editJobPage + "&JobID=" + job.getObjectID())
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job).toMap())
// .mapEntry("cancelProcess", true)
.toMap() %>">
EDIT JOB
</oneit:button>
<a href="#" class="job-edit-menu-item">EXPORT APPLICANT REPORT</a>
</div>
</a>
<div class="job-edit-menu">
<oneit:button value=" " cssClass="job-edit-menu-item" name="gotoPage" skin="link"
requestAttribs="<%= CollectionUtils.mapEntry("nextPage", editJobPage + "&JobID=" + job.getObjectID())
.mapEntry("procParams", CollectionUtils.mapEntry("Job", job).toMap())
.toMap() %>">
EDIT JOB
</oneit:button>
<oneit:button value=" " cssClass="job-edit-menu-item" name="downloadApplicantReport" skin="link"
requestAttribs="<%= CollectionUtils.EMPTY_MAP %>">
EXPORT APPLICANT REPORT
</oneit:button>
</div>
<script>
$(function(){
new jBox('Tooltip', {
attach: '.job-edit',
content: $('.job-edit-menu'),
trigger : 'click',
pointer: 'right:30',
pointTo : 'top',
outside : "x",
offset : {y: 45, x : -70},
addClass : "job-edit-pop",
onOpen : function(){
$(".job-edit").addClass('active');
},
onClose : function(){
$(".job-edit").removeClass('active');
},
closeOnClick : "body"
});
});
</script>
</span>
</div>
</div>
<script>
$(function(){
new jBox('Tooltip', {
attach: '.job-edit',
content: $('.job-edit-menu'),
trigger : 'click',
pointer: 'right:30',
pointTo : 'top',
outside : "x",
offset : {y: 45, x : -70},
addClass : "job-edit-pop",
onOpen : function(){
$(".job-edit").addClass('active');
},
onClose : function(){
$(".job-edit").removeClass('active');
},
closeOnClick : "body"
});
});
</script>
</oneit:dynIncluded>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment