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:
Create a component based on the
atg.purge.condition.SimpleRelatedCondition
class. See Property Configuration for Related Condition Components.Include the Nucleus path to your related condition component in the
relatedConditions
property value for yourPurgeConfiguration
component. See PurgeConfiguration Component.Override the
canPurge
method for the pipeline component that is based on theatg.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 valuetrue
. Implement your own logic and return eithertrue
to delete an item orfalse
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 |
---|---|
| 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 If you need to localize the Dynamo Server Admin user interface, you can supply the resource bundle key for this label in the |
| The key for the parameter in the |
| The value of the parameter in the 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 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 |
| Controls whether users can enter or make changes to the parameter value. See the description of the |
| 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; } } }