Wednesday, February 22, 2012

Portlet Factory Interview Questions


Why to use portlet factory?
Ø  Powerful and flexible tool for rapidly building portlets on top of service oriented architecture.
Ø  Portlet created with WPF are dynamic roboust java 2 enterprise edition application that react automaticalli to change, and can be modified by business users in real time to meet changing  requirement without  requiring any coding , duplicating or versioning of assets.
Ø  WPF simplifies the development ,deployment and change management process , saving companies time and money.
Ø  Support SOA development.
Ø  Roboust integration capabilities with enterprise as well as data.
Ø  WPF has  around 160 wizard like builders that can be used to automate  common development task.

What are building blocks of portlet factory?
            WPF consists of three main building blocks:
Ø  Builders
Ø  Models
Ø  Profiles
Developers work withthese above elements builders models and profiles along with other design elements like HTML pages and XML documents and java classes.A WPF  mechanism known as Factory generation engine  can automatically generate executable applications known as WebApps.



What are builders in WPF?
Builders are the basis of any WPF application.
Builders are wizard based interface that automates common development task, builder can do anything from adding a button to calling a webservice.Builders contains input parameters use to customize the builders output.
Developers usually interact with builders with interface but a combination of java classes and XML are used to create builders on the back end.




What id Model in WPF?

A model is the sequenced collection of builders that generates the application  components  that implement the behaviour ,structure, data and presantation of the application.
Internally a model is simply a XML file contating a series of calls to the builders.
A single WPF prj. Can contain one or more models and subsequently can contain several portlets.

What is Profile in WPF?
A profile contains a set of inputs that varies the way a portlet behaves.
A profile feeds values into builders based on user identity or other contextual information.
Using profiles you can generate different variations of generic portlets for different users or situations.




List of WPF Builders.



I am assuming that we have put the wsdl files under the file structure as follows

Steps for calling WebService  in WPF.


In the WebContent – “WSDL” folder wsdl files are present.


Open the designer – Eclipse - Portlet Factory
Click on “Add a Builder Call to Current Model” button -

Following screen will appear -


Select the “Web Service Call” click on “Ok” button 




The Web Service Call builder allows you to execute several different types of services, and displays different inputs according to the type of service call you choose.
The following steps describe the general process of configuring a web service call.
1.     In the Service Call Type input, select the type of service call: WSDL, SOAP, HTTP, or Local.
2.     Enter the URL for the service.
For WSDL service calls, enter the URL for the WSDL document that describes the service you want to call. The URL may be HTTP-based, for example http://myhost/mywsdl.wsdl or a file within the project, such as WEB-INF/mywsdl.wsdl.
If your organization is using WebSphere Service Registry and Repository (WSRR), you can use WSRR to search for and download WSDL to your project.
3.     Specify the values for the arguments to pass to the service.
For WSDL service calls, the builder call editor lists the arguments that the service requires and you must specify their values.
For SOAP and HTTP service calls, you need to know the required arguments and build up the arguments list in the Arguments input in the builder call editor.
4.     Enter any authentication information.
The other inputs to the Web Service Call builder are service type-specific, and in the case of WSDL service calls, may be read-only or have default values specified by the WSDL document.


Create the Service operation for this Web-Service
Specify the execute method of the “WebService Call” in the “Action To Call”.



In the Consumer Model (for showing the result on the page purpose model)

User the builder - Service Consumer and specify the Provider builder name (for DB/WebService call builder present)


In the Data page we can follow the following things


Here we are specifying
Which result it should show from the operation and also we are specifying which page and span result should be displayed.

When we run the portlet it will show the result in the data-grid format.
If we do not specify any input value it will take the default value from the “input schema”


Currently for the respective input data, data is not present it is showing the only datapage.


Custom builders in WPF?
You might need custom builders  to:
Automate a task that occurs frequently, if same set of some builders appears in your model again and again.
To enforce a particular development standard.
Support a new data type integration.
In such conditions you might need to create custom builders.
Design of a typical builder in WPF.


Link for creating custom builders:http://publib.boulder.ibm.com/infocenter/wpfhelp/v6r1m2/index.jsp?topic=/com.bowstreet.designer.doc/tutorials/Custom_Builder_Introductory_Tutorial.htm

How to personalize a page using Profiling?
Profiling to Personalize Portlets

