Skip to Content

Show the user data of every response for the current Quick Poll in the campaign in a Flex Client, 2nd part

Only we’ll review the main part of the method “getVotesPerCampaingResponse(Map map)” in the SearchService class.

Before to begin we need to consider the following items:


  • com.sapportals.wcm.control.quickpoll.extension.QPResourceManager.

  • com.sapportals.wcm.repository.IResourceContext.



In this operation we must take into account that the quick polls will be processed in according to the quick poll state: current and historical. Therefore, first we need to process the current quick poll and after to process the historical rapid quick polls of the requested campaign.


The main class is “QPResourceManager“, internally  it works with the com.sapportals.wcm.control.quickpoll.extension.QPBaseService class. For to get one instance of the QPResourceManager class, previously we need to get an instance of the class, it’ll reference to the portal service user “cmadmin_service” and then get reference to the ResourceContext class.

Bellow I show the java code :


IUser objNwUser = UMFactory.getServiceUserFactory().getServiceUser(“cmadmin_service”); sapUser = WPUMFactory.getUserFactory().getEP5User(objNwUser);
objResourceCtx = new ResourceContext(sapUser);
QPResourceManager objResourceManager = new QPResourceManager(objResourceCtx);


We’ll put the rigth value of the repository path of the Quick Poll Service (in our case  the value of  “/documents/QuickPoll”):



Previously, the instance variable must be defined, as I show bellow:

            private String strRepositoryPath = “/documents/QuickPoll”;

Next, I write the code to retrieve and process the data of the current quick poll for the requested campaign.


IPropertyName objP = PropertyName.getPN(strNamespace, “quickpollvote”);
ReportQuickPoll report = new ReportQuickPoll();
List lstResponses = new ArrayList();
Quickpoll objQP = objResourceManager.getCurrentQuickpoll(strCampaign);
List lstQuickPolls = new ArrayList();
if (objQP != null)
   QuickpollResponse objQPR = null;
String strNameResource = strRepositoryPath + “/” + strCampaign + “/” + “qp.xml”;
   if(!existsResource(objResourceCtx, RID.getRID(strNameResource)))
new ApplicationException(“Doesn’t exist a current poll  in the KM for the requested campaign”);
   LineQuickPoll lineQP = new LineQuickPoll();
   List lstLineResponses = new ArrayList();
   // Create an ordered list with every options of the quick poll
   for (Iterator ite = objQP.getResponses().iterator(); ite.hasNext();) {
       objQPR = (QuickpollResponse);
    processLineResponses(objP, strNameResource, lineQP, lstResponses, lstQuickPolls);

After, into the methods processLineResponses and processProperty is the core of the service class because it retrieves the information from the quick poll engine, the user who made the vote of the current quick poll.


private void processLineResponses(IPropertyName objP, String strRIDResource, LineQuickPoll lineQP, List lstResponses, List lstQuickPolls )
throws WcmException, ResourceException{
   RID objRID = RID.getRID(strRIDResource, null);
   resource = ResourceFactory.getInstance().getResource(objRID, objResourceCtx);

// Getting the instance of the repository service that allow us to
// extract the information about the related resource to the
// current quick poll
   IApplicationProperties appProps = (IApplicationProperties) ResourceFactory.getInstance().getServiceFactory().getRepositoryService(resource.getRepositoryManager(), strRepositoryService);
    IAppPropertyCollection collProp = appProps.getProperties(objP, resource);
   LineResponse lineResponse = null;
   int totVotes = 0;
   IAppProperty objX = null;
   List listLineResponses = new ArrayList();
   for (IAppPropertyIterator ite= collProp.iterator();ite.hasNext();){
      objX =;
      lineResponse = new LineResponse();
      // Process the quick poll response and get the user information
      processProperty(lineResponse, objX, lstResponses);

private void processProperty(LineResponse objLine, IAppProperty objAppProperty, List lstResponses) {
   // Getting the user who response the quick poll.
   String strUserId = objAppProperty.getUserID();
   try {
      IUser objUser = UMFactory.getUserFactory().getUserByLogonID(strUserId);
      objLine.setUserName(objUser.getFirstName() + ” ” + objUser.getLastName());
      String strValue = objAppProperty.getStringValue().replaceAll(“;”, “”);
      objLine.setResponse((String) lstResponses.get(Integer.parseInt(strValue)));
   } catch (UMException e) {


Our most important statement in the above code is the sentence: 

     String strUserId = objAppProperty.getUserID();

It retrieves the user of current vote. Also we must remind that we have created a list named “lstResponses”, it contains the names of every QuickpollResponse object of the quick poll. This list is ordered in according to the definition in the management iview of Quick Polls.

For to convert  java objects into the XML document we’ll use an utility class. (you can find the source here)

     String strRet = OptimizedReflectionMarshaller.marshal(getVotesPerCampaingXmlResponse(map));

In the last part, we will review the RIA Flex client to show the final web report.

Here you can download the java project.

Show the user data of every response for the current Quick Poll in the campaign in a Flex Client, 3rd part

You must be Logged on to comment or reply to a post.