Subversion Repositories SmartDukaan

Rev

Rev 23763 | Rev 23951 | 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());
31
							put("project_password", "foco");
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
					});
23612 amit.gupta 40
				}
41
			});
42
 
43
	public HttpResponse getReportFile(ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
44
 
45
		Map<String, String> authMap = projectAuthMap.get(projectName);
46
 
47
		Map<String, String> params = new HashMap<>(authMap);
48
		params.put("xmlin", reportName);
49
		params.put("target_format", "CSV");
50
		params.put("execute_mode", "EXECUTE");
51
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
52
	}
53
 
54
	public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
55
 
56
		Map<String, String> authMap = projectAuthMap.get(projectName);
57
 
58
		Map<String, String> params = new HashMap<>(authMap);
59
		params.put("xmlin", reportName);
60
		params.put("target_format", "CSV");
61
		params.put("execute_mode", "EXECUTE");
23637 amit.gupta 62
		params.put("MANUAL_fofoId", String.valueOf(fofoId));
23612 amit.gupta 63
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
64
	}
23945 amit.gupta 65
 
66
	public HttpResponse getJsonFile(ReporticoProject projectName, String reportName, Map<String, String> params) throws HttpHostConnectException, ProfitMandiBusinessException {
67
 
68
		Map<String, String> authMap = projectAuthMap.get(projectName);
69
 
70
		params.putAll(authMap);
71
		params.put("xmlin", reportName);
72
		params.put("target_format", "JSON");
73
		params.put("execute_mode", "EXECUTE");
74
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
75
	}
23612 amit.gupta 76
}