• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PumaService - good Pratice?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic