We are going to create a web-application using the frevvo Data API, which will fetch submissions from the frevvo database and create an HTML report based on those submissions. We will use the Leave Approval Workflow as an example (download it here.) Using this workflow an Employee will file a vacation request, which will be approved by his Manager. This workflow generates a submission XML like this one:
In this tutorial we will get all the submission XMLs for this workflow from the frevvo submission database. Then we will parse the submission XMLs to extract the required data (StartDate, NumberOfDays, TypeOfLeave and IApproveThisVacationRequest fields) for a particular Employee and display this data as a vacation report for that Employee on an HTML page.
Try the Example Application
Install the Web Application
- Download and copy the war file to <frevvo-install-dir>\frevvo\tomcat\webapps directory.
- Re-start frevvo. This will expand the war.
- Edit the <frevvo-install-dir>\frevvo\tomcat\webapps\submission-report-tutorial\showReport.jsp file.
On line number 20, change
- Save the file and re-start frevvo.
Execute the Example Application
- Download the Leave Approval Workflow and upload it in your designer user.
- To check if your web application is working, browse http://<your frevvo server host>:<port>/submission-report-tutorial/showReport.jsp in your browser, E.g. http://localhost:8082/submission-report-tutorial/showReport.jsp. You should see a blank report like this:
- Now, to see the vacation report of an employee:
- As the Tenant Admin
- Create a manager user.
- Create an employee user with the User Id 'demoemployee' and set the Reports To field for this employee user to the manager user that you created above. This will correctly route the flow from employee to manager.
- Create a Role "HR" and another user who has the role "HR." This is where the third step of the workflow will route.
- Login as the employee user and browse the Share URL of your Leave Approval workflow. Then enter details for the leave request and submit the form.
- Login as the manager user and from the manager's task list approve the pending leave approval task for employee.
- Login as the HR user and approve the pending leave approval task.
- As the Tenant Admin
- A submission was created and you should be able to open it from your workflow's submission repository.
Note the '''username=''' parameter that is appended to this URL. This shows submissions for a specific employee. Replace 'demoemployee' with any valid user Id.
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:
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.
- 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:
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
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 (%>):
More info about this section
In these lines we are creating a submission query in q.
Instead of getting all the submissions for all the forms and flows owned by the designer user, we will get the submissions only for our workflow by adding the formTypeID filter to this query as explained in Getting Started with the Data API - Java Client Library Tutorial: Filtering.
You can get the formTypeId for this flow by looking at the Share URL of this flow. For example, if the flows URL is: http://<server:port>/frevvo/web/tn/tutorial/user/designer/app/_N4cF4ZuwEeCwk5wyBHqHrQ/flowtype/_gJZX8O62EeCXN_lW5l3omQ/popupform?locale=, then the bold part of this URL which follows the flowtype is your formTypeId.
HTML for Vacation Reports Table
Add the HTML to create our vacation reports table structure:
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:
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.)
- Save the showReport.jsp file and re-start frevvo.
- Browse: in your browser and see the vacation report for demoemployee.