In this section, you will perform similar tasks to expose builder inputs to the portlet's personalization page.
Individual portlet users with an access level of Privileged User or higher can use the portlet's personalization page. These users can open the personalization page and make their own choices from the available options. The settings they choose control certain behaviors of the portlet depending upon which builder
inputs have been exposed to this page. These settings apply separately to each individual user.
To test the portlet's personalization features, you will need to use the various test users you created in the Setup Requirements section of this tutorial. To be sure these features are working; you will need to log in as one user and make choices on the personalization page then log in as a different user and make different choices.
Using this technique, you should be able to determine that the personalization settings are stored independently for each user.
Since setting up a personalization page is so similar to setting up a configuration page, fewer details are provided in this section as you can refer to the details in the previous section if you need to.

Create the Profile Set and Entries

Personalization pages in portlets often include preferences about how a portlet should appear. The personalization page for this portlet will have options that allow the users to choose which columns of data should appear, how many rows of data should appear on one page, which column to use as the default sort, and whether or not to group the data on the detail page.
In this section, you will create the Profile Set for the personalization page and the Profile Entries in this Profile Set.
1. Create the Profile Set
a. Choose from the File menu File > New > WebSphere Portlet Factory Profile Set
b. Name the Profile Set EP_EditPage
c. In the Description field, enter Employees Portlet Edit Page
d. Click Finish to continue. The new Profile Set will open in the Profile Set Editor. This Profile Set is stored in the WEB-INF\profiles folder in this project and is named EP_EditPage.pset.
2. Create the Profile Entries
By now you should be able to use what you learned while creating the Entries in the EP_ConfigPage Profile Set to create the Entries in this Profile Set without the benefit of detailed instructions. The following table describes the Entries needed in the Profile Set used for the portlet's personalization page.
a. Create the Entries in the EP_EditPage Profile Set. Use the Add button to create new Entries.
b. Save the Profile Set periodically to protect your work.


Profiling the Builder Call Inputs
Some builder call inputs have simple profiling options while others are more complex. Consider the data table in Data Column Modifier. Profiling table rows allows you to enable / disable the entire row or to control the values of individual properties within the row.
1. Open the EP_Profiling_Working model again.
2. Enable control over the number of rows to display
a. Locate the builder call of type Data Column Modifier named allEmployeesFormatting and edit it.
b. In the Settings to control paging of the table data section, locate the input labeled Page Size. This input controls how many rows of data will display at any one time.
c. Profile this input so that the user can choose how many rows to display.
i. Click the next to this input.
ii. Choose the EP_EditPage Profile Set. Be sure to choose the correct Profile Set as this dialog box does not always default to the last Profile Set used.
iii. Choose the PagingRows input you created earlier.
iv. Click OK to save these changes.
d. When completed, this input will be grayed out and the Profile Set : Profile Entry relationship will be displayed below it.
e. Leave this builder call open as you will make more changes to it in the next few steps.
3. Enabling optional display columns
a. In the same builder call, scroll down to the table used to manage the columns of data.
b. Locate the row labeled WORKDEPT and profile it by clicking the on that row. The Profile Row of
Inputs dialog box will open.
i. Note that this box has one to enable / disable the entire row and one for each
property in the row. Since the objective is to profile the Status property which is how a column's visibility is controlled, click the next to Status.
ii. Choose the correct Profile Set and Profile Entry for this input. Be sure to choose the EP_EditPage Profile Set and the WorkDept_OnOff Profile Entry.
iii. Click OK to save these settings.
c. Click OK to close this dialog box. Once saved, the Status column in the WORKDEPT row should be grayed out indicating that it has been profiled.
d. Profile the Status property of the JOB row and the HIREDATE row the same way as the WORKDEPT row. Be sure to choose the correct Profile Set and Profile Entries.
i. Associate the Status property of the JOB row with the Entry called JobTitle_OnOff.
ii. Associate the Status property of the HIREDATE row with the Entry called
HireDate_OnOff.
e. Save and close this builder call by clicking the OK button in the builder call editor.
4. Enabling the default column sorting option
a. Locate the builder call of type Action List named main and edit it. This Action List runs automatically because its name is main. The View and Form builder contains an Action List called main but it is disabled in the Advanced section of the builder call in this model. It was necessary to disable it in order to add the SortSortAction method call described in the next
step.
b. The second action in the list is a call to a method named SortSortAction. Click the button to see the names of the other similar actions.
i. You should see names like SortSortAction, SortSortAction1,
SortSortAction2, etc. Each SortSortAction method corresponds to a sorted
column in the employees data table counting the columns from left to right. For example, if SortSortAction2 is chosen, the third sortable column from the left will be sorted when the page loads for the first time.
ii. Click Cancel to avoid making any changes to the Action List step.
c. Profile the Action List step containing the SortSortAction method call.
i. Click the row in the table containing SortSortAction. The Profile Row of
Inputs dialog box will open.
ii. Click the next to Action List. The idea is to set the name of the method that will be called by using the value in a Profile Entry.
iii. Associate this input with the Default_SortAction Entry in the EP_EditPage Profile Set.
iv. Click OK to save these settings.
d. Save and close this builder call by clicking the OK button in the builder call editor.
5. Save the model.

