Implement Custom Fetch Actions
You can implement custom fetch actions in a ConnectorLib Java connector.
| Action | Description | Method to override |
|---|---|---|
action=Fetch&FetchAction=MyAction
|
Perform custom fetch actions on a repository. |
|
To implement a custom fetch action, override the customFetch method on the ConnectorBase interface.
The method is passed the name of the fetch action that was called in the request. The name is always in upper case, because action names are case-insensitive. You can use the customFetch method to handle as many fetch action names as necessary, however the action names customFetchSYNCHRONIZE, COLLECT, HOLD, and so on, are reserved by the connector for the standard fetch actions.
The customFetch method is also passed a CustomFetchTask object. The CustomFetchTask object provides access to a request object which provides all of the action parameters. You can obtain the request object by calling the method getRequest() on the CustomFetchTask object. To retrieve a single parameter call the method getParameter(parameterName) on the request object, or to retrieve a list of all parameters use the method getParameters(). These methods return parameter objects. To obtain the name and value of a parameter, call the methods getName() and getValue() on the parameter object. You can also use the method getValue(defaultValue) to read a parameter value and use a default value if the parameter is not set.
Other resources, including a collection of identifiers and an ingester, are available through the CustomFetchTask object. You can use these in your implementation of the custom fetch action.
The method can run many times for a single request; each time it is passed a different customFetchCustomFetchTask instance. The number of times that the method runs is determined as follows:customFetch
- The
method runs for each distinct configuration file section name embedded in the identifiers (provided by thecustomFetchidentifiersoridentifiersXMLaction parameters) or included in the request (using theconfigsectionortasksectionsparameters). Theconfigsectionparameter accepts a single name. Thetasksectionsparameter accepts a comma-separated list of names. - If no configuration file sections are provided by identifiers or by the
configsectionortasksectionsparameters, then thecustomFetchmethod runs one time for each task listed in the[FetchTasks]section of the configuration file. -
If no fetch tasks are configured in the connector's configuration file, the
customFetchmethod does not run and the following warning is written to the connector's logs:WARNING: Custom fetch action is not associated with any task configuration sections, no tasks will be executed
Your code must use the parameters from the request to perform the action and populate the action response. getResponse() on the CustomFetchTask object. Set the value of XML elements in the response by calling the method setValue(elementName, value) on the response object.
You can add attributes and nested elements to the action response using XPath-like expressions with element indexes. For example:
Response.setValue("document[0]/metadata[7]/@name", "MyField");
Your implementation of the method should return customFetchfalse only if the fetch action name is not supported. In all other cases, return true. If another failure occurs then throw an exception from the method, giving the reason for the failure.customFetch
The following sample code shows how a custom fetch action might be implemented for a basic connector.
This example provides action=fetch&FetchAction=count, and counts the files below a list of paths:
boolean customFetch(String action, CustomFetchTask task)
{
if (action.equalsIgnoreCase("COUNT"))
{
String[] paths = task.getTaskConfig().readStringArray("DirectoryPathCSVs");
int count = 0;
for (String path : paths)
{
// Count files below path
}
task.getResponse().setValue("file_count", count.toString());
return true;
}
return false;
}