Skip to main content

Version: 22.04

Transaction History Publisher

The Transaction History Publisher is used to publish transaction history data to the customer's data warehouse. The list of ids returned in the result contains published record's primary keys.

This service is configured via the Form Details tab under the Tracking Code section.

Service Invoke Parameters

Parameters are optional except where otherwise indicated.

ParameterDescription
svcDefSvcDef
Required. A service definition value object.
rowsList<map>
Required. The rows data as a List.

Script Result

The script returns a list of numbers which are published.

Error Handling

If an error occurs invoking your Transaction History Publisher script, the error is logged in the Journey Manager database error log, and the user is redirected to the error page on the form space. The transaction is rolled back, and no transaction record is created.

Service Template

This section shows service template Groovy script.

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.vo.*
import com.jcraft.jsch.*

class FluentTransactionHistoryPublisher {

/*
* Perform a transaction history publishing
*
* return: list of the published transactions' primary keys.
*/
List<number> invoke(SvcDef svcDef, List<map> rows) {

/* // JCraft SFTP Upload Example
ChannelSftp channelSftp
Session session
try {
String username = svcDef.svcConn.username
String password = svcDef.svcConn.password
String endpoint = svcDef.svcConn.endpoint

JSch jsch = new JSch()
session = jsch.getSession(username, endpoint, 22)
session.setPassword(password)

Properties config = new Properties()
config.put("StrictHostKeyChecking", "no")
session.setConfig(config)
session.connect()
Channel channel = session.openChannel("sftp")
channel.connect()
channelSftp = (ChannelSftp) channel

// TODO: write the rows in local 'myfile.data' file and then upload
channelSftp.put('/local/storage/myfile.data', '/remote/myfile.data')

} finally {
channelSftp?.disconnect()
session?.disconnect()
}
*/

//Fill and return rows' ids
final List<number> result = new ArrayList<>()
for (Map<string object> row: rows) {
result.add(Long.parseLong(row.get('transaction_history_oid').toString()))
}
return result
}
}

Templates

Unit Test

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.vo.*
import org.junit.Test

class UnitTest extends AbstractJUnitTest {

/*
* Perform service unit test
*
* throws exception if unit test fails
*/
@Test
void testTxnHistoryPublisher() throws Exception {

//TODO fill some rows data
List<map>> rows = new ArrayList<>()

Map params = [
"svcDef": svcDef,
"rows": rows
]

List<number> ids = (List<number>) new ServiceInvoker(svcDef).invoke(params)

logger.info "Published ids.size: " + ids.size()

// Test any business logic performed
assert ids != null
}
}