Subversion Repositories SmartDukaan

Rev

Rev 24509 | Rev 24698 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23612 amit.gupta 1
package com.spice.profitmandi.common.services;
2
 
24694 amit.gupta 3
import java.io.ByteArrayInputStream;
23612 amit.gupta 4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.Map;
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;
23612 amit.gupta 19
 
20
import com.spice.profitmandi.common.enumuration.ReporticoProject;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22
import com.spice.profitmandi.common.web.client.RestClient;
23
 
24
@Component
25
public class ReporticoService {
26
 
23763 amit.gupta 27
	//private String reporticoUrl="http://192.168.134.118/reports/run.php";
28
	private String reporticoUrl="http://50.116.10.120/reports/run.php";
23612 amit.gupta 29
 
23651 amit.gupta 30
	@Autowired
31
	RestClient restClient;
32
 
24694 amit.gupta 33
	@Autowired
34
	RestTemplate restTemplate;
35
 
23612 amit.gupta 36
	public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
37
			new HashMap<ReporticoProject, Map<String, String>>() {
38
				{
39
					put(ReporticoProject.FOCO, new HashMap<String, String>() {
40
						{
41
							put("project", ReporticoProject.FOCO.getValue());
24224 amit.gupta 42
							put("project_password", "smart1234");
23612 amit.gupta 43
						}
44
					});
23637 amit.gupta 45
					put(ReporticoProject.FOCOR, new HashMap<String, String>() {
46
						{
47
							put("project", ReporticoProject.FOCOR.getValue());
48
							put("project_password", "focor");
49
						}
50
					});
23951 amit.gupta 51
					put(ReporticoProject.WAREHOUSENEW, new HashMap<String, String>() {
52
						{
53
							put("project", ReporticoProject.WAREHOUSENEW.getValue());
54
							put("project_password", "warehousenew");
55
						}
56
					});
23612 amit.gupta 57
				}
58
			});
59
 
24509 amit.gupta 60
 
23612 amit.gupta 61
	public HttpResponse getReportFile(ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
62
 
63
		Map<String, String> authMap = projectAuthMap.get(projectName);
64
 
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");
80
 
81
		HttpEntity<String> requestEntity = new HttpEntity<String>("", new HttpHeaders());
82
		ResponseEntity<byte[]> responseEntity = restTemplate.exchange(reporticoUrl, HttpMethod.GET, requestEntity, byte[].class);
83
		return new ByteArrayResource(responseEntity.getBody());
84
 
85
	}
86
 
23612 amit.gupta 87
	public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
88
 
89
		Map<String, String> authMap = projectAuthMap.get(projectName);
90
 
91
		Map<String, String> params = new HashMap<>(authMap);
92
		params.put("xmlin", reportName);
93
		params.put("target_format", "CSV");
94
		params.put("execute_mode", "EXECUTE");
23637 amit.gupta 95
		params.put("MANUAL_fofoId", String.valueOf(fofoId));
23612 amit.gupta 96
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
97
	}
23945 amit.gupta 98
 
99
	public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
100
 
101
		Map<String, String> authMap = projectAuthMap.get(projectName);
102
 
103
		params.putAll(authMap);
104
		params.put("xmlin", reportName);
105
		params.put("target_format", "JSON");
106
		params.put("execute_mode", "EXECUTE");
107
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
108
	}
23612 amit.gupta 109
}