Skip to main content

Version: 23.04

Submission Data Validator

The Submission Data Validator is called when a completed form is submitted. This service can be used to verify that the submitted XML is valid and not an attempted fraudulent transaction.

A Submission Data Validator service may perform business rules validation on the server using Groovy script interrogating the submitted XML. If the service finds validation errors, it can return a list of validation errors which are stored against the transaction, and is visible using the Validation Errors tab. If the service returns one or more validation error strings, the transaction's Data Validation status is set to Error.

Data Valiation Error

Transactions with an Error data validation status aren't delivered using the normal delivery channel. If a form Validation Delivery channel is defined then the transaction is delivered using this channel; otherwise. it is marked as Undeliverable and made ready for submission data purging.

Form Data Valiation Delivery

Service Invoke Parameters

Parameters are not nullable except where otherwise indicated.

ParameterDescription
svcDefSvcDef
A service definition value object.
txnTxn
A transaction record value object.
requestHttpServletRequest
Nullable. A HTTP servlet request.
userUser
Nullable. An authenticated user.

Error Handling

If an error occurs, the system catches the error and logs it to the Journey Manager database error log. The user should not be aware that any error has occurred.

info

Any changes made by the service to the database are persisted with the transaction. It is up to the service to undo any changes it has made.

Templates

Service

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.vo.*
import javax.servlet.http.*

class FluentSubmissionDataValidator {

/*
* Perform submission data validator service
*
* return: list of data validation error messages
*/
List<string> invoke(SvcDef svcDef, Txn txn, HttpServletRequest request, User user) {

// TODO: perform validation logic, return any data validation errors in error list
List errors = new ArrayList<string>()

return errors
}
}

Unit Test

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.query.*
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
import com.avoka.tm.util.*
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 testStatusSubmitted() throws Exception {

String xmlData = testParams['Test XML Data']
Txn txn = new MockVoBuilder().createTxnSubmittedWithXml(xmlData)
MockRequest request = new MockRequest()

Map params = [
"svcDef": svcDef,
"txn": txn,
"request": request,
"user": null
]

List errors = (List) new ServiceInvoker(svcDef).invoke(params)

txn = new TxnQuery()
.setId(txn.id)
.withPropertyMap()
.firstValue()

logger.info txn

// Test any business logic performed
assert txn.formStatus == Txn.FORM_SUBMITTED

assert errors.size() == 0
}
}