| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.services;
|
1 |
package com.spice.profitmandi.common.services;
|
| 2 |
|
2 |
|
| 3 |
import java.util.Collections;
|
3 |
import java.util.Collections;
|
| 4 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| - |
|
5 |
import java.util.List;
|
| 5 |
import java.util.Map;
|
6 |
import java.util.Map;
|
| 6 |
import java.util.Set;
|
7 |
import java.util.Set;
|
| 7 |
|
8 |
|
| 8 |
import org.apache.http.HttpResponse;
|
9 |
import org.apache.http.HttpResponse;
|
| 9 |
import org.apache.http.conn.HttpHostConnectException;
|
10 |
import org.apache.http.conn.HttpHostConnectException;
|
| Line 17... |
Line 18... |
| 17 |
import org.springframework.http.ResponseEntity;
|
18 |
import org.springframework.http.ResponseEntity;
|
| 18 |
import org.springframework.stereotype.Component;
|
19 |
import org.springframework.stereotype.Component;
|
| 19 |
import org.springframework.web.client.RestTemplate;
|
20 |
import org.springframework.web.client.RestTemplate;
|
| 20 |
import org.springframework.web.util.UriComponentsBuilder;
|
21 |
import org.springframework.web.util.UriComponentsBuilder;
|
| 21 |
|
22 |
|
| - |
|
23 |
import com.fasterxml.jackson.databind.JavaType;
|
| - |
|
24 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| - |
|
25 |
import com.fasterxml.jackson.databind.ObjectReader;
|
| 22 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
26 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
27 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
28 |
import com.spice.profitmandi.common.model.ReporticoResponseModel;
|
| 24 |
import com.spice.profitmandi.common.web.client.RestClient;
|
29 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 25 |
|
30 |
|
| 26 |
@Component
|
31 |
@Component
|
| 27 |
public class ReporticoService {
|
32 |
public class ReporticoService {
|
| 28 |
|
33 |
|
| 29 |
//private String reporticoUrl="http://192.168.134.118/reports/run.php";
|
34 |
// private String reporticoUrl="http://192.168.134.118/reports/run.php";
|
| 30 |
@Value("${reportico.url}")
|
35 |
@Value("${reportico.url}")
|
| 31 |
private String reporticoUrl;
|
36 |
private String reporticoUrl;
|
| 32 |
|
37 |
|
| 33 |
@Autowired
|
38 |
@Autowired
|
| 34 |
RestClient restClient;
|
39 |
RestClient restClient;
|
| - |
|
40 |
|
| - |
|
41 |
@Autowired
|
| - |
|
42 |
private ObjectMapper objectMapper;
|
| 35 |
|
43 |
|
| 36 |
@Autowired
|
44 |
@Autowired
|
| 37 |
RestTemplate restTemplate;
|
45 |
RestTemplate restTemplate;
|
| 38 |
|
46 |
|
| 39 |
public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
|
47 |
public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections
|
| 40 |
new HashMap<ReporticoProject, Map<String, String>>() {
|
48 |
.unmodifiableMap(new HashMap<ReporticoProject, Map<String, String>>() {
|
| 41 |
{
|
49 |
{
|
| 42 |
put(ReporticoProject.FOCO, new HashMap<String, String>() {
|
50 |
put(ReporticoProject.FOCO, new HashMap<String, String>() {
|
| 43 |
{
|
51 |
{
|
| 44 |
put("project", ReporticoProject.FOCO.getValue());
|
52 |
put("project", ReporticoProject.FOCO.getValue());
|
| 45 |
put("project_password", "rBRTJYXlTZ");
|
53 |
put("project_password", "rBRTJYXlTZ");
|
| Line 57... |
Line 65... |
| 57 |
put("project_password", "warehousenew");
|
65 |
put("project_password", "warehousenew");
|
| 58 |
}
|
66 |
}
|
| 59 |
});
|
67 |
});
|
| 60 |
}
|
68 |
}
|
| 61 |
});
|
69 |
});
|
| 62 |
|
- |
|
| 63 |
|
70 |
|
| 64 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName)
|
71 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName)
|
| 65 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
72 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 66 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
73 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 67 |
Map<String, String> params = new HashMap<>(authMap);
|
74 |
Map<String, String> params = new HashMap<>(authMap);
|
| 68 |
params.put("xmlin", reportName);
|
75 |
params.put("xmlin", reportName);
|
| 69 |
params.put("target_format", "CSV");
|
76 |
params.put("target_format", "CSV");
|
| 70 |
params.put("execute_mode", "EXECUTE");
|
77 |
params.put("execute_mode", "EXECUTE");
|
| 71 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
78 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
| 72 |
}
|
79 |
}
|
| 73 |
|
80 |
|
| 74 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
|
81 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName)
|
| - |
|
82 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 75 |
|
83 |
|
| 76 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
84 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 77 |
|
85 |
|
| 78 |
Map<String, String> params = new HashMap<>(authMap);
|
86 |
Map<String, String> params = new HashMap<>(authMap);
|
| 79 |
params.put("xmlin", reportName);
|
87 |
params.put("xmlin", reportName);
|
| 80 |
params.put("target_format", "CSV");
|
88 |
params.put("target_format", "CSV");
|
| 81 |
params.put("execute_mode", "EXECUTE");
|
89 |
params.put("execute_mode", "EXECUTE");
|
| 82 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
90 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
| 83 |
Set<String> keys = params.keySet();
|
91 |
Set<String> keys = params.keySet();
|
| 84 |
|
92 |
|
| 85 |
for(String key : keys){
|
93 |
for (String key : keys) {
|
| 86 |
builder.queryParam(key, params.get(key));
|
94 |
builder.queryParam(key, params.get(key));
|
| 87 |
}
|
95 |
}
|
| 88 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
96 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
| 89 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, requestEntity, byte[].class);
|
97 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
|
| - |
|
98 |
requestEntity, byte[].class);
|
| 90 |
return new ByteArrayResource(responseEntity.getBody());
|
99 |
return new ByteArrayResource(responseEntity.getBody());
|
| 91 |
|
100 |
|
| 92 |
}
|
101 |
}
|
| 93 |
|
102 |
|
| 94 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
103 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName,
|
| - |
|
104 |
Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 95 |
|
105 |
|
| 96 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
106 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 97 |
|
107 |
|
| 98 |
params.putAll(authMap);
|
108 |
params.putAll(authMap);
|
| 99 |
params.put("xmlin", reportName);
|
109 |
params.put("xmlin", reportName);
|
| 100 |
params.put("target_format", "CSV");
|
110 |
params.put("target_format", "CSV");
|
| 101 |
params.put("execute_mode", "EXECUTE");
|
111 |
params.put("execute_mode", "EXECUTE");
|
| 102 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
112 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
| 103 |
Set<String> keys = params.keySet();
|
113 |
Set<String> keys = params.keySet();
|
| 104 |
|
114 |
|
| 105 |
for(String key : keys){
|
115 |
for (String key : keys) {
|
| 106 |
builder.queryParam(key, params.get(key));
|
116 |
builder.queryParam(key, params.get(key));
|
| 107 |
}
|
117 |
}
|
| 108 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
118 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
| 109 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, requestEntity, byte[].class);
|
119 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
|
| - |
|
120 |
requestEntity, byte[].class);
|
| 110 |
return new ByteArrayResource(responseEntity.getBody());
|
121 |
return new ByteArrayResource(responseEntity.getBody());
|
| 111 |
|
122 |
|
| 112 |
}
|
123 |
}
|
| 113 |
|
124 |
|
| 114 |
public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
|
125 |
public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName)
|
| - |
|
126 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 115 |
Map<String, String> params = new HashMap<>();
|
127 |
Map<String, String> params = new HashMap<>();
|
| 116 |
params.put("MANUAL_fofoId", String.valueOf(fofoId));
|
128 |
params.put("MANUAL_fofoId", String.valueOf(fofoId));
|
| 117 |
return this.getReportFile(projectName, reportName, params);
|
129 |
return this.getReportFile(projectName, reportName, params);
|
| 118 |
}
|
130 |
}
|
| 119 |
|
131 |
|
| 120 |
|
- |
|
| 121 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
132 |
public HttpResponse getReportFile(ReporticoProject projectName, String reportName, Map<String, String> params)
|
| - |
|
133 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 122 |
if(params==null) {
|
134 |
if (params == null) {
|
| 123 |
params=new HashMap<>();
|
135 |
params = new HashMap<>();
|
| 124 |
}
|
136 |
}
|
| 125 |
params.putAll(projectAuthMap.get(projectName));
|
137 |
params.putAll(projectAuthMap.get(projectName));
|
| 126 |
params.put("xmlin", reportName);
|
138 |
params.put("xmlin", reportName);
|
| 127 |
params.put("target_format", "CSV");
|
139 |
params.put("target_format", "CSV");
|
| 128 |
params.put("execute_mode", "EXECUTE");
|
140 |
params.put("execute_mode", "EXECUTE");
|
| 129 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
141 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
| 130 |
}
|
142 |
}
|
| 131 |
|
143 |
|
| 132 |
public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
|
144 |
public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params)
|
| - |
|
145 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 133 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
146 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 134 |
params.putAll(authMap);
|
147 |
params.putAll(authMap);
|
| 135 |
params.put("xmlin", reportName);
|
148 |
params.put("xmlin", reportName);
|
| 136 |
params.put("target_format", "JSON");
|
149 |
params.put("target_format", "JSON");
|
| 137 |
params.put("execute_mode", "EXECUTE");
|
150 |
params.put("execute_mode", "EXECUTE");
|
| 138 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
151 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
| 139 |
}
|
152 |
}
|
| - |
|
153 |
|
| - |
|
154 |
public <T> List<T> getReports(Class<T> className, ReporticoProject project, String reportName,
|
| - |
|
155 |
Map<String, String> params) throws Exception {
|
| - |
|
156 |
HttpResponse reportResponse = this.getJsonFile(project, reportName, params);
|
| - |
|
157 |
JavaType type = objectMapper.getTypeFactory().constructParametricType(ReporticoResponseModel.class, className);
|
| - |
|
158 |
ObjectReader or = objectMapper.readerFor(type);
|
| - |
|
159 |
ReporticoResponseModel<T> responseObj = or.readValue(reportResponse.getEntity().getContent());
|
| - |
|
160 |
return responseObj.getData();
|
| - |
|
161 |
}
|
| 140 |
}
|
162 |
}
|