Tuesday, December 11, 2012

Sample filter class in ATG

Filter Example:



For Creating filter you need to extend with CachedCollectionFilter class,

All our logic should comes under generateFilteredColection() method,

In this class i have tried to adding some skus to collection,

shouldApplyFilter(), generateContextKey(), generateFilteredCollection() these methods are overriden from CachedCollectionFilter class,


/**
http://immuraliraj.blogspot.in
**/

package atg.custom.filter;

import java.util.Collection;
import java.util.Iterator;

import atg.repository.RepositoryItem;
import atg.service.collections.filter.CachedCollectionFilter;
import atg.service.collections.filter.FilterException;

public class CustomFilter extends CachedCollectionFilter {

    @Override
    public Object generateContextKey(Collection arg0, String arg1,
            RepositoryItem arg2) {
        // TODO Auto-generated method stub
        return null;
    }

   
    @Override
    protected Collection generateFilteredCollection(Collection unfilteredCollection, String collectionIdentifierKey,
            RepositoryItem org) throws FilterException {
        // TODO Auto-generated method stub
        logDebug("Inside the GenerateFilteredCollection : immuraliraj.blogspot.com");
        if(unfilteredCollection == null){       
        return null;
        }
        /*Adding some sku for custom filtered collection*/
        Collection customFilteredCollection = generateNewCollectionObject(unfilteredCollection);
        Iterator iterator = unfilteredCollection.iterator();
        while(iterator.hasNext()){
            RepositoryItem sku = (RepositoryItem)iterator.next();
            customFilteredCollection.add(sku);
        }
       
       
        return customFilteredCollection;
    }

    @Override
    public boolean shouldApplyFilter(Collection arg0, String arg1,
            RepositoryItem arg2) {
        // TODO Auto-generated method stub
        return false;
    }

}


CustomFilter.properties

$class=atg.custom.filter.CustomFilter
$scope=request
cacheEnabled=false



Note: after creating the CustomFilter component, this component will be enable in scenario's so that we can you use this class for creating some sku promotions

No comments:

Popular Posts