|
32 | 32 | import java.util.List; |
33 | 33 | import java.util.Map; |
34 | 34 | import java.util.Set; |
| 35 | +import org.springframework.web.context.request.RequestContextHolder; |
| 36 | +import org.springframework.web.context.request.ServletRequestAttributes; |
35 | 37 |
|
36 | 38 | import javax.crypto.SecretKeyFactory; |
37 | 39 | import javax.crypto.spec.PBEKeySpec; |
|
42 | 44 | import org.slf4j.Logger; |
43 | 45 | import org.slf4j.LoggerFactory; |
44 | 46 | import org.springframework.beans.factory.annotation.Autowired; |
| 47 | +import org.springframework.http.HttpEntity; |
| 48 | +import org.springframework.http.HttpMethod; |
| 49 | +import org.springframework.http.ResponseEntity; |
45 | 50 | import org.springframework.jdbc.core.JdbcTemplate; |
46 | 51 | import org.springframework.scheduling.annotation.Async; |
47 | 52 | import org.springframework.stereotype.Service; |
| 53 | +import org.springframework.util.LinkedMultiValueMap; |
| 54 | +import org.springframework.util.MultiValueMap; |
| 55 | +import org.springframework.web.client.RestTemplate; |
48 | 56 |
|
| 57 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 58 | +import com.fasterxml.jackson.databind.JsonMappingException; |
| 59 | +import com.fasterxml.jackson.databind.ObjectMapper; |
49 | 60 | import com.google.gson.JsonParser; |
50 | 61 | import com.iemr.admin.data.blocking.M_Providerservicemapping_Blocking; |
51 | 62 | import com.iemr.admin.data.employeemaster.M_Community; |
|
85 | 96 | import com.iemr.admin.repository.provideronboard.M_ServiceMasterRepo; |
86 | 97 | import com.iemr.admin.repository.rolemaster.M_UserservicerolemappingForRoleProviderAdminRepo; |
87 | 98 | import com.iemr.admin.service.user.EncryptUserPassword; |
| 99 | +import com.iemr.admin.utils.CookieUtil; |
88 | 100 | import com.iemr.admin.utils.config.ConfigProperties; |
89 | 101 | import com.iemr.admin.utils.exception.IEMRException; |
90 | 102 | import com.iemr.admin.utils.http.HttpUtils; |
91 | 103 | import com.iemr.admin.utils.mapper.InputMapper; |
92 | 104 | import com.iemr.admin.utils.response.OutputResponse; |
93 | 105 |
|
| 106 | +import jakarta.servlet.http.HttpServletRequest; |
| 107 | + |
94 | 108 | @Service |
95 | 109 | public class EmployeeMasterServiceImpl implements EmployeeMasterInter { |
96 | 110 |
|
@@ -124,6 +138,8 @@ public class EmployeeMasterServiceImpl implements EmployeeMasterInter { |
124 | 138 |
|
125 | 139 | @Autowired |
126 | 140 | private EncryptUserPassword encryptUserPassword; |
| 141 | + @Autowired |
| 142 | + private CookieUtil cookieUtil; |
127 | 143 | private InputMapper inputMapper = new InputMapper(); |
128 | 144 | private Logger logger = LoggerFactory.getLogger(EmployeeMasterServiceImpl.class); |
129 | 145 |
|
@@ -305,7 +321,7 @@ public ArrayList<M_UserLangMapping> mapLanguage(List<M_UserLangMapping> resList) |
305 | 321 | } |
306 | 322 |
|
307 | 323 | @Override |
308 | | - public ArrayList<M_UserServiceRoleMapping2> mapRole(List<M_UserServiceRoleMapping2> resList1, String authToken) { |
| 324 | + public ArrayList<M_UserServiceRoleMapping2> mapRole(List<M_UserServiceRoleMapping2> resList1, String authToken) throws JsonMappingException, JsonProcessingException { |
309 | 325 | ArrayList<M_UserServiceRoleMapping2> reslist = (ArrayList<M_UserServiceRoleMapping2>) employeeMasterRepo |
310 | 326 | .saveAll(resList1); |
311 | 327 | if (ENABLE_CTI_USER_CREATION) { |
@@ -375,7 +391,7 @@ public boolean equals(Object obj) { |
375 | 391 | } |
376 | 392 |
|
377 | 393 | @Async |
378 | | - private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1, String authToken) { |
| 394 | + private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1, String authToken) throws JsonMappingException, JsonProcessingException { |
379 | 395 | Map<Integer, UserServiceLine> userServiceLineMap = new HashMap<Integer, UserServiceLine>(); |
380 | 396 | Set<Integer> providerMapIds = new HashSet<Integer>(); |
381 | 397 | for (M_UserServiceRoleMapping2 userRole : resList1) { |
@@ -443,25 +459,31 @@ private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1, |
443 | 459 | } |
444 | 460 | } |
445 | 461 |
|
446 | | - private Set<String> getCTICampaignRoles(String campaignName, String authToken) { |
| 462 | + private Set<String> getCTICampaignRoles(String campaignName, String authToken) throws JsonMappingException, JsonProcessingException { |
| 463 | + RestTemplate restTemplate = new RestTemplate(); |
| 464 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 465 | + HttpServletRequest requestHeader = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) |
| 466 | + .getRequest(); |
| 467 | + String jwtTokenFromCookie = cookieUtil.getJwtTokenFromCookie(requestHeader); |
447 | 468 | Set<String> resultSet = new HashSet<String>(); |
448 | | - HttpUtils httpUtils = new HttpUtils(); |
449 | | - HashMap<String, Object> headers = new HashMap<String, Object>(); |
450 | | - headers.put("Authorization", authToken); |
451 | | - String getRolesURL = configProperties.getPropertyByName("common-url") |
452 | | - + configProperties.getPropertyByName("campaign-roles-url"); |
453 | | - JSONObject request = new JSONObject(); |
454 | | - request.put("campaign", campaignName); |
455 | | - |
456 | | - OutputResponse response = inputMapper.gson().fromJson(httpUtils.post(getRolesURL, request.toString(), headers), |
457 | | - OutputResponse.class); |
| 469 | + MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>(); |
| 470 | + headers.add("Content-Type", "application/json"); |
| 471 | + headers.add("AUTHORIZATION", authToken); |
| 472 | + headers.add("Jwttoken", jwtTokenFromCookie); |
| 473 | + String url = configProperties.getPropertyByName("common-url") + configProperties.getPropertyByName("create-feedback"); |
| 474 | + HttpEntity<Object> request1 = new HttpEntity<Object>(campaignName, headers); |
| 475 | + ResponseEntity<String> responseStr = restTemplate.exchange(url, HttpMethod.POST, request1, String.class); |
| 476 | + OutputResponse response = objectMapper.readValue(responseStr.getBody(), OutputResponse.class); |
458 | 477 | if (response.isSuccess()) { |
459 | 478 | JSONObject obj = new JSONObject(response.getData()); |
460 | 479 | JSONArray roles = obj.getJSONArray("roles"); |
461 | 480 | for (int roleIndex = 0; roleIndex < roles.length(); roleIndex++) { |
462 | 481 | resultSet.add(roles.getString(roleIndex)); |
463 | 482 | } |
464 | 483 | } |
| 484 | +// JSONObject request = new JSONObject(); |
| 485 | +// request.put("campaign", campaignName); |
| 486 | + |
465 | 487 | return resultSet; |
466 | 488 | } |
467 | 489 |
|
@@ -906,7 +928,7 @@ public M_UserServiceRoleMapping2 getDataUsrId(Integer uSRMappingID) { |
906 | 928 | } |
907 | 929 |
|
908 | 930 | @Override |
909 | | - public M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String authToken) { |
| 931 | + public M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String authToken) throws JsonMappingException, JsonProcessingException { |
910 | 932 |
|
911 | 933 | M_UserServiceRoleMapping2 data = employeeMasterRepo.save(usrRole); |
912 | 934 | if (ENABLE_CTI_USER_CREATION) { |
|
0 commit comments