Subversion Repositories SmartDukaan

Rev

Rev 23951 | Rev 24509 | 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
 
3
import java.util.Collections;
4
import java.util.HashMap;
5
import java.util.Map;
6
 
7
import org.apache.http.HttpResponse;
8
import org.apache.http.conn.HttpHostConnectException;
23651 amit.gupta 9
import org.springframework.beans.factory.annotation.Autowired;
23612 amit.gupta 10
import org.springframework.stereotype.Component;
11
 
12
import com.spice.profitmandi.common.enumuration.ReporticoProject;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
14
import com.spice.profitmandi.common.web.client.RestClient;
15
 
16
@Component
17
public class ReporticoService {
18
 
23763 amit.gupta 19
	//private String reporticoUrl="http://192.168.134.118/reports/run.php";
20
	private String reporticoUrl="http://50.116.10.120/reports/run.php";
23612 amit.gupta 21
 
23651 amit.gupta 22
	@Autowired
23
	RestClient restClient;
24
 
23612 amit.gupta 25
	public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
26
			new HashMap<ReporticoProject, Map<String, String>>() {
27
				{
28
					put(ReporticoProject.FOCO, new HashMap<String, String>() {
29
						{
30
							put("project", ReporticoProject.FOCO.getValue());
24224 amit.gupta 31
							put("project_password", "smart1234");
23612 amit.gupta 32
						}
33
					});
23637 amit.gupta 34
					put(ReporticoProject.FOCOR, new HashMap<String, String>() {
35
						{
36
							put("project", ReporticoProject.FOCOR.getValue());
37
							put("project_password", "focor");
38
						}
39
					});
23951 amit.gupta 40
					put(ReporticoProject.WAREHOUSENEW, new HashMap<String, String>() {
41
						{
42
							put("project", ReporticoProject.WAREHOUSENEW.getValue());
43
							put("project_password", "warehousenew");
44
						}
45
					});
23612 amit.gupta 46
				}
47
			});
48
 
49
	public HttpResponse getReportFile(ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
50
 
51
		Map<String, String> authMap = projectAuthMap.get(projectName);
52
 
53
		Map<String, String> params = new HashMap<>(authMap);
54
		params.put("xmlin", reportName);
55
		params.put("target_format", "CSV");
56
		params.put("execute_mode", "EXECUTE");
57
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
58
	}
59
 
60
	public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
61
 
62
		Map<String, String> authMap = projectAuthMap.get(projectName);
63
 
64
		Map<String, String> params = new HashMap<>(authMap);
65
		params.put("xmlin", reportName);
66
		params.put("target_format", "CSV");
67
		params.put("execute_mode", "EXECUTE");
23637 amit.gupta 68
		params.put("MANUAL_fofoId", String.valueOf(fofoId));
23612 amit.gupta 69
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
70
	}
23945 amit.gupta 71
 
72
	public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
73
 
74
		Map<String, String> authMap = projectAuthMap.get(projectName);
75
 
76
		params.putAll(authMap);
77
		params.put("xmlin", reportName);
78
		params.put("target_format", "JSON");
79
		params.put("execute_mode", "EXECUTE");
80
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
81
	}
23612 amit.gupta 82
}