Skip to content

Pipeline

Purpose

The execution pipeline map is used to pass variables between services. The pipeline allows variables to be passed to scripts and services as well as allowing multiple return values. Values are typically Strings however there are specialisations for XML processing and Platform 6 message item keys.

Methods

Binding name: p6.pipeline


get

Get the value of a named pipeline variable as a String.

Syntax

String p6.pipeline.get(String variableName)

Warning

If the content-type of the variable is not suitable for conversion to a String a P6Exception will be thrown.

Example
// Retrieve the invoice XML stored earlier in the pipeline
def invoiceXml = p6.pipeline.get('invoiceXml')
p6.log.debug 'Invoice XML length: ' + invoiceXml.length()

// Read standard platform6 request variables
def dataType = p6.pipeline.get('platform6.request.dataType')
def ids = p6.pipeline.get('platform6.request.ids')
p6.log.debug "Processing request: dataType=${dataType}, ids=${ids}"

getBytes

Get the value of a named pipeline variable as a byte array.

Syntax

byte[] p6.pipeline.getBytes(String variableName)
Example
// Retrieve a PDF attachment stored as binary data
def pdfBytes = p6.pipeline.getBytes('platform6.attachment.data.0')
p6.log.debug 'Attachment size: ' + pdfBytes.length + ' bytes'

getXml

Get the value of a named pipeline variable as a GPathResult (assumed the variable is an Xml String)

Syntax

GPathResult p6.pipeline.getXml(String variableName)
Example
// Parse the invoice XML from the pipeline and extract fields using GPath
def invoice = p6.pipeline.getXml('invoiceXml')
def invoiceNumber = invoice.InvoiceNumber.text()
def amount = invoice.Amount.text()
p6.log.debug "Invoice ${invoiceNumber}: ${amount}"

getXml (advanced)

Extended variant of the above method allowing greater control over the XmlSlurper

Syntax

GPathResult p6.pipeline.getXml(
    String variableName,
    boolean validating,
    boolean namespaceAware,
    boolean allowDocTypeDeclaration,
    boolean loadExternalDtd
)

Info

GPath is a path expression language integrated into Groovy which allows parts of nested structured data to be identified. In this sense, it has similar aims and scope as XPath does for XML. The two main places where you use GPath expressions is when dealing with nested POJOs or when dealing with XML.

Example
// Parse a UBL invoice with namespace awareness enabled
def invoice = p6.pipeline.getXml('ublInvoiceXml', false, true, false, false)
def supplierName = invoice.'cac:AccountingSupplierParty'.'cac:Party'.'cbc:Name'.text()
p6.log.debug 'Supplier: ' + supplierName

getDom

Get the value of a named pipeline variable as a W3C DOM(internal content type is application/p6core.dom)

Syntax

org.w3c.dom.Document p6.pipeline.getDom(String variableName)
Example
// Get the purchase order as a DOM for XSLT processing
def orderDoc = p6.pipeline.getDom('purchaseOrderXml')
def rootElement = orderDoc.getDocumentElement().getTagName()
p6.log.debug 'Root element: ' + rootElement

getPk

Get the named BaseItemPK object (internal content type is application/p6core.itempk)

Syntax

BaseItemPK p6.pipeline.getPk(String variableName)
Example
// Retrieve the transaction primary key from the pipeline
def pk = p6.pipeline.getPk('transactionPK')
def xml = p6.transaction.get(pk)
p6.log.debug 'Retrieved transaction: ' + xml.length() + ' chars'

put

Add or replace the String value of a named pipeline variable. Charset defaults to: text/plain; charset=”utf-8”.

Syntax

TypedContent p6.pipeline.put(String variableName, String value)

Info

Content-type will be default to text/plain and charset to UTF-8

Example
// Store processing status for downstream services
p6.pipeline.put('processingStatus', 'VALIDATED')
p6.pipeline.put('customerId', 'CUST-00712')

put (with contentType)

Add or replace the String value of a named pipeline variable using the given content-type.

Syntax

TypedContent p6.pipeline.put(
    String variableName,
    String value,
    String contentType
)

Info

You can define the charset with the contentType (ie. application/xml;charset=UTF-8)

Example
// Store an XML invoice in the pipeline with the correct content type
def invoiceXml = """<Invoice>
    <InvoiceNumber>INV-2024-0042</InvoiceNumber>
    <Supplier>ACME-CORP</Supplier>
    <Amount currency="EUR">1250.00</Amount>
</Invoice>"""

p6.pipeline.put('invoiceXml', invoiceXml, 'application/xml;charset=UTF-8')

put (byte array)

Add or replace the byte[] value of a named pipeline variable.

Syntax

TypedContent p6.pipeline.put(String variableName, byte[] bytes)

Info

