How to Add "Uncategorized" as an Option to Category Filters in Jive 6.x

Version 2

    Hi everyone, on this edition of "How To In Jive 6" we are going to show you how to add the option of filtering by "uncategorized" content with just some peanut butter and a pine cone--wait a minute, no, that was my tutorial on how to make a bird feeder.

     

     

    Ok, enough with the jokes, lets get down to business.

     

     

    In the content tab of a place, there is a nifty tool that let you filter your content results by a category (see the picture below).  However, if you ever wanted to find out what content doesn't have a category you'll need to click on every piece of content and fill your spreadsheet with the names you find.  Well, that's not very efficient, and I thought I'd share how I added the uncategorized option with a very small amount of code.

     

     

     

    Screenshot-19.png

     

     

     

    First, we have to make a new BrowseFilter class that will tell the application how to filter out the things we do not want; in our case, this is everything that has a category (TagSet in the code) attached to it.

     

     

    Here is the code that does this:

     

    package com.pega.mesh.community.browse.filter;
    
    import java.util.List;
    import java.util.Set;
    
    import com.google.common.collect.Lists;
    import com.jivesoftware.community.browse.QueryFilterDef;
    import com.jivesoftware.community.browse.filter.AbstractBrowseFilter;
    import com.jivesoftware.community.browse.filter.AppliedResultCountFilter;
    import com.jivesoftware.community.browse.filter.BrowseFilter;
    import com.jivesoftware.community.browse.rest.FilterBean;
    import com.jivesoftware.community.browse.rest.impl.AbstractFilterBean;
    
    /**
    * A filter for uncategorized content
    */
    public class MeshUnCategorizedFilter extends AbstractBrowseFilter implements AppliedResultCountFilter {
    
        private final static String PSEUDO_TAGSET_NAME = "uncategorized";
        private final static String CATEGORY_NAME = "Uncategorized";
        public final static String FILTER_NAME_PREFIX = "category";
    
    
        public MeshUnCategorizedFilter() {
            super(makeId(FILTER_NAME_PREFIX, PSEUDO_TAGSET_NAME), CATEGORY_NAME);
        }
    
        @Override
        public FilterBean toBean() {
    
            return new AbstractFilterBean(this){
                @Override
                public String getType() {
                    return "sidebar";
                }
    
            };
        }
    
    
        @Override
        public QueryFilterDef getQueryFilterDef(Set<BrowseFilter> browseFilters, QueryFilterDef.Archetype archetype) {
                StringBuilder predicate = new StringBuilder();
                List<QueryFilterDef.ParamType> paramTypes = Lists.newArrayList();
                List<Object> params = Lists.newArrayList();
    
                predicate.append(" objectid not in (select objectid from jiveobjecttagset) ");
    
                return new QueryFilterDef(true, null, predicate.toString(), paramTypes, params);
        }
    
    }
    
    
    
    
    
    

     

     

     

    The important part of the code is the getQueryFilterDef method which appends your filter--which is actually a part of the where clause of the query that gets executed to retrieve the content--to the result set.  Since this is a query we append " objectid not in (select objectid from jiveobjecttagset) " so that we get rid of anything that has a tagset/category in it--make sure you have the spaces in the front and back of the string just to be safe.

     

     

    Now that we have the logic to filter our content, we need to make sure that when the application goes to get the content he knows to use our new filter.

     

     

    For this, I found it easiest to overlay the PlaceContentObjectBrowseFilterGroupProvider.java class and add the following lines right after the for loop of adding the tagsets (after line 107):

     

    rootFilter.addChild(new MeshUnCategorizedFilter(){
        @Override
        public FilterBean toBean() {
                        return new SimpleFilterBean(this) {
                            public boolean isNested() {
                                return true;
                            }
                        };
                    }
                });
    
    
    
    

     

     

     

    This will add our custom filter to the list of known filters and we will now be able to filter by "Uncategorized."

     

     

    Here are some cool tidbits about what we just did:

     

     

    Below is a  pic of the new look:

     

    Screenshot.png

     

     

    That's it! Now you can look at all the uncategorized content and say "Hey, go put some categories on this stuff!"