Skip to content

Martini Tracker Functions

The Tracker class in Martini is essential for managing and manipulating Tracker-related data. This class provides a comprehensive suite of functions for various operations, tailored for use in both Groovy and other relevant programming environments. These functionalities include:

  • Fetching Tracker-related beans: Essential for initializing and managing Tracker instances.
  • Document Operations:
  • Adding new Tracker documents.
  • Retrieving existing Tracker documents.
  • Deleting unwanted Tracker documents.
  • Document Type Management:
  • Adding new document types to the Tracker.
  • Retrieving existing document types.
  • Document State Operations:
  • Adding states to Tracker documents.
  • Retrieving existing document states.
  • Logging and Properties:
  • Adding logs to Tracker documents.
  • Managing document-specific properties.
  • Search Index Queries: Executing sophisticated queries against the Tracker's search index to retrieve relevant documents and data.

Usage Examples

The following examples illustrate common operations performed using the Tracker class in a Groovy environment.

Adding a Document State

This example demonstrates adding a new state to a Tracker document. This is useful for lifecycle management of documents.

1
2
3
4
5
// Identifier for the document
def internalId = 'your-document-id'

// Add a new document state without a state type
internalId.addDocumentState('Started')

addDocumentState accepts the following parameters, in order: internalId, stateName, stateType, filename, content, and index. Only internalId and stateName are required; stateType is optional and nullable, and content accepts either a String or a byte[] depending on which overload is invoked. Use one of INFO, SUCCESS, WARNING, or ERROR to classify the state so it can be filtered on later:

1
2
3
4
5
6
// String content, classified as a SUCCESS state
internalId.addDocumentState('Processed', 'SUCCESS', 'result.txt', 'Order processed successfully', true)

// byte[] content, classified as an ERROR state
byte[] payload = errorReport.getBytes('UTF-8')
internalId.addDocumentState('Failed', 'ERROR', 'error-report.xml', payload, true)

Omitting stateType (as in the first example) leaves the state unclassified, and existing calls that omit stateType remain valid.

Adding a Document

addDocument creates a Tracker document together with its initial state in a single call, and also accepts an optional stateType for that initial state. Parameters are, in order: internalId, externalId, documentTypeId, stateName, stateType, senderId (defaults to Anonymous), receiverId (defaults to Anonymous), filename, async (defaults to true), content, and properties. As with addDocumentState, content may be supplied as either a String or a byte[], and stateType must be one of INFO, SUCCESS, WARNING, or ERROR when provided:

1
2
3
4
5
6
7
8
9
// String content, initial state classified as INFO
'order-123'.addDocument('order-123-ext', 'Order Processing', 'Received', 'INFO', 'order-service',
                         'fulfillment-service', 'order.json', true, '{ "orderId": "order-123" }',
                         [ 'region': 'us-east' ])

// byte[] content, initial state classified as INFO
byte[] payload = orderJson.getBytes('UTF-8')
'order-124'.addDocument('order-124-ext', 'Order Processing', 'Received', 'INFO', 'order-service',
                         'fulfillment-service', 'order.json', true, payload, [ 'region': 'us-east' ])

The document's stateType field always reflects the type of the most recently added state—whether added through addDocument, addDocumentState, or any other state-adding function—so filtering on the document's stateType returns documents based on their latest known state. For the full list of document and state fields, including stateType's null/default behaviour and which system-generated states are classified automatically, see Martini Services Tracker Document Structure.

Performing a Search in Tracker

Executing a search in the Tracker is straightforward. This example performs a basic search using a wildcard query.

1
2
3
4
5
// Search query using a wildcard
def query = '*:*'

// Perform the search
query.searchTracker()

TrackerMethods.searchTracker does not currently expose a stateType parameter in either overload. For filtering by stateType, see the Tracker Search API.

The Tracker class's functions are designed to be intuitive and easy to integrate into your existing Martini workflows, ensuring a seamless experience in managing Tracker-related operations.