IBM FileNet P8, Version 5.2.1            

Working with Disposal Policies

The following information and code examples demonstrate disposal policy operations. For an overview of disposal policies, see Disposal Policies.

Creating a Disposal Policy

The following Java™ and C# examples show how to create a CmDisposalPolicy, which schedules an ongoing sweep of rejected proposals older than five years. A time slot is used to schedule the sweep, and is set on the CmPolicyControlledSweep object. The server automatically associates the disposal policy with the CmPolicyControlledSweep object. The association is made through a relationship object, represented by CmSweepPolicyRelationship.

Java Example

static PropertyFilter pf = new PropertyFilter();
...
// Create instance of CmDisposalPolicy.
CmDisposalPolicy disPolicy = Factory.CmDisposalPolicy.createInstance(os);

// Make Proposal class the sweep target.
disPolicy.set_SweepTarget(Factory.ClassDefinition.getInstance(os,new Id("{B03157E9-8E5F-4FAD-A3AE-E163BE77E170}")));

// Specify disposition of rejected proposals older than 5 years.
disPolicy.set_FilterExpression("Now() > DateCreated + TimeSpan(1825, 'days') AND Rejected = true"); 

// Set display name to a unique value.
disPolicy.set_DisplayName("Disposition Policy for Rejected Proposals");

disPolicy.save(RefreshMode.REFRESH);

// Get policy controlled sweep associated with disposal policy.
// A policy is associated with no more than one policy controlled sweep.
// Therefore, there can only be one item in the relationship set.
pf.addIncludeProperty(new FilterElement(0, null, null, "Sweep", null));
PropertyIndependentObjectSet prop = (PropertyIndependentObjectSet) disPolicy.fetchProperty("SweepSubscriptions", pf);
CmSweepPolicyRelationshipSet rs = (CmSweepPolicyRelationshipSet) prop.getIndependentObjectSetValue();
Iterator iter = rs.iterator();
CmPolicyControlledSweep controlledSweep  = ((CmSweepPolicyRelationship)iter.next()).get_Sweep();

// Create timeslots so that the job runs every Friday for 6 hours, starting at midnight.
CmTimeslotList tsList = Factory.CmTimeslot.createList();
CmTimeslot ts = Factory.CmTimeslot.createInstance();
ts.set_Weekday(Weekday.FRIDAY);
ts.set_Duration(Integer.valueOf(360));
ts.set_StartMinutesPastMidnight(Integer.valueOf(0));
tsList.add(ts);

// Set timeslots on policy controlled sweep.
controlledSweep.set_SweepTimeslots(tsList);
controlledSweep.save(RefreshMode.REFRESH);

C# Example

static PropertyFilter pf = new PropertyFilter();
...
// Create instance of ICmDisposalPolicy.
ICmDisposalPolicy disPolicy = Factory.CmDisposalPolicy.CreateInstance(os);

// Make Proposal class the sweep target.
disPolicy.SweepTarget = Factory.ClassDefinition.GetInstance(os, new Id("{B03157E9-8E5F-4FAD-A3AE-E163BE77E170}"));

// Specify disposition of rejected proposals older than 5 years.
disPolicy.FilterExpression = "Now() > DateCreated + TimeSpan(1825, 'days') AND Rejected = true";

// Set display name to a unique value.
disPolicy.DisplayName = "Disposition Policy for Rejected Proposals";

disPolicy.Save(RefreshMode.REFRESH);

// Get policy controlled sweep associated with disposal policy.
// A policy is associated with no more than one policy controlled sweep.
// Therefore, there can only be one item in the relationship set.
pf.AddIncludeProperty(new FilterElement(0, null, null, "Sweep", null));
IPropertyIndependentObjectSet prop = (IPropertyIndependentObjectSet)disPolicy.FetchProperty("SweepSubscriptions", pf);
ICmSweepPolicyRelationshipSet prSet = (ICmSweepPolicyRelationshipSet)prop.GetIndependentObjectSetValue();
System.Collections.IEnumerator enumerator = prSet.GetEnumerator();
enumerator.MoveNext();
ICmPolicyControlledSweep controlledSweep = ((ICmSweepPolicyRelationship)enumerator.Current).Sweep;

// Create timeslots so that the job runs every Friday for 6 hours, starting at midnight.
ICmTimeslotList tsList = Factory.CmTimeslot.CreateList();
ICmTimeslot ts = Factory.CmTimeslot.CreateInstance();
ts.Weekday = Weekday.FRIDAY;
ts.Duration = 360;
ts.StartMinutesPastMidnight = 0;
tsList.Add(ts);

// Set timeslots on policy controlled sweep.
controlledSweep.SweepTimeslots = tsList;
controlledSweep.Save(RefreshMode.REFRESH);

Getting Disposal Policies

The following Java and C# examples show how to retrieve all disposal policies persisted in an object store. The code retrieves all of the sweep policies from the object store, then iterates the sweep policies in search of the disposal policies. The code then prints information about each disposal policy.

Java Example

// Get sweep policies persisted in the object store.
CmSweepPolicySet spSet = os.get_SweepPolicies();

// Iterate sweep policy set.
Iterator iter = spSet.iterator();
while (iter.hasNext())
{
   CmSweepPolicy sweepPolicy  = (CmSweepPolicy) iter.next();

   // Test if policy is a disposal policy.
   if (sweepPolicy.getClassName().equalsIgnoreCase("CmDisposalPolicy"))
   {
      // Get each policy's policy controlled sweep.
      // A policy is associated with no more than one policy controlled sweep.
      // Therefore, there can only be one item in the set.
      CmSweepPolicyRelationshipSet sprSet = sweepPolicy.get_SweepSubscriptions();
      Iterator iter2 = sprSet.iterator();
      CmPolicyControlledSweep controlledSweep  = ((CmSweepPolicyRelationship)iter2.next()).get_Sweep();

      System.out.println("Id of controlled sweep: " + controlledSweep.get_Id().toString());
      System.out.println("Disposal policy name: " + sweepPolicy.get_DisplayName());
      System.out.print("Start date: " + sweepPolicy.get_EffectiveStartDate());
      System.out.print("   End date: " + sweepPolicy.get_EffectiveEndDate());
      System.out.println("   Enabled?: " + sweepPolicy.get_IsEnabled() );
      System.out.print("Examined objects: " + sweepPolicy.get_CurrentExaminedObjectCount());
      System.out.print("   Processed objects: " + sweepPolicy.get_CurrentProcessedObjectCount() );
      System.out.println("   Failed objects: " + sweepPolicy.get_CurrentFailedObjectCount() + "\n" );
   }
}

C# Example

// Get sweep policies persisted on the object store.
ICmSweepPolicySet spSet = os.SweepPolicies;

// Iterate sweep policy set.
foreach (ICmSweepPolicy sweepPolicy in spSet)
{
   // Test if policy is a disposal policy.
   if (sweepPolicy.GetClassName().Equals("CmDisposalPolicy"))
   {
      // Get each policy's policy controlled sweep.
      // A policy is associated with no more than one policy controlled sweep.
      // Therefore, there can only be one item in the set.
      ICmSweepPolicyRelationshipSet sprSet = sweepPolicy.SweepSubscriptions;
      System.Collections.IEnumerator enumerator = sprSet.GetEnumerator();
      enumerator.MoveNext();
      ICmPolicyControlledSweep controlledSweep = ((ICmSweepPolicyRelationship)enumerator.Current).Sweep;

      System.Console.WriteLine("Id of controlled sweep: " + controlledSweep.Id.ToString());
      System.Console.WriteLine("Disposal policy name: " + sweepPolicy.DisplayName);
      System.Console.Write("Start date: " + sweepPolicy.EffectiveStartDate);
      System.Console.Write("   End date: " + sweepPolicy.EffectiveEndDate);
      System.Console.Write("   Enabled?: " + sweepPolicy.IsEnabled);
      System.Console.Write("   Examined objects: " + sweepPolicy.CurrentExaminedObjectCount);
      System.Console.Write("   Processed objects: " + sweepPolicy.CurrentProcessedObjectCount);
      System.Console.WriteLine("   Failed objects: " + sweepPolicy.CurrentFailedObjectCount + "\n");
   }
}

Deleting Disposal Policies

The following Java and C# examples show how to delete the disposal policies that target the Proposal class. The code uses an SQL query to retrieve the disposal policies, iterates the result set, and deletes the applicable policies.

Java Example

// Create a SearchSQL instance.
SearchSQL sqlObject = new SearchSQL();
sqlObject.setMaxRecords(20);
sqlObject.setFromClauseInitialValue("CmDisposalPolicy", null, true); 
                
// Check the SQL statement.          
System.out.println("SQL: " + sqlObject.toString()); 

// Create a SearchScope instance.
SearchScope search = new SearchScope(os);

// Execute the fetchObjects method using the specified parameters.
IndependentObjectSet myObjects = search.fetchObjects(sqlObject, null, null, null);
            
// Iterate disposal policies and delete the ones that target the Proposal class.
Iterator iter = myObjects.iterator();
while (iter.hasNext())
{
   CmDisposalPolicy policyObject = (CmDisposalPolicy) iter.next();
   if (policyObject.get_SweepTarget().get_Name().equalsIgnoreCase("Proposals") )
   {
      policyObject.delete();
      System.out.println(policyObject.get_DisplayName() + " deleted.");
      policyObject.save(RefreshMode.REFRESH);
   }
}

C# Example

// Create a SearchSQL instance.
SearchSQL sqlObject = new SearchSQL();
sqlObject.SetMaxRecords(20);
sqlObject.SetFromClauseInitialValue("CmDisposalPolicy", null, true); 
                
// Check the SQL statement.          
System.Console.WriteLine("SQL: " + sqlObject.ToString()); 

// Create a SearchScope instance.
SearchScope search = new SearchScope(os);
            
// Execute the fetchObjects method using the specified parameters.
IIndependentObjectSet myObjects = search.FetchObjects(sqlObject, null, null, null);

// Iterate disposal policies and delete the ones that target the Proposal class.
foreach (ICmDisposalPolicy policyObject in myObjects)
{
   if (policyObject.SweepTarget.Name.Equals("Proposals") )
   {
      policyObject.Delete();
      System.Console.WriteLine(policyObject.DisplayName + " deleted.");
      policyObject.Save(RefreshMode.REFRESH);
   }
}


Last updated: October 2015
disposalpolicy_procedures.htm

© Copyright IBM Corporation 2015.