1
0
-1

In the fluent API, I see that we can call TxnUpdater.setProperty to add set a single property after a Txn object has been created but why isn't there a way to call TxnBuilder.setProperty or TxnBuilder.setPropertyMap to set propertie(s) at the initial creation of the Txn object?

Thanks,

Blake

  1. Ben Warner

    Not sure what you mean or how you came to that conclusion. Can you elaborate on your use case?

  2. Blake Hunter

    My use case it to create a Txn object using the TxnBuilder with a property of "ApplicationID" and a value of "1234". How can I do that?

  3. Blake Hunter

    These properties would be part of the txn.propertyMap

  4. Ben Warner

    Are you doing this in a unit test script or as a genuine solution requirement? Can you describe the business use case. What behavior are you seeing when you try this?

  5. Blake Hunter

    This is being done in a unit test script so that I can can pre-populated the txn with the expected properties before passing the txn to my service for testing. There is no business use case for now other than the ability to facilitate my tests.

  6. Ben Warner

    Thanks for the context, can you paste your code.

  7. Blake Hunter

    Here is my code from the unit test. The service code being tested is a bit large to past in this format:

    class BanamexProcessApplicationTest {
    /*
         * Perform service unit test
         *
         * throws: exception if unit test fails
         */
        void invoke(SvcDef svcDef, Map testParams) throws Exception {
    
            MockRequest request = new MockRequest()
    
            logger.info("svcDef: " + svcDef)
    
            // We are using the existing form and form code "mx-cc-mm"
            Txn txn = new TxnBuilder()
                    .setAddress("1 Street")
                    .setContactEmailAddress("contact@email.com")
                    .setDatetimeScheduled(new Date())
                    .setDatetimeExpiry(new Date())
                    .setEmailSubject("Email subject")
                    .setEmailMessage("Email message")
                    .setFormCode("mx-cc-mm")
                    .setGroupName("Administrator")
                    .setLatitude(new Double(40))
                    .setLongitude(new Double(50))
                    .setReceiptNumber("RCPT-1234")
                    .setSaveChallengeAnswer("saveChallengeAnswer")
                    .setSequence(new Integer(2))
                    .setSpaceName("Account Open - Forms")
                    .setTxnXml("<Txn></Txn>")
                    .setTaskMessage("taskMessage")
                    .setTaskSubject("taskSubject")
                    .setTransRefNumber("TRANS-1234")
                    .withFormDataMap()
                    .withGroupNames()
                    .build()
    
            logger.info("txn.trackingCode: " + txn.trackingCode)
    
            new TxnUpdater(txn)
                    .setProperty("applicationID", "1234")
                    .update()
    
            logger.info("transaction: " + txn)
            logger.info("transaction.trackingCode: " + txn.trackingCode)
            logger.info("transaction.propertyMap before: " + txn.propertyMap)
    
            Txn transaction2 = new TxnQuery()
                    .withAll()
                    .setTrackingCode(txn.trackingCode)
                    .firstValue()
    
            logger.info("transaction2.propertyMap after: " + transaction2.propertyMap)
    
    
            Map params = [
                    "svcDef": svcDef,
                    "txn": txn,
                    "request": request,
                    "user": null
            ]
    
            String result = (String) new ServiceInvoker(svcDef).invoke(params)
    
            logger.info result
    
            Path path = new Path(result)
    
            assert "123 Wall Street" == "123 Wall Street"
        }
    }
  8. Blake Hunter

    Note, that I cannot initially create the Txn object with the "applicationID" property. I have to updated it and then query again to get the updated Txn object.

  9. Ben Warner

    So just to confirm your code actually works, nothing is broken. You're just asking for a more convenient way to write it?

  10. Blake Hunter

    Correct, I could use the TxnUpdater and then TxnQuery but it would make more sense (and is easier) to initalize the Txn's Property Map during the construction of the Txn value object using the TxnBuilder especially since Txn is a value object and is immutable.

CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    This is really a feature request. Feature requests put through the Q&A Forum will not get picked up by the product team. On the Avoka Community Home Page you find a section on Contributing Ideas to improve the product. 

      CommentAdd your comment...