| 10377287 2004-01-19, 2:56 pm |
| Hello,
Here is a test portlet I have made in order to emphasize the problem of puma Group attributes persistence. Unlike the puma User attributes persistence which is working well, it seems that, even if we can add attributes to puma Group and retrieve during th
e living time of the Group object, we can't make them persist in the portal database (one more time, it's working with the puma User). That's why I want to know if it is possible and how or is this a bug of the puma API.
Morevover here are the steps for my test :
1. Install the portlet and add it to a page
2. Display the portlet page : Test attribute values must be null if it is the first time you do it
3. Go to Edit Mode
4. Come back to view mode : Test attribute values must have changed to test1, test2, ...
package portlet;
import java.io.*;
import com.ibm.wps.puma.*;
import com.ibm.wps.puma.beans.*;
import java.util.*;
import javax.naming.directory.*;
import org.apache.jetspeed.portlet.*;
/**
* The problem is not really the possibility to add attributes to users or groups
* but it deals with the data persistence. To test it, you have to go to the edit mode and then
* come back to the view mode. The edit mode must add the attribute and make him persist
* thanks to the sync method. And the problem is that it is working for users and not for groups.
*
*/
public class MyPortlet extends PortletAdapter {
public void init(PortletConfig portletConfig) throws UnavailableException {
super.init(portletConfig);
}
/**
* View mode : just displays the Test attribute value for all
*
*/
public void doView(PortletRequest request, PortletResponse response)
throws PortletException, IOException {
try {
PrintWriter out = response.getWriter();
UserAccessBean uab = new UserAccessBean();
Vector users = uab.findUserAll();
Vector groups = uab.findGroupAll();
out.println("Users : <br><br>");
for (int i=0;i<users.size();i++) {
com.ibm.wps.puma.User user = (com.ibm.wps.puma.User) users.elementAt(i);
/*
* Set the user's attribute
*/
//user.put( "Test", "Test Value User") ;
out.println(user.getCommonName() + " Test : " + user.get("Test") + "<br>");
Vector userGroups = user.getGroups() ;
for( int idx = 0; idx < userGroups.size(); idx++ ) {
Group group = (Group) userGroups.elementAt( idx ) ;
out.println( " belongs to: " + group.getCommonName() + " <br>") ;
}
}
out.println("<hr><br><br>Groups : <br><br>");
for (int i=0;i<groups.size();i++) {
com.ibm.wps.puma.Group group = (com.ibm.wps.puma.Group) groups.elementAt(i);
/*
* Now set the group's attribute to some arbitrary value and retrieve it again
*/
//group.put( "Test", "Test Value Group" );
out.println(group.getCommonName() + " Test : " + (String)group.get("Test") + "<br>");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* add Test attribute and make data persist
*
*/
public void doEdit(PortletRequest request, PortletResponse response)
throws PortletException, IOException {
try {
PrintWriter out = response.getWriter();
UserAccessBean uab = new UserAccessBean();
Vector users = uab.findUserAll();
Vector groups = uab.findGroupAll();
for (int i=0;i<users.size();i++) {
com.ibm.wps.puma.User user = (com.ibm.wps.puma.User) users.elementAt(i);
//attribute Test is added to the user
user.put("Test", "test" + i);
//attribute must be synchronized with the database
uab.sync(user);
}
for (int i=0;i<groups.size();i++) {
com.ibm.wps.puma.Group group = (com.ibm.wps.puma.Group) groups.elementAt(i);
//attribute Test is added to the group
group.put("Test", "test" + i);
//attribute must be synchronized with the database
uab.sync(group);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|