Skip to content

Extending the Platform with Handlers

MECEAP provides tons of extension points allowing custom code to add or change default behavior.

This can be achieved by implementing specific interfaces and exposing it to the Spring Context with @Component or similar.

DocumentFilterCriteriaHandler

Allows to change a FilterCriteria by defining search settings and options for a given document. Every criteria will be intercepted by this handler and will respect the defined settings.

e.g. Adding a negative boost on "old fashioned" type and defining some aggregations for a Document CoffeeRequest

@Component
public class CoffeeReqSearchParams implements DocumentFilterCriteriaHandler<CoffeeRequest> {

    @Override
    void handlerFilterCriteria(FilterCriteria filterCriteria) {
        SearchParams searchParams = filterCriteria.getSearchParams();

        searchParams.addNegativeBoost("coffeeData.type", "old fashioned");

        searchParams.addAggregation(new SearchAggregation()
                .setFieldName("coffeeData.requester.raw")
                .setAggregationType(SearchAggregation.AggregationType.FacetCount)
                .setAggregationName("coffeeData.requester")
                .setTermsAggregationSize(searchParams.getFacetSize())
                .setClazz(CoffeeRequest.class));

        searchParams.addSuggestFields("coffeeData.requester");
    }
}

You can also add/remove some arbitrary criterion using the filterCriteria.and(..) or filterCriteria.getCriterionList()

IndexSettingHandler

Allows to modify the default Mapping Configuration for FullTextSearch.

e.g. Adding new filter and analyser to the default settings for a Document called Supplier

import br.com.me.ceap.dynamic.extension.search.IndexSettingHandler;
import br.com.me.supplier.document.supplier.Supplier;
// ...


@Named
public class SupplierIndexSettingHandler implements IndexSettingHandler<Supplier> {

    @Override
    public IndexSetting settings(IndexSetting defaultSetting) {
        return defaultSetting
                .addFilter(
                        new FilterSetting("myStemmer_ptBR", "stemmer")
                                .addSetting("language", "brazilian"),
                        new FilterSetting("stop_ptBR", "stop")
                                .addSetting("stopwords", "_brazilian_")
                ).addAnalyzer(
                        new AnalyzerSetting("default", "custom")
                                .addCharFilter("html_strip")
                                .addFilter("lowercase", "asciifolding", "stop_ptBR", "stemmer_ptBR")
                );
    }
}

Note that the code is using defaultSetting and adding new filter and analyser to it. The defaultSeeting could be totally ignored, though. In this case just use a new IndexSetting() instead.

SidebarHandler

Allows to modify the sidebar menu by adding custom links.

**e.g. Adding a custom link Categories to the sidebar menu **

import br.com.me.ceap.dynamic.extension.menu.MenuLink;
import br.com.me.ceap.dynamic.extension.web.SideBarHandler;
// ...

@Component
public class SidebarHandler implements SideBarHandler {

    @Override
    public List<MenuLink> getSideBarMenu(List<MenuLink> menu, UserHumanBeing userHumanBeing, UserCustomRoot userCustomRoot) {

        MenuLink category = new MenuLink();
        category.setTitle(UserCatalog.getMessage("label.categories"));
        category.setUrl(CategoryControllerURL.index(userCustomRoot));
        category.setIcon("me-icon icon-list");
        menu.add(category);
        return menu;
    }
}