Merge pull request 'Document Upload' (#13) from Wasi/BS-2343 into dev-pending-20-01-2026
Reviewed-on: https://ct.mfsys.com.pk/aConnect/aConnect-BS/pulls/13osho-marka
commit
1e167e936d
@ -0,0 +1,36 @@
|
|||||||
|
package com.mfsys.aconnect.client.controller;
|
||||||
|
|
||||||
|
import com.mfsys.aconnect.client.service.UploadDocumentService;
|
||||||
|
import com.mfsys.common.configuration.constant.AconnectURI;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UploadDocumentController {
|
||||||
|
|
||||||
|
private final UploadDocumentService uploadDocumentService;
|
||||||
|
|
||||||
|
public UploadDocumentController(UploadDocumentService uploadDocumentService){
|
||||||
|
this.uploadDocumentService = uploadDocumentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = AconnectURI.DEPOSIT_DOCUMENT_UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public ResponseEntity<Map<String, String>> uploadDepositDocuments(@RequestParam("file") List<MultipartFile> files,
|
||||||
|
@RequestHeader("POR_ORGACODE") String porOrgacode, @RequestHeader("Authorization") String token,
|
||||||
|
@RequestHeader("SUS_USERCODE") String susUserCode) {
|
||||||
|
return uploadDocumentService.depositCacheFiles(files, porOrgacode, susUserCode, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = AconnectURI.CRM_DOCUMENT_UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public ResponseEntity<Map<String, String>> uploadCRMDocuments(@RequestParam("file") List<MultipartFile> files,
|
||||||
|
@RequestHeader("POR_ORGACODE") String porOrgacode, @RequestHeader("Authorization") String token,
|
||||||
|
@RequestHeader("SUS_USERCODE") String susUserCode) {
|
||||||
|
return uploadDocumentService.crmCacheFiles(files, porOrgacode, susUserCode, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package com.mfsys.aconnect.client.service;
|
||||||
|
|
||||||
|
import org.springframework.util.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UploadDocumentService {
|
||||||
|
|
||||||
|
@Value("${app.deposit.uri}")
|
||||||
|
private String depositURI;
|
||||||
|
|
||||||
|
@Value("${app.crm.uri}")
|
||||||
|
private String crmURI;
|
||||||
|
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
public UploadDocumentService(RestTemplate restTemplate){
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseEntity<Map<String, String>> depositCacheFiles(
|
||||||
|
List<MultipartFile> files, String porOrgacode, String susUserCode, String token) {
|
||||||
|
|
||||||
|
String url = depositURI + "/deposit" + "/mongodb/cacheFiles";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", porOrgacode);
|
||||||
|
headers.set("SUS_USERCODE", susUserCode);
|
||||||
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
|
body.add("POR_ORGACODE", porOrgacode);
|
||||||
|
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
body.add("file", file.getResource());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
return restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
new ParameterizedTypeReference<Map<String, String>>() {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseEntity<Map<String, String>> crmCacheFiles(
|
||||||
|
List<MultipartFile> files, String porOrgacode, String susUserCode, String token) {
|
||||||
|
|
||||||
|
String url = crmURI + "/crm" + "/mongodb/cacheFiles";
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Authorization", token);
|
||||||
|
headers.set("POR_ORGACODE", porOrgacode);
|
||||||
|
headers.set("SUS_USERCODE", susUserCode);
|
||||||
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
|
||||||
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
|
body.add("POR_ORGACODE", porOrgacode);
|
||||||
|
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
body.add("file", file.getResource());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
|
return restTemplate.exchange(
|
||||||
|
url,
|
||||||
|
HttpMethod.POST,
|
||||||
|
requestEntity,
|
||||||
|
new ParameterizedTypeReference<Map<String, String>>() {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue