Booking Processors

The so-called Booking Processors are the business components that process a booking accordingly to the defined workflow rules. In this context, the Processors use a lot of other components to execute certain tasks, as for example location and inventory resolution as well as creating a single transaction for all elementary booking operations.

When processing a booking, it is important to be aware of the tool type that has to be processed. At the latest, when writing the modified inventories to the database, the business logic has to take care about the tool type in order to insert the data into the correct table.

To achieve this, there's a generalized Booking Processor implementation, which is able to handle the common tasks for all tool types. A part of the corresponding class is shown in listing 1.

public abstract class BookingProcessorBase
{        
    // ...

    public virtual BookingResponse Process(BookingRequest bookingRequest)
    {
        /// ...

        var behavior = BookingBehaviorFactory.Get(bookingRequest.BookingDirection);
        var lookupResult = LocationDiscoveryService.Lookup(bookingRequest);

        if (!lookupResult.LookupSucceeded)
        {
            return HandleFailedLookup(lookupResult);
        }

        bookingRequest.EnrichWithDistributionInfos(lookupResult);
        var transactionRequest = behavior.ApplyOn(bookingRequest);
        var response = ExecuteTransaction(transactionRequest);
        EnrichWithDistributionInfos(bookingRequest, response);

        /// ...

        return response;
    }

    /// ...

    /// Abstract members.

    protected abstract CreditBooking CreateCreditBooking(CorrectionRequest correctionRequest, int amountNew, int amountUsed);

    protected abstract IEnumerable<FreeStockplace> GetFreeLocations(string costunitId, string workplaceId, string articleId, int amountNew);

    protected abstract IEnumerable<Inventory> GetInventories(string fromCostunitId, string fromWorkplaceId, string articleId);

    protected abstract IEnumerable<LogicInventory> GetLogicInventories(string costunitId, string workplaceId, string locationId, string articleId);
}

Listing 1: The BookingProcessorBase implementation.

A first thing that comes into mind when analyzing the listing, is the assignment of the abstract keyword to the BookingProcessorBase class. That is, it is required to create a specialized class that derives from BookingProcessorBase for each available tool type. The requirement to do so is given by the circumstance that dependent on the tool type, the available inventories as well as the storage locations for a booking operation are differing. In addition to Listing 1, this is also illustrated in Figure 1.

Figure 1: Hierarchy of the Booking Processors. The Booking Processors are specialized by the particular tool types and access different database tables.

The Process method shown in the listing defines the default behavior of the booking process, which is valid for all tool types. In case of tool type specific extensions, the method can be overridden in a derived class, which implements tool type specific behavior. Additionally, at the bottom of the listing, there are four abstract methods, that have to be overwritten by specialized Booking Processors in order to provide the data based on the correct tool type.

For instance, one of the methods that have to be overridden in the derived classes is the GetInventories(...) method shown in listing 2. Illustrated is the implementation this method in the ToolBookingProcessor derivation, which takes costunit and article information as input parameters. The only task to be executed in the method is the following:

  1. Query over all tool inventories, filter them by the BookStateNumber and ensure that the inventories are unlocked.
  2. Group the results by the attributes illustrated in the listing and apply the sum(...) aggregate function on the inventory amounts for summarizing the available inventories.

This task is represented by one single LINQ statement, as comes out of listing 2.

protected override IEnumerable<Inventory> GetInventories(string costunitId, string workplaceId, string articleId)
{
    var result = from i in _inventoryManager.GetAllForArticle(costunitId, workplaceId, articleId)
                 where i.BookStateNumber == 0 || i.BookStateNumber == -1 && i.Locked == false
                 group i by new
                 {
                     i.Costunit,
                     i.Workplace,
                     i.LocationId,
                     i.CostunitType,
                     i.StockTypeId,
                     i.ExternalSystemType,
                     i.AutoConfirmLocation,
                     i.ArticleId
                 } into gi
                 select new ToolInventory
                 {
                     Costunit = gi.Key.Costunit,
                     Workplace = gi.Key.Workplace,
                     LocationId = gi.Key.LocationId,
                     CostunitType = gi.Key.CostunitType,
                     StockTypeId = gi.Key.StockTypeId,
                     ExternalSystemType = gi.Key.ExternalSystemType,
                     AutoConfirmLocation = gi.Key.AutoConfirmLocation,
                     ArticleId = gi.Key.ArticleId,
                     AmountNew = gi.Sum(i => i.AmountNew),
                     AmountUsed = gi.Sum(i => i.AmountUsed)
                 };

    return result;
}

Listing 2: The GetInventories(...) method of the ToolBookingProcessor.

results matching ""

    No results matching ""