Plumtree PEI - OnBeforeDeleteObject

by Erik Lane 30. March 2005 09:44

So coding .NET in the world of Plumtree is a unique animal..I'm finding out.  The Plumtree devcenter is a pretty good place for help, although there's not much in the discussions going on, and they do have a significant amount of documentation for their EDK/APIs.  I guess like most things you eventually get beyond what's in the documentation and are off on your own.  I found myself there yesterday.

I was needing to use a PEI.  Most Plumtree installs use the OnAfterLogin PEI so there can be some custom things done after the user logs into the portal.  We're using one too and there are examples for them.  I was now needing to know when a Plumtree object was being deleted so we could also delete some supporting data from our database.  So looking in the Plumtree documentation I found that they have an OnBeforeDeleteObject PEI.  Golden?  Well, sorta.  That is the PEI I need to use but now I've got to get to the object being deleted to find out if it is the type of object I'm looking for and if so, if it has supporting data to delete.  Sounds straight forward to me.  I've done similar things with their EDK but now that I'm in a PEI I need to use the Server API which is less friendly...so I'm sharing for anyone else who cares.

I'm checking to see if it is a Portlet (Plumtree classID = 43) and then check its Admin Preferences for a HTMLCodeID.  If it has one then I know that there is data in our database to delete.

Code:

using com.plumtree.debug;
using com.plumtree.server;
using com.plumtree.openfoundation.util;
using com.plumtree.uiinfrastructure.activityspace;
using com.plumtree.portalpages.pei;
 
 
namespace Company.Pei.Object
 {
 
///
 
/// Implementation of IObjectActions.
 
///
 
public class ObjectActions : IObjectActions
 {
 
private const int _portletClassID = 43;
 
public ObjectActions() : base()
 {
 }
 
#region IObjectActions Members
 public string OnBeforeDeleteObject(AActivitySpace _asCurrentSpace, IPTSession _ptUserSession,
 
int _nClassID, int _nObjectID)
 {
 
try
  {
 
if(_nClassID != _portletClassID)
  {
 
return null;
  }
  IPTGadget gadget = (IPTGadget)_ptUserSession.GetGadgets().Open(_nObjectID,
false);
  IPTAdminSettings settings = (IPTAdminSettings)gadget.GetInterfaces(
"IPTAdminSettings");
 
object[][] arr = settings.LookupAdminGadgetSettings("HTMLCodeID");
  PTDebug.Trace(Component.Portal_Admin,TraceType.Info,
"Got arr.  Checking arr");
 
if(arr[0][0] == null)
  {
  PTDebug.Trace(Component.Portal_Portlets,TraceType.Info,
"HTMLCode IsNull - returning null");
  }
 
else
  {
  PTDebug.Trace(Component.Portal_Admin,TraceType.Info,
"Deleting Freeform HTML Portlet: "
  + gadget.GetName() + " HTMLCodeID: " + arr[1][0].ToString());
  RemoveData(Convert.ToInt32(arr[1][0].ToString());
  }
  }
 
catch(Exception e)
  {
  PTDebug.Trace(Component.Portal_Admin, TraceType.Error, e.Message +
"\n" + e.StackTrace);
  }
 
 
return null;
 }
 
#endregion
 }
 }
Tags:
Comments are closed