Skip to main 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.

  • 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.

Comments

Popular posts from this blog

My first serious Groovy class ..... decompiling java classes with closures

After I read the chapter 6 "closures" of the book Groovy and Grails Recipe, and I decided to use the power of closures of Groovy for resource (files) with other problem that I had, decompile in one step every class of jar library. Well, the purpose of this class is call an external java decompiler (jad) from a Groovy class and execute the command into directory where the jar file was decompressed. And by using the power of closures executes recursively into this directory until find the classes. Well, no more words, here the class package demo class Executor { // directory where the library(jar) was decompressed def path /** * Execute the decompilation of the classes into the directory defined in the path * @return */ def decompileClasses(){ def directory = new File(path) //make use of closures defined in the Object class directory.eachFileRecurse { def name = it.absolutePath //if the current resource hasn't a .class extension continues with

How to .. Integration Non-SAP J2EE-based Web Applications into SAP Portal with SSO Part 1

We are going to integrate Non-SAP J2EE-based Web Applications into the SAP Portal with Application Integrator and SSO. In this part, I will discuss the overall of these posts and configure the iView with Application Integrator Overview of Integration. To perform this integration must take into account the following steps: Deployment of the portal application for the creation of the system portal object Create and set the type of Application Integrator iView that will contain the applications to integrate. Installing SAPSSOEXT and SAPSECU libraries Deployment of the application gateway called SsoGatewayWeb Changing the target application. This integration has the following restrictions: It applies only for web applications based on J2EE Servlet. Depend exclusively on the sucessful load of the libraries supported by SAP (sapssoext and sapsecu) in both Windows and UNIX environments. The target application must have created a profile for the user id logged to the SAP portal, this sh

Convert HTML Content to PDF format using Java

I have researched about to convert HTML to PDF. I got 2 approaches. 1. Using Tidy and XSL-FO. 2. Using the project xhtmlrenderer Basically the 1st approach is : 1. Your HTML will need to be validate in according to XHTML, for this you could use Tidy . 2. After you will need to transform this new XHTML document in XLS-FO, you can review this link to find the stylesheet resource ( XHMTL to XLS-FO ). 3. Finally, convert your XLS-FO document in a PDF document. There are 2 links that could help with this approach: http://www.onjava.com/lpt/a/3924 http://www.javaworld.com/javaworld/jw-04-2006/jw-0410-html.html The 2nd approach is using the project xhtmlrenderer (https://xhtmlrenderer.dev.java.net/) This is easier than 1st approach. This tool hides the steps mentioned in the 1st approach and use CSS. This project uses a CSS parser (http://sourceforge.net/projects/cssparser/). the unique problem the I found out was when you want to use external CSS file in your HTML file. In the example use