NdsBeisUi/src/main/java/com/northgateps/nds/beis/ui/controller/handler/SubmitPrsExemptionHandler.java
/**
     * submits request to esb to register the exemption
     */
submits request to esb to register the exemption
submits request to esb to register the exemption
@Override
    public void onAfterResolvedView(NdsFormModel allModel, final ControllerState<?> controllerState) {
        final BeisAllModel model = (BeisAllModel) allModel;
        final UiData uiData = (UiData) model.getUiData();
        final UiServiceClient uiSvcClient = controllerState.getController().getUiSvcClientFactory().getInstance(
                RegisterPrsExemptionNdsResponse.class);
        RegisterPrsExemptionNdsRequest registerPrsExemptionNdsRequest = new RegisterPrsExemptionNdsRequest();
        final PlatformUser user = PlatformUser.getLoggedInUser();
        String userName = user.getUsername();
        registerPrsExemptionNdsRequest.setUserName(userName);
        registerPrsExemptionNdsRequest.setTenant(user.getTenant());
        RegisterPrsExemptionDetails registerPrsExemptionDetails = new RegisterPrsExemptionDetails();
        ExemptionDetail exemptionDetails = model.getExemptionDetails();
        registerPrsExemptionDetails.setExemptionDetails(exemptionDetails);
        registerPrsExemptionNdsRequest.setPwsText(uiData.getSelectedExemptionTypeText().getPwsDescription());
        registerPrsExemptionNdsRequest.setMaxPenaltyValue(uiData.getPenaltyValue());
        registerPrsExemptionNdsRequest.setRegisterPrsExemptionDetails(registerPrsExemptionDetails);
        uiSvcClient.setTimeLimit(Long.parseLong(submitPrsExemptionServiceTimeout));
        if (!controllerState.isSyncController()) {
            uiSvcClient.post(serviceEndPoint, registerPrsExemptionNdsRequest);
        } else {
            uiSvcClient.postSync(serviceEndPoint, registerPrsExemptionNdsRequest);
        }
        uiSvcClient.setResponseConsumer(new NdsResponseConsumer() {
            @Override
            public boolean consume(NdsResponse response) {
                if (!(response instanceof RegisterPrsExemptionNdsResponse)) {
                    model.setPostSubmitMessage(null); 
                    return false;
                }
                RegisterPrsExemptionNdsResponse registerPrsExemptionNdsResponse = (RegisterPrsExemptionNdsResponse) (response);
                if (registerPrsExemptionNdsResponse.isSuccess()) {
                    return true;
                } else if (registerPrsExemptionNdsResponse.getNdsMessages() != null) {
                    List<ValidationViolation> violations = registerPrsExemptionNdsResponse.getNdsMessages().getViolations();
                    if (violations != null) {
                        for (ValidationViolation validationViolation : violations) {
                            if (validationViolation.getMessage().contains(
                                    "Unable to send e-mail for exemption registration") && violations.size() == 1) {
                                final Map<String, Object> attributes = controllerState.getAttributes();
                                attributes.put("fault", controllerState.getController().sysErr(
                                        ViewMessage.fromViolations(violations), controllerState));
                                return true;
                            }
                        }
                    }
                    model.setPostSubmitMessage(new ViewMessage("Error_ESB_withCausedBy",
                            registerPrsExemptionNdsResponse.getNdsMessages()));
                    return false;
                } else {
                    model.setPostSubmitMessage(new ViewMessage("Error_No_more_information"));
                    return false;
                }
            }
        });
        controllerState.registerUiServiceClient(uiSvcClient);
    }
@ Override public void onAfterResolvedView ( NdsFormModel allModel , final ControllerState < ? > controllerState ) { final BeisAllModel model = ( BeisAllModel ) allModel ; final UiData uiData = ( UiData ) model . getUiData ( ) ; final UiServiceClient uiSvcClient = controllerState . getController ( ) . getUiSvcClientFactory ( ) . getInstance ( RegisterPrsExemptionNdsResponse . class ) ; RegisterPrsExemptionNdsRequest registerPrsExemptionNdsRequest = new RegisterPrsExemptionNdsRequest ( ) ; final PlatformUser user = PlatformUser . getLoggedInUser ( ) ; String userName = user . getUsername ( ) ; registerPrsExemptionNdsRequest . setUserName ( userName ) ; registerPrsExemptionNdsRequest . setTenant ( user . getTenant ( ) ) ; RegisterPrsExemptionDetails registerPrsExemptionDetails = new RegisterPrsExemptionDetails ( ) ; ExemptionDetail exemptionDetails = model . getExemptionDetails ( ) ; registerPrsExemptionDetails . setExemptionDetails ( exemptionDetails ) ; registerPrsExemptionNdsRequest . setPwsText ( uiData . getSelectedExemptionTypeText ( ) . getPwsDescription ( ) ) ; registerPrsExemptionNdsRequest . setMaxPenaltyValue ( uiData . getPenaltyValue ( ) ) ; registerPrsExemptionNdsRequest . setRegisterPrsExemptionDetails ( registerPrsExemptionDetails ) ; uiSvcClient . setTimeLimit ( Long . parseLong ( submitPrsExemptionServiceTimeout ) ) ; if ( ! controllerState . isSyncController ( ) ) { uiSvcClient . post ( serviceEndPoint , registerPrsExemptionNdsRequest ) ; } else { uiSvcClient . postSync ( serviceEndPoint , registerPrsExemptionNdsRequest ) ; } uiSvcClient . setResponseConsumer ( new NdsResponseConsumer ( ) { @ Override public boolean consume ( NdsResponse response ) { if ( ! ( response instanceof RegisterPrsExemptionNdsResponse ) ) { model . setPostSubmitMessage ( null ) ; return false ; } RegisterPrsExemptionNdsResponse registerPrsExemptionNdsResponse = ( RegisterPrsExemptionNdsResponse ) ( response ) ; if ( registerPrsExemptionNdsResponse . isSuccess ( ) ) { return true ; } else if ( registerPrsExemptionNdsResponse . getNdsMessages ( ) != null ) { List < ValidationViolation > violations = registerPrsExemptionNdsResponse . getNdsMessages ( ) . getViolations ( ) ; if ( violations != null ) { for ( ValidationViolation validationViolation : violations ) { if ( validationViolation . getMessage ( ) . contains ( "Unable to send e-mail for exemption registration" ) && violations . size ( ) == 1 ) { final Map < String , Object > attributes = controllerState . getAttributes ( ) ; attributes . put ( "fault" , controllerState . getController ( ) . sysErr ( ViewMessage . fromViolations ( violations ) , controllerState ) ) ; return true ; } } } model . setPostSubmitMessage ( new ViewMessage ( "Error_ESB_withCausedBy" , registerPrsExemptionNdsResponse . getNdsMessages ( ) ) ) ; return false ; } else { model . setPostSubmitMessage ( new ViewMessage ( "Error_No_more_information" ) ) ; return false ; } } } ) ; controllerState . registerUiServiceClient ( uiSvcClient ) ; }
submits request to esb to register the exemption
submits request to esb to register the exemption
// get logged in user's details // defer message // construction back // to controller