| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.common.services;
|
|
|
2 |
|
|
|
3 |
import java.util.Collections;
|
|
|
4 |
import java.util.HashMap;
|
|
|
5 |
import java.util.Map;
|
| 24698 |
amit.gupta |
6 |
import java.util.Set;
|
| 23612 |
amit.gupta |
7 |
|
|
|
8 |
import org.apache.http.HttpResponse;
|
|
|
9 |
import org.apache.http.conn.HttpHostConnectException;
|
| 23651 |
amit.gupta |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24694 |
amit.gupta |
11 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
12 |
import org.springframework.core.io.InputStreamSource;
|
|
|
13 |
import org.springframework.http.HttpEntity;
|
|
|
14 |
import org.springframework.http.HttpHeaders;
|
|
|
15 |
import org.springframework.http.HttpMethod;
|
|
|
16 |
import org.springframework.http.ResponseEntity;
|
| 23612 |
amit.gupta |
17 |
import org.springframework.stereotype.Component;
|
| 24694 |
amit.gupta |
18 |
import org.springframework.web.client.RestTemplate;
|
| 24698 |
amit.gupta |
19 |
import org.springframework.web.util.UriComponentsBuilder;
|
| 23612 |
amit.gupta |
20 |
|
|
|
21 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
22 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
23 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
24 |
|
|
|
25 |
@Component
|
|
|
26 |
public class ReporticoService {
|
|
|
27 |
|
| 23763 |
amit.gupta |
28 |
//private String reporticoUrl="http://192.168.134.118/reports/run.php";
|
|
|
29 |
private String reporticoUrl="http://50.116.10.120/reports/run.php";
|
| 23612 |
amit.gupta |
30 |
|
| 23651 |
amit.gupta |
31 |
@Autowired
|
|
|
32 |
RestClient restClient;
|
|
|
33 |
|
| 24694 |
amit.gupta |
34 |
@Autowired
|
|
|
35 |
RestTemplate restTemplate;
|
|
|
36 |
|
| 23612 |
amit.gupta |
37 |
public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
|
|
|
38 |
new HashMap<ReporticoProject, Map<String, String>>() {
|
|
|
39 |
{
|
|
|
40 |
put(ReporticoProject.FOCO, new HashMap<String, String>() {
|
|
|
41 |
{
|
|
|
42 |
put("project", ReporticoProject.FOCO.getValue());
|
| 26103 |
amit.gupta |
43 |
put("project_password", "sdukaan258");
|
| 23612 |
amit.gupta |
44 |
}
|
|
|
45 |
});
|
| 23637 |
amit.gupta |
46 |
put(ReporticoProject.FOCOR, new HashMap<String, String>() {
|
|
|
47 |
{
|
|
|
48 |
put("project", ReporticoProject.FOCOR.getValue());
|
|
|
49 |
put("project_password", "focor");
|
|
|
50 |
}
|
|
|
51 |
});
|
| 23951 |
amit.gupta |
52 |
put(ReporticoProject.WAREHOUSENEW, new HashMap<String, String>() {
|
|
|
53 |
{
|
|
|
54 |
put("project", ReporticoProject.WAREHOUSENEW.getValue());
|
|
|
55 |
put("project_password", "warehousenew");
|
|
|
56 |
}
|
|
|
57 |
});
|
| 23612 |
amit.gupta |
58 |
}
|
|
|
59 |
});
|
|
|
60 |
|
| 24509 |
amit.gupta |
61 |
|
| 26066 |
amit.gupta |
62 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName)
|
|
|
63 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 23612 |
amit.gupta |
64 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
|
|
65 |
Map<String, String> params = new HashMap<>(authMap);
|
|
|
66 |
params.put("xmlin", reportName);
|
|
|
67 |
params.put("target_format", "CSV");
|
|
|
68 |
params.put("execute_mode", "EXECUTE");
|
|
|
69 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
|
|
70 |
}
|
|
|
71 |
|
| 24694 |
amit.gupta |
72 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
|
|
|
73 |
|
|
|
74 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
|
|
75 |
|
|
|
76 |
Map<String, String> params = new HashMap<>(authMap);
|
|
|
77 |
params.put("xmlin", reportName);
|
|
|
78 |
params.put("target_format", "CSV");
|
|
|
79 |
params.put("execute_mode", "EXECUTE");
|
| 24698 |
amit.gupta |
80 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
|
|
81 |
Set<String> keys = params.keySet();
|
| 24694 |
amit.gupta |
82 |
|
| 24698 |
amit.gupta |
83 |
for(String key : keys){
|
|
|
84 |
builder.queryParam(key, params.get(key));
|
|
|
85 |
}
|
| 24694 |
amit.gupta |
86 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
| 24698 |
amit.gupta |
87 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, requestEntity, byte[].class);
|
| 24694 |
amit.gupta |
88 |
return new ByteArrayResource(responseEntity.getBody());
|
|
|
89 |
|
|
|
90 |
}
|
| 25419 |
amit.gupta |
91 |
|
|
|
92 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
|
|
93 |
|
|
|
94 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
|
|
95 |
|
|
|
96 |
params.putAll(authMap);
|
|
|
97 |
params.put("xmlin", reportName);
|
|
|
98 |
params.put("target_format", "CSV");
|
|
|
99 |
params.put("execute_mode", "EXECUTE");
|
|
|
100 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
|
|
101 |
Set<String> keys = params.keySet();
|
|
|
102 |
|
|
|
103 |
for(String key : keys){
|
|
|
104 |
builder.queryParam(key, params.get(key));
|
|
|
105 |
}
|
|
|
106 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
|
|
107 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, requestEntity, byte[].class);
|
|
|
108 |
return new ByteArrayResource(responseEntity.getBody());
|
|
|
109 |
|
|
|
110 |
}
|
| 24694 |
amit.gupta |
111 |
|
| 23612 |
amit.gupta |
112 |
public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 26066 |
amit.gupta |
113 |
Map<String, String> params = new HashMap<>();
|
|
|
114 |
params.put("MANUAL_fofoId", String.valueOf(fofoId));
|
|
|
115 |
return this.getReportFile(projectName, reportName, params);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
|
|
120 |
if(params==null) {
|
|
|
121 |
params=new HashMap<>();
|
|
|
122 |
}
|
|
|
123 |
params.putAll(projectAuthMap.get(projectName));
|
| 23612 |
amit.gupta |
124 |
params.put("xmlin", reportName);
|
|
|
125 |
params.put("target_format", "CSV");
|
|
|
126 |
params.put("execute_mode", "EXECUTE");
|
|
|
127 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
|
|
128 |
}
|
| 23945 |
amit.gupta |
129 |
|
|
|
130 |
public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
|
|
131 |
|
|
|
132 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
|
|
133 |
|
|
|
134 |
params.putAll(authMap);
|
|
|
135 |
params.put("xmlin", reportName);
|
|
|
136 |
params.put("target_format", "JSON");
|
|
|
137 |
params.put("execute_mode", "EXECUTE");
|
|
|
138 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
|
|
139 |
}
|
| 23612 |
amit.gupta |
140 |
}
|