TRUCK_CALLUP_INTERCEPTOR

Description: Limited to code that overrides parts or all of the truck callup process with staging area setup.

You should define only one active code extension for extension type TRUCK_CALLUP_INTERCEPTOR. If you define more than one, make sure that only one is enabled. If multiple code extensions for this type are enabled, the callup process picks the first one in loop to execute.

Abstract Base Class: AbstractTruckCallupInterceptor

Methods:

Interface: ETruckCallupInterceptor

Module: Road

Version Added: 2.5

Requires Code Extension Name or Name Pattern: No

Code Extension Name or Name Pattern: N/A

Where to specify code extensions of this type: Not needed. N4 automatically searches for a code extension of this type when executing the Road Call-up background job.

 

Code example

The following sample code implements a code extension of type TRUCK_CALLUP_INTERCEPTOR that executes the default behavior of the truck callup process with staging area setup. By default, N4 writes a message to the log file to prove that it executed the process based on the code extension.

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

import com.navis.external.road.AbstractTruckCallupInterceptor;

import com.navis.framework.portal.UserContext;

import com.navis.road.business.model.Gate;

import com.navis.road.business.model.GateExchangeArea;

import com.navis.road.business.model.TruckVisitDetails;

import com.navis.road.business.util.RoadCallupUtil;

import com.navis.road.extension.callup.TruckCallupExtensionContext;

import com.navis.road.extension.callup.TruckCallupExtensionResponse;

public class TruckCallupInterceptor1 extends AbstractTruckCallupInterceptor {

    @Override

    public void executeCallup(TruckCallupExtensionContext inContext, TruckCallupExtensionResponse inResponse) {

        this.log("Called executeCallup from CodeExtension");

        List<TruckVisitDetails> candidateTruckVisits = getCandidateTruckVisits(inContext.getFacilityGkey());

        List<TruckVisitDetails> releaseTruckVisitList = getTrucksToRelease(candidateTruckVisits);

        // If we have some trucks which can be released from staging area, execute release action for them i.e. submit truck visit at "staging"

        /// stage for these trucks.... so that these trucks can proceed to yard.

        if (!releaseTruckVisitList.isEmpty()){

            for(TruckVisitDetails truckVisitDetail:releaseTruckVisitList){

                executeReleaseAction(inContext.getUserContext(), truckVisitDetail);

            }

        }

    }

    @Override

    public List<TruckVisitDetails> getCandidateTruckVisits(Serializable inFacilityGkey) {

        this.log("Called getCandidateTruckVisits from CodeExtension");

        List<TruckVisitDetails> candidateTruckVisits = RoadCallupUtil.getCandidateTruckVisits(inFacilityGkey);

        return candidateTruckVisits;

    }

    @Override

    public boolean transtainerExchangeAreaHasCapacity(TruckVisitDetails inTruckVisitDetails) {

        String exchangeAreaId = inTruckVisitDetails.getTvdtlsNextExchangeAreaId();

        Gate visitGate = inTruckVisitDetails.getTvdtlsGate();

        if(exchangeAreaId != null && visitGate != null){

            ExchangeArea exchangeArea = ExchangeArea.findById(exchangeAreaId);

            return getLaneManager().transtainerExchangeAreaCapacity(exchangeArea, inTruckVisitDetails) > 0L;

        } else {

            return false;

        }

    }

 

    @Override

    public boolean exchangeAreaHasCapacity(TruckVisitDetails inTruckVisitDetails) {

        String exchangeAreaId = inTruckVisitDetails.getTvdtlsNextExchangeAreaId();

        Gate visitGate = inTruckVisitDetails.getTvdtlsGate();

        if(exchangeAreaId != null && visitGate != null){

            GateExchangeArea exchangeArea = GateExchangeArea.findExchangeAreaById(exchangeAreaId, visitGate);

            return exchangeArea.exchangeAreaCapacity() > 0L;

        } else {

            return false;

        }

        this.log("Called exchangeAreaHasCapacity from CodeExtension");

    }

    @Override

    public List<TruckVisitDetails> getTrucksToRelease(List<TruckVisitDetails> inCandidateTruckVisits) {

        List<TruckVisitDetails> releaseTruckVisitList = new ArrayList<TruckVisitDetails>();

        Map<GateExchangeArea,Integer> candidateExchangeAreaMap = new HashMap<GateExchangeArea,Integer>();

        if (inCandidateTruckVisits != null && !inCandidateTruckVisits.isEmpty()) {

            for (TruckVisitDetails candidateTruckVisit : inCandidateTruckVisits) {

                // for each of this candidate truck visit check to see if assigned exchange area has capacity to serve this truck visit.

                boolean okToRelease = false;

                if (candidateTruckVisit.getTvdtlsNextExchangeAreaId() != null){

                    String exchangeAreaId = candidateTruckVisit.getTvdtlsNextExchangeAreaId();

                    Gate visitGate = candidateTruckVisit.getTvdtlsGate();

                    if(exchangeAreaId != null && visitGate != null){

                        GateExchangeArea exchangeArea = GateExchangeArea.findExchangeAreaById(exchangeAreaId, visitGate);

 

                        //Check if the exchange area is a Tranfer Zone - Transtainer block

                        Boolean isTranstainerTransferZone = exchangeArea.isTransferZoneTranstainerBlock();

                        Long exchangeAreaCapacity = 0L;

                        if(isTranstainerTransferZone) {

                            exchangeAreaCapacity = getLaneManager().transtainerExchangeAreaCapacity(exchangeArea, candidateTruckVisit);

                        } else {

                            exchangeAreaCapacity = getLaneManager().exchangeAreaCapacity(exchangeArea);

                        }

 

                        Integer processedCandidateTrucks =

                                candidateExchangeAreaMap.containsKey(exchangeArea) ? candidateExchangeAreaMap.get(exchangeArea) : 0;

                        processedCandidateTrucks++;

                        okToRelease =  exchangeAreaCapacity >= processedCandidateTrucks;

                        candidateExchangeAreaMap.put(exchangeArea,processedCandidateTrucks);

                    }

                }

                if (okToRelease) {

                    //if exchange area has capacity add this truck visit to release list.

                    releaseTruckVisitList.add(candidateTruckVisit);

                }

            }

        }

        return releaseTruckVisitList;

    }

    @Override

    public void executeReleaseAction(UserContext inUserContext, TruckVisitDetails inTruckVisitDetails) {

        this.log("Called executeReleaseAction from CodeExtension");

        RoadCallupUtil.executeReleaseAction(inUserContext, inTruckVisitDetails);

    }

}