NdsBeisUi/src/main/java/com/northgateps/nds/beis/ui/controller/handler/DashboardEventHandler.java
/**
     * If the viewDashboard esb call in the onBeforeValidation event indicates the user 
     * is only partially registered then retrieve the partially registered user details.
     * This handler forces the esb call to complete before the onAfterNavigationUpdate
     * event using setTargetSlice.
     */
If the viewDashboard esb call in the onBeforeValidation event indicates the user
is only partially registered then retrieve the partially registered user details.
This handler forces the esb call to complete before the onAfterNavigationUpdate
event using setTargetSlice.
If the viewDashboard esb call in the onBeforeValidation event indicates the user is only partially registered then retrieve the partially registered user details . This handler forces the esb call to complete before the onAfterNavigationUpdate event using setTargetSlice .
@Override
    public void onAfterValidation(NdsFormModel model, ControllerState<?> controllerState) {
        logger.trace("onAfterValidation Entry");
        BeisAllModel beisModel = (BeisAllModel) model;
        final UiData uiData = (UiData)beisModel.getUiData();
        if (uiData.getRegistrationStatus() != null 
                && uiData.getRegistrationStatus() == RegistrationStatusType.FOUND_PARTIALLY_REGISTERED){
            BeisRegistrationDetails registrationDetails = beisModel.getBeisRegistrationDetails();
            final String serviceEndPoint = ConfigurationFactory.getConfiguration().getString(
                    "esbEndpoint.getPartiallyRegisteredDetails");
            final UiServiceClient uiSvcClient = controllerState.getController().getUiSvcClientFactory().getInstance(
                    GetPartiallyRegisteredDetailsNdsResponse.class);
            logger.trace("ESB endpoint from configuration is: " + serviceEndPoint);
            GetPartiallyRegisteredDetailsNdsRequest request = new GetPartiallyRegisteredDetailsNdsRequest();
            final PlatformUser user = PlatformUser.getLoggedInUser();
            String userName = user.getUsername();
            request.setUsername(userName);
            request.setTenant(user.getTenant());
            uiSvcClient.setTargetSlice("before-navigation-update");
            if (!controllerState.isSyncController()) {
                uiSvcClient.post(serviceEndPoint, request);
            } else {
                uiSvcClient.postSync(serviceEndPoint, request);
            }
            uiSvcClient.setResponseConsumer(new NdsResponseConsumer() {
                @Override
                public boolean consume(NdsResponse response) {
                    GetPartiallyRegisteredDetailsNdsResponse partiallyRegisteredResponse = (GetPartiallyRegisteredDetailsNdsResponse) uiSvcClient.getResponse();
                    if (partiallyRegisteredResponse != null && partiallyRegisteredResponse.isSuccess()
                            && partiallyRegisteredResponse.getPartiallyRegisteredDetails() != null) {
                        fillModelWithRegisteredData(partiallyRegisteredResponse, beisModel);
                        return true;
                    } else {
                        return false;
                    }
                }
                private void fillModelWithRegisteredData(
                        GetPartiallyRegisteredDetailsNdsResponse partiallyRegisteredResponse, BeisAllModel beisModel) {
                    UpdateBeisRegistrationDetails registeredDetails = partiallyRegisteredResponse.getPartiallyRegisteredDetails();
                    registrationDetails.setAccountDetails(registeredDetails.getAccountDetails());
                    BeisUpdateUserDetails updateUserDetails = registeredDetails.getUpdateUserDetails();
                    if (updateUserDetails != null) {
                        BeisUserDetails userDetails = new BeisUserDetails();
                        userDetails.setEmail(updateUserDetails.getEmail());
                        userDetails.setConfirmEmail(updateUserDetails.getEmail());
                        userDetails.setUsername(updateUserDetails.getUsername());
                        if(updateUserDetails.getUserType() !=null){                           
                             userDetails.setUserType(updateUserDetails.getUserType());                           
                        }
                        registrationDetails.setUserDetails(userDetails);
                    }
                    beisModel.setBeisRegistrationDetails(registrationDetails);
                    if (registeredDetails.getContactAddress().getPostcode() != null
                            && registeredDetails.getContactAddress().getPostcode() != "") {
                        final NdsUiData uiData = (NdsUiData) beisModel.getUiData();
                        Map<String, AddressField> addressFields = new HashMap<String, AddressField>();
                        AddressField addressField = new AddressField();
                        addressField.setPostcodeCriterion(registeredDetails.getContactAddress().getPostcode());
                        String key = "beisRegistrationDetails.contactAddress";
                        addressFields.put(key, addressField);
                        uiData.setAddressFields(addressFields);
                    }
                }
            });
            controllerState.registerUiServiceClient(uiSvcClient);
        }
        logger.trace("onAfterValidation Exit");
    }
