...
Create Your Own Web Application
Create Directories and Files
First you will need to create this directory structure in your <frevvo-install-dir>\frevvo\tomcat\webapps folder:
Code Block <frevvo-install-dir>\frevvo\tomcat\webapps |_submission-report-tutorial |_WEB-INF |_lib
Create a new web.xml file in <frevvo-install-dir>\frevvo\tomcat\webapps\submission-report-tutorial\WEB-INF directory, with following content in it. This will define our application as a web application.
Code Block <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> </web-app>
- Copy the frevvo client APIs from <frevvo-install-dir>\frevvo\ext\client directory to the <frevvo-install-dir>\frevvo\tomcat\webapps\submission-report-tutorial\WEB-INF\lib directory. These are the frevvo API libraries which will be called by our web application.
Create the JSP pages which call the frevvo API as explained in this documentation. Create a showReport.jsp file in <frevvo-install-dir>\frevvo\tomcat\webapps\submission-report-tutorial directory with following in it:
Code Block linenumbers true <%@ page import="java.lang.*,java.util.*,com.frevvo.forms.client.*,com.frevvo.forms.client.util.*,com.google.gdata.data.Link,java.io.InputStream,com.google.gdata.client.Service.GDataRequest,java.io.IOException,javax.xml.parsers.*,org.xml.sax.*,org.xml.sax.helpers.DefaultHandler,com.google.gdata.util.ServiceException" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Vacation Report</title> </head> <body id="page-submissions"> <% //Get the frevvo Forms service FormsService service = (FormsService) session.getAttribute ( "frevvo.forms.service" ); if (service != null) { service.logout(); session.removeAttribute ("frevvo.forms.service"); } else { service = new FormsService("http", "localhost", 8082, null); } service.login ("designer@tutorial", "password"); session.setAttribute ("frevvo.forms.service", service); String uId = request.getParameter("username"); //Get the value of username paramter in the request URL if ((uId == null) || (uId.length() == 0)) { uId = "dummy"; //Use a dummy user if username is not specified in the request URL. } %>
Info title More info about this code - The Java code in this content will create the session for frevvo service and login to frevvo using your designer username and password.
- We are also verifying the value of username parameter that is sent in the request URL. If a parameter is retrieved then we will display the vacation report for that user, but if the parameter value is null then we will retrieve nothing.
- Note character sequences <% and %>. All the Java code should be written between these character sequences. We will write the Java code in between HTML tags so as to embed the results returned by API calls into this JSP page in HTML format.
Remember to change
Code Block service.login ("designer@tutorial", "qa");
to
Code Block service.login ("<your-designer-user>@<your-tenant>", "<designer-user-password>");
Get the Submission Feed
Now that we have the frevvo service session, we will get the submission feed of our workflow. Add following lines to the showReport.jsp file before the closing tag (%>):
Code Block |
---|
//Get the Submission Feed
SubmissionQuery q = new SubmissionQuery(service.getFeedURL(SubmissionFeed.class));
String ftId = "_gJZX8O62EeCXN_lW5l3omQ"; //This is the formTypeId of our workflow.
q.setFilter("$formTypeId eq " + ftId);
q.setOrderby("$updated"); //Order the submissions by Date
SubmissionFeed sFeed = service.getFeed(q, SubmissionFeed.class);
int totalLeaves = 0; //Counter for total number of leaves taken by the employee. |
Info | ||
---|---|---|
| ||
|
...
HTML for Vacation Reports Table
Add the HTML to create our vacation reports table structure:
Code Block language xml <div id="bd"> <div id="workarea"> <h2>Vacation Report </h2> <table border="1" cellpadding="6" cellspacing="0" width="50%"> <thead> <tr> <td><b>Start Date</b></td> <td><b>Number Of Days</b></td> <td><b>Type Of Leave</b></td> <td><b>Approved/Denied</b></td> </tr> </thead> <tbody>
Now to display the leave records under this table, we will get all the submission records from the SubmissionFeed. Then we get the Submission XML for all the submissions and parse it to get the relevant data from each submission. Add following in your showReport.jsp file:
Code Block <% //Loop over all the submissions for (SubmissionEntry entry : sFeed.getEntries()) { if(entry.getState().equalsIgnoreCase("SUBMITTED")) { //Consider only those submissions which are in Completed, that is in Submitted state //Get the submission XML Link dLink = (Link) entry.getDocumentLinks("text/xml").get(0); String linkRef = dLink != null ? dLink.getHref() : ""; GDataRequest request1 = service.createLinkQueryRequest(dLink); request1.execute(); InputStream responseStream = request1.getResponseStream(); try { // Parse the submission XML (using the XMLContentHandler class which has SAX Parser configurations) XMLContentHandler xch = new XMLContentHandler();; xch.parse(responseStream); Map<String, String> submittedControlMap = xch.getParams(); if((submittedControlMap.get("EId").equals(uId)) && (submittedControlMap.get("StartDate").contains(Integer.toString(Calendar.getInstance().get(Calendar.YEAR))))) { //Get only current year's submissions and for only a particular employee if(submittedControlMap.get("IApproveThisVacationRequest").equals("Approved")) //Check if the Leave was approved or not totalLeaves = totalLeaves + Integer.parseInt(submittedControlMap.get("NumberOfDays")); %>
Info title More info about this section Here we are looping over all the SubmissionEntries in the SubmissionFeed.
We check if the State of the entry (that is the submission) has value as 'SUBMITTED'. This is because there maybe other submissions with states like 'SAVED' which should not be the part of our report as they are not yet completed.
Then we get the submission XML from that entry and parse it. To parse the XML we will be using the SaxParser which is implemented in the XMLContentHandler class.
The parsed values are stored in a hash map 'submittedControlMap'.
We decide if the leave should be considered in the total leaves count for that employee by checking if:
The leave was taken by the user whose username was passed in the username parameter of the request URL
The StartDate for this leave is within current year.
The leave was Approved by the manager.
Once the submission passes all criteria we need to print it in our HTML. For that we add these lines:. (Note the character sequences <%= and %> which enclose Java expressions, which are evaluated at run time.)
Note the character sequences <%= and %> which enclose Java expressions, which are evaluated at run time.Code Block <tr> <%-- Print the extracted data --%> <td><%= submittedControlMap.get("StartDate") %></td> <td><%= submittedControlMap.get("NumberOfDays") %></td> <td><%= submittedControlMap.get("TypeOfLeave") %></td> <td><%= submittedControlMap.get("IApproveThisVacationRequest") %></td> </tr> <% } } catch (Exception e) { e.printStackTrace(); } } } %> <tr> <td colspan="4"><b>Total Leaves Taken: <%= totalLeaves %> </b></td> </tr> </tbody> </table> </div> </div> </body> </html>
- Save the showReport.jsp file and re-start frevvo.
- Then browseBrowse: http://localhost:8082/submission-report-tutorial/showReport.jsp?username=demoemployee in your browser and see the vacation report for demoemployee.