use of org.primefaces.model.StreamedContent in project opentheso by miledrousset.
the class StatBean method creatCSVFile.
/**
* #JM
* Méthode pour créer un fichier télécharger
* soit un fichier pour les statistiques du thesaurus soit pour les
* statistiques concepts
* @param idTheso
* @return
*/
public StreamedContent creatCSVFile(String idTheso) {
StringBuffer sbr = new StringBuffer();
try {
// ajou du titre au documen CSV
ArrayList<String> line = new ArrayList<>();
line.add("thesaurus : " + idTheso);
line.add(lang.toUpperCase());
line.add(new Date().toString());
if (this.typeStat == 1)
line.add(lb.getMsg("stat.forTheso"));
if (this.typeStat == 2) {
line.add(lb.getMsg("stat.forConcept"));
if (searchFromDate) {
line.add(lb.getMsg("stat.opt3") + " : " + begin);
line.add(lb.getMsg("stat.opt4") + " : " + end);
line.add((typeDate == 1) ? lb.getMsg("stat.opt2.1") : lb.getMsg("stat.opt2.2"));
}
if (searchFromGroup)
line.add(lb.getMsg("stat.group") + " : " + this.selectedGroup);
}
writeLine(sbr, line);
line = new ArrayList<>();
// ajout entête du tableau
if (this.typeStat == 1) {
line.add(lb.getMsg("stat.statTheso1"));
line.add(lb.getMsg("stat.statTheso2"));
line.add(lb.getMsg("stat.statTheso3"));
line.add(lb.getMsg("stat.statTheso4"));
line.add(lb.getMsg("stat.statTheso5"));
}
if (this.typeStat == 2) {
line.add(lb.getMsg("stat.statCpt1"));
line.add(lb.getMsg("stat.idC"));
line.add(lb.getMsg("stat.statCpt2"));
line.add(lb.getMsg("stat.statCpt3"));
line.add(lb.getMsg("stat.statCpt4"));
}
writeLine(sbr, line);
if (this.typeStat == 1) {
for (NodeStatTheso nst : this.statTheso) {
line = new ArrayList<>();
line.add(nst.getGroup());
line.add("" + nst.getNbDescripteur());
line.add("" + nst.getNbNonDescripteur());
line.add("" + nst.getNbNoTrad());
line.add("" + nst.getNbNotes());
writeLine(sbr, line);
}
}
if (this.typeStat == 2) {
for (NodeStatConcept nsc : this.statConcept) {
line = new ArrayList<>();
line.add(nsc.getValue());
line.add(nsc.getIdConcept());
line.add("" + nsc.getDateCreat());
line.add("" + nsc.getDateEdit());
line.add(nsc.getGroup());
writeLine(sbr, line);
}
}
} catch (IOException e) {
System.out.println("erreur pendant l'écriture du fichier" + e);
return null;
}
InputStream stream;
StreamedContent file = null;
try {
stream = new ByteArrayInputStream(sbr.toString().getBytes("UTF-8"));
String name_file = (typeStat == 1) ? "downloadedCsv_Thesaurus_stat.csv" : "downloadedCsv_concept_stat.csv";
file = new DefaultStreamedContent(stream, "text/csv", name_file);
} catch (UnsupportedEncodingException e) {
System.out.println("erreur création inputStream " + e);
return null;
}
return file;
}
use of org.primefaces.model.StreamedContent in project opentheso by miledrousset.
the class SynchroSparql method run.
@Override
public void run() {
System.out.println("dans le run saprtql");
String url = sparqlStruct.getAdresseServeur().replaceAll("http", "jdbc:virtuoso").trim() + ":1111";
VirtGraph graph = new VirtGraph(sparqlStruct.getGraph(), url, sparqlStruct.getNom_d_utilisateur(), sparqlStruct.getMot_de_passe());
String str = "CLEAR GRAPH <" + sparqlStruct.getGraph() + ">";
VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(str, graph);
vur.exec();
Model m = ModelFactory.createDefaultModel();
DownloadBean db = new DownloadBean();
db.setConnect(conn);
StreamedContent file = db.thesoToFile(sparqlStruct.getThesaurus(), liste_lang, liste_group, 0);
try {
m.read(file.getStream(), null);
} catch (Exception e) {
// graph.close();
}
StmtIterator iter = m.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
Triple tri = new Triple(subject.asNode(), predicate.asNode(), object.asNode());
graph.add(tri);
}
graph.close();
}
Aggregations