Subversion Repositories SmartDukaan

Rev

Rev 23637 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.spice.profitmandi.common.enumuration.ReporticoProject;
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.services.ReporticoService;
import com.spice.profitmandi.web.model.LoginDetails;
import com.spice.profitmandi.web.util.CookiesProcessor;

@Controller
public class ReportsController {
        
        private CookiesProcessor cookiesProcessor;  

        @RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)
        public ResponseEntity<?> updateTest(HttpServletRequest request, @PathVariable String fileName, @PathVariable ReporticoProject reporticoProject) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException{
                ReporticoService rs = new ReporticoService();
                LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
                HttpResponse response;
                if(loginDetails.isAdmin()) {
                        response = rs.getReportFile(reporticoProject, fileName  + ".xml");
                } else {
                        response = rs.getReportFile(loginDetails.getFofoId(), reporticoProject, fileName  + ".xml");
                }
                HttpHeaders headers = new HttpHeaders();
                for (Header header : response.getAllHeaders()) {
                        headers.add(header.getName(), header.getValue());
                }
                return new ResponseEntity<InputStreamResource>(new InputStreamResource(response.getEntity().getContent()), headers, HttpStatus.OK);
        }
}