@ Override public void onAfterValidation ( NdsFormModel model , ControllerState < ? > controllerState ) { logger . trace ( "onAfterValidation Entry" ) ; BeisAllModel beisModel = ( BeisAllModel ) model ; final UiData uiData = ( UiData ) beisModel . getUiData ( ) ; if ( uiData . getRegistrationStatus ( ) != null && uiData . getRegistrationStatus ( ) == RegistrationStatusType . FOUND_PARTIALLY_REGISTERED ) { BeisRegistrationDetails registrationDetails = beisModel . getBeisRegistrationDetails ( ) ; final String serviceEndPoint = ConfigurationFactory . getConfiguration ( ) . getString ( "esbEndpoint.getPartiallyRegisteredDetails" ) ; final UiServiceClient uiSvcClient = controllerState . getController ( ) . getUiSvcClientFactory ( ) . getInstance ( GetPartiallyRegisteredDetailsNdsResponse . class ) ; logger . trace ( "ESB endpoint from configuration is: " + serviceEndPoint ) ; GetPartiallyRegisteredDetailsNdsRequest request = new GetPartiallyRegisteredDetailsNdsRequest ( ) ; final PlatformUser user = PlatformUser . getLoggedInUser ( ) ; String userName = user . getUsername ( ) ; request . setUsername ( userName ) ; request . setTenant ( user . getTenant ( ) ) ; uiSvcClient . setTargetSlice ( "before-navigation-update" ) ; if ( ! controllerState . isSyncController ( ) ) { uiSvcClient . post ( serviceEndPoint , request ) ; } else { uiSvcClient . postSync ( serviceEndPoint , request ) ; } uiSvcClient . setResponseConsumer ( new NdsResponseConsumer ( ) { @ Override public boolean consume ( NdsResponse response ) { GetPartiallyRegisteredDetailsNdsResponse partiallyRegisteredResponse = ( GetPartiallyRegisteredDetailsNdsResponse ) uiSvcClient . getResponse ( ) ; if ( partiallyRegisteredResponse != null && partiallyRegisteredResponse . isSuccess ( ) && partiallyRegisteredResponse . getPartiallyRegisteredDetails ( ) != null ) { fillModelWithRegisteredData ( partiallyRegisteredResponse , beisModel ) ; return true ; } else { return false ; } } private void fillModelWithRegisteredData ( GetPartiallyRegisteredDetailsNdsResponse partiallyRegisteredResponse , BeisAllModel beisModel ) { UpdateBeisRegistrationDetails registeredDetails = partiallyRegisteredResponse . getPartiallyRegisteredDetails ( ) ; registrationDetails . setAccountDetails ( registeredDetails . getAccountDetails ( ) ) ; BeisUpdateUserDetails updateUserDetails = registeredDetails . getUpdateUserDetails ( ) ; if ( updateUserDetails != null ) { BeisUserDetails userDetails = new BeisUserDetails ( ) ; userDetails . setEmail ( updateUserDetails . getEmail ( ) ) ; userDetails . setConfirmEmail ( updateUserDetails . getEmail ( ) ) ; userDetails . setUsername ( updateUserDetails . getUsername ( ) ) ; if ( updateUserDetails . getUserType ( ) != null ) { userDetails . setUserType ( updateUserDetails . getUserType ( ) ) ; } registrationDetails . setUserDetails ( userDetails ) ; } beisModel . setBeisRegistrationDetails ( registrationDetails ) ; if ( registeredDetails . getContactAddress ( ) . getPostcode ( ) != null && registeredDetails . getContactAddress ( ) . getPostcode ( ) != "" ) { final NdsUiData uiData = ( NdsUiData ) beisModel . getUiData ( ) ; Map < String , AddressField > addressFields = new HashMap < String , AddressField > ( ) ; AddressField addressField = new AddressField ( ) ; addressField . setPostcodeCriterion ( registeredDetails . getContactAddress ( ) . getPostcode ( ) ) ; String key = "beisRegistrationDetails.contactAddress" ; addressFields . put ( key , addressField ) ; uiData . setAddressFields ( addressFields ) ; } } } ) ; controllerState . registerUiServiceClient ( uiSvcClient ) ; } logger . trace ( "onAfterValidation Exit" ) ; }
If the viewDashboard esb call in the onBeforeValidation event indicates the user
 is only partially registered then retrieve the partially registered user details.
If the viewDashboard esb call in the onBeforeValidation event indicates the user is only partially registered then retrieve the partially registered user details .
// cast the generic model to the beis model // Build a request to get the partially registered details // get logged in user's details // Force this request to the REST service to complete before navigation update. // set the details in the model // Copy the model items // Set the postcode in the UI data