Fetch pending CRM applications
#8
Merged
naeem.ullah
merged 1 commits from Wasi/BS-2194 into dev-pending-20-01-2026 2 weeks ago
@ -0,0 +1,32 @@
|
|||||||
|
package com.mfsys.aconnect.client.controller;
|
||||||
|
|
||||||
|
import com.mfsys.aconnect.client.dto.InProcessApplicationsRequestDTO;
|
||||||
|
import com.mfsys.aconnect.client.service.InProcessApplicationsService;
|
||||||
|
import com.mfsys.common.configuration.constant.AconnectURI;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class InProcessApplicationsController {
|
||||||
|
|
||||||
|
private final InProcessApplicationsService service;
|
||||||
|
|
||||||
|
public InProcessApplicationsController(
|
||||||
|
InProcessApplicationsService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(AconnectURI.CHECK_PENDING_APPLICATIONS_URI)
|
||||||
|
public ResponseEntity<String> getInProcessApplications(@RequestBody InProcessApplicationsRequestDTO request,
|
||||||
|
@RequestHeader("Authorization") String token, @RequestHeader("SUS_USERCODE") String susUserCode) {
|
||||||
|
return service.getInProcessApplications(request, token, susUserCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(AconnectURI.CHECK_INDIVIDUAL_APPLICATIONS_URI)
|
||||||
|
public ResponseEntity<String>getIndividualApplication(
|
||||||
|
@RequestParam("POR_ORGACODE") String porOrgacode,@RequestParam("formId") String formId,
|
||||||
|
@RequestParam(value = "includeFields", required = false) String includeFields,
|
||||||
|
@RequestHeader("Authorization") String token, @RequestHeader("SUS_USERCODE") String susUserCode){
|
||||||
|
return service.getPendingIndividualApplication(porOrgacode, formId, includeFields, token, susUserCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package com.mfsys.aconnect.client.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InProcessApplicationsRequestDTO {
|
||||||
|
|
||||||
|
private String porOrgacode;
|
||||||
|
private String plclocacode;
|
||||||
|
private Integer limit;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean includeRegistrationPending = true;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private boolean includeAuthorizationApproved = true;
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.mfsys.aconnect.client.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LazyListRequestDTO {
|
||||||
|
|
||||||
|
private String collection;
|
||||||
|
private Object filter;
|
||||||
|
private String sortBy;
|
||||||
|
private Integer limit;
|
||||||
|
private List<String> includeFields;
|
||||||
|
}
|
||||||
@ -0,0 +1,160 @@
|
|||||||
|
package com.mfsys.aconnect.client.service;
|
||||||
|
|
||||||
|
import com.mfsys.aconnect.client.dto.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class InProcessApplicationsService {
|
||||||
|
|
||||||
|
@Value("${app.crm.uri}")
|
||||||
|
private String crmURI;
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public InProcessApplicationsService(RestTemplate restTemplate) {
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> param(String columnName, Object columnValue, String columnType, String conditionType) {
|
||||||
|
return Map.of("columnName", columnName, "columnValue", columnValue,
|
||||||
|
"columnType", columnType, "conditionType", conditionType
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> buildWorkflowFilter(InProcessApplicationsRequestDTO req) {
|
||||||
|
List<Object> workflowQueries = new ArrayList<>();
|
||||||
|
|
||||||
|
if (req.isIncludeRegistrationPending()) {
|
||||||
|
workflowQueries.add(Map.of(
|
||||||
|
"params", List.of(
|
||||||
|
param("workFlowStage", "BN_WF_CP_REGISTRATION", "text", "="),
|
||||||
|
param("applicationStatus", "Pending", "text", "=")
|
||||||
|
),
|
||||||
|
"operator", "$and"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (req.isIncludeAuthorizationApproved()) {
|
||||||
|
workflowQueries.add(Map.of(
|
||||||
|
"params", List.of(
|
||||||
|
param("workFlowStage", "BN_WF_CP_AUTHORIZATION", "text", "="),
|
||||||
|
param("applicationStatus", "Approved", "text", "="),
|
||||||
|
param("postProcessCompleted", true, "boolean", "!=")
|
||||||
|
),
|
||||||
|
"operator", "$and"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
workflowQueries.add(Map.of(
|
||||||
|
"params", List.of(
|
||||||
|
param("workFlowStage", "BN_WF_CP_REGISTRATION", "text", "="),
|
||||||
|
param("applicationStatus", "[\"Rejected\",\"Hold\"]", "text", "in")
|
||||||
|
),
|
||||||
|
"operator", "$and"
|
||||||
|
));
|
||||||
|
return Map.of(
|
||||||
|
"nestedQuery", workflowQueries,
|
||||||
|
"operator", "$or"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LazyListRequestDTO buildLazyListPayload(InProcessApplicationsRequestDTO req) {
|
||||||
|
|
||||||
|
List<Object> rootQueries = new ArrayList<>();
|
||||||
|
|
||||||
|
rootQueries.add(Map.of(
|
||||||
|
"params", List.of(
|
||||||
|
param("POR_ORGACODE", req.getPorOrgacode(), "text", "="),
|
||||||
|
param("POR_ORGACODE_ENTRY", req.getPorOrgacode(), "text", "=")
|
||||||
|
),
|
||||||
|
"operator", "$or"
|
||||||
|
));
|
||||||
|
|
||||||
|
rootQueries.add(Map.of(
|
||||||
|
"params", List.of(
|
||||||
|
param("PLC_LOCACODE", "[\"" + req.getPlclocacode() + "\"]", "text", "in"),
|
||||||
|
param("PLC_LOCACODE_ENTRY", "[\"" + req.getPlclocacode() + "\"]", "text", "in")
|
||||||
|
),
|
||||||
|
"operator", "$or"
|
||||||
|
));
|
||||||
|
|
||||||
|
rootQueries.add(buildWorkflowFilter(req));
|
||||||
|
|
||||||
|
LazyListRequestDTO dto = new LazyListRequestDTO();
|
||||||
|
dto.setCollection("BN_WF_CP_CUSTOMERPROFILE");
|
||||||
|
dto.setFilter(Map.of(
|
||||||
|
"nestedQuery", rootQueries,
|
||||||
|
"operator", "$and"
|
||||||
|
));
|
||||||
|
if (req.getLimit() != null) {
|
||||||
|
dto.setLimit(req.getLimit());
|
||||||
|
}
|
||||||
|
dto.setSortBy("{\"workFlowRefNum\":-1}");
|
||||||
|
dto.setIncludeFields(List.of(
|
||||||
|
"CMP_CUSTCODE", "CMP_FIRSTNAME", "CMP_LASTNAME", "PLC_LOCACODE", "workFlowRefNum",
|
||||||
|
"applicationStatus", "workFlowStage", "workFlowLog", "postProcessCompleted", "failureCause",
|
||||||
|
"postProcessInProgress"
|
||||||
|
));
|
||||||
|
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseEntity<String> getInProcessApplications(
|
||||||
|
InProcessApplicationsRequestDTO request, String token, String susUserCode) {
|
||||||
|
|
||||||
|
String url = crmURI + "/crm" + "/mongodb/lazylist";
|
||||||
|
|
||||||
|
LazyListRequestDTO payload = buildLazyListPayload(request);
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", request.getPorOrgacode());
|
||||||
|
headers.set("SUS_USERCODE", susUserCode);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
HttpEntity<LazyListRequestDTO> entity = new HttpEntity<>(payload, headers);
|
||||||
|
|
||||||
|
return restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
entity,
|
||||||
|
String.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseEntity<String> getPendingIndividualApplication(
|
||||||
|
String porOrgacode, String formId, String includeFields, String token, String susUserCode) {
|
||||||
|
|
||||||
|
String url = crmURI + "/crm" + "/mongodb/metadata";
|
||||||
|
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
|
||||||
|
.queryParam("POR_ORGACODE", porOrgacode).queryParam("formId", formId);
|
||||||
|
|
||||||
|
if (includeFields != null && !includeFields.isBlank()) {
|
||||||
|
builder.queryParam("includeFields", includeFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", porOrgacode);
|
||||||
|
headers.set("SUS_USERCODE", susUserCode);
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
|
|
||||||
|
HttpEntity<Void> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
return restTemplate.exchange(
|
||||||
|
builder.toUriString(),
|
||||||
|
HttpMethod.GET,
|
||||||
|
entity,
|
||||||
|
String.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue