Include related conditions in your asset purge function if you need to determine whether to delete a repository item based on information that is not stored in the properties of the item itself. See Related Conditions and Actions.

To configure a related condition component:

  1. Create a component based on the atg.purge.condition.SimpleRelatedCondition class. See Property Configuration for Related Condition Components.

  2. Include the Nucleus path to your related condition component in the relatedConditions property value for your PurgeConfiguration component. See PurgeConfiguration Component.

  3. Override the canPurge method for the pipeline component that is based on the atg.purge.pipeline.processor.CanPurgeProcessor class. This processor component determines whether to delete each repository item that passes through the purge pipeline. See information about this and other basic asset purge components in Configuring Basic Purging Components.

    By default, the canPurge method returns the boolean value true. Implement your own logic and return either true to delete an item or false to skip it. See an example Java class in Overriding the canPurge Method.

Property Configuration for Related Condition Components

Include the properties described in the following table for a related condition component:

Property

Description

defaultName

The user-interface label that describes the related condition.

The label includes a text box to display or edit the parameter value. Include the variable $X in this property value to place the text box inside the label string. If you do not include $X, the text box appears at the end of the label string.

If you need to localize the Dynamo Server Admin user interface, you can supply the resource bundle key for this label in the displayKey property. Include the displayKey property instead of the defaultName property. See information about localizing Web applications in the Platform Programming Guide.

parameterName

The key for the parameter in the java.util.Map of parameters for the PurgeItem objects that represent each repository item in the asset purge pipeline. See PurgeItem Parameters.

parameterValue

The value of the parameter in the java.util.Map of parameters for the PurgeItem objects that represent each repository item in the asset purge pipeline. See PurgeItem Parameters.

The asset purge user interface displays the parameter value along with the label for the related condition. The value appears in a text box at the end of the label. You can move the text box into the label string by including the $X variable in the label text. See the description for the defaultName property.

Note: the label for a related condition always contains a text box to display the parameter value, even if you do not specify or use the value.

Users can enter or make changes to the parameter value if the editable property is set to true.

editable

Controls whether users can enter or make changes to the parameter value. See the description of the parameterValue property.

enabled

Controls whether the related condition is selected in the user interface by default.

The following example configuration file sets the property values for a related condition component.

$class=atg.purge.condition.SimpleRelatedCondition

# A user-interface label that describes the related condition
defaultName=Skip if there are more than $X member orders

# The key for the parameter associated with this condition in the
# Map of parameters for the PurgeItem
parameterName=maxorders
# The value for the parameter in the Map of parameters
parameterValue=2

# Determines whether the end user can alter the parameter value
editable=true

# Determines whether the related condition is selected by default
enabled=true
Overriding the canPurge Method

The basic components of the asset purge development framework include a pipeline processor that controls whether each selected repository item is deleted or skipped. By default, this component is based on the atg.purge.pipeline.processor.CanPurgeProcessor class and it deletes all of the items that it handles. See information about the default processor component in CanPurgeProcessor Component.

The CanPurgeProcessor class includes a canPurge method that returns a Boolean value. If you include a related condition in your asset purge function, create a subclass of CanPurgeProcessor and override its canPurge method. Include the logic that determines whether an item is deleted or skipped in this method.

  • Return true to delete the current repository item.

  • Return false to skip the current repository item.

The following example shows a Java class that overrides the canPurge method. It uses two properties to hold Nucleus paths:

  • The path to the repository that includes the repository items to be purged

  • The path to an OrderQueries component that provides tools for accessing information about orders

These two properties are only used in this example. They are not directly related to overriding the canPurge method.

package mycompany;
import java.util.ArrayList;
import java.util.Set;
import atg.commerce.order.OrderQueries;
import atg.purge.PurgeItem;
import atg.purge.pipeline.processor.CanPurgeProcessor;
import atg.repository.Repository;
import atg.repository.RepositoryItem;

public class MyNewCanPurgeProcessor extends CanPurgeProcessor {

  // The repository and orderQueries properties are used in
  // the example code shown here and are not directly related
  // to overriding the canPurge method.
  // Set the repository from the configuration file.

  Repository mRepository;
  public void setRepository(Repository pRepository)
  {mRepository = pRepository;}
  public Repository getRepository()
  {return mRepository;}
  // Set the OrderQueries path from the configuration file.
  OrderQueries mOrderQueries;
  public void setOrderQueries(OrderQueries pOrderQueries)
  {mOrderQueries = pOrderQueries;}
  public OrderQueries getOrderQueries()
  {return mOrderQueries;}

  // Override the canPurge method with logic based on your related conditions.
  @Override
  protected boolean canPurge(PurgeItem pPurgeItem) throws Exception {
    // Get the repository item that is currently being handled.
    RepositoryItem organization = getRepository().getItem(pPurgeItem.getId(),
      pPurgeItem.getItemType());

    // For example, you could determine how many orders are associated with the
    // users in this organization.

    int ordersforthisorg = 0;
    // Get the user profiles from the members property of the organization.
    Set memberset = (Set) organization.getPropertyValue("members");
    ArrayList<RepositoryItem> members = new ArrayList<RepositoryItem>(memberset);
    for (RepositoryItem member : members) {
      // get the number of orders associated with the profile
      int memberorders =
        getOrderqueries().getOrderCountForProfile(member.getRepositoryId());
      // and add it to the total orders for the organization
      ordersforthisorg = ordersforthisorg + memberorders;
    }

    // This example compares the maximum number of orders from the related
    // condition to the number of orders for the members of the organization.
    // Return true (delete) or false (skip) based on what you find.
    // If the parameter is not present in the PurgeItem, return true.
    // If the user does not select this related condition, the parameter
    // will not be present.

    // Get the maximum number of orders from the PurgeItem parameter with
    // the key "maxorders."
    int maxordersfromassociatedcondition = Integer.parseInt((String)
      pPurgeItem.getParameters().get("maxorders"));
    // Compare the numbers.
    if (pPurgeItem.getParameters().get("maxorders") != null &&
      ordersforthisorg > maxordersfromassociatedcondition) {
      // Do not delete the organization.
      return false;
    } else {
      // Delete the organization.
      return true;
    }
  }
}

Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices