Curator - Groovy action

This feature is not available to users of the Squiz Experience Cloud version of Funnelback.

The GroovyAction curator action performs an action defined by a section of administrator-defined Groovy code. This code must be in the form of a class which implements Funnelback’s com.funnelback.publicui.curator.action.GroovyActionInterface interface.

Parameters

classFile

The full path to the Groovy class file which defines the action.

properties

A map of key-value entries allowing additional configuration information to be provided to the Groovy class.

Example configuration

The actions section of a curator rule in the $SEARCH_HOME/conf/<collection>/<profile>/curator.json configuration file may be updated to have:

"actions" : [ {
    "type" : "GroovyAction",
    "classFile" : "/some_secure_path/TestAction.groovy",
    "properties" : {
      "key1" : "value1",
      "key2" : "value2"
    }
  } ]

Example class implementation

The following example is an implementation of a trigger called 'TestAction' which adds a message containing the current server date to the date model such that it can be presented on the search result page.

Note that the class implements the com.funnelback.publicui.curator.action.GroovyActionInterface which requires the implementation of the runsInPhase and performAction methods.

The runsInPhase method determines when the actions should be executed. Some actions occur before the search results are generated because they modify the request in some way before it is processed, while other actions operate after the results are generated because they modify them before display in some way. The two phases in which an action can run are INPUT and OUTPUT, bout of which are defined in the com.funnelback.publicui.search.model.curator.config.Action.Phase enum class. The runsInPhase method is provided with the proposed phase and any properties defined in the configuration file, and is expected to return true or false based on whether it wishes to be called in that phase.

The performAction method performs the actual action, and accepts two parameters, one being a representation of the search transaction being performed (allowing the user’s query or similar to be determined or modified on the INPUT phase or the results to be manipulated on the OUTPUT phase) and the other being the parameters passed from the configuration file as described above.

import java.util.Map;
import com.funnelback.publicui.search.model.curator.config.Action.Phase;
import com.funnelback.publicui.search.model.curator.data.Message;
import com.funnelback.publicui.search.model.transaction.SearchTransaction;
import com.funnelback.publicui.curator.action.GroovyActionInterface;

public class ActionTest implements GroovyActionInterface {

    @Override
    public boolean runsInPhase(Phase phase, Map<String, Object> properties) {
        return phase.equals(Phase.OUTPUT);
    }

    @Override
    public void performAction(SearchTransaction searchTransaction, Phase phase, Map<String, Object> properties) {
        searchTransaction.getResponse().getCurator().getExhibits().add(
            new Message("The current server time is " + (new Date()), properties, "no-category"));
    }
}

See also

© 2015- Squiz Pty Ltd