parent
1e375887e5
commit
2426fb7c7e
@ -1,7 +1,34 @@
|
|||||||
package com.mfsys.aconnect.client.controller;
|
package com.mfsys.aconnect.client.controller;
|
||||||
|
|
||||||
|
import com.mfsys.aconnect.client.dto.WorkflowRequestDTO;
|
||||||
|
import com.mfsys.aconnect.client.service.CRMService;
|
||||||
|
import com.mfsys.common.configuration.constant.AconnectURI;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class CRMController {
|
public class CRMController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CRMService crmService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CRMController(CRMService crmService) {
|
||||||
|
this.crmService = crmService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(AconnectURI.INDIVIDUAL_CRM_CREATION_URI)
|
||||||
|
public Object createIndividualCRM(@RequestBody WorkflowRequestDTO workflowRequestDTO,
|
||||||
|
@RequestHeader("Authorization") String token) {
|
||||||
|
return crmService.createIndividualCRM(workflowRequestDTO, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(AconnectURI.BUSINESS_CRM_CREATION_URI)
|
||||||
|
public Object createBusinessCRM(@RequestBody WorkflowRequestDTO workflowRequestDTO,
|
||||||
|
@RequestHeader("Authorization") String token) {
|
||||||
|
return crmService.createBusinessCRM(workflowRequestDTO, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,39 @@
|
|||||||
|
package com.mfsys.aconnect.client.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WorkflowRequestDTO {
|
||||||
|
|
||||||
|
private String workFlowId;
|
||||||
|
|
||||||
|
@JsonProperty("SUS_USERCODE")
|
||||||
|
private String susUsercode;
|
||||||
|
|
||||||
|
private Map<String, Object> filesMap;
|
||||||
|
private List<AutoIncrementField> autoIncrementFields;
|
||||||
|
private String formId;
|
||||||
|
private String postProcessFormId;
|
||||||
|
private String payload;
|
||||||
|
private String operation;
|
||||||
|
|
||||||
|
@JsonProperty("POR_ORGACODE")
|
||||||
|
private String porOrgacode;
|
||||||
|
|
||||||
|
private List<List<String>> uniqueConstraints;
|
||||||
|
private List<Object> formCounters;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class AutoIncrementField {
|
||||||
|
private String key;
|
||||||
|
private String type;
|
||||||
|
private List<Object> position;
|
||||||
|
private Boolean incrementByCategoryTag;
|
||||||
|
private Boolean incrementIfFlowTerminated;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package com.mfsys.aconnect.client.service;
|
||||||
|
|
||||||
|
import com.mfsys.aconnect.client.dto.WorkflowRequestDTO;
|
||||||
|
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.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CRMService {
|
||||||
|
|
||||||
|
@Value("${app.crm.uri}")
|
||||||
|
private String crmURI;
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate = new RestTemplate();
|
||||||
|
public Object createIndividualCRM(WorkflowRequestDTO workflowRequestDTO, String token) {
|
||||||
|
String porOrgacode = workflowRequestDTO.getPorOrgacode();
|
||||||
|
String url = crmURI + "/crm" + "/mongodb/formdata" ;
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", porOrgacode);
|
||||||
|
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode());
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
HttpEntity<WorkflowRequestDTO> entity = new HttpEntity<>(workflowRequestDTO, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
entity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object createBusinessCRM(WorkflowRequestDTO workflowRequestDTO, String token) {
|
||||||
|
String porOrgacode = workflowRequestDTO.getPorOrgacode();
|
||||||
|
String url = crmURI + "/crm" + "/mongodb/formdata" ;
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", porOrgacode);
|
||||||
|
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode());
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
HttpEntity<WorkflowRequestDTO> entity = new HttpEntity<>(workflowRequestDTO, headers);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
entity,
|
||||||
|
Map.class
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue