Subversion Repositories SmartDukaan

Rev

Rev 24509 | Rev 24698 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24509 Rev 24694
Line 1... Line 1...
1
package com.spice.profitmandi.common.services;
1
package com.spice.profitmandi.common.services;
2
 
2
 
-
 
3
import java.io.ByteArrayInputStream;
3
import java.util.Collections;
4
import java.util.Collections;
4
import java.util.HashMap;
5
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Map;
6
 
7
 
7
import org.apache.http.HttpResponse;
8
import org.apache.http.HttpResponse;
8
import org.apache.http.conn.HttpHostConnectException;
9
import org.apache.http.conn.HttpHostConnectException;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Autowired;
-
 
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;
10
import org.springframework.stereotype.Component;
17
import org.springframework.stereotype.Component;
-
 
18
import org.springframework.web.client.RestTemplate;
11
 
19
 
12
import com.spice.profitmandi.common.enumuration.ReporticoProject;
20
import com.spice.profitmandi.common.enumuration.ReporticoProject;
13
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
14
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
-
 
15
import com.spice.profitmandi.common.web.client.RestClient;
22
import com.spice.profitmandi.common.web.client.RestClient;
16
 
23
 
17
@Component
24
@Component
18
public class ReporticoService {
25
public class ReporticoService {
19
	
26
	
Line 21... Line 28...
21
	private String reporticoUrl="http://50.116.10.120/reports/run.php";
28
	private String reporticoUrl="http://50.116.10.120/reports/run.php";
22
	
29
	
23
	@Autowired
30
	@Autowired
24
	RestClient restClient;
31
	RestClient restClient;
25
	
32
	
-
 
33
	@Autowired
-
 
34
	RestTemplate restTemplate;
-
 
35
	
26
	public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
36
	public static final Map<ReporticoProject, Map<String, String>> projectAuthMap = Collections.unmodifiableMap(
27
			new HashMap<ReporticoProject, Map<String, String>>() {
37
			new HashMap<ReporticoProject, Map<String, String>>() {
28
				{
38
				{
29
					put(ReporticoProject.FOCO, new HashMap<String, String>() {
39
					put(ReporticoProject.FOCO, new HashMap<String, String>() {
30
						{
40
						{
Line 57... Line 67...
57
		params.put("target_format", "CSV");
67
		params.put("target_format", "CSV");
58
		params.put("execute_mode", "EXECUTE");
68
		params.put("execute_mode", "EXECUTE");
59
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
69
		return restClient.getResponse(reporticoUrl, params, new HashMap<>());
60
	}
70
	}
61
	
71
	
-
 
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
	
62
	public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
87
	public HttpResponse getReportFile(int fofoId, ReporticoProject projectName, String reportName) throws HttpHostConnectException, ProfitMandiBusinessException {
63
		
88
		
64
		Map<String, String> authMap = projectAuthMap.get(projectName);
89
		Map<String, String> authMap = projectAuthMap.get(projectName);
65
		
90
		
66
		Map<String, String> params = new HashMap<>(authMap);
91
		Map<String, String> params = new HashMap<>(authMap);