Search This Blog

Wednesday, December 17, 2014

How retrieve portal users using IBM PUMA Built-in service ?

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.naming.NamingException;

import com.ibm.portal.um.Group;
import com.ibm.portal.um.PagingIterator;
import com.ibm.portal.um.PumaController;
import com.ibm.portal.um.PumaHome;
import com.ibm.portal.um.PumaLocator;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaAttributeException;
import com.ibm.portal.um.exceptions.PumaException;
import com.ibm.portal.um.exceptions.PumaMissingAccessRightsException;
import com.ibm.portal.um.exceptions.PumaModelException;
import com.ibm.portal.um.exceptions.PumaSystemException;

public class IBMPumaUtility {
 
 private static IBMPumaUtility pumaUtility;
 private PumaHome pumaHome;
 
 private IBMPumaUtility() throws NamingException {
  javax.naming.Context ctx = new javax.naming.InitialContext();
  pumaHome = (PumaHome) ctx.lookup(PumaHome.JNDI_NAME);
 }

 public static IBMPumaUtility getInstance() throws NamingException {
  if(pumaUtility == null) {
   pumaUtility = new IBMPumaUtility();
  } 
  return pumaUtility;
 }

 public User getCurrentUser() throws PumaException {
  //To retrieve current User
  PumaProfile profile = pumaHome.getProfile();
  return profile.getCurrentUser();
 }
 
 public List<User> getUsersByAttribute(String attributeName, String attributeValue)
  throws PumaSystemException, PumaAttributeException, PumaMissingAccessRightsException {
  //To find Users by attribute
  //(eg. attrName = "cn" and attrValue="Manish")
  PumaLocator locator = pumaHome.getLocator();
  return locator.findUsersByAttribute(attributeName, attributeValue);
 }
 
 public List<User> findUsersByQuery(String query) 
  throws PumaSystemException, PumaAttributeException, PumaMissingAccessRightsException {
  //If you need to search by mutilple attributes, search users by query
  PumaLocator locator = pumaHome.getLocator();
  //String query = "((cn != 'Manish') and (givenName != 'wpsadmin'))";
  return locator.findUsersByQuery(query);
 }
 
 public Map<String, Object> getUserAttributes(User user)
  throws PumaAttributeException, PumaSystemException, PumaModelException, PumaMissingAccessRightsException {
  List<String> returnAttributes = new ArrayList<String>();
  returnAttributes.add("cn");
  returnAttributes.add("mail");
  PumaProfile profile = pumaHome.getProfile();
  Map<String, Object> values = profile.getAttributes(user, returnAttributes);
  return values;
 }
 
 public List<Group> findGroupsByAttribute(String attributeName, String attributeValue) 
  throws PumaSystemException, PumaAttributeException, PumaMissingAccessRightsException {
  //Just like findUsers you can find Groups by attribute
  PumaLocator locator = pumaHome.getLocator();  
  List<Group> groups = locator.findGroupsByAttribute(attributeName, attributeValue);
  return groups;
 }

 public PagingIterator<User> paginationFindUsersByQuery(String query, int resultsPerPage)
  throws PumaSystemException, PumaAttributeException, PumaMissingAccessRightsException {
  //PumaLocator provides method to either return a List of PagingIterator
  //int resultsPerPage = 10;  
  PumaLocator locator = pumaHome.getLocator();
  Map<String, Integer> pProperties = new HashMap<String, Integer>();
  pProperties.put(PumaLocator.RESULTS_PER_PAGE, resultsPerPage);
  PagingIterator<User> pIterator = locator.findUsersByQuery(query, pProperties);
  return pIterator;
 }
 
 public void updateUserAttribute(User user, String attribute, String value)
  throws PumaAttributeException, PumaSystemException, PumaModelException, PumaMissingAccessRightsException {
  PumaController pController = pumaHome.getController();  
  //Use PumaController to set or remove User attribute
  Map<String, Object> attributes = new HashMap<String, Object>();
  attributes.put(attribute, value);
  pController.setAttributes(user, attributes);   
 }
 
 public void updateUserAttributes(User user, Map<String, Object> attributes)
 throws PumaAttributeException, PumaSystemException, PumaModelException, PumaMissingAccessRightsException {
  PumaController pController = pumaHome.getController();  
  //Use PumaController to set or remove User attribute
  pController.setAttributes(user, attributes);   
 }
 
