NdsBeisUi/src/main/java/com/northgateps/nds/beis/ui/controller/handler/DashboardEventHandler.java
/**
     * The dashboard is the first page. 
     * 
     * When a page is navigated to only the onAfterResolvedView event should fire
     * When moving away from a page onBeforeValidation, onAfterValidation and onAfterNavigationUpdate.
     * 
     * This is the first page in the application and the usual rules do not apply.
     * When moving from CAS login to here all events fire (onBeforeValidation, onAfterValidation, onAfterNavigationUpdate, onAfterResolvedView)
     * When moving back to here from pages such as account detail (onAfterResolvedView).
     * 
     * This event fires:
     * 1. When moving from the security logon page to the dashboard
     * 2. When navigating away from the dashboard page.
     * 
     * The code in this event handler should only run for the first scenario.
     * The viewDashboard service will return the details required for the dashboard page
     * or an indicator that the user is only partially registered.
     *  
     * At the time of coding a partially registered user is one that has not got a UID
     * in LDAP against the user for FOUNDATION_LAYER_PARTY_SERVICE. This indicates the
     * registration service did not successfully communicate the registration to FL.
     * 
     * This handler forces the esb call to complete before the onAfterValidation
     * event using setTargetSlice.
     */
The dashboard is the first page.

When a page is navigated to only the onAfterResolvedView event should fire
When moving away from a page onBeforeValidation, onAfterValidation and onAfterNavigationUpdate.

This is the first page in the application and the usual rules do not apply.
When moving from CAS login to here all events fire (onBeforeValidation, onAfterValidation, onAfterNavigationUpdate, onAfterResolvedView)
When moving back to here from pages such as account detail (onAfterResolvedView).

This event fires:
1. When moving from the security logon page to the dashboard
2. When navigating away from the dashboard page.

The code in this event handler should only run for the first scenario.
The viewDashboard service will return the details required for the dashboard page
or an indicator that the user is only partially registered.

At the time of coding a partially registered user is one that has not got a UID
in LDAP against the user for FOUNDATION_LAYER_PARTY_SERVICE. This indicates the
registration service did not successfully communicate the registration to FL.

This handler forces the esb call to complete before the onAfterValidation
event using setTargetSlice.
The dashboard is the first page . When a page is navigated to only the onAfterResolvedView event should fire When moving away from a page onBeforeValidation onAfterValidation and onAfterNavigationUpdate . This is the first page in the application and the usual rules do not apply . When moving from CAS login to here all events fire ( onBeforeValidation onAfterValidation onAfterNavigationUpdate onAfterResolvedView ) When moving back to here from pages such as account detail ( onAfterResolvedView ) . This event fires : 1 . When moving from the security logon page to the dashboard 2 . When navigating away from the dashboard page . The code in this event handler should only run for the first scenario . The viewDashboard service will return the details required for the dashboard page or an indicator that the user is only partially registered . At the time of coding a partially registered user is one that has not got a UID in LDAP against the user for FOUNDATION_LAYER_PARTY_SERVICE . This indicates the registration service did not successfully communicate the registration to FL . This handler forces the esb call to complete before the onAfterValidation event using setTargetSlice .
@Override
    public void onBeforeValidation(NdsFormModel model, ControllerState<?> controllerState) {
        logger.trace("onBeforeValidation Entry");
        String userName;
        final BeisAllModel beisModel = (BeisAllModel) model;        
        final UiData uiData = (UiData)beisModel.getUiData();
        if (uiData != null && uiData.getRegistrationStatus() == null) {
            final String serviceEndPoint = ConfigurationFactory.getConfiguration().getString(
                    "esbEndpoint.viewDashboard");
            final UiServiceClient uiSvcClient = controllerState.getController().getUiSvcClientFactory().getInstance(
                    GetPRSAccountExemptionsNdsResponse.class);
            logger.trace("ESB endpoint from configuration is: " + serviceEndPoint);
            GetPRSAccountExemptionsNdsRequest request = new GetPRSAccountExemptionsNdsRequest();
            if (beisModel.getBeisRegistrationDetails() == null) {
                beisModel.setBeisRegistrationDetails(new BeisRegistrationDetails());
            }
            final PlatformUser user = PlatformUser.getLoggedInUser();
            userName = user.getUsername();
            request.setUsername(userName);
            request.setTenant(user.getTenant());
            uiSvcClient.setTargetSlice("before-validation");
            if (!controllerState.isSyncController()) {
                uiSvcClient.post(serviceEndPoint, request);
            } else {
                uiSvcClient.postSync(serviceEndPoint, request);
            }
            uiSvcClient.setResponseConsumer(new NdsResponseConsumer() {
                @Override
                public boolean consume(NdsResponse response) {
                    GetPRSAccountExemptionsNdsResponse dashboardResponse = (GetPRSAccountExemptionsNdsResponse) uiSvcClient.getResponse();
                    if (dashboardResponse != null && dashboardResponse.isSuccess()) {
                        beisModel.setDashboardDetails(dashboardResponse.getDashboardDetails());
                        uiData.setRegistrationStatus(RegistrationStatusType.FOUND_REGISTERED);
                        uiData.setUserType(dashboardResponse.getUserType());
                        return true;
                    }
                    if (dashboardResponse.getNdsMessages() != null) {
                        NdsMessages error = dashboardResponse.getNdsMessages();
                        if(error.getViolations() != null){
                            if(error.getViolations().get(0) != null){
                                if (error.getViolations().get(0).getMessage() != null) {                                    
                                    if (error.getViolations().get(0).getMessage().contains(
                                            "The user is only partially registered and does not have a valid account id") || error.getViolations().get(0).getMessage().contains("BEI-187") || error.getViolations().get(0).getMessage().contains("BEI-188") ) {        
                                        uiData.setRegistrationStatus(RegistrationStatusType.FOUND_PARTIALLY_REGISTERED);
                                        return true;        
                                    }
                                }
                            }
                        }
                    }                    
                    return false;
                }
            });
            controllerState.registerUiServiceClient(uiSvcClient);
        }        
        logger.trace("onBeforeValidation Exit");
    }
