Part 2: Implementing a Java API Class
From AgileApps Support Wiki
In this part of the exercise, you implement a new service on the Orders Object to iterate through all the Line Items and update the Line Item count on the order. You are given an example Java API that uses the “Search API” as well as the “Update Object API”. (See the http://agileappscloud.info/aawiki/Java_API for information on these APIs.)
- Set up your package namespace:
- Log in to AgileApps Cloud as yourself and navigate to Configuration > Customization > Developer Resources.
- Click Developer Configuration, and then Edit.
- In the Update Configuration page, for the Namespace, type <your_ subdomain>Orders where you replace <your_subdomain> with your webMethods AgileApps Cloud tenant subdomain name. For example: johnrichardsOrders. Leave the Debug Log Level unchanged.
- Note: The chosen Namespace will become a part of the Package name of the Java classes you add later. You will also define subspaces, when you add classes.
- Click Save.
- Select Classes and click New Class.
- Provide the values for a new Class named UpdateOrder in a package sub-folder TrainingOrders as shown:
- Click Next. The Class Editor opens already providing a skeleton of the class implementation:
- In Windows Explorer, navigate to the <workshop_dir> folder and open the file UpdateOrderClass.txt using a text editor, such as Notepad.
- In the editor, select all the content of the file. Copy the entire content and replace all the content in the webMethods AgileApps Cloud Class Editor by pasting the copied code.
- Adapt the package name: change <your_subdomain>Orders to the Namespace you defined in step 1c) of this exercise, for example:
package com.platform.johnrichardsOrders.TrainingOrders;
- Click Save.
- To set up a test to validate the Class, create a new Business Rule that runs whenever an order is updated to Resolved status:
- Navigate to Configuration > Customization > Objects > Orders > Business Rules.
- On the Event Rules tab, select Updated(0) from the On Record drop-down list, and then click New Rule.
800px - Configure a new Event Rule named Total Line Items that:
- Only fires when an Order is updated with a new Status of Resolved
- Performs two actions:
- o Sets the status to Closed (to prevent the Update Event Rule from firing recursively)
- o Invokes the UpdateLineItems method within class UpdateOrder, which calculates and updates the Line Items Total field for an Order.
- Click Save.
- Test the new class:
Taking It Further
- To try another example that uses a Java API class to provide a pattern validation of the Line Item Object’s Part Number field whenever a Line Item is created or updated. Use the steps in Part 2 of this exercise as guidance and the code provided in the <workshop-dir>\FieldValidations.txt file.
- To extend what you learned in this exercise, see these AgileApps Cloud wiki pages:
- For expert Java programmers, learn how to integrate the AgileApps plugin in your Eclipse installations: