Thursday, July 12, 2018

Advance Scripts for Oracle WebCenter Capture

More documentation can be found here: https://docs.oracle.com/cd/E29542_01/doc.1111/e28275/c01_intro.htm

Script to generate the logs:

----------------------------------------------------------------------------------------------
load("nashorn:mozilla_compat.js");

function logRPCEvent (rpc, funcName) {
var logger = rpc.getLogger();
logger.info("PrintRecogProcEvents.js entered function: " + funcName);
}

function initialize(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "initialize");
}

function processBatch(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "processBatch");
}

function restoreCaptureBatch(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "restoreCaptureBatch");
}

function beginPhase(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "beginPhase");
}

function endPhase(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "endPhase");
}

function extractBatchItem(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "extractBatchItem");
}

function barcodesFoundOnItem(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "barcodesFoundOnItem");
}

function batchItemAllValidBarcodes(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "batchItemAllValidBarcodes");
}

function determineSeparatorPage(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "determineSeparatorPage");
}

function batchItemValidBarcode(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "batchItemValidBarcode");
}

function determineDocType(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "determineDocType");
}

function beginDatabaseLookup(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "beginDatabaseLookup");
}

function determineIndexValues(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "determineIndexValues");
}

function renameOrigCaptureDocTitle(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "renameOrigCaptureDocTitle");
}

function createCaptureDoc(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "createCaptureDoc");
}

function postProcess(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "postProcess");
}

function endBatchProcess(rpc) { // RecognitionProcessorContext
logRPCEvent(rpc, "endBatchProcess");
}
----------------------------------------------------------------------------------------------

Script to Update the Date format 

----------------------------------------------------------------------------------------------
load("nashorn:mozilla_compat.js");
importClass(java.text.SimpleDateFormat);
importClass(java.util.Date);

function logRPCEvent(rpc, logText) {
    var logger = rpc.getLogger();
    logger.info("[WWW] - " + logText);
}

function determineIndexValues(rpc) { // RecognitionProcessorContext
    logRPCEvent(rpc, "determineIndexValues");
    convertDateFormat(rpc);
}



function convertDateFormat(rpc) {
    logRPCEvent(rpc, "convertDateFormat");
    var DOCUMENT_DATE_FIELD = "Document Date";

    var documentDate = getIndexID(rpc, DOCUMENT_DATE_FIELD);
    logRPCEvent(rpc, "Get Index Field Id: " + documentDate);

    var capturedDocument = rpc.getBle().getBatch().getDocuments().get(0);
    logRPCEvent(rpc, "Captured Document : " + capturedDocument);

    var indexValues = rpc.getDocument().getIndexValues();
    for (var i = 0; i < indexValues.size(); i++) {
        var iv = indexValues.get(i);
        if (iv.getFieldID().equals(documentDate)) {
            logRPCEvent(rpc, "FieldID: [" + iv.getFieldID() + "] FieldValue: [" + iv.getFieldValue() + "]");
            var documentDateCapturedValue = iv.getFieldValue();
            iv.setFieldValue(formatRequiredDate(documentDateCapturedValue));
        }
    }
}

// @Format the date to yyyy-MM-dd'T'HH:mm:ss'Z'
function formatRequiredDate(currentDate) {

    var REQUIRED_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    var LOOKUP_DATE_PATTERN = "MM-dd-yyyy";
    var currentDateFormat = new SimpleDateFormat(LOOKUP_DATE_PATTERN);
    var inputDate = currentDateFormat.parse(currentDate);
    currentDateFormat.applyPattern(REQUIRED_PATTERN);

    return currentDateFormat.format(inputDate);
}

// @Return the field object from document
function getFieldDefination(document, field) {
    return document.getParentBatch().getWorkspace().getFieldDefinitions().findByName(field);
}

// @Get the index Id
function getIndexID(rpc, indexName) {
    var workspace = rpc.getWorkspaceEntity();
    var indexDef = findIndexDefinitionByName(workspace, indexName, rpc);

    if (indexDef != null) {
        var indexID = indexDef.getIndexFieldID();
    }
    logRPCEvent(rpc, " In getIndexID : indexID [" + indexID + "]");
    return indexID;
}

// @Get the index definition by name
function findIndexDefinitionByName(workspace, indexName, rpc) {
    logRPCEvent(rpc, " In findIndexDefinitionByName : Workspace [" + workspace + "], Index Name: [" + indexName + "]");
    var indexDefs = workspace.getIndexDefinitions();
    var size = indexDefs.size();
    var foundIndexDef = null;
    for (var i = 0; i < size; i++) {
        var indexDef = indexDefs.get(i);
        if (indexName.equals(indexDef.getFieldName())) {
            foundIndexDef = indexDef;
            break;
        }
    }
    logRPCEvent(rpc, " In findIndexDefinitionByName : foundIndexDef [" + foundIndexDef + "]");
    return foundIndexDef;
}
----------------------------------------------------------------------------------------------

Steps to configure in Capture:


  1. Copy the following code to a text file.
  2. Open the WebCenter Workspace Console.
  3. Select the desired Workspace.
  4. Select the "Advanced" train stop / tab.
  5. Click the "Add New Script" button.
  6. Select type "Recognition Processor" and name the script appropriately. For example, LogsRecProcEvents.
  7. Select the file created above and click submit.
  8. Select the "Processing" tab.
  9. Select the desired Recognition Processor job and click the Edit (pencil) icon.
  10. Go to the "Extensions" train stop / tab.
  11. Click the "Script" pulldown menu.
  12. Select the script created in the Advanced Tab, (e.g. LogsRecProcEvents).
  13. Click "Submit" to apply the script.



No comments:

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...