Skip to content

Commit 19cdc37

Browse files
indraniBanIN40068837
andauthored
401 unauthorized issue resolved (#68)
Co-authored-by: IN40068837 <[email protected]>
1 parent 7176dcb commit 19cdc37

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterInter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.ArrayList;
2525
import java.util.List;
2626

27+
import com.fasterxml.jackson.core.JsonProcessingException;
28+
import com.fasterxml.jackson.databind.JsonMappingException;
2729
import com.iemr.admin.data.employeemaster.M_Community;
2830
import com.iemr.admin.data.employeemaster.M_Gender;
2931
import com.iemr.admin.data.employeemaster.M_ProviderServiceMap1;
@@ -60,7 +62,8 @@ public interface EmployeeMasterInter {
6062

6163
ArrayList<M_UserLangMapping> mapLanguage(List<M_UserLangMapping> resList);
6264

63-
ArrayList<M_UserServiceRoleMapping2> mapRole(List<M_UserServiceRoleMapping2> resList1, String authToken);
65+
// ArrayList<M_UserServiceRoleMapping2> mapRole(List<M_UserServiceRoleMapping2> resList1, String authToken);
66+
public ArrayList<M_UserServiceRoleMapping2> mapRole(List<M_UserServiceRoleMapping2> resList1, String authToken) throws JsonMappingException, JsonProcessingException;
6467

6568
M_UserDemographics mdedit(Integer userID);
6669

@@ -154,7 +157,8 @@ Boolean checkingEmpDetails(String userName, String aadhaarNo, String getpAN, Str
154157

155158
M_UserServiceRoleMapping2 getDataUsrId(Integer uSRMappingID);
156159

157-
M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String string);
160+
// M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String string);
161+
public M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String authToken) throws JsonMappingException, JsonProcessingException;
158162

159163
// ArrayList<M_UserLangMapping> getMappedLanguge();
160164

src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterServiceImpl.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.List;
3333
import java.util.Map;
3434
import java.util.Set;
35+
import org.springframework.web.context.request.RequestContextHolder;
36+
import org.springframework.web.context.request.ServletRequestAttributes;
3537

3638
import javax.crypto.SecretKeyFactory;
3739
import javax.crypto.spec.PBEKeySpec;
@@ -42,10 +44,19 @@
4244
import org.slf4j.Logger;
4345
import org.slf4j.LoggerFactory;
4446
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;
4550
import org.springframework.jdbc.core.JdbcTemplate;
4651
import org.springframework.scheduling.annotation.Async;
4752
import org.springframework.stereotype.Service;
53+
import org.springframework.util.LinkedMultiValueMap;
54+
import org.springframework.util.MultiValueMap;
55+
import org.springframework.web.client.RestTemplate;
4856

57+
import com.fasterxml.jackson.core.JsonProcessingException;
58+
import com.fasterxml.jackson.databind.JsonMappingException;
59+
import com.fasterxml.jackson.databind.ObjectMapper;
4960
import com.google.gson.JsonParser;
5061
import com.iemr.admin.data.blocking.M_Providerservicemapping_Blocking;
5162
import com.iemr.admin.data.employeemaster.M_Community;
@@ -85,12 +96,15 @@
8596
import com.iemr.admin.repository.provideronboard.M_ServiceMasterRepo;
8697
import com.iemr.admin.repository.rolemaster.M_UserservicerolemappingForRoleProviderAdminRepo;
8798
import com.iemr.admin.service.user.EncryptUserPassword;
99+
import com.iemr.admin.utils.CookieUtil;
88100
import com.iemr.admin.utils.config.ConfigProperties;
89101
import com.iemr.admin.utils.exception.IEMRException;
90102
import com.iemr.admin.utils.http.HttpUtils;
91103
import com.iemr.admin.utils.mapper.InputMapper;
92104
import com.iemr.admin.utils.response.OutputResponse;
93105

106+
import jakarta.servlet.http.HttpServletRequest;
107+
94108
@Service
95109
public class EmployeeMasterServiceImpl implements EmployeeMasterInter {
96110

@@ -124,6 +138,8 @@ public class EmployeeMasterServiceImpl implements EmployeeMasterInter {
124138

125139
@Autowired
126140
private EncryptUserPassword encryptUserPassword;
141+
@Autowired
142+
private CookieUtil cookieUtil;
127143
private InputMapper inputMapper = new InputMapper();
128144
private Logger logger = LoggerFactory.getLogger(EmployeeMasterServiceImpl.class);
129145

@@ -305,7 +321,7 @@ public ArrayList<M_UserLangMapping> mapLanguage(List<M_UserLangMapping> resList)
305321
}
306322

307323
@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 {
309325
ArrayList<M_UserServiceRoleMapping2> reslist = (ArrayList<M_UserServiceRoleMapping2>) employeeMasterRepo
310326
.saveAll(resList1);
311327
if (ENABLE_CTI_USER_CREATION) {
@@ -375,7 +391,7 @@ public boolean equals(Object obj) {
375391
}
376392

377393
@Async
378-
private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1, String authToken) {
394+
private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1, String authToken) throws JsonMappingException, JsonProcessingException {
379395
Map<Integer, UserServiceLine> userServiceLineMap = new HashMap<Integer, UserServiceLine>();
380396
Set<Integer> providerMapIds = new HashSet<Integer>();
381397
for (M_UserServiceRoleMapping2 userRole : resList1) {
@@ -443,25 +459,31 @@ private void updateSupervisorRoleInCTI(List<M_UserServiceRoleMapping2> resList1,
443459
}
444460
}
445461

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);
447468
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);
458477
if (response.isSuccess()) {
459478
JSONObject obj = new JSONObject(response.getData());
460479
JSONArray roles = obj.getJSONArray("roles");
461480
for (int roleIndex = 0; roleIndex < roles.length(); roleIndex++) {
462481
resultSet.add(roles.getString(roleIndex));
463482
}
464483
}
484+
// JSONObject request = new JSONObject();
485+
// request.put("campaign", campaignName);
486+
465487
return resultSet;
466488
}
467489

@@ -906,7 +928,7 @@ public M_UserServiceRoleMapping2 getDataUsrId(Integer uSRMappingID) {
906928
}
907929

908930
@Override
909-
public M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String authToken) {
931+
public M_UserServiceRoleMapping2 saveRoleMappingeditedData(M_UserServiceRoleMapping2 usrRole, String authToken) throws JsonMappingException, JsonProcessingException {
910932

911933
M_UserServiceRoleMapping2 data = employeeMasterRepo.save(usrRole);
912934
if (ENABLE_CTI_USER_CREATION) {

0 commit comments

Comments
 (0)