Create the current account credit message subflow

Use the following instructions to create the current account credit message subflow.

  1. Create a new message flow:
    1. Right-click the existing SCANodesSample Message Broker project, click New > Message Flow.
    2. Set Message Flow Name to CurrentAccountCredit, click Finish.
  2. In the Message Flow editor add and rename the nodes listed in the following table.

    Node type Node name
    Input Input
    JavaCompute RetrieveCurrentAccountBalance
    JavaCompute CreditCurrentAccountBalance
    JavaCompute UpdateCurrentAccountBalance
    Output Output

  3. Connect the nodes as described in the following table.

    Node name Terminal Connect to this node
    Input Out RetrieveCurrentAccountBalance
    RetrieveCurrentAccountBalance Out CreditCurrentAccountBalance
    CreditCurrentAccountBalance Out UpdateCurrentAccountBalance
    UpdateCurrentAccountBalance Out Output
  4. Customize the RetrieveCurrentAccountBalance node:
    1. Right-click the RetrieveCurrentAccountBalance node, click Properties.
    2. Click Basic, select Browse to find the Java class field.
    3. In the text field, type CurrentAccount.
    4. Select CurrentAccount_RetrieveCurrentAccountBalance, click OK.
  5. Customize the CreditCurrentAccountBalance node:
    1. Double-click the CreditCurrentAccountBalance node, ensure that Project name is SCANodesSampleJava, click Next.
    2. Ensure that the Source folders on build path and Default output folder contain SCANodesSampleJava, click Next.
    3. Set Package to sca.broker.sample.currentaccount, click Next.
    4. Select the Creating message class template, click Finish.
    5. Right-click the CreditCurrentAccountBalance node, click Open Java.
    6. Add the following import statement:
      import java.math.BigDecimal;
      		
    7. Add the following Java code:
      //Go to tree roots
      MbElement inRoot = inMessage.getRootElement();			
      MbElement outRoot = outMessage.getRootElement();			
      MbMessage locEnv = inAssembly.getLocalEnvironment();
      MbMessage newLocEnv = new MbMessage();
      //Get the operation name
      MbElement sca = locEnv.getRootElement().getFirstElementByPath("SCA");
      MbElement input = sca.getFirstElementByPath("Input");
      MbElement operation = input.getFirstElementByPath("Operation");
      String operationName = operation.getValue().toString();
      //Get the old balance
      MbElement variables = locEnv.getRootElement()
      .getFirstElementByPath("Variables");
      float oldBalance = 
      Float.parseFloat(variables.getFirstElementByPath("oldBalance")
      .getValue().toString());
      //Get the amount to transfer			
      MbElement soap = inRoot.getFirstElementByPath("SOAP");
      MbElement body = soap.getFirstElementByPath("Body");
      MbElement action = body.getLastChild();
      MbElement request = action.getLastChild();
      MbElement amount = request.getFirstElementByPath("amount");
      float transferValue = Float.parseFloat(amount.getValue().toString());
      //Calculate the new balance total
      float newBalance = oldBalance + transferValue;
      MbElement newVariables = 
      newLocEnv.getRootElement().createElementAsLastChild(MbElement.TYPE_NAME, 
      "Variables", null);
      //Accept the transfer and set new balance in LE            
      newVariables.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "newBalance", 
      new BigDecimal(newBalance).setScale
      (2, java.math.BigDecimal.ROUND_HALF_UP)
      .toString());
      //Setup the message reply
      MbElement newXMLNSC = outRoot.createElementAsLastChild
      (MbXMLNSC.PARSER_NAME);
      MbElement newOperation = newXMLNSC.createElementAsLastChild
      (MbElement.TYPE_NAME, 
      operationName + "Response", null);
      newOperation.setNamespace("http://CurrentAccount/");
      MbElement newResponse = newOperation.createElementAsLastChild
      (MbElement.TYPE_NAME, 
      "CurrentAccountResponse", null);           
      newResponse.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, 
      "accept", "yes");				
      // Create the new assembly with the new property overrides
      MbMessageAssembly outAssembly = new MbMessageAssembly(
      					inAssembly,
      					newLocEnv,
      					inAssembly.getExceptionList(),
      					outMessage);
              
    8. Remove the following Java code because it conflicts with MbMessageAssembly that you have just created:
      MbMessageAssembly outAssembly = new MbMessageAssembly
      (inAssembly, outMessage);
         		
  6. Customize the UpdateCurrentAccountBalance node:
    1. Right-click the UpdateCurrentAccountBalance node, click Properties.
    2. Click Basic, select Browse to find the Java class field.
    3. In the text field, type CurrentAccount.
    4. Select CurrentAccount_UpdateCurrentAccountBalance, click OK.

You can now create the current account message flow, see Create the current account message flow.

Back to Extend the sample

Back to sample home