001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.taskadmin;
014:
015: import java.util.Iterator;
016: import java.util.Set;
017: import java.util.HashSet;
018:
019: import javax.servlet.http.HttpServletRequest;
020:
021: import com.sun.portal.taskadmin.ChannelTaskAdmin;
022: import com.sun.portal.taskadmin.TaskAdminException;
023: import com.sun.portal.taskadmin.TaskAdminConstants;
024: import com.sun.portal.taskadmin.context.TaskAdminContext;
025: import com.sun.portal.taskadmin.context.TaskAdminContextFactory;
026: import com.sun.portal.taskadmin.context.TaskAdminContextFactoryManager;
027: import com.sun.portal.taskadmin.context.ISChannelTaskAdminContext;
028:
029: import com.sun.portal.desktop.dp.DPChannel;
030:
031: import com.sun.portal.wsrp.consumer.common.WSRPProviderConstants;
032: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
033: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManagerFactory;
034: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
035: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
036: import com.sun.portal.wsrp.common.stubs.PortletDescription;
037: import com.sun.portal.wsrp.common.stubs.LocalizedString;
038: import com.sun.portal.wsrp.WSRPException;
039: import com.iplanet.sso.SSOException;
040: import com.iplanet.am.sdk.AMException;
041: import com.iplanet.am.sdk.AMRole;
042:
043: /**
044: * This class implements the APIs that can be used
045: * to achieve a set of administrative tasks associated
046: * with WSRP.
047: */
048: public class WSRPTaskAdmin extends ChannelTaskAdmin {
049:
050: //Reference to ProducerEntityManager that administer remote web services offered by the producers.
051: ProducerEntityManager pem = null;
052:
053: public WSRPTaskAdmin(HttpServletRequest req, String baseDN)
054: throws TaskAdminException {
055: super (req, baseDN);
056: try {
057: //initialize ProducerEntityManager.
058: pem = ProducerEntityManagerFactory.getInstance()
059: .getProducerEntityManager(
060: context.getOrganizationDN(baseDN), req);
061: } catch (WSRPException e) {
062: throw new TaskAdminException(
063: "WSRPTaskAdmin():Unable to intialize WSRPTaskAdmin",
064: e);
065: }
066: }
067:
068: /**
069: * Creates a new WSRP portlet channel.
070: * A new channel is created based on the _WSRPProvider.
071: * To create a nested channel, supply a hierarchical channel
072: * name. For example, to create channel A inside of container X, based on
073: * _WSRPProvider provider <br><br>
074: * <code>createWSRPChannel("X" + "/" + "A", "MyProducerId", "MyPortletId");</code>
075: * @param chname WSRP channel name.
076: * @param pid produer entity id (producer id)
077: * @param rid portlet id (portlet handler)
078: * @throws TaskAdminException throws if exception ocurred during WSRP channel creation.
079: */
080: public void createWSRPChannel(String chname, String pid, String rid)
081: throws TaskAdminException {
082: createChannel(chname, WSRPProviderConstants.WSRP_PROVIDER);
083: DPChannel ch = dpRoot.getChannel(chname);
084: ch.getProperties().setString(WSRPProviderConstants.CONSUMER_ID,
085: context.getOrganizationDN(baseDN));
086: ch.getProperties().setString(
087: WSRPProviderConstants.PRODUCER_ENTITY_ID, pid);
088: ch.getProperties().setString(WSRPProviderConstants.PORTLET_ID,
089: rid);
090: ch.getProperties().setString(
091: WSRPProviderConstants.PORTLET_HANDLE, rid);
092: }
093:
094: /**
095: * Returns the name of producer for the given producer ID.
096: * @param producerID producer id.
097: * @return producer name if valid producerID passed.
098: * @throws TaskAdminException throws if exception ocurred during retrieveing the producer name.
099: */
100: public String getProducerName(String producerID)
101: throws TaskAdminException {
102: try {
103: return pem.getProducerEntity(producerID).getName();
104: } catch (WSRPException e) {
105: Object[] tokens = { baseDN, producerID, e.getMessage() };
106: throw new TaskAdminException(
107: TaskAdminConstants.PRODUCER_NAME_ERROR, tokens);
108: }
109: }
110:
111: /**
112: * This method returns the list of producer IDs that are existing
113: * at the baseDN that is passed in. The producers in this list
114: * can be used to get the portlets list by the user that can administer
115: * the baseDN that is passed in.
116: * @return Set of producers that are available at this baseDN.
117: */
118: public Set getExistingProducerIds() throws TaskAdminException {
119: try {
120: return pem.getProducerEntityIds();
121: } catch (WSRPException e) {
122: e.printStackTrace();
123: Object[] tokens = { baseDN, e.getMessage() };
124: throw new TaskAdminException(
125: TaskAdminConstants.PRODUCERS_ID_LIST_ERROR, tokens);
126: }
127: }
128:
129: /**
130: * Returns the portlet ids list for the given producer ID.
131: * @param producerID produer id
132: * @return Set contaning portlet handlers list.
133: * @throws TaskAdminException
134: */
135: public Set getPortletHandlers(String producerID)
136: throws TaskAdminException {
137: HashSet portletHandlers = new HashSet();
138: try {
139: ProducerEntity pe = pem.getProducerEntity(producerID);
140: ServiceDescription sd = pe.getServiceDescription();
141: PortletDescription[] portlets = sd.getOfferedPortlets();
142: for (int i = 0; i < portlets.length; i++) {
143: String handle = portlets[i].getPortletHandle();
144: portletHandlers.add(handle);
145: }
146: } catch (WSRPException e) {
147: Object[] tokens = { baseDN, e.getMessage() };
148: throw new TaskAdminException(
149: TaskAdminConstants.PORTLETS_HANDLER_LIST_ERROR,
150: tokens);
151: }
152: return portletHandlers;
153: }
154:
155: /**
156: * Returns the name of portlet for the given producer ID and portletID.
157: * @param producerID producer id.
158: * @param portletID portlet id (portlet handler)
159: * @return portlet name if valid producerID and portletID passed.
160: * @throws TaskAdminException throws if exception ocurred during retrieveing the portlet name.
161: */
162: public String getPortletName(String producerID, String portletID)
163: throws TaskAdminException {
164: try {
165: PortletDescription pd = pem.getProducerEntity(producerID)
166: .getPortletDescription(portletID);
167: LocalizedString name = pd.getDisplayName();
168: if (name != null && name.getValue() != null) {
169: return name.getValue();
170: } else {
171: //if LocalizedString is null , then return the
172: // portlet handle as a portlet name.
173: return pd.getPortletHandle();
174: }
175: } catch (WSRPException e) {
176: Object[] tokens = { baseDN, producerID, portletID,
177: e.getMessage() };
178: throw new TaskAdminException(
179: TaskAdminConstants.PORTLET_NAME_ERROR, tokens);
180: }
181: }
182: }
|