Content-type will be set to application/octet-stream

Warning

Passing large binary content (e.g. files) through the pipeline is expensive. Prefer writing the content to a local file (temporary or not) and passing only the file path via the pipeline instead.

// Write file content to a temp file and pass the path instead
def tempFile = p6.file.createTemp('report-', '.pdf')
p6.file.write reportBytes to tempFile.absolutePath
p6.pipeline.put('reportPath', tempFile.absolutePath)
Example
// Compute a SHA-256 digest of a document and store it as bytes for downstream verification
def docBytes = p6.pipeline.getBytes('platform6.attachment.data.0')
def digest = java.security.MessageDigest.getInstance('SHA-256').digest(docBytes)
p6.pipeline.put('documentDigest', digest)

put (ItemPK)

Add or replace the ItemPK value of a named pipeline variable. Charset defaults to: application/p6core.itempk

Syntax

TypedContent p6.pipeline.put(String variableName, ItemPK itemPk)
Example
// Store a transaction PK in the pipeline for use by a downstream script
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
p6.pipeline.put('invoicePK', pk)

put (with charset)

Add or replace the Object value of a named pipeline variable using the given charset.

Syntax

TypedContent p6.pipeline.put(
    String variableName,
    Object value,
    String charset
)
Example
// Store JSON data with explicit content type
def jsonPayload = '{"orderId": "PO-2024-1587", "status": "approved"}'
p6.pipeline.put('orderResponse', jsonPayload, 'application/json')

put (org.w3c.dom.Document)

Add or replace the W3C DOM value of a named pipeline variable. Charset defaults to: application/p6core.dom

Syntax

TypedContent p6.pipeline.put(
    String variableName,
    org.w3c.dom.Document value
)
Example
// Transform an XML document and store the result back in the pipeline
def sourceDoc = p6.pipeline.getDom('sourceOrderXml')
def transformedDoc = p6.xslt.process('orderToInvoice', sourceDoc)
p6.pipeline.put('generatedInvoiceXml', transformedDoc)

put (CommonMessage)

New Feature

Since 6.10.12

Inject into the pipeline the headers of the CommonMessage object.

Syntax

void p6.pipeline.put (CommonMessage cm)
Example
def cm = p6.service.cm.build.response(true, 'Invoice processed successfully')
p6.service.cm.header.add('invoiceId', 'INV-2024-0042') to cm
p6.file.write 'exported-data' to 'file:///tmp/export.csv'
p6.service.cm.attachment.add 'file:///tmp/export.csv' to cm
p6.pipeline.put cm

This will fill the following pipeline variables:

Name Content-Type Value Type
platform6.response.status text/plain true String
platform6.response.value text/plain Invoice processed successfully String
invoiceId text/plain INV-2024-0042 String
platform6.content.type.0 text/plain text/plain String
platform6.attachment.name.0 text/plain export.csv String
platform6.attachment.data.0 application/octet-stream exported-data byte[]
def cm = p6.service.cm.build.exception('VALIDATION_ERROR', 'Invoice amount exceeds threshold')
p6.service.cm.header.add('invoiceId', 'INV-2024-0042') to cm
p6.pipeline.put cm

This will fill the following pipeline variables:

Name Content-Type Value Type
platform6.response.status text/plain false String
platform6.response.exception text/plain VALIDATION_ERROR String
platform6.response.exception.message text/plain Invoice amount exceeds threshold String
invoiceId text/plain INV-2024-0042 String

putPk

Add the named BaseItemPK object (internal content type is application/p6core.itempk)

Syntax

TypedContent p6.pipeline.putPk(
    String variableName,
    BaseItemPK baseItemPk
)
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
p6.pipeline.putPk('currentInvoicePK', pk)

// Later retrieve it
def retrievedPk = p6.pipeline.getPk('currentInvoicePK')

remove

Remove the value of a named pipeline variable. The value of the removed variable is returned.

Syntax

String p6.pipeline.remove(String variableName)
Example
// Remove temporary processing data before calling the next service
def tempData = p6.pipeline.remove('tempCalculationResult')
p6.log.debug 'Removed temp data: ' + tempData

variables

Returns a collection of all pipeline variable names.

Syntax

String[] p6.pipeline.variables()
Example
// Log all current pipeline variable names for debugging
p6.pipeline.variables().each {
    p6.log.debug 'Pipeline variable: ' + it
}

toStringMap

Returns a Map of all pipeline variables expressed as Strings

Syntax

Map<String, String> p6.pipeline.toStringMap()
Example
// Dump the full pipeline state for troubleshooting
p6.pipeline.toStringMap().each { key, value ->
    p6.log.debug "  ${key} = ${value}"
}

Warning

This method only includes pipeline variables with a content-type of text. This does not include json, xml etc.