I want to build a report for a poll with details on each poll. I need to get users response for each poll, does anyone has sample code or any APIs I can use.
Today's Poll Portlet?
One solution is to query the database PortalBeans.Contents column, filter PollBean objects, use PollBean API to get a handle for the corresponding PollManager, and loop through the Polls. PollBean API is undocumented, but plenty of examples can be found by examining the portlet .jsp's under <PORTAL_APPLICATION>/beans/pollbean/jsp. The following is provided only as an example, and is not gauranteed to work. <%-- START pollBeanReport.jsp --%> <%@page import="java.sql.*, java.io.*, java.util.*, com.epicentric.jdbc.*, com.epicentric.portalbeans.beans.pollbean.*" %> <html> <body> <% try { ConnectionPool pool = ConnectionPoolManager.getDefaultPool(); Connection conn = pool.getConnection(); PreparedStatement ps = conn.prepareStatement("select CONTENTS from PORTALBEANS"); ResultSet rs = ps.executeQuery(); //table output out.println("<table border=\"1\"><tr><td>PollBean (Portlet) ID</td><td>Title</td><td>Polls</td></tr>"); while (rs.next()) { try { InputStream is = rs.getBlob(1).getBinaryStream(); ObjectInputStream ois = new ObjectInputStream(is); Object obj = ois.readObject(); if (obj instanceof PollBean) { PollBean pb = (PollBean) obj; int Id = pb.getID(); String Name = pb.getName(); String stringId = pb.getStringID(); String title = pb.getTitle(); out.println("<tr><td>" + Id + "</td>"); out.println("<td>" + title + "</td><td>"); PollManager pm = pb.getPollManager(); Poll currentPoll = pm.getCurrentPoll(); if (currentPoll != null) { out.println(buildPollTable(currentPoll)); } Vector previousPolls = pm.getPreviousPolls(); Iterator ppI = previousPolls.iterator(); while(ppI.hasNext()) { Poll previousPoll = (Poll) ppI.next(); out.println(buildPollTable(previousPoll)); } out.println("</td>"); } } catch (Throwable t) { t.printStackTrace(); } } out.println("</tr></table>"); pool.returnConnection(conn); } catch (Throwable t) { t.printStackTrace(); } %> <%! public String buildPollTable(Poll poll) { StringBuilder sb = new StringBuilder(); sb.append("<table border=\"1\"><tr><td>Question</td><td>Start</td><td>End</td><td>User</td><td>Guest Allowed</td><td>results</td></tr><tr>"); sb.append("<td>" + poll.getQuestion() + "</td>"); sb.append("<td>" + poll.getStartDate().toString() + "</td>"); sb.append("<td>" + poll.getDate().toString() + "</td>"); sb.append("<td>" + poll.getUsername() + "</td>"); sb.append("<td>" + poll.isGuestAllowed() + "</td>"); sb.append("<td><table border=\"1\"><tr><td>Choice</td><td>Is Active</td><td>Votes</td></tr>"); int numChoices = poll.getNoOfChoices(); for (int i = 0; i < numChoices; i++) { sb.append("<tr><td>" + poll.getChoiceName(i) + "</td>"); sb.append("<td>" + poll.isChoiceActive(i) + "</td>"); sb.append("<td>" + poll.getVotes(i) + "</td></tr>"); } sb.append("</table></td></tr></table>"); return new String(sb); } %> </body> </html> <%-- END pollBeanReport.jsp --%> Here are instructions to run this in your environment.
1. Create pollBeanReport.jsp under the deployed Portal application directory. The location of this directory depends on the appserver product you are using in your environment. Here is a tomcat example. <TOMCAT_HOME>/webapps/portal/pollBeanReport.jsp 2. Run the .jsp with a web browser by accessing the following address.
<PROTOCOL>://<HOST>:<PORT>/<APPLICATION_CONTEXT>/pollBeanReport.jsp eg: http://localhost:8080/portal/pollBeanReport.jsp
Hi Alexander,
Thanks for the response, It was my mistake to put poll. Actually I need the responses for survey submitted.
This is using Metastore API, in the admin report it is having all the information except user who submitted the response. If you have any details on how to get the user information, please let me know.
Thanks
Mohammed Ahmed
You are welcome Mohammed,
The provided solution is specific to the PollBean portlet, but the general solution is the same. Deserialize the PortalBean objects from the database, filter for the specific *Bean objects you are interested in, and use the portlet API for that portlet to retrieve the desired information. Review the portlet jsp's to find out how to get the responses.
Kind Regards
Alex