@ Override public void onBeforeValidation ( NdsFormModel model , ControllerState < ? > controllerState ) { logger . trace ( "onBeforeValidation Entry" ) ; String userName ; final BeisAllModel beisModel = ( BeisAllModel ) model ; final UiData uiData = ( UiData ) beisModel . getUiData ( ) ; if ( uiData != null && uiData . getRegistrationStatus ( ) == null ) { final String serviceEndPoint = ConfigurationFactory . getConfiguration ( ) . getString ( "esbEndpoint.viewDashboard" ) ; final UiServiceClient uiSvcClient = controllerState . getController ( ) . getUiSvcClientFactory ( ) . getInstance ( GetPRSAccountExemptionsNdsResponse . class ) ; logger . trace ( "ESB endpoint from configuration is: " + serviceEndPoint ) ; GetPRSAccountExemptionsNdsRequest request = new GetPRSAccountExemptionsNdsRequest ( ) ; if ( beisModel . getBeisRegistrationDetails ( ) == null ) { beisModel . setBeisRegistrationDetails ( new BeisRegistrationDetails ( ) ) ; } final PlatformUser user = PlatformUser . getLoggedInUser ( ) ; userName = user . getUsername ( ) ; request . setUsername ( userName ) ; request . setTenant ( user . getTenant ( ) ) ; uiSvcClient . setTargetSlice ( "before-validation" ) ; if ( ! controllerState . isSyncController ( ) ) { uiSvcClient . post ( serviceEndPoint , request ) ; } else { uiSvcClient . postSync ( serviceEndPoint , request ) ; } uiSvcClient . setResponseConsumer ( new NdsResponseConsumer ( ) { @ Override public boolean consume ( NdsResponse response ) { GetPRSAccountExemptionsNdsResponse dashboardResponse = ( GetPRSAccountExemptionsNdsResponse ) uiSvcClient . getResponse ( ) ; if ( dashboardResponse != null && dashboardResponse . isSuccess ( ) ) { beisModel . setDashboardDetails ( dashboardResponse . getDashboardDetails ( ) ) ; uiData . setRegistrationStatus ( RegistrationStatusType . FOUND_REGISTERED ) ; uiData . setUserType ( dashboardResponse . getUserType ( ) ) ; return true ; } if ( dashboardResponse . getNdsMessages ( ) != null ) { NdsMessages error = dashboardResponse . getNdsMessages ( ) ; if ( error . getViolations ( ) != null ) { if ( error . getViolations ( ) . get ( 0 ) != null ) { if ( error . getViolations ( ) . get ( 0 ) . getMessage ( ) != null ) { if ( error . getViolations ( ) . get ( 0 ) . getMessage ( ) . contains ( "The user is only partially registered and does not have a valid account id" ) || error . getViolations ( ) . get ( 0 ) . getMessage ( ) . contains ( "BEI-187" ) || error . getViolations ( ) . get ( 0 ) . getMessage ( ) . contains ( "BEI-188" ) ) { uiData . setRegistrationStatus ( RegistrationStatusType . FOUND_PARTIALLY_REGISTERED ) ; return true ; } } } } } return false ; } } ) ; controllerState . registerUiServiceClient ( uiSvcClient ) ; } logger . trace ( "onBeforeValidation Exit" ) ; }
The dashboard is the first page.
The dashboard is the first page .
// Ensure we have registered details so we can set the partially registered property // get logged in user's details // Force this request to the REST service to complete before validation. // set the details in the model // Set an indicator on the model. // Check for partially registered exception //BEI-187 -The landlord is no longer current and BEI-188 A suitable party does not exist for the PartyRef supplied  // Set an indicator on the model.