Using programmatic API for accessing PLM data

WebSphere Portal Server V 7.0 provides API's that you can use to access the PLM related data. I wanted to try it so i built sample portlet that will query all the portlets installed on portal server and get list of PLM related data for it. You can download it from here

In the HelloPLM portlet i am using AdminPortletModel get list of portlets on my server then i am iterating through each portlet, checking if portlet load monitoring is turned on for it (PortletLoadMetrics object is not null). If the plm is turned on for the portlet then i am reading values like if it is enabled, what is maximum allowed response time and maximum concurrent requests for the portlet


package com.wpcertification.wp70.plm;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.ibm.portal.ModelException;
import com.ibm.portal.ObjectID;
import com.ibm.portal.model.PortletModelHome;
import com.ibm.portal.plm.PortletLoadMetrics;
import com.ibm.portal.plm.service.PortletLoadMetricsService;
import com.ibm.portal.portletmodel.PortletDefinition;
import com.ibm.portal.portletmodel.admin.AdminPortletModel;
import com.ibm.portal.portletmodel.admin.PortletDefinitionList;

public class HelloPLMPortlet extends GenericPortlet{

PortletLoadMetricsService portletLoadMetricService = null;
PortletModelHome portletModelHome;
public void init() throws PortletException {
try {
InitialContext context = new InitialContext();
portletLoadMetricService =
(PortletLoadMetricsService)context.lookup(PortletLoadMetricsService.JNDI_NAME);
portletModelHome = (PortletModelHome)context.lookup(PortletModelHome.JNDI_NAME);
} catch (NamingException e) {
e.printStackTrace();
}
}

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering HelloPLMPortlet.doView()");
response.setContentType("text/html");

try {
List plmDtoList = new ArrayList();
AdminPortletModel adminPortletModel =
portletModelHome.getPortletModelProvider().getAdminPortletModel((ServletRequest)request,
(ServletResponse) response);
PortletDefinitionList portletDefList = adminPortletModel.getPortletDefinitionList();
Iterator portletDefListIt = portletDefList.iterator();
while(portletDefListIt.hasNext()){
PortletDefinition portletDefinition = (PortletDefinition)portletDefListIt.next();
ObjectID portletDefObjectID = portletDefinition.getObjectID();
PLMDto plmDto =getPLMDTO(portletDefObjectID);
if(plmDto.getIsEnabled() != null)
plmDtoList.add(plmDto);
}
request.setAttribute("PLMDtoList", plmDtoList);
getPortletContext().getRequestDispatcher("/index.jsp").include(request, response);
} catch (ModelException e) {
e.printStackTrace();
}
System.out.println("Exiting HelloPLMPortlet.doView()");
}

private PLMDto getPLMDTO(ObjectID objectID ){
PLMDto plmDto = new PLMDto();
plmDto.setPortletUniqueName(objectID.getUniqueName());
PortletLoadMetrics portletLoadMetrics =
portletLoadMetricService.getPortletLoadMetrics(objectID);
System.out.println("Portlet Load Metrics " + portletLoadMetrics);
if(portletLoadMetrics == null)
return plmDto;
plmDto.setMaxAllowedRequest(portletLoadMetrics.getAverageResponseTime()+"");
plmDto.setMaxAllowedRequest(portletLoadMetrics.getCurrentNumberOfRequests()+"");
plmDto.setIsEnabled(Boolean.toString(portletLoadMetrics.isPortletEnabled()));
return plmDto;
}
}



When i tried accessing this portlet on my local machine i noticed that the PortletLoadMetrics object is null for all the portlets except for which i set either the max allowed response time or max no of concurrent request.

In my case only HelloPLM portlet has one of the PLM related preference so this is the output that i get