7 Creating Commit Processor Scripts

This chapter describes creating Commit Processor scripts. The Commit Processor scripting allows customization of commit processor jobs using user-defined JavaScript.

This chapter covers the following topics:

7.1 CommitEventObject Class

The CommitEventObject class contains the properties relevant to the batches or documents being processed. An instance of this class is created before the processing begins and is passed to commit drivers at various stages throughout the processing.

The following table lists the CommitEventObject fields:

Property Type Description
cancel java.lang.Boolean If set to True, the processing operation is canceled.
logger Logger An instance of java.util.logging.Logger that can be used to log data to log files.
workingDirectory java.io.File The current working directory from where the commit driver processes documents.
batch BatchEntity Contains the batch information.
document DocumentEntity The current active document which is being processed.
attachmentFileNames DocumentEntity The current active attachments which is being processed.
exportDriverInformation ExportDriverInformation The export driver information for the attachments.
dateCommitted java.util.Date The date on which the document has been committed.
commitProfile CommitProfileEntity The current commit profile used by the Commit Processor.
documentFileName java.lang.String The file name of the document.

7.2 Commit Processor Events

Commit Processor scripts are JavaScript modules that enable you to customize the behavior of certain Commit Processor events.

This section describes the following Commit Processor events:

7.2.1 preCommit

The preCommit event occurs prior to a document being committed to a repository. The user-defined method can use this functionality to take action for the commit profile being processed by the commit driver. Setting the cancel attribute to true allows all the documents to skip this commit profile and move onto next active commit profile.

Syntax Parameter
public preCommit (CommitEventObject commitEventObject) CommitEventObject

Associated CommitEventObject Properties

7.2.2 preReleaseDocument

The preReleaseDocument event occurs prior to a document being released. It allows the user-defined script to take action for the document being released. The cancel property also allows to cancel further processing of the document by canceling and moving onto the next document.

Syntax Parameter
public preReleaseDocument (CommitEventObject commitEventObject) CommitEventObject

Associated CommitEventObject Properties

7.2.3 postReleaseDocument

The postReleaseDocument event occurs after each document has been released or committed to the repository. It will allow the user-defined script to take action for the document after release. Setting the cancel property to true at this point will not have any effect. This method might not be triggered if there is some problem while committing the document. The Commit Profile “Error Handling Policy” will override the behavior.

For example: Cancel to next commit profile defined in Commit Profile’s “Error Handling Policy” will skip to the next active commit profile in case of an error and then this method will not be called.

Syntax Parameter
public postReleaseDocument (CommitEventObject commitEventObject) CommitEventObject

Associated CommitEventObject Properties

7.2.4 postCommit

The postCommit event occurs after a batch has been processed for a given commit profile. It will allow the user-defined script to later on take some cleanup or logging action. This method execution does not mean that the documents have been committed successfully to the repository. Setting the cancel property to true at this point will not have an effect.

Syntax Parameter
public postCommit (CommitEventObject commitEventObject) CommitEventObject

Associated CommitEventObject Properties

7.3 Sample Commit Processor Scripts

The section contains the following sample Commit Processor scripts:

7.3.1 Sample Commit Processor Script 1

The following script prints all events when a batch goes through commit:

//commit processor javascript to print at the specific events
function preCommit(event){
     java.lang.System.out.println("In preCommit");
     java.lang.System.out.println("Batch name preCommit: "+event.getBatch().getBatchName());	
}
function preReleaseDocument(event){
     java.lang.System.out.println("In preReleaseDocument");
     java.lang.System.out.println("Batch name preReleaseDocument: "+event.getBatch().getBatchName());
}
function postReleaseDocument(event){
     java.lang.System.out.println("In postReleaseDocument");
     java.lang.System.out.println("Batch name postReleaseDocument: "+event.getBatch().getBatchName());
}
function postCommit(event){
     java.lang.System.out.println("In postCommit");
     java.lang.System.out.println("Batch name postCommit: "+event.getBatch().getBatchName());
}

7.3.2 Sample Commit Processor Script 2

The following script cancels operation at the preCommit event:

function preProcessBatch(event){
     event.setCancel(true);
     java.lang.System.out.println("preCommit about to cancel operation commit profile operation.");
     java.lang.System.out.println("preCommit: Batch name "+event.getBatch().getBatchName());
}
function preReleaseDocument(event){
     java.lang.System.out.println("postProcessBatch - this method will not be called.");
     java.lang.System.out.println("postProcessBatch: Batch name "+event.getBatch().getBatchName());
}

7.3.3 Sample Commit Processor Script 3

The following script cancels the document commit at the preReleaseDocument event:

function preReleaseDocument(event){
     event.setCancel(true);
     java.lang.System.out.println("preReleaseDocument batch-"+event.getBatch().getBatchName());
}