7373import com .iemr .tm .repo .registrar .ReistrarRepoBenSearch ;
7474import com .iemr .tm .service .benFlowStatus .CommonBenStatusFlowServiceImpl ;
7575import com .iemr .tm .utils .CookieUtil ;
76+ import com .iemr .tm .utils .RestTemplateUtil ;
77+ import com .iemr .tm .utils .UserAgentContext ;
7678import com .iemr .tm .utils .mapper .InputMapper ;
7779import com .iemr .tm .utils .response .OutputResponse ;
7880
@@ -655,41 +657,36 @@ public String registerBeneficiary(String comingRequest, String Authorization) th
655657 OutputResponse response1 = new OutputResponse ();
656658 Long beneficiaryRegID = null ;
657659 Long beneficiaryID = null ;
658-
660+ Map <String , Object > responseMap = new HashMap <>();
661+
659662 RestTemplate restTemplate = new RestTemplate ();
660- HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
661- .getRequest ();
662- String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
663- MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
664- headers .add ("Content-Type" , MediaType .APPLICATION_JSON + ";charset=utf-8" );
665- // headers.add("Content-Type", MediaType.APPLICATION_JSON);
666- headers .add ("AUTHORIZATION" , Authorization );
667- headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
668- HttpEntity <Object > request = new HttpEntity <Object >(comingRequest , headers );
663+ HttpEntity <Object > request = RestTemplateUtil .createRequestEntity (comingRequest , Authorization );
664+ logger .info ("Before Calling Common-API registration : " +request .getHeaders ());
669665 ResponseEntity <String > response = restTemplate .exchange (registrationUrl , HttpMethod .POST , request ,
670666 String .class );
671667 if (response .getStatusCodeValue () == 200 & response .hasBody ()) {
672668 String responseStr = response .getBody ();
673669 JSONObject responseOBJ = new JSONObject (responseStr );
674670 beneficiaryRegID = responseOBJ .getJSONObject ("data" ).getLong ("beneficiaryRegID" );
675671 beneficiaryID = responseOBJ .getJSONObject ("data" ).getLong ("beneficiaryID" );
676- // System.out.println("hello");
672+ responseMap .put ("benGenId" , beneficiaryID );
673+ responseMap .put ("benRegId" , beneficiaryRegID );
677674
678675 BeneficiaryFlowStatus obj = InputMapper .gson ().fromJson (comingRequest , BeneficiaryFlowStatus .class );
679676 if (obj != null && obj .getIsMobile () != null && obj .getIsMobile ()) {
680- response1 .setResponse ("Beneficiary successfully registered. Beneficiary ID is : " + beneficiaryID );
677+ responseMap .put ("response" , "Beneficiary successfully registered. Beneficiary ID is : " + beneficiaryID +" , BenRegID is : " +beneficiaryRegID );
678+ response1 .setResponse (new Gson ().toJson (responseMap ));
679+
681680 } else {
682681 int i = commonBenStatusFlowServiceImpl .createBenFlowRecord (comingRequest , beneficiaryRegID ,
683682 beneficiaryID );
684683
685684 if (i > 0 ) {
686- if ( i == 1 )
687- response1 .setResponse (
688- "Beneficiary successfully registered. Beneficiary ID is : " + beneficiaryID );
685+ responseMap . put ( "response" , "Beneficiary successfully registered. Beneficiary ID is : " + beneficiaryID + " , BenRegID is : " + beneficiaryRegID );
686+ response1 .setResponse (new Gson (). toJson ( responseMap ));
687+
689688 } else {
690689 response1 .setError (5000 , "Error in registration; please contact administrator" );
691- // log error that beneficiaryID generated but flow part is not
692- // done successfully.
693690 }
694691 }
695692 } else {
@@ -702,15 +699,7 @@ public String registerBeneficiary(String comingRequest, String Authorization) th
702699 public Integer updateBeneficiary (String comingRequest , String Authorization ) throws Exception {
703700 Integer returnOBJ = null ;
704701 RestTemplate restTemplate = new RestTemplate ();
705- HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
706- .getRequest ();
707- String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
708- MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
709- // headers.add("Content-Type", "application/json");
710- headers .add ("Content-Type" , MediaType .APPLICATION_JSON + ";charset=utf-8" );
711- headers .add ("AUTHORIZATION" , Authorization );
712- headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
713- HttpEntity <Object > request = new HttpEntity <Object >(comingRequest , headers );
702+ HttpEntity <Object > request = RestTemplateUtil .createRequestEntity (comingRequest , Authorization );
714703 ResponseEntity <String > response = restTemplate .exchange (beneficiaryEditUrl , HttpMethod .POST , request ,
715704 String .class );
716705
@@ -728,26 +717,18 @@ public Integer updateBeneficiary(String comingRequest, String Authorization) thr
728717 public String beneficiaryQuickSearch (String requestObj , String Authorization ) throws JSONException {
729718 String returnOBJ = null ;
730719 RestTemplate restTemplate = new RestTemplate ();
731- HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
732- .getRequest ();
733- String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
734720 JSONObject obj = new JSONObject (requestObj );
735- MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
736- headers .add ("Content-Type" , "application/json" );
737- headers .add ("AUTHORIZATION" , Authorization );
738- headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
721+ HttpEntity <Object > request = RestTemplateUtil .createRequestEntity (requestObj , Authorization );
722+
739723 if ((obj .has ("beneficiaryID" ) && !obj .isNull ("beneficiaryID" ))
740724 || (obj .has ("HealthID" ) && !obj .isNull ("HealthID" ))
741725 || (obj .has ("HealthIDNumber" ) && !obj .isNull ("HealthIDNumber" ))) {
742- HttpEntity <Object > request = new HttpEntity <Object >(requestObj , headers );
743726 ResponseEntity <String > response = restTemplate .exchange (registrarQuickSearchByIdUrl , HttpMethod .POST ,
744727 request , String .class );
745728 if (response .hasBody ())
746729 returnOBJ = response .getBody ();
747-
748730 } else {
749731 if (obj .has ("phoneNo" ) && !obj .isNull ("phoneNo" )) {
750- HttpEntity <Object > request = new HttpEntity <Object >(requestObj , headers );
751732 ResponseEntity <String > response = restTemplate .exchange (registrarQuickSearchByPhoneNoUrl ,
752733 HttpMethod .POST , request , String .class );
753734 if (response .hasBody ())
@@ -762,15 +743,7 @@ public String beneficiaryQuickSearch(String requestObj, String Authorization) th
762743 public String beneficiaryAdvanceSearch (String requestObj , String Authorization ) throws JSONException {
763744 String returnOBJ = null ;
764745 RestTemplate restTemplate = new RestTemplate ();
765- HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
766- .getRequest ();
767- String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
768- JSONObject obj = new JSONObject (requestObj );
769- MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
770- headers .add ("Content-Type" , "application/json" );
771- headers .add ("AUTHORIZATION" , Authorization );
772- headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
773- HttpEntity <Object > request = new HttpEntity <Object >(requestObj , headers );
746+ HttpEntity <Object > request = RestTemplateUtil .createRequestEntity (requestObj , Authorization );
774747 ResponseEntity <String > response = restTemplate .exchange (registrarAdvanceSearchUrl , HttpMethod .POST , request ,
775748 String .class );
776749
0 commit comments