What are Data Driven Portlets?
In data driven portlets we fetch data from DB either by creating JNDI/connection.In the provider model we use sql Call and other builder data driven builders to fetch data from db.in the consumer model we can use the data.


What is SOA in WPF?



How to achieve Inter portlet communication Between the Portlet in WPF?
 - Imported Model
 - Linked Model

Difference between Imported Model & Linked Model?
http://www-10.lotus.com/ldd/pfwiki.nsf/dx/07282008035003PMWEBR9U.htm
Recomendations:-
Linked Model -
Recommendation: The Linked Model builder should rarely be used directly.   For most scenarios, consider whether techniques such as Service Provider or Model Container can provide the modularity you need.

Imported Model builder -

Recommendation: Use Imported Model when you want to include some builders in multiple models, such as Event Declarations, Shared Variables, or shared utility functions. and method call for example out GETREMOTEUSER METHOD by using substring which we have created.

what is webapp in WPF?

webapp is the name of the structure created by the builders in the model and it is the abstraction for all the elements that can make up a web app including pages, variables, schemas, methods and events.
webappaccess paramater using portlet factory api and used to change variable in webapp.

Wednesday, February 15, 2012

Logging to the portal directly from the url, Passing parameter to portlet directly from url..

If you want to login to the portal directly from the url and want to pass some parameter directly to the portlet from the url follow the below steps:-

Step1:-create custom login portlet and in the portlet get the username and password and the argument that u want to pass, Here I am considering parameter as .param1.param2,param3.

the code is as below :-

package com.ibm.customloginportlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.security.auth.login.LoginException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.log4j.Logger;
import com.ibm.portal.auth.exceptions.AuthenticationException;
import com.ibm.portal.auth.exceptions.AuthenticationFailedException;
import com.ibm.portal.auth.exceptions.PasswordInvalidException;
import com.ibm.portal.auth.exceptions.PortletLoginDisabledException;
import com.ibm.portal.auth.exceptions.SessionTimeOutException;
import com.ibm.portal.auth.exceptions.SystemLoginException;
import com.ibm.portal.auth.exceptions.UserAlreadyLoggedInException;
import com.ibm.portal.auth.exceptions.UserIDInvalidException;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.portlet.service.PortletServiceUnavailableException;
import com.ibm.portal.portlet.service.login.LoginHome;
import com.ibm.portal.portlet.service.login.LoginService;
import com.ibm.websphere.security.WSSecurityException;
import com.ipops.vo.CRMRequestDataVo;


/**
 * Custom Login Portlet
 */
