Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

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.

  • com.sap.security.api.IUser.

 

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 com.sapportals.portal.security.usermanagement.IUser 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");
com.sapportals.portal.security.usermanagement.IUser 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"):

 

      objResourceManager.setRepositoryPath(strRepositoryPath);


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);
report.setNameCampaing(strCampaign);
List lstQuickPolls = new ArrayList();
reporte.setListPolls(lstQuickPolls);
if (objQP != null)
{
   QuickpollResponse objQPR = null;
   
String strNameResource = strRepositoryPath + "/" + strCampaign + "/" + "qp.xml";
   if(!existsResource(objResourceCtx, RID.getRID(strNameResource)))
        throw
new ApplicationException("Doesn't exist a current poll  in the KM for the requested campaign");
   LineQuickPoll lineQP = new LineQuickPoll();
   lineQP.setNamePoll(objQP.getName());
   lineQP.setQuestion(objQP.getQuestion());
   lineQP.setStatePoll(IQuickPollConstants.STATUS_QP_OPENED_AT);
   lineQP.setNameResourceKM(strNameResource);
   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) ite.next();
       lstResponses.add(objQPR.getText());
    }
    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{
   lineQP.setNameResourceKM(strRIDResource);
   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 = ite.next();
      lineResponse = new LineResponse();
      //
      // Process the quick poll response and get the user information
      //
      processProperty(lineResponse, objX, lstResponses);
      listLineResponses.add(lineResponse);
      totVotes++;
   }
   lineQP.setListUserResponses(listLineResponses);
   lineQP.setTotalVotes(Integer.valueOf(String.valueOf(totVotes)));
   lstQuickPolls.add(lineQP);
}

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.setEmail(objUser.getEmail());
      objLine.setUserName(objUser.getFirstName() + " " + objUser.getLastName());
      objLine.setUserId(strUserId);
      objLine.setArea(objUser.getDepartment());
      String strValue = objAppProperty.getStringValue().replaceAll(";", "");
      objLine.setResponse((String) lstResponses.get(Integer.parseInt(strValue)));
   } catch (UMException e) {
     makeLogException(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, 3r...

2 Comments