If you have a comment on this topic, contact Aptify Documentation. If you want to return to the Aptify Community Site, please click here.

Business Logic Metadata

The business logic for an endpoint describes the work that will be done when the endpoint executes.  Business logic is defined as a chain of Aptify process flows.  The framework will execute every process flow in the chain.  The only way to abort processing is for your process flow to throw an exception.  You should throw strongly typed exceptions so they can be interpreted by the error handling framework and produce meaningful output to your callers.  

The business logic property value is an object.  The object is made of one to many properties whose values are objects with the following properties.  

Business Logic Definition properties

Property NameValue

Description

executionTypestring

The value is always '"processFlow".

processFlowPropertiesobjectProcess flow properties object that describes what process flow to execute (detailed below).

Process Flow Properties object properties

Property NameValueDescription
processFlowNamestringThe name of the process flow in Aptify to execute.
processFlowParametersobjectAn object of key-value pairs. The keys are the input properties defined on the process flows. The values can either be literals, values pulled from the output of other business logic that's executed in this request, or values pulled from input context objects.

Examples

The following example assumes we have a process flow named 'Example Get Product Catalog' that has a single input parameter 'ProductId'.  The metadata for executing this process flow would look like this:

{
  "endpoints": {
    "ExamplesGetSingleProduct": {
      "businessLogic": {
        "allProductsRetrieval": {
          "executionType": "processFlow",
          "processFlowProperties": {
            "processFlowName": "Example Get Product Catalog",
            "processFlowParameters": {
              "ProductId": "@Request.ProductId"
            }
          }
        }
      }
      //remaining metadata omitted
    }
  }
}

Passing Parameters

In the example above you'll notice we're passing the value for ProductId with a special kind of syntax:  @Request.ProductId.  This is an example of referencing an input context object.  The input context object is named 'Request' and the property we're asking for is 'ProductId'.  The framework automatically defines a set of input context objects for you.  You can also create your own if needed.  

Passing Output From Other Business Logic Blocks

In addition to this, you can also reference output from other process flows as input to additional process flows. The syntax for this is:  @parent.{businessLogicName}.{outputProperty}.  For example:

Example with multiple process flows
"businessLogic": {
  "ensureActiveCart": {
    "executionType": "processFlow",
    "processFlowProperties": {
      "processFlowName": "Ensure Active Cart Exists",
      "processFlowParameters": {
        "currentUserIdentifierType": "@ShoppingCartUserIdentifier.identifierType",
        "currentUserIdentifierValue": "@ShoppingCartUserIdentifier.identifierValue",
        "serviceApplicationName": "@AuthenticatedAttributes.ServiceApplicationName"
      }
    }
  },
  "addProduct": {
    "executionType": "processFlow",
    "processFlowProperties": {
      "processFlowName": "Add Product",
      "processFlowParameters": {
        "productId": "@request.productId",
        "quantity": "@request.quantity",
        "orderGe": "@parent.ensureActiveCart.outputCurrentOrderGE"
      }
    }
  }
}

The above business logic block executes two stock e-Business process flows.  The first one retrieves the cart for the current user and uses two input context objects.  The second one adds a product to the cart.  It needs an order GE as input.  The 'ensureActiveCart' process flow returns an order GE as an output property named 'outputCurrentOrderGE'.  We reference that order GE with the property value '@parent.ensureActiveCart.outputCurrentOrderGE'.

Renaming Output

When discussing output entity definitions we said that the framework will only map the last piece of output from the last piece of business logic that executed.  Sometimes the last process flow to execute doesn't return the data you want to return from the endpoint.  The output may exist in another piece of business logic that executed earlier.  A special process flow 'Map Context Property' exists for this situation.  It takes a piece of input and returns it as output.  This allows you to take a piece of output from earlier in the business logic chain and return it as the last piece of output.  You will see examples of this throughout the stock metadata.  

 

 

Copyright © 2014-2019 Aptify - Confidential and Proprietary