Subversion Repositories SmartDukaan

Rev

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

Rev 23951 Rev 26063
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.IOException;
3
import java.io.IOException;
-
 
4
import java.util.Map;
4
 
5
 
5
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletRequest;
6
 
7
 
7
import org.apache.http.HttpResponse;
8
import org.apache.http.HttpResponse;
8
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.LogManager;
Line 14... Line 15...
14
import org.springframework.http.ResponseEntity;
15
import org.springframework.http.ResponseEntity;
15
import org.springframework.stereotype.Controller;
16
import org.springframework.stereotype.Controller;
16
import org.springframework.transaction.annotation.Transactional;
17
import org.springframework.transaction.annotation.Transactional;
17
import org.springframework.ui.Model;
18
import org.springframework.ui.Model;
18
import org.springframework.web.bind.annotation.PathVariable;
19
import org.springframework.web.bind.annotation.PathVariable;
-
 
20
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestMethod;
21
 
23
 
22
import com.spice.profitmandi.common.enumuration.ReporticoProject;
24
import com.spice.profitmandi.common.enumuration.ReporticoProject;
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
Line 43... Line 45...
43
	@Autowired
45
	@Autowired
44
	private RoleManager roleManager;
46
	private RoleManager roleManager;
45
	
47
	
46
	private static final Logger log = LogManager.getLogger(OrderController.class);
48
	private static final Logger log = LogManager.getLogger(OrderController.class);
47
 
49
 
48
	@RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)
50
	@RequestMapping(value = "/reports/{projectName}/{fileName}")
49
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
51
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
50
			@PathVariable ReporticoProject projectName)
52
			@PathVariable ReporticoProject projectName, @RequestBody(required=false) Map<String, String> paramsMap)
51
			throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
53
			throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
52
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
54
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
53
		HttpResponse response;
55
		HttpResponse response;
54
	    if (roleManager.isAdmin(loginDetails.getRoleIds())) {
56
	    if (roleManager.isAdmin(loginDetails.getRoleIds())) {
55
			response = reporticoService.getReportFile(projectName, fileName + ".xml");
57
	    	response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
56
		} else {
58
		} else {
57
			response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");
59
			response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");
58
		}
60
		}
59
		HttpHeaders headers = new HttpHeaders();
61
		HttpHeaders headers = new HttpHeaders();
60
		InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
62
		InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
Line 63... Line 65...
63
				"inline; filename=report-" + fileName + ".csv");
65
				"inline; filename=report-" + fileName + ".csv");
64
		headers.setContentLength(response.getEntity().getContentLength());
66
		headers.setContentLength(response.getEntity().getContentLength());
65
		return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
67
		return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
66
	}
68
	}
67
 
69
 
-
 
70
	private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName, Map<String, String> reportParams) throws ProfitMandiBusinessException,  IOException{
-
 
71
		return reporticoService.getReportFile(projectName, fileName, reportParams);
-
 
72
	}
-
 
73
 
68
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
74
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
69
	public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
75
	public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
70
		model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
76
		model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
71
		return "reports";
77
		return "reports";
72
	}
78
	}