 public void removeUserAttribute(User user, String attribute)
  throws PumaAttributeException, PumaSystemException, PumaModelException, PumaMissingAccessRightsException {
  List<String> keys = new ArrayList<String>();
  //keys.add("mail");
  keys.add(attribute);
  
  PumaController pController = pumaHome.getController();
  pController.removeAttributes(user, keys);   
 }

 public void removeUserAttributes(User user, List<String> attributes)
  throws PumaAttributeException, PumaSystemException, PumaModelException, PumaMissingAccessRightsException {
  PumaController pController = pumaHome.getController();
  pController.removeAttributes(user, attributes);   
 }

}


Friday, November 14, 2014

How to Redirect to specific portal page after login in IBM Portal 8 ? 


1. open commonActions.jsp   .

2. Change contentNode="wps.content.root to your specific portal page unique name.

Friday, November 7, 2014

What is the difference between an Edit Shared Setting and a Configure in IBM WCM?


Edit Shared Setting
Configure
Apply setting for this portlet only
Apply setting for all portlets under this node.

Sunday, October 5, 2014

How to make IBM Portal Theme 8.0 Responsive?

http://www.ibm.com/developerworks/library/mo-responsive-design-1/

Monday, August 4, 2014

How to create new custom IBM Portal 8.0 Theme Layout ?




1  1)     open  layout-templates folder .

    2)   Create a copy of any template and paste in the same location.

   3)   Make necessary changes to layout.json file by adding below piece of code for custom layout  creation in portal (Registering new layout by adding an entry to the items array in the following format 

Tuesday, July 22, 2014

How to access IBM WCM library using JAVA API?







sad<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<%@ taglib uri="/WEB-INF/tld/portal-internal.tld" prefix="wps-internal"%>
<%@ taglib uri="/WEB-INF/tld/resolver-v6.tld" prefix="portal-resolver"%> <%@ taglib uri="/WEB-INF/tld/people.tld" prefix="pa"%> <%@ taglib uri="/WEB-INF/tld/menu.tld" prefix="menu"%>
<%@ taglib uri="/WEB-INF/tld/engine.tld" prefix="wps"%>
<%@ page session="true" contentType="text/html" import="java.util.*,java.lang.*,com.ibm.portal.um.*,com.ibm.workplace.wcm.api.*"%> <%@ taglib uri="/WEB-INF/tld/portal.tld" prefix="portal"%>
<%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*"%>
<%@ page import="com.ibm.workplace.wcm.api.*"%> <%@ page import="com.ibm.workplace.wcm.api.exceptions.*"%> <%@page import="java.util.*"%> <%@page import="java.io.*"%> <%@page import="java.net.*"%> <%@page import="java.text.*"%> <%@ page
<c:set var="prefLanguage" value="ar" />
import="java.text.*,java.util.*,java.lang.*,java.util.logging.*,com.ibm.workplace.wcm.api.*,com.ibm.portal.um.*"%> <wps:if locale="en"> <c:set var="prefLanguage" value="en" /> </wps:if> <wps:if locale="ar"> </wps:if> <% try { DocumentId docId = null; DocumentIdIterator itemsIterator = null;
.getDocumentLibrary("Web Content");
Workspace myworkspace = WCM_API.getRepository() .getSystemWorkspace(); if (myworkspace == null) { out.println("Unable to get a valid workspace.<br/>"); } else { out.println("Found workspace<br/>"); } myworkspace.login(); //Set the workspace to the correct library. DocumentLibrary MyLibrary = myworkspace
out.print("<br/><br/>Document id: " + docId.getId());
if (MyLibrary == null) { out.println("Library is null<br/>"); } else { out.println("<br/>My lib is not null"); myworkspace.setCurrentDocumentLibrary(MyLibrary); } itemsIterator = myworkspace.findByName( DocumentTypes.AuthoringTemplate, "Article"); docId = (DocumentId) itemsIterator.next();
itemsIterator = myworkspace.findByName(DocumentTypes.Content, "Sample Article"); docId = (DocumentId) itemsIterator.next(); out.print("<br/><br/>Document id: " + docId.toString()); myworkspace.logout(); } catch (Exception e) { out.println("Exception " + e.getMessage()); e.printStackTrace();
}