In this section we're going to bring some of the most important concepts you've learned until now together to create a novel Order Management System in which various organizations are able to collaborate on a shared ordering process in real-time.
Idea in brief: create an Order Management System in which buyers can place a cancellable order for a quantity of a book against a given supplier. Suppliers have the option of fulfilling or canceling orders at their discretion. Each organization should only have visibility into orders in which they are either the buying or selling party. Changes to the state of an order propagate in real-time.
To get started, create a
BookOrdermodel with the following attributes (refer back to Chapter 2's section on “Creating a Model” for a step-by-step guide on how to create models in Studio):
Field Name Type Description Key Field Internal Check Box OrderNumber String Order number to reference the order by Natural Key - required; Immutable No Supplier ModelLink to Organization Organization which this order is placed against Non-key No Buyer ModelLink to Organization Organization that initiated the order Non-key No Book ModelLink to ZBKS.Book Book that is being ordered. Non-key No Quantity Integer Quantity of the book that's being ordered Non-key No State State State Non-key No
Rebuild the Bookstore module and restart your server.
Re-open the MPT and then Open the
Outlinetile in Bookstore's
Module Process Template.mptfile and select the newly created
Role Typelistbox under the
ZBKS.SampleRoleType. For both the
Writepermissions, select the
By Dimensioncheckbox, select the
Organizationoption, then hit
Select…, and finally, select the
Buyercheckbox in the dialog that opens:
This establishes the read/write privileges for any user with a role type of
ZBKS.SampleRoleTypeonly if that role’s organization matches the organization in any given BookOrder’s
Buyerfield. In other words, if a book’s
Buyerdoes not match the role’s organization, then that role cannot see the BookOrder.
Do the same as above for the
ZBKS.SupplierRoleType, selecting the
Suppliercheckbox instead of the
Buyercheckbox in the dialog that opens, in both the
Writetabs and save the MPT.
Next, with the
BookOrdermodel selected in the
Outlinepane, click the
Viewstab of the MPT and
Adda new view with the following properties:
You should see the new view in the
Viewssection, as well as the details for the
Querytab in the
View Detailssection. Select the following fields to be retrieved from the database for this view:
Book, Buyer, and
Supplierhave been selected as
Permissionstab of the new view grant both
ZBKS.SupplierRoleTypeaccess to the view.
Lastly, under the
Displaytab, select some relevant fields to display.
Now that we have a view defined, let’s proceed to allow buyers to create BookOrders. Select the
Addto add another action with the following properties:
Then modify the permissions to give
ZBKS.SampleRoleTypepermission to create BooktoreOrders.
Finally, define a new action screen for the
These are the fields the user must enter when he clicks on the
Createaction in the user interface.
As a last step we will add a menu item for the new BookOrderList view so that we can access it through the user interface. To do this, navigate to the root of the MPT in the Outline tile, and select the
UiMetaModeltab on the bottom left. Add the following XML under the other
Then add a menu reference to this action inside the
Save the MPT, and then Click
Submitto submit it to the server.
Next, create a form screen for the ZBKS.BookOrder model using User-Defined Pages framework. (Please refer back to Chapter 2's section on "Implementing User-Defined Pages" for a step-by-step guide on how to create User-Defined Pages.)
While creating a User-Defined page select the action "ZBKS.Create" created in step 10.
Routing Rules configuration:
Page Flow configuration:
Page Editor configuration:
You must also select queries for the model links added to the page. Create
web/public/scripts/GlobalRegistry.js(if it doesn't already exist) and add this code:
web/public/build.jsband add a reference to
Then deploy the Bookstore web files and re-open the Page Editor, and set the newly registered queries for both the Organization and Book model link fields and save:
Add the following
WebActionto your UI Meta Model.
Then add a menu reference to this action inside a WebActionGroup tag:
Now, submit the MPT, reload the UI and create a new book order with the following value.
Logging in as the SupplierUser created in earlier sections of the tutorial, we can now see that a new BookOrder is available for us by clicking on the
Book Order Listmenu. We still don't have any actions available to us, though.
We’ll add some actions and a state machine. To do this we will select open the Bookstore’s MPT and select
Outlinepane on the right and navigate to the
State Machinetab. Here we will specify three states:
- Ordered – the initial state of the BookOrder. Signifies that the order has been placed by the buyer and is awaiting action by the seller.
- Fulfilled – signifies that the order has been fulfilled by the seller. A BookOrder can only be moved into this state by the selling organization.
- Canceled – signifies that the order has been placed but was canceled by either party involved in the transaction.
To move the BookOrder between these states we will create a set of
Writeactions on the BookOrder model:
- Fulfill – moves the BookOrder to the Fulfilled state. Executable by a BookOrder’s selling organization.
- Cancel – moves the BookOrder to the Cancelled state. Executable by both a BookOrder’s selling and buying organizations.
Be sure to apply the appropriate
Permissionsto each action and make the action available in the UI by defining a view for it under the
Action Screen -> List Viewtab.
The final step is to mark the actions as transitions between states in the BookOrder’s
Open your SQL editor and execute the following queries so you able to see actions on UI:
We’ve now successfully created a multi-party transaction: a buying organization is able to place an order against a selling organization and both organizations are able to see changes to that order in real-time – given, of course, that they have the proper permissions (you’ll recall that we limited access to the BookOrder model to the buying and selling Organizations of a given BookOrder). As an exercise, you may create additional Organizations, Books, and Users to simulate or more complete Order Management System with multiple sourcing organizations.