NdsBeisUi/src/main/java/com/northgateps/nds/beis/ui/controller/handler/RegisterPrsExemptionHandler.java
/**
     * sets value of selectedExemptionTypeLovText on onAfterResolvedView event
     */
sets value of selectedExemptionTypeLovText on onAfterResolvedView event
sets value of selectedExemptionTypeLovText on onAfterResolvedView event
@Override
    public void onAfterResolvedView(NdsFormModel allModel, final ControllerState<?> controllerState) {
        final BeisAllModel model = (BeisAllModel) allModel;
        final UiData uiData = (UiData) model.getUiData();  
        if (uiData.getSelectedExemptionTypeText().getFrvRequired().equals("true")) {
            List<ExemptionTypeLov> exemptionTypeLovList = uiData.getSelectedExemptionTypeText().getExemptionTypeLovList();
            if (exemptionTypeLovList != null) {
                final String code = model.getExemptionDetails().getExemptionReason();
                ExemptionTypeLov exemptionTypeLovObj = exemptionTypeLovList.stream().filter(
                        x -> x.getCode().equals(code)).findFirst().get();
                String selectedExemptionTypeLovText = exemptionTypeLovObj != null ? exemptionTypeLovObj.getText() : "";
                uiData.setSelectedExemptionTypeLovText(selectedExemptionTypeLovText);
            }
        }
        GetPrsPenaltyRefDataNdsRequest submitRequest = new GetPrsPenaltyRefDataNdsRequest();
        final UiServiceClient uiSvcClient = controllerState.getController().getUiSvcClientFactory().getInstance(
                GetPrsPenaltyRefDataNdsResponse.class);
        uiSvcClient.setRetriesRemaining(0);
        if (!controllerState.isSyncController()) {
            uiSvcClient.post(serviceEndPoint, submitRequest);
        } else {
            uiSvcClient.postSync(serviceEndPoint, submitRequest);
        }
        uiSvcClient.setResponseConsumer(new NdsResponseConsumer() {
            @Override
            public boolean consume(NdsResponse response) {
                if (!(response instanceof GetPrsPenaltyRefDataNdsResponse)) {
                    return false;
                }
                GetPrsPenaltyRefDataNdsResponse fetchResponse = (GetPrsPenaltyRefDataNdsResponse) response;
                if (fetchResponse.getNdsMessages() != null) {
                    model.setPostSubmitMessage(
                            new ViewMessage("Error_ESB_withCausedBy", fetchResponse.getNdsMessages()));                   
                    return false;
                } else {
                    try {
                        List<PenaltyTypeDetails> penaltyTypeTextList = fetchResponse.getPenaltyTypeTextList();
                        String propertyType = model.getExemptionDetails().getPropertyType().toString();
                        for (PenaltyTypeDetails penaltyTypeDetails : penaltyTypeTextList) {
                            if (penaltyTypeDetails.getService() != null
                                    && penaltyTypeDetails.getService().equals(propertyType)
                                    && penaltyTypeDetails.getCode() != null
                                    && penaltyTypeDetails.getCode().equals("EXEMPT")) {
                                uiData.setPenaltyValue(penaltyTypeDetails.getMaxValue());
                            }
                        }
                    } catch (Exception e) {
                        logger.error("Could not set reference data set", e);
                    }
                }
                return true;
            }
        });
        controllerState.registerUiServiceClient(uiSvcClient);        
    }
@ Override public void onAfterResolvedView ( NdsFormModel allModel , final ControllerState < ? > controllerState ) { final BeisAllModel model = ( BeisAllModel ) allModel ; final UiData uiData = ( UiData ) model . getUiData ( ) ; if ( uiData . getSelectedExemptionTypeText ( ) . getFrvRequired ( ) . equals ( "true" ) ) { List < ExemptionTypeLov > exemptionTypeLovList = uiData . getSelectedExemptionTypeText ( ) . getExemptionTypeLovList ( ) ; if ( exemptionTypeLovList != null ) { final String code = model . getExemptionDetails ( ) . getExemptionReason ( ) ; ExemptionTypeLov exemptionTypeLovObj = exemptionTypeLovList . stream ( ) . filter ( x -> x . getCode ( ) . equals ( code ) ) . findFirst ( ) . get ( ) ; String selectedExemptionTypeLovText = exemptionTypeLovObj != null ? exemptionTypeLovObj . getText ( ) : "" ; uiData . setSelectedExemptionTypeLovText ( selectedExemptionTypeLovText ) ; } } GetPrsPenaltyRefDataNdsRequest submitRequest = new GetPrsPenaltyRefDataNdsRequest ( ) ; final UiServiceClient uiSvcClient = controllerState . getController ( ) . getUiSvcClientFactory ( ) . getInstance ( GetPrsPenaltyRefDataNdsResponse . class ) ; uiSvcClient . setRetriesRemaining ( 0 ) ; if ( ! controllerState . isSyncController ( ) ) { uiSvcClient . post ( serviceEndPoint , submitRequest ) ; } else { uiSvcClient . postSync ( serviceEndPoint , submitRequest ) ; } uiSvcClient . setResponseConsumer ( new NdsResponseConsumer ( ) { @ Override public boolean consume ( NdsResponse response ) { if ( ! ( response instanceof GetPrsPenaltyRefDataNdsResponse ) ) { return false ; } GetPrsPenaltyRefDataNdsResponse fetchResponse = ( GetPrsPenaltyRefDataNdsResponse ) response ; if ( fetchResponse . getNdsMessages ( ) != null ) { model . setPostSubmitMessage ( new ViewMessage ( "Error_ESB_withCausedBy" , fetchResponse . getNdsMessages ( ) ) ) ; return false ; } else { try { List < PenaltyTypeDetails > penaltyTypeTextList = fetchResponse . getPenaltyTypeTextList ( ) ; String propertyType = model . getExemptionDetails ( ) . getPropertyType ( ) . toString ( ) ; for ( PenaltyTypeDetails penaltyTypeDetails : penaltyTypeTextList ) { if ( penaltyTypeDetails . getService ( ) != null && penaltyTypeDetails . getService ( ) . equals ( propertyType ) && penaltyTypeDetails . getCode ( ) != null && penaltyTypeDetails . getCode ( ) . equals ( "EXEMPT" ) ) { uiData . setPenaltyValue ( penaltyTypeDetails . getMaxValue ( ) ) ; } } } catch ( Exception e ) { logger . error ( "Could not set reference data set" , e ) ; } } return true ; } } ) ; controllerState . registerUiServiceClient ( uiSvcClient ) ; }
sets value of selectedExemptionTypeLovText on onAfterResolvedView event
sets value of selectedExemptionTypeLovText on onAfterResolvedView event
//To set selected ExemptionType list of value text // create and post the request to get penalty value from service // do not automatically retry on connection errors // convert the returned list to the UI list