public class CustomLoginPortlet extends GenericPortlet {

private static final String  VIEW_JSP       = "/jsp/CustomLoginPortletView.jsp";
private static final String  VIEW_JSP_FAILED     = "/jsp/LoginFailed.jsp";
private static Logger logger = Logger.getLogger (CustomLoginPortlet.class);
LoginHome loginHome;
public void init() throws PortletException{
  try
     {
          InitialContext ctx =  new InitialContext();
          PortletServiceHome psh = (PortletServiceHome) ctx.lookup(LoginHome.JNDI_NAME);
          loginHome = (LoginHome) psh.getPortletService(LoginHome.class);
          }
     catch (NamingException e)
     {
         e.printStackTrace();
         }
     catch (PortletServiceUnavailableException e)
     {
     logger.error("PortletServiceUnavailableException",e);
 }
       }


public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
     {
  response.setContentType("text/html");
  CRMRequestDataVo  vo =getRequestData(request);
  PortletSession session = request.getPortletSession();
  PortletRequestDispatcher dispatcher = null;
  String pageType = (String)session.getAttribute("pageType");
  if(pageType != null && pageType.equalsIgnoreCase("failed"))
  {
dispatcher = getPortletConfig().getPortletContext().getRequestDispatcher(VIEW_JSP_FAILED);
  }
  else
  {
request.setAttribute("CRMData", vo);
dispatcher = getPortletConfig().getPortletContext().getRequestDispatcher(VIEW_JSP);
 
  }
  dispatcher.include(request, response);
  session.removeAttribute("pageType");
    }


public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException
   {
 PortletSession session = request.getPortletSession();
try {
     String userId = request.getParameter("param1");
     String password = request.getParameter("param2");
     LoginService loginService = loginHome.getLoginService(request, response);
 Map contextMap = new HashMap();
 contextMap.put(LoginService.DO_RESUME_SESSION_KEY, new Boolean(false));
 loginService.login(userId, password.toCharArray(), contextMap, null);
 response.sendRedirect("/wps/myportal/orderDisplay?orderID="+request.getParameter("param3"));
 
   }
     catch (PasswordInvalidException e)
     {
     logger.error("PasswordInvalidException:",e);
     }
     catch (UserIDInvalidException e)
     {
     logger.error("UserIDInvalidException:",e);
     }
     catch (AuthenticationFailedException e)
     {
     logger.error("AuthenticationFailedException:",e);
     }
     catch (AuthenticationException e)
     {
     logger.error("AuthenticationException:",e);
     }
     catch (SessionTimeOutException e)
     {
     logger.error("SessionTimeOutException:",e);
      }
     catch (PortletLoginDisabledException e)
     {
     logger.error("PortletLoginDisabledException:",e);
     }
     catch (UserAlreadyLoggedInException e)
     {
     logger.error("UserAlreadyLoggedInException:",e);
      }
     catch (SystemLoginException e)
     {
     logger.error("UserAlreadyLoggedInException:",e);
     }
     catch (LoginException e)
     {
     session.setAttribute("pageType","failed");
     logger.error("LoginException:",e);
     }
     catch (WSSecurityException e)
     {
     logger.error("WSSecurityException:",e);
     }
     catch (com.ibm.portal.auth.exceptions.LoginException e)
     {
     logger.error("com.ibm.portal.auth.exceptions.LoginException:",e);
     }
     catch (Exception e)
     {
     logger.error("Exception:",e);
 response.sendRedirect("/wps/portal/");
     }
 }

private CRMRequestDataVo getRequestData(PortletRequest request){

   CRMRequestDataVo  vo = null;
   HttpServletRequest httpServletRequest = (HttpServletRequest)request;
   while(httpServletRequest instanceof HttpServletRequestWrapper)
   {
     HttpServletRequestWrapper httpServletRequestWrapper = (HttpServletRequestWrapper)httpServletRequest;
     httpServletRequest =  (HttpServletRequest)httpServletRequestWrapper.getRequest();
   
   }

   if(httpServletRequest.getParameter("param1") != null && httpServletRequest.getParameter("param2") != null && httpServletRequest.getParameter("param3") != null  )
     {
     vo = new CRMRequestDataVo();
     vo.setUserName(httpServletRequest.getParameter("param1"));
     vo.setPassword(httpServletRequest.getParameter("param2"));
     vo.setOrderID(httpServletRequest.getParameter("param3"));
     }else
     {
     PortletSession psession = request.getPortletSession();
     psession.setAttribute("pageType","failed");
     }
     return vo;
 
 }


}


In the above code I am using 2 jsps, if the vo is not null then i am passing vo to CustomLoginPortletView.jsp.

The jsp code is :-
<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@page import="com.ipops.vo.*" %>
<portlet:defineObjects />

<form method="post" name="AutoLogin" action="<portlet:actionURL/>">
<%CRMRequestDataVo vo = (CRMRequestDataVo)renderRequest.getAttribute("CRMData"); %>

<input type = "hidden" name="param1" value="<%=vo.getUserName()%>">
<input type = "hidden" name="param2" value="<%=vo.getPassword()%>">
<input type = "hidden" name="param3" value="<%=vo.getOrderID()%>">

</form>

<script language="javaScript" type="text/javascript" >
function autoSubmit()
{

document.AutoLogin.submit();
}
autoSubmit();
</script>

after getting the parameter from the processAction we are redirecting the URL.

Step2:-create a URL Mapping and map it to the portlet where you need the inputs, In my case i am passing param3 as input param.

Step3:- Now logout from the portal and simply put this in the URL:
http://localhost:10040/wps/portal/CRMLogin?param1=wpsadmin&param2=wpsadmin&param3=981139

you will get loged in to the portal and in the portlet you can fetch the param3 and can do further action as per req.