| Line 19... |
Line 19... |
| 19 |
import org.springframework.http.HttpHeaders;
|
19 |
import org.springframework.http.HttpHeaders;
|
| 20 |
import org.springframework.http.HttpMethod;
|
20 |
import org.springframework.http.HttpMethod;
|
| 21 |
import org.springframework.http.ResponseEntity;
|
21 |
import org.springframework.http.ResponseEntity;
|
| 22 |
import org.springframework.stereotype.Component;
|
22 |
import org.springframework.stereotype.Component;
|
| 23 |
import org.springframework.web.client.RestTemplate;
|
23 |
import org.springframework.web.client.RestTemplate;
|
| 24 |
import org.springframework.web.util.UriComponentsBuilder;
|
24 |
import org.springframework.util.LinkedMultiValueMap;
|
| - |
|
25 |
import org.springframework.util.MultiValueMap;
|
| 25 |
|
26 |
|
| 26 |
import java.util.*;
|
27 |
import java.util.*;
|
| 27 |
|
28 |
|
| 28 |
@Component
|
29 |
@Component
|
| 29 |
public class ReporticoService {
|
30 |
public class ReporticoService {
|
| Line 72... |
Line 73... |
| 72 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
73 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 73 |
Map<String, String> params = new HashMap<>(authMap);
|
74 |
Map<String, String> params = new HashMap<>(authMap);
|
| 74 |
params.put("xmlin", reportName);
|
75 |
params.put("xmlin", reportName);
|
| 75 |
params.put("target_format", "CSV");
|
76 |
params.put("target_format", "CSV");
|
| 76 |
params.put("execute_mode", "EXECUTE");
|
77 |
params.put("execute_mode", "EXECUTE");
|
| 77 |
return restClient.getResponse(reporticoUrl, params, null);
|
78 |
return restClient.postResponse(reporticoUrl, params, null);
|
| 78 |
}
|
79 |
}
|
| 79 |
|
80 |
|
| 80 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName)
|
81 |
public InputStreamSource getReportInputStreamSource(ReporticoProject projectName, String reportName)
|
| 81 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
82 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 82 |
|
83 |
|
| Line 84... |
Line 85... |
| 84 |
|
85 |
|
| 85 |
Map<String, String> params = new HashMap<>(authMap);
|
86 |
Map<String, String> params = new HashMap<>(authMap);
|
| 86 |
params.put("xmlin", reportName);
|
87 |
params.put("xmlin", reportName);
|
| 87 |
params.put("target_format", "CSV");
|
88 |
params.put("target_format", "CSV");
|
| 88 |
params.put("execute_mode", "EXECUTE");
|
89 |
params.put("execute_mode", "EXECUTE");
|
| 89 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
- |
|
| 90 |
Set<String> keys = params.keySet();
|
- |
|
| 91 |
|
90 |
|
| - |
|
91 |
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
| 92 |
for (String key : keys) {
|
92 |
for (Map.Entry<String, String> entry : params.entrySet()) {
|
| 93 |
builder.queryParam(key, params.get(key));
|
93 |
formData.add(entry.getKey(), entry.getValue());
|
| 94 |
}
|
94 |
}
|
| - |
|
95 |
HttpHeaders headers = new HttpHeaders();
|
| - |
|
96 |
headers.setContentType(org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED);
|
| 95 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
97 |
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
|
| 96 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
|
98 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(reporticoUrl, HttpMethod.POST,
|
| 97 |
requestEntity, byte[].class);
|
99 |
requestEntity, byte[].class);
|
| 98 |
return new ByteArrayResource(responseEntity.getBody());
|
100 |
return new ByteArrayResource(responseEntity.getBody());
|
| 99 |
|
101 |
|
| 100 |
}
|
102 |
}
|
| 101 |
|
103 |
|
| Line 106... |
Line 108... |
| 106 |
|
108 |
|
| 107 |
params.putAll(authMap);
|
109 |
params.putAll(authMap);
|
| 108 |
params.put("xmlin", reportName);
|
110 |
params.put("xmlin", reportName);
|
| 109 |
params.put("target_format", "CSV");
|
111 |
params.put("target_format", "CSV");
|
| 110 |
params.put("execute_mode", "EXECUTE");
|
112 |
params.put("execute_mode", "EXECUTE");
|
| 111 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(reporticoUrl);
|
- |
|
| 112 |
Set<String> keys = params.keySet();
|
- |
|
| 113 |
|
113 |
|
| - |
|
114 |
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
| 114 |
for (String key : keys) {
|
115 |
for (Map.Entry<String, String> entry : params.entrySet()) {
|
| 115 |
builder.queryParam(key, params.get(key));
|
116 |
formData.add(entry.getKey(), entry.getValue());
|
| 116 |
}
|
117 |
}
|
| - |
|
118 |
HttpHeaders headers = new HttpHeaders();
|
| - |
|
119 |
headers.setContentType(org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED);
|
| 117 |
HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
|
120 |
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
|
| 118 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET,
|
121 |
ResponseEntity<byte[]> responseEntity = restTemplate.exchange(reporticoUrl, HttpMethod.POST,
|
| 119 |
requestEntity, byte[].class);
|
122 |
requestEntity, byte[].class);
|
| 120 |
return new ByteArrayResource(responseEntity.getBody());
|
123 |
return new ByteArrayResource(responseEntity.getBody());
|
| 121 |
|
124 |
|
| 122 |
}
|
125 |
}
|
| 123 |
|
126 |
|
| Line 135... |
Line 138... |
| 135 |
}
|
138 |
}
|
| 136 |
params.putAll(projectAuthMap.get(projectName));
|
139 |
params.putAll(projectAuthMap.get(projectName));
|
| 137 |
params.put("xmlin", reportName);
|
140 |
params.put("xmlin", reportName);
|
| 138 |
params.put("target_format", "CSV");
|
141 |
params.put("target_format", "CSV");
|
| 139 |
params.put("execute_mode", "EXECUTE");
|
142 |
params.put("execute_mode", "EXECUTE");
|
| 140 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
143 |
return restClient.postResponse(reporticoUrl, params, new HashMap<>());
|
| 141 |
}
|
144 |
}
|
| 142 |
|
145 |
|
| 143 |
public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params)
|
146 |
public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params)
|
| 144 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
147 |
throws HttpHostConnectException, ProfitMandiBusinessException {
|
| 145 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
148 |
Map<String, String> authMap = projectAuthMap.get(projectName);
|
| 146 |
params.putAll(authMap);
|
149 |
params.putAll(authMap);
|
| 147 |
params.put("xmlin", reportName);
|
150 |
params.put("xmlin", reportName);
|
| 148 |
params.put("target_format", "JSON");
|
151 |
params.put("target_format", "JSON");
|
| 149 |
params.put("execute_mode", "EXECUTE");
|
152 |
params.put("execute_mode", "EXECUTE");
|
| 150 |
return restClient.getResponse(reporticoUrl, params, new HashMap<>());
|
153 |
return restClient.postResponse(reporticoUrl, params, new HashMap<>());
|
| 151 |
}
|
154 |
}
|
| 152 |
|
155 |
|
| 153 |
public <T> List<T> getReports(Class<T> className, ReporticoProject project, String reportName,
|
156 |
public <T> List<T> getReports(Class<T> className, ReporticoProject project, String reportName,
|
| 154 |
Map<String, String> params) throws Exception {
|
157 |
Map<String, String> params) throws Exception {
|
| 155 |
HttpResponse reportResponse = this.getJsonFile(project, reportName, params);
|
158 |
HttpResponse reportResponse = this.getJsonFile(project, reportName, params);
|