Updated CRMService from Rest Template to Web Client

WebClient
parent 7300455f96
commit 6a4bd310d9

@ -1,16 +1,11 @@
package com.mfsys.aconnect.client.service;
import com.mfsys.aconnect.client.dto.ApproveCRMRequestDTO;
import com.mfsys.aconnect.client.dto.WorkflowApprovalDTO;
import com.mfsys.aconnect.client.dto.WorkflowRequestDTO;
import com.mfsys.aconnect.configuration.config.WebClientConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@Service
public class CRMService {
@ -18,9 +13,9 @@ public class CRMService {
@Value("${app.crm.uri}")
private String crmURI;
private final RestTemplate restTemplate;
public CRMService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
private final WebClientConfig webClientConfig;
public CRMService(WebClientConfig webClientConfig) {
this.webClientConfig = webClientConfig;
}
public Object createIndividualCRM(WorkflowRequestDTO workflowRequestDTO, String token) {
@ -32,16 +27,12 @@ public class CRMService {
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode());
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<WorkflowRequestDTO> entity = new HttpEntity<>(workflowRequestDTO, headers);
ResponseEntity<Map> response = restTemplate.exchange(
return webClientConfig.post(
url,
HttpMethod.POST,
entity,
Map.class
);
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
workflowRequestDTO,
headers
)
.getBody();
}
public Object createBusinessCRM(WorkflowRequestDTO workflowRequestDTO, String token) {
@ -53,16 +44,12 @@ public class CRMService {
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode());
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<WorkflowRequestDTO> entity = new HttpEntity<>(workflowRequestDTO, headers);
ResponseEntity<Map> response = restTemplate.exchange(
return webClientConfig.post(
url,
HttpMethod.POST,
entity,
Map.class
);
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
workflowRequestDTO,
headers
)
.getBody();
}
public Object approveIndividualCRM(ApproveCRMRequestDTO approveCRMRequestDTO, String token) {
@ -74,16 +61,12 @@ public class CRMService {
headers.set("SUS_USERCODE", approveCRMRequestDTO.getSusUserCode());
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ApproveCRMRequestDTO> entity = new HttpEntity<>(approveCRMRequestDTO, headers);
ResponseEntity<Map> response = restTemplate.exchange(
return webClientConfig.patch(
url,
HttpMethod.PATCH,
entity,
Map.class
);
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
approveCRMRequestDTO,
headers
)
.getBody();
}
public Object approveBusinessCRM(ApproveCRMRequestDTO approveCRMRequestDTO, String token) {
@ -95,16 +78,12 @@ public class CRMService {
headers.set("SUS_USERCODE", approveCRMRequestDTO.getSusUserCode());
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ApproveCRMRequestDTO> entity = new HttpEntity<>(approveCRMRequestDTO, headers);
ResponseEntity<Map> response = restTemplate.exchange(
return webClientConfig.patch(
url,
HttpMethod.PATCH,
entity,
Map.class
);
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
approveCRMRequestDTO,
headers
)
.getBody();
}
}

@ -80,10 +80,10 @@ public class WebClientConfig {
}
}
public ResponseEntity<Object> put(String url, Object body, HttpHeaders headers) {
public ResponseEntity<Object> patch(String url, Object body, HttpHeaders headers) {
try {
return webClient
.put()
.method(org.springframework.http.HttpMethod.PATCH)
.uri(url)
.headers(h -> h.addAll(headers))
.contentType(MediaType.APPLICATION_JSON)

Loading…
Cancel
Save