Search in sources :

Example 1 with StreamedContent

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;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NodeStatConcept(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Date(java.util.Date) NodeStatTheso(mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatTheso) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamedContent(org.primefaces.model.StreamedContent) DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent)

Example 2 with StreamedContent

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();
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) VirtuosoUpdateRequest(virtuoso.jena.driver.VirtuosoUpdateRequest) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) Triple(org.apache.jena.graph.Triple) VirtGraph(virtuoso.jena.driver.VirtGraph) Model(org.apache.jena.rdf.model.Model) StreamedContent(org.primefaces.model.StreamedContent) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

StreamedContent (org.primefaces.model.StreamedContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)1 NodeStatConcept (mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatConcept)1 NodeStatTheso (mom.trd.opentheso.bdd.helper.nodes.statistic.NodeStatTheso)1 Triple (org.apache.jena.graph.Triple)1 Model (org.apache.jena.rdf.model.Model)1 Property (org.apache.jena.rdf.model.Property)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Resource (org.apache.jena.rdf.model.Resource)1 Statement (org.apache.jena.rdf.model.Statement)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)1 VirtGraph (virtuoso.jena.driver.VirtGraph)1 VirtuosoUpdateRequest (virtuoso.jena.driver.VirtuosoUpdateRequest)1