Skip to content

All about Matchers

julia-fms edited this page Mar 7, 2016 · 10 revisions

All about Matchers

Contents

  1. Type of matchers
  2. How to add matcher on the centre
  3. How to add matcher on the master
  4. Inter dependable matcher on the centre

Type of matchers

Selection criteria for the centre (which are linked to the entity based properties and autoclompleter is used) or entity based property for the master could be used with the matching functionality or in other words additional filtering could be provided by implementation of the matcher.

This why there two types of matchers:

  • matcher for the centre
  • matcher for the master

Both machers use the same concept and are used in the similar way, but have to be extended from the different parent classes.

Matcher for the centre has to extend AbstractSearchEntityByKeyWithCentreContext. Matcher for the master has to extend AbstractSearchEntityByKeyWithContext.

The good example of the use both this matchers is DriverAllocationWebUiConfig in the TridentFleet.


How to add matcher on the centre

To add matcher to the centre you need to:

  1. Create new class that extends AbstractSearchEntityByKeyWithCentreContext for the entity you are implementing this selection criteria for.
  2. Implement constructor and provide companion object for entity via @Inject
  3. Implement and override completeEqlBasedOnContext method that will contain the filtering logic.
  4. In the WebUiConfiguration in the createEntityCentre() link created matcher to the selection criteria by calling the method withMatcher() and pass mather's class as parameter. The configuration of the autocompleter should be modified by calling the method .withProps() and passing those extra filtering properties (with True for value) for them to be present in the autocompleter.

The following code is the example of the matcher for centre that allows to filter Vehicle not only by its key, but also on radioNo and regNo.

public class VehicleByRegoOrRadioMatcher extends AbstractSearchEntityByKeyWithCentreContext<Vehicle> {

    @Inject
    public VehicleByRegoOrRadioMatcher(final IVehicle coVehicle) {
        super(coVehicle);
    }

    @Override
    protected EntityResultQueryModel<Vehicle> completeEqlBasedOnContext(final CentreContext<Vehicle, ?> context, final String searchString, final ICompoundCondition0<Vehicle> incompleteEql) {
        return incompleteEql
                .or().prop("radioNo").iLike().val(searchString)
                .or().prop("regNo.key").iLike().val(searchString)
                .model();
    }

This is how the matcher should be linked to the selection criteria:

 .addCrit("vehicle").asMulti().autocompleter(Vehicle.class)
         .withMatcher(VehicleByRegoOrRadioMatcher.class)
         .withProps(pair("desc", false), pair("radioNo", true), pair("regNo", true))
         .also()

Basically its means - use autocompleter for the Vehicle but apply some additional filtering implemented via VehicleByRegoOrRadioMatcher, show extra properties desc, radioNo and regNo, but filter only on last two.

User will be presented with the following look and feel when selecting the vehicle:

Picture is comming... when I learn how to upload it into the github


How to add matcher on the master

To add matcher to the master you need ...

  1. Create new class that extends AbstractSearchEntityByKeyWithContext for the entity you are calling autocomleter for.
  2. Implement constructor and provide companion object for entity via @Inject
  3. Implement and override completeEqlBasedOnContext method that will contain the filtering logic.
  4. In the WebUiConfiguration in the createEntityMaster() link created matcher to the property by calling the method withMatcher() and pass mather's class as parameter. The configuration of the autocompleter should be modified by calling the method .withProps() and passing those extra filtering properties (with True for value) for them to be present in the autocompleter.

The following code is the example of the abstract matcher for master that allows to filter active vehicles not only by its key, but also on radioNo and regNo.

public abstract class AbstractActiveVehicleOnMasterMatcher<CONTEXT extends AbstractEntity<?>> extends AbstractSearchEntityByKeyWithContext<CONTEXT, Vehicle> {

    @Inject
    public AbstractActiveVehicleOnMasterMatcher (final IVehicle coVehicle) {
        super(coVehicle);
    }

    @Override
    protected EntityResultQueryModel<Vehicle> completeEqlBasedOnContext(final CONTEXT context, final String searchString, final ICompoundCondition0<Vehicle> incompleteEql) {
        // The condition should be
        //   ( key like % || radioNo like % || regNo like % ) && (active == true)
        // However, incompleteEql already contains key like % without beginning parenthesis
        // Therefore the condition is
        //   ( key like %  && active == true) || (radioNo like % && active == true) || (regNo like % && active == true)

        return incompleteEql.and().prop("active").eq().val(true).
                or().prop("radioNo").iLike().val(searchString).and().prop("active").eq().val(true).
                or().prop("regNo.key").iLike().val(searchString).and().prop("active").eq().val(true).
                model();
    }
}

Based on this abstract class matcher for the DriverAllocation entity is created:

public class DriverAllocationActiveVehicleMatcher extends AbstractActiveVehicleOnMasterMatcher<DriverAllocation> {

    @Inject
    public DriverAllocationActiveVehicleMatcher(final IVehicle coVehicle) {
        super(coVehicle);
    }

}

This is how the matcher should be linked to the property vehicle on the master for the DriverAllocation :

    .addProp("vehicle").asAutocompleter()
    .withMatcher(DriverAllocationActiveVehicleMatcher.class)
    .withProps(pair("desc", false), pair("radioNo", true), pair("regNo", true))
    .also()

Basically its means - use autocompleter for the Vehicle but apply some additional filtering implemented via DriverAllocationActiveVehicleMatcher, show extra properties desc, radioNo and regNo, but filter only on last two.

User will be presented with the following look and feel when selecting the vehicle during entering of new vehicle or modifying existing:

Picture is comming... when I learn how to upload it into the github


Inter dependable matcher on the centre

In some cases matcher can depend on value for the other property...


Clone this wiki locally