======================================== LiveView Field Rules Sample ======================================== This sample is very similar to the Hello LiveView sample, with a few slight differences. This is still a StreamBase Studio project for LiveView that configures a Server instance with the following: - An ItemsSales table that reflects a live view of sales transactions for a merchant. These transactions have a transactionID and a transactionTime as well as a category attribute. This table is configured in the ItemsSales.lvconf file. - An ItemsInventory table, which is a LiveView-managed aggregate table on the ItemsSales table. This table rolls up Items sold by category and reports the average quantity of items sold and their average price, plus a real-time calculation of the current inventory value based on the last sold price. This table is configured in the ItemsInventory.lvconf file. - An EventFlow application (ItemsSalesDataSource/application.sbapp) that is responsible for sending data into the Items table. This application has a Feed Simulation Input Adapter executing the feed simulation named ItemsSales.sbfs. This project also includes a few examples of field-rules in order to highlight the processing that this feature provides. The sample field-rules have simple expressions, but any non-aggregate StreamBase expression is supported. To run this sample in Studio, you can: - In the LiveView Project Viewer, click the green Run button in the upper right. - Right-click any of the lvconf table configuration files in the Project Explorer view and select Run As > Run Configurations > Run (in the invoked Run Configurations dialog). - Right-click the project folder itself, and select Run As > LiveView Fragment For convenience, a LiveView Desktop workspace is available on the server. After the server is running, use the Studio Program launcher to start LiveView Desktop on the included workspace. The launcher is run from Run > External Tools, under the Program category, titled "Start LiveView Desktop (Hello Sample)". On OS X, the provided Desktop launcher can only locate LiveView Desktop if it is installed in the canonical location under STREAMBASE_HOME/liveview/desktop. ItemsSales.lvconf contains a variety of field-rules that will modify tuples prior to entering the LiveView Table. These rules, visible from the Field-Rules tab inside of ItemsSales.lvconf are as follows. The first rule will determine whether or not a discount should be applied. If the quantityRemaining field is greater than or equal to 200, a variable will be set to 'true' signifying that further actions are needed. Additionally, the variable discountAmount will be set to the discount percentage. In these cases, a quantity greater than or equal to 200 will be discounted by 50%, and quantities of greater than or equal to 100, the discount will be 25%. The second rule will apply the above discount. If a discount should be applied, it will multiply the price field by the discountAmount variable. Note that to access values stored in a variable, it is necessary to use current. to refer to that value. This Rule also inserts a value into the new field Discounted. If a discount was applied, the field will contain true, otherwise false. The third and final rule will insert or update the current timestamp into the lastUpdated field. Note that the field is updated and inserted in this case because the lastUpdated field should always contain a new timestamp, whether the tuple is being updated or inserted. To run this sample from the command line outside of Studio, you must: - Package this sample's LiveView fragment project into a fragment archive. - Create a separate StreamBase Application project, and set the pom.xml for that project to depend on the fragment archive created in the previous step. - Create a separate StreamBase Application archive file. - Install that archive into a StreamBase Runtime node. - Start the node. These steps are described in more detail in the "Deploy with epadmin" page of the Concepts Overview in the StreamBase documentation. Additional files present in the project: ItemsSalesDataSource.lvconf - registers the ItemsSalesDataSource/application.sbapp file with LiveView. This application starts automatically after all LiveView tables have loaded on startup. ItemsSales.sbfs - a feed simulation that sends a sales feed to the ItemsSales table. engine.conf - a LiveView configuration file to set up JVM arguments for this sample. lv-interfaces/ItemsSalesDataSource.sbint lv-interfaces/ItemsSalesSchemas.sbint These StreamBase interface (.sbint) files are generated by StreamBase Studio from the information provided in the ItemSales.lvconf file by the LiveView Data Source wizard, and are referenced in ItemsDataSource/application.sbapp. More information is available in the LiveView documentation.