Browse a Repository
The identifiers
fetch action provides information that can be used to browse a repository. It retrieves a list of documents that are present in the repository and generates an identifier for each document.
Action | Description | Method to override |
---|---|---|
/action=fetch&fetchaction=Identifiers
|
Retrieve a list of documents that are present in the repository. | identifiers
|
Prerequisites
To implement this feature, the file Autonomy_JNI.dll
(libAutonomy_JNI.so
on non-Windows platforms) is required. This is provided in the SDK. If you implement this feature but this library is not present, a message is logged in the connector's application log, and the feature is disabled.
Declare the Types of Identifiers
Before implementing the action, you must specify the types of identifier that the connector can return. For example, a connector that retrieves information from a file system might return identifiers that represent folders and identifiers that represent files.
Declare each IdentifierType
as public static final
in the main connector class:
public class FileSystemConnector extends ConnectorBase { public static final IdentifierType IdFolder = new IdentifierType("Folder", IdAttr.Container); public static final IdentifierType IdFile = new IdentifierType("File", IdAttr.Document); ... }
These fields are automatically found by the default implementation of the identifierTypes()
function on the ConnectorBase
class:
public IdentifierTypes identifierTypes();
The default implementation means there is no need for you to implement this function.
You can verify the identifier types you have declared by running /action=GetStatus
, which returns the list of IdentifierTypes
and attributes.
Implement the Identifiers Action
To implement the identifiers
action, override the identifiers
method.
When you implement the action, you can choose whether your users must set the parameter ParentIdentifiers
in the identifiers
action request.
The parameter ParentIdentifiers
accepts a comma-separated list of identifiers. The action should return identifiers for items that exist below the parent identifiers in the repository. For example, the user might specify an identifier for a folder and would expect the action to return identifiers for folders and files contained within that folder. Alternatively, the user might specify the root of the repository by including the special identifier ROOT
. The following sample code demonstrates how to implement the identifiers
action and handle these cases.
public void identifiers( IdentifiersTask task ) throws Throwable { // Check whether we are expanding provided Parent identifiers. // If no Parent Identifiers are provided (when task.usingParentIdentifiers() == false), // you might choose to return Identifiers using some other criteria. if ( task.usingParentIdentifiers() ) { // The special Identifier "ROOT" is used to request the top level // Identifiers in the repository. The task.parentIdentifierIsRoot() // returns true if this special Identifier is present // in the request. if ( task.parentIdentifierIsRoot() ) { // Add root Identifiers. // The parameters are the Identifier, and a name for display purposes. // The task.makeId() function returns an IdentifierBuilder that can be // used to build up the Identifier. task.addIdentifier( task.makeId().reference("/Root").type(IdFolder).get(), "RootReference" ); } // Loop over all parent Identifiers (excluding ROOT) for ( ParentIdentifier parentIdentifier : task.parents() ) { try { // Retrieve the children (may throw). Add child Identifiers. // This call is the same structure as the root Identifier call except // for the additional first argument being the parent Identifier. task.addIdentifier( parentIdentifier, task.makeId().reference("/Root/Child").type(IdFile).get(), "ChildReference" ); } catch ( Exception e ) { // If an error occurs while retrieving the children, this error can be // reported as associated with the parent Identifier. // You can report general errors throughout the task by omitting // the parentIdentifier parameter. task.addError(parentIdentifier, e.getMessage()); } } } }