/**
* Copyright 1999-2001 by Nordija <www.nordija.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**/
package com.nordija.portal;
import java.rmi.RemoteException;
import java.util.*;
import java.io.*;
import java.text.*;
import javax.naming.*;
import javax.ejb.*;
import com.nordija.midtier.utilitybeans.sequence.sessionbean.SequenceServiceHome;
import com.nordija.midtier.utilitybeans.sequence.sessionbean.SequenceService;
import com.nordija.midtier.utilitybeans.sequence.entitybean.Range;
import com.nordija.portal.entity.*;
/**
* This stateless session EJBean is the interface to
* the Portal Administration Service
*/
public class PortalAdminBean
extends com.nordija.midtier.ejb.BaseSessionBean
implements PortalAdminBusiness {
// TODO: Move to properties
private String jndi_userhome = "nordija.portal.UserHome";
private String jndi_portlethome = "nordija.portal.PortletHome";
private String jndi_layouthome = "nordija.portal.LayoutHome";
private transient UserHome userHome;
private transient PortletHome portletHome;
private transient LayoutHome layoutHome;
private Range portletRange;
private Range userRange;
public void ejbCreate() {
System.out.println("Creating new PortalAdminBean");
}
public void ejbPostCreate() {
}
/**
* Retrieves display information about all portlets defined in the portal database
*/
public PortletData[] listPortlets() throws NamingException, RemoteException, FinderException {
Enumeration enum = getPortlets();
Vector data = new Vector();
PortletData[] moddata=null;
while(enum.hasMoreElements()) {
PortletData m = ((Portlet)enum.nextElement()).getAll();
data.addElement(m);
}
moddata = new PortletData[data.size()];
data.copyInto(moddata);
return moddata;
}
/**
* Retrieves display information about all layouts defined in the portal database
*/
public LayoutData[] listLayouts() throws NamingException, RemoteException, FinderException {
Enumeration enum = getLayouts();
Vector data = new Vector();
LayoutData[] moddata=null;
while(enum.hasMoreElements()) {
LayoutData m = ((Layout)enum.nextElement()).getAll();
data.addElement(m);
}
moddata = new LayoutData[data.size()];
data.copyInto(moddata);
return moddata;
}
/**
* Retrieves display information about all users defined in the portal database
*/
public UserData[] listUsers() throws NamingException, RemoteException, FinderException {
Enumeration enum = getUsers();
Vector data = new Vector();
UserData[] moddata=null;
while(enum.hasMoreElements()) {
UserData m = ((User)enum.nextElement()).getAll();
data.addElement(m);
}
moddata = new UserData[data.size()];
data.copyInto(moddata);
return moddata;
}
/**
* Retrieves all portlets defined in the portal database
*/
public Enumeration getPortlets() throws NamingException, RemoteException, FinderException {
return fetchPortletHome().findAll();
}
/**
* Retrieves all layouts defined in the portal database
*/
public Enumeration getLayouts() throws NamingException, RemoteException, FinderException {
return fetchLayoutHome().findAll();
}
/**
* Retrieves all users defined in the portal database
*/
public Enumeration getUsers() throws NamingException, RemoteException, FinderException {
return fetchUserHome().findAll();
}
public User createUser()
throws CreateException, RemoteException, NamingException {
return createUser("no name", "");
}
public User createUser(String name, String email)
throws CreateException, RemoteException, NamingException {
if(userRange == null) {
System.out.println("new userRange");
Context ctx = new InitialContext();
SequenceServiceHome home = (SequenceServiceHome)ctx.lookup("nordija.portal.sequence");
SequenceService seq = home.create();
userRange = seq.getSequenceRange("User",true,10);
}
UserPK pk = new UserPK(userRange.getNextUniqueNumber());
User mod = fetchUserHome().create();
mod.setName(name);
mod.setEmail(email);
return mod;
}
public void deleteUser(long id) throws NamingException, RemoteException, RemoveException {
fetchUserHome().remove(new UserPK(id));
}
public User findUser(long id) throws FinderException, NamingException, RemoteException {
return fetchUserHome().findByPrimaryKey(new UserPK(id));
}
public User findUserByName(String user) throws FinderException, NamingException, RemoteException {
return fetchUserHome().findByUserName(user);
}
public Portlet createPortlet(String name, String jspfile, String description)
throws CreateException, RemoteException, NamingException {
return createPortlet(name, jspfile, description, Portlet.WIDE_PORTLET);
}
public Portlet createPortlet(String name, String jspfile, String description, int widenarrow)
throws CreateException, RemoteException, NamingException {
if(portletRange == null) {
Context ctx = new InitialContext();
SequenceServiceHome home = (SequenceServiceHome)ctx.lookup("nordija.portal.sequence");
SequenceService seq = home.create();
portletRange = seq.getSequenceRange("Portlet",true,10);
}
PortletPK pk = new PortletPK(portletRange.getNextUniqueNumber());
Portlet mod = fetchPortletHome().create(pk, name, widenarrow);
mod.setJspfile(jspfile);
mod.setDescription(description);
return mod;
}
public void deletePortlet(long id) throws NamingException, RemoteException, RemoveException {
fetchPortletHome().remove(new PortletPK(id));
}
public Portlet findPortlet(long id) throws FinderException, NamingException, RemoteException {
return fetchPortletHome().findByPrimaryKey(new PortletPK(id));
}
//////////////////////////////////////////////////////
// Utility methods
/**
* Obtains a reference to the PortletHome
* @return The obtained object reference
*/
protected PortletHome fetchPortletHome() throws NamingException, RemoteException {
if(portletHome == null) {
Context ctx = new InitialContext();
portletHome = (PortletHome)ctx.lookup(jndi_portlethome);
}
return portletHome;
}
/**
* Obtains a reference to the LayoutHome
* @return The obtained object reference
*/
protected LayoutHome fetchLayoutHome() throws NamingException, RemoteException {
if(layoutHome == null) {
Context ctx = new InitialContext();
layoutHome = (LayoutHome)ctx.lookup(jndi_layouthome);
}
return layoutHome;
}
/**
* Obtains a reference to the Userhome
* @return The obtained object reference
*/
protected UserHome fetchUserHome() throws NamingException, RemoteException {
if(userHome == null) {
Context ctx = new InitialContext();
userHome = (UserHome)ctx.lookup(jndi_userhome);
}
return userHome;
}
}