In this example, we added data to the database for a flight plan for two cargo containers. An aircraft has been assigned to this flight plan.

You need to model rules to check if the flight plan is valid by comparing the total of the cargo weights with the maximum cargo weight of the aircraft as follows:

  • If the total cargo weight is less than the maximum cargo weight of the assigned aircraft, the rule should throw an Info message.
  • If the total cargo weight exceeds the maximum cargo weight of the assigned aircraft, the rule should throw a Violation message.

We need to create a Rulesheet by right-clicking on Cargo.ecore, and then choosing New > Rulesheet.

media/image27.png

Name the Rulesheet CheckFlightPlanWeight, and then click Finish.

media/image28.png

Fill in the Rulesheet as illustrated:

media/image29.png

Here are the steps for this task:

  1. Choose the menu option Rulesheet > Advanced View.
  2. From the Vocabulary, drag and drop to the Scope panel:
    1. FlightPlan
    2. The FlightPlan association aircraft onto FlightPlan in the Scope, and then double click on it to open its alias entry box where you enter plane.
    3. The Aircraft attribute maxCargoWeight onto aircraft in the Scope.
    4. The FlightPlan association cargo onto FlightPlan in the Scope, and then double click on it to open its alias entry box where you enter load.
    5. The Cargo attribute weight onto cargo in the Scope.
  3. Write the condition load.weight->sum>plane.maxCargoWeight
  4. Select T in column 1 and F in column 2.
  5. Enter the rule statements as shown.
  6. Save the file.

Let’s look at the sample data that we want to retrieve. In SQL Server Management Studio, right-click the dbo.FlightPlan table and select Select Top 1000 Rows.

media/image30.pngYou should see the following result:

media/image31.png

This retrieves one record—a FlightPlan with a flightNumber (the primary key of FlightPlan) set to 111, that is associated with an aircraft whose tailNumber is N111A.

Let’s look at the Aircraft records. Right-click the dbo.Aircraft table and select Select Top 1000 Rows. This should return one record:

media/image32.png

Note that the tailNumber (which is Aircraft’s primary key) N111A, corresponds to the tailNumber of the associated aircraft in the FlightPlan’s record. Also, notice that the maximum cargo weight is 150000.

Now, let’s look at the cargo records. Right-click the dbo.Cargo table and select Select Top 1000 Rows. You should see the following records:

media/image33.png

Note that in both records, the associated flightNumber is 111, which is same as the flightNumber of the FlightPlan record retrieved earlier. The sum of the cargo weight is 250000, which exceeds the maximum cargo weight of the Aircraft record.