| fabrice SZNAJDERMAN 2006-06-28, 7:33 am |
| Hello,
I use WPS5.1 and PUMA Service.
I have developed one group of classes to allow a user service information for all my portlets.
The code below correspond is the main class of my API.
*******
public class UserServiceImpl implements UserService {
/**Champs de l'annuaire LDAP*/
protected final static String FIRST_NAME = "firstname";
protected final static String LAST_NAME = "lastname";
protected final static String FORWARD_MAIL = "mailaddress";
protected final static String OFFICE_PHONE = "telephoneNumber";
protected final static String CELLPHONE = "mobile";
protected final static String LANGUAGE = "preferredLanguage";
protected final static String PASSWORD = "userPassword";
protected final static String UID = "uid";
protected final static String PAGER = "pager";
protected final static String DESCRIPTION = "description";
protected final static String BUSINESS_UNIT = "companyname";
private final static List keyAttribList = new ArrayList();
/**Service Websphere Portal PUMA*/
private final static String SERVICE_PUMA_KEY =
"portletservice/com.ibm.portal.um.portletservice.PumaHome";
private static PumaHome service = null;
static {
try {
initAttribList();
javax.naming.Context ctx = new javax.naming.InitialContext();
PortletServiceHome psh =
(PortletServiceHome) ctx.lookup(SERVICE_PUMA_KEY);
if (psh != null) {
service = (PumaHome) psh.getPortletService(PumaHome.class);
}
} catch (PortletServiceUnavailableException e) {
e.printStackTrace();
throw new RuntimeException(
"Le service d'accès aux utilisateurs est indisponible",
e);
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException(
"Le service d'accès aux utilisateurs est introuvable",
e);
}
}
.....
*********
You can see, I have created a variable service private static and I have init it in a static bloc.
This class is a singleton. So there is just one instance existing.
With this architecture, Just one instance of service object is create (static). All users use this instance to get Objects : PumaController or PumaProfile.
This is a method of the main class which work with service Object below :
/**
* Mes à jour les champs renseigné dans l'objet User.
*/
public void miseAJourUser(User user, PortletRequest request) {
//implémentation de la mise à jour d'un utilisateur
System.out.println("service = " + service);
PumaController pc = service.getController(request);
Map toUpdate = new HashMap();
if (user.getBusinessUnit() != null) {
toUpdate.put(BUSINESS_UNIT, user.getBusinessUnit());
}
if (user.getCellPhone() != null) {
toUpdate.put(CELLPHONE, user.getCellPhone());
}
if (user.getDescription() != null) {
toUpdate.put(DESCRIPTION, user.getDescription());
}
if (user.getEmail() != null) {
toUpdate.put(FORWARD_MAIL, user.getEmail());
}
if (user.getFirstName() != null) {
toUpdate.put(FIRST_NAME, user.getFirstName());
}
if (user.getLanguage() != null) {
toUpdate.put(LANGUAGE, user.getLanguage());
}
if (user.getLastName() != null) {
toUpdate.put(LAST_NAME, user.getLastName());
}
if (user.getOfficePhone() != null) {
toUpdate.put(OFFICE_PHONE, user.getOfficePhone());
}
if (user.getPager() != null) {
toUpdate.put(PAGER, user.getPager());
}
if (user.getPassword() != null) {
toUpdate.put(PASSWORD, user.getPassword());
}
if (user.getDescription() != null) {
toUpdate.put(DESCRIPTION, user.getDescription());
}
try {
System.out.println("pc.getCurrentUser()" + pc.getCurrentUser().toString());
pc.setAttributes(pc.getCurrentUser(),toUpdate);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Une erreur est survenue durant la mise à jour du profil utilisateur");
}
}
According to you is it a problem which just one instance of PumaHome create for all application?
Thank you very for your help in advance!
Best regards!
Fabrice
|