Tuesday, 11 February 2014

Oracle WebCenter Polls Service Customization to keep poll result until next poll is published

As you all know,
The Polls service lets you create, edit, take, and analyze online polls.

The default behavior of Take Poll Service is,It displays the most recently-published available poll, unless it is set to display a specific poll with the Poll Id parameter. After a user submits a response for that poll, this task flow displays the next most recently-published poll. But what if , you have not published any new poll and user already taken the recently published poll. Then the Poll service show "No Polls Available" in your poll section.

Recently we got the requirement to keep and show the  recently published poll result to end user until the new poll published.



Among the Polls Service Tasks flows provide by framework, we can use two main tasks flow in order achieve our requirement.
1)Take Poll
2)View Poll Result

Both these task flows accept the Poll Id parameter

our goal here is to switch between these two tasks flows.
Because we need to show the published poll for the user who has not taken the Poll yet (by using Take Poll)
and recently published poll result for the user who has taken the poll(By using View Poll result)

In order to do lets quickly observe the Poll service schema which framework provides. In order to do this,

Try to enable the show library option in the "Navigator display options" in Jdeveloper as shown below and observe the schema related to Poll service.(You can able to see these only when you already added the service to your project included the libraries.)



 

By Observing the Poll schema we created one AM Method and one VO based on the below query


select survey_id,response_date,user_id
from wc_survey_response
where user_id = :bind_loginuserid
ORDER BY response_date desc

In VO create one bind variable - (Say for example 'bind_loginuserid' ) of type string and make it required.

In the AmImpl java create the below method to get recent poll responce id


    public String getLastRespondedSurveyId(String userid){
        ViewObjectImpl vo = this.getSurveyResponseVO();
        vo.setNamedWhereClauseParam("bind_loginuserid", userid);
        vo.executeQuery();
       
        if(vo.first() != null){
            return (String)vo.first().getAttribute("SurveyId");
        }
        else{
            return null;
        }
    }
         
          
Next Drag and drop the take poll webcenter service task flow on to the page and in the bindings, click on edit icon to set the task flow parameter as shown below


for the pollId parameter, we are calling bean method and inside bean method we are conditionally calling one of the two task flows .

here is the bean method for your reference
         
         
              public String getPollSurveyId(){
       SurveyBuilder surveyBuilder = SurveyBuilder.getCurrentInstance();
        int count = surveyBuilder.getTakeSurveyBean().getAvailableSurveyCount();
        if(count!=0){
           return "/oracle/webcenter/collab/survey/view/jsf/taskflows/take-polls-definition.xml#take-polls";
        }
        else {
            //String value ="ab3ffed8-5b73-4e97-ac33-7c320c839c02";
            //ADFUtil.setEL("#{pageFlowScope.setPollId}", value);
            return "/oracle/webcenter/collab/survey/view/jsf/taskflows/view-results-definition.xml#view-results";
        }
        //return null;
       
    }
   
    
    public String getLastRespondedPoll(){
        SurveyBuilder surveyBuilder = SurveyBuilder.getCurrentInstance();
         int count = surveyBuilder.getTakeSurveyBean().getAvailableSurveyCount();
         if(count!=0){
             return null;
         }
         else{
             return (String)ADFUtil.executeOperationBinding("getLastRespondedSurveyId", null);
         }
       
    }



the string which we returning is nothing but poll id of either the takepoll or poll result taskflows based on whether user already taken the poll or not. Note: if you want to know poll id of the task flow then just  drag drop the two task flow to find out their task flow id

thats it !!!... so when poll published by admin, it will show the poll as shown below



and when the end user takes the poll, the poll result will be displayed until the next poll is published as shown below
there by achieving the the requirement of keeping poll result until the next poll is published.

2 comments:

  1. How & where to create AO & VO and by which name I am not able to add file in task flow.

    kindly help it is very critical issue I am facing as I am new to ADF.

    ReplyDelete
    Replies
    1. Hi,
      You can create ADF Model Project inside webcenter portal application.
      Once you ADF Model project ready, you can create VO and AM.
      Name can be any thing and use the same VO name in the code
      Create Read only VO based on the query as i mentioned above.
      Create Corresponding AM for this VO. You also need to create AMImpl.java class to create
      getLastRespondedSurveyId method.
      After this step, expose the above method in client interface.Once you exposed you can able to see new method in the Datacontrol.

      Create a page where you want to show Poll service.Create a method action for getLastRespondedSurveyId on this page.
      Now Drag and Drop take poll webcenter service task flow on to the page.
      Go to bindings and Click on Edit icon for the take poll task flow and set parameters as show in screenshot above.
      for the first parameter, i am calling bean(HomePageBean) with backing bean scope. And in my bean i have created lastrespondedPoll
      which will give u poll id for the last Poll. lastrespondedPoll method poll definition i have mentioned above.
      Hope this helps.

      Delete