Vous êtes sur la page 1sur 2

package com.nxm.tools.service.

report;
import java.io.FileNotFoundException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.codehaus.jettison.json.JSONException;
import org.springframework.stereotype.Service;
import com.ael.commons.tools.properties.exceptions.PropertiesException;
import com.nxm.tools.properties.PropertiesManager;
@Service("reportManagerServiceRS")
public class Report {
// @POST
@Path("/exportplanningtoPdf")
@GET
@Produces("application/json")
//@Produces("application/pdf")
//@Consumes("application/json")String infoplaning
public String testPdf() throws FileNotFoundException, JSONException{
String CONFIGFILE;
try {
CONFIGFILE = PropertiesManager.getInstance().getProperty
("REPORTING","jrxml.dir");
System.out.println("config file"+CONFIGFILE);
return "ok";
//return Response.status(200).entity("OK").build();
} catch (PropertiesException e) {
e.printStackTrace();
return "err";
//return Response.status(200).entity(e.printStackTrace()
).build();
}

/* System.out.println("ok");
String url = "jdbc:mysql://localhost/enajah";
String login = "root";
String password = "";
Connection connection = null;
ResponseBuilder response=null;
JSONObject jsonObject = new JSONObject(infoplaning);
String idGroupe = jsonObject.getString("idGroupe");
String month = jsonObject.getString("month");
String year = jsonObject.getString("year");
try {
Driver monDriver = new com.mysql.jdbc.Driver();
DriverManager.registerDriver(monDriver);
connection = (Connection) DriverManager.getConnection(url, login, passwo
rd);
System.out.print("conncetion "+connection);
File jrxmlFile = new File("D:\\planning_mensuel.jrxml");
System.out.println("-------existe-------"+jrxmlFile.exists());
if(jrxmlFile.exists()){
System.out.println("File exists");
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlFile
.getAbsolutePath());
Map<String,Object> params = new HashMap<String, Object>();
params.put("GROUPE_ID", idGroupe);
params.put("MONTH", month);
params.put("YEAR",year);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, par
ams, connection);
String file = "D:\\planning_mensuel.pdf";
JasperExportManager.exportReportToPdfFile(jasperPrint, file);
File filetoDownload=new File(file);
response = Response.ok((Object) filetoDownload);
response.header("Content-Disposition","attachment; filename=planning.pdf
");
}
return response.build();
} catch (JRException e) {
return Response.status(200).entity("Erreur_Technique").build();
} catch (SQLException e) {
return Response.status(200).entity("Erreur_SQL").build();
} finally {
try {
connection.close();
} catch (SQLException e) {
return Response.status(200).entity("ERREUR_SQL").build();
}
}
}*/
}}

Vous aimerez peut-être aussi